pub struct McpClient { /* private fields */ }Expand description
High-level MCP client that manages connection lifecycle and protocol.
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub async fn connect_stdio(
command: &str,
args: &[&str],
env: Option<HashMap<String, String>>,
) -> Result<Self, McpError>
pub async fn connect_stdio( command: &str, args: &[&str], env: Option<HashMap<String, String>>, ) -> Result<Self, McpError>
Connect to an MCP server via stdio (spawn a child process).
Uses the default per-request timeout (DEFAULT_REQUEST_TIMEOUT, 30 s).
For a custom timeout, use McpClient::connect_stdio_with_config.
Sourcepub async fn connect_stdio_with_config(
command: &str,
args: &[&str],
env: Option<HashMap<String, String>>,
config: McpClientConfig,
) -> Result<Self, McpError>
pub async fn connect_stdio_with_config( command: &str, args: &[&str], env: Option<HashMap<String, String>>, config: McpClientConfig, ) -> Result<Self, McpError>
Connect to an MCP server via stdio with custom configuration.
Sourcepub async fn connect_http(url: &str) -> Result<Self, McpError>
pub async fn connect_http(url: &str) -> Result<Self, McpError>
Connect to an MCP server via HTTP.
Uses the default per-request timeout (DEFAULT_REQUEST_TIMEOUT, 30 s).
For a custom timeout, use McpClient::connect_http_with_config.
Sourcepub async fn connect_http_with_config(
url: &str,
config: McpClientConfig,
) -> Result<Self, McpError>
pub async fn connect_http_with_config( url: &str, config: McpClientConfig, ) -> Result<Self, McpError>
Connect to an MCP server via HTTP with custom configuration.
Sourcepub fn from_transport(transport: Box<dyn McpTransport>) -> Self
pub fn from_transport(transport: Box<dyn McpTransport>) -> Self
Create from an existing transport (useful for testing).
Sourcepub async fn initialize(&mut self) -> Result<ServerInfo, McpError>
pub async fn initialize(&mut self) -> Result<ServerInfo, McpError>
Initialize the MCP connection (handshake).
Sourcepub async fn list_tools(&self) -> Result<Vec<McpToolInfo>, McpError>
pub async fn list_tools(&self) -> Result<Vec<McpToolInfo>, McpError>
List available tools from the server.
Sourcepub async fn call_tool(
&self,
name: &str,
arguments: Value,
) -> Result<McpToolCallResult, McpError>
pub async fn call_tool( &self, name: &str, arguments: Value, ) -> Result<McpToolCallResult, McpError>
Call a tool on the server.
Sourcepub fn server_info(&self) -> Option<&ServerInfo>
pub fn server_info(&self) -> Option<&ServerInfo>
Get server info (available after initialize).