fix(client): respect server capabilities before querying components in ClientSessionGroup#2713
Open
gauravSsinha wants to merge 1 commit into
Conversation
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>
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
ClientSessionGroupunconditionally callslist_tools(),list_prompts(), andlist_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):
When a server doesn't implement tools/prompts/resources, the calls return
Method not founderrors that are caught and logged as warnings — but the calls should never be made in the first place.Fix
Check
session.initialize_result.capabilitiesbefore each list call:Only queries capabilities the server explicitly advertised.
Impact
WARNING: Could not fetch prompts/resources/toolslogsFixes #2689