rust_mcp_sdk/session_store.rs
1mod in_memory_session_store;
2use crate::mcp_server::ServerRuntime;
3use async_trait::async_trait;
4pub use in_memory_session_store::*;
5use rust_mcp_transport::SessionId;
6use std::sync::Arc;
7
8/// Trait defining the interface for session storage operations
9///
10/// This trait provides asynchronous methods for managing session data,
11/// Implementors must be Send and Sync to support concurrent access.
12#[async_trait]
13pub trait SessionStore: Send + Sync {
14 /// Retrieves a session by its identifier
15 ///
16 /// # Arguments
17 /// * `key` - The session identifier to look up
18 ///
19 /// # Returns
20 /// * `Option<Arc<ServerRuntime>>` - The session stream if found, None otherwise
21 async fn get(&self, key: &SessionId) -> Option<Arc<ServerRuntime>>;
22 /// Stores a new session with the given identifier
23 ///
24 /// # Arguments
25 /// * `key` - The session identifier
26 /// * `value` - The duplex stream to store
27 async fn set(&self, key: SessionId, value: Arc<ServerRuntime>);
28 /// Deletes a session by its identifier
29 ///
30 /// # Arguments
31 /// * `key` - The session identifier to delete
32 async fn delete(&self, key: &SessionId);
33
34 async fn has(&self, session: &SessionId) -> bool;
35
36 async fn keys(&self) -> Vec<SessionId>;
37
38 async fn values(&self) -> Vec<Arc<ServerRuntime>>;
39
40 /// Clears all sessions from the store
41 async fn clear(&self);
42}