mcp: emit UnsupportedProtocolVersionError for stateful servers rejecting SEP-2575 requests - #1111
Open
jhrozek wants to merge 1 commit into
Open
mcp: emit UnsupportedProtocolVersionError for stateful servers rejecting SEP-2575 requests#1111jhrozek wants to merge 1 commit into
jhrozek wants to merge 1 commit into
Conversation
…ing SEP-2575 requests
A stateful (Stateless == false) Streamable HTTP server rejected requests
carrying `_meta."io.modelcontextprotocol/protocolVersion"` >= 2026-07-28
with a plain-text http.Error body, instead of the JSON-RPC
UnsupportedProtocolVersionError the draft spec requires for a known
version the server has chosen not to support. The body also leaked a
Go-API hint ("set StreamableHTTPOptions.Stateless = true") meant for the
server author, not the client.
Reuse the existing CodeUnsupportedProtocolVersion (-32022) and
UnsupportedProtocolVersionData shape already used by the discover and
initialize paths, listing only the server's legacy-era supported
versions. This lets Client.Connect's existing renegotiation logic
recognize and handle the rejection instead of falling back on an
unrecognized text/plain body. The developer hint moves to a server-side
log line.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.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
A stateful (
Stateless == false) Streamable HTTP server rejected requests carrying_meta."io.modelcontextprotocol/protocolVersion"for MCP2026-07-28with a plain-texthttp.Errorbody, instead of the JSON-RPC error the draft spec requires. Per the draft's Protocol Version Header section, a server that won't serve a known-but-unsupported version MUST respond400 Bad Requestwith anUnsupportedProtocolVersionErrorlisting its supported versions — this is exactly that case (a stateful server that hasn't opted intoStateless).Two things made this clearly a bug rather than a design choice:
The very next branch in the same function already calls
writeJSONRPCErrorwithCodeHeaderMismatchfor an adjacent condition — this branch usedhttp.Errorinstead, inconsistently.The body text (
"set StreamableHTTPOptions.Stateless = true") is a Go-API hint for whoever wrote the server, not something a remote client can act on.Reuse the existing
CodeUnsupportedProtocolVersion(-32022) andUnsupportedProtocolVersionData{Supported, Requested}shape already used by thediscover/initializepaths, soClient.Connect's existing renegotiation logic can recognize this response and fall back cleanly, instead of hitting an unrecognizedtext/plainbody.Supportedlists only the server's legacy-era versions (excludes2026-07-28), since that's the whole point of the rejection.The developer-facing hint moves to a server-side log line instead of the wire body.
server/discoverstays exempt, as before — it's how a client is meant to learn a stateful server's restricted version set in the first place.Test plan
go build ./...go vet ./...go test ./mcp/...(full package)TestStreamableStateful_RejectsNewProtocolto assert the JSON-RPC error shape (code-32022,Requested,Supportedexcluding2026-07-28) instead of the old text-contains-"stateless" checkTestStreamableStateless_AcceptsNewProtocol,TestStreamableClientUnsupportedVersionFallback,TestStreamableStateful_AcceptsDiscoverall still pass unmodified🤖 Generated with Claude Code