fix(mcp-auth): negotiate protocol version instead of rejecting - #381
Merged
Conversation
Add 2025-06-18 to the default supported protocol versions and negotiate downwards on initialize instead of returning JSON-RPC -32602 for an unsupported version. Per the MCP lifecycle spec the server echoes the requested version when supported, otherwise responds with a version it does support. We pick the highest supported version that is not newer than the requested one, because @modelcontextprotocol/sdk <= 1.16.0 rejects any negotiated version outside its own accepted set. Only when no supported version is old enough do we fall back to -32602.
The McpAuth construct test asserted the old default env value; update it to include 2025-06-18 to match the new default.
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
Summary
The MCP server rejected
initializerequests whoseprotocolVersionwas not in the configured set with JSON-RPC-32602, and2025-06-18was missing from the defaults even though the adjacent2025-03-26and2025-11-25revisions were present.This changes
handleInitializeto negotiate a version rather than error:-32602.2025-06-18is added to the default supported set (['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05']).Why negotiate downwards
Per the MCP lifecycle spec, when the client requests an unsupported version the server responds with a version it supports and lets the client decide. We never answer with a version newer than requested, because
@modelcontextprotocol/sdk<= 1.16.0 hardcodesprotocolVersion: LATEST("2025-06-18") and rejects any negotiated version outside its own accepted set. Answering with our latest (2025-11-25) would fail those clients too.Version strings are
YYYY-MM-DD, so lexicographic comparison matches chronological order.Tests
Added regression coverage in
test/mcp-auth/mcp-server.test.ts: echo of2025-06-18, downgrade to the highest not-newer supported version, downgrade for an unknown future version, and the-32602fallback when no version is old enough. All 25 tests pass; lint clean.Related
Companion fix in taimos/nornkeep, whose runtime MCP server (
@taimos/mcp-cognito-auth) carries an identical copy of this logic. Found while adding the Nornkeep server to MetaMCP (SDK 1.16.0).