fix(model): preserve explicit null structuredContent in CallToolResult - #1295
Merged
DaleSeo merged 1 commit intoSep 24, 2026
Conversation
The MCP 2026-07-28 spec allows `structuredContent` to be any JSON value,
including `null`. Deserializing `CallToolResult` collapsed a present
`"structuredContent": null` into `None`, the same as an absent field, and
rejected `{"resultType":"complete","structuredContent":null}` because no
known non-null field was left.
Decode a present `structuredContent` as `Some(value)`, so an explicit
`null` becomes `Some(Value::Null)` and counts as a known field. An absent
field still decodes as `None`, and serialization still omits only `None`.
Signed-off-by: Jean-Marc Le Roux <jeanmarc@lx.industries>
DaleSeo
approved these changes
Sep 24, 2026
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
The MCP 2026-07-28 specification, Tools > Structured Content says:
The 2026-07-28 schema types
CallToolResult.structuredContentasunknown("This can be any JSON value (object, array, string, number, boolean, or null)").So
nullis a legal structured result, and theTextContentcopy is only a SHOULD. TodayCallToolResult's customDeserializereadsstructured_contentas a plainOption<Value>, which decodes a presentnullasNone, the same as an absent field:{"resultType":"complete","content":[],"structuredContent":null}decodes withstructured_content == None: the explicitnullis lost.{"resultType":"complete","structuredContent":null}fails to decode asCallToolResult("expected at least one known CallToolResult field"), so insideServerResultit falls through toCustomResult.We hit this while proxying tool results whose structured value is legitimately
null.Fix
structuredContentasSome(value)(#[serde(default, deserialize_with = "deserialize_present_value")]). An explicitnullbecomesSome(Value::Null)and counts as a known field in the existing guard.Option<Value>. Serialization is unchanged:skip_serializing_if = "Option::is_none"already omits onlyNone, soSome(Value::Null)serializes as"structuredContent": null.null" instead of "JSON object".How Has This Been Tested?
New tests, all failing on
mainexcept the two guards:test_structured_output.rs: explicitnullwithcontentis preserved; explicitnullwithoutcontentdecodes; an absent field staysNone;Some(Value::Null)round-trips as"structuredContent": nullwhileNoneomits the field.test_deserialization.rs(untagged_server_result): both payloads above, plus{"structuredContent": null}, deserialize asServerResult::CallToolResultwithSome(Value::Null); an object with only unknown null fields still falls through toCustomResult(the fix: prevent CallToolResult from shadowing CustomResult in untagged enum deserialization #771 invariant).cargo test --all-features,cargo +nightly fmt --all -- --check, and both clippy invocations from CI pass locally.Breaking Changes
None. Absent
structuredContentstill decodes asNone, and the public field type is unchanged. The only behavior change is that a presentnullnow decodes asSome(Value::Null)instead ofNone, and the second payload above now decodes asCallToolResultinstead of failing.Types of changes
Checklist
Additional context
Related but distinct: #750, #919, #1046, #1094.
🤖 Written by Claude Code (2.1.280) using model claude-opus-5-5