| Crates.io | ultrafast-mcp |
| lib.rs | ultrafast-mcp |
| version | 202506018.1.0 |
| created_at | 2025-07-08 09:11:03.127246+00 |
| updated_at | 2025-07-13 16:24:25.657969+00 |
| description | High-performance, ergonomic Model Context Protocol (MCP) implementation in Rust |
| homepage | https://ultrafast-mcp.com |
| repository | https://github.com/techgopal/ultrafast-mcp |
| max_upload_size | |
| id | 1742297 |
| size | 144,448 |
High-performance, ergonomic Model Context Protocol (MCP) implementation in Rust
UltraFast MCP is a high-performance, developer-friendly MCP framework in the Rust ecosystem. Built with performance, safety, and ergonomics in mind, it enables robust MCP servers and clients with minimal boilerplate while maintaining full MCP 2025-06-18 specification compliance.
UltraFast MCP is designed to be the definitive Rust implementation of the Model Context Protocol, providing:
UltraFast MCP follows a modular architecture with clear separation of concerns:
┌─────────────────────────────────────────────────────────────┐
│ UltraFast MCP │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ CLI │ │ Monitoring │ │ Auth │ │
│ │ Tools │ │ & Metrics │ │ OAuth │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Server │ │ Client │ │ Transport │ │
│ │ Handler │ │ Connection │ │ Layer │ │
│ │ System │ │ Management │ │ HTTP/STDIO │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Core Protocol │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Types │ │ Protocol │ │ Utilities │ │
│ │ & Traits │ │ Messages │ │ & Helpers │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
UltraFast MCP is organized into specialized crates, each focusing on specific functionality:
ultrafast-mcp-core - Foundation LayerPurpose: Core protocol implementation and foundational types
Key Components:
Features:
ultrafast-mcp-server - Server ImplementationPurpose: High-performance server with ergonomic handler system
Key Components:
Features:
ultrafast-mcp-client - Client ImplementationPurpose: Async client with connection management and retry logic
Key Components:
Features:
ultrafast-mcp-transport - Transport LayerPurpose: Flexible transport layer with multiple protocols
Key Components:
Features:
ultrafast-mcp-auth - Authentication SystemPurpose: Comprehensive authentication and authorization support
Key Components:
Features:
ultrafast-mcp-monitoring - Monitoring SystemPurpose: Comprehensive monitoring and observability
Key Components:
Features:
ultrafast-mcp-cli - Command Line InterfacePurpose: Development tools and project management
Key Components:
Features:
ultrafast-mcp-test-utils - Testing UtilitiesPurpose: Common test fixtures and utilities
Key Components:
Features:
ultrafast-mcp - Primary APIPurpose: Convenient re-exports and feature management
Key Components:
Features:
tokio integration# Create a new MCP server project
cargo new my-mcp-server
cd my-mcp-server
# Add UltraFast MCP with HTTP transport and OAuth
cargo add ultrafast-mcp --features="http,oauth"
[dependencies]
ultrafast-mcp = { version = "202506018.1.0", features = [
"http", # HTTP/HTTPS transport
"oauth", # OAuth 2.1 authentication
"monitoring-full", # Complete monitoring suite
"full" # All features enabled
] }
Note: No features are enabled by default for minimal footprint.
core - Basic MCP functionality (types, traits, utilities)stdio - STDIO transport support (includes core functionality)http - HTTP/HTTPS transport support (includes stdio fallback + core functionality)oauth - OAuth 2.1 authentication with PKCE (includes core functionality)monitoring - Basic monitoring capabilities (includes core functionality)monitoring-http - HTTP metrics endpointsmonitoring-jaeger - Jaeger tracing supportmonitoring-otlp - OTLP tracing supportmonitoring-console - Console tracing outputhttp-with-auth - HTTP transport + OAuth authentication (includes stdio fallback + core)monitoring-full - All monitoring featuresminimal - Core + STDIO (minimal working setup)full - Everything enabled# Minimal setup (STDIO only)
cargo add ultrafast-mcp --features="minimal"
# HTTP server with OAuth
cargo add ultrafast-mcp --features="http-with-auth"
# Production setup with monitoring
cargo add ultrafast-mcp --features="http-with-auth,monitoring-full"
# All features enabled
cargo add ultrafast-mcp --features="full"
use ultrafast_mcp::prelude::*;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Deserialize)]
struct GreetRequest {
name: String,
greeting: Option<String>,
}
#[derive(Serialize)]
struct GreetResponse {
message: String,
timestamp: String,
}
// Implement the tool handler
struct GreetToolHandler;
#[async_trait::async_trait]
impl ToolHandler for GreetToolHandler {
async fn handle_tool_call(&self, call: ToolCall) -> MCPResult<ToolResult> {
match call.name.as_str() {
"greet" => {
// Parse the arguments
let args: GreetRequest = serde_json::from_value(
call.arguments.unwrap_or_default()
)?;
// Generate the response
let greeting = args.greeting.unwrap_or_else(|| "Hello".to_string());
let message = format!("{}, {}!", greeting, args.name);
Ok(ToolResult {
content: vec![ToolContent::text(message)],
is_error: Some(false),
})
}
_ => Err(MCPError::method_not_found(
format!("Unknown tool: {}", call.name)
)),
}
}
async fn list_tools(&self, _request: ListToolsRequest) -> MCPResult<ListToolsResponse> {
Ok(ListToolsResponse {
tools: vec![Tool {
name: "greet".to_string(),
description: "Greet a person by name".to_string(),
input_schema: serde_json::json!({
"type": "object",
"properties": {
"name": {"type": "string"},
"greeting": {"type": "string", "default": "Hello"}
},
"required": ["name"]
}),
output_schema: None,
}],
next_cursor: None,
})
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create server configuration
let server_info = ServerInfo {
name: "greeting-server".to_string(),
version: "1.0.0".to_string(),
description: Some("A simple greeting server".to_string()),
authors: None,
homepage: None,
license: None,
repository: None,
};
let capabilities = ServerCapabilities {
tools: Some(ToolsCapability { list_changed: Some(true) }),
..Default::default()
};
// Create and configure the server
let server = UltraFastServer::new(server_info, capabilities)
.with_tool_handler(Arc::new(GreetToolHandler));
// Start the server with STDIO transport
server.run_stdio().await?;
Ok(())
}
use ultrafast_mcp::prelude::*;
use serde_json::json;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create client configuration
let client_info = ClientInfo {
name: "greeting-client".to_string(),
version: "1.0.0".to_string(),
authors: None,
description: Some("A simple greeting client".to_string()),
homepage: None,
repository: None,
license: None,
};
let capabilities = ClientCapabilities::default();
// Create the client
let client = UltraFastClient::new(client_info, capabilities);
// Connect to the server using STDIO
client.connect_stdio().await?;
// Call a tool
let tool_call = ToolCall {
name: "greet".to_string(),
arguments: Some(json!({
"name": "Alice",
"greeting": "Hello there"
})),
};
let result = client.call_tool(tool_call).await?;
println!("Server response: {:?}", result);
// Disconnect
client.disconnect().await?;
Ok(())
}
UltraFast MCP includes comprehensive examples demonstrating various use cases:
Difficulty: Beginner
Focus: Basic server and client setup with high-performance HTTP transport
Key Features:
Difficulty: Intermediate
Focus: File system operations and complex tool handling
Key Features:
Difficulty: Advanced
Focus: Complete MCP feature set with all capabilities
Key Features:
Difficulty: Intermediate
Focus: Comprehensive authentication support
Key Features:
// Main server implementation
pub struct UltraFastServer { ... }
// Server information
pub struct ServerInfo {
pub name: String,
pub version: String,
pub description: Option<String>,
// ... other fields
}
// Server capabilities
pub struct ServerCapabilities {
pub tools: Option<ToolsCapability>,
pub resources: Option<ResourcesCapability>,
pub prompts: Option<PromptsCapability>,
// ... other capabilities
}
// Tool execution handler
#[async_trait]
pub trait ToolHandler: Send + Sync {
async fn handle_tool_call(&self, call: ToolCall) -> MCPResult<ToolResult>;
async fn list_tools(&self, request: ListToolsRequest) -> MCPResult<ListToolsResponse>;
}
// Resource management handler
#[async_trait]
pub trait ResourceHandler: Send + Sync {
async fn read_resource(&self, request: ReadResourceRequest) -> MCPResult<ReadResourceResponse>;
async fn list_resources(&self, request: ListResourcesRequest) -> MCPResult<ListResourcesResponse>;
}
// Prompt generation handler
#[async_trait]
pub trait PromptHandler: Send + Sync {
async fn get_prompt(&self, request: GetPromptRequest) -> MCPResult<GetPromptResponse>;
async fn list_prompts(&self, request: ListPromptsRequest) -> MCPResult<ListPromptsResponse>;
}
// Main client implementation
pub struct UltraFastClient { ... }
// Client information
pub struct ClientInfo {
pub name: String,
pub version: String,
pub description: Option<String>,
// ... other fields
}
// Client capabilities
pub struct ClientCapabilities {
// ... capability fields
}
impl UltraFastClient {
// Connection methods
pub async fn connect_stdio(&self) -> MCPResult<()>;
pub async fn connect_streamable_http(&self, url: &str) -> MCPResult<()>;
// Tool operations
pub async fn call_tool(&self, tool_call: ToolCall) -> MCPResult<ToolResult>;
pub async fn list_tools(&self, request: ListToolsRequest) -> MCPResult<ListToolsResponse>;
// Resource operations
pub async fn read_resource(&self, request: ReadResourceRequest) -> MCPResult<ReadResourceResponse>;
pub async fn list_resources(&self, request: ListResourcesRequest) -> MCPResult<ListResourcesResponse>;
// Lifecycle methods
pub async fn initialize(&self) -> MCPResult<()>;
pub async fn shutdown(&self, reason: Option<String>) -> MCPResult<()>;
pub async fn disconnect(&self) -> MCPResult<()>;
}
// Abstract transport trait
#[async_trait]
pub trait Transport: Send + Sync {
async fn send_message(&mut self, message: JsonRpcMessage) -> Result<()>;
async fn receive_message(&mut self) -> Result<JsonRpcMessage>;
async fn close(&mut self) -> Result<()>;
fn get_state(&self) -> ConnectionState;
}
// Connection state
pub enum ConnectionState {
Disconnected,
Connecting,
Connected,
Reconnecting,
ShuttingDown,
Failed(String),
}
// OAuth configuration
pub struct OAuthConfig {
pub client_id: String,
pub client_secret: String,
pub auth_url: String,
pub token_url: String,
pub redirect_uri: String,
pub scopes: Vec<String>,
}
// OAuth client
pub struct OAuthClient {
// ... implementation
}
// Token response
pub struct TokenResponse {
pub access_token: String,
pub refresh_token: Option<String>,
pub expires_in: Option<u64>,
pub token_type: String,
}
// Monitoring system
pub struct MonitoringSystem {
pub metrics_collector: Arc<MetricsCollector>,
pub health_checker: Arc<HealthChecker>,
pub config: MonitoringConfig,
}
// Health checker
pub struct HealthChecker {
// ... implementation
}
// Metrics collector
pub struct MetricsCollector {
// ... implementation
}
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/techgopal/ultrafast-mcp.git
cd ultrafast-mcp
# Install dependencies
cargo build
# Run tests
cargo test
# Run examples
cargo run --example basic-echo
cargo fmt)cargo clippy)cargo test)This project is licensed under either of
at your option.
UltraFast MCP - Building the future of AI communication, one protocol at a time! 🚀