Skip to content

fix(server): serve malformed legacy bodies through the legacy transport - #1202

Open
e5l wants to merge 4 commits into
devcrocod/sep-2575-stateless-mcpfrom
fix/sep2575-legacy-malformed-body-precedence
Open

e5l wants to merge 4 commits into
devcrocod/sep-2575-stateless-mcpfrom
fix/sep2575-legacy-malformed-body-precedence

Conversation

@e5l

@e5l e5l commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Why

Goal: close the confirmed review findings on #985 with atomic fixes. Follow-up to #985.

On main (af5d784), every POST to mcpStatelessStreamableHttp went through StreamableHttpServerTransport. That transport judges Accept (406) and Content-Type (415) before the body, and answers invalid JSON with -32700 "Parse error: <detail>" plus _onError. The dual-era entry on this branch parses the body first. So a malformed body with a bad Accept or Content-Type got 400, and _onError never fired.

What changed

In mcpDualEraStreamableHttpEndpoint, a body that does not parse goes to the legacy leg unless MCP-Protocol-Version names a request-scoped revision. That is the rule the classifier already applies to bodies that make no claim. The legacy transport then answers exactly as on main. A malformed body under a request-scoped header still gets the existing JSON-RPC -32700 on 400.

Scope

Only bodies that fail to parse as JSON. Parseable bodies are routed as before.

Tradeoffs

Checking Accept and Content-Type in the entry would duplicate the transport's rules. Routing to the transport reuses them unchanged.

Blast Radius

Legacy clients sending malformed JSON get main's statuses and messages back. The endpoint builds a throwaway Server session for such a request, as it did on main.

Verification

  • Failing first (StatelessStreamableHttpMalformedBodyTest): "a malformed body with an unacceptable Accept header answers 406" was expected:<406> but was:<400>. "a malformed body with an unsupported Content-Type answers 415" was expected:<415> but was:<400>. Both pass after the fix.
  • Guard: "a malformed body with acceptable headers answers a JSON-RPC parse error on 400" passes before and after.
  • _onError has no public observer on this endpoint. A temporary print in the transport's catch showed it fire with JsonDecodingException after the fix. The print was then removed.
  • Local: :kotlin-sdk-server:jvmTest, ktlintCheck detekt checkKotlinAbi all pass.
  • CI: build https://github.com/modelcontextprotocol/kotlin-sdk/actions/runs/44297977239 passed. Conformance https://github.com/modelcontextprotocol/kotlin-sdk/actions/runs/44297983387 passed.

🤖 Generated with Claude Code

e5l and others added 4 commits November 18, 2026 12:32
… body

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dual-era endpoint parsed the body before routing, so a body that did
not parse got 400 even when Accept or Content-Type should have answered
406 or 415 first, and the transport's onError never fired. Without a
request-scoped version header such a body is handshake-era traffic, so hand
it to the legacy transport, which judges headers first, answers its own
-32700 and reports the error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant