Skip to main content

ClientHandler

Trait ClientHandler 

Source
pub trait ClientHandler:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn handle_create_message<'life0, 'async_trait>(
        &'life0 self,
        _params: CreateMessageParams,
    ) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, JsonRpcError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn handle_elicit<'life0, 'async_trait>(
        &'life0 self,
        _params: ElicitRequestParams,
    ) -> Pin<Box<dyn Future<Output = Result<ElicitResult, JsonRpcError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn handle_list_roots<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<ListRootsResult, JsonRpcError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_notification<'life0, 'async_trait>(
        &'life0 self,
        _notification: ServerNotification,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Handler for server-initiated requests and notifications.

Implement this trait to handle sampling requests, elicitation requests, roots listing, and server notifications. All methods have default implementations that either return sensible defaults or reject with method_not_found.

The unit type () implements this trait with all defaults, which is used by McpClient::connect().

Provided Methods§

Source

fn handle_create_message<'life0, 'async_trait>( &'life0 self, _params: CreateMessageParams, ) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, JsonRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a sampling/createMessage request from the server.

The server is asking the client to perform LLM inference. Override this to forward the request to your LLM provider.

Default: returns method_not_found error.

Source

fn handle_elicit<'life0, 'async_trait>( &'life0 self, _params: ElicitRequestParams, ) -> Pin<Box<dyn Future<Output = Result<ElicitResult, JsonRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle an elicitation/create request from the server.

The server is asking the client for user input (form data or URL).

Default: returns method_not_found error.

Source

fn handle_list_roots<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<ListRootsResult, JsonRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a roots/list request from the server.

The server is asking which filesystem roots the client has access to. If roots were configured on the McpClient via the builder, those are returned automatically before this method is called.

Default: returns an empty list.

Source

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

Called when the server sends a notification.

Override to handle progress updates, log messages, resource changes, etc.

Default: no-op.

Implementations on Foreign Types§

Source§

impl ClientHandler for ()

Unit type implements ClientHandler with all defaults.

Implementors§