fix(server): reject a modern POST without the required MCP-Protocol-Version header - #2590
Open
davidpavlovschi wants to merge 2 commits into
Conversation
…ersion header A 2026-07-28 POST carrying a valid _meta envelope but no MCP-Protocol-Version header dispatched and answered HTTP 200: the standard-header rung validated only Mcp-Method / Mcp-Name presence, and the classifier cross-checks the version header only when it is present. validateStandardRequestHeaders now rejects the absent header on the standard-header-validation rung with the existing HeaderMismatch (-32020) constructor on HTTP 400, and createMcpHandler passes the header through for that check. The rung still runs only on a modern-classified request, so notifications, legacy POSTs, and GET/DELETE are unchanged. Fixes modelcontextprotocol#2589
🦋 Changeset detectedLatest commit: 4643bbc The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
…client header helper
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2589.
The bug
A 2026-07-28 POST whose body carries a valid
_metaenvelope but whoseMCP-Protocol-Versionheader is absent dispatched and answered HTTP 200. The issue's exact repro (server/discover,mcp-methodpresent, version header omitted) reproduces oncc4b416.Two halves of the ladder each assumed the other covered it:
classifyInboundRequesttreats the protocol-version header as a cross-check only —classifyRequestBodycompares it against the envelope claim underheaderVersion !== undefined, so an absent header is simply not compared.validateStandardRequestHeaders(thestandard-header-validationrung) checks presence ofMcp-Methodand, where applicable,Mcp-Name— but not ofMCP-Protocol-Version. The entry did not even pass the header into it.The 2026-07-28 Streamable HTTP spec requires the header on every POST, and a missing required standard header must be answered
400/HeaderMismatch(-32020).The fix
validateStandardRequestHeadersrejects an absentMCP-Protocol-Versionon a modern-classified request via the existingcrossCheckMismatchconstructor — same rung, same-32020, same HTTP 400, same{ mismatch: { header, body } }data shape, request id echoed. New cell id:version-header-missing. No new error constructor, no new code.createMcpHandlerpassesmcp-protocol-versioninto that call (it previously passed onlymcp-method/mcp-name).Scope
The presence rung runs only on a modern route and returns early for notifications, so:
initialize, no-claim bodies) are untouched;GET/DELETEare still method-routed to legacy serving before any header validation;header-body-version-mismatchcell.Test-fixture updates
Several existing in-repo fixtures built modern POSTs from the body envelope alone, without the header a conformant client sends. They now send it — in
packages/server/test/server/createMcpHandler.test.tsthis is one line in the existingbodyDerivedStandardHeadershelper, whose stated job is "the SEP-2243 standard headers a conformant client derives from the body it sends". Same one-line addition in the listen / capability-gate / e2e-subscriptions / e2e-hosting-entry-session / integration fixtures. No assertion was weakened.Tests added
packages/core-internal/test/shared/standardHeaderValidation.test.ts: missing header rejectsversion-header-missing(400 / -32020); the version rung outranks theMcp-Methodpresence rung; present-and-matching passes; present-and-mismatched still answered by the classifier'sheader-body-version-mismatchcell; a notification without the header is still never enforced.packages/server/test/server/stdHeaderValidation.test.ts: end-to-end throughcreateMcpHandler— missing header → 400 / -32020 with the id echoed; present-and-matching → 200; mismatched → 400 / -32020; a body-lessGETis never header-validated. The existing legacy-untouched cell stays.This change was developed with AI assistance; the tests listed below were run locally.
Validation run locally
Repro asserted before the change (HTTP 200) and after (HTTP 400 / -32020).
packages/server— 42 files, 472 tests passedpackages/core-internal— 69 files, 1438 tests passedpackages/client— 33 files, 797 tests passedpackages/server-legacy(11/168),packages/codemod(19/629),packages/core(1/2) — passedtest/integration— 19 files, 371 tests passedtest/e2e— 42/44 files passed; the only 2 failing files (6 tests:protocol:progress:callback,typescript:protocol:progress:token-injected,tools:call:progress, allssearms) fail identically on unmodifiedcc4b416and are unrelated to this changetest/conformance:test:conformance:server:2026— 114 passed, 0 failed (http-header-validation13/13,http-custom-header-server-validation9/9);test:conformance:server:all— baseline check passedpackages/server,packages/core-internal,test/e2e,test/integrationall clean (prettier included)A changeset is included (
core-internal+server, patch).