rust_mcp_schema/generated_schema/2025_06_18/
validators.rs1pub fn const_str_validator<'de, D>(
18 struct_name: &'static str,
19 field_name: &'static str,
20 expected: &'static str,
21 deserializer: D,
22) -> Result<String, D::Error>
23where
24 D: serde::de::Deserializer<'de>,
25{
26 let value: String = serde::Deserialize::deserialize(deserializer)?;
27 if value == expected {
28 Ok(value)
29 } else {
30 Err(serde::de::Error::custom(format!(
31 "Expected field `{field_name}` in struct `{struct_name}` as const value '{expected}', but got '{value}'",
32 )))
33 }
34}
35
36macro_rules! validate {
52 ($func_name:ident, $struct:expr, $field:expr, $expected:expr $(,)?) => {
53 pub(crate) fn $func_name<'de, D>(deserializer: D) -> Result<String, D::Error>
54 where
55 D: serde::de::Deserializer<'de>,
56 {
57 const_str_validator($struct, $field, $expected, deserializer)
58 }
59 };
60}
61
62validate!(audio_content_type_, "AudioContent", "type_", "audio");
64validate!(boolean_schema_type_, "BooleanSchema", "type_", "boolean");
65validate!(call_tool_request_method, "CallToolRequest", "method", "tools/call");
66validate!(
67 cancelled_notification_method,
68 "CancelledNotification",
69 "method",
70 "notifications/cancelled"
71);
72validate!(complete_request_method, "CompleteRequest", "method", "completion/complete");
73validate!(
74 create_message_request_method,
75 "CreateMessageRequest",
76 "method",
77 "sampling/createMessage"
78);
79validate!(elicit_request_method, "ElicitRequest", "method", "elicitation/create");
80validate!(elicit_requested_schema_type_, "ElicitRequestedSchema", "type_", "object");
81validate!(embedded_resource_type_, "EmbeddedResource", "type_", "resource");
82validate!(enum_schema_type_, "EnumSchema", "type_", "string");
83validate!(get_prompt_request_method, "GetPromptRequest", "method", "prompts/get");
84validate!(image_content_type_, "ImageContent", "type_", "image");
85validate!(initialize_request_method, "InitializeRequest", "method", "initialize");
86validate!(
87 initialized_notification_method,
88 "InitializedNotification",
89 "method",
90 "notifications/initialized"
91);
92validate!(jsonrpc_error_jsonrpc, "JsonrpcError", "jsonrpc", "2.0");
93validate!(jsonrpc_notification_jsonrpc, "JsonrpcNotification", "jsonrpc", "2.0");
94validate!(jsonrpc_request_jsonrpc, "JsonrpcRequest", "jsonrpc", "2.0");
95validate!(jsonrpc_response_jsonrpc, "JsonrpcResponse", "jsonrpc", "2.0");
96validate!(list_prompts_request_method, "ListPromptsRequest", "method", "prompts/list");
97validate!(
98 list_resource_templates_request_method,
99 "ListResourceTemplatesRequest",
100 "method",
101 "resources/templates/list"
102);
103validate!(
104 list_resources_request_method,
105 "ListResourcesRequest",
106 "method",
107 "resources/list"
108);
109validate!(list_roots_request_method, "ListRootsRequest", "method", "roots/list");
110validate!(list_tools_request_method, "ListToolsRequest", "method", "tools/list");
111validate!(
112 logging_message_notification_method,
113 "LoggingMessageNotification",
114 "method",
115 "notifications/message"
116);
117validate!(ping_request_method, "PingRequest", "method", "ping");
118validate!(
119 progress_notification_method,
120 "ProgressNotification",
121 "method",
122 "notifications/progress"
123);
124validate!(
125 prompt_list_changed_notification_method,
126 "PromptListChangedNotification",
127 "method",
128 "notifications/prompts/list_changed"
129);
130validate!(prompt_reference_type_, "PromptReference", "type_", "ref/prompt");
131validate!(
132 read_resource_request_method,
133 "ReadResourceRequest",
134 "method",
135 "resources/read"
136);
137validate!(resource_link_type_, "ResourceLink", "type_", "resource_link");
138validate!(
139 resource_list_changed_notification_method,
140 "ResourceListChangedNotification",
141 "method",
142 "notifications/resources/list_changed"
143);
144validate!(
145 resource_template_reference_type_,
146 "ResourceTemplateReference",
147 "type_",
148 "ref/resource"
149);
150validate!(
151 resource_updated_notification_method,
152 "ResourceUpdatedNotification",
153 "method",
154 "notifications/resources/updated"
155);
156validate!(
157 roots_list_changed_notification_method,
158 "RootsListChangedNotification",
159 "method",
160 "notifications/roots/list_changed"
161);
162validate!(set_level_request_method, "SetLevelRequest", "method", "logging/setLevel");
163validate!(string_schema_type_, "StringSchema", "type_", "string");
164validate!(subscribe_request_method, "SubscribeRequest", "method", "resources/subscribe");
165validate!(text_content_type_, "TextContent", "type_", "text");
166validate!(tool_input_schema_type_, "ToolInputSchema", "type_", "object");
167validate!(
168 tool_list_changed_notification_method,
169 "ToolListChangedNotification",
170 "method",
171 "notifications/tools/list_changed"
172);
173validate!(tool_output_schema_type_, "ToolOutputSchema", "type_", "object");
174validate!(
175 unsubscribe_request_method,
176 "UnsubscribeRequest",
177 "method",
178 "resources/unsubscribe"
179);