Skip to main content

mcp_utils/
status.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4pub enum McpServerStatus {
5    Connected { tool_count: usize },
6    Authenticating,
7    Failed { error: String },
8    NeedsOAuth,
9}
10
11#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
12pub enum McpServerAuthCapability {
13    #[default]
14    Unavailable,
15    OAuth,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
19pub struct McpServerStatusEntry {
20    pub name: String,
21    pub status: McpServerStatus,
22    pub auth_capability: McpServerAuthCapability,
23    #[serde(default)]
24    pub proxied: bool,
25}
26
27impl McpServerStatusEntry {
28    pub fn new(name: impl Into<String>, status: McpServerStatus) -> Self {
29        Self { name: name.into(), status, auth_capability: McpServerAuthCapability::Unavailable, proxied: false }
30    }
31
32    pub fn with_auth_capability(mut self, auth: McpServerAuthCapability) -> Self {
33        self.auth_capability = auth;
34        self
35    }
36
37    pub fn with_proxied(mut self, proxied: bool) -> Self {
38        self.proxied = proxied;
39        self
40    }
41
42    pub fn can_authenticate(&self) -> bool {
43        self.auth_capability == McpServerAuthCapability::OAuth
44            && !matches!(self.status, McpServerStatus::Authenticating)
45    }
46}