Expand description
§rmcp-actix-web
actix-web transport implementations for RMCP (Rust Model Context Protocol).
This crate provides HTTP-based transport layers for the Model Context Protocol (MCP), offering a complete alternative to the default Axum-based transports in the main RMCP crate. If you’re already using actix-web in your application or prefer its API, this crate allows you to integrate MCP services seamlessly without introducing additional web frameworks.
§Features
- [SSE (Server-Sent Events) Transport][SseService] (DEPRECATED): Real-time, unidirectional communication from server to client
- [Streamable HTTP Transport][StreamableHttpService]: Bidirectional communication with session management
- Full MCP Compatibility: Implements the complete MCP specification
- Drop-in Replacement: Same service implementations work with either Axum or actix-web transports
- Production Ready: Built on battle-tested actix-web framework
§Quick Start
§Streamable HTTP Server Example
use rmcp_actix_web::transport::{StreamableHttpService, AuthorizationHeader};
use rmcp::transport::streamable_http_server::session::local::LocalSessionManager;
use rmcp::{ServerHandler, model::ServerInfo};
use actix_web::{App, HttpServer};
use std::{sync::Arc, time::Duration};
#[actix_web::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
HttpServer::new(|| {
let http_service = StreamableHttpService::builder()
.service_factory(Arc::new(|| Ok(MyMcpService::new())))
.session_manager(Arc::new(LocalSessionManager::default()))
.stateful_mode(true)
.sse_keep_alive(Duration::from_secs(30))
.build();
App::new()
.service(http_service.scope())
})
.bind("127.0.0.1:8080")?
.run()
.await?;
Ok(())
}
§Transport Selection
- Streamable HTTP: Full bidirectional communication with session management
- [SSE Transport][transport::sse_server] (DEPRECATED): Legacy unidirectional transport, please migrate to StreamableHttp
§Examples
See the examples/
directory for complete working examples:
counter_streamable_http.rs
- Streamable HTTP server examplecomposition_streamable_http_example.rs
- StreamableHttp with custom mountingauthorization_proxy_example.rs
- Authorization header forwarding example
§Framework-Level Composition
Both transports support framework-level composition aligned with RMCP patterns, allowing you to mount MCP services at custom paths within existing actix-web applications.
§Service Composition
use rmcp_actix_web::transport::{StreamableHttpService, AuthorizationHeader};
use rmcp::transport::streamable_http_server::session::local::LocalSessionManager;
use actix_web::{App, web};
use std::{sync::Arc, time::Duration};
HttpServer::new(|| {
let http_service = StreamableHttpService::builder()
.service_factory(Arc::new(|| Ok(MyService::new())))
.session_manager(Arc::new(LocalSessionManager::default()))
.stateful_mode(true)
.sse_keep_alive(Duration::from_secs(30))
.build();
// Mount at custom path using scope()
App::new()
.service(web::scope("/api/v1/calculator").service(http_service.scope()))
}).bind("127.0.0.1:8080")?.run().await
See the examples/
directory for complete working examples of composition patterns.
§Performance Considerations
- Streamable HTTP maintains persistent sessions which may use more memory
- Uses efficient async I/O through actix-web’s actor system
- Framework-level composition adds minimal overhead
§Feature Flags
This crate supports selective compilation of transport types:
transport-streamable-http-server
(default): Enables StreamableHttp transporttransport-sse-server
(DEPRECATED): Enables legacy SSE transport
To use only StreamableHttp transport, disable default features:
[dependencies]
rmcp-actix-web = { version = "0.6", default-features = false, features = ["transport-streamable-http-server"] }
Modules§
- transport
- Transport implementations for the Model Context Protocol using actix-web.