pub struct McpClient { /* private fields */ }Expand description
A transport-generic MCP client over a tokio byte stream.
Cheap to clone (all state is shared); clones see the same connection.
Use McpClient::connect for an arbitrary transport or
McpStdioClient::spawn for a child-process stdio server.
Lifecycle: connect → initialize →
list_tools / call_tool
/ into_tools → shutdown.
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub fn connect<R, W>(reader: R, writer: W) -> Self
pub fn connect<R, W>(reader: R, writer: W) -> Self
Connect over an arbitrary transport using newline-delimited framing (the MCP stdio convention).
Sourcepub fn connect_with_framing<R, W>(
reader: R,
writer: W,
framing: Framing,
) -> Self
pub fn connect_with_framing<R, W>( reader: R, writer: W, framing: Framing, ) -> Self
Connect over an arbitrary transport with explicit framing.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
true once initialize has completed.
Sourcepub fn set_request_timeout(&self, timeout: Duration)
pub fn set_request_timeout(&self, timeout: Duration)
Override the per-request timeout (default: 30 s).
Sourcepub async fn initialize(&self) -> Result<InitializeResult>
pub async fn initialize(&self) -> Result<InitializeResult>
Perform the MCP initialize handshake: negotiate the protocol
revision, advertise clientInfo/capabilities, then send the
notifications/initialized notification.
Sourcepub async fn list_tools(&self) -> Result<Vec<McpToolInfo>>
pub async fn list_tools(&self) -> Result<Vec<McpToolInfo>>
List the server’s tools (tools/list).
Sourcepub async fn call_tool(&self, name: &str, arguments: Value) -> Result<Value>
pub async fn call_tool(&self, name: &str, arguments: Value) -> Result<Value>
Call a tool (tools/call).
On success returns the concatenated text content items as a
Value::String (the common case), or the raw result object if the
server returned no text content. A result with isError: true maps to
RustyError::Tool.
Sourcepub async fn into_tools(&self) -> Result<Vec<Arc<dyn Tool>>>
pub async fn into_tools(&self) -> Result<Vec<Arc<dyn Tool>>>
List the server’s tools and wrap each as a Rusty Core Tool,
ready for crate::tool::ToolRegistry::register_shared.