Skip to content

Claude models fail on MCP tools with no required parameters (undefined vs {}) #9020

@belovedEmperor

Description

@belovedEmperor

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

  1. Configure @modelcontextprotocol/server-memory MCP server
  2. Use a Claude model (e.g., claude-sonnet-4-20250514)
  3. Trigger memory_read_graph tool (no required params)
  4. Tool execution aborted with invalid_union error

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions