Expand description
§TurboMCP Server
Production-ready MCP (Model Context Protocol) server implementation with zero-boilerplate development, transport-agnostic design, and WASM support.
§Features
- Zero Boilerplate - Use
#[server]and#[tool]macros for instant setup - 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
- Graceful Shutdown - Clean termination with in-flight request handling
§Quick Start
ⓘ
use turbomcp_server::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
}
}
#[tokio::main]
async fn main() {
// Simplest: uses STDIO by default
Calculator.serve().await.unwrap();
}§Runtime Transport Selection
ⓘ
use turbomcp_server::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"),
_ => Transport::stdio(),
})
.serve()
.await
.unwrap();
}§Bring Your Own Server (Axum Integration)
ⓘ
use axum::Router;
use turbomcp_server::prelude::*;
#[tokio::main]
async fn main() {
// Get MCP as an Axum router
let mcp = Calculator.builder().into_axum_router();
// Merge with your app
let app = Router::new()
.route("/health", get(|| async { "OK" }))
.merge(mcp);
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
axum::serve(listener, app).await?;
}Re-exports§
pub use middleware::McpMiddleware;pub use middleware::MiddlewareStack;pub use middleware::Next;
Modules§
- middleware
- Typed middleware for MCP request processing.
- prelude
- Prelude for easy imports.
- transport
- Transport implementations for different protocols. v3 Transport module - shared abstractions for all transports.
Structs§
- Client
Capabilities - Client capabilities received during initialization.
- Composite
Handler - Server composition through handler mounting. A composite handler that mounts multiple handlers with prefixes.
- Connection
Counter - Connection counter for tracking active connections.
- Connection
Guard - Guard that releases a connection slot when dropped.
- Connection
Limits - Connection limits.
- Json
RpcIncoming - Incoming JSON-RPC message - can be request or notification.
- Json
RpcOutgoing - Outgoing JSON-RPC response - wire format for transport.
- Protocol
Config - Protocol version configuration.
- Rate
Limit Config - Rate limiting configuration.
- Rate
Limiter - Rate limiter using token bucket algorithm.
- Request
Context - Context information for an MCP request.
- Required
Capabilities - Required client capabilities.
- Server
Builder - Server builder for configuring and running MCP servers.
- Server
Config - Server configuration.
- Server
Config Builder - Builder for server configuration.
- Visibility
Layer - Progressive disclosure through component visibility control.
A visibility layer that wraps an
McpHandlerand filters components. - Visibility
Session Guard - Progressive disclosure through component visibility control. RAII guard that automatically cleans up session visibility state when dropped.
Enums§
- Capability
Validation - Result of capability validation.
- Config
Validation Error - Errors that can occur during configuration validation.
- Transport
- Transport configuration for the server.
- Transport
Type - Transport type identifier.
Constants§
- SUPPORTED_
PROTOCOL_ VERSIONS - Supported protocol versions.
Traits§
- McpHandler
- The unified MCP handler trait.
- McpHandler
Ext - Extension trait for running McpHandler on various transports.
- McpServer
Ext - Extension trait for creating server builders from handlers.
Functions§
- parse_
request - Parse a JSON string into a JSON-RPC incoming request.
- route_
request - Route a JSON-RPC request to the appropriate handler method.
- route_
request_ with_ config - Route a JSON-RPC request with custom server configuration.
- serialize_
response - Serialize a JSON-RPC outgoing response to a string.