pub struct Client { /* private fields */ }Expand description
Cheaply-cloneable MCP client. Cloning shares the same underlying
transport via Arc. After Client::shutdown the transport is gone
and further calls return ClientError::Request.
Implementations§
Source§impl Client
impl Client
pub async fn connect(target: &Target) -> Result<Self>
Sourcepub async fn reconnect(&self) -> Result<()>
pub async fn reconnect(&self) -> Result<()>
Tears down the current transport and opens a new one. Other tasks
holding a &self reference will see the new transport on their
next call. Phase E1 changed this from &mut self to &self so
callers can recover after a fault without exclusive ownership of
the Client.
pub async fn list_tools(&self) -> Result<Vec<Tool>>
pub async fn list_resources(&self) -> Result<Vec<Resource>>
pub async fn list_prompts(&self) -> Result<Vec<Prompt>>
pub async fn call_tool( &self, name: &str, arguments: Value, timeout: Duration, ) -> CallOutcome
Sourcepub async fn shutdown(&self) -> Result<()>
pub async fn shutdown(&self) -> Result<()>
Shuts the underlying transport down. After this call other clones of
this Client keep working semantically but return ProtocolError
on every method (the transport is gone).
pub fn target(&self) -> &Target
Trait Implementations§
Source§impl McpExec for Client
impl McpExec for Client
Source§fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Tool>, ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Tool>, ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists every tool exposed by the server.
Source§fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
arguments: Value,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = CallOutcome> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
arguments: Value,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = CallOutcome> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Calls a tool, applying
timeout. Returns a CallOutcome that the
caller pattern-matches; this method itself never errors.Source§fn reconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn reconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Tears down the transport and rebuilds it. Used after a hang/crash
so subsequent calls can succeed. Concurrent callers see either the
old or the new transport, never a torn state.
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
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