Repository navigation
Release v2.4.1 - #2075
Merged
Merged
Release v2.4.1#2075
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
halter73
approved these changes
Dec 4, 2026
halter73
left a comment
Contributor
There was a problem hiding this comment.
The #2067 entry should call out the ttlMs change in ModelContextProtocol.Extensions.Tasks. Default servers now send "ttlMs": null for unlimited tasks, which SEP-2663 requires (ttlMs: number | null, not optional). The 2.4.0 task converters call GetInt64() on it, so a 2.4.0 client polling a 2.4.1 server throws a JsonException. I reproduced it against the published 2.4.0 package.
After "MCP protocol types such as Tool still omit optional null properties.", maybe something like:
The exception is `ttlMs` in task results and status notifications from `ModelContextProtocol.Extensions.Tasks`. SEP-2663 requires `ttlMs` and uses `null` for unlimited tasks, so 2.4.1 always includes it.
**Before (2.4.0)**: `{ "taskId": "abc", "status": "working", ... }`
**After (2.4.1)**: `{ "taskId": "abc", "status": "working", "ttlMs": null, ... }`And under "Adapting your code":
* 2.4.0 task clients fail to read `"ttlMs": null`. Upgrade clients before servers, or set a finite `InMemoryMcpTaskStore.DefaultTimeToLive` so servers send a number.
tarekgh
approved these changes
Dec 4, 2026
tarekgh
left a comment
Contributor
There was a problem hiding this comment.
LGTM, modulo the compatibility risk.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 77d62a9)
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.
Release v2.4.1
This servicing release for the 2.4 series fixes three serialization bugs in
ModelContextProtocol.Core. Tool results and client responses containing annotated content blocks failed to serialize or deserialize. Schema-requirednullproperties were omitted from structured content. Image and audio data in sampling messages was base64-encoded twice. Each fix corrects the JSON that the SDK writes or accepts. If your code compensated for the incorrect behavior, update it to match the corrected serialization. Each entry below includes before-and-after payloads.Fixes #2072
Release Notes
What's Changed
Fix serialization of annotated content blocks in tool results Fix serialization of annotated content blocks in tool results #2039 by @tarekgh
In 2.4.0, content blocks with
annotationsand resource links withiconsfailed to serialize or deserialize. They threwInvalidOperationException: Cannot insert the values of 'TypeInfoResolver' or 'TypeInfoResolverChain' to 'TypeInfoResolverChain'.Servers returned a generic error instead of the tool result, and clients failed to read results that contained annotations. Version 2.4.1 restores the 2.3.1 behavior.A tool that returns
new TextContentBlock { Text = "x", Annotations = new Annotations { Audience = [Role.User] } }:Before (2.4.0): the client receives an error instead of the result.
{ "jsonrpc": "2.0", "id": 1, "error": { "code": -32603, "message": "An error occurred." } }After (2.4.1): the tool result is returned.
{ "jsonrpc": "2.0", "id": 1, "result": { "content": [ { "type": "text", "text": "x", "annotations": { "audience": [ "user" ] } } ] } }Clients also deserialize results like this one again. In 2.4.0, the same exception occurred when they read the result:
{ "content": [ { "type": "text", "text": "x", "annotations": { "audience": [ "user" ] } } ] }Adapting your code: If you removed
AnnotationsorIconsfrom tool results, stayed on 2.3.1, or caught and retried around this exception, you can remove those workarounds.Write null user-defined properties by default Write null user-defined properties by default #2067 by @halter73 (co-authored by @copilot)
McpJsonUtilities.DefaultOptionsno longer omitsnullvalues. User-defined data serialized with those options now includesnullmembers. That data includes tool return values andstructuredContent, tool arguments sent by clients, and data serialized with copies ofDefaultOptions. Previously, a nullable member that the generatedoutputSchemalisted asrequiredwas dropped when it wasnull. A client that validated the result against that schema then rejected it.A tool that uses
UseStructuredContent = trueand returnsnew Order("42", null)forpublic record Order(string Id, string? Note):Before (2.4.0):
noteis omitted, so the result doesn't conform to the tool's ownoutputSchema.After (2.4.1):
noteis written asnull, so the result conforms to the schema.The same applies to
nullmembers of objects that clients pass as tool arguments. For afilterargument of typerecord Filter(string City, string? Units):Before (2.4.0): the server received
"arguments": { "filter": { "city": "Seattle" } }.After (2.4.1): the server receives
"arguments": { "filter": { "city": "Seattle", "units": null } }.Top-level arguments whose value is
nullwere already sent asnulland are unchanged. MCP protocol types such asToolstill omit optionalnullproperties.Task results and status notifications are an exception: SEP-2663 requires
ttlMs, usingnullto mean an unlimited task lifetime. ModelContextProtocol.Extensions.Tasks now always includes that property. Representative task-result fields (other fields omitted):Before (2.4.0):
{ "taskId": "abc", "status": "working" }After (2.4.1):
{ "taskId": "abc", "status": "working", "ttlMs": null }Adapting your code:
requiredentries, or supplied serializer options that keptnullvalues, you can remove those workarounds.nulldifferently from an omitted member, update it to handle explicitnullvalues.nullin the schema or keep omitting that property.nullvalues, apply[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]to individual properties. Alternatively, provideMcpServerToolCreateOptions.SerializerOptions(or your ownJsonSerializerOptions) withDefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull. Make sure the schema doesn't require the omitted properties."ttlMs": null. Upgrade clients before servers, or set a finiteInMemoryMcpTaskStore.DefaultTimeToLiveso servers send a number.Fix double base64 encoding of image/audio content in sampling messages Fix double base64 encoding of image/audio content in sampling messages #2034 by @atailakh
SamplingMessage.ContentandCreateMessageResult.Contentencoded the data for image and audio content blocks twice. They now encode it once, matching standaloneContentBlockserialization and the format the SDK reads. For example, this affected images sent throughMcpServer.SampleAsyncorAsSamplingChatClient(). After one decoding step, recipients got base64 text instead of the media bytes, and model providers could reject the image.A sampling message that contains
ImageContentBlock.FromBytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A], "image/png"). Only thedatamember changes:Before (2.4.0): base64 of the base64 text. One decoding step produces the text
iVBORw0KGgo=, not the PNG bytes.After (2.4.1): the PNG bytes encoded once.
Adapting your code:
datatwice, or detected and unwrapped double-encoded media from C# SDK 2.4.0 senders, decode it once. Otherwise, it will corrupt correctly encoded data.SingleItemOrListConverter<T>now serializes each item with the contract forTrather than the item's runtime type. If you use this converter with derived types thatTdoesn't describe, their extra members are no longer written. To include them, add[JsonDerivedType]metadata or a converter forT.Repository Infrastructure Updates
Acknowledgements
UseStructuredContent: with the default serializer options,structuredContentomits a null property thatoutputSchemarequires #1915 (resolved by Write null user-defined properties by default #2067)Full Changelog: v2.4.0...v2.4.1
API Compatibility Report
✅ All validated packages pass API compatibility validation. The CI-equivalent
dotnet clean -c Release; dotnet pack -c Releasecompleted with 0 warnings and 0 errors.PackageValidationBaselineVersionis unchanged (2.0.0), and no suppression files were modified.McpServerRequestHandler.get_Handler, one per TFM)API Diff Report
✅ There are no public API changes in any of the 6 packages between v2.4.0 and v2.4.1.
Generated with Microsoft.DotNet.ApiDiff.Tool 10.0.406-servicing.26577.108 at
net10.0. The 2.4.0 packages were compared against the 2.4.1 Release packages for ModelContextProtocol.Core, ModelContextProtocol, ModelContextProtocol.AspNetCore, ModelContextProtocol.Extensions.Apps, ModelContextProtocol.Extensions.Skills, and ModelContextProtocol.Extensions.Tasks. A control run of ModelContextProtocol.Core 2.3.1 → 2.4.0 produced a non-empty diff, confirming that the tool detects changes.Note
This pull request description, including the draft release notes, was generated with GitHub Copilot.