use actix_web::{App, HttpServer, middleware};
use rmcp::transport::streamable_http_server::session::local::LocalSessionManager;
use rmcp_actix_web::transport::StreamableHttpService;
use std::{sync::Arc, time::Duration};
use tracing_subscriber::{
layer::SubscriberExt,
util::SubscriberInitExt,
{self},
};
mod common;
use common::counter::Counter;
const BIND_ADDRESS: &str = "127.0.0.1:8080";
#[actix_web::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "debug".to_string().into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
println!("\n🚀 Streamable HTTP Server (actix-web) running at http://{BIND_ADDRESS}");
println!("📡 GET / - Resume SSE stream with session ID");
println!("📮 POST / - Send JSON-RPC requests");
println!("🗑️ DELETE / - Close session");
println!("\nPress Ctrl+C to stop the server\n");
let http_service = StreamableHttpService::builder()
.service_factory(Arc::new(|| Ok(Counter::new()))) .session_manager(Arc::new(LocalSessionManager::default())) .stateful_mode(true) .sse_keep_alive(Duration::from_secs(30)) .build();
HttpServer::new(move || {
App::new()
.wrap(middleware::Logger::default())
.wrap(middleware::NormalizePath::trim())
.service(http_service.clone().scope())
})
.bind(BIND_ADDRESS)?
.run()
.await?;
println!("✅ Server stopped");
Ok(())
}