pub struct Session { /* private fields */ }Expand description
An MCP session between client and server.
Tracks the state of an initialized MCP connection.
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(
server_info: ServerInfo,
server_capabilities: ServerCapabilities,
) -> Self
pub fn new( server_info: ServerInfo, server_capabilities: ServerCapabilities, ) -> Self
Creates a new uninitialized session.
Sourcepub fn state(&self) -> &SessionState
pub fn state(&self) -> &SessionState
Returns a reference to the session state.
Session state persists across requests within this session and can be used to store handler-specific data.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Returns whether the session has been initialized.
Sourcepub fn initialize(
&mut self,
client_info: ClientInfo,
client_capabilities: ClientCapabilities,
protocol_version: String,
)
pub fn initialize( &mut self, client_info: ClientInfo, client_capabilities: ClientCapabilities, protocol_version: String, )
Initializes the session with client info.
Sourcepub fn client_info(&self) -> Option<&ClientInfo>
pub fn client_info(&self) -> Option<&ClientInfo>
Returns the client info if initialized.
Sourcepub fn client_capabilities(&self) -> Option<&ClientCapabilities>
pub fn client_capabilities(&self) -> Option<&ClientCapabilities>
Returns the client capabilities if initialized.
Sourcepub fn server_info(&self) -> &ServerInfo
pub fn server_info(&self) -> &ServerInfo
Returns the server info.
Sourcepub fn server_capabilities(&self) -> &ServerCapabilities
pub fn server_capabilities(&self) -> &ServerCapabilities
Returns the server capabilities.
Sourcepub fn protocol_version(&self) -> Option<&str>
pub fn protocol_version(&self) -> Option<&str>
Returns the negotiated protocol version.
Sourcepub fn subscribe_resource(&mut self, uri: String)
pub fn subscribe_resource(&mut self, uri: String)
Subscribes to a resource URI for this session.
Sourcepub fn unsubscribe_resource(&mut self, uri: &str)
pub fn unsubscribe_resource(&mut self, uri: &str)
Unsubscribes from a resource URI for this session.
Sourcepub fn is_resource_subscribed(&self, uri: &str) -> bool
pub fn is_resource_subscribed(&self, uri: &str) -> bool
Returns true if this session is subscribed to the given resource URI.
Sourcepub fn set_log_level(&mut self, level: LogLevel)
pub fn set_log_level(&mut self, level: LogLevel)
Sets the session log level for log notifications.
Sourcepub fn log_level(&self) -> Option<LogLevel>
pub fn log_level(&self) -> Option<LogLevel>
Returns the current session log level for log notifications.
Sourcepub fn supports_sampling(&self) -> bool
pub fn supports_sampling(&self) -> bool
Returns whether the client supports sampling (LLM completions).
Sourcepub fn supports_elicitation(&self) -> bool
pub fn supports_elicitation(&self) -> bool
Returns whether the client supports elicitation (user input requests).
Sourcepub fn supports_roots(&self) -> bool
pub fn supports_roots(&self) -> bool
Returns whether the client supports roots listing.
Sourcepub fn notify_resource_updated(
&self,
uri: &str,
sender: &NotificationSender,
) -> bool
pub fn notify_resource_updated( &self, uri: &str, sender: &NotificationSender, ) -> bool
Sends a resource updated notification if the session is subscribed.
Returns true if a notification was sent.