Trait McpClient

Source
pub trait McpClient: Sync + Send {
Show 39 methods // Required methods fn start<'async_trait>( self: Arc<Self>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait; fn set_server_details( &self, server_details: InitializeResult, ) -> SdkResult<()>; fn shut_down<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn is_shut_down<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn sender<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = &RwLock<Option<MessageDispatcher<ServerMessage>>>> + Send + 'async_trait>> where MessageDispatcher<ServerMessage>: McpDispatch<ServerMessage, MessageFromClient>, Self: 'async_trait, 'life0: 'async_trait; fn client_info(&self) -> &InitializeRequestParams; fn server_info(&self) -> Option<InitializeResult>; // Provided methods fn get_client_info(&self) -> &InitializeRequestParams { ... } fn get_server_info(&self) -> Option<InitializeResult> { ... } fn is_initialized(&self) -> bool { ... } fn server_version(&self) -> Option<Implementation> { ... } fn get_server_version(&self) -> Option<Implementation> { ... } fn server_capabilities(&self) -> Option<ServerCapabilities> { ... } fn get_server_capabilities(&self) -> Option<ServerCapabilities> { ... } fn server_has_tools(&self) -> Option<bool> { ... } fn server_has_prompts(&self) -> Option<bool> { ... } fn server_has_experimental(&self) -> Option<bool> { ... } fn server_has_resources(&self) -> Option<bool> { ... } fn server_supports_logging(&self) -> Option<bool> { ... } fn get_instructions(&self) -> Option<String> { ... } fn instructions(&self) -> Option<String> { ... } fn request<'life0, 'async_trait>( &'life0 self, request: RequestFromClient, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<ResultFromServer>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_notification<'life0, 'async_trait>( &'life0 self, notification: NotificationFromClient, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn ping<'life0, 'async_trait>( &'life0 self, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn complete<'life0, 'async_trait>( &'life0 self, params: CompleteRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<CompleteResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn set_logging_level<'life0, 'async_trait>( &'life0 self, level: LoggingLevel, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn get_prompt<'life0, 'async_trait>( &'life0 self, params: GetPromptRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<GetPromptResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn list_prompts<'life0, 'async_trait>( &'life0 self, params: Option<ListPromptsRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListPromptsResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn list_resources<'life0, 'async_trait>( &'life0 self, params: Option<ListResourcesRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListResourcesResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn list_resource_templates<'life0, 'async_trait>( &'life0 self, params: Option<ListResourceTemplatesRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListResourceTemplatesResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn read_resource<'life0, 'async_trait>( &'life0 self, params: ReadResourceRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<ReadResourceResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn subscribe_resource<'life0, 'async_trait>( &'life0 self, params: SubscribeRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn unsubscribe_resource<'life0, 'async_trait>( &'life0 self, params: UnsubscribeRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn call_tool<'life0, 'async_trait>( &'life0 self, params: CallToolRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<CallToolResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn list_tools<'life0, 'async_trait>( &'life0 self, params: Option<ListToolsRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListToolsResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_roots_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<RootsListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn assert_server_capabilities( &self, request_method: &String, ) -> SdkResult<()> { ... } fn assert_client_notification_capabilities( &self, notification_method: &String, ) -> Result<(), RpcError> { ... } fn assert_client_request_capabilities( &self, request_method: &String, ) -> Result<(), RpcError> { ... }
}

Required Methods§

Source

fn start<'async_trait>( self: Arc<Self>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Source

fn set_server_details(&self, server_details: InitializeResult) -> SdkResult<()>

Source

fn shut_down<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn is_shut_down<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn sender<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = &RwLock<Option<MessageDispatcher<ServerMessage>>>> + Send + 'async_trait>>
where MessageDispatcher<ServerMessage>: McpDispatch<ServerMessage, MessageFromClient>, Self: 'async_trait, 'life0: 'async_trait,

Source

fn client_info(&self) -> &InitializeRequestParams

Source

fn server_info(&self) -> Option<InitializeResult>

Provided Methods§

Source

fn get_client_info(&self) -> &InitializeRequestParams

👎Deprecated since 0.2.0: Use client_info() instead.
Source

fn get_server_info(&self) -> Option<InitializeResult>

👎Deprecated since 0.2.0: Use server_info() instead.
Source

fn is_initialized(&self) -> bool

Checks whether the server has been initialized with client

Source

fn server_version(&self) -> Option<Implementation>

Returns the server’s name and version information once initialization is complete. This method retrieves the server details, if available, after successful initialization.

Source

fn get_server_version(&self) -> Option<Implementation>

👎Deprecated since 0.2.0: Use server_version() instead.
Source

fn server_capabilities(&self) -> Option<ServerCapabilities>

Returns the server’s capabilities. After initialization has completed, this will be populated with the server’s reported capabilities.

Source

fn get_server_capabilities(&self) -> Option<ServerCapabilities>

👎Deprecated since 0.2.0: Use server_capabilities() instead.
Source

fn server_has_tools(&self) -> Option<bool>

Checks if the server has tools available.

This function retrieves the server information and checks if the server has tools listed in its capabilities. If the server info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if tools are available, or Some(false) if not.

§Returns
  • None if server information is not yet available.
  • Some(true) if tools are available on the server.
  • Some(false) if no tools are available on the server.
println!("{}",1);
Source

fn server_has_prompts(&self) -> Option<bool>

Checks if the server has prompts available.

This function retrieves the server information and checks if the server has prompts listed in its capabilities. If the server info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if prompts are available, or Some(false) if not.

§Returns
  • None if server information is not yet available.
  • Some(true) if prompts are available on the server.
  • Some(false) if no prompts are available on the server.
Source

fn server_has_experimental(&self) -> Option<bool>

Checks if the server has experimental capabilities available.

This function retrieves the server information and checks if the server has experimental listed in its capabilities. If the server info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if experimental is available, or Some(false) if not.

§Returns
  • None if server information is not yet available.
  • Some(true) if experimental capabilities are available on the server.
  • Some(false) if no experimental capabilities are available on the server.
Source

fn server_has_resources(&self) -> Option<bool>

Checks if the server has resources available.

This function retrieves the server information and checks if the server has resources listed in its capabilities. If the server info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if resources are available, or Some(false) if not.

§Returns
  • None if server information is not yet available.
  • Some(true) if resources are available on the server.
  • Some(false) if no resources are available on the server.
Source

fn server_supports_logging(&self) -> Option<bool>

Checks if the server supports logging.

This function retrieves the server information and checks if the server has logging capabilities listed. If the server info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if logging is supported, or Some(false) if not.

§Returns
  • None if server information is not yet available.
  • Some(true) if logging is supported by the server.
  • Some(false) if logging is not supported by the server.
Source

fn get_instructions(&self) -> Option<String>

👎Deprecated since 0.2.0: Use instructions() instead.
Source

fn instructions(&self) -> Option<String>

Source

fn request<'life0, 'async_trait>( &'life0 self, request: RequestFromClient, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<ResultFromServer>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a request to the server and processes the response.

This function sends a RequestFromClient message to the server, waits for the response, and handles the result. If the response is empty or of an invalid type, an error is returned. Otherwise, it returns the result from the server.

Source

fn send_notification<'life0, 'async_trait>( &'life0 self, notification: NotificationFromClient, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a notification. This is a one-way message that is not expected to return any response. The method asynchronously sends the notification using the transport layer and does not wait for any acknowledgement or result.

Source

fn ping<'life0, 'async_trait>( &'life0 self, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

A ping request to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.

This function creates a PingRequest with no specific parameters, sends the request and awaits the response Once the response is received, it attempts to convert it into the expected result type.

§Returns

A SdkResult containing the rust_mcp_schema::Result if the request is successful. If the request or conversion fails, an error is returned.

Source

fn complete<'life0, 'async_trait>( &'life0 self, params: CompleteRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<CompleteResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn set_logging_level<'life0, 'async_trait>( &'life0 self, level: LoggingLevel, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn get_prompt<'life0, 'async_trait>( &'life0 self, params: GetPromptRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<GetPromptResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn list_prompts<'life0, 'async_trait>( &'life0 self, params: Option<ListPromptsRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListPromptsResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn list_resources<'life0, 'async_trait>( &'life0 self, params: Option<ListResourcesRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListResourcesResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn list_resource_templates<'life0, 'async_trait>( &'life0 self, params: Option<ListResourceTemplatesRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListResourceTemplatesResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn read_resource<'life0, 'async_trait>( &'life0 self, params: ReadResourceRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<ReadResourceResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn subscribe_resource<'life0, 'async_trait>( &'life0 self, params: SubscribeRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn unsubscribe_resource<'life0, 'async_trait>( &'life0 self, params: UnsubscribeRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn call_tool<'life0, 'async_trait>( &'life0 self, params: CallToolRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<CallToolResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn list_tools<'life0, 'async_trait>( &'life0 self, params: Option<ListToolsRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListToolsResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn send_roots_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<RootsListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn assert_server_capabilities(&self, request_method: &String) -> SdkResult<()>

Asserts that server capabilities support the requested method.

Verifies that the server has the necessary capabilities to handle the given request method. If the server is not initialized or lacks a required capability, an error is returned. This can be utilized to avoid sending requests when the opposing party lacks support for them.

Source

fn assert_client_notification_capabilities( &self, notification_method: &String, ) -> Result<(), RpcError>

Source

fn assert_client_request_capabilities( &self, request_method: &String, ) -> Result<(), RpcError>

Implementors§