6 releases
new 0.1.5 | Mar 13, 2025 |
---|---|
0.1.4 | Mar 13, 2025 |
#35 in #mcp
103 downloads per month
Used in 3 crates
18KB
432 lines
Tiny MCP Server
A Rust implementation of the Machine Communication Protocol (MCP) server, designed for efficient and reliable communication between machines and tools.
Features
- Multiple Transport Layers: Supports both stdio and Server-Sent Events (SSE) transports
- Extensible Tool System: Easily register custom tools with the server
- Type-Safe API: Leverages Rust's type system for safe and reliable communication
- Asynchronous Design: Built on tokio for high-performance async I/O
- Simple Integration: Just add a single dependency to your project
- Convenient Imports: Use the prelude module to import all necessary types and traits
Installation
Add this to your Cargo.toml
:
[dependencies]
tiny_mcp_server = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
serde_json = "1.0"
Quick Start
For convenience, you can use the prelude module to import all necessary types and traits:
use serde_json::{Value, json};
use std::error::Error;
use tiny_mcp_server::prelude::*;
#[mcp_tool(
description = "A simple greeting tool",
version = "1.0.0",
category = "examples"
)]
pub async fn say_hello(name: String) -> MCPResult<Value> {
Ok(json!({
"greeting": format!("Hello {name}")
}))
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Start with stdio transport
server::start_stdio().await
}
Documentation
For more detailed documentation, see the API documentation.
Examples
Check out the examples directory for more usage examples:
stdio.rs
: Example using stdio transportsse.rs
: Example using SSE transport
License
This project is licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Dependencies
~2.6–9MB
~79K SLoC