pub struct ServerManager { /* private fields */ }Expand description
Manages all MCP server connections with lazy connection, idle timeout, and health checks.
Implementations§
Source§impl ServerManager
impl ServerManager
pub fn new(global_idle_timeout_minutes: u64) -> Self
Sourcepub fn register(&mut self, name: &str, entry: ServerEntry, config_hash: u64)
pub fn register(&mut self, name: &str, entry: ServerEntry, config_hash: u64)
Register or update a server definition (from config). Does not connect. If the server already exists, its entry is replaced and the old connection is dropped so that next use reconnects with the new config.
Sourcepub async fn ensure_connected(&mut self, name: &str) -> bool
pub async fn ensure_connected(&mut self, name: &str) -> bool
Ensure a server is connected (lazy connect). Returns true if connected/available.
Sourcepub fn get_client(&self, name: &str) -> Option<Arc<Mutex<McpClient>>>
pub fn get_client(&self, name: &str) -> Option<Arc<Mutex<McpClient>>>
Get a connected client for a server (must call ensure_connected first).
Sourcepub fn status(&self, name: &str) -> Option<ConnectionStatus>
pub fn status(&self, name: &str) -> Option<ConnectionStatus>
Get the connection status for a server.
Sourcepub fn mark_failed(&mut self, name: &str)
pub fn mark_failed(&mut self, name: &str)
Mark a connection as failed after a tool call error.
Sourcepub fn touch(&mut self, name: &str)
pub fn touch(&mut self, name: &str)
Touch a server (update last_used timestamp, e.g. after successful tool call).
Sourcepub async fn disconnect(&mut self, name: &str)
pub async fn disconnect(&mut self, name: &str)
Disconnect a server (idle shutdown).
Sourcepub fn idle_timeout(&self, name: &str) -> Duration
pub fn idle_timeout(&self, name: &str) -> Duration
Get the idle timeout for a server (per-server override or global default).
Sourcepub async fn sweep_idle(&mut self)
pub async fn sweep_idle(&mut self)
Check for idle servers and disconnect them.
Sourcepub fn server_names(&self) -> Vec<String>
pub fn server_names(&self) -> Vec<String>
Get a list of all registered server names.
Sourcepub fn remove(&mut self, name: &str)
pub fn remove(&mut self, name: &str)
Synchronously remove a server entry, dropping any existing connection. The client Arc is dropped; in-flight calls holding a clone of the Arc can still complete.
Sourcepub fn should_connect_eagerly(&self, name: &str) -> bool
pub fn should_connect_eagerly(&self, name: &str) -> bool
Check if a server should be connected eagerly at startup.
Sourcepub fn config_hash(&self, name: &str) -> Option<u64>
pub fn config_hash(&self, name: &str) -> Option<u64>
Get the config hash for a server.