High-performance, async-first Rust implementation of the Model Context Protocol (MCP)
A Rust native port of the Ox Fast MCP library (originally based on FastMCP Python), providing a high-level, efficient interface for building MCP servers and clients using modern Rust practices.
- 🚀 High Performance: Built on
tokioandactix-webfor non-blocking I/O. - �️ Memory Safe: Leverages Rust's ownership model for crash-free execution.
- 🔌 Flexible Transports: Full support for Stdio (Pipe) and SSE (HTTP) transports.
- 🔒 Secure: Built-in authentication (OAuth, OIDC, JWT) and rate limiting.
- � Zero-Cost Abstractions: Type-safe interfaces with minimal runtime overhead.
- � Comprehensive Examples: Ready-to-run examples for tools, resources, and auth.
rs-fast-mcp/
├── src/
│ ├── utilities/ # Common helpers (LruCache, JSON Schema)
│ ├── tools/ # Tool management (Execution, Validation)
│ ├── prompts/ # Prompt templates and execution
│ ├── resources/ # Resource management (URI templates, Reading)
│ ├── client/ # MCP Client SDK (Transport, Session)
│ ├── server/ # MCP Server implementation
│ │ ├── core.rs # Core server logic & Builder
│ │ ├── middleware/ # Auth, Rate Limiting, Caching
│ │ ├── transport/ # Stdio and HTTP/SSE transports
│ │ └── auth/ # Authentication providers (OIDC, OAuth, etc.)
│ ├── mcp/ # Protocol types and message definitions
│ ├── cli/ # Command-line interface definitions
│ └── lib.rs # Library entry point
├── examples/ # Usage examples (demos, integrations)
├── tests/ # Integration tests
├── specs/ # Specifications (Gemini)
├── Cargo.toml # Project configuration
└── README.md # This file
All modules are fully tested and passing:
✅ MCP Core & Utilities: 13 tests passing
- Protocol parsing, Configuration loading
- JSON Schema validation, Settings management
✅ Server Module: 25 tests passing
- Core server lifecycle, Stdio/SSE transports
- Authentication (Google, GitHub, OIDC, etc.)
- Middleware (Rate limiting, Caching, Logging)
- Request handling and mounting
✅ Client Module: 7 tests passing
- Client-server integration, Error handling
- Transport instantiation, Authentication injection
- Proxy support
✅ Tools Module: 7 tests passing
- Registration, Execution, Validation
- Duplicate handling, Fuzzy matching
✅ Resources Module: 5 tests passing
- Management, Reading, Templates
- Subscriptions, Stats
✅ Prompts Module: 2 tests passing
- Management and Execution
Provides strong, serde-compatible definitions for all MCP protocol messages, structures, and capabilities.
The heart of rs-fast-mcp. Manages the server lifecycle, handles incoming requests via Stdio or Http transports, and orchestrates Tools, Resources, and Prompts. Includes middleware support for:
- Authentication: Generic
AuthProvidertrait with implementations for Google, Azure, OCI, Supabase, WorkOS, Scalekit. - Rate Limiting: Token bucket algorithm.
- Caching: Automated result caching.
A robust async client for connecting to MCP servers. Supports:
- Discovery: List tools, prompts, resources.
- Execution: Call tools, get prompts, read resources.
- Transports: Seamless switching between Stdio and SSE.
Dedicated managers for registration, lookup, and execution of MCP primitives with built-in validation (JSON Schema).
Add this to your Cargo.toml:
[dependencies]
rs-fast-mcp = { git = "https://github.com/neuron-ng/rs-fast-mcp.git" }cargo build --releasecargo testrs-fast-mcp includes a CLI for serving and inspecting.
# Start a server (echo example)
cargo run -- serve --transport stdio
# Connect as a client
cargo run -- client --server-url http://localhost:8000/sse
# Inspect a server
cargo run -- inspectWe provide a comprehensive suite of examples to get you started:
| Example | Description | Command |
|---|---|---|
simple_server |
Basic Echo server | cargo run --example simple_server |
demo |
Comprehensive Stdio demo | cargo run --example demo |
filesystem |
File operations tool | cargo run --example filesystem |
calculator_server |
Math tools | cargo run --example calculator_server |
http_demo |
HTTP/SSE Transport | cargo run --example http_demo |
auth_demo |
Auth Middleware Integration | cargo run --example auth_demo |
smart_home |
WebSocket / Stateful Mock | cargo run --example smart_home |
complex_inputs |
Nested Schema Validation | cargo run --example complex_inputs |
atproto_server |
AT Protocol Client | cargo run --example atproto_server |
google_oauth_demo |
Google OAuth | cargo run --example google_oauth_demo |
github_oauth_demo |
GitHub OAuth | cargo run --example github_oauth_demo |
authkit_dcr |
Custom Routes & DCR | cargo run --example authkit_dcr |
For detailed specifications, see specs/gemini/.
- tokio: Async runtime
- actix-web: HTTP server framework
- serde: Serialization/Deserialization
- reqwest: HTTP client
- async-trait: Async trait support
- clap: CLI argument parsing
| Feature | Ox Fast MCP (OCaml) | Rs Fast MCP (Rust) | FastMCP (Python) |
|---|---|---|---|
| Type Safety | ✅ Strong Static | ✅ Strong Static | ❌ Runtime |
| Async Model | ✅ Lwt | ✅ Tokio | ✅ asyncio |
| Performance | ✅ Native | 🚀 Native (Highest) | ❌ Interpreted |
| Ecosystem | 🐫 OCaml | 🦀 Crates.io | 🐍 PyPI |
| Error Handling | ✅ Result Types | ✅ Result Types | ❌ Exceptions |
- Zero-Cost Async:
tokioprovides industry-standard, high-performance async execution. - Ecosystem: direct access to the vast crates.io ecosystem (e.g.,
reqwestfor OAuth,sqlxfor DBs). - Tooling: Cargo provides best-in-class build, test, and dependency management.
- Interop: Easy to embed in other applications or compile to WASM (future potential).
We welcome contributions!
- Fork the repository.
- Create a feature branch.
- Implement your changes with tests.
- Submit a Pull Request.
Please refer to the specs/ directory for architectural guidance.
- v0.1.0 (Current):
- Full OCaml port completed.
- Stdio and HTTP transports.
- All Auth providers implemented.
- Comprehensive example suite.
MIT License - see LICENSE file for details.
Ported with ❤️ from OCaml to Rust