diff --git a/src/api/mcp/mod.rs b/src/api/mcp/mod.rs index 0e4348e..d397e78 100644 --- a/src/api/mcp/mod.rs +++ b/src/api/mcp/mod.rs @@ -18,36 +18,6 @@ use tokio::sync::mpsc; use tools::{handle_tool_call, tool_definitions}; use uuid::Uuid; -#[get("/mcp")] -pub fn sse(state: &State, shutdown: Shutdown) -> EventStream![] { - let connections = state.mcp_connections.clone(); - let connection_id = Uuid::new_v4().to_string(); - let endpoint = format!("/mcp/{}", connection_id); - let (sender, mut receiver) = mpsc::unbounded_channel(); - connections.insert(connection_id.clone(), sender); - - EventStream! { - yield Event::data(endpoint).event("endpoint"); - - loop { - tokio::select! { - _ = shutdown.clone() => break, - message = receiver.recv() => { - match message { - Some(message) => yield Event::data(message).event("message"), - None => break, - } - } - _ = tokio::time::sleep(std::time::Duration::from_secs(15)) => { - yield Event::comment("keepalive"); - } - } - } - - connections.remove(&connection_id); - } -} - #[post("/mcp", data = "")] pub async fn route( body: Json, @@ -79,6 +49,36 @@ pub async fn route_sse( ) } +#[get("/mcp")] +pub fn sse(state: &State, shutdown: Shutdown) -> EventStream![] { + let connections = state.mcp_connections.clone(); + let connection_id = Uuid::new_v4().to_string(); + let endpoint = format!("/mcp/{}", connection_id); + let (sender, mut receiver) = mpsc::unbounded_channel(); + connections.insert(connection_id.clone(), sender); + + EventStream! { + yield Event::data(endpoint).event("endpoint"); + + loop { + tokio::select! { + _ = shutdown.clone() => break, + message = receiver.recv() => { + match message { + Some(message) => yield Event::data(message).event("message"), + None => break, + } + } + _ = tokio::time::sleep(std::time::Duration::from_secs(15)) => { + yield Event::comment("keepalive"); + } + } + } + + connections.remove(&connection_id); + } +} + async fn handle_request( body: Json, token: MaybeBearerToken,