一个高性能的异步工具包,用于在 Rust 中构建 MCP 服务器和客户端。
This SDK fully implements the MCP 2026-07-28 stateless protocol and passes 100% of official MCP conformance tests (110/110 server, 440/440 client).
rust-mcp-sdk provides the necessary components for developing both servers and clients in the MCP ecosystem. It leverages the rust-mcp-schema crate for type-safe schema objects and includes powerful procedural macros.
Focus on your application logic, rust-mcp-sdk handles the protocol, transports, and the rest.
⚠️ Version notice: This is
rust-mcp-sdk2.x, implementing the new MCP 2026-07-28 (stateless) specification. For the previous MCP 2025-11-25 specification, userust-mcp-sdk1.x:rust-mcp-sdk = "1"See the upgrade guide to migrate from 1.x to 2.0.
Version matrix:
SDK version Protocol Branch 2.0 MCP 2026-07-28 (stateless) main1.x (LTS) MCP 2025-11-25 release-1.xUpgrading? See the upgrade guide.
Key Features
_meta with RequestContextiss validation (SEP-2468)Add to your Cargo.toml:
[dependencies]
rust-mcp-sdk = "2.0.0" # Check crates.io for the latest version…Creating a Streamable HTTP MCP server in rust-mcp-sdk allows multiple clients to connect simultaneously with no additional setup. The setup is nearly identical to the stdio example , the only difference is which HTTP backend crate you install and which function you call to create the server.
Post only - the 2026-07-28 protocol is stateless. GET and DELETE endpoints return 405 Method Not Allowed.
rust-mcp-axum)Add rust-mcp-axum to your dependencies and use create_axum_server() with AxumServerOptions.
…rust-mcp-actix)Add rust-mcp-actix to your dependencies and use create_actix_server() with ActixServerOptions.
…Both backends support a BYO-server (Bring Your Own Server) mode, letting you mount MCP endpoints onto a router or app you already control - no need to hand over the server lifecycle.
| Backend | Function | Docs |
|---|---|---|
| Axum | mcp_routes(state, &mount_opts, http_handler) |
rust-mcp-axum README |
| Actix-web | mcp_scope(state, http_handler, &mount_opts) |
rust-mcp-actix README |
The SDK is completely framework-agnostic. If you are using a different HTTP framework (like Rocket, Salvo, or Warp), you can build a custom integration by adapting your framework's native Request/Response types to the SDK's core HTTP handling logic.
See the Custom HTTP Framework Integration Guide for architectural details.
Axum server is highly customizable through AxumServerOptions:
let server = create_axum_server(
server_details,
handler.to_mcp_server_handler(),
AxumServerOptions {
host: "127.0.0.1".to_string(),
port: 8080,
auth: Some(Arc::new(auth_provider)), // enable authentication
health_endpoint: Some("/health".into()), // health check
sse_support: true, // backward-compat SSE
..Default::default()
},
);
server.start().await?;allowed_hosts is not set, it auto-derives from host:port.Following is implementation of an MCP client that starts the @modelcontextprotocol/server-everything server, discovers the server's capabilities, lists available tools, and calls a tool.
…For more examples (stdio, Streamable HTTP, clients, auth, etc.), see the examples/ directory.
For step-by-step tutorials (server, client, HTTP deployment, OAuth, and more), see the documentation site.
See the hello-world-mcp-server-stdio example running in the MCP Inspector:
Enable with the macros feature.
mcp_toolGenerate a Tool from a struct, with metadata (icons, hints, etc.).
…tool_box!()Automatically generates an enum based on the provided list of tools.
tool_box!(GreetingTools, [SayHelloTool, SayGoodbyeTool]);
let tools: Vec = GreetingTools::tools();mcp_elicit()Generates type-safe elicitation (Form or URL mode) for user input.
#[mcp_elicit(message = "Please enter your info", mode = form)]
#[derive(JsonSchema)]
pub struct UserInfo {
#[json_schema(title = "Name", min_length = 5, max_length = 100)]
pub name: String,
#[json_schema(title = "Email", format = "email")]
pub email: Option,
#[json_schema(title = "Age", minimum = 15, maximum = 125)]
pub age: i32,
#[json_schema(title = "Tags")]
pub tags: Vec,
}A procedural macro attribute that generates utility methods to create fully populated Resource instances from compile-time metadata , usually used for exposing static assets like files, images, or documents. Also generates a RESOURCE_URI associated constant, usable in match patterns, and a resource_mime_type() accessor.
For complete documentation, example usage, and a list of all available attributes, please refer to https://crates.io/crates/rust-mcp-macros.
A procedural macro attribute that generates utility methods to create fully populated ResourceTemplate instances from compile-time metadata for exposing parameterized server resources. Also generates a RESOURCE_URI_TEMPLATE associated constant, usable in match patterns, and a resource_template_mime_type() accessor.
For complete documentation, example usage, and a list of all available attributes, please refer to https://crates.io/crates/rust-mcp-macros.
A procedural macro attribute that generates utility methods to create fully populated Prompt instances from compile-time metadata, and , when the optional messages attribute is provided , to parse request arguments (from_arguments) and render them into a GetPromptResult (render). Struct fields become typed prompt arguments (String = required, Option = optional, String + default = fallback), the prompts/get handler itself is left to the user.
For complete documentation, example usage, and a list of all available attributes, please refer to https://crates.io/crates/rust-mcp-macros.
mcp_icon!()A convenient icon builder for implementations and tools, offering full attribute support including theme, size, mime, and more.
example usage:
let icon: crate::schema::Icon = mcp_icon!(
src = "http://website.com/icon.png",
mime_type = "image/png",
sizes = ["64x64"],
theme = "dark"
);MCP servers can verify tokens issued by other systems, integrate with external identity providers, or manage the entire authentication process.
RemoteAuthProvider enables authentication with identity providers that support Dynamic Client Registration (DCR), letting MCP clients auto-register and obtain credentials.
OAuthProxy enables authentication with OAuth providers that don't support DCR.
server: Activates MCP server capabilitiesclient: Activates MCP client capabilitiesmacros: Procedural macros for Tool, Elicit, Resource structuressse: Server-Sent Events (SSE) transportstreamable-http: Streamable HTTP transportstdio: Standard input/output (stdio) transportauth: OAuth authentication support for MCP serverstls-no-provider: TLS without a crypto providerAll features are enabled by default:
[dependencies]
rust-mcp-sdk = "2.0.0"[dependencies]
rust-mcp-sdk = { version = "2.0.0", default-features = false, features = ["server", "macros", "stdio"] }[dependencies]
rust-mcp-sdk = { version = "2.0.0", default-features = false, features = ["client", "stdio"] }ServerHandler and ServerHandlerCoreNote: Use server_runtime::create_server() or `server_runtime_core::create_s
暂无开放 Issues,或尚未同步最近议题。