-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
Description
Description
Claude models send undefined for MCP tool arguments when a tool has no required parameters. OpenCode passes this through unchanged, causing Zod validation to fail on the MCP server side.
Gemini models send {} for the same tools and work fine.
Steps to reproduce
- Configure
@modelcontextprotocol/server-memoryMCP server - Use a Claude model (e.g.,
claude-sonnet-4-20250514) - Trigger
memory_read_graphtool (no required params) - Tool execution aborted with
invalid_unionerror
Error output
[
{
"code": "invalid_union",
"errors": [
[
{
"expected": "record",
"code": "invalid_type",
"path": [
"state",
"input"
],
"message": "Invalid input: expected record, received undefined"
}
],
[
{
"expected": "object",
"code": "invalid_type",
"path": [
"part"
],
"message": "Invalid input: expected object, received undefined"
},
{
"expected": "string",
"code": "invalid_type",
"path": [
"delta"
],
"message": "Invalid input: expected string, received undefined"
}
],
[
{
"expected": "object",
"code": "invalid_type",
"path": [
"part"
],
"message": "Invalid input: expected object, received undefined"
},
{
"expected": "string",
"code": "invalid_type",
"path": [
"delta"
],
"message": "Invalid input: expected string, received undefined"
}
]
],
"path": [],
"message": "Invalid input"
}
]Root cause
In packages/opencode/src/mcp/index.ts, convertMcpTool's execute function passes args directly:
arguments: args as Record<string, unknown>When Claude sends undefined, this becomes arguments: undefined to the MCP server.
Suggested fix
arguments: args ?? {}Environment
- OS: NixOS
- Models affected: Claude (all versions tested)
- Models working: Gemini
Reactions are currently unavailable