Expand description
§rmcp_mux - MCP Server Multiplexer
A library for multiplexing MCP (Model Context Protocol) servers, allowing a single server process to serve multiple clients via Unix sockets.
§Features
- Single server, multiple clients: One MCP server child process serves many clients
- Initialize caching: First initialize response is cached for subsequent clients
- Request ID rewriting: Transparent request routing with ID collision avoidance
- Automatic restarts: Exponential backoff restart of failed server processes
- Active client limiting: Semaphore-based concurrency control
§Usage as Library
use rmcp_mux::{MuxConfig, run_mux_server};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = MuxConfig::new("/tmp/my-mcp.sock", "npx")
.with_args(vec!["-y".into(), "@anthropic/mcp-server".into()])
.with_max_clients(10)
.with_service_name("my-mcp-server");
run_mux_server(config).await
}§Usage with Multiple Mux Instances
use rmcp_mux::{MuxConfig, spawn_mux_server, MuxHandle};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Spawn multiple mux servers in a single process
let handles: Vec<MuxHandle> = vec![
spawn_mux_server(MuxConfig::new("/tmp/mcp1.sock", "server1")).await?,
spawn_mux_server(MuxConfig::new("/tmp/mcp2.sock", "server2")).await?,
];
// Wait for all to complete (or shutdown signal)
for handle in handles {
handle.wait().await?;
}
Ok(())
}Re-exports§
pub use config::CliOptions;pub use config::Config;pub use config::ResolvedParams;pub use config::ServerConfig;pub use runtime::MAX_PENDING;pub use runtime::MAX_QUEUE;pub use runtime::health_check;pub use runtime::run_mux;pub use runtime::run_mux_internal;pub use runtime::run_proxy;pub use state::MuxState;pub use state::ServerStatus;pub use state::StatusSnapshot;
Modules§
- config
- Configuration types and loading for rmcp_mux.
- runtime
- Runtime module for the mux daemon.
- scan
- state
- tray
- wizard
- Interactive wizard for configuring rmcp_mux services and rewiring MCP clients.
Structs§
- MuxConfig
- Configuration for embedding rmcp_mux in your application.
- MuxHandle
- Handle for a spawned mux server.
Constants§
Functions§
- check_
health - Perform a health check on a mux socket.
- run_
mux_ server - Run a mux server blocking until shutdown.
- run_
mux_ with_ shutdown - Run mux with external shutdown control.
- spawn_
mux_ server - Spawn a mux server as a background task.