Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233---title: pingsidebarTitle: ping---
# `fastmcp.server.middleware.ping`
Ping middleware for keeping client connections alive.
## Classes
### `PingMiddleware` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/ping.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Middleware that sends periodic pings to keep client connections alive.
Starts a background ping task on first message from each session. The tasksends server-to-client pings at the configured interval until the sessionends.
**Methods:**
#### `on_message` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/ping.py#L42" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_message(self, context: MiddlewareContext, call_next: CallNext) -> Any```
Start ping task on first message from a session.