-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Is your feature request related to a problem? Please describe.
I'm frustrated that the server can only send notifications (like tools_list_changed) to the client associated with the current request. When the server changes tools, resources, or prompts outside of a request handler (e.g., when an administrator updates available tools), there’s no way to notify all connected clients. This is because the ServerSession is responsible for sending notifications, and it is only available while handling a specific client request. This leads to clients being out of sync with the server’s actual state.
Describe the solution you'd like
Track all active ServerSession instances in the server. Expose an API to broadcast notifications (such as tools_list_changed) to every connected client, not just the one associated with the current request context. This would let the server proactively inform all clients of important changes, keeping everyone in sync.
Describe alternatives you've considered
- Sending notifications only in response to client requests (current behavior), but this doesn’t cover server-initiated changes.
- Attempting to access the request context outside a handler, but this raises errors and isn’t supported by the current design.
- Implementing a custom session registry in user code, but this is error-prone and would be better handled by the framework.
Additional context
This feature would support dynamic server-side changes (such as feature flags, admin actions, or configuration updates while the server is running) and improve the consistency and user experience for all clients.
I’m open to feedback or alternative approaches if there’s a better way to achieve this. Thanks for considering this improvement!
Related issues
- how to trigger a resources_changed or listChanged #710 – How to trigger a resources_changed or listChanged notification
- removing a tool or resource dynamically #711 – Removing a tool or resource dynamically