From ac4146ec8da167b92b6a3fde66c92edb44ad8fe8 Mon Sep 17 00:00:00 2001 From: apexlnc <43242113+apexlnc@users.noreply.github.com> Date: Wed, 28 Jan 2026 19:21:12 -0500 Subject: [PATCH] fix(tasks): correct enum variant ordering for deserialization 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. --- crates/rmcp/src/model.rs | 9 +++++---- .../client_json_rpc_message_schema.json | 6 +++--- .../client_json_rpc_message_schema_current.json | 6 +++--- .../server_json_rpc_message_schema.json | 9 +++++---- .../server_json_rpc_message_schema_current.json | 9 +++++---- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/rmcp/src/model.rs b/crates/rmcp/src/model.rs index e0f0bb242..3c86fbbdc 100644 --- a/crates/rmcp/src/model.rs +++ b/crates/rmcp/src/model.rs @@ -2045,6 +2045,7 @@ impl RequestParamsMeta for CancelTaskParams { pub type CancelTaskParam = CancelTaskParams; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "camelCase")] +#[serde(deny_unknown_fields)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct GetTaskInfoResult { #[serde(skip_serializing_if = "Option::is_none")] @@ -2130,11 +2131,11 @@ ts_union!( | UnsubscribeRequest | CallToolRequest | ListToolsRequest - | CustomRequest | GetTaskInfoRequest | ListTasksRequest | GetTaskResultRequest - | CancelTaskRequest; + | CancelTaskRequest + | CustomRequest; ); impl ClientRequest { @@ -2153,11 +2154,11 @@ impl ClientRequest { ClientRequest::UnsubscribeRequest(r) => r.method.as_str(), ClientRequest::CallToolRequest(r) => r.method.as_str(), ClientRequest::ListToolsRequest(r) => r.method.as_str(), - ClientRequest::CustomRequest(r) => r.method.as_str(), ClientRequest::GetTaskInfoRequest(r) => r.method.as_str(), ClientRequest::ListTasksRequest(r) => r.method.as_str(), ClientRequest::GetTaskResultRequest(r) => r.method.as_str(), ClientRequest::CancelTaskRequest(r) => r.method.as_str(), + ClientRequest::CustomRequest(r) => r.method.as_str(), } } } @@ -2222,11 +2223,11 @@ ts_union!( | ListToolsResult | CreateElicitationResult | EmptyResult - | CustomResult | CreateTaskResult | ListTasksResult | GetTaskInfoResult | TaskResult + | CustomResult ; ); diff --git a/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json b/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json index e0d90fa8a..6e45c5f15 100644 --- a/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json +++ b/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json @@ -862,9 +862,6 @@ { "$ref": "#/definitions/RequestOptionalParam4" }, - { - "$ref": "#/definitions/CustomRequest" - }, { "$ref": "#/definitions/Request9" }, @@ -876,6 +873,9 @@ }, { "$ref": "#/definitions/Request11" + }, + { + "$ref": "#/definitions/CustomRequest" } ], "required": [ diff --git a/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema_current.json b/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema_current.json index e0d90fa8a..6e45c5f15 100644 --- a/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema_current.json +++ b/crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema_current.json @@ -862,9 +862,6 @@ { "$ref": "#/definitions/RequestOptionalParam4" }, - { - "$ref": "#/definitions/CustomRequest" - }, { "$ref": "#/definitions/Request9" }, @@ -876,6 +873,9 @@ }, { "$ref": "#/definitions/Request11" + }, + { + "$ref": "#/definitions/CustomRequest" } ], "required": [ diff --git a/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json b/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json index b848d4ee5..f15968578 100644 --- a/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json +++ b/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json @@ -857,7 +857,8 @@ } ] } - } + }, + "additionalProperties": false }, "Icon": { "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 @@ { "$ref": "#/definitions/EmptyObject" }, - { - "$ref": "#/definitions/CustomResult" - }, { "$ref": "#/definitions/CreateTaskResult" }, @@ -2466,6 +2464,9 @@ }, { "$ref": "#/definitions/TaskResult" + }, + { + "$ref": "#/definitions/CustomResult" } ] }, diff --git a/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json b/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json index b848d4ee5..f15968578 100644 --- a/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json +++ b/crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json @@ -857,7 +857,8 @@ } ] } - } + }, + "additionalProperties": false }, "Icon": { "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 @@ { "$ref": "#/definitions/EmptyObject" }, - { - "$ref": "#/definitions/CustomResult" - }, { "$ref": "#/definitions/CreateTaskResult" }, @@ -2466,6 +2464,9 @@ }, { "$ref": "#/definitions/TaskResult" + }, + { + "$ref": "#/definitions/CustomResult" } ] },