-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(server): createRequestStateCodec; pin conformance to main@d70d7ad; toNodeHandler onerror + ctx.log spec-align #2332
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
felixweinberger
wants to merge
4
commits into
fweinberger/on-tonodehandler
Choose a base branch
from
fweinberger/on-codec-conformance
base: fweinberger/on-tonodehandler
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2eebbfa
feat(server): add createRequestStateCodec — opt-in HMAC sealing for t…
felixweinberger 5677604
chore(test/conformance): pin conformance to local build of main @ d70…
felixweinberger a7233af
fix(server,node): modern-era ctx.log suppresses on absent _meta.logLe…
felixweinberger f4e4654
fix(server,node): requestState bind stored as keyed HMAC tag; guard t…
felixweinberger 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,5 @@ | ||
| --- | ||
| '@modelcontextprotocol/server': minor | ||
| --- | ||
|
|
||
| Add `createRequestStateCodec({ key, ttlSeconds?, bind? })`, an opt-in HMAC-SHA256 sealing helper for the multi-round-trip `requestState`: `mint` seals a JSON-serializable payload (with TTL and optional context binding) and `verify` drops directly into `ServerOptions.requestState.verify`. WebCrypto-based and runtime-neutral; verification is fail-closed and constant-time. The `ServerOptions.requestState.verify` hook's return type is widened to `unknown | Promise<unknown>` (the seam already discarded the return value) so the codec's `verify` is directly assignable. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| export * from './middleware/hostHeaderValidation.js'; | ||
| export * from './middleware/originValidation.js'; | ||
| export * from './streamableHttp.js'; | ||
| export type { FetchLikeMcpHandler, NodeIncomingMessageLike, NodeMcpRequestHandler, NodeServerResponseLike } from './toNodeHandler.js'; | ||
| export type { | ||
| FetchLikeMcpHandler, | ||
| NodeIncomingMessageLike, | ||
| NodeMcpRequestHandler, | ||
| NodeServerResponseLike, | ||
| ToNodeHandlerOptions | ||
| } from './toNodeHandler.js'; | ||
| export { toNodeHandler } from './toNodeHandler.js'; |
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.
🟡 docs/migration-SKILL.md's multi-round-trip section (line 554) still tells readers to integrity-protect requestState themselves but never mentions the createRequestStateCodec helper or the ServerOptions.requestState.verify hook that this PR adds and documents in the sibling docs/migration.md. Consider adding a one-sentence pointer so the LLM-applied SKILL doc steers migrations to the new helper instead of hand-rolled HMAC.
Extended reasoning...
What's missing. This PR introduces
createRequestStateCodec({ key, ttlSeconds?, bind? })in@modelcontextprotocol/serverand rewrites the requestState paragraph indocs/migration.md(~line 1238) to present the codec plusServerOptions.requestState.verifyas the intended drop-in. It also converts the SDK's own worked examples (examples/mrtr/server.ts,test/conformance/src/everythingServer.ts) from hand-rollednode:cryptoHMAC to the codec. Howeverdocs/migration-SKILL.md— which describes itself as the LLM-optimized mirror of migration.md and IS touched by this PR (thetoNodeHandler { onerror }lines at 596–602) — still carries only the old guidance in its multi-round-trip section.\n\nThe exact gap. Line 554 of migration-SKILL.md reads: "requestStateround-trips as an opaque string and comes back as attacker-controlled input — integrity-protect (HMAC/AEAD) and verify it yourself when relying on it." A grep of the whole file finds zero occurrences ofcreateRequestStateCodecorrequestState.verify(the only otherrequestStatementions, lines 514/525/528, are about the wire-lift, not integrity protection).\n\nWhy it matters. The SKILL file exists specifically so tools like Claude Code can mechanically apply the migration. With the sentence as-is, an automated migration of a multi-round-trip server will conclude the consumer must hand-roll HMAC — exactly the boilerplate this PR's helper was added to eliminate, and exactly what this PR removed from its own examples. The two migration docs are otherwise kept in step by this PR (the{ fetch, close, notify, bus }andtoNodeHandleronerror updates land in both), so the requestState section is the one place they now diverge.\n\nStep-by-step proof.\n1.grep -n createRequestStateCodec docs/migration-SKILL.md→ no matches;grep -n requestState docs/migration-SKILL.md→ lines 514, 525, 528 (wire-lift) and 554 (the verify-it-yourself sentence).\n2.docs/migration.mdin this PR's diff now says: "…and an opt-in helper to drop into it:createRequestStateCodec({ key, ttlSeconds?, bind? })returns{ mint, verify }…verifyis exactly the function you assign to the hook."\n3. An LLM following migration-SKILL.md §12d for a server using requestState therefore writescreateHmac/timingSafeEqualboilerplate, while the same migration applied from migration.md (or by reading the updated examples) would use the codec.\n\nOn the refutation. It is true that the hard "document in both files" rule in CLAUDE.md is scoped to breaking changes, that the existing sentence at line 554 remains technically accurate (the SDK still applies no sealing by default), and that the codec has no v1 API to map from — so this is not a correctness error and should not block the PR. But the SKILL doc is not purely a v1→v2 mapping table: its §12d already carries this exact security-guidance prose, which is the SKILL-side counterpart of the migration.md paragraph this PR rewrote, and the PR edits the SKILL file anyway. Leaving the two docs divergent on the one point where the SDK now ships a first-class answer is an avoidable inconsistency, hence filed as a non-blocking nit rather than a normal finding.\n\nFix. Append one sentence to the line-554 paragraph along the lines of: "…or drop the SDK'screateRequestStateCodec({ key, ttlSeconds?, bind? })intoServerOptions.requestState.verify(mint withcodec.mint, decode on re-entry withcodec.verify)."