Rust implementation of the Model Context Protocol (MCP) schema. Type-safe data structures for model context exchange.
<p align="center">
<img width="200" src="./assets/rust-mcp-schema.png" alt="Rust MCP Schema Logo">
</p>
# Model Context Protocol (MCP) Schema for Rust
[](https://crates.io/crates/rust-mcp-schema)
[](https://docs.rs/rust-mcp-schema/0.1.0)
[](https://github.com/rust-mcp-stack/rust-mcp-schema/actions/workflows/ci.yml)
This crate provides a type-safe Rust implementation of the official Model Context Protocol (MCP) schema. It supports all officially released versions, including `2025_06_18`, `2025_03_26`, `2024_11_05`, and the `draft` version for early adoption.
The MCP schemas in this repository are [automatically generated](#schema-generation) from the official Model Context Protocol specifications, ensuring they are always up-to-date and aligned with the latest releases.
---
**Note:** This crate **only** provides an implementation of the MCP schema. It does not include server or client implementations.
<img align="top" src="assets/rust-mcp-stack-icon.png" width="24" style="border-radius:0.2rem;"> If you are looking for a high-performance, asynchronous toolkit for building MCP servers and clients, check out [rust-mcp-sdk](https://crates.io/crates/rust-mcp-sdk). Focus on your application's logic while `rust-mcp-sdk` handles the MCP protocol details!
---
## Table of Contents
- [Features](#features)
- [Usage](#usage)
- [Schema Versions](#schema-versions)
- [Switching Schema Versions](#switching-schema-versions)
- [Schema Generation](#schema-generation)
- [Schema Utilities (`schema_utils`)](#schema-utilities-schema_utils)
- [What does `schema_utils` do?](#what-does-schema_utils-do)
- [Usage Examples](#usage-examples)
- [Detecting an `InitializeRequest` Message on an MCP Server](#detecting-an-initializerequest-message-on-an-mcp-server)
- [Creating an `InitializeResult` Response on an MCP Server](#creating-an-initializeresult-response-on-an-mcp-server)
- [Detecting an `InitializeResult` Response Message in an MCP Client](#detecting-an-initializeresult-response-message-in-an-mcp-client)
- [Usage Examples (Without `schema_utils`)](#usage-examples-without-schema_utils)
- [Detecting an `InitializeRequest` Message on an MCP Server (without `schema_utils`)](#detecting-an-initializerequest-message-on-an-mcp-server-without-schema_utils)
- [Contributing](#contributing)
## Features
- 🧩 **Type-Safe MCP Implementation:** Provides a robust and type-safe implementation of the MCP protocol specification in Rust.
- 💎 **Auto-Generated Schemas:** Schemas are automatically generated and synchronized with the official MCP specifications, ensuring accuracy and up-to-date compatibility.
- 📜 **Comprehensive Version Support:** Includes all officially released versions of the MCP schema: `2025_06_18`, `2025_03_26`, `2024_11_05`, and the `draft` version for early adoption and experimentation.
- 🛠 **Schema Utilities Module (`schema_utils`):** Offers a complimentary `schema_utils` module to enhance developer productivity and ensure development integrity through strongly-typed objects and implementations.
## Usage
This crate provides Rust data structures that represent the official Model Context Protocol (MCP) schema.
The Model Context Protocol (MCP) is an open protocol that enables seamless integration between Large Language Model (LLM) applications and external data sources and tools. It provides a standardized way to connect LLMs with the context they need, whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows.
This crate includes the schema with `serialization` and `deserialization` support via `serde_json`, along with the necessary trait implementations for structs and enums. This facilitates the creation and handling of various MCP messages, such as requests, responses, notifications, and errors.
This crate is designed for developing **MCP Servers** and **MCP Clients** in Rust. For more information on the MCP architecture, refer to the [official documentation](https://spec.modelcontextprotocol.io/specification).
---
<img align="top" src="assets/rust-mcp-stack-icon.png" width="24" style="border-radius:0.2rem;"> Check out [rust-mcp-sdk](https://crates.io/crates/rust-mcp-sdk), a high-performance, asynchronous toolkit for building MCP servers and clients based on `rust-mcp-schema`. Focus on your application's logic while `rust-mcp-sdk` handles the MCP protocol details!
---
## Schema Versions
This repository provides all officially released schema versions, including the `draft` version, allowing you to prepare and adapt your applications ahead of upcoming official schema releases.
- [2025_06_18](src/generated_schema/2025_06_18)
- [2025_03_26](src/generated_schema/2025_03_26)
- [2024_11_05](src/generated_schema/2024_11_05)
- [draft](src/generated_schema/draft)
### Switching Schema Versions
By default, the latest version of the MCP protocol schema is enabled.
Each schema version has a corresponding Cargo feature that can be enabled in your project's `Cargo.toml`.
Multiple schema versions may be enabled concurrently if needed. Non-default versions are available under explicitly named modules, for example:
- `rust_mcp_schema::mcp_2024_11_05`
- `rust_mcp_schema::mcp_draft`
**Example: Enable the `2024_11_05` version of the schema:**
```toml
# Cargo.toml
rust-mcp-schema = { version = "0.7.1", default-features = false, features = ["2024_11_05"] }
Example: Enable the draft
version of the schema:
# Cargo.toml
rust-mcp-schema = { version = "0.7.1", default-features = false, features = ["draft"] }
Schemas are generated from the official schema.ts
and schema.json
files available in the Model Context Protocol (MCP) repository.
A customized version of typify, along with additional pre-processing and post-processing steps, transforms the schema specifications into Rust code.
The code used to generate schemas from
schema.ts
andschema.json
is not included in this repository. However, we are considering making it available as a CLI tool in the future, allowing developers to generate MCP schemas as Rust code that can be directly integrated into their projects.
schema_utils
)The Rust implementations of the MCP schemas in this crate are automatically generated from the official MCP GitHub repository.
mcp_schema.rs provides all the core structures and enums with serialization/deserialization support, allowing you to use them as needed and extend their functionality.
To streamline development, improve compile-time type checking, and reduce the potential for errors, we've implemented utility types and functions that offer more strongly-typed objects and implementations, all without modifying the originally generated schema.
Please refer to schema_utils.rs for more details.
Using
schema_utils
is optional. It is enabled by default through theschema_utils
Cargo feature and can be used fromrust_mcp_schema::schema_utils
.
If you prefer not to use `schema
rust-mcp-stack/rust-mcp-schema
February 8, 2025
July 1, 2025
Rust