Skip to main content

kotoba/
status.rs

1use serde::Serialize;
2use std::time::Instant;
3
4/// Standardized status/health information for MCP servers.
5///
6/// Every pleme-io MCP server should expose a `status` tool that returns
7/// this struct (or a superset of it).
8#[derive(Debug, Clone, Serialize)]
9pub struct StatusInfo {
10    pub name: String,
11    pub version: String,
12    pub uptime_secs: u64,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub status: Option<String>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub details: Option<serde_json::Value>,
17}
18
19/// Tracks server start time for uptime calculation.
20pub struct UptimeTracker {
21    started: Instant,
22}
23
24impl UptimeTracker {
25    pub fn new() -> Self {
26        Self { started: Instant::now() }
27    }
28
29    pub fn uptime_secs(&self) -> u64 {
30        self.started.elapsed().as_secs()
31    }
32
33    /// Build a `StatusInfo` with the current uptime.
34    pub fn status(&self, name: &str, version: &str) -> StatusInfo {
35        StatusInfo {
36            name: name.to_string(),
37            version: version.to_string(),
38            uptime_secs: self.uptime_secs(),
39            status: Some("healthy".to_string()),
40            details: None,
41        }
42    }
43}
44
45impl Default for UptimeTracker {
46    fn default() -> Self {
47        Self::new()
48    }
49}