turbomcp_protocol/types/
ping.rs

1//! Connection testing types
2//!
3//! This module contains types for MCP ping functionality,
4//! allowing connection health checking between clients and servers.
5
6use serde::{Deserialize, Serialize};
7
8/// Ping request parameters (optional data)
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10pub struct PingParams {
11    /// Optional data to echo back
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub data: Option<serde_json::Value>,
14}
15
16/// Ping request wrapper
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct PingRequest {
19    /// Ping parameters
20    #[serde(flatten)]
21    pub params: PingParams,
22}
23
24/// Ping result (echoes back the data)
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct PingResult {
27    /// Echoed data from the request
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub data: Option<serde_json::Value>,
30    /// Optional metadata per MCP 2025-06-18 specification
31    #[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
32    pub _meta: Option<serde_json::Value>,
33}
34
35impl PingResult {
36    /// Create a new ping result
37    pub fn new(data: Option<serde_json::Value>) -> Self {
38        Self { data, _meta: None }
39    }
40
41    /// Create a ping result with no data
42    pub fn empty() -> Self {
43        Self::new(None)
44    }
45
46    /// Add metadata to this result
47    pub fn with_meta(mut self, meta: serde_json::Value) -> Self {
48        self._meta = Some(meta);
49        self
50    }
51}