Skip to content

Commit 370b184

Browse files
committed
fix: adviced comments
1 parent dc2e989 commit 370b184

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

crates/rmcp/src/transport/streamable_http_server/tower.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub struct StreamableHttpServerConfig {
3434
pub sse_keep_alive: Option<Duration>,
3535
/// If true, the server will create a session for each request and keep it alive.
3636
pub stateful_mode: bool,
37+
/// Cancellation token for the Streamable HTTP server.
38+
///
39+
/// When this token is cancelled, all active sessions are terminated and
40+
/// the server stops accepting new requests.
3741
pub cancellation_token: CancellationToken,
3842
}
3943

crates/rmcp/tests/test_with_js.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,20 @@ async fn test_with_js_streamable_http_client() -> anyhow::Result<()> {
9494
.wait()
9595
.await?;
9696

97+
let ct = CancellationToken::new();
9798
let service: StreamableHttpService<Calculator, LocalSessionManager> =
9899
StreamableHttpService::new(
99100
|| Ok(Calculator::new()),
100101
Default::default(),
101102
StreamableHttpServerConfig {
102103
stateful_mode: true,
103104
sse_keep_alive: None,
105+
cancellation_token: ct.child_token(),
104106
},
105107
);
106108
let router = axum::Router::new().nest_service("/mcp", service);
107109
let tcp_listener = tokio::net::TcpListener::bind(STREAMABLE_HTTP_BIND_ADDRESS).await?;
108-
let ct = CancellationToken::new();
110+
109111
let handle = tokio::spawn({
110112
let ct = ct.clone();
111113
async move {

examples/servers/src/counter_streamhttp.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use rmcp::transport::{
2-
StreamableHttpServerConfig,
3-
streamable_http_server::{StreamableHttpService, session::local::LocalSessionManager},
1+
use rmcp::transport::streamable_http_server::{
2+
StreamableHttpServerConfig, StreamableHttpService, session::local::LocalSessionManager,
43
};
54
use tracing_subscriber::{
65
layer::SubscriberExt,

0 commit comments

Comments
 (0)