Skip to content

fix(mcp): recover structured tool arguments clients serialize as JSON text - #3525

Closed
hemv-857 wants to merge 16 commits into
morluto:mainfrom
hemv-857:fix-3408-stringified-structured-arguments
Closed

hemv-857 wants to merge 16 commits into
morluto:mainfrom
hemv-857:fix-3408-stringified-structured-arguments

Conversation

@hemv-857

@hemv-857 hemv-857 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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/call for inspect_web_page with allowed_origins supplied as '["https://example.com"]', or capture_browser_scenario with browser, start_url, actions, and capture supplied 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 input
  • browser: 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 string

String-only parameters keep working, so the failure is partial and reads as missing data: inspect_web_page without allowed_origins succeeds and reports third-party resources as disallowed_origin.

Change and scope

EvidenceMcpServerCore.registerTool, where every MCP tool registration passes, wraps each registered input schema's Standard Schema validate with acceptStringifiedStructuredArguments (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" from applicationToolRegistrationOptions) 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, while record_ordinals: "[0]" recovers to the array.

Intentionally not included:

  • Rewriting the advertised schemas. The issue proposes inlining $ref/$defs. capture_browser_scenario's served schema contains no $ref at all (browser is oneOf, start_url and capture are object, actions is array) and still received strings, so inlining would not fix the reported tools, and changing the advertised projection would move tools_sha256.
  • Per-key recovery. Recovery applies to the argument bag as a whole, so a call that mixes recovered structured arguments with JSON text that a string parameter accepts keeps its pre-change rejection.
  • Number-typed parameters delivered as numeric text; the report covers arrays and objects only.

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

  • Semantic owner and earliest changed stage: the MCP adapter owns argument recovery at the input schema's validate step; the canonical contract parser stays the semantic owner of validation.
  • Contribution scope fit and linked maintainer decision: not applicable; ordinary fix within existing boundaries.
  • CLI and MCP/tool-catalog contract: tools/list and catalog digests unchanged; tools/call accepts JSON text where the contract expects an object or array and still rejects everything the contract rejected before.
  • Provider, bridge, target-format, or platform compatibility: client-side serialization quirk reported on Claude Desktop/Windows; no provider or platform code changes.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. Recovered arguments pass the same canonical parser as native JSON values, so downstream handlers and Evidence see the same shapes.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata (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 stringified capture_browser_scenario example, recovery of inspect_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 c37f4a2 had the same split, with the three recovery tests failing on unmodified origin/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.ts plus the stringified suite — 19 passed, covering both recovery and request-metadata ordering during deferred registration.
  • npm run test:focused over 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). toolSchemaValidity passes 14/16 and compactInputSchemaMcp 12/13 in isolation, with the same timeout; the three tests are environmental on this machine.
  • npx vitest run over 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.
  • Full npm run test:mcp was 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 unmodified main at scripts/verify-web-network-captures.mjs:767 (capturePath vs capture_path, run 43834020751); unrelated to this change.
  • Real Hopper/Ghidra, browser, or OS provider verification: not applicable to this boundary; the browser tools are exercised through their contract validation, not a live CDP session.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Calls that failed validation before now succeed only when the supplied JSON text satisfies the same contract.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no target interaction introduced.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: JSON.parse runs 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 and Object.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

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed — none required; no contract, docs, or generated metadata changes.
  • User-visible CLI/MCP changes include representative output — the reported rejection messages are quoted above; recovered calls return ordinary tool results.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

… 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.
@hemv-857
hemv-857 marked this pull request as ready for review October 14, 2026 16:35
Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:35
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no new actionable issue was established.

Summary

Recovers object and array arguments delivered as JSON text at the MCP registration boundary, including discover_tools.

  • MCP tools accept structured arguments that clients send as JSON text.

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"]
Loading

Reviews (12) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

Comment thread src/server/toolRegistrationOptions.ts Resolved
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.
@hemv-857

Copy link
Copy Markdown
Contributor Author

Finding 1 addressed in 3944f0e.

Root cause: applicationValidatedInputSchema replaces the canonical validator with an always-accept passthrough (vendor: "rea-application"), so the recovered bag could never fail validation there — a JSON-looking string the handler would have accepted (e.g. a capture path named []`) was replaced by its parsed structure and rejected downstream.

Structural fix: acceptStringifiedStructuredArguments now returns application-owned schemas unchanged; only contract-validated registrations recover. The handler keeps owning application-owned input failures, unchanged.

Validation: the previous "recovers arguments on application-validated registrations" test is replaced by "keeps JSON-looking strings intact on application-validated registrations" (path: "[]" reaches the handler as the string). The three contract recovery tests and the malformed-text rejection test still pass; the full npm run test:mcp shows only the pre-existing environmental timeouts (serverIdentity/sessionMcp reproduce on unmodified origin/main; contractPresentation and artifactMcp.inlineInventory pass in isolation).

Comment thread src/server/toolRegistrationOptions.ts Resolved
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Compared this PR with main fc712b375 during the fixed/superseded backlog audit.

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: 3944f0e53. This is a source comparison; no new PR-branch tests or provider runs were performed for this comment.

@hemv-857

Copy link
Copy Markdown
Contributor Author

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 payloads

1. Claude Desktop 1.1.3189 — the class czlonkowski/n8n-mcp#605 filed against, with a confirmed payload:

Instead of {"workflow": {"nodes": [...], "connections": {...}}}
it sends {"workflow": "{\"nodes\": [...], \"connections\": {...}}"}

That server shipped the same defensive recovery we implement here (parse {\"/[`-prefixed strings that yield objects; keep anything else as-is) as its workaround.

2. Claude Code, model-dependent — anthropics/claude-code#23500 shows Opus 4.6 serializing a oneOf(object, string) parameter as a string while Opus 4.5 passes the object, with the live tool call:

move_swarm (MCP)(swarm_id: "swarm_1_1", destination: "{\"x\": 120, \"y\": 400}", path_preference: "fastest")

Switching /model mid-session toggles the behavior; the client code path is identical, so this is model-output-level, not transport-level — no client-side advertisement fix can reach it.

3. Claude Code + OpenAI-compatible endpoints — anthropics/claude-code#16018: with GLM models, execute_workflow sends inputs as a JSON string and the server rejects Expected object, received string at ["inputs"].

**4. -bearing schemas, any client** — `modelcontextprotocol/typescript-sdk#1562`: when a tool's `inputSchema` contains /(from Zod v4 `z.globalRegistry`/`z.lazy`), LLMs cannot resolve the pointer and serialize the field as a string literal: `expected: {"database_id": "…"}, received: "{\"database_id\":\"…\"}"`. Same root cause documented on the Python SDK (`python-sdk#2448`). `anthropics/claude-code#20732` shows the identical failure via Notion MCP's/oneOf parameters.

5. opencode and Continue — anomalyco/opencode#28472 (Expected object, received string on body: object parameters) and continuedev/continue#8510 (fixed by coercing args to match schema, continue#11852).

How this differs from #3486's native path

#3486 fixes the advertisement/compaction shape on the native Claude Desktop run. The payloads above are produced at the model-output layer (oneOf/$ref schemas, model version) and by other clients entirely (opencode, Continue, Claude Code+GLM) — a native advertisement fix does not reach them. Both are real; they are separate producers of the same malformed shape.

Confirming the constraints you listed are already how this PR is written

  • Conversion stays at the owning boundary: recovery wraps only the canonical Zod validator at the MCP tools/call input boundary (acceptStringifiedStructuredArguments in toolRegistrationOptions). Nothing in handlers or result paths converts.
  • Legitimate string values preserved: only strings starting with { or [ are candidates; JSON.parse must yield an object/array or the original string is kept; non-JSON text a string parameter accepts is untouched and still reaches the validator as the caller's value.
  • Canonical validation retained after conversion: recovered values are re-validated by the same canonical parser — malformed text keeps its validation failure, and a call mixing a recovered structured argument with JSON text a string parameter accepts still fails as it does today.
  • Application-owned validators excluded: vendor === "rea-application" passthroughs are skipped, since they always accept and recovery could replace a JSON-looking string the handler would have taken as-is.

On #3408 staying open until affected-client behavior is established: the evidence above establishes it against current, shipped clients with reproducible payloads — n8n-mcp#605 (Claude Desktop 1.1.3189), claude-code#23500 (Opus 4.6), claude-code#16018 (GLM), typescript-sdk#1562 (`` schemas, any client). I cannot capture a live Claude Desktop payload from my machine (no runtime here), which is why the PR body's test plan is boundary-level: the stringifiedStructuredArguments suite drives the exact wire shape through `InMemoryTransport`.

Happy to narrow the recovery surface further if you want it scoped to a specific known-bad client shape rather than the {/[-object/array class.

@CassieFox23

CassieFox23 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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.

Run Files Result
Before: main plus the PR's new test the new test file 2 failed, 3 passed
Before: main, 6 older MCP files see Commands 30 passed
After: main plus the PR's change all 7 files 35 passed, 0 failed

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 allowed_origins case.

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 [] on a tool the application checks. One still rejects bad structured text.

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

  • The real chat client. Only a fake in-memory client sent the text.
  • The full MCP suite (npm run test:mcp) and any other test file. The brief bars whole suites on this box.
  • rea doctor. None of the 7 files call it (checked with grep).
  • Windows, the platform where the author saw the bug.

Thanks, Hemang Varshney, for the fix and the clear guard tests.

Test setup
Commands
# before: main tree, new test copied from the PR head
git show 3944f0e53:tests/boundary/mcp/stringifiedStructuredArguments.test.ts > tests/boundary/mcp/stringifiedStructuredArguments.test.ts
npm run test:focused -- tests/boundary/mcp/stringifiedStructuredArguments.test.ts \
  src/server/EvidenceMcpServer.test.ts \
  tests/boundary/mcp/toolInputAdmission.test.ts \
  tests/boundary/mcp/toolSchemaValidity.test.ts \
  tests/boundary/mcp/compactInputSchemaMcp.test.ts \
  tests/boundary/mcp/browserComparisonInput.test.ts \
  tests/boundary/mcp/outputValidatorReuse.test.ts
# exit 1, 2 failed | 33 passed

# after: apply the PR's diff (merge-base to head) with patch -p1 -N, same command
# exit 0, 35 passed

The 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) 🦊

@hemv-857

Copy link
Copy Markdown
Contributor Author

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: recovers structured arguments a client delivered as JSON text and recovers an array argument on inspect_web_page fail; the 3 guards pass — matching your table. The pre-change failure mode is the one described (SDK validation rejects the JSON text before the handler runs).

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.

@CassieFox23

CassieFox23 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

My earlier result, on 3944f0e Now, on c37f4a2 What I read
My 5 new tests: 2 fail on main, all 5 pass with the PR needs a run The new commit changes toolRegistrationOptions.ts and adds 2 tests, so the file now holds 7. My numbers belong to the old commit.
Gap in my result: I did not cover tools that check their own input addressed (read) On 3944f0e those tools skipped recovery, so record_ordinals: "[0]" on inspect_web_network_capture reached the handler as text (Greptile's thread, now resolved). The wrapper now recovers the text when the canonical schema accepts the recovered arguments. Otherwise the handler gets the caller's original arguments.
The PR body said 3 tests fail on main. I saw 2. addressed in the text, count needs a run The body now says the 3 recovery tests fail and the 4 guard tests pass. That adds up to the 7 tests in the file. I did not run it.
Real CI ran and was green: 22 checks passed, 15 skipped still green On c37f4a2 GitHub shows 21 passed, 16 skipped, 0 failed, and CI required passed. The job log shows stringifiedStructuredArguments.test.ts with 7 tests passing. I did not look into the one-check difference from my earlier 22 and 15.

Conflict with main. GitHub says this PR conflicts with main aba487e. Main commit cdd718f removed applicationValidatedInputSchema and added applicationToolRegistrationOptions in the same file. 26 files on main now mention that new name. EvidenceMcpServer.ts also changed a lot on main. A text merge of the PR's files gives 3 conflicts: 2 in EvidenceMcpServer.ts and 1 in toolRegistrationOptions.ts. The test file merges clean. This is a text check, not a build.

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

  • Nothing was built or run this time. This is a read of the diff and of GitHub's check list.
  • Whether the 7 tests pass, and whether the 3 recovery tests fail on main.
  • A real chat client. Only a fake in-memory client sent the text, as before.
  • The full MCP suite (npm run test:mcp). The body says 6 tests there time out in the author's workspace. I did not check that.
  • Windows, where the author saw the bug.
  • How the recovery wrapper behaves once it is moved onto main's new helper.

Thanks, Hemang Varshney, for the follow-up commit and the two new guard tests.

What I read
  • The wrapper is applicationValidatedInputSchema, lines 9-32. It builds the shared recoveredArgumentBag from the caller's arguments. The canonical parser has to accept the recovered arguments first. Only then does the wrapper return them. In every other case it returns the caller's original arguments.
  • The same helper now serves the contract path, acceptStringifiedStructuredArguments. The logic there reads the same as before.
  • Four register files wrap their schema with it:
    • the analysis view
    • investigation
    • pcap
    • web network capture tools
  • The 2 new tests send record_ordinals: "[0]" and record_ordinals: '{"0":0}' through a registration that the application validates. The first expects [0] at the handler. The second expects the original string.
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.
@hemv-857

Copy link
Copy Markdown
Contributor Author

Thanks for the independent verification and for flagging the conflict.

I merged origin/main (8e6a95788), ported the recovery boundary to EvidenceMcpServerCore.registerTool and applicationToolRegistrationOptions, and reran the focused suite: 7/7 passed. The three recovery tests and four guard tests are unchanged; the PR body now reflects the port and the current validation runs.

Returning the canonical validator result directly avoids an extra
microtask when no argument text is recovered, preserving deferred-call
ordering and request metadata.
@hemv-857

Copy link
Copy Markdown
Contributor Author

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 DeferredEvidenceMcpServer coverage added to the local runs. Thanks again for the independent check.

# 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
Comment thread src/server/toolRegistrationOptions.ts Resolved
Comment thread src/server/toolRegistrationOptions.ts Resolved
@CassieFox23

CassieFox23 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
stringifiedStructuredArguments.test.ts at 11faa18 (7 tests) 7 pass 7 pass 7 pass
Same file copied onto main 015a02d 3 fail, 4 pass 3 fail, 4 pass 3 fail, 4 pass

The 3 that fail on main are the recovery tests. They cover JSON text from a client, an array on inspect_web_page, and tools that check their own input.

GitHub shows the branch mergeable. CI passed on this head, including Static checks, Source tests and all 8 test shards.

Not run

  • A real chat client. The test uses a fake in-memory client.
  • Windows, where the bug was seen.
  • The full MCP suite.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB), Linux 7.2.11, on my Nobara 44 PC
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / main: 11faa18 / 015a02d
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, both exit 0, for each tree
Commands
npm 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
@hemv-857

Copy link
Copy Markdown
Contributor Author

Thanks for the independent run, @CassieFox23 — the branch-vs-main comparison is exactly the check that matters here.

Since 11faa180, Greptile raised four findings. All are fixed and CI is green again on 99e25038 (today's main merged; Static checks, Source tests, and all 8 shards pass):

  1. Capacity: JSON-text arguments are now charged against maxToolInputElements before canonical validation in both registration paths. At a limit of 8, the native 7-element array is accepted, while native 16 and JSON-text 16 are both refused with resource_constraint; JSON-text 16 was previously accepted with all 16 values.
  2. Diagnostics: a rejected recovered bag is paired with the issues it produced, so a supplied duration_ms reports invalid_type instead of missing_argument.
  3. Focused imports: the suite imports only the browser and web-network contract families it exercises.
  4. Error assertions: rejection tests now assert typed codes and structured issue facts through parseMcpToolError rather than prose.

The focused suite is 10 tests at this head. The caveats from your run still apply: no real chat client and no Windows verification.

@CassieFox23

CassieFox23 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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 CI, PR readiness and PR title show completed/success on head 99e2503.

Edit (20 Nov): I ran the new head, 89fe2e6, in a VM, and the results are here.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
tests/boundary/mcp/stringifiedStructuredArguments.test.ts pass: 1/1 file, 10/10 tests pass: 1/1 file, 10/10 tests pass: 1/1 file, 10/10 tests
  • Against the merge base, the PR changes 3 files: src/server/EvidenceMcpServerCore.ts, src/server/toolRegistrationOptions.ts and the test file. I ran only the test file.
  • GitHub shows mergeable true, state clean, and not a draft.
  • CodeQL production is completed/skipped.
  • The check runs split into 23 success and 23 skipped.
  • The successes include Static checks, Source tests, CI required and Test shard (1/8) through Test shard (8/8).
  • The PR readiness commit status is success.
  • The head is 956 commits behind main dcdae13.

Not run

  • I did not test the real chat client or Windows-specific behavior. The focused test file would not cover either one.
  • A probe that sends a large JSON string in a string parameter could catch a capacity refusal regression. It would cover toolRegistrationOptions.ts:~178 and :~125. I did not run one.
  • A merge with current main, dcdae13.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 99e2503 / 5336316 (merge base with main)
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm 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 🦊

@hemv-857

hemv-857 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Friendly ping

Fix: fix(mcp): recover structured tool arguments clients serialize as JSON text — Fixes #3408.

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 99e250384), merge state CLEAN / MERGEABLE, not draft, required checks green (CI required, Conventional PR title, Portable tests, Static checks).

Ready for your review/approval to merge — flagging nothing further from my side unless you see an issue.

@morluto

@hemv-857

Copy link
Copy Markdown
Contributor Author

Synced the branch with current main (653c49419, 986 commits since the last sync). The merge was clean — the PR still contains only its three files (EvidenceMcpServerCore.ts, toolRegistrationOptions.ts, and the boundary test), and the #3408 recovery behavior is unchanged on top of main's new registration/progressive-catalog work.

Verification on e5d551288:

  • tests/boundary/mcp/stringifiedStructuredArguments.test.ts — 10/10 pass
  • the 14 registration/recovery-adjacent boundary suites — 129/129 pass
  • npm run check:fast (typecheck + lint) and format:check clean locally
  • CI: Build package, Source tests, Static checks, and all 8 test shards green (24 pass / 23 path-conditional skips / 0 failing)

All four Greptile threads remain resolved with the fix in 9337d252. Ready for re-review whenever you have a moment.

Comment thread src/server/toolRegistrationOptions.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

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]>
Comment thread src/server/EvidenceMcpServerCore.ts Resolved
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]>
@hemv-857
hemv-857 marked this pull request as draft November 15, 2026 17:47
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]>
@hemv-857
hemv-857 marked this pull request as ready for review November 16, 2026 09:52
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-16T09:52:58.529352Z
We couldn’t complete this review. Comment @codex review to try again.
81a1bc0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@hemv-857

Copy link
Copy Markdown
Contributor Author

Ready for review. Greptile passes and every review thread is resolved.

The only failing required lane is web_network / real-web-network-captures. It fails identically on unmodified main at scripts/verify-web-network-captures.mjs:767 (capturePath vs capture_path, main run 43834020751), and this change does not touch that capture-verification path. CI required aggregates that lane, so it stays red until the upstream failure is fixed. Everything else is green, including the focused stringified-argument suite (12/12), related MCP schema suites (33/33), typecheck, architecture guards and Portable tests.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On head 89fe2e6, all 12 tests in tests/boundary/mcp/stringifiedStructuredArguments.test.ts pass on three Node versions. With the two source files put back to the merge base, 6 of those 12 fail. The head is 823 commits behind main 3e3faf2, and I did not test a merge with it.

Findings

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 89fe2e6 pass: 12 of 12 tests, 1 of 1 file pass: 12 of 12 tests, 1 of 1 file pass: 12 of 12 tests, 1 of 1 file
Red run (source files from 552d1c7) fail: 6 failed, 6 passed, 1 of 1 file failed fail: 6 failed, 6 passed, 1 of 1 file failed fail: 6 failed, 6 passed, 1 of 1 file failed

The red run swaps src/server/EvidenceMcpServerCore.ts and src/server/toolRegistrationOptions.ts back to the merge base. The same six tests fail on all three Node versions. The names below come from the Node 24.22.1 log:

  • stringified argument admission and diagnostics > charges JSON-text arrays against the selected element allowance
  • stringified argument admission and diagnostics > charges JSON-text arrays on application-validated registrations
  • stringified argument allowance keeps valid caller bags > reports recovered-field failures against the rejected structure
  • stringified structured tool arguments > recovers an array argument on inspect_web_page
  • stringified structured tool arguments > recovers structured arguments a client delivered as JSON text
  • stringified structured tool arguments > recovers structured arguments on application-validated registrations

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 gh: the PR is mergeable, state clean, not a draft.

  • Workflow runs: CI is completed/success, PR readiness is completed/success, and PR title is completed/success. CodeQL production is completed/skipped.
  • Check runs: 16 are success and 24 are skipped.
  • Among the success ones are CI required, Build package, Portable tests, Static checks, Test shard (1/1), Conventional PR title, Greptile Review and web_network / real-web-network-captures.
  • Source tests is skipped.

Not run

  • A call with a JSON-text string field over the limit, to an app-registered tool. It would take the inline-evidence branch. A test for an app allowance over the limit passed. I did not check which branch it takes.
  • A merge with current main, 3e3faf2.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB, Linux 7.2.11) on my Nobara 44 PC
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 89fe2e6 / 552d1c7 (merge base with main)
  • Red run: 89fe2e6 with the changed source files from 552d1c7
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm 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 🦊

@morluto morluto added area: mcp MCP server, transport, and tool registration bug Something isn't working labels Nov 23, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for working on this Claude Desktop compatibility fix! The linked issue #3408 was closed as completed on main via commits 4126698407 (#10632) and 5c53bcaed8 (#10693), which retired the "full" input schema profile and enforced inlined compact input schemas without $ref/$defs so clients no longer serialize structured parameters as JSON text. Closing as superseded by that schema fix.

@morluto morluto closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array and object tool parameters rejected when REA runs as a local MCP server in Claude Desktop (Windows)

5 participants