TurboMCP Protocol
Complete Model Context Protocol (MCP) specification implementation with JSON-RPC 2.0 and runtime schema validation.
Overview
turbomcp-protocol
provides a complete, specification-compliant implementation of the Model Context Protocol (MCP) version 2025-06-18. This crate handles all protocol-level concerns including message formatting, capability negotiation, and runtime validation.
Key Features
📋 Complete MCP Specification Support
- MCP 2025-06-18 - Full implementation of the latest protocol specification
- All message types - Tools, resources, prompts, and capabilities
- Capability negotiation - Automatic feature detection and handshake
- Version compatibility - Forward and backward compatibility support
🔧 JSON-RPC 2.0 Implementation
- Compliant message format - Request, response, and notification handling
- ID correlation - Automatic request/response correlation
- Error handling - Standard JSON-RPC error codes and extensions
- Batch processing - Support for batch request/response operations
✅ Runtime Schema Validation
- JSON Schema validation - Runtime validation using
jsonschema
crate - Type safety - Rust type definitions for all MCP message types
- Parameter validation - Tool and resource parameter validation
- Schema generation - Automatic schema generation from Rust types
🤝 Capability Management
- Server capabilities - Tools, resources, prompts declarations
- Client capabilities - Sampling, roots, progress reporting
- Feature negotiation - Automatic capability matching
- Extension support - Custom capability extensions
🔄 MCP 2025-06-18 Enhanced Features
- Bidirectional communication - Server-initiated requests to clients
- Elicitation support - Server can request structured input from users
- Completion context - Enhanced completion with references and metadata
- Resource templates - Dynamic resource generation with parameters
- Ping/keepalive - Connection health monitoring
Architecture
┌─────────────────────────────────────────────┐
│ TurboMCP Protocol │
├─────────────────────────────────────────────┤
│ MCP Message Types │
│ ├── InitializeRequest/Response │
│ ├── 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 ;
MCP 2025-06-18 Enhanced Types (v1.0.3)
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-06-18",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0.0"}
}
}"#;
let request: JsonRpcRequest = from_str?;
// Handle specific message types
match request.method.as_str
Schema Validation
use ;
// Define tool parameters with schema validation
// Validate tool call parameters
let params = json!;
let result: ValidationResult = validate_tool_call?;
match result
Capability Negotiation
use ;
// Define server capabilities
let server_caps = ServerCapabilities ;
// Define client capabilities
let client_caps = ClientCapabilities ;
// Negotiate capabilities
let negotiated = negotiate_capabilities?;
Error Handling
use ;
// Create protocol-specific errors
// Convert to MCP error
let mcp_error = Protocol;
Custom Message Types
use ;
use ;
// Define custom message types
// Create custom JSON-RPC messages
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
Feature Flags
Feature | Description | Default |
---|---|---|
validation |
Enable runtime schema validation | ✅ |
extensions |
Enable MCP extension message types | ❌ |
batch |
Enable JSON-RPC batch processing | ✅ |
async-validation |
Enable async schema validation | ❌ |
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 (no validation)
Testing
# Run protocol compliance tests
# Test with all message types
# Validate against MCP specification
Schema Validation
# Generate JSON schemas from Rust types
# Validate example messages
Related Crates
- turbomcp - Main framework (uses this crate)
- turbomcp-core - Core types and utilities
- turbomcp-transport - Transport layer
- turbomcp-server - Server framework
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 high-performance Rust SDK for the Model Context Protocol.