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>>
Sourcepub async fn server_capabilities(&self) -> Option<ServerCapabilities>
pub async fn server_capabilities(&self) -> Option<ServerCapabilities>
Returns a clone of the server’s announced ServerCapabilities
from the initial initialize handshake, or None if the client
has been shut down or the handshake hadn’t completed.
Per MCP spec, clients should not call resources/list or
prompts/list against a server that didn’t declare the
corresponding capability — doing so produces a noisy
-32601 method not found from compliant servers. Use this to
gate optional listing calls.
Sourcepub async fn list_resources(&self) -> Result<Vec<Resource>>
pub async fn list_resources(&self) -> Result<Vec<Resource>>
Lists the server’s resources. Returns Ok(vec![]) (silently)
when the server didn’t declare the resources capability at
init time — this avoids spamming a -32601 method not found
failure for servers that legitimately don’t expose resources.
Callers needing to distinguish “not advertised” from “empty”
should check Self::server_capabilities first.
Sourcepub async fn list_prompts(&self) -> Result<Vec<Prompt>>
pub async fn list_prompts(&self) -> Result<Vec<Prompt>>
Lists the server’s prompts. Same capability-aware short-circuit
as Self::list_resources: returns Ok(vec![]) when the
server didn’t declare the prompts capability.
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,
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,
timeout. Returns a CallOutcome that the
caller pattern-matches; this method itself never errors.