Skip to main content

ElicitFormSchema

Struct ElicitFormSchema 

Source
pub struct ElicitFormSchema {
    pub schema_type: String,
    pub properties: HashMap<String, PrimitiveSchemaDefinition>,
    pub required: Vec<String>,
}
Expand description

Restricted JSON Schema for elicitation forms.

Based on JSON Schema 2020-12, but restricted to a flat object with primitive-typed properties. Complex types (arrays, nested objects) are not supported – only string, integer, number, boolean, and enum fields.

The schema is validated by the client before submitting the form response. Required fields must be present, and each value must match its declared type.

Use the builder methods to construct a schema with string, integer, number, boolean, and enum fields, optionally with default values.

§Example

use tower_mcp_types::protocol::ElicitFormSchema;

let schema = ElicitFormSchema::new()
    .string_field("name", Some("Your full name"), true)
    .string_field_with_default("greeting", Some("How to greet"), false, "Hello")
    .integer_field("age", Some("Your age"), false)
    .enum_field(
        "role",
        Some("Select your role"),
        vec!["admin".into(), "user".into(), "guest".into()],
        true,
    )
    .enum_field_with_default(
        "theme",
        Some("Color theme"),
        false,
        &["light", "dark", "auto"],
        "auto",
    )
    .boolean_field("subscribe", Some("Subscribe to updates"), false);

assert_eq!(schema.required, vec!["name", "role"]);
assert_eq!(schema.properties.len(), 6);

Fields§

§schema_type: String

Must be “object”

§properties: HashMap<String, PrimitiveSchemaDefinition>

Map of property names to their schema definitions

§required: Vec<String>

List of required property names

Implementations§

Source§

impl ElicitFormSchema

Source

pub fn new() -> ElicitFormSchema

Create a new form schema

Source

pub fn string_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema

Add a string field

Source

pub fn string_field_with_default( self, name: &str, description: Option<&str>, required: bool, default: &str, ) -> ElicitFormSchema

Add a string field with a default value

Source

pub fn integer_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema

Add an integer field

Source

pub fn integer_field_with_default( self, name: &str, description: Option<&str>, required: bool, default: i64, ) -> ElicitFormSchema

Add an integer field with a default value

Source

pub fn number_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema

Add a number field

Source

pub fn number_field_with_default( self, name: &str, description: Option<&str>, required: bool, default: f64, ) -> ElicitFormSchema

Add a number field with a default value

Source

pub fn boolean_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema

Add a boolean field

Source

pub fn boolean_field_with_default( self, name: &str, description: Option<&str>, required: bool, default: bool, ) -> ElicitFormSchema

Add a boolean field with a default value

Source

pub fn enum_field( self, name: &str, description: Option<&str>, options: Vec<String>, required: bool, ) -> ElicitFormSchema

Add a single-select enum field

Source

pub fn enum_field_with_default( self, name: &str, description: Option<&str>, required: bool, options: &[&str], default: &str, ) -> ElicitFormSchema

Add a single-select enum field with a default value

Source

pub fn raw_field( self, name: &str, schema: Value, required: bool, ) -> ElicitFormSchema

Add a raw JSON schema field

Use this for advanced schema features not covered by the typed builders.

Trait Implementations§

Source§

impl Clone for ElicitFormSchema

Source§

fn clone(&self) -> ElicitFormSchema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ElicitFormSchema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for ElicitFormSchema

Source§

fn default() -> ElicitFormSchema

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ElicitFormSchema

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ElicitFormSchema, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ElicitFormSchema

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,