pub struct LdsState { /* private fields */ }Expand description
Top-level mutable state for the MCP server.
Holds a ledger of all live Sessions, indexed by session_id (opaque
hash) and alias (human-readable label). One session is designated the
default session, returned by Self::session for backward-compatible
tool calls that pre-date per-call session_id addressing.
The MCP handler wraps this in Arc<RwLock<LdsState>> for concurrent tool
access. Mutations (create / close / alias) take the write lock; reads
(resolve / list / describe / doctor) take the read lock.
Implementations§
Source§impl LdsState
impl LdsState
pub fn new() -> LdsState
Sourcepub fn create_session(
&mut self,
config: SessionConfig,
make_default: bool,
) -> Result<Arc<Session>, CoreError>
pub fn create_session( &mut self, config: SessionConfig, make_default: bool, ) -> Result<Arc<Session>, CoreError>
Create a new session and register it in the ledger.
If make_default is true (or no default exists yet), the new session
becomes the implicit default.
Returns CoreError::AliasConflict if config.alias is already
taken by another session.
Sourcepub fn start_session(
&mut self,
config: SessionConfig,
) -> Result<Arc<Session>, CoreError>
pub fn start_session( &mut self, config: SessionConfig, ) -> Result<Arc<Session>, CoreError>
Backward-compatible entry point used by the legacy session_start
MCP tool. Always replaces the default session.
Sourcepub fn resolve(&self, key: &str) -> Result<Arc<Session>, CoreError>
pub fn resolve(&self, key: &str) -> Result<Arc<Session>, CoreError>
Look up a session by id or alias.
key is tried as an alias first, then as a session_id. Returns
CoreError::SessionNotFound if neither matches.
Sourcepub fn session(&self) -> Result<Arc<Session>, CoreError>
pub fn session(&self) -> Result<Arc<Session>, CoreError>
Return the default session for backward-compatible tool calls.
pub fn default_session_id(&self) -> Option<&str>
Sourcepub fn list_sessions(&self) -> Vec<SessionEntry>
pub fn list_sessions(&self) -> Vec<SessionEntry>
Snapshot every session in the ledger.
Sourcepub fn describe(&self, key: &str) -> Result<SessionEntry, CoreError>
pub fn describe(&self, key: &str) -> Result<SessionEntry, CoreError>
Describe a single session by id or alias.
Sourcepub fn set_alias(&mut self, key: &str, alias: String) -> Result<(), CoreError>
pub fn set_alias(&mut self, key: &str, alias: String) -> Result<(), CoreError>
Assign or change an alias on an existing session.
Returns CoreError::AliasConflict if the new alias is already held
by another session.