feat(mcp): expose protocolVersions configuration in McpClientBuilder#1187
Open
BeastDamon wants to merge 1 commit intoagentscope-ai:mainfrom
Open
feat(mcp): expose protocolVersions configuration in McpClientBuilder#1187BeastDamon wants to merge 1 commit intoagentscope-ai:mainfrom
BeastDamon wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Allow users to specify supported MCP protocol versions when building MCP clients via a new protocolVersions(String...) builder method. This enables compatibility with MCP servers that respond with newer protocol versions (e.g., 2025-03-26) during initialization, which previously caused 'Unsupported protocol version' errors. Implementation uses a ProtocolVersionOverrideTransport decorator that wraps any McpClientTransport and overrides protocolVersions(), working with all transport types (StdIO, SSE, StreamableHTTP). Closes agentscope-ai#1173
aef14b7 to
1b2de72
Compare
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.
AgentScope-Java Version
1.0.12-SNAPSHOT (main branch)
Description
When connecting to third-party MCP servers via stdio transport, the client fails with "Unsupported protocol version" if the server responds with a protocol version other than "2024-11-05". For example, CodeGraphContext returns
"protocolVersion": "2025-03-26"in its initialize response.The root cause is that
McpTransport.protocolVersions()defaults toList.of("2024-11-05")only, andLifecycleInitializer.doInitialize()performs a strictprotocolVersions.contains(result.protocolVersion())check. Neither the MCP Java SDK'sMcpClientbuilder nor AgentScope'sMcpClientBuilderexposes this configuration to users.The MCP protocol is actively evolving (4 versions already defined in
ProtocolVersions.java), making hardcoded single-version lists increasingly problematic for third-party server integration.This PR adds a
protocolVersions(String...)method toMcpClientBuilder:Implementation uses a
ProtocolVersionOverrideTransportdecorator that wraps anyMcpClientTransportand overridesprotocolVersions(). This approach:protocolVersions()is not calledFiles changed:
McpClientBuilder.javaprotocolVersions()builder method +ProtocolVersionOverrideTransportinner classMcpClientBuilderTest.javadocs/en/task/mcp.mddocs/zh/task/mcp.mdHow to test:
Closes #1173
Checklist
mvn spotless:applymvn test)