Skip to main content

utils/
mcp_status.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
5#[serde(tag = "type", rename_all = "snake_case", rename_all_fields = "camelCase")]
6pub enum McpServerStatus {
7    Connecting,
8    Connected {
9        tool_count: usize,
10    },
11    Authenticating,
12    Failed {
13        error: String,
14    },
15    #[serde(rename = "needs_oauth")]
16    NeedsOAuth,
17}
18
19#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default, JsonSchema)]
20#[serde(rename_all = "lowercase")]
21pub enum McpServerAuthCapability {
22    #[default]
23    Unavailable,
24    OAuth,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
28#[serde(rename_all = "camelCase")]
29pub struct McpServerStatusEntry {
30    pub name: String,
31    pub status: McpServerStatus,
32    pub auth_capability: McpServerAuthCapability,
33    #[serde(rename = "deferTools", default)]
34    pub deferred_tools: bool,
35}
36
37impl McpServerStatusEntry {
38    pub fn new(name: impl Into<String>, status: McpServerStatus) -> Self {
39        Self { name: name.into(), status, auth_capability: McpServerAuthCapability::Unavailable, deferred_tools: false }
40    }
41
42    pub fn with_auth_capability(mut self, auth: McpServerAuthCapability) -> Self {
43        self.auth_capability = auth;
44        self
45    }
46
47    pub fn with_deferred_tools(mut self, deferred_tools: bool) -> Self {
48        self.deferred_tools = deferred_tools;
49        self
50    }
51
52    pub fn can_authenticate(&self) -> bool {
53        self.auth_capability == McpServerAuthCapability::OAuth
54    }
55}