π Bug Report: MCP Tool JSON Parsing Errors on OpenCode (GLM-4.7)
Description
Summary
When using MCP generator tools with GLM-4.7 in OpenCode, the model frequently produces invalid JSON arguments for MCP tool calls, causing repeated JSON parsing failed errors.
The same MCP server + model works correctly on other clients (e.g. RooCode, KiloCode).
This leads to:
- Tool call failures
- Infinite retry loops
- Model βgiving upβ mid-task
Environment
-
Client: OpenCode
-
Model: GLM-4.7
-
MCP Server: Custom local MCP (generator tools)
-
Other clients tested (working):
- RooCode β
- KiloCode β
-
OS: Linux
-
Transport: MCP stdio / local
Affected Tools (examples)
-
generator-mcp_get_relations -
generator-mcp_update_database -
generator-mcp_execute_dynamic_api
Example Errors
β Invalid JSON (unquoted value)
Invalid input for tool generator-mcp_get_relations: JSON parsing failed
Text: {"table_name":"t_purchase_invoice","direction":both}
Error: Unexpected identifier "both"
β UUID not quoted
Invalid input for tool generator-mcp_execute_dynamic_api: JSON parsing failed
Text:
{"id":cf56856a-5b7f-47aa-9877-8f45d1d2c1ee,"method":"GET","model":"m_customer","operation":"detail"}
Error: Unexpected identifier "cf56856a"
β Repeated failure even after self-correction
{"source":api}
Error: Unexpected identifier "api"
Model attempts to βfixβ it but keeps emitting invalid JSON.
Expected Behavior
- OpenCode should enforce or validate strict JSON serialization before MCP tool execution
- Model output for tool arguments should be auto-corrected or rejected before sending to MCP
- Same behavior consistency as RooCode / KiloCode
Actual Behavior
- Model emits JS-like objects, not valid JSON
- No client-side sanitation or retry with correction
- Tool execution fails repeatedly
- Model eventually halts or degrades output quality
Why This Is a Client Bug (Not MCP / Model)
- β Same MCP server works perfectly on other clients
- β Same prompts + GLM-4.7 succeed elsewhere
- β Only OpenCode shows persistent JSON formatting failures
This strongly suggests:
OpenCode does not strictly constrain / validate tool call JSON before execution
Suggested Fixes
- Strict JSON validation layer before MCP call
- Auto-quoting for enums / strings when schema requires it
- Reject & re-prompt model when tool args are invalid (instead of executing)
- Optional: show tool schema-aware JSON fixer
Impact
- Makes MCP unusable for complex workflows
- Breaks parallel tool execution
- Causes model instability and task abandonment
Reproducibility
- π Reproducible ~80β90% of the time on OpenCode
- β Not reproducible on RooCode / KiloCode
Closing
This issue significantly affects MCP reliability in OpenCode. Please prioritize JSON argument enforcement for tool calls.
Thanks π
Plugins
No response
OpenCode version
1.1.15
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response