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.
This PR expands the universe of supported server notification types that a client can handle to include all existing types defined in
types.pyas well as any other type deriving fromServerNotification, both unknown via a fallback handler and known via a custom handler registry.Motivation and Context
In the current state, Python clients can only handle a few notifications sent by servers, essentially making those server-sent notifications useless. To empower client developers to handle any kind of notification servers may send them, I created this PR.
How Has This Been Tested?
test_custom_notifications.pyandtest_notification_callbacks.pyBreaking Changes
None, this approach is fully backward-compatible
Types of changes
Checklist
Additional context
Handling "known custom" server notifications (although I expect it to be a narrow use case right now, with private MCP registries I think this will get more popular) is done by creating a registry dictionary where the keys are the notification string literal and the values are references to the handler functions, then passing that in to a new client constructor parameter. This is given priority when routing notifications, however I am not tied to that specific ordering.
I would like eventually to do notification discovery, but I don't think the juice is worth the squeeze at the moment.