An application reads a resource, then spends time preparing an answer from it. During that time, the resource changes. The answer may now depend on an older copy. A resource subscription gives the application a way to learn which URI needs another read.
A subscription names the resource
In the Model Context Protocol (MCP), each resource has a URI. Clients retrieve its contents with resources/read. A server can advertise support for resource-specific update notifications through its subscribe capability. The resource specification describes these as separate operations: reading gets content; subscribing requests notice of changes.
To watch a resource, the client sends subscriptions/listen with its URI in resourceSubscriptions. That request opens a stream for notifications. The server first acknowledges the subscription and states which requested notifications it agreed to send. The client should check that acknowledgment before the initial read; reading first would leave a gap in which a change could go unnoticed. The subscription specification shows the request and acknowledgment.
The update identifies what changed
When a watched resource changes, the server sends notifications/resources/updated. The notification includes the resource URI and a subscription ID. Its example contains no replacement content. The client can use the URI to request the resource again with resources/read. The resource specification shows both messages.
There is a related signal for a different event. notifications/resources/list_changed concerns the list of available resources. The server may support list changes and resource-specific updates independently. A client watching a document should therefore handle an update to that document separately from a change to the resource list. The resource specification defines both capabilities.
What to do
- Check that the server advertises resource subscription support. Open
subscriptions/listenfor the URI and check that the acknowledgment includes the requested subscription. - Read the URI whose contents the application needs with
resources/read. Keep the subscription active while using that content. The subscription specification describes this check. - When an update names the URI, mark the earlier copy stale and call
resources/readagain before using that content in a pending answer. - If the stream closes, restore the subscription. A client using stdio must send a new listen request after reconnecting. The subscription specification describes how subscriptions end.

The Campfire
CommentsThanks. Your comment is waiting for the desk. Once it is approved it appears here within about a minute.
Add a comment