| Crates.io | mcp-schema |
| lib.rs | mcp-schema |
| version | 0.2.0 |
| created_at | 2024-12-22 03:05:38.173194+00 |
| updated_at | 2025-08-09 06:53:49.226991+00 |
| description | Rust port of the Model Context Protocol (MCP) schema originally written in TypeScript. |
| homepage | |
| repository | https://github.com/yonaka15/mcp-schema |
| max_upload_size | |
| id | 1491672 |
| size | 54,805 |
A Rust implementation of the Model Context Protocol (MCP) schema, providing type-safe definitions for building MCP clients and servers.
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.
This Rust implementation provides several advantages:
Add mcp-schema to your project:
cargo add mcp-schema
Or add to your Cargo.toml:
[dependencies]
mcp-schema = "0.2.0"
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
})),
is_error: Some(false),
};
use mcp_schema::*;
use serde_json::json;
// Request user input with schema validation
let elicitation = ElicitationCreateParams {
message: "Please provide your preferences".to_string(),
requested_schema: json!({
"type": "object",
"properties": {
"theme": {
"type": "string",
"enum": ["light", "dark", "auto"]
}
},
"required": ["theme"]
}),
};
// Handle user response
let response = ElicitationCreateResult {
action: ElicitationAction::Accept,
content: Some(json!({
"theme": "dark"
})),
};
readOnlyHint: Tool doesn't modify statedestructiveHint: Tool performs destructive operationsidempotentHint: Tool can be called multiple times safelyopenWorldHint: Tool may return different results over timemcp-schema/
├── src/
│ ├── lib.rs # Public API exports
│ └── types.rs # Core MCP type definitions
├── tests/
│ └── test_latest_spec.rs # Comprehensive test suite
├── Cargo.toml # Project configuration
└── README.md # This file
Run the test suite:
cargo test
Tests cover:
# Build the library
cargo build
# Run tests
cargo test
# Check formatting
cargo fmt --check
# Run linter
cargo clippy
# Generate documentation
cargo doc --open
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.