TurboMCP Protocol
Model Context Protocol (MCP) implementation for MCP 2025-11-25, with JSON-RPC 2.0 and runtime schema validation.
Table of Contents
- Overview
- Key Features
- Version Selection Guide
- Architecture
- MCP Message Types
- Usage
- Message Flow
- Feature Flags
- Supported MCP Methods
- Integration
Overview
turbomcp-protocol provides a specification-compliant implementation of the Model Context Protocol (MCP). This crate handles protocol-level concerns including message formatting, capability negotiation, and runtime validation.
MCP Version Support
TurboMCP v3 targets MCP 2025-11-25 as the latest stable protocol and keeps
adapter support for 2025-06-18 compatibility. Core protocol capabilities are
enabled by default; runtime negotiation policy is configured by the server or
client transport layer.
| Spec Version | Status | Notes |
|---|---|---|
| MCP 2025-11-25 | ✅ Full Support | Canonical v3 protocol surface |
| MCP 2025-06-18 | ✅ Compatibility | Supported through version adapters |
Quick Start:
[]
= "3.1.4"
Only the experimental Tasks API (SEP-1686) requires a feature flag:
[]
= { = "3.1.4", = ["experimental-tasks"] }
Key Features
MCP Specification Support
- MCP specification implementation with current message types
- Tools, resources, prompts, and capabilities support
- Capability negotiation with feature detection and handshake
- Exact-version negotiation support
JSON-RPC 2.0 Implementation
- Compliant message format with request, response, and notification handling
- ID correlation for automatic request/response matching
- Standard JSON-RPC error codes and extensions
- Support for batch request/response operations
Runtime Schema Validation
- JSON Schema validation using
jsonschemacrate - Rust type definitions for MCP message types
- Tool and resource parameter validation
- Schema generation from Rust types
Capability Management
- Type-State Capability Builders - Compile-time validated capability configuration
- Server capabilities for tools, resources, prompts declarations
- Client capabilities including sampling, roots, progress reporting
- Feature negotiation with capability matching
- Support for custom capability extensions
MCP Enhanced Features
- Bidirectional communication for server-initiated requests to clients
- Elicitation support for server-requested structured input from users
- Completion context with references and metadata
- Resource templates for dynamic resource generation with parameters
- Ping/keepalive for connection health monitoring
Architecture
┌─────────────────────────────────────────────┐
│ TurboMCP Protocol │
├─────────────────────────────────────────────┤
│ MCP Message Types │
│ ├── InitializeRequest/InitializeResult │
│ ├── Tool/Resource/Prompt messages │
│ ├── Capability negotiation │
│ └── Notification handling │
├─────────────────────────────────────────────┤
│ JSON-RPC 2.0 Layer │
│ ├── Request/Response correlation │
│ ├── ID generation and tracking │
│ ├── Error code standardization │
│ └── Batch message processing │
├─────────────────────────────────────────────┤
│ Schema Validation │
│ ├── Runtime JSON schema validation │
│ ├── Parameter type checking │
│ ├── Response format validation │
│ └── Custom schema extension support │
└─────────────────────────────────────────────┘
MCP Message Types
Core Message Types
use ;
use ;
MCP Enhanced Types
use ;
use ;
JSON-RPC Infrastructure
use ;
Usage
Basic Protocol Handling
use ;
// Parse incoming JSON-RPC request
let json_data = r#"{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-11-25",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "2.0.0"}
}
}"#;
let request: JsonRpcRequest = from_str?;
// Handle specific message types
match request.method.as_str
Message Validation
use ;
// Create a validator with default rules
let validator = default;
// Parse and validate a JSON-RPC request
let json_data = r#"{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {"name": "add", "arguments": {"a": 5, "b": 3}}
}"#;
let request: JsonRpcRequest = from_str?;
let result = validator.validate_request;
match result
Type-State Capability Builders
use ;
// Compile-time validated server capabilities
let server_caps = new
.enable_tools // Enable tools capability
.enable_resources // Enable resources capability
.enable_prompts // Enable prompts capability
.enable_tool_list_changed // ✅ Only available when tools enabled
.enable_resources_subscribe // ✅ Only available when resources enabled
.enable_resources_list_changed // ✅ Only available when resources enabled
.build;
// Opt-out client capabilities (all enabled by default)
let client_caps = new
.enable_roots_list_changed // Configure sub-capabilities
.build; // All capabilities enabled!
// Opt-in pattern for restrictive clients
let minimal_client = minimal
.enable_sampling // Only enable what you need
.enable_roots
.build;
Traditional Capability Negotiation
use ;
// Traditional approach (still supported)
let server_caps = ServerCapabilities ;
// Define client capabilities
let client_caps = ClientCapabilities ;
Error Handling
The protocol crate re-exports McpError (also aliased as Error) from
turbomcp-core as the canonical MCP error type, with rich context and
observability support.
Creating Errors
Error constructors return McpError directly (not Box<_>):
use ;
// MCP specification errors (map to standard error codes)
let err = tool_not_found; // -32001
let err = tool_execution_failed; // -32002
let err = prompt_not_found; // -32003
let err = resource_not_found; // -32004
let err = resource_access_denied; // -32005
let err = invalid_params; // -32602
let err = user_rejected; // -1
// Add context with the builder pattern
let err = internal
.with_operation
.with_component
.with_request_id;
Working with JSON-RPC Errors
use ;
// Create JSON-RPC errors directly. `JsonRpcError::code` is an i32;
// use `JsonRpcErrorCode::code()` to get the numeric value.
// Convert an McpError to its JSON-RPC / HTTP numeric codes
let err = tool_not_found;
let code = err.jsonrpc_error_code; // -32001
let http = err.http_status; // 404
// Inspect the ErrorKind directly
assert_eq!;
Error Properties
use McpError;
let err = timeout;
// Check error characteristics
if err.is_retryable
if err.is_temporary
// Get HTTP status code for REST APIs
let status = err.http_status; // 408
// Get MCP-compliant JSON-RPC error code
let code = err.jsonrpc_error_code; // -32012
Integration with Application Layer
If you're using the main turbomcp crate, you typically use McpError in your tool handlers. The server layer automatically converts to Box<Error>:
// In your tool handler (turbomcp crate)
use ;
async
// Server layer converts to:
// ServerError::Protocol(Error::tool_execution_failed("my_tool", "Something failed"))
See the turbomcp crate error handling docs for the complete error architecture.
Custom Message Types
use ;
use RequestId;
use ;
// Define custom message types
// Create custom JSON-RPC messages.
// Note: `jsonrpc` is a `JsonRpcVersion` newtype, and `params` is `Option<Value>`.
Message Flow
sequenceDiagram
participant Client
participant Protocol as turbomcp-protocol
participant Server
Client->>Protocol: Raw JSON message
Protocol->>Protocol: Parse JSON-RPC
Protocol->>Protocol: Validate message format
Protocol->>Protocol: Extract MCP message
Protocol->>Protocol: Validate against schema
Protocol->>Server: Typed MCP message
Server->>Protocol: Typed MCP response
Protocol->>Protocol: Serialize response
Protocol->>Protocol: Wrap in JSON-RPC
Protocol->>Client: JSON response
Version Selection Guide
Protocol Version
TurboMCP v3 targets MCP 2025-11-25 as the latest stable version. The default VersionManager
(VersionManager::default() / Version::known_versions()) advertises
the stable set — 2025-06-18 and 2025-11-25 — and negotiates exact
matches (newest is selected as current).
For full cross-version translation with older peers, the crate also
ships version adapters for 2025-06-18 (and a draft DRAFT-2026-v1
type) in turbomcp_protocol::versioning::adapter — use
adapter_for_version to opt into field-level filtering.
Core Features (Always Enabled)
All core MCP 2025-11-25 features are now always available - no feature flags needed:
- URL Elicitation (SEP-1036) - URL mode for OAuth/sensitive data
- Sampling Tools (SEP-1577) - Tool calling in LLM sampling
- Icons (SEP-973) - Icon metadata for tools, resources, prompts
- Enum Improvements (SEP-1330) - Standards-compliant enum schemas
[]
= "3.1.4" # All core features included
Runtime Version Negotiation
Client-side:
use ;
// `protocol_version` is a `ProtocolVersion`; string literals convert via `.into()`.
let init = InitializeRequest ;
Server-side:
use ;
// With the default `VersionManager`, the server must respond with the
// exact version it supports (2025-11-25) or fail initialization.
let result = InitializeResult ;
Key Principle: Clients request a version; the default server
implementation accepts it only on exact match. Use the adapters in
versioning::adapter if you need to translate across versions.
Migration from v2.x
This section is historical. v3 does not preserve the old multi-version runtime policy.
TurboMCP v3.0 simplifies feature flags - all MCP 2025-11-25 features are now core:
Before (v2.x):
= { = "2.x", = ["mcp-url-elicitation", "mcp-icons"] }
After (v3.0):
= "3.1.4" # All features included by default
Example:
// No feature guards needed - URLElicitRequestParams is always available
use URLElicitRequestParams;
Feature Flags
Default Features
| Feature | Description | Default |
|---|---|---|
std |
Standard library support | ✅ |
simd |
SIMD-accelerated JSON parsing (simd-json, sonic-rs) | ✅ |
Performance Features
| Feature | Description | Default |
|---|---|---|
zero-copy |
Zero-copy message handling (bytes/serde) |
❌ |
rkyv |
rkyv zero-copy serialization bridge | ❌ |
messagepack |
MessagePack serialization via msgpacker |
❌ |
wire |
turbomcp-wire codec abstraction |
❌ |
wire-simd |
Wire codec with SIMD acceleration | ❌ |
wire-msgpack |
Wire codec with MessagePack support | ❌ |
mmap |
Memory-mapped file support | ❌ |
lock-free |
Lock-free data structures (experimental, requires unsafe) | ❌ |
Observability Features
| Feature | Description | Default |
|---|---|---|
tracing |
OpenTelemetry tracing integration | ❌ |
metrics |
Prometheus metrics collection | ❌ |
fancy-errors |
Rich error reporting with miette | ❌ |
Platform Features
| Feature | Description | Default |
|---|---|---|
wasm |
WebAssembly support (no_std compatible) | ❌ |
MCP 2025-11-25 Features
Core Features (Always Enabled)
These MCP 2025-11-25 features are now always available - no feature flag needed:
| Feature | SEP | Description |
|---|---|---|
| URL Elicitation | SEP-1036 | URL mode for OAuth/sensitive data collection |
| Sampling Tools | SEP-1577 | Tool calling support in LLM sampling |
| Icons | SEP-973 | Icon metadata for tools/resources/prompts |
| Enum Improvements | SEP-1330 | Standards-based enum schemas (oneOf, anyOf) |
Optional Features
| Feature | SEP | Description | Enabled by Default |
|---|---|---|---|
experimental-tasks |
SEP-1686 | Convenience APIs for durable task operations; wire types are available | ❌ |
Legend:
- ✅ : Always enabled (core feature)
- ❌ : Disabled by default (requires explicit feature flag)
Authentication & Security:
Full OAuth 2.1 / OpenID Discovery / DPoP / incremental-consent support
lives in the companion crates turbomcp-auth and turbomcp-dpop, not
in turbomcp-protocol. This crate only ships the SSRF / URL-validation
primitives needed by the protocol layer itself (see
security).
Feature Flag Examples
Minimal build (stable spec only):
[]
= { = "3.1.4", = false, = ["std"] }
High-performance build:
[]
= { = "3.1.4", = ["simd", "zero-copy", "lock-free"] }
Observable production build:
[]
= { = "3.1.4", = ["simd", "tracing", "metrics"] }
Full MCP 2025-11-25 support (default):
[]
= "3.1.4" # All core features included
With experimental Tasks API:
[]
= { = "3.1.4", = ["experimental-tasks"] }
Supported MCP Methods
Core Methods
initialize- Protocol initialization and capability negotiationinitialized- Initialization completion notification
Tool Methods
tools/list- List available toolstools/call- Execute a tool with parameters
Resource Methods
resources/list- List available resourcesresources/read- Read resource contentresources/updated- Resource change notification
Prompt Methods
prompts/list- List available promptsprompts/get- Get prompt content
Capability Methods
capabilities/changed- Capability change notification
Integration
With TurboMCP Framework
Protocol handling is automatic when using the main framework:
use *;
Direct Protocol Usage
For custom implementations or integrations:
use ;
;
Development
Building
# Build with all features
# Build minimal (std only)
# Build with specific features
Testing
# Run protocol compliance tests
# Test with all features enabled
# Validate against MCP specification
Schema Validation
# Run validation tests
# Run message validation tests
Related Crates
- turbomcp - Main framework (uses this crate)
- turbomcp-transport - Transport layer
- turbomcp-server - Server framework
Note: In v2.0.0, turbomcp-core was merged into this crate to eliminate circular dependencies and improve cohesion.
External Resources
- MCP Specification - Official protocol specification
- JSON-RPC 2.0 - JSON-RPC specification
- JSON Schema - Schema validation specification
License
Licensed under the MIT License.
Part of the TurboMCP Rust SDK for the Model Context Protocol.