Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ impl ServerRuntime {
let transport = self.transport_by_stream(stream_id).await?;

let (disconnect_tx, mut disconnect_rx) = oneshot::channel::<()>();
let _ = transport.keep_alive(ping_interval, disconnect_tx).await;
let abort_alive_task = transport
.keep_alive(ping_interval, disconnect_tx)
.await?
.abort_handle();

// in case there is a payload, we consume it by transport to get processed
if let Some(payload) = payload {
Expand Down Expand Up @@ -429,11 +432,13 @@ impl ServerRuntime {
}
// close the stream after all messages are sent, unless it is a standalone stream
if !stream_id.eq(DEFAULT_STREAM_ID){
abort_alive_task.abort();
return Ok(());
}
}
_ = &mut disconnect_rx => {
self.remove_transport(stream_id).await?;
abort_alive_task.abort();
// Disconnection detected by keep-alive task
return Err(SdkError::connection_closed().into());

Expand Down
Loading