Skip to main content

ClientRequestHandler

Trait ClientRequestHandler 

Source
pub trait ClientRequestHandler: Send + Sync {
    // Required methods
    fn handle_create_message<'life0, 'async_trait>(
        &'life0 self,
        params: CreateMessageParams,
    ) -> Pin<Box<dyn Future<Output = McpResult<CreateMessageResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn handle_list_roots<'life0, 'async_trait>(
        &'life0 self,
        params: ListRootsParams,
    ) -> Pin<Box<dyn Future<Output = McpResult<ListRootsResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn handle_elicit<'life0, 'async_trait>(
        &'life0 self,
        params: ElicitParams,
    ) -> Pin<Box<dyn Future<Output = McpResult<ElicitResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn handle_ping<'life0, 'async_trait>(
        &'life0 self,
        params: PingParams,
    ) -> Pin<Box<dyn Future<Output = McpResult<PingResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for handling server-initiated requests

Trait defines the interface for processing requests that the MCP server sends to the client. Each method corresponds to a specific MCP method that servers can invoke on clients for bidirectional communication.

Required Methods§

Source

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

Handle sampling/createMessage request from the server

Method is called when the server wants the client to generate a message using an LLM (Large Language Model). This enables the server to leverage the client’s AI capabilities.

§Arguments
  • params - Parameters for message creation including conversation context
§Returns

Result containing the generated message or an error

Source

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

Handle roots/list request from the server

Method is called when the server wants to know what root directories or file system areas the client has access to. This is used for file system integration and resource discovery.

§Arguments
  • params - Parameters for root listing (typically empty)
§Returns

Result containing available roots or an error

Source

fn handle_elicit<'life0, 'async_trait>( &'life0 self, params: ElicitParams, ) -> Pin<Box<dyn Future<Output = McpResult<ElicitResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle elicitation/create request from the server

Method is called when the server wants to collect structured input from the user through a form-like interface. This enables interactive workflows where the server needs user confirmation or additional data.

§Arguments
  • params - Parameters defining the form schema and message
§Returns

Result containing user’s response (accept/decline/cancel) and form data

Source

fn handle_ping<'life0, 'async_trait>( &'life0 self, params: PingParams, ) -> Pin<Box<dyn Future<Output = McpResult<PingResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle ping request from the server

Method is called when the server wants to test connectivity or measure latency to the client.

§Arguments
  • params - Ping parameters (typically empty)
§Returns

Result containing ping response or an error

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§