pub trait ClientHandler: Send + Sync {
// Provided methods
fn create_message(
&self,
_request: CreateMessageRequest,
) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send { ... }
fn elicit(
&self,
_request: ElicitRequest,
) -> impl Future<Output = Result<ElicitResult, McpError>> + Send { ... }
fn list_roots(
&self,
) -> impl Future<Output = Result<Vec<Root>, McpError>> + Send { ... }
fn on_connected(&self) -> impl Future<Output = ()> + Send { ... }
fn on_disconnected(&self) -> impl Future<Output = ()> + Send { ... }
fn on_task_progress(
&self,
_task_id: TaskId,
_progress: TaskProgress,
) -> impl Future<Output = ()> + Send { ... }
fn on_resource_updated(
&self,
_uri: String,
) -> impl Future<Output = ()> + Send { ... }
fn on_resources_list_changed(&self) -> impl Future<Output = ()> + Send { ... }
fn on_tools_list_changed(&self) -> impl Future<Output = ()> + Send { ... }
fn on_prompts_list_changed(&self) -> impl Future<Output = ()> + Send { ... }
}Expand description
Handler trait for server-initiated requests.
Implement this trait to handle requests that servers send to clients. All methods have default implementations that return “not supported” errors.
§Example
use mcpkit_client::ClientHandler;
use mcpkit_core::types::{CreateMessageRequest, CreateMessageResult};
use mcpkit_core::error::McpError;
struct MyHandler;
impl ClientHandler for MyHandler {
// Override methods as needed to handle server requests
}Provided Methods§
Sourcefn create_message(
&self,
_request: CreateMessageRequest,
) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send
fn create_message( &self, _request: CreateMessageRequest, ) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send
Handle a sampling request from the server.
The server is asking the client’s LLM to generate a response. This is used for agentic workflows where the server needs LLM capabilities.
§Errors
Returns an error if sampling is not supported or the request fails.
Sourcefn elicit(
&self,
_request: ElicitRequest,
) -> impl Future<Output = Result<ElicitResult, McpError>> + Send
fn elicit( &self, _request: ElicitRequest, ) -> impl Future<Output = Result<ElicitResult, McpError>> + Send
Handle an elicitation request from the server.
The server is asking for user input. The client should present the request to the user and return their response.
§Errors
Returns an error if elicitation is not supported or the request fails.
Sourcefn list_roots(&self) -> impl Future<Output = Result<Vec<Root>, McpError>> + Send
fn list_roots(&self) -> impl Future<Output = Result<Vec<Root>, McpError>> + Send
List roots that the client exposes.
Roots are file system paths that the server can access. This is typically used for file-based operations.
§Errors
Returns an error if roots are not supported.
Sourcefn on_connected(&self) -> impl Future<Output = ()> + Send
fn on_connected(&self) -> impl Future<Output = ()> + Send
Called when the connection is established.
Override this to perform setup after initialization.
Sourcefn on_disconnected(&self) -> impl Future<Output = ()> + Send
fn on_disconnected(&self) -> impl Future<Output = ()> + Send
Called when the connection is closed.
Override this to perform cleanup.
Sourcefn on_task_progress(
&self,
_task_id: TaskId,
_progress: TaskProgress,
) -> impl Future<Output = ()> + Send
fn on_task_progress( &self, _task_id: TaskId, _progress: TaskProgress, ) -> impl Future<Output = ()> + Send
Called when a task makes progress.
Override this to track task progress updates from the server.
Sourcefn on_resource_updated(&self, _uri: String) -> impl Future<Output = ()> + Send
fn on_resource_updated(&self, _uri: String) -> impl Future<Output = ()> + Send
Called when a resource has been updated.
Override this to react to resource changes (requires subscription).
Sourcefn on_resources_list_changed(&self) -> impl Future<Output = ()> + Send
fn on_resources_list_changed(&self) -> impl Future<Output = ()> + Send
Called when the list of available resources has changed.
Override this to refresh your cached resource list.
Sourcefn on_tools_list_changed(&self) -> impl Future<Output = ()> + Send
fn on_tools_list_changed(&self) -> impl Future<Output = ()> + Send
Called when the list of available tools has changed.
Override this to refresh your cached tool list.
Sourcefn on_prompts_list_changed(&self) -> impl Future<Output = ()> + Send
fn on_prompts_list_changed(&self) -> impl Future<Output = ()> + Send
Called when the list of available prompts has changed.
Override this to refresh your cached prompt list.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.