#[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>,
) -> ElicitationSchema
pub fn new( properties: BTreeMap<String, PrimitiveSchemaDefinition>, ) -> ElicitationSchema
Create a new elicitation schema with the given properties
Sourcepub fn from_json_schema(
schema: Map<String, Value>,
) -> Result<ElicitationSchema, Error>
pub fn from_json_schema( schema: Map<String, Value>, ) -> Result<ElicitationSchema, 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<ElicitationSchema, Error>where
T: JsonSchema,
pub fn from_type<T>() -> Result<ElicitationSchema, Error>where
T: JsonSchema,
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>) -> ElicitationSchema
pub fn with_required(self, required: Vec<String>) -> ElicitationSchema
Set the required fields
Sourcepub fn with_title(
self,
title: impl Into<Cow<'static, str>>,
) -> ElicitationSchema
pub fn with_title( self, title: impl Into<Cow<'static, str>>, ) -> ElicitationSchema
Set the title
Sourcepub fn with_description(
self,
description: impl Into<Cow<'static, str>>,
) -> ElicitationSchema
pub fn with_description( self, description: impl Into<Cow<'static, str>>, ) -> ElicitationSchema
Set the description
Sourcepub fn with_schema(
self,
schema: impl Into<Cow<'static, str>>,
) -> ElicitationSchema
pub fn with_schema( self, schema: impl Into<Cow<'static, str>>, ) -> ElicitationSchema
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§fn clone(&self) -> ElicitationSchema
fn clone(&self) -> ElicitationSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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<ElicitationSchema, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ElicitationSchema, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<ElicitationSchemaWire> for ElicitationSchema
impl From<ElicitationSchemaWire> for ElicitationSchema
Source§fn from(schema: ElicitationSchemaWire) -> ElicitationSchema
fn from(schema: ElicitationSchemaWire) -> ElicitationSchema
Source§impl JsonSchema for ElicitationSchema
impl JsonSchema for ElicitationSchema
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 moreSource§impl PartialEq for ElicitationSchema
impl PartialEq for ElicitationSchema
Source§impl Serialize for ElicitationSchema
impl Serialize for ElicitationSchema
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ElicitationSchema
Auto Trait Implementations§
impl Freeze for ElicitationSchema
impl RefUnwindSafe for ElicitationSchema
impl Send for ElicitationSchema
impl Sync for ElicitationSchema
impl Unpin for ElicitationSchema
impl UnsafeUnpin for ElicitationSchema
impl UnwindSafe for ElicitationSchema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more