anomalyco / anomalyco/opencode
MCP client serializes nested object params as JSON string instead of object
@kitlangton is already working on this.
Since Aug 26, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
When an MCP tool declares a parameter with a nested object type (e.g. metadata: Option<StoreMetadata> where StoreMetadata is a struct with tags and type fields), OpenCode's MCP client sends the parameter value as a JSON string instead of a JSON object.
The MCP server (Rust, using serde deserialization) receives:
"metadata": "{"tags": ["tag1", "tag2"], "type": "decision"}"
instead of:
"metadata": {"tags": ["tag1", "tag2"], "type": "decision"}
This causes -32602: failed to deserialize parameters: invalid type: string "...", expected struct StoreMetadata.
Steps to reproduce
- Configure an MCP server with a tool that accepts a nested object parameter (e.g.
opencode-memorywithmemory_storewhich takesmetadata: {tags, type}) - Ask the agent to store a memory with metadata
- The tool call fails with the deserialization error
Expected behavior
OpenCode should send nested object parameters as JSON objects, not as stringified JSON. The MCP schema correctly declares these as object types — the client should honor that.
Root cause analysis
The MCP tool schema for memory_store defines:
"metadata": {
"anyOf": [
{"$ref": "#/$defs/StoreMetadata"},
{"type": "null"}
],
"description": "Optional metadata object; tags + type live here."
}
And StoreMetadata is:
"StoreMetadata": {
"type": "object",
"properties": {
"tags": {...},
"type": {"type": "string"}
}
}
OpenCode appears to stringify the object value before passing it to the MCP server via JSON-RPC, likely in the parameter serialization layer.
Environment
OpenCode version: latest (opencode/big-pickle via Ollama)
MCP server: opencode-memory v0.1.4 (Rust, rajarshighoshal/opencode-memory)
Transport: stdio (local)
OS: Linux
Suggested fix
In the MCP client parameter serialization path, detect when a parameter value is a string that parses as valid JSON matching the expected schema type (object), and deserialize it before sending to the MCP server. Alternatively, ensure the LLM-generated tool call arguments preserve proper JSON object nesting.
Related
This affects any MCP server with nested object parameters (not just opencode-memory)
The same MCP server works correctly with Claude Code and Codex CLI
### Plugins
_No response_
### OpenCode version
_No response_
### Steps to reproduce
1. Configure an MCP server with a tool that accepts a nested object parameter (e.g. `opencode-memory` with `memory_store` which takes `metadata: {tags, type}`)
2. Ask the agent to store a memory with metadata
3. The tool call fails with the deserialization error
### Screenshot and/or share link
_No response_
### Operating System
Ubuntu 24.06 LTS
### Terminal
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.