tiny change

This commit is contained in:
2026-05-22 10:12:28 +02:00
parent 042fe0cae2
commit a9b71abca4
+30 -30
View File
@@ -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<AppState>, 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 = "<body>")]
pub async fn route(
body: Json<JsonRpcRequest>,
@@ -79,6 +49,36 @@ pub async fn route_sse(
)
}
#[get("/mcp")]
pub fn sse(state: &State<AppState>, 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<JsonRpcRequest>,
token: MaybeBearerToken,