[BUG] Claude Code incorrectly serializes JSON objects as strings when calling MCP tools
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Code / CLI
- Claude CLI version: 1.0.72 (Claude Code)
- Operating System: macOS Sequoya 15.6 (24G84)
- Terminal: Terminal/CLI - zsh 5.9 (arm64-apple-darwin24.0)
Bug Description
Claude Code incorrectly serializes JSON objects as strings when passing them to MCP tools, causing validation errors. When using MCP tools that expect native JSON objects (like ConPort's mcp__conport__update_product_context), Claude Code wraps the object parameter in quotes, converting it to a string, which fails schema validation.
Steps to Reproduce
- Use an MCP tool that expects a JSON object parameter (e.g., install the Context Portal MCP, and use
mcp__conport__update_product_contextwithpatch_contentparameter). - Pass a JSON object like
{"key": "value"}as the parameter value - Observe that Claude Code sends the parameter as a quoted string:
"{\"key\": \"value\"}"instead of a native JSON object - The MCP server receives a string instead of an object and fails validation with "Input validation error: '...' is not valid under any of the given schemas"
Expected Behavior
When Claude Code calls MCP tools with JSON object parameters, it should pass the objects as native JSON objects, not as quoted strings. For example:
{
"workspace_id": "/path/to/workspace",
"patch_content": {"key": "value"}
}
Note the expected schema for the parameter:
"patch_content": {
"anyOf": [
{"additionalProperties": true, "type": "object"},
{"type": "null"}
],
"default": null,
"description": "The full new context content as a dictionary. Overwrites existing.",
"title": "Content"
}
Actual Behavior
Claude Code incorrectly serializes the JSON object parameter as a string:
{
"workspace_id": "/path/to/workspace",
"patch_content": "{\"key\": \"value\"}"
}
This causes MCP servers to receive strings instead of objects, leading to schema validation failures. MCP server returns the error message:
Error: Input validation error: '{"key": "value"}' is not valid under any of the given schemas
Additional Context
- This issue affects all MCP tools that expect object-type parameters
- The issue persists regardless of how the JSON is formatted in the Claude Code interface
- Multiple attempts were made with different formatting approaches, all resulting in the same string serialization
- ConPort MCP server schema validation correctly rejects the incorrectly serialized parameters
- Other AI coding asssistant tools (like Roo Code) work correctly with the same MCP server (e.g. ConPort) and its tools
- The issue appears to be in Claude Code's parameter serialization logic when calling MCP tools
- Error message example:
Input validation error: '{"key": "value"}' is not valid under any of the given schemas
Reproduction Commands
/mcp update product context
mcp__conport__update_product_context with content: {"key": "value"}
This bug prevents proper usage of MCP tools that require JSON object parameters, limiting the functionality of Claude Code with MCP servers.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗