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,
) -> Session
pub fn new( server_info: ServerInfo, server_capabilities: ServerCapabilities, ) -> Session
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: &Arc<dyn Fn(JsonRpcRequest) + Send + Sync>,
) -> bool
pub fn notify_resource_updated( &self, uri: &str, sender: &Arc<dyn Fn(JsonRpcRequest) + Send + Sync>, ) -> bool
Sends a resource updated notification if the session is subscribed.
Returns true if a notification was sent.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more