diff --git a/crates/rust-mcp-sdk/src/hyper_servers/hyper_runtime.rs b/crates/rust-mcp-sdk/src/hyper_servers/hyper_runtime.rs index 109dde5..85cf791 100644 --- a/crates/rust-mcp-sdk/src/hyper_servers/hyper_runtime.rs +++ b/crates/rust-mcp-sdk/src/hyper_servers/hyper_runtime.rs @@ -70,6 +70,12 @@ impl HyperRuntime { result.map_err(|err| err.into()) } + /// Returns a list of active session IDs from the session store. + pub async fn sessions(&self) -> Vec { + self.state.session_store.keys().await + } + + /// Retrieves the runtime associated with the given session ID from the session store. pub async fn runtime_by_session( &self, session_id: &SessionId, diff --git a/crates/rust-mcp-sdk/src/hyper_servers/routes/hyper_utils.rs b/crates/rust-mcp-sdk/src/hyper_servers/routes/hyper_utils.rs index 79bf226..0a77913 100644 --- a/crates/rust-mcp-sdk/src/hyper_servers/routes/hyper_utils.rs +++ b/crates/rust-mcp-sdk/src/hyper_servers/routes/hyper_utils.rs @@ -172,10 +172,7 @@ pub async fn start_new_session( session_id.to_owned(), )); - tracing::info!( - "a new client joined : {}", - runtime.session_id().await.unwrap_or_default().to_owned() - ); + tracing::info!("a new client joined : {}", &session_id); let response = create_sse_stream( runtime.clone(), diff --git a/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs b/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs index 49b5c3c..44f3e53 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs @@ -197,6 +197,11 @@ impl McpServer for ServerRuntime { } Ok(()) } + + #[cfg(feature = "hyper-server")] + fn session_id(&self) -> Option { + self.session_id.to_owned() + } } impl ServerRuntime { @@ -435,11 +440,6 @@ impl ServerRuntime { } } - #[cfg(feature = "hyper-server")] - pub(crate) async fn session_id(&self) -> Option { - self.session_id.to_owned() - } - #[cfg(feature = "hyper-server")] pub(crate) fn new_instance( server_details: Arc, diff --git a/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs b/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs index 0130c33..2eab9db 100644 --- a/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs +++ b/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs @@ -1,5 +1,3 @@ -use std::time::Duration; - use crate::schema::{ schema_utils::{ ClientMessage, McpMessage, MessageFromServer, NotificationFromServer, RequestFromServer, @@ -16,6 +14,8 @@ use crate::schema::{ SetLevelRequest, ToolListChangedNotification, ToolListChangedNotificationParams, }; use async_trait::async_trait; +use rust_mcp_transport::SessionId; +use std::time::Duration; use crate::{error::SdkResult, utils::format_assertion_message}; @@ -405,4 +405,7 @@ pub trait McpServer: Sync + Send { } Ok(()) } + + #[cfg(feature = "hyper-server")] + fn session_id(&self) -> Option; }