Skip to content

Respond with the latest supported protocol version when initialize requests an unknown one - #1339

Open
psp65 wants to merge 3 commits into
smithy-lang:mainfrom
psp65:mcp-initialize-latest-version
Open

Respond with the latest supported protocol version when initialize requests an unknown one#1339
psp65 wants to merge 3 commits into
smithy-lang:mainfrom
psp65:mcp-initialize-latest-version

Conversation

@psp65

@psp65 psp65 commented Aug 29, 2026

Copy link
Copy Markdown

Note: stacked on #1338 — the first commit here is that PR's; this PR's own change is the second commit. Kept as draft until #1338 lands.

What behavior changes?

initialize requesting a protocol version the server does not know (e.g. a future revision) now answers with the latest version the server supports (2025-11-25 today):

{"result":{"protocolVersion":"2025-11-25", ...}}

Previously handleInitialize left the field unset for unknown versions, so the Smithy model default — 2024-11-05, the oldest version — leaked into InitializeResult. Known requested versions are still echoed unchanged, and the behavior for a missing protocolVersion param is intentionally untouched (pinned by an existing test).

Why is this change needed?

The MCP spec requires that a server that does not support the requested version respond with the latest version it does support. #1304's description documents this exact bug; it was fixed for 2025-11-25 by adding that version to the known list, which left the general unknown-version fallback broken. This is the general fix, and step 2 of the 2026-07-28 ladder in #1337.

How was this validated?

  • ProtocolVersionTest.latestVersionIs2025_11_25 and McpServerTest.initializeWithUnknownProtocolVersionAnswersLatestSupported (initialize @2026-07-28"2025-11-25"); known-version echo was already covered by existing tests. Module test/check green, including the integration suite.
  • End-to-end against our internal gateway: Python SDK 1.28.1 and 2.0.0 (auto and legacy modes) negotiate 2025-11-25 exactly as before.

What should reviewers focus on?

  • ProtocolVersion.latestVersion() is derived from the supported-version registry so it cannot drift when future versions are added — and the registry moved into an initialization-on-demand holder. That holder is load-bearing: computing the max during class init of the sealed base class NPEs when a subclass INSTANCE is the first member of the hierarchy touched (base <clinit> runs while the subclass clinit is in progress and reads a still-null INSTANCE). The integration suite caught this; the unit suite alone would not have.
  • The UnknownVersion branch in handleInitialize.

Additional Links


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Param Parikh added 2 commits August 27, 2026 23:06
Per JSON-RPC 2.0, a request carrying an id must receive a response; the
server previously returned null for unknown methods, which surfaced as
an HTTP 200 with an empty body through HTTP transports. Notifications
(requests without an id) are still silently dropped.

This also makes MCP 2026-07-28 clients' auto mode fall back to the
legacy handshake via a clean, deterministic -32601 on the
server/discover probe instead of relying on a synthesized parse error
from the empty body.

https://issues.amazon.com/issues/APPDEV-2256
… versions

Per the MCP spec, a server that does not support the requested protocol
version must respond with the latest version it supports. Previously
handleInitialize left protocolVersion unset for unknown versions, so
the Smithy model default (2024-11-05, the oldest version) leaked into
InitializeResult.

Add ProtocolVersion.latestVersion(), derived from the supported-version
registry so it cannot drift as versions are added. The registry moves
into an initialization-on-demand holder: computing the latest during
class init of the sealed base class NPEs when a subclass INSTANCE is
the first member of the hierarchy touched (base clinit reads a
still-null INSTANCE; caught by McpServerIntegrationTest).

Known versions are still echoed as-is; a missing protocolVersion param
keeps its existing behavior.

https://issues.amazon.com/issues/APPDEV-2257
@adwsingh
adwsingh marked this pull request as ready for review August 29, 2026 00:14
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