Conversation
When tool call arguments are parsed via JSON.parse(), string-typed parameters containing valid JSON (e.g. file content for .json files) get deeply parsed into objects. Built-in tools handle this via getStringArg(), but MCP tools with dynamic schemas had no equivalent fix, causing write_file and similar tools to receive objects instead of strings. Add coerceArgsToSchema() that checks the tool's inputSchema and re-stringifies any values that should be strings before passing args to the MCP client. Fixes #8510
Documentation ReviewNo documentation updates needed for this PR. Reasoning: This PR is an internal bug fix that transparently handles edge cases in MCP tool argument parsing. The This fix:
The existing MCP documentation covers configuration, setup, and transport types—documenting internal argument coercion mechanics would add unnecessary implementation detail that doesn't help developers use Continue more effectively. |
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/tools/parseArgs.ts">
<violation number="1" location="core/tools/parseArgs.ts:51">
P2: This coercion is too broad for `type: "string"`: it also converts number/boolean inputs to strings, which can mask invalid tool arguments instead of only fixing deep-parsed object/array values.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Only re-stringify values that are objects or arrays (the actual deep-parsing issue). Numbers and booleans passed to a string-typed parameter are left as-is so they surface as type errors rather than being silently converted.
Summary
type: "string"(e.g.write_filecontent parameter)coerceArgsToSchema()that checks the tool'sinputSchemaand re-stringifies any values that were deeply parsed byJSON.parse()but should remain as stringsgetStringArg(), but MCP tools with dynamic schemas had no equivalent fixTest plan
coerceArgsToSchema()covering: object→string coercion, array→string coercion, no-op for already-string values, no-op for non-string schema types, no schema, mixed args, immutabilityparseArgs.vitest.tspassFixes #8510
Summary by cubic
Coerces MCP tool args to match string-typed schema params so tools don’t receive parsed objects/arrays. Applies before calling the MCP client to fix cases like
write_filewhere JSON content must remain a string.coerceArgsToSchema()that re-stringifies only object/array values when the schema saystype: "string", and used it before MCPcallTool.Written for commit 42d2037. Summary will update on new commits.