What is MCP Rust SDK?
MCP Rust SDK is the official Rust implementation of the Model Context Protocol, the open standard for letting AI applications call tools, read resources and use prompts hosted by an outside process. It sits in the Agent Frameworks & Builders category of the Agents & Automation tools and is open-source, written in Rust and licensed Apache-2.0 for new contributions, with existing code under MIT.
Overview
MCP Rust SDK is the official Rust implementation of the Model Context Protocol, the open standard for letting AI applications call tools, read resources and use prompts hosted by an outside process. It is published on crates.io as `rmcp`, built on the Tokio async runtime, and covers both roles: a server that exposes capabilities to an assistant, and a client that connects to any MCP server and calls them. A companion crate, `rmcp-macros`, supplies the procedural macros that generate the tool plumbing.
Writing a server mostly means writing an `impl` block. You mark methods with `#[tool]`, put `#[tool_router]` on the block, and derive `serde::Deserialize` plus `schemars::JsonSchema` on the parameter struct; the SDK builds each tool's input and output JSON Schema (draft 2020-12) from the field names, types and doc comments. For servers that also need prompts, resources or custom metadata, you implement the `ServerHandler` trait and enable the matching capabilities yourself.
The crate is split into Cargo features, so a binary only compiles what it uses: `server` and `macros` are on by default, while `client`, `auth` (OAuth 2.1), `elicitation` and each transport are opt-in. Transports are pluggable — stdio for local subprocess servers, Streamable HTTP exposed as a Tower service you mount on an axum or hyper router, and any type implementing the `Transport` trait. The project deliberately ships no legacy two-endpoint HTTP+SSE transport, pointing users to Streamable HTTP instead.
What it does
- `#[tool]`, `#[tool_router]` and `#[tool_handler]` macros that wire Rust methods up as MCP tools, with JSON Schema derived through `schemars`
- Server and client in one crate, gated by Cargo features (`server`, `client`, `macros`, `auth`, `elicitation`) so unused parts stay out of the build
- stdio, child-process and Streamable HTTP transports, plus a `Transport` trait for custom ones; the HTTP server is a Tower service for axum or hyper
- Coverage of the wider protocol: resources, prompts, sampling, elicitation, roots, logging, completions, subscriptions, pagination and long-running tasks
- Client-side response caching that honours server TTL hints and is invalidated by list-changed and resource-updated notifications
- OAuth 2.1 client support with PKCE (S256), dynamic client registration, metadata discovery and automatic token refresh
Getting started
Add the rmcp crate with the server features, write a tools-only server as an annotated impl block, run it over stdio for a desktop client, then connect to MCP servers from Rust with the client side of the same crate.
Add the dependencies
The README's import is `cargo add rmcp --features server`; the stdio server below also uses the `transport-io` feature and the `schemars` re-export, and the README lists tokio and serde as the base dependencies. Add the `client` feature when you need the client side.
cargo add rmcp --features server,macros,schemars,transport-io
cargo add tokio --features macros,rt-multi-thread,io-std
cargo add serde --features derive
cargo add anyhowWrite a tools-only server
This is the calculator from the README. `#[tool_router(server_handler)]` generates the `ServerHandler` implementation, so a tools-only server needs no separate trait impl; the `AddParams` fields become the tool's input schema. `serve(stdio())` speaks MCP over stdin and stdout.
use rmcp::{handler::server::wrapper::Parameters, schemars, tool, tool_router, ServiceExt, transport::stdio};
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
struct AddParams {
a: i32,
b: i32,
}
#[derive(Clone)]
struct Calculator;
#[tool_router(server_handler)]
impl Calculator {
#[tool(description = "Add two numbers")]
fn add(&self, Parameters(AddParams { a, b }): Parameters<AddParams>) -> String {
(a + b).to_string()
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let service = Calculator.serve(stdio()).await?;
service.waiting().await?;
Ok(())
}Try a server from Claude Desktop or the Inspector
The repository's examples include a counter server. Build it in release mode, then point an `mcpServers` entry in `claude_desktop_config.json` at the binary (on Windows the path ends in `.exe`). The MCP Inspector (`npx @modelcontextprotocol/inspector`) is the other way the examples suggest for calling tools by hand.
cargo build --release -p mcp-server-examples --example servers_counter_stdio
# claude_desktop_config.json
{
"mcpServers": {
"counter": {
"command": "PATH-TO/rust-sdk/target/release/examples/servers_counter_stdio",
"args": []
}
}
}Connect to a server as a client
With the `client` and `transport-child-process` features, `TokioChildProcess` launches a server binary and talks to it over its stdio. Once connected, `list_all_tools()` walks every page of the tool list and `call_tool` invokes one by name.
use rmcp::{ServiceExt, transport::{TokioChildProcess, ConfigureCommandExt}};
use tokio::process::Command;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ().serve(TokioChildProcess::new(Command::new("npx").configure(|cmd| {
cmd.arg("-y").arg("@modelcontextprotocol/server-everything");
}))?).await?;
let tools = client.list_all_tools().await?;
Ok(())
}Serve over Streamable HTTP
With the `transport-streamable-http-server` feature, `StreamableHttpService` wraps a handler factory as a Tower service that you nest on an axum router (`Counter` is the handler from the repository's examples). Without per-session state the factory runs per request, so keep shared state such as database pools in a cloneable handle captured by the closure.
use rmcp::transport::streamable_http_server::{
StreamableHttpService, StreamableHttpServerConfig,
session::local::LocalSessionManager,
};
let config = StreamableHttpServerConfig::default()
.with_legacy_session_mode(false) // stateless for legacy versions too
.with_json_response(true); // plain JSON replies for simple tools
let service = StreamableHttpService::new(
|| Ok(Counter::new()), // a fresh handler per request
LocalSessionManager::default().into(),
config,
);
let router = axum::Router::new().nest_service("/mcp", service);Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Ship an MCP server as a single compiled Rust binary that a desktop assistant or coding agent launches over stdio
- Add an MCP endpoint to an existing axum or hyper web service by mounting the Streamable HTTP Tower service on its router
- Build a Rust agent or desktop app that connects to third-party MCP servers, lists their tools and calls them
- Put OAuth 2.1 in front of a hosted MCP server, or authenticate a Rust client against one
How MCP Rust SDK compares
MCP Rust SDK alongside other open-source agent frameworks & builders tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| DeepSeek Harness | ★ 289k | DeepSeek AI's open-source agent harness (dsh), built on Cordis, where models, tools, skills, sessions, sandboxes, storage and the UI are all plugins composed through profiles. |
| AutoGPT | ★ 188k | One of the earliest autonomous agent projects, now a platform for building and running agents from reusable blocks and workflows. |
| DeerFlow | ★ 86k | ByteDance's open-source super agent harness built on LangGraph: skills, sub-agents, sandboxes, a filesystem and long-term memory for long-horizon research, coding and content tasks. |
| nanobot | ★ 50.5k | Lightweight self-hosted personal AI agent framework in Python, with a WebUI, terminal and chat-app channels, tools, long-term memory, MCP and scheduled automations. |
| LangGraph | ★ 45.6k | A library from the LangChain team for building stateful, graph-based agent workflows with explicit control over steps, memory, and human-in-the-loop checkpoints. |
| Agno | ★ 43.3k | A fast Python framework (formerly Phidata) for building agents with memory, tools, and multimodal inputs, plus a runtime for deploying them in production. |
| AgentGPT | ★ 36.3k | AgentGPT lets you name a custom AI, give it a goal, and watch it plan tasks, run them, and learn from the results, all from a web browser. |
| MCP Rust SDK | ★ 4.2k | The official Rust SDK (the rmcp crate) for Model Context Protocol servers and clients |
