ElicitationHandler

Trait ElicitationHandler 

Source
pub trait ElicitationHandler:
    Send
    + Sync
    + Debug {
    // Required method
    fn handle_elicitation<'life0, 'async_trait>(
        &'life0 self,
        request: ElicitationRequest,
    ) -> Pin<Box<dyn Future<Output = HandlerResult<ElicitationResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Handler for server-initiated elicitation requests

Elicitation is a mechanism where servers can request user input during operations. For example, a server might need user preferences, authentication credentials, or configuration choices to complete a task.

Implementations should:

  • Present the schema/prompt to the user in an appropriate UI
  • Validate user input against the provided schema
  • Handle user cancellation gracefully
  • Respect timeout constraints

§Examples

use turbomcp_client::handlers::{ElicitationAction, ElicitationHandler, ElicitationRequest, ElicitationResponse, HandlerResult};
use async_trait::async_trait;
use serde_json::json;

#[derive(Debug)]
struct CLIElicitationHandler;

#[async_trait]
impl ElicitationHandler for CLIElicitationHandler {
    async fn handle_elicitation(
        &self,
        request: ElicitationRequest,
    ) -> HandlerResult<ElicitationResponse> {
        println!("Server request: {}", request.prompt);
         
        // In a real implementation, you would:
        // 1. Parse the schema to understand what input is needed
        // 2. Present an appropriate UI (CLI prompts, GUI forms, etc.)
        // 3. Validate the user's input against the schema
        // 4. Return the structured response
         
        Ok(ElicitationResponse {
            action: ElicitationAction::Accept,
            content: Some(json!({ "user_choice": "example_value" })),
        })
    }
}

Required Methods§

Source

fn handle_elicitation<'life0, 'async_trait>( &'life0 self, request: ElicitationRequest, ) -> Pin<Box<dyn Future<Output = HandlerResult<ElicitationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle an elicitation request from the server

This method is called when a server needs user input. The implementation should present the request to the user and collect their response.

§Arguments
  • request - The elicitation request containing prompt, schema, and metadata
§Returns

Returns the user’s response or an error if the operation failed.

Implementors§