🐛 Bug Report: MCP Tool JSON Parsing Errors on OpenCode (GLM-4.7) #5101

Open
opened 2026-02-16 17:48:43 -05:00 by yindo · 0 comments
Owner

Originally created by @izzamoe on GitHub (Jan 12, 2026).

Originally assigned to: @thdxr on GitHub.

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

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Terminal

No response

Originally created by @izzamoe on GitHub (Jan 12, 2026). Originally assigned to: @thdxr on GitHub. ### 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) ```text 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 ```text 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 ```text {"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 PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" ### Terminal _No response_
yindo added the bug label 2026-02-16 17:48:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5101