pub struct McpClient<T: McpTransport> { /* private fields */ }Expand description
MCP client for communicating with MCP servers.
The client handles the MCP protocol, including initialization, tool discovery, and tool execution.
§Example
ⓘ
use agent_sdk::mcp::{McpClient, StdioTransport};
// Spawn server and create client
let transport = StdioTransport::spawn("npx", &["-y", "mcp-server"]).await?;
let client = McpClient::new(transport, "my-server".to_string()).await?;
// List available tools
let tools = client.list_tools().await?;
// Call a tool
let result = client.call_tool("tool_name", json!({"arg": "value"})).await?;Implementations§
Source§impl<T: McpTransport> McpClient<T>
impl<T: McpTransport> McpClient<T>
Sourcepub const fn new_uninitialized(transport: Arc<T>, server_name: String) -> Self
pub const fn new_uninitialized(transport: Arc<T>, server_name: String) -> Self
Create a client without initialization.
Use this if you need to control when initialization happens.
Sourcepub async fn initialize(&mut self) -> Result<&InitializeResult>
pub async fn initialize(&mut self) -> Result<&InitializeResult>
Initialize the MCP connection.
This must be called before using other methods.
§Errors
Returns an error if the server rejects initialization.
Sourcepub fn server_name(&self) -> &str
pub fn server_name(&self) -> &str
Get the server name.
Sourcepub const fn server_info(&self) -> Option<&InitializeResult>
pub const fn server_info(&self) -> Option<&InitializeResult>
Get server info if initialized.
Sourcepub async fn list_tools(&self) -> Result<Vec<McpToolDefinition>>
pub async fn list_tools(&self) -> Result<Vec<McpToolDefinition>>
Sourcepub async fn call_tool_raw(
&self,
name: &str,
arguments: Option<Value>,
) -> Result<McpToolCallResult>
pub async fn call_tool_raw( &self, name: &str, arguments: Option<Value>, ) -> Result<McpToolCallResult>
Auto Trait Implementations§
impl<T> Freeze for McpClient<T>
impl<T> RefUnwindSafe for McpClient<T>where
T: RefUnwindSafe,
impl<T> Send for McpClient<T>
impl<T> Sync for McpClient<T>
impl<T> Unpin for McpClient<T>
impl<T> UnwindSafe for McpClient<T>where
T: RefUnwindSafe,
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