micro/go-micro · error

key is required

Error message

key is required

What it means

The built-in store "read" MCP tool requires the "key" input parameter identifying the store record to fetch. An empty or missing key fails the guard before store.Read is called.

Source

Thrown at gateway/mcp/mcp.go:495

				return nil, err
			}
			return map[string]interface{}{"keys": keys}, nil
		},
	})

	addFramework(&Tool{
		Name:        "micro_store_read",
		Description: "Read a record from the data store by key",
		InputSchema: map[string]interface{}{
			"type": "object",
			"properties": map[string]interface{}{
				"key": map[string]interface{}{"type": "string", "description": "Record key"},
			},
		},
		Handler: func(input map[string]interface{}) (interface{}, error) {
			key, _ := input["key"].(string)
			if key == "" {
				return nil, fmt.Errorf("key is required")
			}
			records, err := store.Read(key)
			if err != nil {
				return nil, err
			}
			if len(records) == 0 {
				return map[string]interface{}{"error": "not found"}, nil
			}
			return map[string]interface{}{"key": key, "value": string(records[0].Value)}, nil
		},
	})

	addFramework(&Tool{
		Name:        "micro_store_write",
		Description: "Write a record to the data store",
		InputSchema: map[string]interface{}{
			"type": "object",
			"properties": map[string]interface{}{

View on GitHub (pinned to 24529f1404)

Solutions

  1. Pass a non-empty "key" string in the tool input: {"key": "user:123"}.
  2. If you need a listing, check whether the store implementation offers a list capability instead of calling read with an empty key.
  3. Validate that the key value is non-empty in the client before invoking the tool.

Example fix

// before
input := map[string]interface{}{} // no key
// after
input := map[string]interface{}{"key": "user:123"}
Defensive patterns

Strategy: validation

Validate before calling

key, _ := input["key"].(string)
if key == "" {
    return errors.New("store read requires a non-empty 'key' argument")
}

Type guard

func validKey(input map[string]interface{}) (string, bool) {
    k, ok := input["key"].(string)
    return k, ok && k != ""
}

Try / catch

records, err := callTool("store_read", map[string]interface{}{"key": key})
if err != nil {
    if strings.Contains(err.Error(), "key is required") {
        // supply the key and retry
    }
}

Prevention

When it happens

Trigger: An MCP client calls the store read tool with input {} or {"key": ""}; the handler short-circuits with "key is required" instead of reading from the store.

Common situations: LLM omits the key argument; caller assumed the tool would list all records instead of reading by key; key variable was empty because upstream data was missing.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/7edabca405cca774. Report an issue: GitHub.