Skip to content

fix(mcp-auth): negotiate protocol version instead of rejecting - #381

Merged
hoegertn merged 3 commits into
mainfrom
fix/mcp-protocol-version-negotiation
Aug 30, 2026
Merged

fix(mcp-auth): negotiate protocol version instead of rejecting#381
hoegertn merged 3 commits into
mainfrom
fix/mcp-protocol-version-negotiation

Conversation

@hoegertn

Copy link
Copy Markdown
Contributor

Summary

The MCP server rejected initialize requests whose protocolVersion was not in the configured set with JSON-RPC -32602, and 2025-06-18 was missing from the defaults even though the adjacent 2025-03-26 and 2025-11-25 revisions were present.

This changes handleInitialize to negotiate a version rather than error:

  • Requested version is supported → echo it back.
  • Otherwise → return the highest supported version that is not newer than the requested one (downward negotiation).
  • Only when no supported version is old enough → fall back to -32602.

2025-06-18 is 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 hardcodes protocolVersion: 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 of 2025-06-18, downgrade to the highest not-newer supported version, downgrade for an unknown future version, and the -32602 fallback 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).

kiro-agent and others added 3 commits August 30, 2026 14:46
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>
@hoegertn
hoegertn merged commit c35fe16 into main Aug 30, 2026
4 checks passed
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.

2 participants