Repository navigation
Conversation
Enigmage
force-pushed
the
fix-2026-only-server-rejects-legacy
branch
from
October 6, 2026 14:22
597f2c0 to
c47e426
Compare
Enigmage
marked this pull request as ready for review
October 6, 2026 14:32
Enigmage
marked this pull request as draft
October 6, 2026 14:56
Enigmage
force-pushed
the
fix-2026-only-server-rejects-legacy
branch
from
October 6, 2026 14:59
c47e426 to
79d2351
Compare
Enigmage
marked this pull request as ready for review
October 6, 2026 15:01
A server configured with SupportedProtocolVersions containing only versions >= 2026-07-28 should not silently serve legacy clients that use the initialize/initialized handshake protocol. Previously, such clients would receive a successful (if confusing) response: stateful servers would accept any post-initialize method call because ephemeral session setup bypassed the version check, and stateless servers would always appear initialized due to ephemeral connect opts synthesizing fake InitializeParams. Fix the stateful path by detecting a 2026-only server configuration in the uninitialized branch of handle() and returning CodeUnsupportedProtocolVersion before falling through to the generic "method invalid during initialization" error. Fix the stateless path by checking the legacy flag in serveStateless() immediately after ephemeralConnectOpts(), before any method dispatch. Both paths include an UnsupportedProtocolVersionData payload listing the server's supported versions so clients can adapt. Fixes modelcontextprotocol#1313
Enigmage
force-pushed
the
fix-2026-only-server-rejects-legacy
branch
from
October 6, 2026 15:09
914ee33 to
d5a828d
Compare
This branch has not been deployed
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.
Fixes #1313.
Note: this PR does not change initialize behavior on a 2026-only server, it still succeeds with protocolVersion20251125 per the existing "server with no handshake version" test. We can discuss if we want to reject initialize with -32022 as well.
A server configured with
SupportedProtocolVersionscontaining only versions>= 2026-07-28should reject legacy clients that use theinitialize/initializedhandshake protocol with a clearCodeUnsupportedProtocolVersionerror, rather than silently serving them in a degraded state.What was broken
Two paths allowed legacy requests to slip through on a 2026-only server:
Stateful, uninitialized:
handle()reached the "method invalid during initialization" error path for any non-initializecall, but returned a generic error instead ofCodeUnsupportedProtocolVersion. The caller had no signal that the server will never support the legacy protocol.Stateless:
serveStateless()callsephemeralConnectOpts(), which synthesizes fakeInitializeParamsfor every request — making every session appear already initialized. This caused all legacy stateless calls to dispatch successfully and produce results, with no rejection at all.Fix
server.go— stateful uninitialized path:In the
handle()branch for uninitialized legacy calls, detect when the server has no legacy-supporting version configured and returnCodeUnsupportedProtocolVersionwith anUnsupportedProtocolVersionDatapayload before falling through to the generic error.streamable.go— stateless path:In
serveStateless(), afterephemeralConnectOpts(), check whether the server has any legacy-supporting version configured. If not, write aCodeUnsupportedProtocolVersionerror response and return.Behavior
initialize: allowed —negotiatedVersionreturnsprotocolVersion20251125as a courtesy per existing semantics inshared.go.initializecall (stateful, uninitialized): rejected withCodeUnsupportedProtocolVersion.CodeUnsupportedProtocolVersionand HTTP 400.SupportedProtocolVersionsare unaffected.Tests
TestServerSupportedProtocolVersions_InitializeLegacy: verifiesinitializesucceeds on a 2026-only server and returnsprotocolVersion20251125.TestServerSupportedProtocolVersions_LegacyDispatch: verifies a legacytools/listcall without_metais rejected withCodeUnsupportedProtocolVersionon a 2026-only stateful server.TestStreamableStateless_RejectsLegacyOn2026OnlyServer: verifies a legacy POST to a stateless 2026-only server returns HTTP 400 withCodeUnsupportedProtocolVersion.