-
Notifications
You must be signed in to change notification settings - Fork 665
Description
Describe the bug
Adding both WithMeta and WithProgress to an McpClientTool causes the tool invocation to fail in McpClient.CallToolAsync (SendRequestWithProgressAsync).
To Reproduce
Example usage:
var mcpTools = await mcpClient.ListToolsAsync(cancellationToken: cancellationToken); mcpTools = mcpTools.Select(tool => tool.WithMeta(new JsonObject { ["chatRequestId"] = requestGuid }));
Minimal reproduction of the problematic code:
var meta = new JsonObject { ["key"] = "value" }; JsonObject metaWithProgress = meta is not null ? new(meta) : [];
Expected behavior
The meta instance should be cloned so that adding the progress ID does not modify the original meta instance. Tool invocation should then succeed.
Posible fix
https://github.com/modelcontextprotocol/csharp-sdk/blob/main/src/ModelContextProtocol.Core/Client/McpClient.Methods.cs#L880)
current code:
JsonObject metaWithProgress = meta is not null ? new(meta) : [];
replace with:
JsonObject metaWithProgress = meta is not null ? (JsonObject)meta.DeepClone() : [];
This ensures progress information is added to a deep clone of meta, leaving the original metadata untouched.