Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        record: &'life1 mut SessionRecord,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save<'life0, 'life1, 'async_trait>(
        &'life0 self,
        record: &'life1 SessionRecord,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn load<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Storage backend for MCP session metadata.

Implementations persist SessionRecords keyed by session ID. The default implementation is MemorySessionStore; external stores (Redis, Postgres, etc.) typically live in separate crates.

§Semantics

  • create must ensure the ID in the record is unique, retrying ID generation if necessary.
  • save trusts the caller’s ID and performs an upsert.
  • load returns None for unknown or expired sessions. Implementations may choose to return expired records and let the caller decide, or filter them out.
  • delete is idempotent – removing a non-existent ID is not an error.

Required Methods§

Source

fn create<'life0, 'life1, 'async_trait>( &'life0 self, record: &'life1 mut SessionRecord, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new session record.

The implementation must ensure record.id does not collide with an existing session, regenerating the ID if needed.

Source

fn save<'life0, 'life1, 'async_trait>( &'life0 self, record: &'life1 SessionRecord, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Persist an existing session record. The ID is trusted.

Source

fn load<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load a session record by ID. Returns None if unknown or expired.

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove a session record. Idempotent.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl SessionStore for MemorySessionStore

Source§

impl<Cache, Store> SessionStore for CachingSessionStore<Cache, Store>
where Cache: SessionStore, Store: SessionStore,