pub struct ElicitationSchema {
pub type_: ObjectTypeConst,
pub title: Option<Cow<'static, str>>,
pub properties: BTreeMap<String, PrimitiveSchema>,
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§
§type_: ObjectTypeConstAlways “object” for elicitation schemas
title: Option<Cow<'static, str>>Optional title for the schema
properties: BTreeMap<String, PrimitiveSchema>Property definitions (must be primitive types)
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, PrimitiveSchema>) -> ElicitationSchema
pub fn new(properties: BTreeMap<String, PrimitiveSchema>) -> 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 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 · 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 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 more