sse endpoint
This commit is contained in:
+25
-1
@@ -6,10 +6,34 @@ use protocol::{
|
||||
ApiResponse, InitializeResult, JSONRPC_VERSION, JsonRpcRequest, jsonrpc_error,
|
||||
jsonrpc_notification_ok, jsonrpc_ok,
|
||||
};
|
||||
use rocket::{State, http::Status, post, serde::json::Json};
|
||||
use rocket::{
|
||||
Shutdown, State, get,
|
||||
http::Status,
|
||||
post,
|
||||
response::stream::{Event, EventStream},
|
||||
serde::json::Json,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use tools::{handle_tool_call, tool_definitions};
|
||||
|
||||
const MCP_MESSAGE_ENDPOINT_EVENT: &str = "endpoint";
|
||||
|
||||
#[get("/mcp")]
|
||||
pub fn sse(shutdown: Shutdown) -> EventStream![] {
|
||||
EventStream! {
|
||||
yield Event::json(&serde_json::json!({ "path": "/mcp" })).event(MCP_MESSAGE_ENDPOINT_EVENT);
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = shutdown.clone() => break,
|
||||
_ = tokio::time::sleep(std::time::Duration::from_secs(15)) => {
|
||||
yield Event::comment("keepalive");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/mcp", data = "<body>")]
|
||||
pub async fn route(
|
||||
body: Json<JsonRpcRequest>,
|
||||
|
||||
Reference in New Issue
Block a user