Logo Rust MCP Schema

Rust MCP Schema

Tổ chức
rust-mcp-stack

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

Nhà phát hànhrust-mcp-stack
Kho mãrust-mcp-schema
Ngôn ngữRust
Bản fork
4
Sao
76
Công cụ có sẵn
0
Phương thức truyền tảistdio
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    Rust MCP Schema cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    76 sao và 4 bản fork từ kho mã được liên kết.

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:

  • 2026-07-28 (default)
  • 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

  • 🧩 Type-safe implementation of the MCP protocol specification.
  • 💎 Auto-generated schemas are always synchronized with the official schema specifications.
  • 📜 Includes all official released versions : 2026-07-28, 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.

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_2025_11_25

📌 Note: the three most recent schemas (2026_07_28, 2025_11_25 and draft) are also re-exported at the crate root and are therefore mutually exclusive — enable at most one of them at a time. Older versions (2025_06_18, 2025_03_26, 2024_11_05) are module-only and can be combined with any one of them.

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

toml
# Cargo.toml
rust-mcp-schema = { version: 2.0.0 , default-features = false, features=["2025_06_18"] }

Example: enable `draft`` version of the schema :

toml
#Cargo.toml
rust-mcp-schema = { version: 2.0.0 , default-features = false, features=["draft"] }

How are Schemas generated?

Schemas are generated from the official schema.ts and schema.json files available in the original Model Context Protocol (MCP) repository.

Using a customized version of typify, along with additional pre-processing and post-processing steps, the schema specifications are transformed into Rust code.

📌 Note

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.

What is 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.

📌 Note

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.

If you prefer not to use schema_utils, you can directly work with the enums and structs provided in mcp_schema.rs, adapting them to your needs and creating your own utility types and functions around them.

Visit Usage Examples (Without Using schema_utils) to see an alternative approach.

What does the schema_utils do?

The official schema defines a unified JsonrpcMessage type that encompasses all messages and notifications within the MCP protocol.

To 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.

Please refer to schema_utils.rs and the Usage Examples section for more details.

Usage Examples

: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.

Detecting a CallToolRequest Message on an MCP Server

The 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 a CallToolRequest message.

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.

rs

pub fn handle_message(message_payload: &str) -> std::result::Result<(), RpcError> {
    // Deserialize message into ClientMessage.
    let message = ClientMessage::from_str(message_payload)?;

    // Check if the message is a Request
    if let ClientMessage::Request(client_request) = message {
        // Requests delegate to the schema-generated `ClientRequest` enum via `ClientJsonrpcRequest::Known`
        if let ClientJsonrpcRequest::Known(ClientRequest::CallToolRequest(call_tool_request)) = client_request {
            // Process the CallToolRequest (and eventually send a CallToolResult back to the client)
            handle_call_tool_request(call_tool_request);
        }
    }
    Ok(())
}

Refer to examples/mcp_server_handle_message.rs for a complete match implementation that handles all possible ClientMessage variants.

Creating a CallToolResult Response on an MCP Server.

In response to a CallToolRequest, the MCP Server is expected to return a CallToolResult message.

This code snippet demonstrates how to create a CallToolResult, serialize it into a string, and send it back to the client via the transport layer.

rs
    // create a CallToolResult object (the builder sets `resultType: "complete"`)
    let tool_result = CallToolResult::text_content(vec![TextContent::new(
        "Sunny, 22°C in Paris.".to_string(),
        None,
        None,
    )]);

    // wrap it in a JSON-RPC response envelope addressed to the request's `id`
    let message = ServerJsonrpcResponse::new(RequestId::Integer(0), tool_result.into());

    // Serialize the MCP message into a valid JSON string for sending to the client
    let json_payload = serde_json::to_string(&message).unwrap();

    println!("{}", json_payload);

output:

json
{
  "id": 0,
  "jsonrpc": "2.0",
  "result": {
    "content": [{ "type": "text", "text": "Sunny, 22°C in Paris." }],
    "resultType": "complete"
  }
}

Detecting a CallToolResult Response Message in an MCP Client:

rs
fn handle_message(message_payload: &str) -> std::result::Result<(), AppError> {
    // Deserialize message into ServerMessage.
    // ServerMessage represents a message sent by an MCP Server and received by an MCP Client.
    let mcp_message = ServerMessage::from_str(message_payload)?;

    // Check if the message is a Response type of message
    if let ServerMessage::Response(server_response) = mcp_message {
        // Check if it's a CallToolResult response
        if let ServerResult::CallToolResult(call_tool_result) = &server_response.result {
            // Process the CallToolResult
            handle_call_tool_result(call_tool_result);
        }
    }
    Ok(())
}

Refer to mcp_client_handle_message.rs for a complete match implementation that handles all possible ServerMessage variants.

Usage Examples (Without Utilizing schema_utils)

If you prefer not to use schema_utils, you can directly work with the generated types in your application or build custom utilities around them.

Detecting a CallToolRequest Message on an MCP Server (without schema_utils)

The following code example illustrates how to detect a CallToolRequest message on an MCP server:

rs

fn handle_message(message_payload: &str) -> std::result::Result<(), AppError> {
    // Deserialize the JSON-RPC payload directly into ClientRequest.
    // Its `Deserialize` impl dispatches on the `method` field.
    let client_request: ClientRequest = serde_json::from_str(message_payload).unwrap();

    // Check it's a "tools/call" request
    if let ClientRequest::CallToolRequest(call_tool_request) = client_request {
        // Now that we can handle the message, we simply print out the details.
        println!("CallTool request received!");

        println!("Tool name : {:?} ", call_tool_request.params.name);
        println!("Arguments : {:?} ", call_tool_request.params.arguments);
    }

    Ok(())
}

Contributing

We welcome everyone who wishes to contribute! Please refer to the contributing guidelines for more details.

All contributions, including issues and pull requests, must follow Rust's Code of Conduct.

Unless 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.

Dùng MCP Rust MCP Schema với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối Rust MCP Schema, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm Rust MCP Schema làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của Rust MCP Schema.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "rust-mcp-schema": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của Rust MCP Schema, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của Rust MCP Schema.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng Rust MCP Schema giúp tôi làm việc này không?
Rust MCP Schema
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng Rust MCP Schema.

Câu hỏi thường gặp

Máy chủ MCP Rust MCP Schema dùng để làm gì?

Rust MCP Schema là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP Rust MCP Schema với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng Rust MCP Schema với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP Rust MCP Schema với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối Rust MCP Schema, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP Rust MCP Schema với TypingMind?

Rust MCP Schema hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP Rust MCP Schema cung cấp những công cụ nào trong TypingMind?

Rust MCP Schema cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP Rust MCP Schema không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu Rust MCP Schema yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇