Skip to main content

Module server_hub

Module server_hub 

Source
Expand description

McpServerHub - A hub that aggregates multiple MCP servers into a single server.

The McpServerHub connects to multiple external MCP servers and exposes their tools as a unified MCP server that can be wrapped by McpStdioServer or McpHttpServer.

§Example

use mcp::{McpServerHub, McpServerConnectionConfig};
use mcp::server::stdio::McpStdioServer;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a hub that aggregates multiple servers
    let hub = McpServerHub::new("aggregator");

    // Connect to external servers
    let calc_config = McpServerConnectionConfig::stdio(
        "calculator",
        "node",
        vec!["calc-server.js".into()],
    );
    hub.connect(calc_config).await?;

    let files_config = McpServerConnectionConfig::stdio(
        "files",
        "python",
        vec!["files-server.py".into()],
    );
    hub.connect(files_config).await?;

    // Run as a stdio server - all connected tools are now exposed
    McpStdioServer::run(hub.into_config()).await?;
    Ok(())
}

Structs§

McpServerHub
A hub that aggregates multiple MCP servers into a single MCP server.