Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rust-mcp-sdk

> 开发工具
Open source

A high-performance, asynchronous toolkit for building MCP servers and clients in Rust.

188 stars0 likes2 views
WebsiteGitHub

About

A high-performance, asynchronous toolkit for building MCP servers and clients in Rust.

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-sdk 2.x, implementing the new MCP 2026-07-28 (stateless) specification. For the previous MCP 2025-11-25 specification, use rust-mcp-sdk 1.x:

toml
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) main
1.x (LTS) MCP 2025-11-25 release-1.x

Upgrading? See the upgrade guide.

Key Features

  • MCP 2026-07-28 (stateless protocol)
  • 100% MCP Conformance - server 110/110, client 440/440 on 2026-07-28
  • Transports: Stdio, Streamable HTTP, and backward-compatible SSE support
  • Framework Agnostic: Axum, Actix, and BYO Server integrations
  • MRTR (Mid-Request Turn-Around) for server→client input requests
  • Response cache (SEP-2549) with principal-scoped privacy + auto-pagination
  • Per-request _meta with RequestContext
  • Multi-client concurrency
  • DNS Rebinding Protection
  • Message Observer (Telemetry & Monitoring)
  • HTTP Health Checks (for load balancers & container orchestration)
  • OAuth Authentication for MCP Servers
    • Remote Oauth Provider
      • Keycloak Provider (via rust-mcp-extra)
      • WorkOS Authkit Provider (via rust-mcp-extra)
      • Scalekit Authkit Provider (via rust-mcp-extra)
  • OAuth Authentication for MCP Clients (metadata discovery, CIMD, PKCE, token refresh, pluggable storage)
  • Issuer-bound credentials (SEP-2352), strict iss validation (SEP-2468)

Table of Contents

  • Quick Start
  • Minimal MCP Server (Stdio)
  • Minimal MCP Server (Streamable HTTP)
  • Minimal MCP Client (Stdio)
  • Usage Examples
  • Macros
    • mcp_tool
    • tool_box
    • mcp_elicit
    • mcp_resource
    • mcp_resource_template
    • mcp_prompt
    • mcp_icon
  • Authentication
  • HTTP Server Backends (Axum & Actix)
  • Cargo features
  • Handler Traits
  • Message Observer (Telemetry & Monitoring)
  • Health Check Endpoint
  • Projects using Rust MCP SDK
  • Contributing
  • Development
  • License

Quick Start

Add to your Cargo.toml:

toml
[dependencies]
rust-mcp-sdk = "2.0.0"  # Check crates.io for the latest version

Minimal MCP Server (Stdio)

…

HTTP Server Backends (Axum & Actix)

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.

Axum Backend (rust-mcp-axum)

Add rust-mcp-axum to your dependencies and use create_axum_server() with AxumServerOptions.

…

Actix-web Backend (rust-mcp-actix)

Add rust-mcp-actix to your dependencies and use create_actix_server() with ActixServerOptions.

…

BYO-server: Embed MCP in your Existing App

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

Custom HTTP Framework Integrations

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.

AxumServerOptions

Axum server is highly customizable through AxumServerOptions:

rust
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?;

Security Considerations

  • DNS rebinding protection is enabled by default. If allowed_hosts is not set, it auto-derives from host:port.
  • When running locally, bind only to localhost (127.0.0.1 / localhost) rather than all network interfaces (0.0.0.0)
  • Use TLS/HTTPS for production deployments

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.

…

Usage Examples

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:

Macros

Enable with the macros feature.

mcp_tool

Generate a Tool from a struct, with metadata (icons, hints, etc.).

…

tool_box!()

Automatically generates an enum based on the provided list of tools.

rust
tool_box!(GreetingTools, [SayHelloTool, SayGoodbyeTool]);
let tools: Vec = GreetingTools::tools();

mcp_elicit()

Generates type-safe elicitation (Form or URL mode) for user input.

rust
#[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,
}

◾ mcp_resource()

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.

◾ mcp_resource_template()

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.

◾ mcp_prompt()

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:

rust
let icon: crate::schema::Icon = mcp_icon!(
    src = "http://website.com/icon.png",
    mime_type = "image/png",
    sizes = ["64x64"],
    theme = "dark"
);

Authentication

MCP servers can verify tokens issued by other systems, integrate with external identity providers, or manage the entire authentication process.

RemoteAuthProvider

RemoteAuthProvider enables authentication with identity providers that support Dynamic Client Registration (DCR), letting MCP clients auto-register and obtain credentials.

OAuthProxy

OAuthProxy enables authentication with OAuth providers that don't support DCR.

Cargo Features

Available Features

  • server: Activates MCP server capabilities
  • client: Activates MCP client capabilities
  • macros: Procedural macros for Tool, Elicit, Resource structures
  • sse: Server-Sent Events (SSE) transport
  • streamable-http: Streamable HTTP transport
  • stdio: Standard input/output (stdio) transport
  • auth: OAuth authentication support for MCP servers
  • tls-no-provider: TLS without a crypto provider

Default Features

All features are enabled by default:

toml
[dependencies]
rust-mcp-sdk = "2.0.0"

Using Only the Server Features

toml
[dependencies]
rust-mcp-sdk = { version = "2.0.0", default-features = false, features = ["server", "macros", "stdio"] }

Using Only the Client Features

toml
[dependencies]
rust-mcp-sdk = { version = "2.0.0", default-features = false, features = ["client", "stdio"] }

Handler Traits

Choosing Between ServerHandler and ServerHandlerCore

  • ServerHandler: Recommended. Default implementations for all MCP messages. Override only what you need.
  • ServerHandlerCore: Full control over request/notification/error dispatch.

Note: Use server_runtime::create_server() or `server_runtime_core::create_s

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustcrates-iomcp-clientmcp-servermcp-tools

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具