subscriptions
Typed event vocabulary for subscriptions/listen (2026-07-28, SEP-2575), shared by server and client.
Every event is a level trigger ("this changed, refetch if you care"), so both sides bound buffers by dedupe.
SUBSCRIPTION_ID_META_KEY
module-attribute
SUBSCRIPTION_ID_META_KEY = (
"io.modelcontextprotocol/subscriptionId"
)
The _meta key on every listen-stream frame; the value is the subscriptions/listen request's JSON-RPC id.
ToolsListChanged
dataclass
The server's tool list changed.
Source code in src/mcp/shared/subscriptions.py
40 41 42 | |
PromptsListChanged
dataclass
The server's prompt list changed.
Source code in src/mcp/shared/subscriptions.py
45 46 47 | |
ResourcesListChanged
dataclass
The server's resource list changed.
Source code in src/mcp/shared/subscriptions.py
50 51 52 | |
ResourceUpdated
dataclass
The resource at uri changed and may need to be read again.
Source code in src/mcp/shared/subscriptions.py
55 56 57 58 59 | |
ServerEvent
module-attribute
ServerEvent = (
ToolsListChanged
| PromptsListChanged
| ResourcesListChanged
| ResourceUpdated
)
An event a server publishes for delivery to listen subscribers.
event_to_notification
event_to_notification(
event: ServerEvent, meta: dict[str, Any]
) -> ServerNotification
Build the stamped wire notification for event (the server's direction).
Source code in src/mcp/shared/subscriptions.py
66 67 68 69 70 71 72 73 74 | |
LISTEN_STREAM_METHODS
module-attribute
LISTEN_STREAM_METHODS: frozenset[str] = frozenset(
{
*_LIST_CHANGED_EVENTS,
"notifications/resources/updated",
}
)
The notification methods that ride subscriptions/listen streams at 2026-07-28
(and, at that era, nowhere else): the change-notification vocabulary.
event_from_wire
event_from_wire(
method: str, params: Mapping[str, Any] | None
) -> ServerEvent | None
The event a raw listen-stream frame announces, or None if it carries none.
Takes the raw wire dict: the client demultiplexes before the typed notification parse.
Source code in src/mcp/shared/subscriptions.py
88 89 90 91 92 93 94 95 96 97 98 | |
event_matches
event_matches(
honored: SubscriptionFilter,
uris: frozenset[str],
event: ServerEvent,
) -> bool
Whether event is within the stream's honored filter (uris: the honored resource subscriptions as a set).
The admission predicate both sides share: server delivery and client intake honor only what was acknowledged.
Source code in src/mcp/shared/subscriptions.py
101 102 103 104 105 106 107 108 109 110 111 | |