rmcp crate, which provides procedural macros (#[tool], #[tool_router], #[tool_handler]) to register MCP tools with minimal boilerplate. The server runs asynchronously using Tokio with a stdio transport.
Basic calculator server
Located at03-GettingStarted/samples/rust.
Cargo.toml
Cargo.toml
Server code
src/main.rs
How the macros work
| Macro | Purpose |
|---|---|
#[tool_router] | Applied to the impl Calculator block — generates a tool_router() method that builds a dispatch table from all #[tool] methods |
#[tool(description = "...")] | Marks an async method as an MCP tool and attaches a description used in the tool schema |
#[tool_handler] | Applied to the impl ServerHandler for Calculator block — wires ToolRouter into the MCP protocol handler |
Parameters<T> | Deserializes and validates the incoming JSON arguments into a typed struct |
Input schema
All four tools share the sameCalculatorRequest struct:
schemars::JsonSchema is derived automatically — rmcp uses this to generate the JSON Schema that clients see when they call tools/list.
Available tools
| Tool | Input | Returns |
|---|---|---|
add | { a, b } | "a + b" as a string |
subtract | { a, b } | "a - b" as a string |
multiply | { a, b } | "a * b" as a string |
divide | { a, b } | "a / b" or "Error: Division by zero" |