SamplingHandler

Trait SamplingHandler 

Source
pub trait SamplingHandler:
    Send
    + Sync
    + Debug {
    // Required method
    fn handle_create_message<'life0, 'async_trait>(
        &'life0 self,
        request: CreateMessageRequest,
    ) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

MCP-compliant sampling handler trait

The client receives sampling requests and delegates to configured LLM services. This maintains perfect separation of concerns per MCP specification.

Required Methods§

Source

fn handle_create_message<'life0, 'async_trait>( &'life0 self, request: CreateMessageRequest, ) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a sampling/createMessage request from a server

This method should:

  1. Present the request to the user for approval
  2. Delegate to an external LLM service (could be another MCP server)
  3. Present the result to the user for review
  4. Return the approved result

Implementors§

Source§

impl SamplingHandler for LLMRegistry

Implement SamplingHandler for LLMRegistry

Source§

impl SamplingHandler for DelegatingSamplingHandler