pub struct McpServerManager { /* private fields */ }Expand description
Manages the lifecycle of one or more MCP servers and their tools.
Call McpServerManager::register_all to spawn every configured server,
discover its tools, and register them into a ToolRegistry. The manager
keeps the underlying McpClients alive so they can handle tool calls.
Implementations§
Source§impl McpServerManager
impl McpServerManager
Sourcepub fn new(servers: Vec<McpServer>) -> Self
pub fn new(servers: Vec<McpServer>) -> Self
Create a new manager from a list of server configurations.
The servers are not spawned until register_all is called.
Sourcepub async fn register_all(
&self,
registry: &mut ToolRegistry,
) -> Result<Vec<(String, usize)>>
pub async fn register_all( &self, registry: &mut ToolRegistry, ) -> Result<Vec<(String, usize)>>
Spawn all configured servers, discover their tools, and register them
into the given ToolRegistry.
Returns a list of (server_name, tool_count) pairs for logging.
§Errors
Returns an error if any server fails to start or if tool discovery fails. Servers are started sequentially; a failure stops the process.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Shut down all running MCP clients.
This drops the clients, which causes their background tasks (stdio reader/writer, SSE listener) to be cancelled.
Sourcepub async fn running_count(&self) -> usize
pub async fn running_count(&self) -> usize
Return the number of currently running clients.