mcp: allow restricting the protocol versions a server supports - #1199
Open
guglielmo-san wants to merge 9 commits into
Open
mcp: allow restricting the protocol versions a server supports#1199guglielmo-san wants to merge 9 commits into
guglielmo-san wants to merge 9 commits into
Conversation
…ted and advertised protocol versions
guglielmo-san
force-pushed
the
mcp-supported-protocol-versions
branch
from
August 26, 2026 13:17
6e8c6fb to
127f147
Compare
…lVersions function call
…function was deprecated or removed
…ntation for better fallback behavior
…nsure consistent version matching
…nsport and simplify documentation regarding version negotiation
…upported versions in shared.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) |
Member
There was a problem hiding this comment.
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
}| return !slices.Contains(opts.SupportedProtocolVersions, v) | ||
| }) | ||
| } | ||
| if len(protocolVersions) == 0 { |
Member
There was a problem hiding this comment.
this is unreachable if len(opts.SupportedProtocolVersions) > 0 and all elements are present in supportedProtocolVersions
| // 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 |
Member
There was a problem hiding this comment.
Let's reference [SupportedProtocolVersions] as the source of valid values.
| // (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 |
Member
There was a problem hiding this comment.
line 371 in this file needs to be updated, currently checks supportedProtocolVersions ignoring server opts
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 #945