Crates.io | turbomcp-core |
lib.rs | turbomcp-core |
version | 1.1.0-exp.3 |
created_at | 2025-08-26 17:15:43.320228+00 |
updated_at | 2025-08-29 19:47:40.095897+00 |
description | Core abstractions and optimized message processing for the TurboMCP SDK |
homepage | |
repository | https://github.com/Epistates/turbomcp |
max_upload_size | |
id | 1811550 |
size | 426,136 |
High-performance core abstractions and SIMD-accelerated message processing for the TurboMCP SDK.
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.
simd-json
and sonic-rs
Bytes
-based message handlingthiserror
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
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 |
use turbomcp_core::{RequestContext, Message, Context, McpResult};
// Create a request context for correlation and observability
let mut context = RequestContext::new();
// SIMD-accelerated message parsing happens automatically
let json_data = br#"{"jsonrpc": "2.0", "method": "tools/list"}"#;
let message = Message::parse_with_simd(json_data)?;
// Context provides rich observability
context.info("Processing request").await?;
use turbomcp_core::{SessionManager, SessionConfig};
// Configure session management with LRU eviction
let config = SessionConfig::new()
.with_max_sessions(1000)
.with_ttl_seconds(3600);
let session_manager = SessionManager::with_config(config);
// Sessions are automatically managed with efficient cleanup
let session = session_manager.create_session().await?;
use turbomcp_core::{McpError, McpResult};
fn process_request() -> McpResult<String> {
// Rich error types with automatic context
if invalid_input {
return Err(McpError::InvalidInput(
"Request missing required field".to_string()
));
}
// Errors automatically include correlation context
Ok("processed".to_string())
}
Enable maximum performance with SIMD acceleration:
[dependencies]
turbomcp-core = { version = "1.0", features = ["simd"] }
Note: SIMD features require compatible CPU architectures (x86_64 with AVX2 or ARM with NEON).
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 | โ |
turbomcp-core
is automatically included when using the main TurboMCP framework:
use turbomcp::prelude::*;
// Core functionality is available through the prelude
#[server]
impl MyServer {
#[tool("Example with context")]
async fn my_tool(&self, ctx: Context) -> McpResult<String> {
// Context is powered by turbomcp-core
ctx.info("Processing request").await?;
Ok("result".to_string())
}
}
For custom implementations or integrations:
use turbomcp_core::{
RequestContext, SessionManager, Message, McpError, McpResult
};
struct CustomHandler {
sessions: SessionManager,
}
impl CustomHandler {
async fn handle_request(&self, data: &[u8]) -> McpResult<String> {
let context = RequestContext::new();
let message = Message::parse_with_simd(data)?;
// Use core functionality directly
context.info("Custom processing").await?;
Ok("processed".to_string())
}
}
Core error types for comprehensive error handling:
use turbomcp_core::McpError;
match result {
Err(McpError::InvalidInput(msg)) => {
// Handle validation errors
},
Err(McpError::SessionExpired(id)) => {
// Handle session lifecycle
},
Err(McpError::Performance(details)) => {
// Handle performance issues
},
Ok(value) => {
// Process success case
}
}
# Build with all features
cargo build --features simd,metrics,tracing
# Build optimized for production
cargo build --release --features simd
# Run comprehensive tests
cargo test
# Run performance benchmarks
cargo bench
# Test SIMD features (requires compatible CPU)
cargo test --features simd
Licensed under the MIT License.
Part of the TurboMCP high-performance Rust SDK for the Model Context Protocol.