mcp-protocol-sdk 0.2.0

Rust SDK for the Model Context Protocol (MCP)
Documentation
mcp-protocol-sdk-0.2.0 has been yanked.

MCP Protocol SDK

Crates.io Documentation License: MIT CI Security Audit codecov

A production-ready, feature-complete Rust implementation of the Model Context Protocol

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.


πŸ“š Complete Documentation & Guides | πŸ“– API Reference | πŸš€ Getting Started


✨ Features

  • πŸ¦€ Pure Rust - Zero-cost abstractions, memory safety, and blazing performance
  • πŸ”Œ Multiple Transports - STDIO, HTTP, WebSocket support with optional features
  • πŸ› οΈ 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
  • πŸ“¦ Modular Design - Optional features for minimal binary size
  • πŸ”’ Production Ready - Comprehensive error handling, validation, and testing
  • πŸ“– Excellent Docs - Complete guides for servers, clients, and integrations

πŸš€ Quick Start

Add to Your Project

[dependencies]
mcp-protocol-sdk = "0.1.0"

# Or with specific features only:
mcp-protocol-sdk = { version = "0.1.0", features = ["stdio", "validation"] }

Build an MCP Server (5 minutes)

use mcp_protocol_sdk::prelude::*;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create server
    let mut server = McpServer::new("my-calculator", "1.0.0");
    
    // Add a tool
    let calc_tool = Tool::new("add", "Add two numbers")
        .with_parameter("a", "First number", true)
        .with_parameter("b", "Second number", true);
    
    server.add_tool(calc_tool);
    
    // Handle tool calls
    server.set_tool_handler("add", |params| async move {
        let a = params["a"].as_f64().unwrap_or(0.0);
        let b = params["b"].as_f64().unwrap_or(0.0);
        Ok(json!({ "result": a + b }))
    });
    
    // Start server (compatible with Claude Desktop)
    let transport = StdioServerTransport::new();
    server.run(transport).await?;
    
    Ok(())
}

Build an MCP Client

use mcp_protocol_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to server
    let client = McpClient::new()
        .with_name("my-client")
        .build();
    
    let transport = StdioClientTransport::new();
    client.connect(transport).await?;
    client.initialize().await?;
    
    // Use server capabilities
    let tools = client.list_tools().await?;
    let result = client.call_tool("add", json!({"a": 5, "b": 3})).await?;
    
    println!("Result: {}", result);
    Ok(())
}

🎯 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):

mcp-protocol-sdk = { version = "0.1.0", default-features = false, features = ["stdio"] }

πŸ“‹ 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

🌍 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
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
Client Example Basic client usage STDIO Client patterns

πŸ› οΈ Development

Prerequisites

  • Rust 1.75+
  • Cargo

Build & Test

# Build with all features
cargo build --all-features

# Test with different feature combinations  
cargo test --no-default-features --features stdio
cargo test --all-features

# Run examples
cargo run --example echo_server --features stdio,tracing-subscriber

Feature Development

# Test minimal build
cargo check --no-default-features --lib

# Test specific transports
cargo check --no-default-features --features http
cargo check --no-default-features --features websocket

🀝 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

Built with ❀️ in Rust