Skip to content

Commit 7e022b8

Browse files
committed
chore: change StringFormat to enum
1 parent 8fa6ad7 commit 7e022b8

File tree

3 files changed

+86
-13
lines changed

3 files changed

+86
-13
lines changed

crates/rmcp/src/model/elicitation_schema.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ pub enum PrimitiveSchema {
6161
// STRING SCHEMA
6262
// =============================================================================
6363

64+
/// String format types allowed by the MCP specification.
65+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
66+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
67+
#[serde(rename_all = "kebab-case")]
68+
pub enum StringFormat {
69+
/// Email address format
70+
Email,
71+
/// URI format
72+
Uri,
73+
/// Date format (YYYY-MM-DD)
74+
Date,
75+
/// Date-time format (ISO 8601)
76+
DateTime,
77+
}
78+
6479
/// Schema definition for string properties.
6580
///
6681
/// Compliant with MCP 2025-06-18 specification for elicitation schemas.
@@ -92,7 +107,7 @@ pub struct StringSchema {
92107

93108
/// String format - limited to: "email", "uri", "date", "date-time"
94109
#[serde(skip_serializing_if = "Option::is_none")]
95-
pub format: Option<Cow<'static, str>>,
110+
pub format: Option<StringFormat>,
96111
}
97112

98113
impl Default for StringSchema {
@@ -117,31 +132,31 @@ impl StringSchema {
117132
/// Create an email string schema
118133
pub fn email() -> Self {
119134
Self {
120-
format: Some(Cow::Borrowed("email")),
135+
format: Some(StringFormat::Email),
121136
..Default::default()
122137
}
123138
}
124139

125140
/// Create a URI string schema
126141
pub fn uri() -> Self {
127142
Self {
128-
format: Some(Cow::Borrowed("uri")),
143+
format: Some(StringFormat::Uri),
129144
..Default::default()
130145
}
131146
}
132147

133148
/// Create a date string schema
134149
pub fn date() -> Self {
135150
Self {
136-
format: Some(Cow::Borrowed("date")),
151+
format: Some(StringFormat::Date),
137152
..Default::default()
138153
}
139154
}
140155

141156
/// Create a date-time string schema
142157
pub fn date_time() -> Self {
143158
Self {
144-
format: Some(Cow::Borrowed("date-time")),
159+
format: Some(StringFormat::DateTime),
145160
..Default::default()
146161
}
147162
}
@@ -189,8 +204,8 @@ impl StringSchema {
189204
}
190205

191206
/// Set format (limited to: "email", "uri", "date", "date-time")
192-
pub fn format(mut self, format: impl Into<Cow<'static, str>>) -> Self {
193-
self.format = Some(format.into());
207+
pub fn format(mut self, format: StringFormat) -> Self {
208+
self.format = Some(format);
194209
self
195210
}
196211
}

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,31 @@
21982198
}
21992199
]
22002200
},
2201+
"StringFormat": {
2202+
"description": "String format types allowed by the MCP specification.",
2203+
"oneOf": [
2204+
{
2205+
"description": "Email address format",
2206+
"type": "string",
2207+
"const": "email"
2208+
},
2209+
{
2210+
"description": "URI format",
2211+
"type": "string",
2212+
"const": "uri"
2213+
},
2214+
{
2215+
"description": "Date format (YYYY-MM-DD)",
2216+
"type": "string",
2217+
"const": "date"
2218+
},
2219+
{
2220+
"description": "Date-time format (ISO 8601)",
2221+
"type": "string",
2222+
"const": "date-time"
2223+
}
2224+
]
2225+
},
22012226
"StringSchema": {
22022227
"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\"",
22032228
"type": "object",
@@ -2211,9 +2236,13 @@
22112236
},
22122237
"format": {
22132238
"description": "String format - limited to: \"email\", \"uri\", \"date\", \"date-time\"",
2214-
"type": [
2215-
"string",
2216-
"null"
2239+
"anyOf": [
2240+
{
2241+
"$ref": "#/definitions/StringFormat"
2242+
},
2243+
{
2244+
"type": "null"
2245+
}
22172246
]
22182247
},
22192248
"maxLength": {

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,31 @@
21982198
}
21992199
]
22002200
},
2201+
"StringFormat": {
2202+
"description": "String format types allowed by the MCP specification.",
2203+
"oneOf": [
2204+
{
2205+
"description": "Email address format",
2206+
"type": "string",
2207+
"const": "email"
2208+
},
2209+
{
2210+
"description": "URI format",
2211+
"type": "string",
2212+
"const": "uri"
2213+
},
2214+
{
2215+
"description": "Date format (YYYY-MM-DD)",
2216+
"type": "string",
2217+
"const": "date"
2218+
},
2219+
{
2220+
"description": "Date-time format (ISO 8601)",
2221+
"type": "string",
2222+
"const": "date-time"
2223+
}
2224+
]
2225+
},
22012226
"StringSchema": {
22022227
"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\"",
22032228
"type": "object",
@@ -2211,9 +2236,13 @@
22112236
},
22122237
"format": {
22132238
"description": "String format - limited to: \"email\", \"uri\", \"date\", \"date-time\"",
2214-
"type": [
2215-
"string",
2216-
"null"
2239+
"anyOf": [
2240+
{
2241+
"$ref": "#/definitions/StringFormat"
2242+
},
2243+
{
2244+
"type": "null"
2245+
}
22172246
]
22182247
},
22192248
"maxLength": {

0 commit comments

Comments
 (0)