fix: require status field to discriminate GetTaskResult from GetTaskPayloadResult#734
Open
blackwell-systems wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…ayloadResult The content-based polymorphic deserializer matches GetTaskResult on the presence of "taskId" alone. This incorrectly captures GetTaskPayloadResult responses (tasks/result), which wrap arbitrary JSON and may also contain a "taskId" key but not a "status" key. Tighten the discriminator to require both "taskId" and "status", since GetTaskResult always has both fields. GetTaskPayloadResult responses (which lack "status") now correctly fall through to other deserializers or the empty result handler. Fixes modelcontextprotocol#601 Signed-off-by: Dayna Blackwell <dayna@blackwell-systems.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Fixes #601
The content-based polymorphic deserializer in
selectClientResultDeserializerandselectServerResultDeserializermatchesGetTaskResulton the presence of"taskId"alone. This incorrectly capturesGetTaskPayloadResultresponses (tasks/result), which wrap arbitrary JSON and may also contain a"taskId"key but not a"status"key.When
Protocol.request<GetTaskPayloadResult>()receives a response that was deserialized asGetTaskResult, the uncheckedas Tcast at line 478 of Protocol.kt throws aClassCastException.Fix
Tighten the discriminator in both
selectClientResultDeserializerandselectServerResultDeserializerto require both"taskId"and"status", sinceGetTaskResultalways has both fields (status is required per the MCP task schema).GetTaskPayloadResultresponses (which lack"status") now correctly fall through to other deserializers or the empty result handler.How Has This Been Tested?
Added two test cases to
TasksTest:task payload result with content field is not deserialized as GetTaskResult: verifies that aCallToolResult-shaped JSON (with"content"but no"status") is correctly deserialized asCallToolResult, notGetTaskResulttask get result with status is correctly deserialized as GetTaskResult: verifies that JSON with both"taskId"and"status"is still correctly deserialized asGetTaskResultAll 37 existing tests continue to pass.
Types of changes
Checklist