Skip to main content

Crate turbomcp_server

Crate turbomcp_server 

Source
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§

ClientCapabilities
Client capabilities received during initialization.
CompositeHandler
Server composition through handler mounting. A composite handler that mounts multiple handlers with prefixes.
ConnectionCounter
Connection counter for tracking active connections.
ConnectionGuard
Guard that releases a connection slot when dropped.
ConnectionLimits
Connection limits.
JsonRpcIncoming
Incoming JSON-RPC message - can be request or notification.
JsonRpcOutgoing
Outgoing JSON-RPC response - wire format for transport.
ProtocolConfig
Protocol version configuration.
RateLimitConfig
Rate limiting configuration.
RateLimiter
Rate limiter using token bucket algorithm.
RequestContext
Context information for an MCP request.
RequiredCapabilities
Required client capabilities.
ServerBuilder
Server builder for configuring and running MCP servers.
ServerConfig
Server configuration.
ServerConfigBuilder
Builder for server configuration.
VisibilityLayer
Progressive disclosure through component visibility control. A visibility layer that wraps an McpHandler and filters components.
VisibilitySessionGuard
Progressive disclosure through component visibility control. RAII guard that automatically cleans up session visibility state when dropped.

Enums§

CapabilityValidation
Result of capability validation.
ConfigValidationError
Errors that can occur during configuration validation.
Transport
Transport configuration for the server.
TransportType
Transport type identifier.

Constants§

SUPPORTED_PROTOCOL_VERSIONS
Supported protocol versions.

Traits§

McpHandler
The unified MCP handler trait.
McpHandlerExt
Extension trait for running McpHandler on various transports.
McpServerExt
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.