pub struct McpClient<T: ClientTransport> { /* private fields */ }Expand description
MCP Client for connecting to MCP servers
Implementations§
Source§impl<T: ClientTransport> McpClient<T>
impl<T: ClientTransport> McpClient<T>
Sourcepub fn with_roots(transport: T, roots: Vec<Root>) -> Self
pub fn with_roots(transport: T, roots: Vec<Root>) -> Self
Create a new MCP client with roots capability
The client will declare roots support during initialization.
Sourcepub fn with_capabilities(transport: T, capabilities: ClientCapabilities) -> Self
pub fn with_capabilities(transport: T, capabilities: ClientCapabilities) -> Self
Create a new MCP client with custom capabilities
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 is initialized
Sourcepub async fn set_roots(&mut self, roots: Vec<Root>) -> Result<()>
pub async fn set_roots(&mut self, roots: Vec<Root>) -> Result<()>
Set roots and notify the server if initialized
If the client is already initialized, sends a roots list changed notification.
Sourcepub async fn add_root(&mut self, root: Root) -> Result<()>
pub async fn add_root(&mut self, root: Root) -> Result<()>
Add a root and notify the server if initialized
Sourcepub async fn remove_root(&mut self, uri: &str) -> Result<bool>
pub async fn remove_root(&mut self, uri: &str) -> Result<bool>
Remove a root by URI and notify the server if initialized
Sourcepub fn list_roots(&self) -> ListRootsResult
pub fn list_roots(&self) -> ListRootsResult
Get the roots list result (for responding to server’s roots/list request)
Returns a result suitable for responding to a roots/list request from the server.
Sourcepub async fn initialize(
&mut self,
client_name: &str,
client_version: &str,
) -> Result<&InitializeResult>
pub async fn initialize( &mut self, client_name: &str, client_version: &str, ) -> Result<&InitializeResult>
Initialize the MCP connection
Sourcepub async fn list_tools(&mut self) -> Result<ListToolsResult>
pub async fn list_tools(&mut self) -> Result<ListToolsResult>
List available tools
Sourcepub async fn call_tool(
&mut self,
name: &str,
arguments: Value,
) -> Result<CallToolResult>
pub async fn call_tool( &mut self, name: &str, arguments: Value, ) -> Result<CallToolResult>
Call a tool
Sourcepub async fn list_resources(&mut self) -> Result<ListResourcesResult>
pub async fn list_resources(&mut self) -> Result<ListResourcesResult>
List available resources
Sourcepub async fn read_resource(&mut self, uri: &str) -> Result<ReadResourceResult>
pub async fn read_resource(&mut self, uri: &str) -> Result<ReadResourceResult>
Read a resource
Sourcepub async fn list_prompts(&mut self) -> Result<ListPromptsResult>
pub async fn list_prompts(&mut self) -> Result<ListPromptsResult>
List available prompts
Sourcepub async fn get_prompt(
&mut self,
name: &str,
arguments: Option<HashMap<String, String>>,
) -> Result<GetPromptResult>
pub async fn get_prompt( &mut self, name: &str, arguments: Option<HashMap<String, String>>, ) -> Result<GetPromptResult>
Get a prompt
Sourcepub async fn complete(
&mut self,
reference: CompletionReference,
argument_name: &str,
argument_value: &str,
) -> Result<CompleteResult>
pub async fn complete( &mut self, reference: CompletionReference, argument_name: &str, argument_value: &str, ) -> Result<CompleteResult>
Request completion suggestions from the server
This is used to get autocomplete suggestions for prompt arguments or resource URIs.
Sourcepub async fn complete_prompt_arg(
&mut self,
prompt_name: &str,
argument_name: &str,
argument_value: &str,
) -> Result<CompleteResult>
pub async fn complete_prompt_arg( &mut self, prompt_name: &str, argument_name: &str, argument_value: &str, ) -> Result<CompleteResult>
Request completion for a prompt argument
Sourcepub async fn complete_resource_uri(
&mut self,
resource_uri: &str,
argument_name: &str,
argument_value: &str,
) -> Result<CompleteResult>
pub async fn complete_resource_uri( &mut self, resource_uri: &str, argument_name: &str, argument_value: &str, ) -> Result<CompleteResult>
Request completion for a resource URI