Skip to content

mcp: reject discover when transport lacks version - #1108

Open
piyushbag wants to merge 2 commits into
modelcontextprotocol:mainfrom
piyushbag:fix/discover-reject-unsupported-version
Open

mcp: reject discover when transport lacks version#1108
piyushbag wants to merge 2 commits into
modelcontextprotocol:mainfrom
piyushbag:fix/discover-reject-unsupported-version

Conversation

@piyushbag

Copy link
Copy Markdown
Contributor

Problem

On a stateful Streamable HTTP server, ServerSession.handle gates new-protocol requests against the global supportedProtocolVersions list. The transport-filtered list (via filterSupportedVersions / SupportsProtocolVersion) can omit 2026-07-28, yet server/discover still returned HTTP 200 with a DiscoverResult that excluded the probed version instead of UnsupportedProtocolVersionError.

Approach

Align the version gate in handle with the session's transport-filtered supportedVersions, matching what server/discover advertises. Rename and update the stateful regression test to expect HTTP 400 with CodeUnsupportedProtocolVersion.

Test plan

  • go test ./...
  • go test -race ./...
  • Updated TestStreamableStateful_DiscoverRejectsUnsupportedVersion

Fixes #1025

piyushbag and others added 2 commits July 23, 2026 08:56
Use the session transport-filtered supportedVersions in
ServerSession.handle so stateful Streamable HTTP servers return
UnsupportedProtocolVersionError instead of a DiscoverResult that omits
the probed protocol version.
Comment thread mcp/server.go
Comment on lines +1866 to +1870
if validatedMeta.usesNewProtocol {
requested := validatedMeta.initializeParams.ProtocolVersion
ss.mu.Lock()
versions := ss.supportedVersions
ss.mu.Unlock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rejecting calls to server/discover when stateless=false, will make the ss.supportedVersions useless.
We decided to implement it in this way to allow a more meaningful response in case of new server but on stateful mode.
If we want to change this implementation, it would be easier to change the code in streamable, removing the guard for server discover

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.

(possible) 2026-07-28 spec violation: server/discover response without 2026-07-28 support

2 participants