Skip to content

fix(clientsessiongroup): only query negotiated capabilities#2753

Open
mr-brobot wants to merge 1 commit into
modelcontextprotocol:mainfrom
mr-brobot:fix/clientsessiongroup-capabilities
Open

fix(clientsessiongroup): only query negotiated capabilities#2753
mr-brobot wants to merge 1 commit into
modelcontextprotocol:mainfrom
mr-brobot:fix/clientsessiongroup-capabilities

Conversation

@mr-brobot
Copy link
Copy Markdown

@mr-brobot mr-brobot commented Jun 1, 2026

Summary

Fixes #2689

ClientSessionGroup queried prompts, resources, and tools unconditionally on every connect, ignoring the ServerCapabilities returned by initialize(). A server advertising only some capabilities (e.g. tools) returned JSON-RPC Method not found for the rest, which was swallowed into spurious WARNING logs — contrary to the lifecycle spec: clients MUST "Only use capabilities that were successfully negotiated."

Changes

  • _aggregate_components now gates each list_* call on the matching capability from session.initialize_result.capabilities.
  • The MCPError fallback is preserved for servers that advertise a capability but still fail the method; a missing initialize_result falls back to the prior unconditional behavior.
  • Adds test_client_session_group_skips_unsupported_capabilities, parametrized over tools/prompts/resources-only servers.

The same code path exists on v1.x and 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

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>
@mr-brobot mr-brobot force-pushed the fix/clientsessiongroup-capabilities branch from 04133d5 to 6e03f80 Compare June 1, 2026 13:54
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.

ClientSessionGroup attempts to use capabilities that were not advertised

1 participant