Expand description
§TurboMCP - Model Context Protocol SDK
Rust SDK for the Model Context Protocol (MCP) with zero-boilerplate macros, transport-agnostic design, and WASM support.
§Features
- Zero Boilerplate -
#[server],#[tool],#[resource],#[prompt]macros - Transport Agnostic - STDIO, HTTP, WebSocket, TCP, Unix sockets
- Runtime Selection - Choose transport at runtime without recompilation
- BYO Server - Integrate with existing Axum/Tower infrastructure
- WASM Ready - no_std compatible core for edge deployment
- Type Safe - Automatic JSON schema generation from Rust types
§Quick Start
ⓘ
use turbomcp::prelude::*;
#[derive(Clone)]
struct Calculator;
#[server(name = "calculator", version = "1.0.0")]
impl Calculator {
/// Add two numbers together
#[tool]
async fn add(&self, a: i64, b: i64) -> i64 {
a + b
}
/// Multiply two numbers
#[tool]
async fn multiply(&self, a: i64, b: i64) -> i64 {
a * b
}
}
#[tokio::main]
async fn main() {
Calculator.serve().await.unwrap();
}§Runtime Transport Selection
ⓘ
use turbomcp::prelude::*;
#[tokio::main]
async fn main() {
let transport = std::env::var("MCP_TRANSPORT").unwrap_or_default();
Calculator.builder()
.transport(match transport.as_str() {
"http" => Transport::http("0.0.0.0:8080"),
"ws" => Transport::websocket("0.0.0.0:8080"),
"tcp" => Transport::tcp("0.0.0.0:9000"),
_ => Transport::stdio(),
})
.serve()
.await
.unwrap();
}§BYO Server (Axum Integration)
ⓘ
use axum::{Router, routing::get};
use turbomcp::prelude::*;
#[tokio::main]
async fn main() {
// Get MCP routes as an Axum router
let mcp = Calculator.builder().into_axum_router();
// Merge with your existing routes
let app = Router::new()
.route("/health", get(|| async { "OK" }))
.merge(mcp);
// Run with your own server
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, app).await.unwrap();
}§Feature Flags
Choose the right feature set for your use case:
# Minimal (STDIO only, recommended for CLI tools)
turbomcp = { version = "3.0", default-features = false, features = ["minimal"] }
# Full (all transports)
turbomcp = { version = "3.0", features = ["full"] }Available features:
stdio- Standard I/O transport (default, works with Claude Desktop)http- HTTP/SSE transportwebsocket- WebSocket bidirectional transporttcp- Raw TCP socket transportunix- Unix domain socket transport
Re-exports§
pub use turbomcp_telemetry as telemetry;telemetry
Modules§
- prelude
- Convenient prelude for TurboMCP applications.
- testing
- In-memory test client for ergonomic MCP server testing. In-memory test client for ergonomic MCP server testing.
Structs§
- Call
Tool Request - Request payload for tool invocation A request to execute a specific tool.
- Call
Tool Result - Response payload for tool execution results
The result of a
CallToolRequest. - Client
Capabilities - Client capability declaration during initialization Client capabilities per MCP 2025-11-25 specification
- Image
- Image content type for multimodal responses Wrapper for returning base64-encoded image data.
- Initialize
Request - Initial handshake request from client to server
The
initializerequest is sent by the client as the first message after connection. - Initialize
Result - Initial handshake response with server capabilities
The response to a successful
initializerequest. - Json
- JSON content wrapper for structured data responses Wrapper for returning JSON-serialized data from a tool handler.
- Json
RpcError - JSON-RPC 2.0 error object JSON-RPC error object
- Json
RpcNotification - JSON-RPC 2.0 notification (no response expected) JSON-RPC notification message (no response expected)
- Json
RpcRequest - JSON-RPC 2.0 request message JSON-RPC request message
- Json
RpcResponse - JSON-RPC 2.0 response message JSON-RPC response message
- McpError
- Unified MCP error type
- Message
- A message in a prompt (
PromptMessageper spec). - Prompt
- Prompt definition.
- Prompt
Argument - Argument definition for prompts.
- Prompt
Result - Result from getting a prompt.
- Request
Context - Minimal request context that works on all platforms.
- Resource
- Resource definition.
- Resource
Link - A resource link (reference without embedding contents).
- Resource
Result - Result from reading a resource.
- Server
Builder - Builder for configuring and launching MCP servers with transports Server builder for configuring and running MCP servers.
- Server
Capabilities - Server capability declaration during initialization Server capabilities per MCP 2025-11-25 specification
- Server
Config - Configuration for MCP server behavior, timeouts, and protocol versions Server configuration.
- Server
Config Builder - Builder for constructing
ServerConfigwith type-safe defaults Builder for server configuration. - Server
Info - Server information for MCP initialization.
- Text
- Text content type for string responses Wrapper for explicitly returning text content.
- Tool
- Tool definition.
- Tool
Error - Tool execution error with code and message
Error type for tool handlers that supports the
?operator. - Tool
Input Schema - JSON Schema for tool input parameters.
- Tool
Result - Result from calling a tool.
Enums§
- Message
Id - Unique identifier for correlating requests and responses Unique identifier for messages
- Resource
Contents - Contents of a resource (text or binary).
- Role
- Role in a conversation or prompt message.
- Sampling
Content - Content block for sampling messages (
SamplingMessageContentBlockper spec). - Sampling
Content Block - Wrapper that deserializes as either a single content block or an array.
- Transport
- Transport configuration enum for runtime transport selection Transport configuration for the server.
Constants§
- CRATE_
NAME - TurboMCP crate name
- VERSION
- TurboMCP version from Cargo.toml
Traits§
- Into
Prompt Result - Convert any type to a
PromptResult. - Into
Resource Result - Convert any type to a
ResourceResult. - Into
Tool Error - Trait for converting errors into tool error responses Convenience trait for converting to ToolError with context.
- Into
Tool Response - Trait for converting values into tool responses Trait for types that can be converted into a tool response.
- Into
Tool Result - Convert any type to a
ToolResult. - McpHandler
- The unified MCP handler trait.
- McpHandler
Ext - Extension trait providing transport-specific serve methods (
serve_stdio,serve_http, etc.) Extension trait for running McpHandler on various transports. - McpServer
Ext - Extension trait for MCP server operations Extension trait for creating server builders from handlers.
Type Aliases§
- McpResult
- Result type alias for MCP operations
Attribute Macros§
- description
- Provides a description for a tool parameter.
- prompt
- Marks a method as a prompt handler within a
#[server]block. - resource
- Marks a method as a resource handler within a
#[server]block. - server
- Marks an impl block as an MCP server with automatic McpHandler implementation.
- tool
- Marks a method as a tool handler within a
#[server]block.