modelcontextprotocol/rust-sdk

The official Rust SDK for the Model Context Protocol

What it solves

This project provides an official Rust SDK for the Model Context Protocol (MCP), allowing developers to build servers and clients that can exchange tools, resources, and prompts in a standardized way. It simplifies the integration of AI models with external data sources and executable functions.

How it works

The SDK implements the MCP specification using the tokio async runtime. It provides a set of crates (rmcp and rmcp-macros) that offer:

  • Server Implementation: Developers can use procedural macros like #[tool], #[prompt], and #[tool_router] to declaratively expose functions as tools or prompts. It handles JSON Schema generation for parameters via schemars.
  • Client Implementation: Clients can discover and invoke tools, read resources, and use prompt templates from MCP servers.
  • Transport Layer: It supports various transports, including standard I/O (stdio) and child process management, to enable communication between the client and server.
  • Lifecycle Management: It supports multiple startup modes (Initialize, Discover, and Auto) to handle protocol version negotiation and capability discovery.

Who it’s for

Rust developers who want to build MCP-compliant servers (to expose data or functionality to AI agents) or MCP clients (to connect AI models to a suite of external tools and resources).

Highlights

  • Declarative Tooling: Uses Rust macros to reduce boilerplate when defining tools and prompts.
  • Multi-modal Support: Tools can return mixed content, including text, base64-encoded images, and audio.
  • Flexible Resources: Supports URI-based resource access, including dynamic URI templates for parameterized data retrieval.
  • Protocol Compliance: Implements the stable MCP 2026-07-28 specification with backward compatibility for earlier versions.
  • Async Native: Built on tokio for high-performance asynchronous I/O.

相關

  • 專案
  • 專案
  • 專案
  • 專案
  • 專案