fastmcp.experimental.events.subscription
Client functions for the MCP Events extension: list, poll and subscribe.
Experimental: this API may change in any release without a deprecation period.
Functions
list_events_mcp
events/list request and return its protocol result.
Args:
cursor: Optional pagination cursor from a previous result.
RuntimeError: If the client is disconnected or Events was not negotiated.MCPError: If the server rejects the request.
list_events
max_pages: Maximum number of pages to fetch before raising.
RuntimeError: If Events was not negotiated or the page limit is reached.MCPError: If the server rejects a request.
poll_events_mcp
events/poll request and return its protocol result.
Args:
name: Event type to poll.arguments: Subscription arguments matching the eventβs input schema.cursor: Position from a previous poll.Nonestarts from now: the server returns no events and a cursor for later polls.max_age_ms: Do not replay events older than this.max_events: Cap on the number of events returned.
RuntimeError: If the client is disconnected or Events was not negotiated.MCPError: If the server rejects the request.
subscribe_events
events/stream request open
and the server writes events to it; a stream that is cut off or goes
quiet is reopened from the cursor a few times before the error is raised. With poll delivery the client asks
on the interval the server recommends and drains a backlog without
waiting. Either way events already yielded are dropped, and the
subscription runs only while iterated: leaving the async for ends it.
Args:
name: Event type to subscribe to.arguments: Subscription arguments matching the eventβs input schema.cursor: Position to resume from.Nonestarts from now.max_age_ms: Do not replay events older than this.max_events: Cap on the number of events per poll.min_poll_interval: Shortest wait between polls, in seconds, whatever the server recommends.delivery:"push"or"poll". By default the subscription uses push when the event type offers it and poll otherwise.
Classes
EventBacklogFullError
A push subscriptionβs consumer fell so far behind that frames were lost.
The subscription has ended. Its cursor is the last cursor the server
confirmed, which can be the start of the batch that overflowed, so
resubscribing from it repeats events rather than skipping them. A push
batch larger than the buffer overflows again on every retry; a consumer
that cannot keep up should poll with max_events instead.
EventSubscription
One subscription to an event type, iterated with async for.
cursor is the position to resume from: at or before the last event
yielded, never after an event not yet yielded. Persist it and pass
it to subscribe_events(client, ..., cursor=...) to resume after a restart. truncated
is set once the server reports that it skipped events the cursor asked for.