Skip to main content

MCPClient

Struct MCPClient 

Source
pub struct MCPClient { /* private fields */ }
Expand description

Client for communicating with MCP tool providers over any transport.

Implementations§

Source§

impl MCPClient

Source

pub async fn spawn( command: &str, args: &[&str], env: &HashMap<String, String>, ) -> Result<Self>

Spawn an MCP server as a child process and talk to it over stdio.

Source

pub fn connect_http( url: &str, headers: &HashMap<String, String>, allow_env: &[String], ) -> Result<Self>

Connect to an MCP server over HTTP.

Source

pub fn set_refresher(&mut self, refresher: Arc<dyn BearerRefresher>)

Attach a refresher used to re-authenticate on a mid-session 401.

Only the HTTP transport acts on it; stdio ignores it. The daemon sets this for an OAuth-backed HTTP server so a long run whose token expires keeps working.

Source

pub async fn from_config(config: &MCPServerConfig) -> Result<Self>

Build a client for a configured server, over whichever transport the entry describes.

Callers above this point - discovery, execution, the tool registry - never learn which one it turned out to be.

Source

pub async fn from_config_with_auth( config: &MCPServerConfig, auth_header: Option<(String, String)>, allow_env: &[String], ) -> Result<Self>

Self::from_config with a resolved Authorization header injected for an HTTP server.

auth_header is the (name, value) pair from crate::OAuthClient::authorization_header; it is layered on top of the config’s static headers (and wins on a clash, since a live token should override a stale hard-coded one). Ignored for stdio servers, which carry no HTTP headers.

Source

pub async fn connect(&mut self) -> Result<()>

Connect to the MCP server by sending initialize and initialized messages.

Source

pub async fn list_tools(&mut self) -> Result<Vec<ToolMetadata>>

List available tools from the server, following nextCursor pagination.

tools/list is a paginated operation. Reading only the first response silently exposes just the first page of a large server’s catalogue, so this loops until the server stops returning a cursor, bounded by an internal page limit so a server that returns a cursor forever can’t spin the loop.

Source

pub async fn call_tool( &mut self, name: &str, arguments: Value, ) -> Result<ToolResult>

Call a tool on the server.

Source

pub async fn shutdown(&mut self) -> Result<()>

Shutdown the MCP server.

Always succeeds: a dead or unresponsive server must never block cleanup.

Source

pub fn capabilities(&self) -> Option<&ServerCapabilities>

Get the server capabilities (available after connect).

Source

pub fn protocol_version(&self) -> Option<&str>

The protocol revision agreed with the server (available after connect).

Source

pub fn cached_tools(&self) -> &[ToolMetadata]

Get the cached tool list.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more