rmcp-actix-web
actix-web transport implementations for RMCP (Rust Model Context Protocol)
This crate provides actix-web-based transport implementations for the Model Context Protocol, offering a complete alternative to the default Axum-based transports in the main RMCP crate.
Overview
rmcp-actix-web provides:
- Streamable HTTP transport: Bidirectional communication with session management
- Framework-level composition: Mount MCP services at custom paths using actix-web Scope
- Full MCP compatibility: Implements the complete MCP protocol specification
- RMCP ecosystem alignment: APIs that follow RMCP patterns for maximum consistency
⚠️ Security Notice
This transport forwards Authorization headers to MCP services. If your MCP service passes these tokens to upstream APIs (proxy pattern), be aware this violates MCP specifications. See SECURITY.md for details.
Contributing
We welcome contributions to rmcp-actix-web! Please follow these guidelines:
How to Contribute
- Fork the repository on GitLab
- Create a feature branch from
main:git checkout -b feature/my-new-feature - Make your changes and ensure they follow the project's coding standards
- Add tests for your changes if applicable and run examples to verify functionality
- Run the test suite to ensure nothing is broken:
cargo test - Commit your changes with clear, descriptive commit messages
- Push to your fork and create a merge request
Development Setup
# Clone your fork
# Build the project
# Run tests
# Run examples
Code Standards
- Follow Rust conventions and use
cargo fmtto format code - Run
cargo clippy --all-targetsto catch common mistakes - Add documentation for public APIs
- Include tests for new functionality
Reporting Issues
Found a bug or have a feature request? Please report it on our GitLab issue tracker.
Installation
Add this to your Cargo.toml:
[]
= "0.2"
= "0.3"
= "4"
Feature Flags
Control which transports are compiled:
# Default: StreamableHttp transport enabled
= "0.2"
# Only StreamableHttp transport (explicit)
= { = "0.2", = false, = ["transport-streamable-http-server"] }
Compatibility Matrix
| rmcp-actix-web | rmcp |
|---|---|
| 0.6.1 | 0.6.3 |
| 0.4.2 | 0.6.1 |
| 0.2.2 | 0.3.0 |
| 0.2.x | 0.2.x |
| 0.1.x | 0.2.x |
Quick Start
Framework-Level Composition
Mount MCP services at custom paths within existing actix-web applications:
use StreamableHttpService;
use LocalSessionManager;
use ;
use Arc;
async
Examples
See the examples/ directory for complete working examples:
Basic Examples
counter_streamable_http.rs- Streamable HTTP server example
Composition Examples
composition_streamable_http_example.rs- StreamableHttp with custom mounting
Proxy Examples
authorization_proxy_example.rs- MCP service acting as a proxy using Authorization headers
Running Examples
# Basic StreamableHttp server
# Framework composition with StreamableHttp
# Authorization proxy example
Each example includes detailed documentation and curl commands for testing.
Key Features
Framework-Level Composition
- StreamableHttp:
StreamableHttpService::builder().build()with.scope()for composition - Custom Paths: Mount services at any path using actix-web's Scope system
- Builder API: Consistent builder pattern for service configuration
Protocol Support
- Full MCP Compatibility: Implements complete MCP protocol specification
- Bidirectional Communication: Both request/response and streaming patterns
- Session Management: Stateful and stateless modes for StreamableHttp
- Keep-Alive: Configurable keep-alive intervals for connection health
Integration
- Drop-in Replacement: Same service implementations work with Axum or actix-web
- Middleware Support: Full integration with actix-web middleware stack
- Custom Paths: Mount services at any path using actix-web's Scope system
- Built on actix-web: Leverages the mature actix-web framework
Middleware Extension Propagation
Use the on_request hook to propagate typed data from actix-web middleware to MCP request handlers. This is useful for passing JWT claims, user context, or other authentication data:
use StreamableHttpService;
use HttpMessage;
use Arc;
let http_service = builder
.service_factory
.session_manager
.on_request_fn
.build;
The propagated extensions are accessible in your MCP service handlers via RequestContext::extensions.
Proxy Support
- Authorization Forwarding: Bearer tokens from Authorization headers can be forwarded to MCP services (requires
authorization-token-passthroughfeature) - MCP Proxy Pattern: Enable MCP services to act as proxies to backend APIs
- Selective Header Forwarding: Only forwards Authorization header when feature is enabled
- Type-Safe Access: Access forwarded headers via
RequestContextextensions - Security Notice: Token passthrough violates MCP specifications - see SECURITY.md for important details
License
MIT License - see LICENSE file for details.