MCP Protocol SDK
A production-ready, feature-complete Rust implementation of the Model Context Protocol
π Quick Start: Getting Started | Implementation Guide | Examples
The MCP Protocol SDK enables seamless integration between AI models and external systems through a standardized protocol. Build powerful tools, resources, and capabilities that AI can discover and use dynamically.
π v0.5.0 Released - Production-ready SDK with comprehensive GitHub Actions CI/CD, enhanced documentation, and complete development infrastructure.
π Documentation | π API Reference | π Getting Started | π vs Official SDK
π― Quick Links: π Implementation Guide | π Platform Support | π§ Examples | π Transports
β¨ Features
- π¦ Pure Rust - Zero-cost abstractions, memory safety, and blazing performance
- π Multi-Platform - Native support for Linux, macOS, Windows + ARM64/Intel architectures
- π Multiple Transports - STDIO, HTTP, WebSocket support with optional features
- β‘ Advanced HTTP Transport - Connection pooling, retry logic, 45% faster performance
- π οΈ Complete MCP Support - Tools, resources, prompts, logging, and sampling
- π― Type-Safe - Comprehensive type system with compile-time guarantees
- π Async/Await - Built on Tokio for high-performance concurrent operations
- π¦ Unified Architecture - All functionality in one crate
- π Production Ready - 97 comprehensive tests, full validation, and error handling
- π Latest Schema - 100% compliant with MCP 2025-06-18 specification
- π Built-in Metrics - Performance monitoring and health checks
- π Excellent Docs - Complete guides for servers, clients, and integrations
π Quick Start
Add to Your Project
[]
= "0.5.0"
= { = "1.0", = ["full"] }
= "0.1"
= "1.0"
# Or with specific features only:
= { = "0.5.0", = ["stdio", "validation"] }
Build an MCP Server (Working Example)
use *;
use async_trait;
use HashMap;
use ;
// Step 1: Create a tool handler (required by actual API)
;
async
Build an MCP Client
use *;
use McpClient;
use TransportConfig;
async
Alternative: Using ToolBuilder (Advanced)
use ToolBuilder;
// Create tools with advanced features and validation
let tool = new
.description
.version
.schema
.strict_validation
.read_only
.idempotent
.cacheable
.build?;
β οΈ Important API Notes
Server Requirements
- Tool Handlers: Must implement the
ToolHandler
trait withasync fn call()
- String Parameters: Server and tool names require
String
, not&str
- JSON Schemas: Tools require explicit JSON schema definitions
- Async Traits: Use
#[async_trait]
for all handler implementations
Getting Started Tips
- Start with STDIO: Easiest transport for Claude Desktop integration
- Implement ToolHandler: Required for all tools - no closure shortcuts
- Handle Errors: Use
McpResult<T>
and proper error handling - Add Dependencies: Don't forget
async-trait
,tokio
, andserde_json
π― Use Cases
Scenario | Description | Guide |
---|---|---|
π₯οΈ Claude Desktop Integration | Add custom tools to Claude Desktop | π Guide |
β‘ Cursor IDE Enhancement | AI-powered development tools | π Guide |
π VS Code Extensions | Smart code assistance and automation | π Guide |
ποΈ Database Access | SQL queries and data analysis | π Example |
π API Integration | External service connectivity | π Example |
π File Operations | Filesystem tools and utilities | π Example |
π¬ Chat Applications | Real-time AI conversations | π Example |
ποΈ Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β AI Client β β MCP Protocol β β MCP Server β
β (Claude, etc.) βββββΊβ SDK βββββΊβ (Your Tools) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββΌββββββββββ
β β β
ββββββββΌβββ ββββββΌββββ βββββΌβββββ
β STDIO β β HTTP β βWebSocketβ
βTransportβ βTransportβ βTransportβ
βββββββββββ ββββββββββ ββββββββββ
π§ Feature Flags
Optimize your binary size by selecting only needed features:
Feature | Description | Default | Size Impact |
---|---|---|---|
stdio |
STDIO transport for Claude Desktop | β | Minimal |
http |
HTTP transport for web integration | β | +2MB |
websocket |
WebSocket transport for real-time | β | +1.5MB |
validation |
Enhanced input validation | β | +500KB |
tracing-subscriber |
Built-in logging setup | β | +300KB |
Minimal Example (STDIO only):
= { = "0.5.0", = false, = ["stdio"] }
π Performance
The advanced HTTP transport provides significant performance improvements:
| Transport | Requests/Second | Average Latency | Success Rate | Key Features | |-----------|-----------------|-----------------|--------------||--------------| | Advanced HTTP | 802 req/sec | 0.02ms | 100% | Connection pooling, retry logic | | Standard HTTP | 551 req/sec | 0.04ms | 100% | Basic HTTP client |
45% Performance Improvement with advanced features! π―
Quick Performance Test
# Run benchmark comparison
# Test conservative settings (recommended)
π Full Advanced Transport Guide
π Protocol Support
β Complete MCP 2024-11-05 Implementation
- Core Protocol - JSON-RPC 2.0 with full error handling
- Tools - Function calling with parameters and validation
- Resources - Static and dynamic content access
- Prompts - Reusable prompt templates with parameters
- Logging - Structured logging with multiple levels
- Sampling - LLM sampling integration and control
- Roots - Resource root discovery and management
- Progress - Long-running operation progress tracking
π‘οΈ MCP Protocol Schema Compliance
This SDK provides 100% verified compliance with the official MCP Protocol Schema (2025-06-18), ensuring seamless interoperability with all MCP-compatible systems.
β Comprehensive Validation
Our comprehensive test suite validates every aspect of the MCP protocol:
# Run the full schema compliance test suite
Results: 299 tests passing
with 100.0% compliance rate
π
π Schema Compliance Report
Component | Status | Features Validated |
---|---|---|
Core Types | β 100% | Implementation, Capabilities, Content |
JSON-RPC | β 100% | Requests, Responses, Errors, Notifications, Batching |
Tools | β 100% | Definitions, Parameters, Annotations, Execution |
Resources | β 100% | Static/Dynamic, Templates, Subscriptions |
Prompts | β 100% | Templates, Arguments, Message Generation |
Sampling | β 100% | Message Creation, Model Preferences |
Logging | β 100% | All levels, Structured messages |
Progress | β 100% | Notifications, Cancellation |
Roots | β 100% | Discovery, List management |
Completions | β 100% | Auto-complete for prompts/resources |
π 2025-06-18 Features
Full support for all latest MCP protocol enhancements:
- π΅ Audio Content - Native audio message support
- π Enhanced Tool Results - Structured content alongside text blocks
- π Enhanced Resources - Rich metadata with title and meta fields
- π οΈ Advanced Tool Management - Complete tool discovery and categorization
- π Enhanced Progress - Detailed progress tracking
- π JSON-RPC Batching - Efficient bulk operations
- π¦ Zero Breaking Changes - Full backward compatibility maintained
π§ͺ Validation Architecture
// Example: Schema validation in action
use *;
// All types are schema-compliant by construction
let tool_info = ToolInfo ;
// JSON serialization matches schema exactly
let json = to_value?;
π Manual Verification
You can verify schema compliance yourself:
# 1. Run comprehensive schema tests
# 2. Check specific protocol components
# 3. Validate against official schema (if available)
# The tests verify serialization matches expected JSON-RPC format
π Continuous Compliance
- Automated Testing - Every commit runs full schema validation
- Version Tracking - Tests updated with each protocol version
- Regression Prevention - Breaking changes detected immediately
- Documentation Sync - Schema changes reflected in docs
π€ Interoperability Guarantee
With 100% schema compliance, this SDK guarantees compatibility with:
- Claude Desktop - Official Anthropic client
- Third-party MCP Clients - Any standards-compliant implementation
- Custom Integrations - Your own MCP-based tools
- Future Protocol Versions - Forward compatibility design
π View Full Schema Compliance Details
π Multi-Platform Support
π» Supported Platforms
Platform | Architecture | Testing | Status |
---|---|---|---|
Linux | x86_64, ARM64, musl | β Automated | β Production Ready |
macOS | Intel, Apple Silicon | β Automated | β Production Ready |
Windows | x86_64, GNU | β Automated | β Production Ready |
π Cross-Compilation
# Add targets for cross-compilation
# Build for different platforms
π§ Platform-Specific Features
- Process Management: Native tokio::process on all platforms
- File System: Platform-aware path handling and permissions
- TLS/SSL: OpenSSL on Linux, native TLS on macOS/Windows
- Performance: Optimized builds for each architecture
π Integration Ecosystem
AI Clients
- Claude Desktop - Ready-to-use STDIO integration
- Cursor IDE - Smart development assistance
- VS Code - Extension development framework
- Custom AI Apps - HTTP/WebSocket APIs
Development Tools
- Jupyter Notebooks - Data science workflows
- Streamlit Apps - Interactive AI applications
- Browser Extensions - Web-based AI tools
- Mobile Apps - React Native integration
π Examples
Example | Description | Transport | Features |
---|---|---|---|
Conservative HTTP Demo | Production-ready HTTP client | Advanced HTTP | Connection pooling, metrics |
Transport Benchmark | Performance comparison | Multiple | 45% speed improvement |
Advanced HTTP Client | Full-featured HTTP demo | Advanced HTTP | Retry logic, health checks |
Echo Server | Simple tool demonstration | STDIO | Basic tools |
Database Server | SQL query execution | STDIO | Database access |
HTTP Server | RESTful API integration | HTTP | Web services |
WebSocket Server | Real-time communication | WebSocket | Live updates |
File Server | File system operations | STDIO | File handling |
Basic Client | Basic client usage | STDIO | Client patterns |
π οΈ Development
Prerequisites
- Rust 1.85+
- Cargo
Build & Test
# Build with all features
# Test with different feature combinations
# Run examples
Feature Development
# Test minimal build
# Test specific transports
π€ Contributing
We welcome contributions! Please see our Contributing Guide for details.
Areas for Contribution
- π Bug Reports - Help us improve reliability
- π‘ Feature Requests - Suggest new capabilities
- π Documentation - Improve guides and examples
- π§ Tool Integrations - Build example servers
- π§ͺ Testing - Expand test coverage
- π Performance - Optimize critical paths
π Roadmap
- Advanced Authentication - OAuth2, JWT, mTLS support
- Monitoring Integration - Prometheus metrics, health checks
- Plugin System - Dynamic tool loading and registration
- Schema Registry - Tool and resource schema management
- Load Balancing - Multiple server instance coordination
- Caching Layer - Response caching and invalidation
- Rate Limiting - Advanced traffic control
- Admin Dashboard - Web-based server management
π License
Licensed under the MIT License.
π Acknowledgments
- Anthropic - For creating the MCP specification
- Tokio Team - For the excellent async runtime
- Serde Team - For JSON serialization/deserialization
- Rust Community - For the amazing ecosystem
π Read the Full Documentation | π Get Started Now | π Implementation Guide
Built with β€οΈ in Rust