pub struct Session {
pub id: String,
pub client_info: Option<Implementation>,
pub capabilities: Option<ClientCapabilities>,
pub protocol_version: Option<String>,
/* private fields */
}Expand description
Session represents a single MCP client connection
Fields§
§id: StringUnique session ID
client_info: Option<Implementation>Client information (set during initialization)
capabilities: Option<ClientCapabilities>Client capabilities (set during initialization)
protocol_version: Option<String>Negotiated protocol version (set during initialization)
Implementations§
Source§impl Session
impl Session
Sourcepub fn initialize(
&mut self,
client_info: Implementation,
capabilities: ClientCapabilities,
protocol_version: String,
)
pub fn initialize( &mut self, client_info: Implementation, capabilities: ClientCapabilities, protocol_version: String, )
Initialize session with client info and capabilities Transitions: Created -> Ready
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if session is initialized (Ready or Degraded)
Sourcepub fn protocol_version(&self) -> Option<&str>
pub fn protocol_version(&self) -> Option<&str>
Get the negotiated protocol version
Sourcepub fn record_error(&mut self)
pub fn record_error(&mut self)
Record an error, potentially transitioning to Degraded state Transitions: Ready -> Degraded (after threshold errors)
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
Record success, potentially recovering from Degraded state Transitions: Degraded -> Ready (resets error count)
Sourcepub fn lifecycle(&self) -> SessionLifecycle
pub fn lifecycle(&self) -> SessionLifecycle
Get current lifecycle state
Sourcepub fn error_count(&self) -> u32
pub fn error_count(&self) -> u32
Get current error count
Sourcepub fn remove_state(&self, key: &str) -> Option<Value>
pub fn remove_state(&self, key: &str) -> Option<Value>
Remove state value
Sourcepub fn clear_state(&self)
pub fn clear_state(&self)
Clear all state
Sourcepub fn state_keys(&self) -> Vec<String>
pub fn state_keys(&self) -> Vec<String>
Get all state keys
Sourcepub fn override_tool(&self, name: impl Into<String>, tool: Arc<dyn Tool>)
pub fn override_tool(&self, name: impl Into<String>, tool: Arc<dyn Tool>)
Override a tool (same name, different implementation)
Sourcepub fn unhide_tool(&self, name: &str)
pub fn unhide_tool(&self, name: &str)
Unhide a tool
Sourcepub fn alias_tool(&self, alias: impl Into<String>, target: impl Into<String>)
pub fn alias_tool(&self, alias: impl Into<String>, target: impl Into<String>)
Add a tool alias (alias -> target)
Sourcepub fn remove_tool_alias(&self, alias: &str)
pub fn remove_tool_alias(&self, alias: &str)
Remove a tool alias
Check if a tool is hidden
Sourcepub fn resolve_tool_alias<'a>(&self, name: &'a str) -> Cow<'a, str>
pub fn resolve_tool_alias<'a>(&self, name: &'a str) -> Cow<'a, str>
Resolve a tool alias to its target name
Sourcepub fn get_tool_override(&self, name: &str) -> Option<Arc<dyn Tool>>
pub fn get_tool_override(&self, name: &str) -> Option<Arc<dyn Tool>>
Get a tool override for this session
Sourcepub fn get_tool_extra(&self, name: &str) -> Option<Arc<dyn Tool>>
pub fn get_tool_extra(&self, name: &str) -> Option<Arc<dyn Tool>>
Get an extra tool added to this session
Sourcepub fn add_resource(&self, resource: Arc<dyn Resource>)
pub fn add_resource(&self, resource: Arc<dyn Resource>)
Add an extra resource to this session
Sourcepub fn override_resource(
&self,
uri: impl Into<String>,
resource: Arc<dyn Resource>,
)
pub fn override_resource( &self, uri: impl Into<String>, resource: Arc<dyn Resource>, )
Override a resource (same URI, different implementation)
Sourcepub fn hide_resource(&self, uri: impl Into<String>)
pub fn hide_resource(&self, uri: impl Into<String>)
Hide a resource from this session
Sourcepub fn unhide_resource(&self, uri: &str)
pub fn unhide_resource(&self, uri: &str)
Unhide a resource
Check if a resource is hidden
Sourcepub fn get_resource_override(&self, uri: &str) -> Option<Arc<dyn Resource>>
pub fn get_resource_override(&self, uri: &str) -> Option<Arc<dyn Resource>>
Get a resource override for this session
Sourcepub fn get_resource_extra(&self, uri: &str) -> Option<Arc<dyn Resource>>
pub fn get_resource_extra(&self, uri: &str) -> Option<Arc<dyn Resource>>
Get an extra resource added to this session
Sourcepub fn resource_overrides(&self) -> &Arc<DashMap<String, Arc<dyn Resource>>>
pub fn resource_overrides(&self) -> &Arc<DashMap<String, Arc<dyn Resource>>>
Get all resource overrides
Sourcepub fn resource_extras(&self) -> &Arc<DashMap<String, Arc<dyn Resource>>>
pub fn resource_extras(&self) -> &Arc<DashMap<String, Arc<dyn Resource>>>
Get all extra resources
Sourcepub fn add_prompt(&self, prompt: Arc<dyn Prompt>)
pub fn add_prompt(&self, prompt: Arc<dyn Prompt>)
Add an extra prompt to this session
Sourcepub fn override_prompt(&self, name: impl Into<String>, prompt: Arc<dyn Prompt>)
pub fn override_prompt(&self, name: impl Into<String>, prompt: Arc<dyn Prompt>)
Override a prompt (same name, different implementation)
Sourcepub fn hide_prompt(&self, name: impl Into<String>)
pub fn hide_prompt(&self, name: impl Into<String>)
Hide a prompt from this session
Sourcepub fn unhide_prompt(&self, name: &str)
pub fn unhide_prompt(&self, name: &str)
Unhide a prompt
Check if a prompt is hidden
Sourcepub fn get_prompt_override(&self, name: &str) -> Option<Arc<dyn Prompt>>
pub fn get_prompt_override(&self, name: &str) -> Option<Arc<dyn Prompt>>
Get a prompt override for this session
Sourcepub fn get_prompt_extra(&self, name: &str) -> Option<Arc<dyn Prompt>>
pub fn get_prompt_extra(&self, name: &str) -> Option<Arc<dyn Prompt>>
Get an extra prompt added to this session
Sourcepub fn prompt_overrides(&self) -> &Arc<DashMap<String, Arc<dyn Prompt>>>
pub fn prompt_overrides(&self) -> &Arc<DashMap<String, Arc<dyn Prompt>>>
Get all prompt overrides
Sourcepub fn apply_profile(&self, profile: &SessionProfile)
pub fn apply_profile(&self, profile: &SessionProfile)
Apply a session profile
This adds/overrides/hides tools, resources, and prompts according to the profile
Sourcepub fn clear_customizations(&self)
pub fn clear_customizations(&self)
Clear all session customizations