{"id":25649622,"url":"https://github.com/rust-mcp-stack/rust-mcp-schema","last_synced_at":"2026-01-23T14:11:45.625Z","repository":{"id":276548119,"uuid":"929517783","full_name":"rust-mcp-stack/rust-mcp-schema","owner":"rust-mcp-stack","description":"A type-safe implementation of the official Model Context Protocol (MCP) schema in Rust.","archived":false,"fork":false,"pushed_at":"2025-04-04T23:28:07.000Z","size":1374,"stargazers_count":36,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T18:20:12.139Z","etag":null,"topics":["crates-io","mcp-client","mcp-host","mcp-server","model-context-protocol","rust","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-mcp-stack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["hashemix"]}},"created_at":"2025-02-08T18:21:21.000Z","updated_at":"2025-04-13T16:56:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cf78022-7e0d-4ae4-8953-ad1d1f0bfa4b","html_url":"https://github.com/rust-mcp-stack/rust-mcp-schema","commit_stats":null,"previous_names":["rust-mcp-stack/rust-mcp-schema"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-mcp-stack%2Frust-mcp-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-mcp-stack%2Frust-mcp-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-mcp-stack%2Frust-mcp-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-mcp-stack%2Frust-mcp-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-mcp-stack","download_url":"https://codeload.github.com/rust-mcp-stack/rust-mcp-schema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249126114,"owners_count":21216727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crates-io","mcp-client","mcp-host","mcp-server","model-context-protocol","rust","rust-lang"],"created_at":"2025-02-23T14:22:48.781Z","updated_at":"2026-01-23T14:11:45.614Z","avatar_url":"https://github.com/rust-mcp-stack.png","language":"Rust","funding_links":["https://github.com/sponsors/hashemix"],"categories":["📚 Projects (1974 total)","🔧 Utilities"],"sub_categories":["MCP Servers"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"./assets/rust-mcp-schema.png\" alt=\"Description\" width=\"300\"\u003e\n\u003c/p\u003e\n\n# Model Context Protocol (MCP) Schema for Rust\n\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/rust-mcp-schema?style=for-the-badge\u0026logo=rust\u0026color=FE965D\" height=\"22\"\u003e](https://crates.io/crates/rust-mcp-schema)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-rust_mcp_schema-0ECDAB?style=for-the-badge\u0026logo=docs.rs\" height=\"22\"\u003e](https://docs.rs/rust-mcp-schema/latest/rust_mcp_schema)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/rust-mcp-stack/rust-mcp-schema/ci.yml?style=for-the-badge\" height=\"22\"\u003e\n](https://github.com/rust-mcp-stack/rust-mcp-schema/actions/workflows/ci.yml)\n\nA type-safe Rust implementation of the official Model Context Protocol (MCP) schema, supporting all official MCP Protocol versions:\n\n- `2025-11-25`\n- `2025-06-18`\n- `2025-03-26`\n- `2024-11-05`\n- `draft`\n\nThe MCP schemas in this repository are [automatically generated](#how-are-schemas-generated) from the official Model Context Protocol, ensuring they are always up-to-date and aligned with the latest official specifications.\n\n---\n\n**Note:** This crate **only** provides an implementation of the MCP schema.\n\n\u003cimg align=\"top\" src=\"assets/rust-mcp-stack-icon.png\" width=\"24\" style=\"border-radius:0.2rem;\"\u003e If you are looking for a high-performance, asynchronous toolkit for building MCP servers and clients, checkout [rust-mcp-sdk](https://crates.io/crates/rust-mcp-sdk).\nFocus on your app's logic while [rust-mcp-sdk](https://crates.io/crates/rust-mcp-sdk) takes care of the rest!\n\n---\n\n## Contents:\n\n- [Features](#features)\n- [How can this crate be used?](#how-can-this-crate-be-used)\n\n- [Schema Versions](#schema-versions)\n  - [How to switch between different schema versions?](#how-to-switch-between-different-schema-versions)\n  - [How are Schemas generated?](#how-are-schemas-generated)\n- [What is `schema_utils`?](#what-is-schema_utils)\n- [What does the schema_utils do?](#what-does-the-schema_utils-do)\n- [Usage Examples](#usage-examples)\n  - [Detecting an InitializeRequest Message on an MCP Server](#detecting-an-initializerequest-message-on-an-mcp-server)\n  - [Creating an InitializeResult Response on an MCP Server](#creating-an-initializeresult-response-on-an-mcp-server)\n  - [Detecting an InitializeResult Response Message in an MCP Client](#detecting-an-initializeresult-response-message-in-an-mcp-client)\n- [Usage Examples (Without Utilizing schema_utils)](#usage-examples-without-utilizing-schema_utils)\n\n  - [Detecting an InitializeRequest Message on an MCP Server (without schema_utils)](#detecting-an-initializerequest-message-on-an-mcp-server-without-schema_utils)\n\n- [Contributing](CONTRIBUTING.md)\n\n## Features\n\n- 🧩 Type-safe implementation of the MCP protocol specification.\n- 💎 Auto-generated schemas are always synchronized with the official schema specifications.\n- 📜 Includes all official released versions : `2025-11-25`, `2025-06-18`, `2025-03-26`, `2024-11-05` and `draft` version for early adoption.\n- 🛠 Complimentary schema utility module (schema_utils) to boost productivity and ensure development integrity.\n\n## How can this crate be used?\n\nThis Crate provides Rust implementation of the official Model Context Protocol (MCP) schema.\n\nModel 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.\n\nThis 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.\n\nThis crate could be used for developing an **MCP Server** or **MCP Client** in Rust.\nFor more information on the MCP architecture, refer to the [official documentation](https://spec.modelcontextprotocol.io/specification).\n\n---\n\n\u003cimg align=\"top\" src=\"assets/rust-mcp-stack-icon.png\" width=\"24\" style=\"border-radius:0.2rem;\"\u003e Check out [rust-mcp-sdk](https://crates.io/crates/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](https://crates.io/crates/rust-mcp-sdk) takes care of the rest!\n\n---\n\n## Schema Versions\n\nThis 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.\n\n- [2025-11-25](src/generated_schema/2025_11_25)\n- [2025-06-18](src/generated_schema/2025_06_18)\n- [2025-03-26](src/generated_schema/2025_03_26)\n- [2024-11-05](src/generated_schema/2024_11_05)\n- [draft](src/generated_schema/draft)\n\n### How to switch between different schema versions?\n\nBy default, the latest version of the MCP Protocol schema is enabled.\n\nEach schema version has a corresponding Cargo feature that can be enabled in your project's Cargo.toml.\n\nMultiple schema versions may be enabled concurrently if needed. Non-default versions are available under explicitly named modules, for example:\n\n- rust_mcp_schema::mcp_2025_06_18\n- rust_mcp_schema::mcp_draft\"\n\nExample: enable `2025-06-18` version of the schema:\n\n\u003c!-- x-release-please-start-version --\u003e\n\n```toml\n# Cargo.toml\nrust-mcp-schema = { version: 0.9.5 , default-features = false, features=[\"2025_06_18\"] }\n```\n\nExample: enable `draft`` version of the schema :\n\n```toml\n#Cargo.toml\nrust-mcp-schema = { version: 0.9.5 , default-features = false, features=[\"draft\"] }\n```\n\n\u003c!-- x-release-please-end --\u003e\n\n## How are Schemas generated?\n\nSchemas are generated from the official `schema.ts` and `schema.json` files available in the original [Model Context Protocol (MCP) repository](https://github.com/modelcontextprotocol/specification/tree/main/schema).\n\nUsing a customized version of [typify](https://github.com/oxidecomputer/typify), along with additional pre-processing and post-processing steps, the schema specifications are transformed into Rust code.\n\n### 📌 Note\n\n\u003e The code used to generate schemas from `schema.ts` and `schema.json` is not included in this repository. However, I am 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.\n\n## What is `schema_utils`?\n\nThe Rust implementations of the MCP schemas in this crate are automatically generated from the official MCP GitHub repository.\n\n[mcp_schema.rs](src/generated_schema/2024_11_05/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.\n\nTo 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.\n\nPlease refer to [schema_utils.rs](src/generated_schema/2024_11_05/schema_utils.rs) for more details.\n\n### 📌 Note\n\n\u003e Using schema_utils is optional. It is enabled by default through the schema_utils Cargo feature and can be used from `rust_mcp_schema::schema_utils`.\n\n\u003e If you prefer not to use schema_utils, you can directly work with the enums and structs provided in [mcp_schema.rs](src/generated_schema/2024_11_05/mcp_schema.rs), adapting them to your needs and creating your own utility types and functions around them.\n\nVisit [Usage Examples (Without `Using schema_utils`)](#usage-examples-without-utilizing-schema_utils) to see an alternative approach.\n\n### What does the schema_utils do?\n\nThe official schema defines a unified `JsonrpcMessage` type that encompasses all messages and notifications within the MCP protocol.\n\nTo enhance type safety and usability, `schema_utils` divides JsonrpcMessage into two distinct categories: `ClientMessage` and `ServerMessage`. Each category includes the relevant types for both standard and custom messages.\n\nPlease refer to [schema_utils.rs](src/generated_schema/2024_11_05/schema_utils.rs) and the [Usage Examples](usage-examples) section for more details.\n\n## Usage Examples\n\n:point_right: The following examples focus solely on the serialization and deserialization of schema messages, assuming the JSON-RPC message has already been received in the application as a string.\n\n### Detecting an `InitializeRequest` Message on an MCP Server\n\nThe following code snippet demonstrates how an MCP message, represented as a JSON string, can be deserialized into a ClientMessage and how to identify it as an InitializeRequest message.\n\n\u003e Note: ClientMessage represents MCP messages sent from an MCP client. The following code demonstrates how an MCP server can deserialize received messages from an MCP client.\n\n```rs\n\npub fn handle_messagew(message_payload: \u0026str) -\u003e std::result::Result\u003c(), RpcError\u003e {\n    // Deserialize message into ClientMessage.\n    let message = ClientMessage::from_str(\u0026message_payload)?;\n\n    // Check if the message is a Request\n    if let ClientMessage::Request(message_object) = message {\n        // Check if it's an InitializeRequest\n        if let ClientRequest::InitializeRequest(initialize_request) = client_request {\n            // Process the InitializeRequest (and eventually send back a InitializedNotification back to the server)\n            handle_initialize_request(initialize_request);\n        }\n    }\n    Ok(())\n}\n\n```\n\nRefer to [examples/mcp_server_handle_message.rs](examples/mcp_server_handle_message.rs) for a complete match implementation that handles all possible `ClientMessage` variants.\n\n### Creating an `InitializeResult` Response on an MCP Server.\n\nIn response to an InitializeRequest, the MCP Server is expected to return an InitializeResult message.\n\nThis code snippet demonstrates how to create an InitializeRequest, serialize it into a string, and send it back to the client via the transport layer.\n\n```rs\n    // create InitializeResult object\n    let initial_result = InitializeResult {\n        capabilities: ServerCapabilities {\n            logging: None,\n            prompts: Some(ServerCapabilitiesPrompts {list_changed: Some(true)}),\n            resources: Some(ServerCapabilitiesResources {list_changed: Some(true),subscribe: Some(true)}),\n            tools: Some(ServerCapabilitiesTools { list_changed: Some(true)}),\n            completions: None,\n            tasks: Some(ServerTasks { cancel: Some(Map::new()), list: Some(Map::new()), requests: None }),\n            experimental: None,\n        },\n        instructions: Some(String::from(\"mcp server instructions....\")),\n        meta: Some(\n            json!({\n                \"meta 1\": serde_json::Value::String(\"meta-value\".into()),\n                \"meta 2\": serde_json::Value::Number(serde_json::Number::from(225)),\n                \"feature-xyz\": serde_json::Value::Bool(true)\n            }).as_object().unwrap().to_owned(),\n        ),\n        protocol_version: ProtocolVersion::V2025_11_25.into(),\n        server_info: Implementation {\n            name: String::from(\"rust mcp server\"),\n            title: Some(\"Cool mcp server!\".into()),\n            version: String::from(\"1.0.0\"),\n            description: Some(\"your rust mcp server description....\".into()),\n            icons: vec![],\n            website_url: Some(\"https://github.com/rust-mcp-stack/rust-mcp-schema\".into()),\n        },\n    };\n\n    // JsonrpcResultResponse  vs  JsonrpcResponse\n    // Create a ServerMessage (a message intended to be sent from the server)\n    let message = ServerJsonrpcResponse::new(RequestId::Integer(0), initial_result.into());\n\n    // Serialize the MCP message into a valid JSON string for sending to the client\n    let json_payload = serde_json::to_string(\u0026message).unwrap();\n\n    println!(\"{}\", json_payload);\n```\n\noutput:\n\n```json\n{\n  \"id\": 0,\n  \"jsonrpc\": \"2.0\",\n  \"result\": {\n    \"capabilities\": {\n      \"prompts\": { \"listChanged\": true },\n      \"resources\": { \"listChanged\": true, \"subscribe\": true },\n      \"tasks\": { \"cancel\": {}, \"list\": {} },\n      \"tools\": { \"listChanged\": true }\n    },\n    \"instructions\": \"mcp server instructions....\",\n    \"protocolVersion\": \"2025-11-25\",\n    \"serverInfo\": {\n      \"description\": \"your rust mcp server description....\",\n      \"name\": \"rust mcp server\",\n      \"title\": \"Cool mcp server!\",\n      \"version\": \"1.0.0\",\n      \"websiteUrl\": \"https://github.com/rust-mcp-stack/rust-mcp-schema\"\n    },\n    \"_meta\": { \"feature-xyz\": true, \"meta 1\": \"meta-value\", \"meta 2\": 225 }\n  }\n}\n```\n\n### Detecting an `InitializeResult` Response Message in an MCP Client:\n\n```rs\nfn handle_message(message_payload: \u0026str) -\u003e std::result::Result\u003c(), AppError\u003e {\n    // Deserialize message into ServerMessage.\n    // ServerMessage represents a message sent by an MCP Server and received by an MCP Client.\n    let mcp_message = ServerMessage::from_str(message_payload)?;\n\n    // Check if the message is a Response type of message\n    if let ServerMessage::Response(server_response) = mcp_message {\n        // Check if it's a InitializeResult response\n        if let ServerResult::InitializeResult(initialize_result) = server_response.result {\n            //Process the InitializeResult and send an InitializedNotification back to the server for acknowledgment.\n            handle_initialize_result(initialize_request);\n        }\n    }\n    Ok(())\n}\n```\n\nRefer to [mcp_client_handle_message.rs](examples/mcp_client_handle_message.rs) for a complete match implementation that handles all possible `ServerMessage` variants.\n\n## Usage Examples (Without Utilizing `schema_utils`)\n\nIf you prefer not to use schema_utils, you can directly work with the generated types in your application or build custom utilities around them.\n\n### Detecting an InitializeRequest Message on an MCP Server (without schema_utils)\n\nThe following code example illustrates how to detect an InitializeRequest message on an MCP server:\n\n```rs\n\nfn handle_message(message_payload: \u0026str) -\u003e std::result::Result\u003c(), AppError\u003e {\n    // Deserialize json string into JsonrpcMessage\n    let message: JsonrpcMessage = serde_json::from_str(message_payload).unwrap();\n\n    // Check it's a Request type of message\n    if let JsonrpcMessage::Request(client_message) = message {\n        let client_request: ClientRequest = serde_json::from_value(client_message.params.into()).unwrap();\n\n        // Check method to detect is a \"initialize\" request\n        if let ClientRequest::InitializeRequest(initialize_request) = client_request {\n            // Now that we can handle the message, we simply print out the details.\n            println!(\"Initialize request received!\");\n\n            println!(\"Client name : {:?} \", initialize_request.params.client_info.name);\n            println!(\"Client version : {:?} \", initialize_request.params.client_info.version);\n            \n        }\n    }\n\n    Ok(())\n}\n```\n\n## Contributing\n\nWe welcome everyone who wishes to contribute! Please refer to the [contributing guidelines](CONTRIBUTING.md) for more details.\n\nAll contributions, including issues and pull requests, must follow\n[Rust's Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct).\n\nUnless explicitly stated otherwise, any contribution you submit for inclusion in `rust-mcp-schema` is provided under the terms of the MIT License, without any additional conditions or restrictions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-mcp-stack%2Frust-mcp-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-mcp-stack%2Frust-mcp-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-mcp-stack%2Frust-mcp-schema/lists"}