Repository navigation
Conversation
|
I lean toward the #2067 approach, assuming we accept the broader default change. Writing nulls through normal One design point would make this stronger: keep the generated output schema aligned with the actual serialization contract. In particular, if The tradeoff is that #2067 affects all user data serialized with References: Go output schema inference, Rust output schema inference, Python structured serialization, TypeScript output validation. |
Write nulls for user-defined data by default while keeping null protocol properties omitted through explicit annotations. Add coverage for protocol null omission and document how to opt out. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
5e65693 to
eed4772
Compare
…ion-disabled tests JsonRpcMessageContext is never serialized, so it no longer needs JsonIgnore attributes. Skip the new reflection-dependent null-handling tests when reflection-based serialization is disabled (net9.0 test target). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
852b33f452755f8dd78dfd439686d8a9d55ce834↑ Release build has 0 warnings; 3,700 Core tests passed on .NET 10, targeted .NET Framework 4.7.2 and 754 ASP.NET Core tests passed; the Native AOT app published and ran.
↑ Full Core suite passed with reflection disabled (net9.0 build on the .NET 10 runtime), the configuration that failed CI earlier.
↓ One Core test failed because the remote Docker image lacks
trigger-sampling-request; .NET 8 was not run locally and CI for this head is pending.↓ The change intentionally changes default user-data serialization; compatibility impact is documented below.
↑ The new regression test fails on
mainand passes with this change.structuredContentmember and validates the serialized result against its output schema.↓ No production payload from the original report was available.
Fixes #1915. Related to #690, which reported the same required-null mismatch. This is a simpler alternative to #1929.
Summary
McpJsonUtilities.DefaultOptionsserializes user-defined data such as tool results, structured content and tool arguments. It now uses the standardJsonIgnoreCondition.Neverdefault, so null-valued members are written and match JSON schemas that mark nullable members as required. This uses normal System.Text.Json behavior, without a custom repair serializer or runtime type-classification hook.Protocol DTOs continue to omit optional null properties regardless of serializer options. The source-generated options no longer set a global null-omission default; nullable protocol properties in Core and the Skills, Tasks and Apps extensions are explicitly annotated with
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]. A guard test covers protocol types registered in the SDK's source-generated contexts and fails if a nullable property lacks null-omission metadata. The test also covers types reached through derived contracts behind custom converters.There are no public API changes. The behavior and opt-out are documented in
docs/concepts/tools/tools.md.Compatibility
This intentionally changes default serialization for user-defined data serialized with
DefaultOptions:null.nullmembers where they previously omitted them. A server may treat an absent value differently from an explicitnull.DefaultOptions, and MEAI or extension types serialized through it, now write nulls by default.To omit nulls for user-defined data, apply
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]to individual properties or supplyMcpServerToolCreateOptions.SerializerOptionswithDefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull. Make sure the schema does not require omitted properties.Note
This PR description and change were generated with GitHub Copilot.