turbomcp_server/handlers/traits/
ping.rs1use async_trait::async_trait;
4use serde_json::Value;
5use turbomcp_protocol::RequestContext;
6use turbomcp_protocol::types::{PingRequest, PingResult};
7
8use crate::ServerResult;
9
10#[async_trait]
12pub trait PingHandler: Send + Sync {
13 async fn handle(&self, request: PingRequest, ctx: RequestContext) -> ServerResult<PingResult>;
15
16 async fn get_health_status(&self, _ctx: RequestContext) -> ServerResult<Value> {
18 Ok(serde_json::json!({
19 "status": "healthy",
20 "timestamp": chrono::Utc::now().to_rfc3339(),
21 }))
22 }
23
24 async fn get_connection_metrics(&self, _ctx: RequestContext) -> ServerResult<Option<Value>> {
26 Ok(None) }
28
29 async fn handle_timeout(&self, _request_id: &str, _ctx: RequestContext) -> ServerResult<()> {
31 Ok(())
32 }
33
34 fn include_health_details(&self) -> bool {
36 false
37 }
38
39 fn response_threshold_ms(&self) -> u64 {
41 5_000 }
43
44 async fn process_ping_payload(
46 &self,
47 payload: Option<&Value>,
48 _ctx: RequestContext,
49 ) -> ServerResult<Option<Value>> {
50 Ok(payload.cloned())
52 }
53}