feat: add default value support to string, number, and integer schemas (#686)

This commit is contained in:
Dale Seo 2026-02-26 10:02:11 -05:00 committed by GitHub
parent 6c336a90c1
commit 93bfb4ac6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 79 additions and 0 deletions

View file

@ -113,6 +113,10 @@ pub struct StringSchema {
/// String format - limited to: "email", "uri", "date", "date-time"
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<StringFormat>,
/// Default value
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<String>,
}
impl Default for StringSchema {
@ -124,6 +128,7 @@ impl Default for StringSchema {
min_length: None,
max_length: None,
format: None,
default: None,
}
}
}
@ -213,6 +218,12 @@ impl StringSchema {
self.format = Some(format);
self
}
/// Set default value
pub fn with_default(mut self, default: impl Into<String>) -> Self {
self.default = Some(default.into());
self
}
}
// =============================================================================
@ -246,6 +257,10 @@ pub struct NumberSchema {
/// Maximum value (inclusive)
#[serde(skip_serializing_if = "Option::is_none")]
pub maximum: Option<f64>,
/// Default value
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<f64>,
}
impl Default for NumberSchema {
@ -256,6 +271,7 @@ impl Default for NumberSchema {
description: None,
minimum: None,
maximum: None,
default: None,
}
}
}
@ -307,6 +323,12 @@ impl NumberSchema {
self.description = Some(description.into());
self
}
/// Set default value
pub fn with_default(mut self, default: f64) -> Self {
self.default = Some(default);
self
}
}
// =============================================================================
@ -340,6 +362,10 @@ pub struct IntegerSchema {
/// Maximum value (inclusive)
#[serde(skip_serializing_if = "Option::is_none")]
pub maximum: Option<i64>,
/// Default value
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<i64>,
}
impl Default for IntegerSchema {
@ -350,6 +376,7 @@ impl Default for IntegerSchema {
description: None,
minimum: None,
maximum: None,
default: None,
}
}
}
@ -401,6 +428,12 @@ impl IntegerSchema {
self.description = Some(description.into());
self
}
/// Set default value
pub fn with_default(mut self, default: i64) -> Self {
self.default = Some(default);
self
}
}
// =============================================================================

View file

@ -1186,6 +1186,14 @@
"description": "Schema definition for integer properties.\n\nCompliant with MCP 2025-06-18 specification for elicitation schemas.\nSupports only the fields allowed by the MCP spec.",
"type": "object",
"properties": {
"default": {
"description": "Default value",
"type": [
"integer",
"null"
],
"format": "int64"
},
"description": {
"description": "Human-readable description",
"type": [
@ -1763,6 +1771,14 @@
"description": "Schema definition for number properties (floating-point).\n\nCompliant with MCP 2025-06-18 specification for elicitation schemas.\nSupports only the fields allowed by the MCP spec.",
"type": "object",
"properties": {
"default": {
"description": "Default value",
"type": [
"number",
"null"
],
"format": "double"
},
"description": {
"description": "Human-readable description",
"type": [
@ -2869,6 +2885,13 @@
"description": "Schema definition for string properties.\n\nCompliant with MCP 2025-06-18 specification for elicitation schemas.\nSupports only the fields allowed by the MCP spec:\n- format limited to: \"email\", \"uri\", \"date\", \"date-time\"",
"type": "object",
"properties": {
"default": {
"description": "Default value",
"type": [
"string",
"null"
]
},
"description": {
"description": "Human-readable description",
"type": [

View file

@ -1186,6 +1186,14 @@
"description": "Schema definition for integer properties.\n\nCompliant with MCP 2025-06-18 specification for elicitation schemas.\nSupports only the fields allowed by the MCP spec.",
"type": "object",
"properties": {
"default": {
"description": "Default value",
"type": [
"integer",
"null"
],
"format": "int64"
},
"description": {
"description": "Human-readable description",
"type": [
@ -1763,6 +1771,14 @@
"description": "Schema definition for number properties (floating-point).\n\nCompliant with MCP 2025-06-18 specification for elicitation schemas.\nSupports only the fields allowed by the MCP spec.",
"type": "object",
"properties": {
"default": {
"description": "Default value",
"type": [
"number",
"null"
],
"format": "double"
},
"description": {
"description": "Human-readable description",
"type": [
@ -2869,6 +2885,13 @@
"description": "Schema definition for string properties.\n\nCompliant with MCP 2025-06-18 specification for elicitation schemas.\nSupports only the fields allowed by the MCP spec:\n- format limited to: \"email\", \"uri\", \"date\", \"date-time\"",
"type": "object",
"properties": {
"default": {
"description": "Default value",
"type": [
"string",
"null"
]
},
"description": {
"description": "Human-readable description",
"type": [