Fix WithMeta + WithProgress causing tool invocation failure#1464
Merged
stephentoub merged 3 commits intomainfrom Mar 27, 2026
Merged
Fix WithMeta + WithProgress causing tool invocation failure#1464stephentoub merged 3 commits intomainfrom
stephentoub merged 3 commits intomainfrom
Conversation
…nstructor Replace `new JsonObject(meta)` with `(JsonObject)meta.DeepClone()` in both SendRequestWithProgressAsync and SendRequestWithProgressAsTaskAsync to prevent InvalidOperationException when JsonNode values already have a parent. Add tests covering progress with meta, InvokeAsync path, mutation safety, chaining all With* methods, and merging RequestOptions meta with progress. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/d4ec72e6-6d91-429a-92ae-84f8eaa41bbc
Copilot
AI
changed the title
[WIP] Fix tool invocation failure with WithMeta and WithProgress
Fix WithMeta + WithProgress causing tool invocation failure
Mar 25, 2026
stephentoub
reviewed
Mar 25, 2026
Use [Theory] with useInvokeAsync parameter and a shared helper method to test both CallAsync and InvokeAsync paths without code duplication. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/9ab96e2e-534b-4f1d-a047-5cb7f49cd078
stephentoub
approved these changes
Mar 25, 2026
halter73
approved these changes
Mar 27, 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.
new JsonObject(meta)reparents child nodes from the source, throwingInvalidOperationException("The node already has a parent") when the original meta object is still live. This breaks anyMcpClientToolusage combiningWithMetaandWithProgress.Fix
Replace
new JsonObject(meta)with(JsonObject)meta.DeepClone()in bothSendRequestWithProgressAsyncandSendRequestWithProgressAsTaskAsync—consistent with howRequestOptions.GetMetaForRequest()already handles this.Tests
Six new tests covering:
CallAsyncwith progress token in metaWithMeta+ progress via bothCallAsyncandInvokeAsync(AIFunction) pathsWith*methods chained together with progressRequestOptions.Meta💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.