Skip to content

McpClientTool WithMeta and WithProgress cause tool invokation to fail #1463

@pfegerneo

Description

@pfegerneo

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.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions