pub struct ElicitationRequest { /* private fields */ }Expand description
Ergonomic wrapper around protocol ElicitRequest with request ID
This type wraps the protocol-level ElicitRequest and adds the request ID
from the JSON-RPC envelope. It provides ergonomic accessors while preserving
full type safety from the protocol layer.
§Design Philosophy
Rather than duplicating protocol types, we wrap them. This ensures:
- Type safety is preserved (ElicitationSchema stays typed!)
- No data loss (Duration instead of lossy integer seconds)
- Single source of truth (protocol crate defines MCP types)
- Automatic sync (protocol changes propagate automatically)
§Examples
use turbomcp_client::handlers::ElicitationRequest;
async fn handle(request: ElicitationRequest) {
// Access request ID
println!("ID: {:?}", request.id());
// Access message
println!("Message: {}", request.message());
// Access typed schema (not Value!)
for (name, property) in &request.schema().properties {
println!("Field: {}", name);
}
// Access timeout as Duration
if let Some(timeout) = request.timeout() {
println!("Timeout: {:?}", timeout);
}
}Implementations§
Source§impl ElicitationRequest
impl ElicitationRequest
Sourcepub fn new(id: MessageId, request: ElicitRequest) -> Self
pub fn new(id: MessageId, request: ElicitRequest) -> Self
Create a new elicitation request wrapper
§Arguments
id- Request ID from JSON-RPC enveloperequest- Protocol-level elicit request
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Get human-readable message for the user
This is the primary prompt/question being asked of the user.
Sourcepub fn schema(&self) -> &ElicitationSchema
pub fn schema(&self) -> &ElicitationSchema
Get schema defining expected response structure
Returns the typed ElicitationSchema which provides:
- Type-safe access to properties
- Required field information
- Validation constraints
§Note
This returns a TYPED schema, not serde_json::Value.
You can inspect the schema structure type-safely:
for (name, definition) in &request.schema().properties {
match definition {
PrimitiveSchemaDefinition::String { description, .. } => {
println!("String field: {}", name);
}
PrimitiveSchemaDefinition::Number { minimum, maximum, .. } => {
println!("Number field: {} ({:?}-{:?})", name, minimum, maximum);
}
_ => {}
}
}Sourcepub fn timeout(&self) -> Option<Duration>
pub fn timeout(&self) -> Option<Duration>
Get optional timeout as Duration
Converts milliseconds from the protocol to ergonomic Duration type.
No data loss occurs (unlike converting to integer seconds).
Sourcepub fn is_cancellable(&self) -> bool
pub fn is_cancellable(&self) -> bool
Check if request can be cancelled by the user
Sourcepub fn as_protocol(&self) -> &ElicitRequest
pub fn as_protocol(&self) -> &ElicitRequest
Get access to underlying protocol request if needed
For advanced use cases where you need the raw protocol type.
Sourcepub fn into_protocol(self) -> ElicitRequest
pub fn into_protocol(self) -> ElicitRequest
Consume wrapper and return protocol request
Trait Implementations§
Source§impl Clone for ElicitationRequest
impl Clone for ElicitationRequest
Source§fn clone(&self) -> ElicitationRequest
fn clone(&self) -> ElicitationRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more