
Rust port of the Model Context Protocol (MCP) schema originally written in TypeScript.
概览
A of the Model Context Protocol (MCP) schema, providing type-safe definitions for building MCP clients and servers. is an open protocol that enables between Large Language Model (LLM) applications and external data sources or tools. - : Expose tools and functions that can be called by language models - : Enable two-way interaction between AI systems and external services - : Strong typing for all protocol messages and data structures - : Support for custom tools, prompts, and resources - Building AI-enhanced development environments - Creating intelligent chat interfaces with external tool access - Developing custom AI workflows with multiple tool integrations - Enabling LLMs to interact with databases, APIs, and file systems This Rust implementation provides several advantages: - : Catch errors at compile time with Rust's strong type system - : Zero-cost abstractions and efficient memory management - : Memory safety guarantees without garbage collection - : Seamless JSON...
README
以下为原文 README 节选,完整内容请查看原文。
mcp-schema
A Rust implementation of the Model Context Protocol (MCP) schema, providing type-safe definitions for building MCP clients and servers.
What is MCP?
Model Context Protocol (MCP) is an open protocol that enables secure, bidirectional communication between Large Language Model (LLM) applications and external data sources or tools.
Key Features
- Tool Integration: Expose tools and functions that can be called by language models
- Bidirectional Communication: Enable two-way interaction between AI systems and external services
- Type Safety: Strong typing for all protocol messages and data structures
- Extensible Architecture: Support for custom tools, prompts, and resources
Use Cases
- Building AI-enhanced development environments
- Creating intelligent chat interfaces with external tool access
- Developing custom AI workflows with multiple tool integrations
- Enabling LLMs to interact with databases, APIs, and file systems
Why Rust?
This Rust implementation provides several advantages:
- Type Safety: Catch errors at compile time with Rust’s strong type system
- Performance: Zero-cost abstractions and efficient memory management
- Reliability: Memory safety guarantees without garbage collection
- Serde Integration: Seamless JSON serialization/deserialization
- Cross-Platform: Build native MCP servers and clients for any platform
Installation
Add mcp-schema to your project:
cargo add mcp-schema
Or add to your Cargo.toml:
[dependencies]
mcp-schema = "0.2.0"
Usage
Basic Example
use mcp_schema::*;
use serde_json::json;
// Create a tool with annotations
let tool = Tool {
name: "calculate".to_string(),
title: Some("Calculator".to_string()),
description: Some("Perform calculations".to_string()),
input_schema: json!({
"type": "object",
"properties": {
"expression": {"type": "string"}
}
}),
output_schema: Some(json!({
"type": "object",
"properties": {
"result": {"type": "number"}
}
})),
annotations: Some(ToolAnnotations {
read_only_hint: Some(true),
destructive_hint: Some(false),
idempotent_hint: Some(true),
open_world_hint: Some(false),
}),
};
// Handle tool results with structured content
let result = CallToolResult {
content: vec![
ContentBlock::Text(TextContent {
text: "Calculation complete".to_string(),
})
],
structured_content: Some(json!({
"result": 42,
"confidence": 0.95
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →