modelcontextprotocol/rust-sdk
The official Rust SDK for the Model Context Protocol
RMCP – Rust Model Context Protocol SDK
What it is
- An official Rust implementation of the Model Context Protocol (MCP), a specification for communication between AI agents (clients) and AI‑powered services (servers).
- Provides both a client and server library that run on the Tokio async runtime.
- Includes a procedural‑macro crate (
rmcp-macros) that generates boilerplate for tools, prompts, resources, subscriptions, and other MCP capabilities.
Key capabilities (as of the 2026‑07‑28 spec)
- Server discovery & version negotiation – clients can discover a server’s supported protocol versions and capabilities before any request.
- Transport‑neutral subscriptions – long‑running streams of updates (e.g., resource changes, notifications) work over any transport (stdio, child‑process, HTTP, etc.).
- Multi‑round‑trip requests – a single logical request can involve several back‑and‑forth messages.
- Response caching – built‑in support for cached responses to avoid redundant work.
- Standard HTTP routing headers – MCP messages can carry HTTP‑style headers for routing, authentication, etc.
- Tools, Prompts, Resources – first‑class abstractions for callable functions, reusable message templates, and data blobs, all described with JSON‑Schema 2020‑12.
- OAuth support – the SDK can attach OAuth tokens to requests.
Typical use‑cases
- Building AI agents that call remote tools (e.g., calculators, image generators) via a standard protocol.
- Exposing LLM‑backed services (code reviewers, summarizers) as MCP servers that any client can discover and invoke.
- Implementing RAG pipelines where resources (files, DB rows) are served over MCP and cached on the client side.
- Creating plug‑and‑play tool ecosystems where third‑party developers publish tool crates that can be auto‑discovered.
How to get started
# Add the core crate (with server features) to your Cargo.toml
cargo add rmcp --features server
Or pull the latest development version directly from GitHub:
cargo add rmcp --features server \
--git https://github.com/modelcontextprotocol/rust-sdk --branch main
Minimal client example
use rmcp::{ServiceExt, transport::TokioChildProcess, ConfigureCommandExt};
use tokio::process::Command;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Spawn a server process (here the npm package that implements the reference server)
let client = ().serve(
TokioChildProcess::new(Command::new("npx").configure(|cmd| {
cmd.arg("-y").arg("@modelcontextprotocol/server-everything");
}))
)?.await?;
// Example request – list the server’s roots
let roots = client.list_roots().await?;
println!("Roots: {:?}", roots);
Ok(())
}
Minimal server example (a simple calculator)
use rmcp::{tool, tool_router, ServiceExt, transport::stdio};
use serde::Deserialize;
#[derive(Debug, Deserialize, schemars::JsonSchema)]
struct AddParams { a: i32, b: i32 }
#[tool_router(server_handler)]
struct Calculator;
impl Calculator {
#[tool(description = "Add two numbers")]
fn add(&self, params: rmcp::handler::server::wrapper::Parameters<AddParams>) -> String {
(params.0.a + params.0.b).to_string()
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let service = Calculator.serve(stdio()).await?;
service.waiting().await?;
Ok(())
}
The macros generate the JSON‑Schema for the tool’s parameters and wire the RPC routing automatically.
Project structure
crates/rmcp– core protocol implementation, client & server runtimes, models, transports.crates/rmcp-macros– procedural macros (#[tool],#[prompt],#[resource], etc.) that reduce boilerplate.examples/– ready‑to‑run demos for servers (calculator, counter) and clients (everything over stdio).
Maturity & ecosystem
- Published on crates.io (
rmcpcrate) with CI badges indicating automated testing. - Implements the stable MCP spec (2026‑07‑28) while remaining backward compatible with the 2025‑11‑25 version.
- Documentation hosted on docs.rs; the full MCP spec lives at
modelcontextprotocol.io. - Community discussion for migration to newer spec versions is provided via a GitHub discussion link.
Where to learn more
- Specification: https://modelcontextprotocol.io/specification/2026-07-28
- Crate docs: https://docs.rs/rmcp/latest/rmcp
- GitHub repo: https://github.com/modelcontextprotocol/rust-sdk
- Migration guide: https://github.com/modelcontextprotocol/rust-sdk/discussions/969
The SDK is a genuine, production‑grade Rust library for building AI‑agent communication services that follow the Model Context Protocol.
Related
- Project
- Project
- Project
- Project
- Project