Repository navigation
Conversation
… text Claude Desktop delivers array and object tool arguments as JSON text, so SDK input validation rejected every structured parameter of every tool before its handler ran (morluto#3408): inspect_web_page's allowed_origins and capture_browser_scenario's browser, start_url, actions, and capture all arrived as strings. Recover JSON text at the registered input schema's validate step, in EvidenceMcpServer.registerTool where every tool registration passes, then run the canonical parser unchanged: JSON text a string parameter accepts keeps its meaning, malformed text keeps its validation failure, and native JSON values are untouched. The recovered bag is built with object spread and Object.fromEntries so argument keys cannot pollute prototypes, and the advertised JSON Schema is spread through unchanged, so tools/list and catalog digests do not move. capture_browser_scenario's served schema contains no $ref, so inlining shared definitions would not fix the reported tools; the advertised projection is left alone for the same reason.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The reviewed changes appear safe to merge; no new actionable issue was established. SummaryRecovers object and array arguments delivered as JSON text at the MCP registration boundary, including
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["JSON-text arguments"] --> B["Decode object and array text"]
B --> C{"Decoded bag fits allowance?"}
C -- No --> D{"Original bag validates?"}
D -- Yes --> E["Keep original arguments"]
D -- No --> F["Return resource_constraint"]
C -- Yes --> G{"Decoded bag validates?"}
G -- Yes --> H["Use recovered arguments"]
G -- No --> I["Fall back to original arguments"]
I --> J["Canonical or handler-owned error"]
Reviews (12) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile |
Application-owned validators always accept (morluto#3525 review), so recovery could replace a JSON-looking string the handler would have accepted, such as a capture path named []. Contract-validated tools keep recovery; application-validated registrations pass arguments through unchanged.
|
Finding 1 addressed in 3944f0e. Root cause: Structural fix: Validation: the previous "recovers arguments on application-validated registrations" test is replaced by "keeps JSON-looking strings intact on application-validated registrations" ( |
|
Compared this PR with main The stringified-argument recovery in this PR is not on main, so it remains separate from the earlier schema-validation fixes. #3486 now records a native Claude Desktop run using compact advertisements; that is useful evidence for comparing the two approaches, rather than assuming both are needed. Please pin the actual malformed tool-call payload/client behavior that still requires recovery. Keep any conversion at the owning input boundary, preserve legitimate string values, and retain canonical validation after conversion. Public MCP cases should distinguish supported encoded objects/arrays from malformed JSON and already-valid arguments. #3408 should remain open until the affected-client behavior is established. PR head reviewed: |
|
Pinning the malformed client behavior, as requested. The recovery is not speculative — multiple real MCP clients currently deliver structured arguments as JSON text, with documented wire payloads: Pinned client behavior and payloads1. Claude Desktop 1.1.3189 — the class
That server shipped the same defensive recovery we implement here (parse 2. Claude Code, model-dependent —
Switching 3. Claude Code + OpenAI-compatible endpoints — **4. 5. opencode and Continue — How this differs from #3486's native path
Confirming the constraints you listed are already how this PR is written
On Happy to narrow the recovery surface further if you want it scoped to a specific known-bad client shape rather than the |
|
TL;DR: The fix works on my box. On current main, 2 of the 5 new tests fail. With this change, all 5 pass, and 30 older MCP tests still pass. Real CI also ran and passed. Edit (24 Oct): I re-read the new commit on c37f4a2, without running anything. The follow-up is here. Tested pull request 3525 on top of main 62bf098 (#4169). The tests use a fake in-memory MCP client. They send the argument text that a closed-source desktop chat client sends. I ran no real chat client.
Two tests fail on main. In both, the tool handler never ran, because the SDK rejected the JSON text first. They are the full-scenario case and the Three tests pass on main and after the change. They guard other behaviour. One keeps JSON text that a string parameter accepts. One keeps a path named The PR body says three tests fail on main. I saw two fail on this head. The body does not say which three, so I cannot say which one differs. The before and after is still clear. CI: the live PR shows 22 checks passed and 15 skipped. They include 5 test shards, source tests, static checks and package builds. So real CI ran and was green. Not run
Thanks, Hemang Varshney, for the fix and the clear guard tests. Test setup
CommandsThe patch applied to main with small offsets and no rejects. The test hunk was skipped because the test file was already in place. 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Thanks for the independent run — the 2-fail/3-pass split you measured is correct, and I've corrected the PR body accordingly: it said "the three recovery tests fail" on main, but the suite is 2 recovery tests + 3 guard tests, and exactly the 2 recovery tests fail pre-change. I re-verified on a clean origin/main worktree with only the test file added: Your "Not run" list is accurate about the remaining gaps: no real chat client here either — recovery is verified through the same style of in-memory MCP client sending the reported wire values, and the original report was Windows. |
|
TL;DR: I read the new commit c37f4a2 and ran nothing. It fixes a gap my first test did not reach: tools that check their own input now get the JSON-text recovery too. GitHub's CI is green on this commit, but the PR conflicts with main, because main rebuilt the same helper on 22 Oct. Edit (7 Nov): I ran the tests at 11faa18 and on main in a VM, and the results are here.
Conflict with main. GitHub says this PR conflicts with main aba487e. Main commit cdd718f removed Bot threads. Both review threads are resolved. None is open. CI scope. GitHub's run tested this commit merged into main f85a932 (17 Oct), not into today's main. Still not run
Thanks, Hemang Varshney, for the follow-up commit and the two new guard tests. What I read
Test setup🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
Main moved the MCP registration boundary into EvidenceMcpServerCore and replaced applicationValidatedInputSchema with applicationToolRegistrationOptions. Port argument recovery to both boundaries and keep the regression tests on the new API.
|
Thanks for the independent verification and for flagging the conflict. I merged |
Returning the canonical validator result directly avoids an extra microtask when no argument text is recovered, preserving deferred-call ordering and request metadata.
|
CI is green after the port: Source tests, all 8 shards, and Greptile pass. One CI run caught a deferred-registration ordering regression from the async wrapper. Fixed by returning the canonical validator result directly for native arguments, with |
# Conflicts: # experiments/analysis-efficiency/source-to-bundle.mjs # src/contracts/toolOutputSchemaGroups.ts # src/domain/explicitSensitiveFailure.test.ts # src/ida/IdaProvider.ts # src/server/EvidenceMcpServerCore.ts # tests/boundary/mcp/enhancedTools.04-uses-complete-inventories-inline.test.ts
|
TL;DR: The 7 tests pass at 11faa18 on Node 22, 24 and 26. On today's main, the 3 recovery tests fail and the 4 guard tests pass, as the PR body says. So the fix is still needed. Edit (11 Nov): I ran the new head, 99e2503, in a VM, and the results are here. Thanks, hemv-857, for the port and the re-sync. My last comment above was a read with two items that needed a run. This is that run, in a VM.
The 3 that fail on main are the recovery tests. They cover JSON text from a client, an array on GitHub shows the branch mergeable. CI passed on this head, including Static checks, Source tests and all 8 test shards. Not run
Test setupCommandsnpm ci --offline
npm run test:prepare
npm run test:focused -- tests/boundary/mcp/stringifiedStructuredArguments.test.ts
# main: the same, after copying that one test file from 11faa18012 into a main 015a02d57b tree🤖 Written and tested with Claude Code (Opus 5.5), posted with my OK 🦊 |
JSON text recovered after the SDK's admission check bypassed REA_MCP_MAX_INPUT_ELEMENTS, so a 16-element array encoded as text reached the canonical parser while the same native array was refused. Count the recovered bag with the SDK's element semantics before canonical validation in both registration paths and throw the SDK's refusal text so delivery keeps the typed resource_constraint error. Pair a rejected recovered bag with the issues it produced so invalid_type diagnostics walk the rejected structure instead of reporting supplied fields as missing. Cover native and JSON-text boundaries for canonical and application registrations, the supplied-field diagnostic, and the named contract families the focused suite exercises.
…structured-arguments # Conflicts: # src/server/toolRegistrationOptions.ts
|
Thanks for the independent run, @CassieFox23 — the branch-vs-main comparison is exactly the check that matters here. Since
The focused suite is 10 tests at this head. The caveats from your run still apply: no real chat client and no Windows verification. |
|
TL;DR: I ran the one test file this PR changed on head 99e2503. The test file passed on Node 22.23.4, 24.22.1 and 26.12.1, with 10 of 10 tests each time. The CI workflows Edit (20 Nov): I ran the new head, 89fe2e6, in a VM, and the results are here.
Not run
Test setupCommandsnpm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- tests/boundary/mcp/stringifiedStructuredArguments.test.ts🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
Friendly pingFix: Claude Desktop delivers array/object tool arguments as JSON text, so structured parameters failed SDK input validation before reaching handlers. Status: branch checked out (, head Ready for your review/approval to merge — flagging nothing further from my side unless you see an issue. |
…structured-arguments
|
Synced the branch with current Verification on
All four Greptile threads remain resolved with the fix in |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
…08-stringified-structured-arguments Resolve src/server/EvidenceMcpServerCore.ts: keep the compact advertised-input presentation via EvidenceMcpServerCore.presentInput and layer the stringified structured arguments recovery (acceptStringifiedStructuredArguments) on top of the recovered input schema before canonical validation and capture. Signed-off-by: Hemang Varshney <[email protected]>
Address Greptile review findings on the stringified structured arguments work (morluto#3525): 1. Discovery (REA_MCP_TOOL_CATALOG_PROFILE=hot-cold) still rejected JSON-text structured names (discover_tools) because the progressive catalog registration bypassed the registerTool recovery override. Apply the same stringified-arguments recovery and decoded-input guard to the discover_tools registration. 2. The element allowance refused the decoded argument bag before the caller's original arguments could be considered. When the decoded candidate exceeds the allowance, keep the original arguments when the validator accepts them, and refuse only when it does not. Verified locally: typecheck clean; tests/boundary/mcp/stringifiedStructuredArguments 10/10; related compact/admission/schema suites pass (2 pre-existing environmental stdio failures). Signed-off-by: Hemang Varshney <[email protected]>
Signed-off-by: Hemang Varshney <[email protected]>
Follow main's shared MCP test-client validation (morluto#10960): the architecture guard rejects a default-validating SDK client in tests. Pass createMcpSchemaValidation through the client, matching the other MCP boundary suites. Signed-off-by: Hemang Varshney <[email protected]>
… allowance Greptile found that a string parameter carrying JSON text larger than the input allowance was refused as resource_constraint even though the original bag satisfied the contract. The over-limit fallback compared parsed object identity, which canonical Zod validation never preserves, so it never kept the caller's arguments. Keep the original bag when the canonical parser accepts it, and refuse without canonicalizing the oversized decoded candidate otherwise. The application wrapper accepts every request, so retain its underlying contract validator and consult that for the original bag. Verified locally: typecheck clean; stringifiedStructuredArguments 12/12; related MCP schema suites 33/33; architecture guards pass. Signed-off-by: Hemang Varshney <[email protected]>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Ready for review. Greptile passes and every review thread is resolved. The only failing required lane is |
Signed-off-by: Hemang Varshney <[email protected]>
|
TL;DR: On head 89fe2e6, all 12 tests in Findings
The red run swaps
The PR changes 3 files against the merge base. Those are the two source files above and the test file. CI on the head, read live with
Not run
Test setupCommandsnpm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- tests/boundary/mcp/stringifiedStructuredArguments.test.ts🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
|
Thank you for working on this Claude Desktop compatibility fix! The linked issue #3408 was closed as completed on |
Summary
Fixes #3408.
Claude Desktop delivers array and object tool arguments as JSON text, so every structured parameter of every tool failed SDK input validation before reaching its handler. Recover JSON text at the registered input schema's validation step in
EvidenceMcpServerCore.registerTool, then let the canonical parser decide the result unchanged.Problem and expected behavior
Smallest trigger:
tools/callforinspect_web_pagewithallowed_originssupplied as'["https://example.com"]', orcapture_browser_scenariowithbrowser,start_url,actions, andcapturesupplied as JSON text. Violated invariant: a structured parameter whose supplied value is valid JSON text for that parameter's schema should be validated as that structure instead of being rejected as a string.Reported before this change (REA 6.4.0, Claude Desktop 2.37337.1 on Windows 11):
Input validation error: Invalid arguments for tool inspect_web_page: Invalid inputbrowser: Invalid input: expected object, received string, start_url: Invalid input: expected object, received string, actions: Invalid input: expected array, received string, capture: Invalid input: expected object, received stringString-only parameters keep working, so the failure is partial and reads as missing data:
inspect_web_pagewithoutallowed_originssucceeds and reports third-party resources asdisallowed_origin.Change and scope
EvidenceMcpServerCore.registerTool, where every MCP tool registration passes, wraps each registered input schema's Standard SchemavalidatewithacceptStringifiedStructuredArguments(src/server/toolRegistrationOptions.ts). For each top-level string argument that starts with{or[and parses as a JSON object or array, the parsed bag is validated first. If that fails but the caller's original bag validates (JSON text a string parameter accepts), the original is kept. If both fail, the parsed form's content-level issues are reported. Native JSON values never take this path and pass straight to the canonical validator without an extra async hop, so deferred-call ordering and request metadata stay unchanged; the advertised JSON Schema projection is spread through unchanged. Application-owned validators (vendor: "rea-application"fromapplicationToolRegistrationOptions) recover through the same shared bag-merge helper inside their own wrapper: the canonical parser chooses between the recovered bag and the caller's original, the wrapper returns only client-supplied bags (never the canonical parser's parsed output, so application-owned parsing stays in the handler), and when neither bag satisfies the canonical parser the handler receives the caller's original arguments — a capture path named[]keeps its string, whilerecord_ordinals: "[0]"recovers to the array.Intentionally not included:
$ref/$defs.capture_browser_scenario's served schema contains no$refat all (browserisoneOf,start_urlandcaptureareobject,actionsisarray) and still received strings, so inlining would not fix the reported tools, and changing the advertised projection would movetools_sha256.Contribution scope: ordinary fix within the existing MCP boundary. No target execution, injection, mutation, or protection recovery, so no maintainer scope decision is required.
Contract and boundary impact
validatestep; the canonical contract parser stays the semantic owner of validation.tools/listand catalog digests unchanged;tools/callaccepts JSON text where the contract expects an object or array and still rejects everything the contract rejected before.docs/public/product-catalog.json), package, or installation impact: none. No contract or example edits, so regenerated catalogs are unchanged.Expected effects:
No listed target effect is introduced: this change normalizes MCP argument delivery only. Unchecked items do not establish absence.
Evidence and regression coverage
Tests added or updated:
tests/boundary/mcp/stringifiedStructuredArguments.test.ts(12 tests) covering recovery of a fully stringifiedcapture_browser_scenarioexample, recovery ofinspect_web_page.allowed_origins, preservation of JSON text in a string parameter, preservation of a JSON-looking string (capture_path: "[]") on an application-validated registration, recovery of structured text on an application-validated registration (record_ordinals: "[0]"), preservation of the caller's original arguments when neither bag satisfies the canonical parser, and continued rejection of malformed structured text.Base reproduction: the pre-port head
c37f4a2had the same split, with the three recovery tests failing on unmodifiedorigin/main(the handler never ran on the contract tools; application-owned registrations never recovered) and the four guard tests passing. This merge only moves the recovery boundary to main's new core registration and application helper; with the change, all seven pass.User-visible CLI/MCP output: the reported
Input validation error: Invalid arguments for tool ...results become ordinary tool results of the recovered call. Real browser output was not captured here; the recovery boundary is covered by the in-memory MCP client tests above.Remaining proof gaps: Claude Desktop itself was not run (Windows/Electron unavailable in this environment). Recovery is verified through an in-memory MCP client sending exactly the reported wire values. Upstream stringification cases that do not arrive as JSON text ([BUG] Claude Desktop - Code - MCP InputSchema with nullable arrays has type silently dropped anthropics/claude-code#58747 type stripping) are not recoverable server-side.
Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npx vitest run tests/boundary/mcp/stringifiedStructuredArguments.test.ts— 12 passed, including two allowance regressions for JSON text in string parameters.src/server/DeferredEvidenceMcpServer.test.tsplus the stringified suite — 19 passed, covering both recovery and request-metadata ordering during deferred registration.npm run test:focusedover stringifiedStructuredArguments, EvidenceMcpServer, toolInputAdmission, toolSchemaValidity, compactInputSchemaMcp, browserComparisonInput, outputValidatorReuse — 43 passed, 3 failed; all three are the same catalog tests exceeding the 30 s test timeout under load (59 s, 47 s, 40 s).toolSchemaValiditypasses 14/16 andcompactInputSchemaMcp12/13 in isolation, with the same timeout; the three tests are environmental on this machine.npx vitest runover compactInputSchemaMcp, browserComparisonInput, toolInputAdmission, toolSchemaValidity and outputValidatorReuse — 33 passed.npm run check:fast— passed (typecheck and lint).npm run verify:architecture-guards— passed.npx oxfmt --check <changed files>— passed.npm run test:mcpwas not rerun after the merge; the focused MCP set above is the post-merge evidence.Greptile Review— passed; every review thread is resolved.web_network / real-web-network-captures— fails identically on unmodifiedmainatscripts/verify-web-network-captures.mjs:767(capturePathvscapture_path, run 43834020751); unrelated to this change.Compatibility, safety, and release
JSON.parseruns only on top-level string arguments that begin with{or[, inside the existing MCP request size bound, at most twice per call. The recovered bag is built with object spread andObject.fromEntries(own data properties, no[[Set]]), so__proto__argument keys cannot pollute prototypes. Recovered values pass the same canonical parser as before, and the change adds no file, process, network, or authority access.Author readiness
Human owner: @hemv-857
Before merge
type(scope): outcome.