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.
Solutions
- Pass a non-empty "key" string in the tool input: {"key": "user:123"}.
- If you need a listing, check whether the store implementation offers a list capability instead of calling read with an empty key.
- 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
- Never pass an empty key hoping to list records — read is key-based only.
- Sanitize/validate keys at the application layer before invoking the tool.
- Check upstream data sources so the key variable can't be empty.
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
- name is required
- topic is required
- addr (nats subject) must not be empty
- addr (nats subject) must not contain space characters
- ai model is nil
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/7edabca405cca774.
Report an issue: GitHub.
Appendix: 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)