Skip to content

Add client callbacks for list_changed notifications#2281

Open
omar-y-abdi wants to merge 3 commits intomodelcontextprotocol:mainfrom
omar-y-abdi:fix/handle-list-changed-notifications
Open

Add client callbacks for list_changed notifications#2281
omar-y-abdi wants to merge 3 commits intomodelcontextprotocol:mainfrom
omar-y-abdi:fix/handle-list-changed-notifications

Conversation

@omar-y-abdi
Copy link

Fixes #2107.

ClientSession._received_notification silently dropped ToolListChangedNotification, ResourceListChangedNotification, and PromptListChangedNotification via a catch-all pass. This adds optional callback parameters (tools_list_changed_callback, resources_list_changed_callback, prompts_list_changed_callback) following the existing logging_callback pattern, so clients can react when the server signals that its tool, resource, or prompt lists have changed.

Changes:

  • Added ListChangedFnT protocol type and default no-op callback in session.py
  • Added three new optional callback params to ClientSession.init
  • Added match cases in _received_notification for the three notification types
  • Wired the callbacks through the Client dataclass in client.py
  • Added 4 tests: one for each notification type plus a negative test

The ClientSession._received_notification method silently dropped
ToolListChangedNotification, ResourceListChangedNotification, and
PromptListChangedNotification. Add optional callback parameters
following the existing logging_callback pattern so clients can
react when the server signals that its tool, resource, or prompt
lists have changed.

Github-Issue: modelcontextprotocol#2107
…hods

These methods are now exercised by the new list_changed callback tests,
so the strict-no-cover CI check rejects the pragma.

Github-Issue: modelcontextprotocol#2107
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.

Handle list_changed notifications instead of dropping them

1 participant