Model Context Protocol (MCP) Schema for Rust
@rust-mcp-stack
A type-safe implementation of the official Model Context Protocol (MCP) schema in Rust.
概要
What is Model Context Protocol (MCP) Schema for Rust?
A type-safe Rust implementation of the official Model Context Protocol (MCP) schema, supporting all official MCP protocol versions (2025-11-25, 2025-06-18, 2025-03-26, 2024-11-05, and draft). The schemas are automatically generated from the official MCP specification, ensuring alignment with the latest standards. This crate is intended for developers building MCP servers or clients in Rust who need strongly typed message structures.
How to use Model Context Protocol (MCP) Schema for Rust?
Add the crate to your Cargo.toml with a specific schema version feature (e.g., features = ["2025_06_18"]). The default feature selects the latest version. Use the provided structs and enums with serde for serialization/deserialization. Optionally enable schema_utils (default) to access ClientMessage and ServerMessage types for stronger type safety.
Key features of Model Context Protocol (MCP) Schema for Rust
- Type-safe implementation of the MCP protocol specification
- Auto-generated schemas synced with official specifications
- Supports all released versions plus a draft version
- Complementary
schema_utilsmodule for improved developer productivity - Simple feature flags to switch between schema versions
Use cases of Model Context Protocol (MCP) Schema for Rust
- Build an MCP server in Rust with strongly typed request/response handling
- Develop an MCP client that correctly parses and constructs protocol messages
- Integrate MCP message formatting into AI-powered IDEs or chat interfaces
- Experiment with upcoming protocol changes using the draft schema version
FAQ from Model Context Protocol (MCP) Schema for Rust
How do I switch between different schema versions?
Enable the corresponding Cargo feature in your Cargo.toml. For example, features = ["2025_06_18"] uses the 2025-06-18 schema. Multiple versions can be enabled simultaneously; non-default versions are available under explicitly named modules (e.g., rust_mcp_schema::mcp_2025_06_18).
Does this crate provide a full MCP server or client implementation?
No. This crate only implements the MCP schema (types, serialization, deserialization). For a high‑performance asynchronous toolkit to build servers and clients, see rust-mcp-sdk, which is built on top of this schema.
What are the runtime requirements?
The crate relies on serde and serde_json for JSON serialization. No external runtime (e.g., Tokio) is required unless you add a transport layer. The schema itself is pure data structures.
How are the schemas generated?
They are generated from the official schema.ts and schema.json files in the MCP specification repository, using a customized version of typify plus pre‑ and post‑processing steps. The generation tool is not public but may be released as a CLI later.
What is schema_utils and do I have to use it?
schema_utils provides utility types (ClientMessage, ServerMessage) that split the unified JsonrpcMessage into client‑ and server‑specific messages for stronger type checking. It is enabled by default and optional. You can work directly with the raw schemas without it.