Part 7 of 14 · 2 min read
Notifications, and talking to older servers
Change notifications on `subscriptions/listen`, and detecting which era a server speaks.
Servers have things to say that are not replies, such as "the tool list changed" or "a resource was updated." In the new form the client asks for a stream with a request called subscriptions/listen. The response to that request never ends until someone closes it. The request carries a filter (toolsListChanged, promptsListChanged, resourcesListChanged, resourceSubscriptions). The server's first message is notifications/subscriptions/acknowledged, naming which of them it will honour. Every later message on the stream carries the id of the listen request in _meta.
In the example the client asks for three kinds of notification. The server does not support prompt-list changes, so it acknowledges two: resourceSubscriptions and toolsListChanged. A second client restocks a book. The listener receives notifications/resources/updated with the matching subscription id. A resource nobody subscribed to produces nothing. On stdio all subscriptions share stdout. So two open listeners, sorted by subscription id, receive 1 and 2 notifications respectively when three changes land across two books. If the connection drops while a client is away, nothing resends what it missed. Take a client that reads a book showing 2 copies and disconnects. Someone restocks it to 7. The client reconnects and listens again. It receives 0 notifications and would still believe the book has 2 copies. Only re-reading the resource shows 7. The rule for a client is to re-read anything it caches after every reconnect. It should never assume that no notification means no change.
A client that must work with servers it did not choose detects the era in order. It POSTs a modern probe first. If that fails with an unrecognised error, it tries the earlier handshake (initialize, which returns a session id in Mcp-Session-Id). If that fails too, a GET to the same URL reaching an endpoint event marks the deprecated HTTP+SSE transport, which new work should not adopt. In the example the earlier server issues an unguessable 32-character session id. It answers a request with no session id with a bare 400. It answers an ended session with 404, after which the client must start a new session. It lets a client end a session with DELETE.
Session ids are not authentication
In the earlier form a session id identifies a conversation; it was never meant to prove who you are. The specification's security guidance for that era warns about session hijacking (a stolen or guessed id), so ids must be unguessable and bound to the authenticated user. The new revision removes sessions, but handles (module 2) have the same risk and the same answer.