#[non_exhaustive]pub struct ElicitationSchema {
pub schema: Option<Cow<'static, str>>,
pub type_: ObjectTypeConst,
pub title: Option<Cow<'static, str>>,
pub properties: BTreeMap<String, PrimitiveSchemaDefinition>,
pub property_order: Option<Vec<String>>,
pub required: Option<Vec<String>>,
pub description: Option<Cow<'static, str>>,
}Expand description
Type-safe elicitation schema for requesting structured user input.
This enforces the MCP 2025-06-18 specification that elicitation schemas must be objects with primitive-typed properties.
§Example
use rmcp::model::*;
let schema = ElicitationSchema::builder()
.required_email("email")
.required_integer("age", 0, 150)
.optional_bool("newsletter", false)
.build();Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.schema: Option<Cow<'static, str>>Optional JSON Schema dialect identifier (the $schema keyword).
The 2025-11-25 protocol revision allows a requestedSchema to declare its
dialect. It is preserved verbatim so a declared dialect survives a
decode/re-encode round-trip instead of being silently dropped.
type_: ObjectTypeConstAlways “object” for elicitation schemas
title: Option<Cow<'static, str>>Optional title for the schema
properties: BTreeMap<String, PrimitiveSchemaDefinition>Property definitions (must be primitive types)
property_order: Option<Vec<String>>Property names in wire order. Schemas constructed from a BTreeMap
use the map’s sorted key order.
required: Option<Vec<String>>List of required property names
description: Option<Cow<'static, str>>Optional description of what this schema represents
Implementations§
Source§impl ElicitationSchema
impl ElicitationSchema
Sourcepub fn new(properties: BTreeMap<String, PrimitiveSchemaDefinition>) -> Self
pub fn new(properties: BTreeMap<String, PrimitiveSchemaDefinition>) -> Self
Create a new elicitation schema with the given properties
Sourcepub fn from_json_schema(schema: JsonObject) -> Result<Self, Error>
pub fn from_json_schema(schema: JsonObject) -> Result<Self, Error>
Convert from a JSON Schema object (typically generated by schemars)
This allows converting from JsonObject to ElicitationSchema, which is useful when working with automatically generated schemas from types.
§Example
use rmcp::model::*;
let json_schema = schema_for_type::<MyType>();
let elicitation_schema = ElicitationSchema::from_json_schema(json_schema)?;§Errors
Returns a serde_json::Error if the JSON object cannot be deserialized
into a valid ElicitationSchema.
Sourcepub fn from_type<T>() -> Result<Self, Error>where
T: JsonSchema,
Available on crate feature schemars only.
pub fn from_type<T>() -> Result<Self, Error>where
T: JsonSchema,
schemars only.Generate an ElicitationSchema from a Rust type that implements JsonSchema
This is a convenience method that combines schema generation and conversion. It uses the same schema generation settings as the rest of the MCP SDK.
§Example
use rmcp::model::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(JsonSchema, Serialize, Deserialize)]
struct UserInput {
name: String,
age: u32,
}
let schema = ElicitationSchema::from_type::<UserInput>()?;§Errors
Returns a serde_json::Error if the generated schema cannot be converted
to a valid ElicitationSchema.
Sourcepub fn with_required(self, required: Vec<String>) -> Self
pub fn with_required(self, required: Vec<String>) -> Self
Set the required fields
Sourcepub fn with_title(self, title: impl Into<Cow<'static, str>>) -> Self
pub fn with_title(self, title: impl Into<Cow<'static, str>>) -> Self
Set the title
Sourcepub fn with_description(self, description: impl Into<Cow<'static, str>>) -> Self
pub fn with_description(self, description: impl Into<Cow<'static, str>>) -> Self
Set the description
Sourcepub fn with_schema(self, schema: impl Into<Cow<'static, str>>) -> Self
pub fn with_schema(self, schema: impl Into<Cow<'static, str>>) -> Self
Set the JSON Schema dialect identifier (the $schema keyword).
Sourcepub fn builder() -> ElicitationSchemaBuilder
pub fn builder() -> ElicitationSchemaBuilder
Create a builder for constructing elicitation schemas fluently
Trait Implementations§
Source§impl Clone for ElicitationSchema
impl Clone for ElicitationSchema
Source§impl Debug for ElicitationSchema
impl Debug for ElicitationSchema
Source§impl<'de> Deserialize<'de> for ElicitationSchema
impl<'de> Deserialize<'de> for ElicitationSchema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for ElicitationSchema
Available on crate feature schemars only.
impl JsonSchema for ElicitationSchema
schemars only.Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more