pub trait ElicitationHandler: Send + Sync {
// Required method
fn elicit(
&self,
request: ElicitRequest,
ctx: &Context<'_>,
) -> impl Future<Output = Result<ElicitResult, McpError>> + Send;
}Expand description
Handler for elicitation requests (structured user input).
Implement this trait to allow the server to request structured input from the user through the client. This enables interactive workflows where servers can gather user preferences, confirmations, or data.
§Example
ⓘ
use mcpkit_server::{ElicitationHandler, Context};
use mcpkit_core::types::elicitation::{ElicitRequest, ElicitResult};
use mcpkit_core::error::McpError;
struct MyServer;
impl ElicitationHandler for MyServer {
async fn elicit(
&self,
request: ElicitRequest,
ctx: &Context<'_>,
) -> Result<ElicitResult, McpError> {
// The client will display the request to the user
ctx.peer().elicit(request).await
}
}§Use Cases
- Requesting user confirmation before destructive operations
- Gathering user preferences or configuration
- Prompting for credentials or sensitive information
- Interactive wizards or multi-step forms
Required Methods§
Sourcefn elicit(
&self,
request: ElicitRequest,
ctx: &Context<'_>,
) -> impl Future<Output = Result<ElicitResult, McpError>> + Send
fn elicit( &self, request: ElicitRequest, ctx: &Context<'_>, ) -> impl Future<Output = Result<ElicitResult, McpError>> + Send
Request structured input from the user.
This allows the server to gather information from the user through the client interface. The client will present the request to the user according to the specified schema and return their response.
§Arguments
request- The elicitation request specifying the message and schema.ctx- The request context providing access to the peer connection.
§Returns
The result of the elicitation, including the user’s action (accept, decline, or cancel) and any provided content.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.