Model Context Protocol (MCP) Schema for Rust

by rust-mcp-stack

75 stars
503 downloads
Not rated
GitHub

About

A type-safe implementation of the official Model Context Protocol (MCP) schema in Rust.

Details

Author
rust-mcp-stack
GitHub stars
75
Downloads
503
Categories
Other

- 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_utils module for improved developer productivity
- Simple feature flags to switch between schema versions

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.

Model Context Protocol (MCP) Schema for Rust

crates.io
docs.rs
build status

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
- draft

The MCP schemas in this repository are automatically generated from the official Model Context Protocol, ensuring they are always up-to-date and aligned with the latest official specifications.

---

Note: This crate only provides an implementation of the MCP schema.

If you are looking for a high-performance, asynchronous toolkit for building MCP servers and clients, checkout rust-mcp-sdk.
Focus on your app's logic while rust-mcp-sdk takes care of the rest!

---

Contents:

- Features
- How can this crate be used?

- Schema Versions
- How to switch between different schema versions?
- How are Schemas generated?
- What is schema_utils?
- What does the schema_utils do?
- Usage Examples
- Detecting an InitializeRequest Message on an MCP Server
- Creating an InitializeResult Response on an MCP Server
- Detecting an InitializeResult Response Message in an MCP Client
- Usage Examples (Without Utilizing schema_utils)

- Detecting an InitializeRequest Message on an MCP Server (without schema_utils)

- Contributing

Features

- 🧩 Type-safe implementation of the MCP protocol specification.
- πŸ’Ž Auto-generated schemas are always synchronized with the official schema specifications.
- πŸ“œ Includes all official released versions : 2025-11-25, 2025-06-18, 2025-03-26, 2024-11-05 and draft version for early adoption.
- πŸ›  Complimentary schema utility module (schema_utils) to boost productivity and ensure development integrity.

How can this crate be used?

This Crate provides Rust implementation of the official Model Context Protocol (MCP) schema.

Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you’re building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.

This crate includes the schema with serialization / deserialization support via serde_json, along with a minimal implementation of the necessary traits for structs and enums. This helps in creating and using various MCP messages such as requests, responses, notifications, and errors.

This crate could be used for developing an MCP Server or MCP Client in Rust.
For more information on the MCP architecture, refer to the official documentation.

---

Check out rust-mcp-sdk , a high-performance, asynchronous toolkit for building MCP servers and clients which is based on rust-mcp-schema. Focus on your app's logic while rust-mcp-sdk takes care of the rest!

---

Schema Versions

This repository provides all official released versions the schema , including draft version, enabling you to prepare and adapt your applications ahead of upcoming official schema releases.

- 2025-11-25
- 2025-06-18
- 2025-03-26
- 2024-11-05
- draft

How to switch between different 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_2025_06_18
- rust_mcp_schema::mcp_draft"

Example: enable 2025-06-18 version of the schema:

<!-- x-release-please-start-version -->

```toml

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.