Start Debugging

MCP C# SDK 2.4.1 Writes null Properties in structuredContent by Default

ModelContextProtocol 2.4.1 stops McpJsonUtilities.DefaultOptions from dropping null members, so structured tool results finally match their own outputSchema. It also fixes annotated content blocks that crashed in 2.4.0 and double base64 encoding of images in sampling messages.

This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process

The official MCP C# SDK shipped v2.4.1 on December 4, 2026. It is a patch release, but not a quiet one: all three fixes change the JSON that ModelContextProtocol.Core writes or accepts, and one of them changes a serializer default. If you upgraded to 2.4.0 for the Skills extension, read this before bumping again.

Null members are no longer dropped

Until 2.4.0, McpJsonUtilities.DefaultOptions omitted null values. That clashed with the SDK’s own schema generation. Take a tool with UseStructuredContent = true:

public record Order(string Id, string? Note);

[McpServerTool(UseStructuredContent = true)]
public static Order GetOrder(string id) => new(id, null);

The generated outputSchema lists both id and note as required, with note typed as ["string", "null"]. In 2.4.0 the server then returned "structuredContent": { "id": "42" }, which does not conform to that schema, and any client validating results against outputSchema rejected it. In 2.4.1 (PR #2067) the result is:

"structuredContent": { "id": "42", "note": null }

The change applies to everything serialized with DefaultOptions or a copy of it: tool return values, structuredContent, and object-valued tool arguments that clients send. A record Filter(string City, string? Units) argument now arrives as { "city": "Seattle", "units": null } instead of losing units. MCP protocol types such as Tool still omit optional nulls.

If you relied on the old behavior, you can opt back in per property or per tool:

public record Order(
    string Id,
    [property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    string? Note);

Or pass McpServerToolCreateOptions.SerializerOptions with DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull. Either way, make sure the schema no longer marks the omitted property as required, otherwise you are back to the original bug.

A rollout-order trap with Tasks

ModelContextProtocol.Extensions.Tasks now always writes ttlMs, using null for an unlimited task lifetime as SEP-2663 requires. Clients on the 2.4.0 Tasks package fail to read "ttlMs": null. The release notes give two options: upgrade clients before servers, or set a finite InMemoryMcpTaskStore.DefaultTimeToLive so servers keep sending a number during the transition.

Annotated content blocks work again

The second fix (PR #2039) is a straight regression repair. In 2.4.0, any content block with Annotations, or a resource link with Icons, threw InvalidOperationException: Cannot insert the values of 'TypeInfoResolver' or 'TypeInfoResolverChain' to 'TypeInfoResolverChain'. Servers answered with a generic -32603 error, and clients failed to read results containing annotations. 2.4.1 restores the 2.3.1 behavior, so workarounds like stripping Annotations or pinning to 2.3.1 can go.

Images in sampling were base64 encoded twice

The third fix (PR #2034) affects SamplingMessage.Content and CreateMessageResult.Content. Image and audio data sent through McpServer.SampleAsync or AsSamplingChatClient() was encoded twice, so one decode produced base64 text instead of bytes, and model providers could reject the image. If you added a second decode step to compensate, remove it now, or it will corrupt correctly encoded data from 2.4.1 senders.

One subtle side effect: SingleItemOrListConverter<T> now serializes each item with the contract for T rather than the runtime type, so members of derived types that T does not describe are no longer written unless you add [JsonDerivedType] metadata.

The full before-and-after payloads for each change are in the v2.4.1 release notes. For most servers the upgrade is a fix, but anything that treats an explicit null differently from a missing member deserves a test pass before it ships.

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.