Skip to content

fix(mcp): validate doctor probe against its discovered output contract - #1461

Merged
N0zoM1z0 merged 1 commit into
mainfrom
fix/mcp-doctor-discovered-output-validation
Oct 10, 2026
Merged

N0zoM1z0 merged 1 commit into
mainfrom
fix/mcp-doctor-discovered-output-validation

Conversation

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

The MCP doctor could report healthy: true for a binary_session reply that violated the output schema advertised by the same production server. Discover the complete tool/prompt inventory first, select the probe definition by name, and pass that definition to the SDK call. Keep the absolute deadline and owned-child cleanup.

A rejected probe now reports the request/schema failure while retaining the already observed server and inventory, rather than replacing them with an undifferentiated transport failure. The successful report and default Evidence contract remain unchanged.

Validation:

  • A committed stdio replay regression captures fresh metadata and a valid reply from the actual production server, then checks both valid and schema-invalid replies. The invalid case fails on the original main implementation and passes with this fix.
  • All nine doctor/CLI-help tests, full serial typecheck, lint, duplication gate and changed-file formatting pass under the documented two-CPU and process-family budget.
  • The actual public CLI doctor report is byte-identical (1,593 bytes). A 74-byte JavaScript target produces identical default Evidence to main through CLI and SDK stdio MCP; text/structured parity, source digest and subsequent ping pass.
  • Independent fault injection at the actual production stdio producer confirms main accepts an extra output property and the fix rejects it. This exercises the production client/server boundary; it does not certify a deep-analysis provider.

This is a diagnostic correctness fix. Interleaved cold CLI timings did not establish a speedup, and no model-token saving is claimed. The SDK internal cause of the original default-path behavior remains unverified.

Closes #1454. Refs #1065, #723, #1433.

@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.

@N0zoM1z0
N0zoM1z0 merged commit ea92328 into main Oct 10, 2026
19 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/mcp-doctor-discovered-output-validation branch October 10, 2026 06:33
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: This merged while I was testing, so this is a post-merge check. The fix works. The doctor now catches a bad probe reply. Base said "healthy" for it. Good replies give the same report as before, byte for byte. When the probe fails, head still shows the server and tool list. No test processes were left behind.

Healthy path

Real rea mcp doctor on the real server. Base vs head, compared with cmp.

Node --json (1,593 B) default toon (1,101 B) Exit
22.23.1 identical identical 0 / 0
24.18.0 identical identical 0 / 0
26.11.1 identical identical 0 / 0

I did not need to clean up any fields. There were no times, pids or paths. Stderr was empty.

Bad replies

A small stdio proxy sat in front of the real server. It changed only the binary_session reply. Same results on Nodes 22, 24 and 26.

Reply Base Head Head reason clear? Server and tools kept? Leftovers
Extra property (#1454) healthy not healthy yes yes none
Missing required field healthy not healthy yes, but long yes none
Wrong type, required field healthy not healthy yes, but long yes none
Text only, no structuredContent not healthy not healthy yes yes none
Text differs from structured healthy healthy n/a yes none
Reply never comes (30 s) not healthy not healthy yes head yes, base no none
Server exits mid-probe not healthy not healthy yes head yes, base no none
isError: true not healthy not healthy no yes none
5 MiB reply healthy healthy n/a yes none
PR fixture, invalid healthy not healthy yes yes none

Exit code was 0 when healthy and 1 when not. That held in all 72 runs.

A few small notes. None of them block this PR.

  • The long reasons come from anyOf. The first part still names the field.
  • On head, a schema reject also fails server-identity. It says "package=missing". The reply did carry the right identity. A reader might chase the wrong fault.
  • isError: true never shows the error text. Base does the same thing.
  • The doctor does not compare text to structured content. Size is not checked either. Both seem out of scope here.
  • oxlint gives one new warning on head. inspectProductionMcpSession now has complexity 22. The limit is 20. Base has no warning there.

I also found why base skipped the check. See "SDK check" below.

Cold start

Real CLI doctor, pinned to two cores. Ten runs each after two warm-ups, interleaved. Load went up to 5.6, so these are rough.

Node Base median Head median Head − base
22 3,118 ms 3,194 ms +76 ms
24 3,068 ms 3,243 ms +174 ms
26 2,242 ms 2,267 ms +25 ms

The ranges overlap on every Node. Head waits for the tool list before the probe now. A small cost fits that, but these runs can't prove it.

Tests

  • Head, Nodes 22, 24 and 26: the doctor and help tests pass, 9 of 9.
  • Base with the new test copied in: 1 of 5 fails, as it should. It reports healthy for the invalid reply.
  • Head, Node 24: tsc --noEmit passes.
  • Head, Node 24: oxlint on the three changed files has 0 errors. It has the 1 warning above.

Not run

  • check:fast and verify:*. They need git history, and my copy has none.
  • The full suite, format check and duplication gate.
  • The PR's claim about default Evidence on a JS target. This diff does not touch that path.
  • A child that ignores SIGTERM. That cleanup code did not change.
  • The base negative test on Nodes 22 and 26. I ran it on 24 only.

Thanks N0zoM1z0 for the clear issue and the replay fixture.

How the bad replies were made
  • The doctor runs from each tree's dist/mcpDoctor.js through runProductionMcpDoctor.
  • Its child is a stdio proxy. The proxy starts node <tree>/scripts/rea.mjs mcp.
  • Only the binary_session reply is changed.
  • Missing field: result.capabilities removed.
  • Wrong type: result.open set to the string "false".
  • Extra, missing and wrong type keep the text in sync with the new structured content.
  • Text differs: structured is valid, text says open: true.
  • Never: the reply is dropped. The default 30 s deadline applies.
  • Server exit: the proxy kills the server when the probe arrives.
  • isError: the reply becomes one text item with isError: true.
  • 5 MiB: one extra text item of 5 MiB. The rest stays valid.
  • The doctor owns the proxy. The real server is a grandchild.
  • The proxy kills its server on SIGTERM or stdin close. So part of the server cleanup is the proxy's work.
  • The fixture rows have no grandchild. They were clean too, which is the cleaner proof.
  • Leftovers: ps checked for the proxy, server and fixture after each run.
  • 72 runs in total. Zero leftovers.
Head reasons, word for word (Node 24)
  • Extra: Structured content does not match the tool's output schema: data must NOT have additional properties
  • Missing: ... data/result must have required property 'capabilities', ... and 9 more anyOf lines
  • Wrong type: ... data/result/open must be boolean, ... and 10 more anyOf lines
  • Text only: Tool binary_session has an output schema but did not return structured content
  • Never: Error: Production MCP doctor deadline expired (base: same text, under transport, with server: null)
  • Server exit: Connection closed (base: same text, under transport, with server: null)
  • isError: binary_session target-free request with ok: false

Never took 30.0 to 30.3 s on both trees.

SDK check

The issue left the SDK cause open. I think I found it. The SDK picks its output check when callTool starts. It takes it from the cached tools/list. On base, the probe ran beside listTools. So no list was cached yet, and no check ran. I tried the base tree with the list first, then the call. The SDK then rejected the bad reply.

  • SDK file: @modelcontextprotocol/client 2.3.1, dist/index.mjs, line 4244.
  • callTool gets its validator from options.toolDefinition if given.
  • If not, it reads the cached tools/list when the call starts.
  • Base tree, proxy adds one extra property, no toolDefinition:
    • listTools and callTool together: accepted.
    • listTools first, then callTool: rejected, data must NOT have additional properties.
Cold start raw
Node Base min–max Head min–max
22 2,868–4,170 ms 3,018–4,170 ms
24 2,968–3,368 ms 2,567–3,469 ms
26 2,167–2,267 ms 2,217–2,418 ms
  • Command: taskset -c 2,3 node scripts/rea.mjs mcp doctor --json
  • Clean env, nice -n 10, all runs exit 0.
  • Order switched each pair.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 946bde7d / 1ec490f3 (the head commit's parent), merged as ea923287
  • MCP SDK: @modelcontextprotocol/client 2.3.1
  • Built with npm ci and npm run build:cached on Node 24.18.0

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
morluto#1461)

Validate the target-free probe against the named definition discovered from the complete production catalog. Preserve initialized server and inventory observations when the SDK rejects the probe, and retain the schema failure reason, absolute deadline and owned-child cleanup.

The negative stdio replay regression fails on original main and passes the fix; actual production-boundary fault injection confirms rejection. Nine doctor/help tests, serial full static checks and real small-target CLI/MCP parity pass. Successful doctor reports remain byte-identical. No performance or model-token reduction is claimed.

Closes morluto#1454. Refs morluto#1065, morluto#723, morluto#1433.
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: mcp MCP server, transport, and tool registration label Nov 23, 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 area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MCP doctor reports healthy for a schema-invalid probe reply

3 participants