pub struct McpClient<T: ClientTransport> { /* private fields */ }Expand description
MCP Client for connecting to MCP servers
Provides a high-level API for interacting with MCP servers, handling request/response correlation and protocol details.
Implementations§
Source§impl<T: ClientTransport + 'static> McpClient<T>
impl<T: ClientTransport + 'static> McpClient<T>
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the default request timeout
Sourcepub fn with_client_info(self, name: &str, version: &str) -> Self
pub fn with_client_info(self, name: &str, version: &str) -> Self
Set the client info for initialization
Sourcepub fn server_info(&self) -> Option<&InitializeResult>
pub fn server_info(&self) -> Option<&InitializeResult>
Get the server info (available after initialization)
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if the client has been initialized
Sourcepub async fn initialize(
&mut self,
client_name: &str,
client_version: &str,
) -> ClientResult<InitializeResult>
pub async fn initialize( &mut self, client_name: &str, client_version: &str, ) -> ClientResult<InitializeResult>
Initialize the connection with the server
This must be called before any other methods.
Sourcepub async fn list_tools(&self) -> ClientResult<ListToolsResult>
pub async fn list_tools(&self) -> ClientResult<ListToolsResult>
List available tools from the server
Sourcepub async fn list_all_tools(&self) -> ClientResult<Vec<Tool>>
pub async fn list_all_tools(&self) -> ClientResult<Vec<Tool>>
List all tools, automatically handling pagination
Sourcepub async fn call_tool(
&self,
name: &str,
arguments: Value,
) -> ClientResult<CallToolResult>
pub async fn call_tool( &self, name: &str, arguments: Value, ) -> ClientResult<CallToolResult>
Call a tool on the server
Sourcepub async fn list_resources(&self) -> ClientResult<ListResourcesResult>
pub async fn list_resources(&self) -> ClientResult<ListResourcesResult>
List available resources from the server
Sourcepub async fn list_all_resources(&self) -> ClientResult<Vec<Resource>>
pub async fn list_all_resources(&self) -> ClientResult<Vec<Resource>>
List all resources, automatically handling pagination
Sourcepub async fn read_resource(&self, uri: &str) -> ClientResult<ReadResourceResult>
pub async fn read_resource(&self, uri: &str) -> ClientResult<ReadResourceResult>
Read a resource from the server
Sourcepub async fn list_resource_templates(
&self,
) -> ClientResult<ListResourceTemplatesResult>
pub async fn list_resource_templates( &self, ) -> ClientResult<ListResourceTemplatesResult>
List resource templates from the server
Sourcepub async fn list_prompts(&self) -> ClientResult<ListPromptsResult>
pub async fn list_prompts(&self) -> ClientResult<ListPromptsResult>
List available prompts from the server
Sourcepub async fn list_all_prompts(&self) -> ClientResult<Vec<Prompt>>
pub async fn list_all_prompts(&self) -> ClientResult<Vec<Prompt>>
List all prompts, automatically handling pagination
Sourcepub async fn get_prompt(
&self,
name: &str,
arguments: Option<HashMap<String, String>>,
) -> ClientResult<GetPromptResult>
pub async fn get_prompt( &self, name: &str, arguments: Option<HashMap<String, String>>, ) -> ClientResult<GetPromptResult>
Get a prompt by name
Sourcepub async fn complete(
&self,
params: CompleteRequestParam,
) -> ClientResult<CompleteResult>
pub async fn complete( &self, params: CompleteRequestParam, ) -> ClientResult<CompleteResult>
Request completion suggestions
Sourcepub async fn ping(&self) -> ClientResult<()>
pub async fn ping(&self) -> ClientResult<()>
Send a ping to the server
Sourcepub async fn close(&self) -> ClientResult<()>
pub async fn close(&self) -> ClientResult<()>
Close the client connection
Sourcepub async fn notify_progress(
&self,
progress_token: &str,
progress: f64,
total: Option<f64>,
) -> ClientResult<()>
pub async fn notify_progress( &self, progress_token: &str, progress: f64, total: Option<f64>, ) -> ClientResult<()>
Send a progress notification
Sourcepub async fn notify_cancelled(
&self,
request_id: &str,
reason: Option<&str>,
) -> ClientResult<()>
pub async fn notify_cancelled( &self, request_id: &str, reason: Option<&str>, ) -> ClientResult<()>
Send a cancellation notification
Sourcepub async fn notify_roots_list_changed(&self) -> ClientResult<()>
pub async fn notify_roots_list_changed(&self) -> ClientResult<()>
Send a roots list changed notification