--- title: ping sidebarTitle: ping --- # `fastmcp.server.middleware.ping` Ping middleware for keeping client connections alive. ## Classes ### `PingMiddleware` Middleware that sends periodic pings to keep client connections alive. Starts a background ping task on first message from each session. The task sends server-to-client pings at the configured interval until the session ends. **Methods:** #### `on_message` ```python on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any ``` Start ping task on first message from a session.