TurboMCP Core
High-performance core abstractions and SIMD-accelerated message processing for the TurboMCP SDK.
Overview
turbomcp-core
provides the foundational layer for TurboMCP, featuring performance-critical types and zero-copy optimization utilities. This crate serves as the foundation that enables TurboMCP's industry-leading performance characteristics.
Key Features
๐ SIMD-Accelerated Processing
- 2-3x faster JSON parsing with
simd-json
andsonic-rs
- Vectorized operations for better CPU cache utilization
- SIMD-optimized message handling throughout the request lifecycle
๐ฆ Zero-Copy Architecture
- Memory-efficient processing with
Bytes
-based message handling - Minimal allocations through careful lifetime management
- SmallVec and CompactStr for optimized small data structures
- Lock-free data structures for high-concurrency scenarios
- Buffer pooling for reduced allocations
- Lazy JSON parsing for on-demand deserialization
- Memory-mapped file support for large data handling
๐งต Thread-Safe Session Management
- Concurrent session tracking with thread-safe state management
- LRU eviction policies with configurable memory limits
- Request correlation and distributed tracing support
๐ฏ Rich Error Handling
- Structured error types with full context using
thiserror
- Error propagation with automatic conversion and context preservation
- Debugging support with detailed error information
๐ Observability Integration
- Built-in metrics hooks for performance monitoring
- Tracing integration points for distributed observability
- Request correlation IDs for end-to-end tracking
๐ฏ Enhanced Context Types (v1.0.3)
- ElicitationContext - Server-initiated user input requests with JSON schema validation
- CompletionContext - Intelligent autocompletion with reference tracking
- PingContext - Bidirectional health monitoring and keepalive
- ResourceTemplateContext - Dynamic resource generation with RFC 6570 templates
- BidirectionalContext - Support for server-initiated requests to clients
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TurboMCP Core โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ SIMD Message Processing โ
โ โโโ simd-json acceleration โ
โ โโโ sonic-rs optimization โ
โ โโโ Zero-copy Bytes handling โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Session & Context Management โ
โ โโโ RequestContext lifecycle โ
โ โโโ Thread-safe session state โ
โ โโโ Correlation ID management โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Error Handling & Observability โ
โ โโโ Structured McpError types โ
โ โโโ Context preservation โ
โ โโโ Metrics & tracing hooks โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Performance Characteristics
Benchmarks vs Standard Libraries
Operation | Standard | TurboMCP Core | Improvement |
---|---|---|---|
JSON Parsing | 100ms | 35ms | 2.8x faster |
Message Processing | 50ms | 18ms | 2.7x faster |
Memory Usage | 100MB | 60MB | 40% reduction |
Concurrent Throughput | 1000 req/s | 2800 req/s | 2.8x higher |
Optimization Features
- ๐ SIMD Acceleration - CPU-level vectorized JSON processing
- ๐ฆ Zero-Copy - Minimal memory allocations and copies
- ๐ Efficient Collections - SmallVec, CompactStr for small data
- ๐งต Lock-Free Operations - Where possible for maximum concurrency
Usage
Basic Usage
use ;
// Create a request context for correlation and observability
let mut context = new;
// SIMD-accelerated message parsing happens automatically
let json_data = br#"{"jsonrpc": "2.0", "method": "tools/list"}"#;
let message = parse_with_simd?;
// Context provides rich observability and user information
context.info.await?;
// Enhanced Context features (v1.0.3)
if context.is_authenticated
Advanced Session Management
use ;
// Configure session management with LRU eviction
let config = new
.with_max_sessions
.with_ttl_seconds;
let session_manager = with_config;
// Sessions are automatically managed with efficient cleanup
let session = session_manager.create_session.await?;
Error Handling
use ;
SIMD Feature Flag
Enable maximum performance with SIMD acceleration:
[]
= { = "1.0.3", = ["simd"] }
Note: SIMD features require compatible CPU architectures (x86_64 with AVX2 or ARM with NEON).
Feature Flags
Feature | Description | Default |
---|---|---|
simd |
Enable SIMD-accelerated JSON processing | โ |
metrics |
Enable built-in performance metrics | โ |
tracing |
Enable distributed tracing support | โ |
compression |
Enable message compression utilities | โ |
Integration
With TurboMCP Framework
turbomcp-core
is automatically included when using the main TurboMCP framework:
use *;
// Core functionality is available through the prelude
Direct Usage
For custom implementations or integrations:
use ;
Error Types
Core error types for comprehensive error handling:
use McpError;
match result
Development
Building
# Build with all features
# Build optimized for production
Testing
# Run comprehensive tests
# Run performance benchmarks
# Test SIMD features (requires compatible CPU)
Related Crates
- turbomcp - Main framework (uses this crate)
- turbomcp-protocol - MCP protocol implementation
- turbomcp-transport - Transport layer
- turbomcp-server - Server framework
License
Licensed under the MIT License.
Part of the TurboMCP high-performance Rust SDK for the Model Context Protocol.