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.
This commit is contained in:
apexlnc 2026-01-29 20:30:53 -05:00 • committed by GitHub
commit 32a68aa239
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 18 deletions

View file

@ -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
;
);

View file

@ -862,9 +862,6 @@
{
"$ref": "#/definitions/RequestOptionalParam4"
},
{
"$ref": "#/definitions/CustomRequest"
},
{
"$ref": "#/definitions/Request9"
},
@ -876,6 +873,9 @@
},
{
"$ref": "#/definitions/Request11"
},
{
"$ref": "#/definitions/CustomRequest"
}
],
"required": [

View file

@ -862,9 +862,6 @@
{
"$ref": "#/definitions/RequestOptionalParam4"
},
{
"$ref": "#/definitions/CustomRequest"
},
{
"$ref": "#/definitions/Request9"
},
@ -876,6 +873,9 @@
},
{
"$ref": "#/definitions/Request11"
},
{
"$ref": "#/definitions/CustomRequest"
}
],
"required": [

View file

@ -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"
}
]
},

View file

@ -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"
}
]
},