MoCoPr (More Copper) ๐ฅ
A comprehensive and developer-friendly Rust implementation of the Model Context Protocol (MCP), making it extremely simple to build MCP servers and clients with production-ready features.
๐ Features
- ๐ง Complete MCP Implementation: Full support for MCP specification (2025-06-18)
- ๐ Developer-Friendly API: Intuitive builder patterns and macros for rapid development
- ๐ Multiple Transports: stdio, WebSocket, and HTTP transport support with automatic reconnection
- ๐ Type-Safe: Leverages Rust's type system for protocol safety and compile-time guarantees
- โก High Performance: Built on tokio for high-performance async I/O with benchmarked optimizations
- ๐ Extensible: Plugin architecture for custom resources, tools, and prompts
- ๐ Well-Documented: Comprehensive documentation, examples, and tutorials
- ๐ก๏ธ Production Ready: Comprehensive error handling, logging, metrics, and security features
- ๐งช Thoroughly Tested: Extensive test suite with 95%+ code coverage and stress testing
- ๐ Observable: Built-in tracing, metrics, and health checks
๐ฆ Crates
MoCoPr is organized into several specialized crates for maximum flexibility:
๐โโ๏ธ Quick Start
Add MoCoPr to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["full"] }
= "1.0"
Creating an MCP Server
use *;
async
Creating an MCP Client
use *;
async
๐ Documentation
๐ Guides and Tutorials
- Quick Start Guide - Get up and running in 5 minutes
- Building Your First MCP Server - Comprehensive tutorial
- Advanced Server Features - Middleware, validation, etc.
- Production Deployment - Production-ready deployment guide
- Performance Tuning - Performance optimization and tuning
- Architecture Guide - System architecture and design patterns
- Security Best Practices - Security guidelines and recommendations
- Performance Optimization - Benchmarking and optimization tips
๐ง API Documentation
- Core API Reference - Protocol types and utilities
- Server API Reference - Server builder and handlers
- Client API Reference - Client connection management
- Macros Reference - Derive macro documentation
๐ Examples
The examples/ directory contains comprehensive examples:
| Example | Description | Transport | Complexity |
|---|---|---|---|
| simple-server | Basic MCP server with tools and resources | stdio | Beginner |
| simple-client | Basic MCP client usage | stdio | Beginner |
| calculator-server | Full-featured calculator with validation | stdio | Intermediate |
| file-server | File system operations with security | stdio | Intermediate |
| websocket-chat | Real-time chat server | WebSocket | Advanced |
| http-api | REST-like HTTP interface | HTTP | Advanced |
| production-server | Production-ready server with all features | All | Expert |
Run any example:
# Run the calculator server
# Run the file server
# Run with custom transport
๐ Features in Detail
Transport Support
MoCoPr supports multiple transport mechanisms with automatic failover:
// stdio transport (process communication)
server.run_stdio.await?;
// WebSocket transport (real-time web apps)
server.run_websocket.await?;
// HTTP transport (stateless requests)
server.run_http.await?;
// Multiple transports simultaneously
server.run_all.await?;
Advanced Features
Middleware and Validation
let server = builder
.with_middleware
.with_middleware
.with_middleware
.with_validation
.build?;
Monitoring and Observability
use *;
let server = builder
.with_metrics
.with_tracing
.with_health_checks
.build?;
Error Handling and Recovery
let client = builder
.with_retry_policy
.with_timeout
.with_connection_recovery
.connect_stdio.await?;
let result = a + b;
Ok(ToolsCallResponse::success(vec![
Content::from(format!("{} + {} = {}", a, b, result))
]))
}
);
// Build and run the server
let server = McpServer::builder()
.with_info("Calculator Server", "1.0.0")
.with_tools()
.with_tool(calculator)
.build()?;
server.run_stdio().await?;
Ok(())
}
### Creating an MCP Client
```rust
use mocopr_client::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// Connect to a server
let client = McpClientBuilder::new()
.with_info("My Client".to_string(), "1.0.0".to_string())
.connect_stdio("my-mcp-server", &[])
.await?;
// List available tools
let tools = client.list_tools().await?;
println!("Available tools: {:?}", tools.tools);
// Call a tool
let result = client.call_tool(
"add".to_string(),
Some(json!({"a": 5, "b": 3}))
).await?;
println!("Result: {:?}", result);
client.close().await?;
Ok(())
}
๐ ๏ธ Advanced Usage
Using Macros for Clean Code
use *;
;
File Resources
let file_resource = file_resource!;
Template Prompts
let prompt = template_prompt!;
๐ Transport Support
Stdio (Process Communication)
// Server
server.run_stdio.await?;
// Client
let client = new
.with_info
.connect_stdio
.await?;
WebSocket
// Server
server.run_websocket.await?;
// Client
let client = new
.with_info
.connect_websocket
.await?;
๐ Examples
The repository includes several complete examples:
- Simple Server: Basic MCP server with resources, tools, and prompts
- Simple Client: Client that connects and interacts with servers
- File Server: Server that exposes file system resources
- Calculator Server: Advanced calculator with multiple operations
Run examples:
# Start the simple server
# In another terminal, run the client
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ MCP Client โ โ MCP Server โ
โ โ โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โ โ Session โ โโโโโโค โ Session โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โ โ โ โ โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โ โ Transport โ โโโโโโค โ Transport โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โโโ stdio/websocket โโโโโโ
Core Components
- Protocol Layer: JSON-RPC 2.0 message handling
- Transport Layer: Pluggable transport implementations
- Session Management: Connection lifecycle and state
- Handler Registry: Dynamic resource/tool/prompt registration
- Type System: Full MCP type definitions with serde support
๐งช Testing
# Run all tests
# Run tests for a specific crate
# Run with logging
RUST_LOG=debug
๐ Requirements
- Rust: 1.70 or later
- Dependencies: See
Cargo.tomlfor full list
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
๐ Related
MoCoPr - Making MCP integration in Rust as easy as adding copper to your project! โก