pub struct McpClient { /* private fields */ }Expand description
A connected MCP server via stdio transport.
Spawns the configured command as a child process, performs the MCP
initialize handshake, fetches the tool list, and provides a
call_tool method to invoke server-side tools.
§Thread safety
All mutable state is behind Mutex, making &self the only
shared reference needed for every operation. The struct is Sync.
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub fn new(config: McpServerConfig) -> Self
pub fn new(config: McpServerConfig) -> Self
Create a new client for the given server configuration.
The server is not spawned until connect is called.
Sourcepub async fn connect(&self) -> Result<(), AgentError>
pub async fn connect(&self) -> Result<(), AgentError>
Spawn the server process and perform the MCP initialize handshake.
After the handshake succeeds the client sends the notifications/initialized
notification and fetches the tool list via tools/list.
Sourcepub async fn call_tool(
&self,
name: &str,
arguments: Value,
) -> Result<Value, AgentError>
pub async fn call_tool( &self, name: &str, arguments: Value, ) -> Result<Value, AgentError>
Call an MCP tool by name with the given arguments.
Returns the result portion of the JSON-RPC response on success.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Kill the server process and release I/O handles.