pub struct MCPClient { /* private fields */ }Expand description
Client for communicating with MCP tool providers over any transport.
Implementations§
Source§impl MCPClient
impl MCPClient
Sourcepub async fn spawn(
command: &str,
args: &[&str],
env: &HashMap<String, String>,
) -> Result<Self>
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.
Sourcepub fn connect_http(
url: &str,
headers: &HashMap<String, String>,
allow_env: &[String],
) -> Result<Self>
pub fn connect_http( url: &str, headers: &HashMap<String, String>, allow_env: &[String], ) -> Result<Self>
Connect to an MCP server over HTTP.
Sourcepub fn set_refresher(&mut self, refresher: Arc<dyn BearerRefresher>)
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.
Sourcepub async fn from_config(config: &MCPServerConfig) -> Result<Self>
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.
Sourcepub async fn from_config_with_auth(
config: &MCPServerConfig,
auth_header: Option<(String, String)>,
allow_env: &[String],
) -> Result<Self>
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.
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Connect to the MCP server by sending initialize and initialized messages.
Sourcepub async fn list_tools(&mut self) -> Result<Vec<ToolMetadata>>
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.
Sourcepub async fn call_tool(
&mut self,
name: &str,
arguments: Value,
) -> Result<ToolResult>
pub async fn call_tool( &mut self, name: &str, arguments: Value, ) -> Result<ToolResult>
Call a tool on the server.
Sourcepub async fn shutdown(&mut self) -> Result<()>
pub async fn shutdown(&mut self) -> Result<()>
Shutdown the MCP server.
Always succeeds: a dead or unresponsive server must never block cleanup.
Sourcepub fn capabilities(&self) -> Option<&ServerCapabilities>
pub fn capabilities(&self) -> Option<&ServerCapabilities>
Get the server capabilities (available after connect).
Sourcepub fn protocol_version(&self) -> Option<&str>
pub fn protocol_version(&self) -> Option<&str>
The protocol revision agreed with the server (available after connect).
Sourcepub fn cached_tools(&self) -> &[ToolMetadata]
pub fn cached_tools(&self) -> &[ToolMetadata]
Get the cached tool list.