kuri (栗 or くり)
About
Ergonomic framework to write MCP Servers in Rust
Details
- Author
- itsaphel
- GitHub stars
- 12
- Downloads
- 138
- Categories
- Other
Jump to
- Ergonomic developer experience with minimal macros and boilerplate
- Tools and prompts are plain async Rust functions
- Built on the tower ecosystem for middleware (timeouts, tracing)
- Core MCP lifecycle: initialization, capability negotiation, session control
- stdio transport included; HTTP streaming transport planned
Add kuri and its dependencies (tokio, serde, schemars, etc.) to your Cargo.toml. Then use MCPServiceBuilder to create a service, register tools and prompts via the #[tool] and #[prompt] macros, and serve over the stdio transport with serve(service.into_request_service(), StdioTransport::new()).
kuri (栗 or くり)
kuri is a framework to build [Model Context Protocol][mcp-docs] (MCP) servers, focused on developer ergonomics and clarity.
MCP allows an LLM to execute predefined functions (called 'tools'), which allow it to fetch data and have side effects (ie: interact with the outside world). The LLM just needs to provide the input arguments of the function, which is then executed and the response is returned to the model. These tools are provided by "MCP servers", which can be ran locally, and a single server can provide multiple tools.
Design philosophy
Rust is an excellent language to write reliable MCP servers, with its strong type system and correctness guarantees. kuri aims to make MCP server programming in Rust extremely pleasant, to facilitate using Rust for building MCP servers. Our design goals are:
- Ergonomic developer experience: MCP server programming should feel like normal Rust programming. Tools and prompts are just plain async Rust functions.
- Minimal use of macros (#[tool], #[prompt]): only for attaching tool and argument descriptions, not complex code generation.
- Minimal boilerplate: focus on your application logic, not on serialisation or MCP protocol routing.
- Take advantage of the [tower] ecosystem of middleware, services and utilities. Get timeouts, tracing, panic-handling, and more for free, and re-use components from [axum], [tonic] and [hyper].
The above is some of what sets us apart from other MCP server crates. We're focused on doing one thing, and doing it really well. And there's no magic complex macros, your application code remains self-explanatory, and kuri's internals are clean to read and understand. kuri also builds on [tower], allowing you to re-use a rich ecosystem of middleware and layers.
Example
use kuri::{MCPServiceBuilder, ServiceExt, ToolError, prompt, serve, tool, transport::StdioTransport};
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub enum Operation {
Add,
Subtract,
Multiply,
Divide,
}
// A pure function that takes three inputs and returns an integer. Descriptions
// for the tool and its parameters help the model decide which tool to use, and
// correctly supply the tool's parameters.
#[tool(
description = "Perform basic arithmetic operations",
params(
x = "First number in the calculation",
y = "Second number in the calculation",
operation = "The operation to perform (add, subtract, multiply, divide)"
)
)]
async fn calculator(x: i32, y: i32, operation: Operation) -> Result<i32, ToolError> {
match operation {
Operation::Add => Ok(x + y),
Operation::Subtract => Ok(x - y),
Operation::Multiply => Ok(x * y),
Operation::Divide => {
if y == 0 {
Err(ToolError::ExecutionError("Division by zero".to_string()))
} else {
Ok(x / y)
}
}
}
}
// Creates a prompt template for text summarisation. The application provides
// the text to summarise, and an optional format parameter (denoted using Rust's
// Option type). kuri tells the model that format may be omitted.
#[prompt(
description = "Generates a prompt for summarising text",
params(
text = "The text to summarise",
format = "Optional format for the summary (eg: 'bullet points' or 'Shakespeare')"
)
)]
async fn summarise_text(text: String, format: Option<String>) -> String {
let format_instruction = match format {
Some(f) => format!(" in the format of {}", f),
None => String::new(),
};
format!(
"Please summarize the following text{}:\n\n{}",
format_instruction, text
)
}
#[tokio::main]
async fn main() -> Result<(), TransportError> {
// Create the MCP service with the server's name
let service = MCPServiceBuilder::new("kuri's test server".to_string())
// Register the tool and prompt
.with_tool(Calculator)
.with_prompt(SummariseText)
.build();
// Serve over the stdio transport
serve(service.into_request_service(), StdioTransport::new()).await
}
More in [the examples]
To get started, add kuri and some necessary dependencies to your Cargo.toml:
[dependencies]
kuri = "0.1"
async-trait = "0.1"
schemars = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
MCP specification support
- [x] Core lifecycle: connection initialisation, capability negotiation, and session control
- [x] Tools: Feature complete with tests
- [x] Prompts: Mostly complete with tests
- [ ] Resources
- Transports
- [x] stdin/stdout
- [ ] Streaming HTTP ([2025-03-26 protocol])
- Extra (optional) features
- [ ] [Completions][mcp-completions]
- [ ] [Pagination][mcp-pagination]
Our current priorities are adding HTTP transport support, stabilising the API, and ensuring full support of the core specification.
Contributing
The goal of this project is to build a pleasant, ergonomic, idiomatic Rust library for building MCP Servers. It's in an early phase, so the structure can still change. If you enjoy any of Rust, MCP, building crates, or network protocols (maybe you're into protohackers!), we'd love to have you! Get involved in the repo, or reach out by email if you want to chat!
If you've used this framework for your project: thanks for trying it out! I'd love to hear about your experience!
[hyper]: https://github.com/hyperium/hyper
[tonic]: https://github.com/hyperium/tonic
[tower]: https://github.com/tower-rs/tower
[axum]: https://github.com/tokio-rs/axum
[actix]: https://github.com/actix/actix-web
[mcp-docs]: https://modelcontextprotocol.io
[the examples]: examples/
[2025-03-26 protocol]: https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http
[mcp-completions]: https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/completion
[mcp-pagination]: https://spec.modelcontextprotocol.io/specification/2025-03-26/server/utilities/pagination/
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



