Skip to content

mcp: allow restricting the protocol versions a server supports - #1199

Open
guglielmo-san wants to merge 9 commits into
modelcontextprotocol:mainfrom
guglielmo-san:mcp-supported-protocol-versions
Open

mcp: allow restricting the protocol versions a server supports#1199
guglielmo-san wants to merge 9 commits into
modelcontextprotocol:mainfrom
guglielmo-san:mcp-supported-protocol-versions

Conversation

@guglielmo-san

@guglielmo-san guglielmo-san commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #945

@guglielmo-san
guglielmo-san force-pushed the mcp-supported-protocol-versions branch from 6e8c6fb to 127f147 Compare August 26, 2026 13:17
Comment thread mcp/transport.go
// supported is the set of protocol versions the server negotiates, newest
// first, so that a connection deriving the session's effective version
// reaches the same answer the initialize handshake did.
sessionUpdated(state ServerSessionState, supported []string)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doesn't look clean. I'd rather we add a new field to session state:

type ServerSessionState struct {
  ...
  NegotiatedProtocolVersion string `json:"negotiatedProtocolVersion,omitempty"`
}

compute it on initialize, and in sessionUpdated the logic becomes

protocolVersion := state.NegotiatedProtocolVersion
if protocolVersion == "" { // the last spec version that did not protocol-version header
  protocolVersion = protocolVersion20250326
}

Comment thread mcp/server.go
return !slices.Contains(opts.SupportedProtocolVersions, v)
})
}
if len(protocolVersions) == 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is unreachable if len(opts.SupportedProtocolVersions) > 0 and all elements are present in supportedProtocolVersions

Comment thread mcp/server.go
// to those listed. If empty, every version supported by this version of the
// SDK is used.
//
// The value can only narrow support, never widen it: [NewServer] panics if

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's reference [SupportedProtocolVersions] as the source of valid values.

Comment thread mcp/streamable.go
// (i.e. exclude 2026-07-28, since that's what the request asked for
// and what we're rejecting).
legacyVersions := slices.DeleteFunc(slices.Clone(supportedProtocolVersions), func(v string) bool {
advertised := supportedProtocolVersions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

line 371 in this file needs to be updated, currently checks supportedProtocolVersions ignoring server opts

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.

Set list of supported versions

2 participants