Skip to main content

ElicitationHandler

Trait ElicitationHandler 

Source
pub trait ElicitationHandler: Send + Sync {
    // Required methods
    fn handle_form_elicitation<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        message: &'life1 str,
        schema: &'life2 ElicitationSchema,
        metadata: Option<&'life3 Value>,
    ) -> Pin<Box<dyn Future<Output = Result<CreateElicitationResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn handle_url_elicitation<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        message: &'life1 str,
        url: &'life2 str,
        elicitation_id: &'life3 str,
        metadata: Option<&'life4 Value>,
    ) -> Pin<Box<dyn Future<Output = Result<CreateElicitationResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             Self: 'async_trait;
}
Available on crate feature tools only.
Expand description

Trait for handling MCP elicitation requests from servers.

Implement this trait to provide custom elicitation behavior when an MCP server requests additional information during tool execution.

§Example

use adk_tool::ElicitationHandler;
use rmcp::model::{CreateElicitationResult, ElicitationAction, ElicitationSchema};

struct MyHandler;

#[async_trait::async_trait]
impl ElicitationHandler for MyHandler {
    async fn handle_form_elicitation(
        &self,
        message: &str,
        schema: &ElicitationSchema,
        metadata: Option<&serde_json::Value>,
    ) -> Result<CreateElicitationResult, Box<dyn std::error::Error + Send + Sync>> {
        println!("Server asks: {message}");
        Ok(CreateElicitationResult::new(ElicitationAction::Accept))
    }

    async fn handle_url_elicitation(
        &self,
        message: &str,
        url: &str,
        elicitation_id: &str,
        metadata: Option<&serde_json::Value>,
    ) -> Result<CreateElicitationResult, Box<dyn std::error::Error + Send + Sync>> {
        println!("Server asks to visit: {url}");
        Ok(CreateElicitationResult::new(ElicitationAction::Accept))
    }
}

Required Methods§

Source

fn handle_form_elicitation<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, message: &'life1 str, schema: &'life2 ElicitationSchema, metadata: Option<&'life3 Value>, ) -> Pin<Box<dyn Future<Output = Result<CreateElicitationResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Handle a form-based elicitation request.

The server sends a human-readable message and a typed schema describing the data it needs. Return Accept with content matching the schema, Decline to refuse, or Cancel to abort the operation.

Source

fn handle_url_elicitation<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, message: &'life1 str, url: &'life2 str, elicitation_id: &'life3 str, metadata: Option<&'life4 Value>, ) -> Pin<Box<dyn Future<Output = Result<CreateElicitationResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, Self: 'async_trait,

Handle a URL-based elicitation request.

The server sends a URL for the user to visit and interact with externally. The elicitation_id uniquely identifies this request for the completion notification flow.

Implementors§