-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(server): reject a modern POST that omits the required MCP-Protoco… #2594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KKonstantinov
wants to merge
1
commit into
main
Choose a base branch
from
fix/2589-createMcpHandler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| '@modelcontextprotocol/core-internal': patch | ||
| '@modelcontextprotocol/server': patch | ||
| --- | ||
|
|
||
| Reject a modern (2026-07-28) POST that omits the required `MCP-Protocol-Version` header. | ||
|
|
||
| `createMcpHandler` accepted a request whose body carried a valid per-request `_meta` | ||
| envelope but whose `MCP-Protocol-Version` header was absent: the request was classified | ||
| modern, dispatched, and answered `200` — tool handlers ran. Only the _mismatch_ case | ||
| (header present, disagreeing with the body) was rejected, so of the three standard | ||
| headers SEP-2243 requires on every modern POST, presence was enforced for `Mcp-Method` | ||
| and `Mcp-Name` but not for `MCP-Protocol-Version`. | ||
|
|
||
| Such a request is now refused with `400 Bad Request` and JSON-RPC `-32020` | ||
| (`HeaderMismatch`), matching the shape the sibling missing-header cells already emit and | ||
| echoing the request id — per the Streamable HTTP spec, which requires the header on every | ||
| POST and lists a missing required standard header as a `HeaderMismatch` failure. The | ||
| spec's allowance to treat a header-less request as `2025-03-26` is available only to a | ||
| server that also serves pre-2025-06-18 clients, and permits routing it to _legacy_ | ||
| handling — never serving it as 2026-07-28; under `legacy: 'reject'` the requirement is | ||
| unconditional. | ||
|
|
||
| Era classification is deliberately unchanged and stays body-primary: a proxy that strips | ||
| the header still must not change the era, so such a request is still _classified_ modern | ||
| and is refused one rung later, at `standard-header-validation` — the same rung that | ||
| already answers a missing `Mcp-Method`. Legacy-era traffic is untouched, notifications | ||
| are unaffected, and stdio serving (which has no HTTP headers) is not involved. | ||
|
|
||
| Clients built with this SDK always send the header, so no first-party client is affected; | ||
| hand-rolled clients that omitted it must add it. |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The rewritten rationale for the standard-header-validation rung says "The spec requires all three on every modern POST", but Mcp-Name is required only for tools/call, prompts/get, and resources/read (per the SEP-2243 'Required For' column cited by MCP_NAME_HEADER_SOURCE in this same file) — and validateStandardRequestHeaders itself enforces Mcp-Name presence only for those three methods. The changeset (.changeset/require-mcp-protocol-version-header.md) repeats the same overstatement; consider adding the qualifier the migration doc and the new modernStandardHeaders JSDoc already use ('Mcp-Name only for the methods that mirror params.name / params.uri') in both places.
Extended reasoning...
What the prose claims vs. what the code does
The new rationale string for the
standard-header-validationrung (packages/core-internal/src/shared/inboundClassification.ts,INBOUND_VALIDATION_LADDER) states:This overstates
Mcp-Name. Per SEP-2243 § Standard Request Headers, the "Required For" column scopesMcp-Nametotools/call,prompts/get, andresources/readonly — the exact table cited by theMCP_NAME_HEADER_SOURCEdoc comment a few hundred lines below in the same file, whose map is{ 'tools/call': 'name', 'prompts/get': 'name', 'resources/read': 'uri' }.The implementation agrees with the spec, not the rationale
validateStandardRequestHeadersin this same file enforcesMcp-Namepresence only whenObject.hasOwn(MCP_NAME_HEADER_SOURCE, method)hits — i.e. only for those three methods — and even then only when the body actually carries the mirroredparams.name/params.urivalue (if (bodyValue === undefined) return undefined). Every other method passes the rung with noMcp-Nameat all.Step-by-step proof from this PR's own tests
packages/server/test/server/stdHeaderValidation.test.tspins: "Mcp-Name is not required for methods outside its source map" — a moderntools/listPOST withmcp-protocol-versionandmcp-methodbut nomcp-nameis served200.packages/core-internal/test/shared/standardHeaderValidation.test.tspins: "a present Mcp-Method header passes for a method with no Mcp-Name source" —validateStandardRequestHeadersreturnsundefinedfor a moderntools/listwithoutMcp-Name.The changeset repeats the overstatement
.changeset/require-mcp-protocol-version-header.md: "of the three standard headers SEP-2243 requires on every modern POST, presence was enforced for Mcp-Method and Mcp-Name" — same unqualified claim, in text that will ship in release notes.The accurate wording already exists in this PR
Both
docs/migration/support-2026-07-28.mdand the newmodernStandardHeadershelper JSDoc intest/e2e/helpers/index.tscarry the correct qualifier: "Mcp-Nameonly for the methods that mirrorparams.name/params.uri". So the fix is mechanical: add that same parenthetical to the rung rationale and the changeset.Why nit: this is prose-only — the ladder rationale is documentation-as-data and the changeset is release-notes text; no runtime behavior is affected, and the enforcement code itself is correct. It matches the repo's Documentation & Changesets recurring catch (prose in the diff contradicting the implementation in the same diff), which asks for it to be flagged but does not make it blocking.