fastmcp.server.tasks.notifications
Distributed notification queue for background task events (SEP-1686).
Enables distributed Docket workers to send MCP notifications to clients
without holding session references. Workers push to a Redis queue,
the MCP server process subscribes and forwards to the client’s session.
Pattern: Fire-and-forward with retry
- One queue per session_id
- LPUSH/BRPOP for reliable ordered delivery
- Retry up to 3 times on delivery failure, then discard
- TTL-based expiration for stale messages
Functions
push_notification
session_id: Target session’s identifiernotification: MCP notification dict (method, params, _meta)docket: Docket instance for Redis access
notification_subscriber_loop
- Maintains a heartbeat (active subscriber marker for debugging)
- Blocks on BRPOP waiting for notifications
- Forwards notifications to the client’s session
- Retries failed deliveries, then discards (no dead-letter queue)
session_id: Session identifier to subscribe tosession: MCP ServerSession for sending notificationsdocket: Docket instance for Redis accessfastmcp: FastMCP server instance (for elicitation relay)
ensure_subscriber_running
session_id: Session identifiersession: MCP ServerSessiondocket: Docket instancefastmcp: FastMCP server instance (for elicitation relay)
stop_subscriber
session_id: Session identifier

