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 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 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.
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for McpClient
impl !RefUnwindSafe for McpClient
impl Send for McpClient
impl Sync for McpClient
impl Unpin for McpClient
impl UnsafeUnpin for McpClient
impl !UnwindSafe for McpClient
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