pub struct McpClient { /* private fields */ }Expand description
An MCP client owns a transport and manages JSON-RPC communication.
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub async fn spawn(server: &McpServer) -> Result<Self>
pub async fn spawn(server: &McpServer) -> Result<Self>
Spawn an MCP server (stdio or HTTP+SSE), perform the initialize handshake, and return a ready-to-use client.
If server.url is set, uses HTTP+SSE transport. Otherwise uses stdio.
Sourcepub async fn spawn_with_timeout(
server: &McpServer,
read_timeout: Duration,
) -> Result<Self>
pub async fn spawn_with_timeout( server: &McpServer, read_timeout: Duration, ) -> Result<Self>
Like [spawn], but with a custom stdio read timeout. Tests use
a short value (e.g. 500ms) to keep the suite fast; production
callers should stick to [spawn].
Sourcepub async fn list_tools(&mut self) -> Result<Vec<McpToolSpec>>
pub async fn list_tools(&mut self) -> Result<Vec<McpToolSpec>>
Call tools/list and return the discovered tool specs.
Sourcepub fn with_elicitation(self, slot: SharedElicitationHandler) -> Self
pub fn with_elicitation(self, slot: SharedElicitationHandler) -> Self
Attach a shared elicitation-handler slot (Claude control channel).
Sourcepub async fn call_tool(
&mut self,
name: &str,
arguments: Value,
) -> Result<String>
pub async fn call_tool( &mut self, name: &str, arguments: Value, ) -> Result<String>
Call a tool by name with the given arguments.
Returns the textual content of the first content[].text block.
Errors if isError is true in the response.
When the server returns JSON-RPC -32042 (UrlElicitationRequired) and
an ElicitationHandler is installed, the host is asked via the
Claude control channel before the error is returned to the caller.
Sourcepub async fn list_resources(&mut self) -> Result<Vec<McpResource>>
pub async fn list_resources(&mut self) -> Result<Vec<McpResource>>
Call resources/list and return the discovered resources.
Sourcepub async fn read_resource(
&mut self,
uri: &str,
) -> Result<Vec<McpResourceContent>>
pub async fn read_resource( &mut self, uri: &str, ) -> Result<Vec<McpResourceContent>>
Call resources/read for a specific resource URI.
Returns the list of content items.
Sourcepub async fn list_prompts(&mut self) -> Result<Vec<McpPrompt>>
pub async fn list_prompts(&mut self) -> Result<Vec<McpPrompt>>
Call prompts/list and return the discovered prompts.
Sourcepub async fn get_prompt(
&mut self,
name: &str,
arguments: Option<HashMap<String, String>>,
) -> Result<Vec<McpPromptMessage>>
pub async fn get_prompt( &mut self, name: &str, arguments: Option<HashMap<String, String>>, ) -> Result<Vec<McpPromptMessage>>
Call prompts/get for a specific prompt name with optional arguments.
Returns the list of messages.