Skip to content

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

Closed as not planned

Description

@izzamoe

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

Activity

  1. cieske commented on Feb 3, 2026

    @cieske

    I also meet JSON parsing error when using opencode + GLM-4.7 flash(served locally) and remove speculative-config-related option from serving guide solve the issues. Maybe not exactly the same situation due to the different providers, just leave it at that.

  2. LittleCoinCoin commented on Feb 20, 2026

    @LittleCoinCoin

    @cieske's suggestion to remove speculative-config also fixed it for a vllm self-hosted GLM-4.7-Flash.

  3. simonjhy commented on Mar 11, 2026

    @simonjhy

    I meet this issue even I did not set speculative-config parameter

  4. removed
    bugSomething isn't working
    on May 3, 2026
  5. github-actions commented on Jul 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions