fix: parse JSON-string MCP tool arguments before type check#255
fix: parse JSON-string MCP tool arguments before type check#255pajitosingh wants to merge 1 commit into
Conversation
Some LLMs (DeepSeek V4 Pro, others) emit MCP tool call arguments as
JSON-encoded strings (e.g. '{"headless": true}') rather than as
native objects. This causes validateParams() to reject valid MCP
tool calls with 'Invalid JSON argument' errors.
The fix adds a JSON.parse() guard before the existing type check,
falling through silently if parsing fails. The existing code path
then handles it as before (either accepts the object or rejects
malformed input).
This matches the fix applied to Roo Code v3.54.0 which was field-
tested across multiple MCP providers (playwright-stealth etc).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds JSON string parsing to the ChangesArguments JSON Parsing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/core/tools/UseMcpToolTool.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Some LLMs (DeepSeek V4 Pro and others) emit MCP tool call
argumentsas JSON-encoded strings rather than as native objects:{ "arguments": "{\"headless\": true}" }instead of:
{ "arguments": { "headless": true } }The existing
validateParams()method inUseMcpToolTool.tsrejects these with "Invalid JSON argument" errors because the type check (typeof params.arguments !== "object") fails on strings.This is the same bug that plagued Roo Code v3.54.0 (see Roo-Code issues #10919 and the archive discussion).
Fix
Adds a
JSON.parse()guard before the existing type check. Ifargumentsarrives as a string, attempt to parse it into an object. If parsing fails (malformed JSON), we fall through silently and the existing code path handles it as before (rejects with the appropriate error).Safety
typeofcheck passes the string guard, goes straight to the object type check → no changeJSON.parse()unwraps the string into an object → type check passes → fixJSON.parse()throws,catch {}swallows it → falls through to the existing error path → graceful rejectionTesting
Summary by CodeRabbit