pub struct McpBridge { /* private fields */ }Expand description
MCP bridge — connects multiple MCP servers to the tool system.
McpBridge owns the collection of registered MCP server configurations
and manages McpClient instances for active servers.
§Example
let mut bridge = McpBridge::new();
bridge.register_server(McpServer::new("files", "npx")
.with_args(vec!["-y", "@anthropic/mcp-server-filesystem"]));
// Initialize all servers
bridge.initialize_all().await?;
// List all tools across all servers
let tools = bridge.list_tools().await?;Implementations§
Source§impl McpBridge
impl McpBridge
Sourcepub fn register_server(&self, server: McpServer)
pub fn register_server(&self, server: McpServer)
Register an MCP server configuration (does not start the process).
Sourcepub fn get_server(&self, name: &str) -> Option<McpServer>
pub fn get_server(&self, name: &str) -> Option<McpServer>
Get a server configuration by name.
Sourcepub async fn initialize_all(&self) -> Result<(), Error>
pub async fn initialize_all(&self) -> Result<(), Error>
Initialize all enabled MCP servers.
Each server is spawned as a child process and receives the initialize request. Servers that fail to initialize are logged but do not cause a total failure.
Sourcepub async fn initialize_server(&self, name: &str) -> Result<(), Error>
pub async fn initialize_server(&self, name: &str) -> Result<(), Error>
Initialize a specific server by name.
Sourcepub async fn list_tools(&self) -> Result<Vec<McpTool>, Error>
pub async fn list_tools(&self) -> Result<Vec<McpTool>, Error>
List all available tools from all initialized MCP servers.
Tools are collected from each server’s cache (refreshed on demand).
Sourcepub async fn cached_tools(&self, server_name: &str) -> Option<Vec<McpTool>>
pub async fn cached_tools(&self, server_name: &str) -> Option<Vec<McpTool>>
Get cached tools for a specific server.
Sourcepub async fn call_tool(
&self,
server_name: &str,
tool_name: &str,
args: Value,
) -> Result<McpToolCallResult, Error>
pub async fn call_tool( &self, server_name: &str, tool_name: &str, args: Value, ) -> Result<McpToolCallResult, Error>
Call an MCP tool on a specific server.
Sourcepub async fn shutdown_all(&self) -> Result<(), Error>
pub async fn shutdown_all(&self) -> Result<(), Error>
Shutdown all connected MCP server processes.
Sourcepub async fn refresh_tools(
&self,
server_name: &str,
) -> Result<Vec<McpTool>, Error>
pub async fn refresh_tools( &self, server_name: &str, ) -> Result<Vec<McpTool>, Error>
Refresh tools from a specific server.
Sourcepub async fn clear_cache(&self, server_name: &str)
pub async fn clear_cache(&self, server_name: &str)
Clear the tool cache for a server.
Sourcepub async fn remove_server(&self, name: &str) -> Result<(), Error>
pub async fn remove_server(&self, name: &str) -> Result<(), Error>
Remove a server by name (disconnects client if active, removes config).
Sourcepub async fn toggle_server(&self, name: &str) -> Result<bool, Error>
pub async fn toggle_server(&self, name: &str) -> Result<bool, Error>
Toggle a server’s enabled flag. Returns the new enabled state.
Sourcepub async fn clear_all_caches(&self)
pub async fn clear_all_caches(&self)
Clear all caches.