pub struct McpClient { /* private fields */ }
Expand description
Main MCP client implementation
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub fn new(name: String, version: String) -> Self
pub fn new(name: String, version: String) -> Self
Create a new MCP client with the given name and version
Sourcepub fn with_config(name: String, version: String, config: ClientConfig) -> Self
pub fn with_config(name: String, version: String, config: ClientConfig) -> Self
Create a new MCP client with custom configuration
Sourcepub fn set_capabilities(&mut self, capabilities: ClientCapabilities)
pub fn set_capabilities(&mut self, capabilities: ClientCapabilities)
Set client capabilities
Sourcepub fn info(&self) -> &ClientInfo
pub fn info(&self) -> &ClientInfo
Get client information
Sourcepub fn capabilities(&self) -> &ClientCapabilities
pub fn capabilities(&self) -> &ClientCapabilities
Get client capabilities
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Get client configuration
Sourcepub async fn server_capabilities(&self) -> Option<ServerCapabilities>
pub async fn server_capabilities(&self) -> Option<ServerCapabilities>
Get server capabilities (if connected)
Sourcepub async fn server_info(&self) -> Option<ServerInfo>
pub async fn server_info(&self) -> Option<ServerInfo>
Get server information (if connected)
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if the client is connected
Sourcepub async fn connect<T>(&mut self, transport: T) -> McpResult<InitializeResult>where
T: Transport + 'static,
pub async fn connect<T>(&mut self, transport: T) -> McpResult<InitializeResult>where
T: Transport + 'static,
Connect to an MCP server using the provided transport
Sourcepub async fn disconnect(&self) -> McpResult<()>
pub async fn disconnect(&self) -> McpResult<()>
Disconnect from the server
Sourcepub async fn list_tools(
&self,
cursor: Option<String>,
) -> McpResult<ListToolsResult>
pub async fn list_tools( &self, cursor: Option<String>, ) -> McpResult<ListToolsResult>
List available tools from the server
Sourcepub async fn call_tool(
&self,
name: String,
arguments: Option<HashMap<String, Value>>,
) -> McpResult<CallToolResult>
pub async fn call_tool( &self, name: String, arguments: Option<HashMap<String, Value>>, ) -> McpResult<CallToolResult>
Call a tool on the server
Sourcepub async fn list_resources(
&self,
cursor: Option<String>,
) -> McpResult<ListResourcesResult>
pub async fn list_resources( &self, cursor: Option<String>, ) -> McpResult<ListResourcesResult>
List available resources from the server
Sourcepub async fn read_resource(&self, uri: String) -> McpResult<ReadResourceResult>
pub async fn read_resource(&self, uri: String) -> McpResult<ReadResourceResult>
Read a resource from the server
Sourcepub async fn subscribe_resource(
&self,
uri: String,
) -> McpResult<SubscribeResourceResult>
pub async fn subscribe_resource( &self, uri: String, ) -> McpResult<SubscribeResourceResult>
Subscribe to resource updates
Sourcepub async fn unsubscribe_resource(
&self,
uri: String,
) -> McpResult<UnsubscribeResourceResult>
pub async fn unsubscribe_resource( &self, uri: String, ) -> McpResult<UnsubscribeResourceResult>
Unsubscribe from resource updates
Sourcepub async fn list_prompts(
&self,
cursor: Option<String>,
) -> McpResult<ListPromptsResult>
pub async fn list_prompts( &self, cursor: Option<String>, ) -> McpResult<ListPromptsResult>
List available prompts from the server
Sourcepub async fn get_prompt(
&self,
name: String,
arguments: Option<HashMap<String, String>>,
) -> McpResult<GetPromptResult>
pub async fn get_prompt( &self, name: String, arguments: Option<HashMap<String, String>>, ) -> McpResult<GetPromptResult>
Get a prompt from the server
Sourcepub async fn create_message(
&self,
params: CreateMessageParams,
) -> McpResult<CreateMessageResult>
pub async fn create_message( &self, params: CreateMessageParams, ) -> McpResult<CreateMessageResult>
Create a message using server-side sampling
Sourcepub async fn ping(&self) -> McpResult<PingResult>
pub async fn ping(&self) -> McpResult<PingResult>
Send a ping to the server
Sourcepub async fn set_logging_level(
&self,
level: LoggingLevel,
) -> McpResult<SetLoggingLevelResult>
pub async fn set_logging_level( &self, level: LoggingLevel, ) -> McpResult<SetLoggingLevelResult>
Set the logging level on the server
Sourcepub async fn receive_notification(
&self,
) -> McpResult<Option<JsonRpcNotification>>
pub async fn receive_notification( &self, ) -> McpResult<Option<JsonRpcNotification>>
Receive notifications from the server