pub struct McpClient { /* private fields */ }Implementations§
Source§impl McpClient
impl McpClient
Sourcepub async fn connect(
server_url: &str,
headers: Option<HashMap<String, String>>,
) -> Result<Self, McpError>
pub async fn connect( server_url: &str, headers: Option<HashMap<String, String>>, ) -> Result<Self, McpError>
Connects to an MCP server over streamable HTTP.
§Errors
Returns an error if URL resolution, HTTP client or header construction, the initialization timeout, or the MCP handshake fails.
Sourcepub async fn connect_stdio(
command: &str,
args: &[String],
env: Option<&HashMap<String, String>>,
cwd: Option<&str>,
) -> Result<Self, McpError>
pub async fn connect_stdio( command: &str, args: &[String], env: Option<&HashMap<String, String>>, cwd: Option<&str>, ) -> Result<Self, McpError>
Spawns a local stdio MCP server and connects over stdin/stdout.
§Errors
Returns McpError::SpawnStdio if the process cannot be spawned.
Returns McpError::Connect if the MCP initialization handshake fails.
Sourcepub async fn list_tools(&self) -> Result<Vec<Tool>, McpError>
pub async fn list_tools(&self) -> Result<Vec<Tool>, McpError>
Lists tools exposed by the connected MCP server.
§Errors
Returns McpError::Timeout if tools/list exceeds the configured timeout.
Returns McpError::Operation if the server rejects or fails the request.
Sourcepub async fn call_tool(
&self,
name: &str,
arguments: Option<Value>,
) -> Result<CallToolResult, McpError>
pub async fn call_tool( &self, name: &str, arguments: Option<Value>, ) -> Result<CallToolResult, McpError>
Calls a tool exposed by the connected MCP server.
§Errors
Returns McpError::InvalidArguments if arguments is not a JSON object.
Returns McpError::Timeout if tools/call exceeds the configured timeout.
Returns McpError::Operation if the server rejects or fails the request.
Returns McpError::UnexpectedResponse if the server returns another response kind.
Auto Trait Implementations§
impl !RefUnwindSafe for McpClient
impl !UnwindSafe for McpClient
impl Freeze for McpClient
impl Send for McpClient
impl Sync for McpClient
impl Unpin for McpClient
impl UnsafeUnpin for McpClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more