Repository navigation
fix: serialize ElicitRequest mode discriminator only once - #1045
aditya-786 wants to merge 2 commits into
Conversation
ElicitRequest declares its subtype discriminator with @JsonTypeInfo(..., property = "mode"), so Jackson already writes the mode property during serialization. ElicitFormRequest and ElicitUrlRequest also annotated their mode() accessor with @JsonProperty("mode"), so mode was written twice, producing a duplicate JSON key. Mark the overridden mode() accessors @JsonIgnore, mirroring the existing fix on Content.type(). Deserialization is unaffected (it uses the discriminator and the @jsoncreator factories). Adds ElicitRequestJsonTests, mirroring ContentJsonTests.
|
Thanks for picking this up! I tested it against a real server and found a side effect on the wire, details in #1345. Setup: cherry-picked onto v2.2.0, Jackson 3.3.0, Streamable HTTP servlet transport, MCP Inspector 2.13.0, server-initiated form elicitation. The exception is gone and elicitation works, but 2.2.0 + Jackson 3.1.8: {"jsonrpc":"2.0","method":"elicitation/create","id":"…","params":{"message":"Delete task #2 …","requestedSchema":{…},"mode":"form"}}This PR + Jackson 3.3.0: {"jsonrpc":"2.0","method":"elicitation/create","id":"…","params":{"message":"Delete task #2 …","requestedSchema":{…}}}
#1345 has a test that catches this and an alternative ( |
|
mvn -pl mcp-test -am test -Dtest=ElicitRequestJsonTests,ContentJsonTests,McpSchemaTests |
Problem
ElicitRequestdeclares its subtype discriminator with@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "mode"), so Jackson already writes themodeproperty when serializing anElicitFormRequestorElicitUrlRequest. Both subtypes also annotate their overriddenmode()accessor with@JsonProperty("mode"), somodeis written a second time, producing a duplicate JSON key:{"mode":"form","message":"msg","requestedSchema":{"type":"object"},"mode":"form"} {"mode":"url","message":"msg","url":"https://example.com","elicitationId":"eid","mode":"url"}Duplicate object keys violate RFC 8259 and can be rejected by strict client-side parsers.
This is the same defect already fixed on the parallel
Contenthierarchy, whereContent.type()is marked@JsonIgnoreandContentJsonTestsguards it by counting rawtypeoccurrences. The elicitation request types were missed.Fix
Mark the overridden
mode()accessors onElicitFormRequestandElicitUrlRequest@JsonIgnore, mirroringContent.type(). The@JsonTypeInfomachinery still writesmodeexactly once, and deserialization is unaffected since it uses the discriminator plus the@JsonCreatorfromJsonfactories.Tests
ElicitRequestJsonTestsmirrorsContentJsonTests: it asserts each subtype serializesmodeexactly once (counting raw occurrences, since the existingassertThatJsontree comparison silently collapses duplicate keys) and that both round-trip back to the correct subtype.All green (195 schema + 5 content + 4 new). Before the change the two count assertions fail (
modeappears twice); after, they pass.