pub struct McpClient { /* private fields */ }Expand description
MCP Client for connecting to external servers
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub async fn connect_subprocess(
command: &str,
args: &[&str],
) -> Result<Arc<Self>>
pub async fn connect_subprocess( command: &str, args: &[&str], ) -> Result<Arc<Self>>
Connect to an MCP server via subprocess
Sourcepub fn new(transport: Arc<dyn Transport>) -> Self
pub fn new(transport: Arc<dyn Transport>) -> Self
Create a new MCP client with custom transport
Sourcepub fn with_registry(
transport: Arc<dyn Transport>,
registry: Arc<McpRegistry>,
name: Option<String>,
) -> Self
pub fn with_registry( transport: Arc<dyn Transport>, registry: Arc<McpRegistry>, name: Option<String>, ) -> Self
Create a new MCP client with a shared registry for multi-server management
Sourcepub async fn initialize(&self) -> Result<InitializeResult>
pub async fn initialize(&self) -> Result<InitializeResult>
Initialize the connection with the server
Sourcepub fn registry(&self) -> Arc<McpRegistry>
pub fn registry(&self) -> Arc<McpRegistry>
Get the registry associated with this client
Sourcepub async fn server_name(&self) -> Option<String>
pub async fn server_name(&self) -> Option<String>
Get the server name if set
Sourcepub async fn set_server_name(&self, name: String)
pub async fn set_server_name(&self, name: String)
Set the server name for registry tracking
Sourcepub async fn has_capability(&self, capability: &str) -> bool
pub async fn has_capability(&self, capability: &str) -> bool
Check if the connected server has a specific capability
Sourcepub async fn capabilities(&self) -> Option<ServerCapabilities>
pub async fn capabilities(&self) -> Option<ServerCapabilities>
Get server capabilities
Sourcepub async fn discover_tools_from_registry(&self) -> Vec<(String, McpTool)>
pub async fn discover_tools_from_registry(&self) -> Vec<(String, McpTool)>
Discover tools from the registry across all connected servers
Sourcepub async fn find_tool_in_registry(
&self,
tool_name: &str,
) -> Option<(String, McpTool)>
pub async fn find_tool_in_registry( &self, tool_name: &str, ) -> Option<(String, McpTool)>
Find a tool across all servers in the registry
Sourcepub async fn refresh_tools(&self) -> Result<Vec<McpTool>>
pub async fn refresh_tools(&self) -> Result<Vec<McpTool>>
Refresh the list of available tools
Sourcepub async fn call_tool(
&self,
name: &str,
arguments: Value,
) -> Result<CallToolResult>
pub async fn call_tool( &self, name: &str, arguments: Value, ) -> Result<CallToolResult>
Call a tool
Sourcepub async fn list_resources(&self) -> Result<Vec<McpResource>>
pub async fn list_resources(&self) -> Result<Vec<McpResource>>
List available resources
Sourcepub async fn read_resource(&self, uri: &str) -> Result<ReadResourceResult>
pub async fn read_resource(&self, uri: &str) -> Result<ReadResourceResult>
Read a resource
Sourcepub async fn list_prompts(&self) -> Result<Vec<McpPrompt>>
pub async fn list_prompts(&self) -> Result<Vec<McpPrompt>>
List available prompts
Sourcepub async fn get_prompt(
&self,
name: &str,
arguments: Value,
) -> Result<GetPromptResult>
pub async fn get_prompt( &self, name: &str, arguments: Value, ) -> Result<GetPromptResult>
Get a prompt
Auto Trait Implementations§
impl !Freeze for McpClient
impl !RefUnwindSafe for McpClient
impl Send for McpClient
impl Sync for McpClient
impl Unpin for McpClient
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Apply a transformation to the response body. Read more
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using HTTP status codes. Read more
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using gRPC headers. Read more