pub struct McpClient { /* private fields */ }Expand description
Model Context Protocol client supporting initialize, tools/list, and tools/call.
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub fn new(transport: impl McpTransport + 'static) -> Self
pub fn new(transport: impl McpTransport + 'static) -> Self
Wraps any McpTransport implementation.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Overrides the per-request timeout.
Sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Updates the per-request timeout on an existing client.
Sourcepub fn open_stdio(
command: &str,
args: &[String],
env: &BTreeMap<String, String>,
timeout: Duration,
) -> Result<Self, McpError>
pub fn open_stdio( command: &str, args: &[String], env: &BTreeMap<String, String>, timeout: Duration, ) -> Result<Self, McpError>
Spawns a stdio MCP server and returns an uninitialized client.
Sourcepub fn open_http(
url: impl Into<String>,
headers: BTreeMap<String, String>,
bearer_token: Option<String>,
timeout: Duration,
) -> Self
pub fn open_http( url: impl Into<String>, headers: BTreeMap<String, String>, bearer_token: Option<String>, timeout: Duration, ) -> Self
Creates a Streamable HTTP MCP client (uninitialized).
Sourcepub fn open_server(
server: &ConfiguredServer,
env_lookup: &EnvLookup,
bearer_token: Option<String>,
timeout: Duration,
) -> Result<Self, McpError>
pub fn open_server( server: &ConfiguredServer, env_lookup: &EnvLookup, bearer_token: Option<String>, timeout: Duration, ) -> Result<Self, McpError>
Opens a transport for a validated ConfiguredServer.
Refuses untrusted project servers before spawning commands or making HTTP requests.
Sourcepub fn connect_server(
server: &ConfiguredServer,
env_lookup: &EnvLookup,
bearer_token: Option<String>,
timeout: Duration,
) -> Result<(Self, InitializeResult), McpError>
pub fn connect_server( server: &ConfiguredServer, env_lookup: &EnvLookup, bearer_token: Option<String>, timeout: Duration, ) -> Result<(Self, InitializeResult), McpError>
Opens and performs the MCP initialize handshake for a ConfiguredServer.
Sourcepub fn server_info(&self) -> Option<&InitializeResult>
pub fn server_info(&self) -> Option<&InitializeResult>
Returns the cached InitializeResult if initialize has completed.
Sourcepub fn initialize(&mut self) -> Result<InitializeResult, McpError>
pub fn initialize(&mut self) -> Result<InitializeResult, McpError>
Runs the MCP initialize request followed by notifications/initialized.
Sourcepub fn list_tools_page(
&mut self,
cursor: Option<&str>,
) -> Result<ToolsListResult, McpError>
pub fn list_tools_page( &mut self, cursor: Option<&str>, ) -> Result<ToolsListResult, McpError>
Fetches a single page from tools/list.
Sourcepub fn list_tools(&mut self) -> Result<Vec<Tool>, McpError>
pub fn list_tools(&mut self) -> Result<Vec<Tool>, McpError>
Fetches all tools from tools/list, following nextCursor pagination if returned.
Sourcepub fn call_tool(
&mut self,
name: &str,
arguments: Value,
) -> Result<ToolCallResult, McpError>
pub fn call_tool( &mut self, name: &str, arguments: Value, ) -> Result<ToolCallResult, McpError>
Invokes a tool via tools/call and returns structured content blocks and isError.