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: StringMust 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
impl ElicitFormSchema
Sourcepub fn new() -> ElicitFormSchema
pub fn new() -> ElicitFormSchema
Create a new form schema
Sourcepub fn string_field(
self,
name: &str,
description: Option<&str>,
required: bool,
) -> ElicitFormSchema
pub fn string_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema
Add a string field
Sourcepub fn string_field_with_default(
self,
name: &str,
description: Option<&str>,
required: bool,
default: &str,
) -> ElicitFormSchema
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
Sourcepub fn integer_field(
self,
name: &str,
description: Option<&str>,
required: bool,
) -> ElicitFormSchema
pub fn integer_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema
Add an integer field
Sourcepub fn integer_field_with_default(
self,
name: &str,
description: Option<&str>,
required: bool,
default: i64,
) -> ElicitFormSchema
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
Sourcepub fn number_field(
self,
name: &str,
description: Option<&str>,
required: bool,
) -> ElicitFormSchema
pub fn number_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema
Add a number field
Sourcepub fn number_field_with_default(
self,
name: &str,
description: Option<&str>,
required: bool,
default: f64,
) -> ElicitFormSchema
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
Sourcepub fn boolean_field(
self,
name: &str,
description: Option<&str>,
required: bool,
) -> ElicitFormSchema
pub fn boolean_field( self, name: &str, description: Option<&str>, required: bool, ) -> ElicitFormSchema
Add a boolean field
Sourcepub fn boolean_field_with_default(
self,
name: &str,
description: Option<&str>,
required: bool,
default: bool,
) -> ElicitFormSchema
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
Sourcepub fn enum_field(
self,
name: &str,
description: Option<&str>,
options: Vec<String>,
required: bool,
) -> ElicitFormSchema
pub fn enum_field( self, name: &str, description: Option<&str>, options: Vec<String>, required: bool, ) -> ElicitFormSchema
Add a single-select enum field
Sourcepub fn enum_field_with_default(
self,
name: &str,
description: Option<&str>,
required: bool,
options: &[&str],
default: &str,
) -> ElicitFormSchema
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
Trait Implementations§
Source§impl Clone for ElicitFormSchema
impl Clone for ElicitFormSchema
Source§fn clone(&self) -> ElicitFormSchema
fn clone(&self) -> ElicitFormSchema
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more