Skip to content
Back to search

rust-mcp-sdk

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

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/rust-mcp-stack/rust-mcp-sdk with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/rust-mcp-stack/rust-mcp-sdk'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/rust-mcp-stack--rust-mcp-sdk/badge.svg)](/listings/rust-mcp-stack--rust-mcp-sdk)

HTML

<a href="/listings/rust-mcp-stack--rust-mcp-sdk"><img src="/api/listings/rust-mcp-stack--rust-mcp-sdk/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Add to your Cargo.toml:

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

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 586 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <p align="center">
  2. <img width="200" src="https://raw.githubusercontent.com/rust-mcp-stack/rust-mcp-sdk/main/assets/rust-mcp-sdk.png" alt="Rust MCP SDK" width="300">
  3. </p>
  4. <div align="center">
  5. [<img alt="crates.io" src="https://img.shields.io/crates/v/rust-mcp-sdk?style=for-the-badge&logo=rust&color=FE965D" height="22">](https://crates.io/crates/rust-mcp-sdk)
  6. [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-rust_mcp_SDK-0ECDAB?style=for-the-badge&logo=docs.rs" height="22">](https://docs.rs/rust-mcp-sdk)
  7. [<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/rust-mcp-stack/rust-mcp-sdk/ci.yml?style=for-the-badge" height="22">](https://github.com/rust-mcp-stack/rust-mcp-sdk/actions/workflows/ci.yml)
  8. [<img alt="conformance" src="https://img.shields.io/badge/conformance-2026--07--28%20100%25-green?style=for-the-badge" height="22">](https://github.com/rust-mcp-stack/rust-mcp-sdk/actions/workflows/conformance.yml)
  9. [<img alt="tier-check" src="https://img.shields.io/github/actions/workflow/status/rust-mcp-stack/rust-mcp-sdk/tier-check.yml?style=for-the-badge" height="22">](https://github.com/rust-mcp-stack/rust-mcp-sdk/actions/workflows/tier-check.yml)
  10. A high-performance, asynchronous Rust toolkit for building MCP servers and clients.
  11. [📖 Documentation](https://rust-mcp-stack.github.io/rust-mcp-sdk/) · [Tutorials](https://rust-mcp-stack.github.io/rust-mcp-sdk/docs/tutorials/build-your-first-mcp-server) · [Examples](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples) · [Upgrade Guide](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/UPGRADING.md) · [Changelog](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/CHANGELOG.md) <br/>
  12. [Contributing](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/CONTRIBUTING.md) · [Report a bug](https://github.com/rust-mcp-stack/rust-mcp-sdk/issues/new?template=bug_report.md) · [Request a Feature](https://github.com/rust-mcp-stack/rust-mcp-sdk/issues/new?template=feature_request.md)
  13. </div>
  14. ------
  15. **🥇 Tier 1 SDK:** passes 100% of scored conformance scenarios, and the official MCP conformance tool's `tier-check` reports **Tier 1** under SEP-1730. [Tier-check runs](https://github.com/rust-mcp-stack/rust-mcp-sdk/actions/workflows/tier-check.yml) · [release reports](https://github.com/rust-mcp-stack/rust-mcp-sdk/releases)
  16. ✅ This SDK fully implements the [MCP 2026-07-28](https://docs.rs/rust-mcp-schema/latest/rust_mcp_schema/) stateless protocol and passes **100% of official MCP conformance tests**.
  17. `rust-mcp-sdk` provides the necessary components for developing both servers and clients in the MCP ecosystem. It leverages the [rust-mcp-schema](https://crates.io/crates/rust-mcp-schema) crate for type-safe schema objects and includes powerful procedural macros.
  18. Focus on your application logic, rust-mcp-sdk handles the protocol, transports, and the rest.
  19. ----
  20. **Version notice:** This is `rust-mcp-sdk` **2.x**, implementing the new **MCP 2026-07-28** (stateless) specification.
  21. For the previous **MCP 2025-11-25** specification, use **`rust-mcp-sdk` 1.x**.
  22. See the [upgrade guide](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/UPGRADING.md) to migrate from 1.x to 2.0.
  23. **Version matrix:**
  24. | SDK version | Protocol | Branch |
  25. |---|---|---|
  26. | 2.0 | MCP 2026-07-28 (stateless) | `main` |
  27. | 1.x (LTS) | MCP 2025-11-25 | `release-1.x` |
  28. **Upgrading?** See the [upgrade guide](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/UPGRADING.md).
  29. ----
  30. **Key Features**
  31. - ✅ Latest MCP protocol specification supported: 2026-07-28
  32. - **🥇 Tier 1 SDK** - official MCP conformance tool's `tier-check` reports **Tier 1** under SEP-1730. [see tier-check runs](https://github.com/rust-mcp-stack/rust-mcp-sdk/actions/workflows/tier-check.yml)·
  33. - ✅ **100% MCP Conformance** - passes all [official](https://github.com/modelcontextprotocol/conformance) client (254/254) and server (40/40) [conformance tests](https://github.com/rust-mcp-stack/rust-mcp-sdk/actions/workflows/conformance.yml)
  34. - ✅ Transports: Stdio, Streamable HTTP, and backward-compatible SSE support
  35. - ✅ Framework Agnostic: Axum, Actix, and BYO Server integrations
  36. - ✅ MRTR (Mid-Request Turn-Around) for server→client input requests
  37. - ✅ Response cache (SEP-2549) with principal-scoped privacy + auto-pagination
  38. - ✅ Per-request `_meta` with `RequestContext`
  39. - ✅ Multi-client concurrency
  40. - ✅ DNS Rebinding Protection
  41. - ✅ Message Observer (Telemetry & Monitoring)
  42. - ✅ HTTP Health Checks (for load balancers & container orchestration)
  43. - ✅ OAuth Authentication for MCP Servers
  44. - ✅ [Remote Oauth Provider](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-sdk/src/auth/auth_provider/remote_auth_provider.rs)
  45. - **Keycloak** Provider (via [rust-mcp-extra](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-extra/README.md#keycloak))
  46. - **WorkOS** Authkit Provider (via [rust-mcp-extra](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-extra/README.md#workos-authkit))
  47. - **Scalekit** Authkit Provider (via [rust-mcp-extra](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-extra/README.md#scalekit))
  48. - ✅ OAuth Authentication for MCP Clients (metadata discovery, CIMD, PKCE, token refresh, pluggable storage)
  49. - ✅ Issuer-bound credentials (SEP-2352), strict `iss` validation (SEP-2468)
  50. ## Table of Contents
  51. - [Quick Start](#quick-start)
  52. - [Minimal MCP Server (Stdio)](#minimal-mcp-server-stdio)
  53. - [Minimal MCP Server (Streamable HTTP)](#minimal-mcp-server-streamable-http)
  54. - [Minimal MCP Client (Stdio)](#minimal-mcp-client-stdio)
  55. - [Usage Examples](#usage-examples)
  56. - [Macros](#macros)
  57. - [mcp_tool](#mcp_tool)
  58. - [tool_box](#-tool_box)
  59. - [mcp_elicit](#-mcp_elicit)
  60. - [mcp_resource](#-mcp_resource)
  61. - [mcp_resource_template](#-mcp_resource_template)
  62. - [mcp_prompt](#-mcp_prompt)
  63. - [mcp_icon](#-mcp_icon)
  64. - [Authentication](#authentication)
  65. - [HTTP Server Backends (Axum & Actix)](#http-server-backends-axum--actix)
  66. - [Cargo features](#cargo-features)
  67. - [Handler Traits](#handler-traits)
  68. - [Message Observer (Telemetry & Monitoring)](#message-observer-telemetry--monitoring)
  69. - [Health Check Endpoint](#health-check-endpoint)
  70. - [Contributing](#contributing)
  71. - [Development](#development)
  72. - [License](#license)
  73. ## Quick Start
  74. <!-- x-release-please-start-version -->
  75. Add to your Cargo.toml:
  76. ```toml
  77. [dependencies]
  78. rust-mcp-sdk = "2.0.0" # Check crates.io for the latest version
  79. ```
  80. <!-- x-release-please-end -->
  81. ## Minimal MCP Server (Stdio)
  82. ```rs
  83. use async_trait::async_trait;
  84. use rust_mcp_sdk::{
  85. error::SdkResult, macros, mcp_icon,
  86. mcp_server::{server_runtime, McpServerOptions, ServerHandler},
  87. schema::*,
  88. McpServer, RequestContext, ServerDetails, StdioTransport, ToMcpServerHandler,
  89. TransportOptions,
  90. };
  91. // Define an MCP tool
  92. #[macros::mcp_tool(name = "say_hello", description = "returns \"Hello from Rust MCP SDK!\" message")]
  93. #[derive(Debug, ::serde::Deserialize, ::serde::Serialize, macros::JsonSchema)]
  94. pub struct SayHelloTool {}
  95. // Define a custom handler
  96. #[derive(Default)]
  97. struct HelloHandler;
  98. #[async_trait]
  99. impl ServerHandler for HelloHandler {
  100. async fn handle_list_tools_request(
  101. &self,
  102. _request: Option<PaginatedRequestParams>,
  103. _context: &RequestContext,
  104. _runtime: std::sync::Arc<dyn McpServer>,
  105. ) -> std::result::Result<ListToolsResult, RpcError> {
  106. Ok(ListToolsResult {
  107. tools: vec![SayHelloTool::tool()],
  108. meta: None,
  109. next_cursor: None,
  110. cache_scope: Default::default(),
  111. result_type: "complete".to_string(),
  112. ttl_ms: 0,
  113. })
  114. }
  115. async fn handle_call_tool_request(
  116. &self,
  117. params: CallToolRequestParams,
  118. _context: &RequestContext,
  119. _runtime: std::sync::Arc<dyn McpServer>,
  120. ) -> std::result::Result<ServerResult, CallToolError> {
  121. if params.name == "say_hello" {
  122. Ok(ServerResult::CallToolResult(CallToolResult {
  123. content: vec![ContentBlock::TextContent(TextContent::new(
  124. "Hello from Rust MCP SDK!".to_string(),
  125. None,
  126. None,
  127. ))],
  128. is_error: None,
  129. meta: None,
  130. result_type: "complete".to_string(),
  131. }))
  132. } else {
  133. Err(CallToolError::unknown_tool(params.name))
  134. }
  135. }
  136. }
  137. #[tokio::main]
  138. async fn main() -> SdkResult<()> {
  139. let server_details = ServerDetails {
  140. server_info: Implementation {
  141. name: "hello-rust-mcp".into(),
  142. version: "0.1.0".into(),
  143. title: Some("Hello World MCP Server".into()),
  144. description: Some("A minimal Rust MCP server".into()),
  145. icons: vec![mcp_icon!(
  146. src = "https://raw.githubusercontent.com/rust-mcp-stack/rust-mcp-sdk/main/assets/rust-mcp-icon.png",
  147. mime_type = "image/png",
  148. sizes = ["128x128"],
  149. theme = "light"
  150. )],
  151. website_url: Some("https://github.com/rust-mcp-stack/rust-mcp-sdk".into()),
  152. },
  153. capabilities: ServerCapabilities {
  154. tools: Some(ServerCapabilitiesTools { list_changed: None }),
  155. ..Default::default()
  156. },
  157. instructions: None,
  158. meta: None,
  159. };
  160. let transport = StdioTransport::new(TransportOptions::default())?;
  161. let handler = HelloHandler::default().to_mcp_server_handler();
  162. let server = server_runtime::create_server(McpServerOptions {
  163. server_details,
  164. transport,
  165. handler,
  166. message_observer: None,
  167. });
  168. server.start().await
  169. }
  170. ```
  171. ## HTTP Server Backends (Axum & Actix)
  172. 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.
  173. Post only - the 2026-07-28 protocol is stateless. GET and DELETE endpoints return 405 Method Not Allowed.
  174. ### Axum Backend (`rust-mcp-axum`)
  175. Add [`rust-mcp-axum`](https://crates.io/crates/rust-mcp-axum) to your dependencies and use `create_axum_server()` with `AxumServerOptions`.
  176. ```rust
  177. use async_trait::async_trait;
  178. use rust_mcp_axum::{create_axum_server, AxumServerOptions};
  179. use rust_mcp_sdk::{
  180. error::SdkResult, macros,
  181. mcp_server::ServerHandler, schema::*,
  182. };
  183. // ... (define SayHelloTool and HelloHandler as shown above)
  184. #[tokio::main]
  185. async fn main() -> SdkResult<()> {
  186. let server_details = ServerDetails { /* ... */ };
  187. let handler = HelloHandler::default().to_mcp_server_handler();
  188. let server = create_axum_server(
  189. server_details,
  190. handler,
  191. AxumServerOptions {
  192. host: "127.0.0.1".to_string(),
  193. ..Default::default()
  194. },
  195. );
  196. server.start().await?;
  197. Ok(())
  198. }
  199. ```
  200. ### Actix-web Backend (`rust-mcp-actix`)
  201. Add [`rust-mcp-actix`](https://crates.io/crates/rust-mcp-actix) to your dependencies and use `create_actix_server()` with `ActixServerOptions`.
  202. ```rust
  203. use rust_mcp_actix::{create_actix_server, ActixServerOptions};
  204. use rust_mcp_sdk::{
  205. error::SdkResult,
  206. mcp_server::ServerHandler, schema::*,
  207. };
  208. // ... (define SayHelloTool and HelloHandler as shown above)
  209. #[tokio::main]
  210. async fn main() -> SdkResult<()> {
  211. let server_details = ServerDetails { /* ... */ };
  212. let handler = HelloHandler::default().to_mcp_server_handler();
  213. let server = create_actix_server(
  214. server_details,
  215. handler,
  216. ActixServerOptions {
  217. host: "127.0.0.1".to_string(),
  218. ..Default::default()
  219. },
  220. );
  221. server.start().await?;
  222. Ok(())
  223. }
  224. ```
  225. ### BYO-server: Embed MCP in your Existing App
  226. 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.
  227. | Backend | Function | Docs |
  228. |---|---|---|
  229. | Axum | `mcp_routes(state, &mount_opts, http_handler)` | [`rust-mcp-axum` README](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-axum/README.md) |
  230. | Actix-web | `mcp_scope(state, http_handler, &mount_opts)` | [`rust-mcp-actix` README](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-actix/README.md) |
  231. ### Custom HTTP Framework Integrations
  232. 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.
  233. See the [Custom HTTP Framework Integration Guide](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/doc/custom-http-framework-integration.md) for architectural details.
  234. ### AxumServerOptions
  235. Axum server is highly customizable through `AxumServerOptions`:
  236. ```rs
  237. let server = create_axum_server(
  238. server_details,
  239. handler.to_mcp_server_handler(),
  240. AxumServerOptions {
  241. host: "127.0.0.1".to_string(),
  242. port: 8080,
  243. auth: Some(Arc::new(auth_provider)), // enable authentication
  244. health_endpoint: Some("/health".into()), // health check
  245. sse_support: true, // backward-compat SSE
  246. ..Default::default()
  247. },
  248. );
  249. server.start().await?;
  250. ```
  251. ### Security Considerations
  252. - DNS rebinding protection is enabled by default. If `allowed_hosts` is not set, it auto-derives from `host:port`.
  253. - When running locally, bind only to localhost (127.0.0.1 / localhost) rather than all network interfaces (0.0.0.0)
  254. - Use TLS/HTTPS for production deployments
  255. Following is implementation of an MCP client that starts the [@modelcontextprotocol/server-everything](https://www.npmjs.com/package/@modelcontextprotocol/server-everything) server, discovers the server's capabilities, lists available tools, and calls a tool.
  256. ```rust
  257. use async_trait::async_trait;
  258. use rust_mcp_sdk::{
  259. error::SdkResult,
  260. mcp_client::{client_runtime, ClientHandler, McpClientOptions},
  261. schema::*,
  262. ClientDetails, McpClient, StdioTransport, ToMcpClientHandler, TransportOptions,
  263. };
  264. pub struct MyClientHandler;
  265. #[async_trait]
  266. impl ClientHandler for MyClientHandler {
  267. // Override handler methods as needed.
  268. // See: crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs
  269. }
  270. #[tokio::main]
  271. async fn main() -> SdkResult<()> {
  272. let client_details = ClientDetails {
  273. client_info: Implementation {
  274. name: "simple-rust-mcp-client".into(),
  275. version: "0.1.0".into(),
  276. description: None,
  277. icons: vec![],
  278. title: None,
  279. website_url: None,
  280. },
  281. capabilities: ClientCapabilities::default(),
  282. };
  283. let transport = StdioTransport::create_with_server_launch(
  284. "npx",
  285. vec!["-y".to_string(), "@modelcontextprotocol/server-everything@latest".to_string()],
  286. None,
  287. TransportOptions::default(),
  288. )?;
  289. let handler = MyClientHandler {};
  290. let client = client_runtime::create_client(McpClientOptions::new(
  291. client_details,
  292. transport,
  293. handler.to_mcp_client_handler(),
  294. ));
  295. client.clone().start().await?;
  296. // Discover the server
  297. let discover = client.request_discover(Default::default()).await?;
  298. println!("Supported protocol versions: {:?}", discover.supported_versions);
  299. // List tools
  300. let tools = client.request_tool_list(None).await?.tools;
  301. tools.iter().enumerate().for_each(|(i, tool)| {
  302. println!(" {}. {} : {}", i + 1, tool.name, tool.description.unwrap_or_default());
  303. });
  304. // Call a tool (supports MRTR auto-retry)
  305. let result = client.call_tool(CallToolRequestParams {
  306. name: "say_hello".to_string(),
  307. arguments: None,
  308. input_responses: None,
  309. request_state: None,
  310. meta: RequestMetaObject::default(),
  311. }).await?;
  312. client.shut_down().await?;
  313. Ok(())
  314. }
  315. ```
  316. ## Usage Examples
  317. For more examples (stdio, Streamable HTTP, clients, auth, etc.), see the [examples/](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/) directory.
  318. 👉 For step-by-step tutorials (server, client, HTTP deployment, OAuth, and more), see the [documentation site](https://rust-mcp-stack.github.io/rust-mcp-sdk/docs/tutorials/build-your-first-mcp-server).
  319. See the [hello-world-mcp-server-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-sdk/examples/hello-world-mcp-server-stdio.rs) example running in the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector):
  320. <img src="https://raw.githubusercontent.com/rust-mcp-stack/rust-mcp-sdk/main/assets/examples/hello-world-mcp-server.gif" alt="hello world mcp server in rust" width="800" />
  321. ## Macros
  322. Enable with the `macros` feature.
  323. ### `mcp_tool`
  324. Generate a [Tool](https://docs.rs/rust-mcp-schema/latest/rust_mcp_schema/struct.Tool.html) from a struct, with metadata (icons, hints, etc.).
  325. ```rs
  326. #[mcp_tool(
  327. name = "write_file",
  328. title = "Write File Tool",
  329. description = "Create or overwrite a file with new content.",
  330. destructive_hint = false, idempotent_hint = false, open_world_hint = false, read_only_hint = false,
  331. meta = r#"{ "key": "value" }"#,
  332. icons = [(src = "https://website.com/write.png", mime_type = "image/png", sizes = ["128x128"], theme = "light")]
  333. )]
  334. #[derive(rust_mcp_macros::JsonSchema)]
  335. pub struct WriteFileTool {
  336. /// The target file's path for writing content.
  337. pub path: String,
  338. /// The string content to be written to the file
  339. pub content: String,
  340. }
  341. ```
  342. ### `tool_box!()`
  343. Automatically generates an enum based on the provided list of tools.
  344. ```rs
  345. tool_box!(GreetingTools, [SayHelloTool, SayGoodbyeTool]);
  346. let tools: Vec<Tool> = GreetingTools::tools();
  347. ```
  348. ### `mcp_elicit()`
  349. Generates type-safe elicitation (Form or URL mode) for user input.
  350. ```rs
  351. #[mcp_elicit(message = "Please enter your info", mode = form)]
  352. #[derive(JsonSchema)]
  353. pub struct UserInfo {
  354. #[json_schema(title = "Name", min_length = 5, max_length = 100)]
  355. pub name: String,
  356. #[json_schema(title = "Email", format = "email")]
  357. pub email: Option<String>,
  358. #[json_schema(title = "Age", minimum = 15, maximum = 125)]
  359. pub age: i32,
  360. #[json_schema(title = "Tags")]
  361. pub tags: Vec<String>,
  362. }
  363. ```
  364. ### ◾ [mcp_resource()](https://crates.io/crates/rust-mcp-macros)
  365. A procedural macro attribute that generates utility methods to create fully populated [Resource](https://docs.rs/rust-mcp-schema/latest/rust_mcp_schema/struct.Resource.html) 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.
  366. 📝 For complete documentation, example usage, and a list of all available attributes, please refer to https://crates.io/crates/rust-mcp-macros.
  367. ### ◾ [mcp_resource_template()](https://crates.io/crates/rust-mcp-macros)
  368. A procedural macro attribute that generates utility methods to create fully populated [ResourceTemplate](https://docs.rs/rust-mcp-schema/latest/rust_mcp_schema/struct.ResourceTemplate.html) 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.
  369. 📝 For complete documentation, example usage, and a list of all available attributes, please refer to https://crates.io/crates/rust-mcp-macros.
  370. ### ◾ [mcp_prompt()](https://crates.io/crates/rust-mcp-macros)
  371. A procedural macro attribute that generates utility methods to create fully populated [Prompt](https://docs.rs/rust-mcp-schema/latest/rust_mcp_schema/struct.Prompt.html) 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<String>` = optional, `String` + `default` = fallback), the prompts/get handler itself is left to the user.
  372. 📝 For complete documentation, example usage, and a list of all available attributes, please refer to https://crates.io/crates/rust-mcp-macros.
  373. ### ◾ `mcp_icon!()`
  374. A convenient icon builder for implementations and tools, offering full attribute support including theme, size, mime, and more.
  375. example usage:
  376. ```rs
  377. let icon: crate::schema::Icon = mcp_icon!(
  378. src = "http://website.com/icon.png",
  379. mime_type = "image/png",
  380. sizes = ["64x64"],
  381. theme = "dark"
  382. );
  383. ```
  384. ## Authentication
  385. MCP servers can verify tokens issued by other systems, integrate with external identity providers, or manage the entire authentication process.
  386. ### RemoteAuthProvider
  387. [RemoteAuthProvider](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/crates/rust-mcp-sdk/src/auth/auth_provider/remote_auth_provider.rs) enables authentication with identity providers that support Dynamic Client Registration (DCR), letting MCP clients auto-register and obtain credentials.
  388. ### OAuthProxy
  389. OAuthProxy enables authentication with OAuth providers that don't support DCR.
  390. ## Cargo Features
  391. ### Available Features
  392. - `server`: Activates MCP server capabilities
  393. - `client`: Activates MCP client capabilities
  394. - `macros`: Procedural macros for Tool, Elicit, Resource structures
  395. - `sse`: Server-Sent Events (SSE) transport
  396. - `streamable-http`: Streamable HTTP transport
  397. - `stdio`: Standard input/output (stdio) transport
  398. - `auth`: OAuth authentication support for MCP servers
  399. - `tls-no-provider`: TLS without a crypto provider
  400. ### Default Features
  401. All features are enabled by default:
  402. <!-- x-release-please-start-version -->
  403. ```toml
  404. [dependencies]
  405. rust-mcp-sdk = "2.0.0"
  406. ```
  407. <!-- x-release-please-end -->
  408. ### Using Only the Server Features
  409. <!-- x-release-please-start-version -->
  410. ```toml
  411. [dependencies]
  412. rust-mcp-sdk = { version = "2.0.0", default-features = false, features = ["server", "macros", "stdio"] }
  413. ```
  414. <!-- x-release-please-end -->
  415. ### Using Only the Client Features
  416. <!-- x-release-please-start-version -->
  417. ```toml
  418. [dependencies]
  419. rust-mcp-sdk = { version = "2.0.0", default-features = false, features = ["client", "stdio"] }
  420. ```
  421. <!-- x-release-please-end -->
  422. ## Handler Traits
  423. ### Choosing Between `ServerHandler` and `ServerHandlerCore`
  424. - **ServerHandler**: Recommended. Default implementations for all MCP messages. Override only what you need.
  425. - **ServerHandlerCore**: Full control over request/notification/error dispatch.
  426. **Note:** Use `server_runtime::create_server()` or `server_runtime_core::create_server()` depending on which handler you implement.
  427. ### Choosing Between `ClientHandler` and `ClientHandlerCore`
  428. Same principles apply on the client side: use `client_runtime::create_client()` with `ClientHandler`, or `client_runtime_core::create_client()` with `ClientHandlerCore`.
  429. ## Message Observer (Telemetry & Monitoring)
  430. Implement `McpObserver` to intercept all incoming and outgoing MCP messages for telemetry, logging, debugging, or monitoring.
  431. ```rs
  432. let server = server_runtime::create_server(McpServerOptions {
  433. server_details,
  434. transport,
  435. handler: handler.to_mcp_server_handler(),
  436. message_observer: Some(SimpleServerObserver::new()),
  437. });
  438. ```
  439. ## Health Check Endpoint
  440. An optional HTTP health check endpoint for load balancers and container orchestration:
  441. ```rs
  442. let server = create_axum_server(
  443. server_details,
  444. handler.to_mcp_server_handler(),
  445. AxumServerOptions {
  446. host: "127.0.0.1".into(),
  447. health_endpoint: Some("/health".into()),
  448. ..Default::default()
  449. },
  450. );
  451. ```
  452. ## Contributing
  453. We welcome everyone who wishes to contribute! Please refer to the [contributing](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/CONTRIBUTING.md) guidelines for more details.
  454. Check out our [development guide](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/development.md) for instructions on setting up, building, testing, formatting, and trying out example projects.
  455. All contributions, including issues and pull requests, must follow Rust's Code of Conduct.
  456. Unless explicitly stated otherwise, any contribution you submit for inclusion in rust-mcp-sdk is provided under the terms of the MIT License, without any additional conditions or restrictions.
  457. ## Development
  458. Check out our [development guide](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/development.md) for instructions on setting up, building, testing, formatting, and trying out example projects.
  459. ## License
  460. This project is licensed under the MIT License. see the [LICENSE](https://github.com/rust-mcp-stack/rust-mcp-sdk/blob/main/LICENSE) file for details.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.