feat: Add protocol_version parameter to ClientSession#2321
Open
goingforstudying-ctrl wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat: Add protocol_version parameter to ClientSession#2321goingforstudying-ctrl wants to merge 1 commit intomodelcontextprotocol:mainfrom
goingforstudying-ctrl wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
This change allows users to specify a custom protocol version when initializing a ClientSession, instead of always using LATEST_PROTOCOL_VERSION. This is needed for connecting to MCP servers that require a specific protocol version (e.g., Snowflake's managed MCP server requires 2025-06-18). Changes: - Added protocol_version parameter to ClientSession.__init__() - Stored protocol_version as instance variable _protocol_version - Updated initialize() to use self._protocol_version instead of hardcoded constant - Added tests for both custom and default protocol version scenarios Backwards compatible: defaults to LATEST_PROTOCOL_VERSION when not specified. Fixes modelcontextprotocol#2307
2 tasks
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
Fixes #2307 - Adds the ability to specify a custom protocol version in ClientSession.initialize().
Problem
ClientSession.initialize() hardcodes protocolVersion=types.LATEST_PROTOCOL_VERSION with no way for the caller to override it. When connecting to an MCP server that requires a specific protocol version (e.g., Snowflake's managed MCP server requires "2025-06-18"), the only workaround is to mutate the module-level constant before calling initialize().
Solution
Added an optional protocol_version parameter to ClientSession.init():
Then use it in initialize():
Changes
Testing
Backwards Compatibility
Fully backwards compatible - existing callers get the current default (LATEST_PROTOCOL_VERSION) when protocol_version is not specified.
Closes #2307