pub struct McpClientSession { /* private fields */ }Expand description
A guard-based session for a single MCP server connection.
The session connects on creation and disconnects when dropped. Tool
descriptors are cached after the first successful list_tools call
to avoid redundant round-trips.
Implementations§
Source§impl McpClientSession
impl McpClientSession
Sourcepub async fn connect(
name: impl Into<String>,
transport: Arc<dyn McpTransport>,
) -> Result<Self, AgentError>
pub async fn connect( name: impl Into<String>, transport: Arc<dyn McpTransport>, ) -> Result<Self, AgentError>
Connects to the server and returns a new session.
§Errors
Returns AgentError if the transport fails to connect.
Sourcepub async fn status(&self) -> McpServerStatus
pub async fn status(&self) -> McpServerStatus
Returns the current connection status from the transport.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Returns true if the session is currently connected.
Sourcepub fn cached_tools(&self) -> &[McpToolDescriptor]
pub fn cached_tools(&self) -> &[McpToolDescriptor]
Returns a reference to the cached tool descriptors.
The cache is empty until populate_tool_cache
has been called.
Sourcepub async fn populate_tool_cache(&mut self) -> Result<(), AgentError>
pub async fn populate_tool_cache(&mut self) -> Result<(), AgentError>
Fetches the tool list from the server and caches the results.
Overwrites any previously cached descriptors.
§Errors
Returns AgentError if the transport call fails.
Sourcepub fn transport(&self) -> &Arc<dyn McpTransport>
pub fn transport(&self) -> &Arc<dyn McpTransport>
Returns a reference to the underlying transport.
Trait Implementations§
Source§impl Debug for McpClientSession
impl Debug for McpClientSession
Auto Trait Implementations§
impl Freeze for McpClientSession
impl !RefUnwindSafe for McpClientSession
impl Send for McpClientSession
impl Sync for McpClientSession
impl Unpin for McpClientSession
impl UnsafeUnpin for McpClientSession
impl !UnwindSafe for McpClientSession
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