MCP Runner
About
MCP Runner is a Rust library for running and interacting with Model Context Protocol (MCP) servers locally. It provides a complete solution for managing MCP server processes, communicating via JSON-RPC, and optionally proxying Server-Sent Events (SSE) to enable client…
Details
- License
- MIT
Explore
- Unified JSON-RPC API: Single endpoint for all MCP server interactions via JSON-RPC
- Authentication: Optional Bearer token authentication for secure access
- Server Access Control: Restrict which servers can be accessed through the proxy
- Event Streaming: Real-time updates from MCP servers to clients via SSE
- Cross-Origin Support: Built-in CORS support for web browser clients
- JSON-RPC Compatibility: Full support for JSON-RPC 2.0 messages in both directions
- Efficient Event Broadcasting: Uses Tokio broadcast channels for efficient event distribution
Add this to your Cargo.toml:
[dependencies]
mcp-runner = "0.3.1"
Configure the SSE proxy in your configuration file:
{
"mcpServers": { / server configs / },
"sseProxy": {
"address": "127.0.0.1", // Listen address (localhost only) - default if omitted
"port": 3000, // Port to listen on - default if omitted
"workers": 4, // Number of worker threads - default is 4 if omitted
"allowedServers": [ // Optional: restrict which servers can be accessed
"fetch",
"filesystem"
],
"authenticate": { // Optional: require authentication
"bearer": {
"token": "your-secure-token-here"
}
}
}
}
A Rust library for running and interacting with Model Context Protocol (MCP) servers locally.
Overview
MCP Runner provides a complete solution for managing Model Context Protocol servers in Rust applications. It enables:
- Starting and managing MCP server processes
- Configuring multiple servers through a unified interface
- Communicating with MCP servers using JSON-RPC
- Listing and calling tools exposed by MCP servers
- Accessing resources provided by MCP servers
- Proxying Server-Sent Events (SSE) to enable clients to connect to MCP servers
Installation
Add this to your Cargo.toml:
[dependencies]
mcp-runner = "0.3.1"
Quick Start
Here's a simple example of using MCP Runner to start a server and call a tool:
use mcp_runner::{McpRunner, error::Result};
use serde::{Deserialize, Serialize};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<()> {
// Create runner from config file
let mut runner = McpRunner::from_config_file("config.json")?;
// Start all servers and the SSE proxy if configured
let (server_ids, proxy_started) = runner.start_all_with_proxy().await;
let server_ids = server_ids?;
if proxy_started {
println!("SSE proxy started successfully");
}
// Get client for interacting with a specific server
let server_id = runner.get_server_id("fetch")?;
let client = runner.get_client(server_id)?;
// Initialize the client
client.initialize().await?;
// List available tools
let tools = client.list_tools().await?;
println!("Available tools:");
for tool in tools {
println!(" - {}: {}", tool.name, tool.description);
}
// Call the fetch tool with structured input
let fetch_result = client.call_tool("fetch", &json!({
"url": "https://modelcontextprotocol.io"
})).await?;
println!("Fetch result: {}", fetch_result);
// Stop the server when done
runner.stop_server(server_id).await?;
Ok(())
}
Observability
This library uses the tracing crate for logging and diagnostics. To enable logging, ensure you have a tracing_subscriber configured in your application and set the RUST_LOG environment variable. For example:
```bash
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



