pub struct McpServerManager { /* private fields */ }Expand description
Manages the lifecycle of one or more MCP servers.
Implementations§
Source§impl McpServerManager
impl McpServerManager
Sourcepub fn with_namespace(self, namespace: McpToolNamespace) -> Self
pub fn with_namespace(self, namespace: McpToolNamespace) -> Self
Sets the tool naming strategy for every adapter built by this manager.
Sourcepub fn set_namespace(&mut self, namespace: McpToolNamespace) -> &mut Self
pub fn set_namespace(&mut self, namespace: McpToolNamespace) -> &mut Self
Replaces the tool naming strategy in place.
Sourcepub fn namespace(&self) -> &McpToolNamespace
pub fn namespace(&self) -> &McpToolNamespace
Returns the active tool naming strategy.
Sourcepub fn with_handler_config(self, handler_config: McpHandlerConfig) -> Self
pub fn with_handler_config(self, handler_config: McpHandlerConfig) -> Self
Replaces the McpHandlerConfig applied to every connection this
manager opens.
Sourcepub fn set_handler_config(
&mut self,
handler_config: McpHandlerConfig,
) -> &mut Self
pub fn set_handler_config( &mut self, handler_config: McpHandlerConfig, ) -> &mut Self
Sets the McpHandlerConfig in place.
Sourcepub fn handler_config(&self) -> &McpHandlerConfig
pub fn handler_config(&self) -> &McpHandlerConfig
Returns the active McpHandlerConfig.
Sourcepub fn with_server(self, config: McpServerConfig) -> Self
pub fn with_server(self, config: McpServerConfig) -> Self
Registers a server configuration. Returns self for chaining.
Sourcepub fn with_server_options(
self,
config: McpServerConfig,
options: McpServerOptions,
) -> Self
pub fn with_server_options( self, config: McpServerConfig, options: McpServerOptions, ) -> Self
Registers a server configuration with lifecycle options. Returns
self for chaining.
Sourcepub fn register_server(&mut self, config: McpServerConfig) -> &mut Self
pub fn register_server(&mut self, config: McpServerConfig) -> &mut Self
Registers a server configuration by mutable reference.
Sourcepub fn register_server_with_options(
&mut self,
config: McpServerConfig,
options: McpServerOptions,
) -> &mut Self
pub fn register_server_with_options( &mut self, config: McpServerConfig, options: McpServerOptions, ) -> &mut Self
Registers a server configuration and lifecycle options by mutable reference.
Sourcepub fn connected_server(
&self,
server_id: &McpServerId,
) -> Option<&McpServerHandle>
pub fn connected_server( &self, server_id: &McpServerId, ) -> Option<&McpServerHandle>
Returns the handle for a connected server, or None if not connected.
Sourcepub fn connected_servers(&self) -> Vec<&McpServerHandle>
pub fn connected_servers(&self) -> Vec<&McpServerHandle>
Returns handles for all currently connected servers.
Sourcepub fn subscribe_catalog_events(&self) -> Receiver<McpCatalogEvent>
pub fn subscribe_catalog_events(&self) -> Receiver<McpCatalogEvent>
Subscribes to MCP catalog and lifecycle events.
Sourcepub async fn connect_server(
&mut self,
server_id: &McpServerId,
) -> Result<McpServerHandle, McpError>
pub async fn connect_server( &mut self, server_id: &McpServerId, ) -> Result<McpServerHandle, McpError>
Connects a single registered server by its identifier.
Sourcepub async fn connect_all(&mut self) -> Result<Vec<McpServerHandle>, McpError>
pub async fn connect_all(&mut self) -> Result<Vec<McpServerHandle>, McpError>
Connects all registered servers concurrently.
Sourcepub async fn connect_all_settled(&mut self) -> McpConnectAllSettled
pub async fn connect_all_settled(&mut self) -> McpConnectAllSettled
Connects all registered servers concurrently and waits for every connection attempt to settle.
Unlike Self::connect_all, this method does not fail fast. Every
server is attempted in parallel; successful connections are installed
into the manager and tool catalog, while each failed connection is
returned with its McpServerId and McpError.
Sourcepub async fn refresh_server(
&mut self,
server_id: &McpServerId,
) -> Result<McpDiscoverySnapshot, McpError>
pub async fn refresh_server( &mut self, server_id: &McpServerId, ) -> Result<McpDiscoverySnapshot, McpError>
Re-discovers capabilities for a connected server.
Sourcepub async fn refresh_changed_catalogs(
&mut self,
) -> Result<Vec<McpCatalogEvent>, McpError>
pub async fn refresh_changed_catalogs( &mut self, ) -> Result<Vec<McpCatalogEvent>, McpError>
Processes pending server list-change notifications.
Sourcepub async fn disconnect_server(
&mut self,
server_id: &McpServerId,
) -> Result<(), McpError>
pub async fn disconnect_server( &mut self, server_id: &McpServerId, ) -> Result<(), McpError>
Disconnects a server and removes it from active connections.
Sourcepub async fn resolve_auth(
&mut self,
resolution: AuthResolution,
) -> Result<(), McpError>
pub async fn resolve_auth( &mut self, resolution: AuthResolution, ) -> Result<(), McpError>
Stores or clears authentication credentials for a server.
Sourcepub fn tool_registry(&self) -> ToolRegistry
pub fn tool_registry(&self) -> ToolRegistry
Builds a one-shot snapshot ToolRegistry of every tool across all
connected servers. Use source instead when wiring
the manager into an [agentkit_loop::Agent] so tool catalog changes
flow through automatically.
Sourcepub fn source(&self) -> CatalogReader
pub fn source(&self) -> CatalogReader
Returns the manager’s federated CatalogReader.
The manager keeps an internal CatalogWriter in sync with every
connect, disconnect, and catalog refresh; the returned reader sees
the added/removed/changed tool sets via
[ToolSource::drain_catalog_events]. Pass it to
[agentkit_loop::AgentBuilder::tools] alongside any frozen native
ToolRegistry.
Each call returns a fresh reader subscription — events emitted before this call are not replayed. Call once at agent setup time and reuse.
Sourcepub fn capability_provider(&self) -> McpCapabilityProvider
pub fn capability_provider(&self) -> McpCapabilityProvider
Builds a combined McpCapabilityProvider from all connected servers.