fix(clientsessiongroup): only query negotiated capabilities#2753
Open
mr-brobot wants to merge 1 commit into
Open
fix(clientsessiongroup): only query negotiated capabilities#2753mr-brobot wants to merge 1 commit into
mr-brobot wants to merge 1 commit into
Conversation
ClientSessionGroup._aggregate_components queried prompts, resources, and tools unconditionally on every connect, ignoring the ServerCapabilities returned by initialize(). A server that advertised only some of these (e.g. tools) returned JSON-RPC "Method not found" for the rest, which was swallowed into spurious WARNING logs. The MCP lifecycle spec requires clients to only use capabilities that were successfully negotiated. Gate each list_* call on the matching capability from session.initialize_result.capabilities, falling back to the prior unconditional behavior when initialize_result is absent so the existing MCPError handler still covers servers that advertise a capability but fail the method. Fixes modelcontextprotocol#2689 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
04133d5 to
6e03f80
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.
Summary
Fixes #2689
ClientSessionGroupqueried prompts, resources, and tools unconditionally on every connect, ignoring theServerCapabilitiesreturned byinitialize(). A server advertising only some capabilities (e.g. tools) returned JSON-RPCMethod not foundfor the rest, which was swallowed into spuriousWARNINGlogs — contrary to the lifecycle spec: clients MUST "Only use capabilities that were successfully negotiated."Changes
_aggregate_componentsnow gates eachlist_*call on the matching capability fromsession.initialize_result.capabilities.MCPErrorfallback is preserved for servers that advertise a capability but still fail the method; a missinginitialize_resultfalls back to the prior unconditional behavior.test_client_session_group_skips_unsupported_capabilities, parametrized over tools/prompts/resources-only servers.The same code path exists on
v1.xand likely warrants a[v1.x]backport.Note
I followed the suggestion strictly, but I think the fallback behavior for "misbehaving servers" has questionable value. Sharing as-is for feedback.
🤖 Generated with Claude Code