Skip to content

Commit 32a68aa

Browse files
authored
fix(tasks): correct enum variant ordering for deserialization (#634)
Move CustomRequest and CustomResult to end of their respective untagged enums to ensure specific task variants match before catch-all custom types. Add deny_unknown_fields to GetTaskInfoResult to prevent matching arbitrary JSON objects. Fixes issue where tasks/get, tasks/list, tasks/result, and tasks/cancel incorrectly deserialized as CustomRequest instead of their typed variants.
1 parent d84573a commit 32a68aa

5 files changed

Lines changed: 21 additions & 18 deletions

File tree

crates/rmcp/src/model.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,7 @@ impl RequestParamsMeta for CancelTaskParams {
20452045
pub type CancelTaskParam = CancelTaskParams;
20462046
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
20472047
#[serde(rename_all = "camelCase")]
2048+
#[serde(deny_unknown_fields)]
20482049
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
20492050
pub struct GetTaskInfoResult {
20502051
#[serde(skip_serializing_if = "Option::is_none")]
@@ -2130,11 +2131,11 @@ ts_union!(
21302131
| UnsubscribeRequest
21312132
| CallToolRequest
21322133
| ListToolsRequest
2133-
| CustomRequest
21342134
| GetTaskInfoRequest
21352135
| ListTasksRequest
21362136
| GetTaskResultRequest
2137-
| CancelTaskRequest;
2137+
| CancelTaskRequest
2138+
| CustomRequest;
21382139
);
21392140

21402141
impl ClientRequest {
@@ -2153,11 +2154,11 @@ impl ClientRequest {
21532154
ClientRequest::UnsubscribeRequest(r) => r.method.as_str(),
21542155
ClientRequest::CallToolRequest(r) => r.method.as_str(),
21552156
ClientRequest::ListToolsRequest(r) => r.method.as_str(),
2156-
ClientRequest::CustomRequest(r) => r.method.as_str(),
21572157
ClientRequest::GetTaskInfoRequest(r) => r.method.as_str(),
21582158
ClientRequest::ListTasksRequest(r) => r.method.as_str(),
21592159
ClientRequest::GetTaskResultRequest(r) => r.method.as_str(),
21602160
ClientRequest::CancelTaskRequest(r) => r.method.as_str(),
2161+
ClientRequest::CustomRequest(r) => r.method.as_str(),
21612162
}
21622163
}
21632164
}
@@ -2222,11 +2223,11 @@ ts_union!(
22222223
| ListToolsResult
22232224
| CreateElicitationResult
22242225
| EmptyResult
2225-
| CustomResult
22262226
| CreateTaskResult
22272227
| ListTasksResult
22282228
| GetTaskInfoResult
22292229
| TaskResult
2230+
| CustomResult
22302231
;
22312232
);
22322233

crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,6 @@
862862
{
863863
"$ref": "#/definitions/RequestOptionalParam4"
864864
},
865-
{
866-
"$ref": "#/definitions/CustomRequest"
867-
},
868865
{
869866
"$ref": "#/definitions/Request9"
870867
},
@@ -876,6 +873,9 @@
876873
},
877874
{
878875
"$ref": "#/definitions/Request11"
876+
},
877+
{
878+
"$ref": "#/definitions/CustomRequest"
879879
}
880880
],
881881
"required": [

crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema_current.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,6 @@
862862
{
863863
"$ref": "#/definitions/RequestOptionalParam4"
864864
},
865-
{
866-
"$ref": "#/definitions/CustomRequest"
867-
},
868865
{
869866
"$ref": "#/definitions/Request9"
870867
},
@@ -876,6 +873,9 @@
876873
},
877874
{
878875
"$ref": "#/definitions/Request11"
876+
},
877+
{
878+
"$ref": "#/definitions/CustomRequest"
879879
}
880880
],
881881
"required": [

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@
857857
}
858858
]
859859
}
860-
}
860+
},
861+
"additionalProperties": false
861862
},
862863
"Icon": {
863864
"description": "A URL pointing to an icon resource or a base64-encoded data URI.\n\nClients that support rendering icons MUST support at least the following MIME types:\n- image/png - PNG images (safe, universal compatibility)\n- image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)\n\nClients that support rendering icons SHOULD also support:\n- image/svg+xml - SVG images (scalable but requires security precautions)\n- image/webp - WebP images (modern, efficient format)",
@@ -2452,9 +2453,6 @@
24522453
{
24532454
"$ref": "#/definitions/EmptyObject"
24542455
},
2455-
{
2456-
"$ref": "#/definitions/CustomResult"
2457-
},
24582456
{
24592457
"$ref": "#/definitions/CreateTaskResult"
24602458
},
@@ -2466,6 +2464,9 @@
24662464
},
24672465
{
24682466
"$ref": "#/definitions/TaskResult"
2467+
},
2468+
{
2469+
"$ref": "#/definitions/CustomResult"
24692470
}
24702471
]
24712472
},

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@
857857
}
858858
]
859859
}
860-
}
860+
},
861+
"additionalProperties": false
861862
},
862863
"Icon": {
863864
"description": "A URL pointing to an icon resource or a base64-encoded data URI.\n\nClients that support rendering icons MUST support at least the following MIME types:\n- image/png - PNG images (safe, universal compatibility)\n- image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)\n\nClients that support rendering icons SHOULD also support:\n- image/svg+xml - SVG images (scalable but requires security precautions)\n- image/webp - WebP images (modern, efficient format)",
@@ -2452,9 +2453,6 @@
24522453
{
24532454
"$ref": "#/definitions/EmptyObject"
24542455
},
2455-
{
2456-
"$ref": "#/definitions/CustomResult"
2457-
},
24582456
{
24592457
"$ref": "#/definitions/CreateTaskResult"
24602458
},
@@ -2466,6 +2464,9 @@
24662464
},
24672465
{
24682466
"$ref": "#/definitions/TaskResult"
2467+
},
2468+
{
2469+
"$ref": "#/definitions/CustomResult"
24692470
}
24702471
]
24712472
},

0 commit comments

Comments
 (0)