pub struct SessionManager { /* private fields */ }Expand description
Comprehensive session manager for MCP applications
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(config: SessionConfig) -> Self
pub fn new(config: SessionConfig) -> Self
Create a new session manager
Sourcepub fn start(&self)
pub fn start(&self)
Start the session manager (begin cleanup task).
Idempotent: subsequent calls after the first are no-ops. The
cleanup_timer write-guard guards both the field assignment and
the tokio::spawn, so a second start() cannot leak a parallel
cleanup loop on the same DashMap.
Sourcepub fn get_or_create_session(
&self,
client_id: String,
transport_type: String,
) -> ClientSession
pub fn get_or_create_session( &self, client_id: String, transport_type: String, ) -> ClientSession
Create or get existing session for a client
Sourcepub fn update_client_activity(&self, client_id: &str)
pub fn update_client_activity(&self, client_id: &str)
Update client activity
Sourcepub fn authenticate_client(
&self,
client_id: &str,
client_name: Option<String>,
token: Option<String>,
) -> bool
pub fn authenticate_client( &self, client_id: &str, client_name: Option<String>, token: Option<String>, ) -> bool
Authenticate a client session
Sourcepub fn record_request(&self, request_info: RequestInfo)
pub fn record_request(&self, request_info: RequestInfo)
Record a request for analytics
Sourcepub fn get_analytics(&self) -> SessionAnalytics
pub fn get_analytics(&self) -> SessionAnalytics
Get session analytics
Sourcepub fn get_active_sessions(&self) -> Vec<ClientSession>
pub fn get_active_sessions(&self) -> Vec<ClientSession>
Get all active sessions
Sourcepub fn get_session(&self, client_id: &str) -> Option<ClientSession>
pub fn get_session(&self, client_id: &str) -> Option<ClientSession>
Get session by client ID
Sourcepub fn client_extractor(&self) -> Arc<ClientIdExtractor>
pub fn client_extractor(&self) -> Arc<ClientIdExtractor>
Get client ID extractor
Sourcepub fn terminate_session(&self, client_id: &str) -> bool
pub fn terminate_session(&self, client_id: &str) -> bool
Terminate a session
Sourcepub fn get_request_history(&self, limit: Option<usize>) -> Vec<RequestInfo>
pub fn get_request_history(&self, limit: Option<usize>) -> Vec<RequestInfo>
Get request history
Sourcepub fn get_session_events(&self, limit: Option<usize>) -> Vec<SessionEvent>
pub fn get_session_events(&self, limit: Option<usize>) -> Vec<SessionEvent>
Get session events
Sourcepub fn add_pending_elicitation(
&self,
client_id: String,
elicitation: ElicitationContext,
)
pub fn add_pending_elicitation( &self, client_id: String, elicitation: ElicitationContext, )
Add a pending elicitation for a client
Sourcepub fn get_pending_elicitations(
&self,
client_id: &str,
) -> Vec<ElicitationContext>
pub fn get_pending_elicitations( &self, client_id: &str, ) -> Vec<ElicitationContext>
Get all pending elicitations for a client
Sourcepub fn update_elicitation_state(
&self,
client_id: &str,
elicitation_id: &str,
state: ElicitationState,
) -> bool
pub fn update_elicitation_state( &self, client_id: &str, elicitation_id: &str, state: ElicitationState, ) -> bool
Update an elicitation state
Sourcepub fn remove_completed_elicitations(&self, client_id: &str)
pub fn remove_completed_elicitations(&self, client_id: &str)
Remove completed elicitations for a client
Sourcepub fn clear_elicitations(&self, client_id: &str)
pub fn clear_elicitations(&self, client_id: &str)
Clear all elicitations for a client
Sourcepub fn add_active_completion(
&self,
client_id: String,
completion: CompletionContext,
)
pub fn add_active_completion( &self, client_id: String, completion: CompletionContext, )
Add an active completion for a client
Sourcepub fn get_active_completions(&self, client_id: &str) -> Vec<CompletionContext>
pub fn get_active_completions(&self, client_id: &str) -> Vec<CompletionContext>
Get all active completions for a client
Sourcepub fn remove_completion(&self, client_id: &str, completion_id: &str) -> bool
pub fn remove_completion(&self, client_id: &str, completion_id: &str) -> bool
Remove a specific completion
Sourcepub fn clear_completions(&self, client_id: &str)
pub fn clear_completions(&self, client_id: &str)
Clear all completions for a client
Sourcepub fn get_enhanced_analytics(&self) -> SessionAnalytics
pub fn get_enhanced_analytics(&self) -> SessionAnalytics
Get session statistics including elicitations and completions