Skip to content

Commit 9f9c65f

Browse files
committed
fix: parse JSON-string MCP tool arguments before type check
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).
1 parent 45b239c commit 9f9c65f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/core/tools/UseMcpToolTool.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ export class UseMcpToolTool extends BaseTool<"use_mcp_tool"> {
111111
return { isValid: false }
112112
}
113113

114-
// Native-only: arguments are already a structured object.
114+
// Some LLMs emit arguments as JSON-encoded strings rather than objects.
115+
// Parse them early so the type check below sees the unwrapped object.
116+
if (typeof params.arguments === "string") {
117+
try {
118+
params.arguments = JSON.parse(params.arguments)
119+
} catch {}
120+
}
121+
115122
let parsedArguments: Record<string, unknown> | undefined
116123
if (params.arguments !== undefined) {
117124
if (typeof params.arguments !== "object" || params.arguments === null || Array.isArray(params.arguments)) {

0 commit comments

Comments
 (0)