{"type":"mcp_client","name":"rust-mcp-schema","description":"Rust implementation of the Model Context Protocol (MCP) schema. Type-safe data structures for model context exchange.","category":"Developer Tools","language":"Rust","stars":74,"forks":4,"owner":"rust-mcp-stack","github_url":"https://github.com/rust-mcp-stack/rust-mcp-schema","homepage":null,"setup":"## Setup\n\nTo use the `rust-mcp-schema` crate in your Rust project, follow these steps:\n\n**1. Prerequisites:**\n\n*   Ensure you have Rust and Cargo installed. You can download them from [https://www.rust-lang.org/](https://www.rust-lang.org/).\n\n**2. Installation:**\n\nAdd the following to your `Cargo.toml` file:\n\n```toml\n[dependencies]\nrust-mcp-schema = \"0.7.1\" # Replace with the desired version\n```\n\nThis will include the latest version of the MCP Protocol schema by default.\n\n**3. Switching Schema Versions (Optional):**\n\nIf you need to use a specific schema version, disable the default features and enable the feature corresponding to the desired version.  You can enable multiple schema versions concurrently if needed.\n\n*   **Example: Enable the `2024_11_05` schema version:**\n\n    ```toml\n    [dependencies]\n    rust-mcp-schema = { version = \"0.7.1\", default-features = false, features = [\"2024_11_05\"] }\n    ```\n\n*   **Example: Enable the `draft` schema version:**\n\n    ```toml\n    [dependencies]\n    rust-mcp-schema = { version = \"0.7.1\", default-features = false, features = [\"draft\"] }\n    ```\n\n**4. Using the Crate:**\n\nIn your Rust code, import the crate and use the desired schema version.  If you are using a specific version, access it through its module name.\n\n```rust\nuse rust_mcp_schema; // For the default (latest) version\n\n// For a specific version (e.g., 2024_11_05):\n#[cfg(feature = \"2024_11_05\")]\nuse rust_mcp_schema::mcp_2024_11_05 as mcp;\n\n// Example usage (assuming you've enabled the 2024_11_05 feature):\n#[cfg(feature = \"2024_11_05\")]\nfn main() {\n    // Access types from the specific schema version\n    let _ = mcp::InitializeRequest {\n        client_info: None,\n        capabilities: None,\n        protocol_version: None,\n        _meta: None,\n    };\n\n    println!(\"Using the 2024_11_05 schema.\");\n}\n\n#[cfg(not(feature = \"2024_11_05\"))]\nfn main() {\n    println!(\"Using the default schema.\");\n}\n```\n\n**5. Enabling `schema_utils` (Optional):**\n\nThe `schema_utils` module is enabled by default. If you want to explicitly enable it (or re-enable it after disabling default features), ensure the `schema_utils` feature is included:\n\n```toml\n[dependencies]\nrust-mcp-schema = { version = \"0.7.1\", features = [\"schema_utils\"] }\n```\n\nThen, you can access it in your code:\n\n```rust\nuse rust_mcp_schema::schema_utils;\n```\n\n**Note:** There are no specific environment variables or configuration files required for this crate. The schema version is controlled through Cargo features.","tools":"## Available Tools\n\n- **Type-safe MCP Protocol Implementation:** Provides a type-safe Rust implementation of the Model Context Protocol (MCP) specification, ensuring data integrity and reducing runtime errors.\n\n- **Auto-Generated Schemas:** Schemas are automatically generated and synchronized with the official MCP schema specifications, guaranteeing up-to-date alignment with the latest protocol definitions.\n\n- **Comprehensive Schema Versions:** Includes all official released versions of the MCP schema, such as `2025_06_18`, `2025_03_26`, `2024_11_05`, and a `draft` version for early adoption, allowing developers to work with different protocol versions as needed.\n\n  *Example:* To enable a specific schema version, add it as a feature in your `Cargo.toml`:\n\n  ```toml\n  # Cargo.toml\n  rust-mcp-schema = { version: \"0.7.1\", default-features = false, features=[\"2024_11_05\"] }\n  ```\n\n- **`schema_utils` Module:** A complimentary schema utility module that enhances productivity and ensures development integrity by providing strongly-typed objects and implementations without modifying the originally generated schema. It divides the unified `JsonrpcMessage` type into `ClientMessage` and `ServerMessage` for improved type safety.\n\n  *Example:* Using `schema_utils` to detect an `InitializeRequest` message on an MCP server:\n\n  ```rs\n  use rust_mcp_schema::schema_utils::{ClientMessage, RequestFromClient};\n  use rust_mcp_schema::ClientRequest;\n\n  pub fn handle_message(message_payload: &str)->Result<Error> {\n      let message = ClientMessage::from_str(&message_payload)?;\n\n      if let ClientMessage::Request(message_object) = message {\n          if let RequestFromClient::ClientRequest(client_request) = message_object.request {\n              if let ClientRequest::InitializeRequest(initialize_request) = client_request {\n                  handle_initialize_request(initialize_request);\n              }\n          }\n      }\n  }\n  ```","faq":null,"created_at":"2025-02-08T18:21:21+00:00","updated_at":"2025-07-01T18:08:58+00:00","source_url":"https://model-context-protocol.com/clients/rust-mcp-schema","related_articles":[]}