use actix_web::web::PayloadConfig;
use actix_web::{web, Scope};
use rust_mcp_sdk::mcp_http::{McpAppState, McpHttpHandler, McpMountOptions};
use std::sync::Arc;
pub fn mcp_scope(
state: Arc<McpAppState>,
http_handler: Arc<McpHttpHandler>,
opts: &McpMountOptions,
) -> Scope {
let sse_message_endpoint = opts.sse_messages_endpoint.clone();
let scope = web::scope("")
.app_data(web::Data::new(state))
.app_data(web::Data::from(http_handler.clone()))
.app_data(web::Data::new(crate::routes::sse::SseMessageEndpoint(
sse_message_endpoint,
)))
.app_data(PayloadConfig::new(opts.max_request_body_size))
.service(
web::resource(&opts.streamable_http_endpoint)
.route(web::get().to(crate::routes::streamable_http::handle_streamable_http_get))
.route(web::post().to(crate::routes::streamable_http::handle_streamable_http_post))
.route(
web::delete().to(crate::routes::streamable_http::handle_streamable_http_delete),
),
)
.service(
web::resource(&opts.sse_endpoint).route(web::get().to(crate::routes::sse::handle_sse)),
)
.service(
web::resource(&opts.sse_messages_endpoint)
.route(web::post().to(crate::routes::messages::handle_messages)),
);
let scope = if let Some(auth_scope) = crate::routes::auth::auth_routes(http_handler) {
scope.service(auth_scope)
} else {
scope
};
let scope = if let Some(ref endpoint) = opts.health_endpoint {
scope.service(
web::resource(endpoint)
.route(web::get().to(crate::routes::health::handle_health_check)),
)
} else {
scope
};
scope.default_service(web::route().to(crate::routes::fallback::not_found))
}