pub struct ClientSession { /* private fields */ }Expand description
Client session that manages connection lifecycle and notifications
Implementations§
Source§impl ClientSession
impl ClientSession
Sourcepub fn with_config(client: McpClient, config: SessionConfig) -> Self
pub fn with_config(client: McpClient, config: SessionConfig) -> Self
Create a new client session with custom configuration
Sourcepub async fn state(&self) -> SessionState
pub async fn state(&self) -> SessionState
Get the current session state
Sourcepub fn subscribe_state_changes(&self) -> Receiver<SessionState>
pub fn subscribe_state_changes(&self) -> Receiver<SessionState>
Subscribe to state changes
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if the session is connected
Sourcepub async fn add_notification_handler<H>(&self, handler: H)where
H: NotificationHandler + 'static,
pub async fn add_notification_handler<H>(&self, handler: H)where
H: NotificationHandler + 'static,
Add a notification handler
Sourcepub async fn connect<T>(&self, transport: T) -> McpResult<ConnectResult>where
T: Transport + 'static,
pub async fn connect<T>(&self, transport: T) -> McpResult<ConnectResult>where
T: Transport + 'static,
Connect to the server with the provided transport
Sourcepub async fn disconnect(&self) -> McpResult<()>
pub async fn disconnect(&self) -> McpResult<()>
Disconnect from the server
Sourcepub async fn reconnect<T>(
&self,
transport_factory: impl Fn() -> T + Send + Sync + 'static,
) -> McpResult<ConnectResult>where
T: Transport + 'static,
pub async fn reconnect<T>(
&self,
transport_factory: impl Fn() -> T + Send + Sync + 'static,
) -> McpResult<ConnectResult>where
T: Transport + 'static,
Reconnect to the server with smart retry logic
Sourcepub fn client(&self) -> Arc<Mutex<McpClient>> ⓘ
pub fn client(&self) -> Arc<Mutex<McpClient>> ⓘ
Get the underlying client (for direct operations)
Sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
Get session configuration
Sourcepub async fn list_tools(
&self,
cursor: Option<String>,
) -> McpResult<ListToolsResult>
pub async fn list_tools( &self, cursor: Option<String>, ) -> McpResult<ListToolsResult>
List available tools from the server
Sourcepub async fn call_tool(
&self,
params: CallToolParams,
) -> McpResult<CallToolResult>
pub async fn call_tool( &self, params: CallToolParams, ) -> McpResult<CallToolResult>
Call a tool on the server
Sourcepub async fn list_resources(
&self,
cursor: Option<String>,
) -> McpResult<ListResourcesResult>
pub async fn list_resources( &self, cursor: Option<String>, ) -> McpResult<ListResourcesResult>
List available resources from the server
Sourcepub async fn read_resource(
&self,
params: ReadResourceParams,
) -> McpResult<ReadResourceResult>
pub async fn read_resource( &self, params: ReadResourceParams, ) -> McpResult<ReadResourceResult>
Read a resource from the server
Sourcepub async fn list_prompts(
&self,
cursor: Option<String>,
) -> McpResult<ListPromptsResult>
pub async fn list_prompts( &self, cursor: Option<String>, ) -> McpResult<ListPromptsResult>
List available prompts from the server
Sourcepub async fn get_prompt(
&self,
params: GetPromptParams,
) -> McpResult<GetPromptResult>
pub async fn get_prompt( &self, params: GetPromptParams, ) -> McpResult<GetPromptResult>
Get a prompt from the server
Source§impl ClientSession
impl ClientSession
Sourcepub async fn stats(&self) -> SessionStats
pub async fn stats(&self) -> SessionStats
Get session statistics
Auto Trait Implementations§
impl !RefUnwindSafe for ClientSession
impl !UnwindSafe for ClientSession
impl Freeze for ClientSession
impl Send for ClientSession
impl Sync for ClientSession
impl Unpin for ClientSession
impl UnsafeUnpin for ClientSession
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].