Update src/mcp.rs
Browse files- src/mcp.rs +31 -7
src/mcp.rs
CHANGED
|
@@ -65,7 +65,9 @@ impl McpServer {
|
|
| 65 |
let init_result = json!({
|
| 66 |
"protocolVersion": "2024-11-05",
|
| 67 |
"capabilities": {
|
| 68 |
-
"tools": {
|
|
|
|
|
|
|
| 69 |
},
|
| 70 |
"serverInfo": {
|
| 71 |
"name": "rust-mcp-search",
|
|
@@ -348,17 +350,39 @@ async fn handle_sse(
|
|
| 348 |
) -> (HeaderMap, Sse<impl Stream<Item = Result<Event, Infallible>>>) {
|
| 349 |
let mut headers = HeaderMap::new();
|
| 350 |
headers.insert("x-accel-buffering", HeaderValue::from_static("no"));
|
| 351 |
-
headers.insert(header::CACHE_CONTROL, HeaderValue::from_static("no-cache"));
|
| 352 |
headers.insert(header::CONNECTION, HeaderValue::from_static("keep-alive"));
|
|
|
|
| 353 |
|
| 354 |
-
|
|
|
|
| 355 |
Ok(Event::default().event("endpoint").data("/rpc")),
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
let stream = initial.chain(interval);
|
| 362 |
|
| 363 |
-
(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
}
|
|
|
|
| 65 |
let init_result = json!({
|
| 66 |
"protocolVersion": "2024-11-05",
|
| 67 |
"capabilities": {
|
| 68 |
+
"tools": {
|
| 69 |
+
"listChanged": true
|
| 70 |
+
}
|
| 71 |
},
|
| 72 |
"serverInfo": {
|
| 73 |
"name": "rust-mcp-search",
|
|
|
|
| 350 |
) -> (HeaderMap, Sse<impl Stream<Item = Result<Event, Infallible>>>) {
|
| 351 |
let mut headers = HeaderMap::new();
|
| 352 |
headers.insert("x-accel-buffering", HeaderValue::from_static("no"));
|
| 353 |
+
headers.insert(header::CACHE_CONTROL, HeaderValue::from_static("no-cache, no-transform"));
|
| 354 |
headers.insert(header::CONNECTION, HeaderValue::from_static("keep-alive"));
|
| 355 |
+
headers.insert(header::CONTENT_TYPE, HeaderValue::from_static("text/event-stream"));
|
| 356 |
|
| 357 |
+
// Emit initial endpoint AND tool availability notification immediately
|
| 358 |
+
let initial_events = vec![
|
| 359 |
Ok(Event::default().event("endpoint").data("/rpc")),
|
| 360 |
+
Ok(Event::default().event("message").data(
|
| 361 |
+
json!({
|
| 362 |
+
"jsonrpc": "2.0",
|
| 363 |
+
"method": "notifications/tools/list_changed",
|
| 364 |
+
"params": {}
|
| 365 |
+
})
|
| 366 |
+
.to_string(),
|
| 367 |
+
)),
|
| 368 |
+
];
|
| 369 |
+
|
| 370 |
+
let initial = tokio_stream::iter(initial_events);
|
| 371 |
|
| 372 |
+
// 5-second heartbeats keep connection alive on Hugging Face Spaces proxy
|
| 373 |
+
let interval = tokio_stream::wrappers::IntervalStream::new(tokio::time::interval(
|
| 374 |
+
Duration::from_secs(5),
|
| 375 |
+
))
|
| 376 |
+
.map(|_| Ok(Event::default().comment("keep-alive")));
|
| 377 |
|
| 378 |
let stream = initial.chain(interval);
|
| 379 |
|
| 380 |
+
(
|
| 381 |
+
headers,
|
| 382 |
+
Sse::new(stream).keep_alive(
|
| 383 |
+
KeepAlive::new()
|
| 384 |
+
.interval(Duration::from_secs(5))
|
| 385 |
+
.text("keep-alive"),
|
| 386 |
+
),
|
| 387 |
+
)
|
| 388 |
}
|