| Crates.io | mcp_rust_schema |
| lib.rs | mcp_rust_schema |
| version | 0.1.4 |
| created_at | 2025-01-07 16:32:08.810254+00 |
| updated_at | 2025-01-07 17:13:46.606337+00 |
| description | Rust Schema for the Model Context Protocol (MCP) |
| homepage | |
| repository | https://github.com/infosechoudini/mcp-rust-schema |
| max_upload_size | |
| id | 1507433 |
| size | 37,641 |
A Rust implementation of the Model Context Protocol (MCP) schema, providing type definitions and validation for MCP messages.
Add this to your Cargo.toml:
[dependencies]
mcp_rust_schema = "0.1.4"
use mcp_rust_schema::protocol::{Request, RequestId};
use mcp_rust_schema::types::RequestMeta;
use serde_json::json;
// Create a new request
let request = Request::new(
"test/method",
Some(json!({"key": "value"})),
RequestId::String("test-1".to_string()),
Some(RequestMeta {
progress_token: None,
}),
);
use mcp_rust_schema::types::Resource;
use serde_json::json;
use jsonschema::Validator;
// Create a resource
let resource = Resource {
uri: "file:///test.txt".to_string(),
title: "Test File".to_string(),
description: Some("A test file".to_string()),
contents: ResourceContents::Text {
text: "Hello World".to_string(),
uri: "file:///test.txt".to_string(),
mime_type: Some("text/plain".to_string()),
},
mime_type: Some("text/plain".to_string()),
annotations: None,
};
// Validate against schema
let resource_json = serde_json::to_value(resource)?;
let validator = jsonschema::validator_for(&schema)?;
assert!(validator.is_valid(&resource_json));
The library provides comprehensive error handling:
use mcp_rust_schema::error::Error;
match result {
Ok(value) => println!("Success: {:?}", value),
Err(Error::Protocol { code, message, .. }) => println!("Protocol error {}: {}", code, message),
Err(Error::Serialization(e)) => println!("Serialization error: {}", e),
Err(e) => println!("Other error: {}", e),
}
This project is licensed under the MIT License - see the LICENSE file for details.
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)