SessionManager

Struct SessionManager 

Source
pub struct SessionManager { /* private fields */ }
Expand description

Global session manager for MCP servers

Implementations§

Source§

impl SessionManager

Source

pub fn new(default_capabilities: ServerCapabilities) -> Self

Create a new session manager with InMemory storage

Source

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

Source

pub fn with_storage( storage: Arc<BoxedSessionStorage>, default_capabilities: ServerCapabilities, ) -> Self

Create a new session manager with specific storage backend

Source

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

Source

pub async fn create_session(&self) -> String

Create a new session and return its ID

Source

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)

Source

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

Source

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

Source

pub async fn touch_session(&self, session_id: &str) -> Result<(), SessionError>

Get session and update last accessed time

Source

pub async fn initialize_session( &self, session_id: &str, client_info: Implementation, client_capabilities: ClientCapabilities, ) -> Result<(), SessionError>

Initialize a session with client information

Source

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

Source

pub async fn session_exists(&self, session_id: &str) -> bool

Check if session exists and is valid

Source

pub async fn get_session_state( &self, session_id: &str, key: &str, ) -> Option<Value>

Get session state value

Source

pub async fn set_session_state(&self, session_id: &str, key: &str, value: Value)

Set session state value

Source

pub async fn remove_session_state( &self, session_id: &str, key: &str, ) -> Option<Value>

Remove session state value

Source

pub async fn is_session_initialized(&self, session_id: &str) -> bool

Check if session is initialized

Source

pub async fn remove_session(&self, session_id: &str) -> bool

Remove a session

Source

pub async fn cleanup_expired(&self) -> usize

Cleanup expired sessions

Source

pub async fn send_event_to_session( &self, session_id: &str, event: SessionEvent, ) -> Result<(), SessionError>

Send event to specific session

Source

pub async fn broadcast_event(&self, event: SessionEvent)

Broadcast event to all sessions

Source

pub async fn session_count(&self) -> usize

Get active session count

Source

pub fn create_session_context( self: &Arc<Self>, session_id: &str, ) -> Option<SessionContext>

Create session context for a session

Source

pub fn start_cleanup_task(self: Arc<Self>) -> JoinHandle<()>

Start automatic cleanup task

Source

pub async fn get_session_event_receiver( &self, session_id: &str, ) -> Option<Receiver<SessionEvent>>

Get a session’s event receiver for SSE streaming

Source

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

Source

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

Source

pub fn get_default_capabilities(&self) -> ServerCapabilities

Get the default capabilities for use by other components

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,