opencode icon indicating copy to clipboard operation
opencode copied to clipboard

πŸ› Bug Report: MCP Tool JSON Parsing Errors on OpenCode (GLM-4.7)

Open izzamoe opened this issue 2 days ago β€’ 0 comments

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

  1. Strict JSON validation layer before MCP call
  2. Auto-quoting for enums / strings when schema requires it
  3. Reject & re-prompt model when tool args are invalid (instead of executing)
  4. 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

izzamoe avatar Jan 13 '26 00:01 izzamoe