pub struct SessionManager { /* private fields */ }Expand description
Global session manager for MCP servers
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(default_capabilities: ServerCapabilities) -> Self
pub fn new(default_capabilities: ServerCapabilities) -> Self
Create a new session manager with InMemory storage
Sourcepub fn with_timeouts(
default_capabilities: ServerCapabilities,
session_timeout: Duration,
cleanup_interval: Duration,
) -> Self
pub fn with_timeouts( default_capabilities: ServerCapabilities, session_timeout: Duration, cleanup_interval: Duration, ) -> Self
Create a new session manager with custom timeouts and InMemory storage
Sourcepub fn with_storage(
storage: Arc<BoxedSessionStorage>,
default_capabilities: ServerCapabilities,
) -> Self
pub fn with_storage( storage: Arc<BoxedSessionStorage>, default_capabilities: ServerCapabilities, ) -> Self
Create a new session manager with specific storage backend
Sourcepub fn with_storage_and_timeouts(
storage: Arc<BoxedSessionStorage>,
default_capabilities: ServerCapabilities,
session_timeout: Duration,
cleanup_interval: Duration,
) -> Self
pub fn with_storage_and_timeouts( storage: Arc<BoxedSessionStorage>, default_capabilities: ServerCapabilities, session_timeout: Duration, cleanup_interval: Duration, ) -> Self
Create a new session manager with custom storage and timeouts
Sourcepub async fn create_session(&self) -> String
pub async fn create_session(&self) -> String
Create a new session and return its ID
Sourcepub async fn create_session_with_id(&self, session_id: String) -> String
pub async fn create_session_with_id(&self, session_id: String) -> String
Create a new session with a specific ID (for testing only - see trait documentation)
Sourcepub async fn add_session_to_cache(
&self,
session_id: String,
server_capabilities: ServerCapabilities,
)
pub async fn add_session_to_cache( &self, session_id: String, server_capabilities: ServerCapabilities, )
Add an externally created session to the cache Used when session_handler creates a session directly in storage
Sourcepub async fn load_session_from_storage(
&self,
session_id: &str,
) -> Result<bool, SessionError>
pub async fn load_session_from_storage( &self, session_id: &str, ) -> Result<bool, SessionError>
Load session from storage into cache with its actual capabilities This preserves the negotiated capabilities and session state from persistent storage
Sourcepub async fn touch_session(&self, session_id: &str) -> Result<(), SessionError>
pub async fn touch_session(&self, session_id: &str) -> Result<(), SessionError>
Get session and update last accessed time
Sourcepub async fn initialize_session(
&self,
session_id: &str,
client_info: Implementation,
client_capabilities: ClientCapabilities,
) -> Result<(), SessionError>
pub async fn initialize_session( &self, session_id: &str, client_info: Implementation, client_capabilities: ClientCapabilities, ) -> Result<(), SessionError>
Initialize a session with client information
Sourcepub async fn initialize_session_with_version(
&self,
session_id: &str,
client_info: Implementation,
client_capabilities: ClientCapabilities,
mcp_version: McpVersion,
) -> Result<(), SessionError>
pub async fn initialize_session_with_version( &self, session_id: &str, client_info: Implementation, client_capabilities: ClientCapabilities, mcp_version: McpVersion, ) -> Result<(), SessionError>
Initialize a session with client information and negotiated protocol version
Sourcepub async fn session_exists(&self, session_id: &str) -> bool
pub async fn session_exists(&self, session_id: &str) -> bool
Check if session exists and is valid
Sourcepub async fn get_session_state(
&self,
session_id: &str,
key: &str,
) -> Option<Value>
pub async fn get_session_state( &self, session_id: &str, key: &str, ) -> Option<Value>
Get session state value
Sourcepub async fn set_session_state(&self, session_id: &str, key: &str, value: Value)
pub async fn set_session_state(&self, session_id: &str, key: &str, value: Value)
Set session state value
Sourcepub async fn remove_session_state(
&self,
session_id: &str,
key: &str,
) -> Option<Value>
pub async fn remove_session_state( &self, session_id: &str, key: &str, ) -> Option<Value>
Remove session state value
Sourcepub async fn is_session_initialized(&self, session_id: &str) -> bool
pub async fn is_session_initialized(&self, session_id: &str) -> bool
Check if session is initialized
Sourcepub async fn remove_session(&self, session_id: &str) -> bool
pub async fn remove_session(&self, session_id: &str) -> bool
Remove a session
Sourcepub async fn cleanup_expired(&self) -> usize
pub async fn cleanup_expired(&self) -> usize
Cleanup expired sessions
Sourcepub async fn send_event_to_session(
&self,
session_id: &str,
event: SessionEvent,
) -> Result<(), SessionError>
pub async fn send_event_to_session( &self, session_id: &str, event: SessionEvent, ) -> Result<(), SessionError>
Send event to specific session
Sourcepub async fn broadcast_event(&self, event: SessionEvent)
pub async fn broadcast_event(&self, event: SessionEvent)
Broadcast event to all sessions
Sourcepub async fn session_count(&self) -> usize
pub async fn session_count(&self) -> usize
Get active session count
Sourcepub fn create_session_context(
self: &Arc<Self>,
session_id: &str,
) -> Option<SessionContext>
pub fn create_session_context( self: &Arc<Self>, session_id: &str, ) -> Option<SessionContext>
Create session context for a session
Sourcepub fn start_cleanup_task(self: Arc<Self>) -> JoinHandle<()>
pub fn start_cleanup_task(self: Arc<Self>) -> JoinHandle<()>
Start automatic cleanup task
Sourcepub async fn get_session_event_receiver(
&self,
session_id: &str,
) -> Option<Receiver<SessionEvent>>
pub async fn get_session_event_receiver( &self, session_id: &str, ) -> Option<Receiver<SessionEvent>>
Get a session’s event receiver for SSE streaming
Sourcepub fn subscribe_all_session_events(&self) -> Receiver<(String, SessionEvent)>
pub fn subscribe_all_session_events(&self) -> Receiver<(String, SessionEvent)>
Subscribe to events from all sessions Returns a receiver that gets (session_id, event) tuples for all session events
Sourcepub fn get_storage(&self) -> Arc<BoxedSessionStorage> ⓘ
pub fn get_storage(&self) -> Arc<BoxedSessionStorage> ⓘ
Get the storage backend for use by other components (e.g., HTTP server) This ensures all components use the same storage backend
Sourcepub fn get_default_capabilities(&self) -> ServerCapabilities
pub fn get_default_capabilities(&self) -> ServerCapabilities
Get the default capabilities for use by other components
Sourcepub async fn session_exists_in_cache(&self, session_id: &str) -> bool
pub async fn session_exists_in_cache(&self, session_id: &str) -> bool
Check if session exists in the in-memory cache only (not storage)
Auto Trait Implementations§
impl !Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl !UnwindSafe for SessionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more