Expand description
§TurboMCP Core
Core MCP types and primitives - no_std compatible for WASM targets.
This crate provides the foundational types for the Model Context Protocol (MCP)
that can be used in no_std environments including WebAssembly.
§Features
std(default): Enable standard library support, including richer error typesrich-errors: Enable UUID-based error tracking (requiresstd)wasm: Enable WASM-specific optimizationszero-copy: Enable rkyv zero-copy serialization for internal message passing
§Unified Handler Trait
The McpHandler trait is the core abstraction for MCP servers. It works on
both native and WASM targets through platform-adaptive bounds:
ⓘ
use turbomcp_core::{McpHandler, RequestContext};
use turbomcp_types::*;
#[derive(Clone)]
struct MyServer;
impl McpHandler for MyServer {
fn server_info(&self) -> ServerInfo {
ServerInfo::new("my-server", "1.0.0")
}
// ... other methods
}§Platform-Adaptive Bounds
The MaybeSend and MaybeSync marker traits enable unified code:
- Native: Requires
Send + Syncfor multi-threaded executors - WASM: No thread safety requirements (single-threaded)
§no_std Usage
[dependencies]
turbomcp-core = { version = "3.6.0", default-features = false }§Module Organization
auth: Authentication traits and types (portable across native/WASM)handler: Unified MCP handler traitcontext: Request context typesmarker: Platform-adaptive marker traitserror: Error types and handlingjsonrpc: JSON-RPC 2.0 types
MCP protocol types (tools, resources, prompts, capabilities, etc.) live in
turbomcp_types and are re-exported from this crate’s root.
§Example
use turbomcp_core::{Tool, ToolInputSchema};
use turbomcp_core::error::{McpError, ErrorKind};
// Create a tool definition
let tool = Tool {
name: "calculator".into(),
description: Some("Performs calculations".into()),
input_schema: ToolInputSchema::default(),
..Default::default()
};Re-exports§
pub use error::ErrorKind;pub use error::McpError;pub use error::McpResult;pub use jsonrpc::JSONRPC_VERSION;pub use jsonrpc::JsonRpcError;pub use jsonrpc::JsonRpcErrorCode;pub use jsonrpc::JsonRpcIncoming;pub use jsonrpc::JsonRpcNotification;pub use jsonrpc::JsonRpcOutgoing;pub use jsonrpc::JsonRpcRequest;pub use jsonrpc::JsonRpcResponse;pub use jsonrpc::JsonRpcVersion;pub use jsonrpc::RequestId;pub use jsonrpc::ResponseId;pub use response::Image;pub use response::IntoToolError;pub use response::IntoToolResponse;pub use response::Json;pub use response::Text;pub use response::ToolError;pub use security::DANGEROUS_URI_SCHEMES;pub use security::DEFAULT_MAX_STRING_LENGTH;pub use security::DEFAULT_MAX_URI_LENGTH;pub use security::InputLimits;pub use security::InputValidationError;pub use security::check_uri_scheme_safety;pub use security::sanitize_error_message;pub use auth::AuthError;pub use auth::Authenticator;pub use auth::Credential;pub use auth::CredentialExtractor;pub use auth::HeaderExtractor;pub use auth::JwtAlgorithm;pub use auth::JwtConfig;pub use auth::Principal;pub use auth::StandardClaims;pub use context::RequestContext;pub use context::TransportType;pub use handler::McpHandler;pub use marker::MaybeSend;pub use marker::MaybeSync;pub use session::Cancellable;pub use session::McpSession;pub use session::SessionFuture;
Modules§
- auth
- Authentication traits and types for MCP servers.
- context
- Unified request context for MCP handlers.
- error
- Unified MCP error handling - no_std compatible.
- error_
codes - Protocol error codes (JSON-RPC standard + MCP extensions)
- features
- Protocol feature constants
- handler
- Unified MCP handler trait for cross-platform server implementations.
- jsonrpc
- JSON-RPC 2.0 types - no_std compatible.
- marker
- Platform-adaptive marker traits for cross-platform compatibility.
- meta_
keys - Keys TurboMCP writes into MCP
_metamaps. - methods
- Protocol method names (single source of truth)
- response
- Response traits for ergonomic tool handler returns.
- rkyv_
types zero-copy - Zero-copy message types using rkyv serialization.
- router
- Shared MCP request router for all platforms.
- security
- Security utilities for error sanitization and input validation.
- session
- Bidirectional session and cancellation abstractions.
- uri_
template - Matching a URI against an RFC 6570 URI template.
Macros§
- mcp_err
- Convenience macro for creating errors with location
Structs§
- Annotations
- Annotations for content providing metadata.
- Audio
Content - Audio content (base64 encoded).
- Embedded
Resource - Embedded resource content in a message.
- Icon
- Icon for tools, resources, prompts, or servers.
- Image
Content - Image content (base64 encoded).
- Message
- A message in a prompt (
PromptMessageper spec). - Prompt
- Prompt definition.
- Prompt
Argument - Argument definition for prompts.
- Prompt
Result - Result from getting a prompt.
- Resource
- Resource definition.
- Resource
Annotations - Annotations for resources.
- Resource
Result - Result from reading a resource.
- Resource
Template - Resource template definition.
- Server
Info - Server information for MCP initialization.
- Text
Content - Text content with optional annotations.
- Tool
- Tool definition.
- Tool
Annotations - Annotations for tools describing behavior hints.
- Tool
Input Schema - JSON Schema for tool input parameters.
- Tool
Result - Result from calling a tool.
Enums§
- Content
- Content block in MCP messages (
ContentBlockper spec). - Resource
Contents - Contents of a resource (text or binary).
- Role
- Role in a conversation or prompt message.
Constants§
- DEFAULT_
TIMEOUT_ MS - Default timeout for operations in milliseconds
- LOG_
LEVELS - The eight logging severities MCP defines, in ascending order.
- MAX_
MESSAGE_ SIZE - Maximum message size in bytes (1MB)
- PROTOCOL_
VERSION - MCP Protocol version supported by this SDK (latest official spec).
- SDK_
NAME - SDK name
- SDK_
VERSION - SDK version
- SUPPORTED_
VERSIONS - Supported protocol version strings.
Traits§
- Into
Prompt Result - Convert any type to a
PromptResult. - Into
Resource Result - Convert any type to a
ResourceResult. - Into
Tool Result - Convert any type to a
ToolResult.
Functions§
- log_
level_ rank - Severity rank of a log level, or
Noneif it is not one ofLOG_LEVELS.