Skip to content

Commit 5b81b64

Browse files
authored
feat: added method value validation and more strickt restriction on const values (#91)
* feat: update schema with strict const validations * chore: add validators and tests * clippy fix * chore: update tests to support draft version * chore: typo
1 parent 83ad262 commit 5b81b64

File tree

16 files changed

+2179
-190
lines changed

16 files changed

+2179
-190
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143

144144
### Bug Fixes
145145

146-
* custom result deserialization conflic with rust_mcp_schema::Result ([#44](https://github.com/rust-mcp-stack/rust-mcp-schema/issues/44)) ([f141060](https://github.com/rust-mcp-stack/rust-mcp-schema/commit/f14106047ee6fdc499f0915ea2029954cf06d634))
146+
* custom result deserialization conflict with rust_mcp_schema::Result ([#44](https://github.com/rust-mcp-stack/rust-mcp-schema/issues/44)) ([f141060](https://github.com/rust-mcp-stack/rust-mcp-schema/commit/f14106047ee6fdc499f0915ea2029954cf06d634))
147147

148148
## [0.1.9](https://github.com/rust-mcp-stack/rust-mcp-schema/compare/v0.1.8...v0.1.9) (2025-03-02)
149149

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Multiple schema versions may be enabled concurrently if needed. Non-default vers
8686
- rust_mcp_schema::mcp_2024_11_05
8787
- rust_mcp_schema::mcp_draft"
8888

89-
Example: enable `2024_11_05` version of the shema:
89+
Example: enable `2024_11_05` version of the schema:
9090

9191
<!-- x-release-please-start-version -->
9292

@@ -95,7 +95,7 @@ Example: enable `2024_11_05` version of the shema:
9595
rust-mcp-schema = { version: 0.7.4 , default-features = false, features=["2024_11_05"] }
9696
```
9797

98-
Example: enable `draft`` version of the shema (2024_11_05) :
98+
Example: enable `draft`` version of the schema (2024_11_05) :
9999

100100
```toml
101101
#Cargo.toml

src/generated_schema.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ macro_rules! define_schema_version {
44
$mod_name:ident,
55
$schema_path:literal,
66
$utils_path:literal,
7+
$validators_path:literal,
78
$schema_mod:ident,
89
$utils_mod:ident
910
) => {
@@ -15,6 +16,9 @@ macro_rules! define_schema_version {
1516
#[path = $utils_path]
1617
mod $utils_mod;
1718

19+
#[path = $validators_path]
20+
mod validators;
21+
1822
#[cfg(feature = $feature)]
1923
pub mod $mod_name {
2024
pub use super::$schema_mod::*;
@@ -37,6 +41,7 @@ define_schema_version!(
3741
mcp_2025_06_18,
3842
"generated_schema/2025_06_18/mcp_schema.rs",
3943
"generated_schema/2025_06_18/schema_utils.rs",
44+
"generated_schema/2025_06_18/validators.rs",
4045
__int_2025_06_18,
4146
__int_utils_2025_06_18
4247
);
@@ -47,6 +52,7 @@ define_schema_version!(
4752
mcp_2025_03_26,
4853
"generated_schema/2025_03_26/mcp_schema.rs",
4954
"generated_schema/2025_03_26/schema_utils.rs",
55+
"generated_schema/2025_03_26/validators.rs",
5056
__int_2025_03_26,
5157
__int_utils_2025_03_26
5258
);
@@ -57,6 +63,7 @@ define_schema_version!(
5763
mcp_2024_11_05,
5864
"generated_schema/2024_11_05/mcp_schema.rs",
5965
"generated_schema/2024_11_05/schema_utils.rs",
66+
"generated_schema/2024_11_05/validators.rs",
6067
__int_2024_11_05,
6168
__int_utils_2024_11_05
6269
);
@@ -67,6 +74,7 @@ define_schema_version!(
6774
mcp_draft,
6875
"generated_schema/draft/mcp_schema.rs",
6976
"generated_schema/draft/schema_utils.rs",
77+
"generated_schema/draft/validators.rs",
7078
__int_draft,
7179
__int_utils_draft
7280
);

src/generated_schema/2024_11_05/mcp_schema.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/// ----------------------------------------------------------------------------
2-
/// This file is auto-generated by mcp-schema-gen v0.4.2.
2+
/// This file is auto-generated by mcp-schema-gen v0.4.4.
33
/// WARNING:
44
/// It is not recommended to modify this file directly. You are free to
55
/// modify or extend the implementations as needed, but please do so at your own risk.
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
8-
/// Hash : 3473e6e72b222f44163b41eab8d4b0973ac106b6
9-
/// Generated at : 2025-09-17 19:15:48
8+
/// Hash : 71204c22f8e062795dca00a87d31070033572ba2
9+
/// Generated at : 2025-10-03 15:17:01
1010
/// ----------------------------------------------------------------------------
1111
///
12+
use super::validators as validate;
1213
/// MCP Protocol Version
1314
pub const LATEST_PROTOCOL_VERSION: &str = "2024-11-05";
1415
/// JSON-RPC Version
@@ -171,6 +172,7 @@ pub struct BlobResourceContents {
171172
/// </details>
172173
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
173174
pub struct CallToolRequest {
175+
#[serde(deserialize_with = "validate::call_tool_request_method")]
174176
method: ::std::string::String,
175177
pub params: CallToolRequestParams,
176178
}
@@ -359,6 +361,7 @@ A client MUST NOT attempt to cancel its initialize request.*/
359361
/// </details>
360362
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
361363
pub struct CancelledNotification {
364+
#[serde(deserialize_with = "validate::cancelled_notification_method")]
362365
method: ::std::string::String,
363366
pub params: CancelledNotificationParams,
364367
}
@@ -766,6 +769,7 @@ impl ::std::convert::From<Result> for ClientResult {
766769
/// </details>
767770
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
768771
pub struct CompleteRequest {
772+
#[serde(deserialize_with = "validate::complete_request_method")]
769773
method: ::std::string::String,
770774
pub params: CompleteRequestParams,
771775
}
@@ -1063,6 +1067,7 @@ pub struct CompleteResultCompletion {
10631067
/// </details>
10641068
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
10651069
pub struct CreateMessageRequest {
1070+
#[serde(deserialize_with = "validate::create_message_request_method")]
10661071
method: ::std::string::String,
10671072
pub params: CreateMessageRequestParams,
10681073
}
@@ -1358,7 +1363,7 @@ pub struct EmbeddedResource {
13581363
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
13591364
pub annotations: ::std::option::Option<EmbeddedResourceAnnotations>,
13601365
pub resource: EmbeddedResourceResource,
1361-
#[serde(rename = "type")]
1366+
#[serde(rename = "type", deserialize_with = "validate::embedded_resource_type_")]
13621367
type_: ::std::string::String,
13631368
}
13641369
impl EmbeddedResource {
@@ -1498,6 +1503,7 @@ pub struct EmptyResult(pub Result);
14981503
/// </details>
14991504
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
15001505
pub struct GetPromptRequest {
1506+
#[serde(deserialize_with = "validate::get_prompt_request_method")]
15011507
method: ::std::string::String,
15021508
pub params: GetPromptRequestParams,
15031509
}
@@ -1648,7 +1654,7 @@ pub struct ImageContent {
16481654
///The MIME type of the image. Different providers may support different image types.
16491655
#[serde(rename = "mimeType")]
16501656
pub mime_type: ::std::string::String,
1651-
#[serde(rename = "type")]
1657+
#[serde(rename = "type", deserialize_with = "validate::image_content_type_")]
16521658
type_: ::std::string::String,
16531659
}
16541660
impl ImageContent {
@@ -1776,6 +1782,7 @@ pub struct Implementation {
17761782
/// </details>
17771783
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
17781784
pub struct InitializeRequest {
1785+
#[serde(deserialize_with = "validate::initialize_request_method")]
17791786
method: ::std::string::String,
17801787
pub params: InitializeRequestParams,
17811788
}
@@ -1915,6 +1922,7 @@ pub struct InitializeResult {
19151922
/// </details>
19161923
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
19171924
pub struct InitializedNotification {
1925+
#[serde(deserialize_with = "validate::initialized_notification_method")]
19181926
method: ::std::string::String,
19191927
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
19201928
pub params: ::std::option::Option<InitializedNotificationParams>,
@@ -2008,6 +2016,7 @@ pub struct InitializedNotificationParams {
20082016
pub struct JsonrpcError {
20092017
pub error: RpcError,
20102018
pub id: RequestId,
2019+
#[serde(deserialize_with = "validate::jsonrpc_error_jsonrpc")]
20112020
jsonrpc: ::std::string::String,
20122021
}
20132022
impl JsonrpcError {
@@ -2110,6 +2119,7 @@ impl ::std::convert::From<JsonrpcError> for JsonrpcMessage {
21102119
/// </details>
21112120
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
21122121
pub struct JsonrpcNotification {
2122+
#[serde(deserialize_with = "validate::jsonrpc_notification_jsonrpc")]
21132123
jsonrpc: ::std::string::String,
21142124
pub method: ::std::string::String,
21152125
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
@@ -2199,6 +2209,7 @@ pub struct JsonrpcNotificationParams {
21992209
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
22002210
pub struct JsonrpcRequest {
22012211
pub id: RequestId,
2212+
#[serde(deserialize_with = "validate::jsonrpc_request_jsonrpc")]
22022213
jsonrpc: ::std::string::String,
22032214
pub method: ::std::string::String,
22042215
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
@@ -2299,6 +2310,7 @@ pub struct JsonrpcRequestParamsMeta {
22992310
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
23002311
pub struct JsonrpcResponse {
23012312
pub id: RequestId,
2313+
#[serde(deserialize_with = "validate::jsonrpc_response_jsonrpc")]
23022314
jsonrpc: ::std::string::String,
23032315
pub result: Result,
23042316
}
@@ -2345,6 +2357,7 @@ impl JsonrpcResponse {
23452357
/// </details>
23462358
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
23472359
pub struct ListPromptsRequest {
2360+
#[serde(deserialize_with = "validate::list_prompts_request_method")]
23482361
method: ::std::string::String,
23492362
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
23502363
pub params: ::std::option::Option<ListPromptsRequestParams>,
@@ -2459,6 +2472,7 @@ pub struct ListPromptsResult {
24592472
/// </details>
24602473
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
24612474
pub struct ListResourceTemplatesRequest {
2475+
#[serde(deserialize_with = "validate::list_resource_templates_request_method")]
24622476
method: ::std::string::String,
24632477
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
24642478
pub params: ::std::option::Option<ListResourceTemplatesRequestParams>,
@@ -2574,6 +2588,7 @@ pub struct ListResourceTemplatesResult {
25742588
/// </details>
25752589
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
25762590
pub struct ListResourcesRequest {
2591+
#[serde(deserialize_with = "validate::list_resources_request_method")]
25772592
method: ::std::string::String,
25782593
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
25792594
pub params: ::std::option::Option<ListResourcesRequestParams>,
@@ -2699,6 +2714,7 @@ structure or access specific locations that the client has permission to read fr
26992714
/// </details>
27002715
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
27012716
pub struct ListRootsRequest {
2717+
#[serde(deserialize_with = "validate::list_roots_request_method")]
27022718
method: ::std::string::String,
27032719
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
27042720
pub params: ::std::option::Option<ListRootsRequestParams>,
@@ -2835,6 +2851,7 @@ pub struct ListRootsResult {
28352851
/// </details>
28362852
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
28372853
pub struct ListToolsRequest {
2854+
#[serde(deserialize_with = "validate::list_tools_request_method")]
28382855
method: ::std::string::String,
28392856
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
28402857
pub params: ::std::option::Option<ListToolsRequestParams>,
@@ -3017,6 +3034,7 @@ impl ::std::fmt::Display for LoggingLevel {
30173034
/// </details>
30183035
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
30193036
pub struct LoggingMessageNotification {
3037+
#[serde(deserialize_with = "validate::logging_message_notification_method")]
30203038
method: ::std::string::String,
30213039
pub params: LoggingMessageNotificationParams,
30223040
}
@@ -3353,6 +3371,7 @@ pub struct PaginatedResult {
33533371
/// </details>
33543372
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
33553373
pub struct PingRequest {
3374+
#[serde(deserialize_with = "validate::ping_request_method")]
33563375
method: ::std::string::String,
33573376
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
33583377
pub params: ::std::option::Option<PingRequestParams>,
@@ -3466,6 +3485,7 @@ pub struct PingRequestParamsMeta {
34663485
/// </details>
34673486
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
34683487
pub struct ProgressNotification {
3488+
#[serde(deserialize_with = "validate::progress_notification_method")]
34693489
method: ::std::string::String,
34703490
pub params: ProgressNotificationParams,
34713491
}
@@ -3659,6 +3679,7 @@ pub struct PromptArgument {
36593679
/// </details>
36603680
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
36613681
pub struct PromptListChangedNotification {
3682+
#[serde(deserialize_with = "validate::prompt_list_changed_notification_method")]
36623683
method: ::std::string::String,
36633684
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
36643685
pub params: ::std::option::Option<PromptListChangedNotificationParams>,
@@ -3814,7 +3835,7 @@ impl ::std::convert::From<EmbeddedResource> for PromptMessageContent {
38143835
pub struct PromptReference {
38153836
///The name of the prompt or prompt template
38163837
pub name: ::std::string::String,
3817-
#[serde(rename = "type")]
3838+
#[serde(rename = "type", deserialize_with = "validate::prompt_reference_type_")]
38183839
type_: ::std::string::String,
38193840
}
38203841
impl PromptReference {
@@ -3867,6 +3888,7 @@ impl PromptReference {
38673888
/// </details>
38683889
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
38693890
pub struct ReadResourceRequest {
3891+
#[serde(deserialize_with = "validate::read_resource_request_method")]
38703892
method: ::std::string::String,
38713893
pub params: ReadResourceRequestParams,
38723894
}
@@ -4275,6 +4297,7 @@ pub struct ResourceContents {
42754297
/// </details>
42764298
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
42774299
pub struct ResourceListChangedNotification {
4300+
#[serde(deserialize_with = "validate::resource_list_changed_notification_method")]
42784301
method: ::std::string::String,
42794302
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
42804303
pub params: ::std::option::Option<ResourceListChangedNotificationParams>,
@@ -4347,7 +4370,7 @@ pub struct ResourceListChangedNotificationParams {
43474370
/// </details>
43484371
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
43494372
pub struct ResourceReference {
4350-
#[serde(rename = "type")]
4373+
#[serde(rename = "type", deserialize_with = "validate::resource_reference_type_")]
43514374
type_: ::std::string::String,
43524375
///The URI or URI template of the resource.
43534376
pub uri: ::std::string::String,
@@ -4506,6 +4529,7 @@ pub struct ResourceTemplateAnnotations {
45064529
/// </details>
45074530
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
45084531
pub struct ResourceUpdatedNotification {
4532+
#[serde(deserialize_with = "validate::resource_updated_notification_method")]
45094533
method: ::std::string::String,
45104534
pub params: ResourceUpdatedNotificationParams,
45114535
}
@@ -4676,6 +4700,7 @@ The server should then request an updated list of roots using the ListRootsReque
46764700
/// </details>
46774701
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
46784702
pub struct RootsListChangedNotification {
4703+
#[serde(deserialize_with = "validate::roots_list_changed_notification_method")]
46794704
method: ::std::string::String,
46804705
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
46814706
pub params: ::std::option::Option<RootsListChangedNotificationParams>,
@@ -5078,6 +5103,7 @@ impl ::std::convert::From<LoggingMessageNotification> for ServerNotification {
50785103
/// </details>
50795104
#[derive(::serde::Serialize, Clone, Debug)]
50805105
#[serde(untagged)]
5106+
#[allow(clippy::large_enum_variant)]
50815107
pub enum ServerRequest {
50825108
PingRequest(PingRequest),
50835109
CreateMessageRequest(CreateMessageRequest),
@@ -5141,6 +5167,7 @@ impl ::std::convert::From<ListRootsRequest> for ServerRequest {
51415167
/// </details>
51425168
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
51435169
#[serde(untagged)]
5170+
#[allow(clippy::large_enum_variant)]
51445171
pub enum ServerResult {
51455172
InitializeResult(InitializeResult),
51465173
ListResourcesResult(ListResourcesResult),
@@ -5238,6 +5265,7 @@ impl ::std::convert::From<Result> for ServerResult {
52385265
/// </details>
52395266
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
52405267
pub struct SetLevelRequest {
5268+
#[serde(deserialize_with = "validate::set_level_request_method")]
52415269
method: ::std::string::String,
52425270
pub params: SetLevelRequestParams,
52435271
}
@@ -5315,6 +5343,7 @@ pub struct SetLevelRequestParams {
53155343
/// </details>
53165344
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
53175345
pub struct SubscribeRequest {
5346+
#[serde(deserialize_with = "validate::subscribe_request_method")]
53185347
method: ::std::string::String,
53195348
pub params: SubscribeRequestParams,
53205349
}
@@ -5406,7 +5435,7 @@ pub struct TextContent {
54065435
pub annotations: ::std::option::Option<TextContentAnnotations>,
54075436
///The text content of the message.
54085437
pub text: ::std::string::String,
5409-
#[serde(rename = "type")]
5438+
#[serde(rename = "type", deserialize_with = "validate::text_content_type_")]
54105439
type_: ::std::string::String,
54115440
}
54125441
impl TextContent {
@@ -5599,7 +5628,7 @@ pub struct ToolInputSchema {
55995628
>,
56005629
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
56015630
pub required: ::std::vec::Vec<::std::string::String>,
5602-
#[serde(rename = "type")]
5631+
#[serde(rename = "type", deserialize_with = "validate::tool_input_schema_type_")]
56035632
type_: ::std::string::String,
56045633
}
56055634
impl ToolInputSchema {
@@ -5658,6 +5687,7 @@ impl ToolInputSchema {
56585687
/// </details>
56595688
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
56605689
pub struct ToolListChangedNotification {
5690+
#[serde(deserialize_with = "validate::tool_list_changed_notification_method")]
56615691
method: ::std::string::String,
56625692
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
56635693
pub params: ::std::option::Option<ToolListChangedNotificationParams>,
@@ -5738,6 +5768,7 @@ pub struct ToolListChangedNotificationParams {
57385768
/// </details>
57395769
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
57405770
pub struct UnsubscribeRequest {
5771+
#[serde(deserialize_with = "validate::unsubscribe_request_method")]
57415772
method: ::std::string::String,
57425773
pub params: UnsubscribeRequestParams,
57435774
}

0 commit comments

Comments
 (0)