Skip to content

fix(client): respect server capabilities before querying components in ClientSessionGroup#2713

Open
gauravSsinha wants to merge 1 commit into
modelcontextprotocol:mainfrom
substrai:fix/session-group-respect-capabilities
Open

fix(client): respect server capabilities before querying components in ClientSessionGroup#2713
gauravSsinha wants to merge 1 commit into
modelcontextprotocol:mainfrom
substrai:fix/session-group-respect-capabilities

Conversation

@gauravSsinha
Copy link
Copy Markdown

Summary

ClientSessionGroup unconditionally calls list_tools(), list_prompts(), and list_resources() on every connect, regardless of whether the server advertised those capabilities. This violates the MCP lifecycle spec.

Problem

From the MCP spec (Capability Negotiation / Operation):

Both parties MUST: ... Only use capabilities that were successfully negotiated.

When a server doesn't implement tools/prompts/resources, the calls return Method not found errors that are caught and logged as warnings — but the calls should never be made in the first place.

Fix

Check session.initialize_result.capabilities before each list call:

caps = session.initialize_result.capabilities if session.initialize_result else None
if caps and caps.prompts is not None:
    prompts = (await session.list_prompts()).prompts

Only queries capabilities the server explicitly advertised.

Impact

  • Eliminates spurious WARNING: Could not fetch prompts/resources/tools logs
  • Brings the client into spec compliance
  • Reduces unnecessary network round-trips to servers that don't support all capabilities

Fixes #2689

ClientSessionGroup unconditionally called list_tools(), list_prompts(),
and list_resources() on every connect, regardless of whether the server
advertised those capabilities. This violates the MCP lifecycle spec
which states clients MUST only use capabilities that were successfully
negotiated.

Fix: check session.initialize_result.capabilities before each list
call. Only query prompts/resources/tools if the server advertised the
corresponding capability (caps.prompts/resources/tools is not None).

Fixes modelcontextprotocol#2689

Signed-off-by: Gaurav Kumar Sinha <gaurav@substrai.dev>
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