WithMeta for McpClientTool#1027
Merged
stephentoub merged 4 commits intomodelcontextprotocol:mainfrom Dec 5, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a WithMetadata method to McpClientTool, enabling clients to include custom metadata with tool call requests. This follows the same copy-semantics pattern as the existing WithProgress method, making it easy to inject host-specific context (e.g., trace IDs, authentication tokens) into MCP tool calls without modifying the original tool instance.
Key changes:
- Added
WithMetadata(JsonObject)method toMcpClientToolfor attaching metadata to tool calls - Updated
CallToolAsyncmethods to accept and properly handle metadata parameters - Metadata is correctly merged with protocol-level fields like progress tokens when both are used
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/ModelContextProtocol.Core/Client/McpClientTool.cs |
Added _metadata field, updated constructors to propagate metadata, and implemented WithMetadata method with comprehensive XML documentation |
src/ModelContextProtocol.Core/Client/McpClient.Methods.cs |
Updated CallToolAsync to accept metadata parameter, properly clone metadata when combining with progress tokens to prevent mutation |
src/ModelContextProtocol.Core/Client/McpClientExtensions.cs |
Added meta parameter to CallToolAsync extension method signature and XML documentation |
tests/ModelContextProtocol.Tests/Client/McpClientToolTests.cs |
Added MetadataEchoTool test server tool and four comprehensive test cases covering metadata passing, instance creation, method chaining, and multiple instances with different metadata; also cleaned up trailing whitespace |
stephentoub
reviewed
Nov 25, 2025
stephentoub
reviewed
Nov 25, 2025
9 tasks
0c79f20 to
08c7b99
Compare
08c7b99 to
71b84ab
Compare
stephentoub
approved these changes
Dec 5, 2025
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.
Make it possible to send request metadata (
_meta) with Tool calls, by adding a WithMeta method similar to WithProgress. The copy semantics make it easy to have (outer) host context specific metadata injections.Usage Example:
This is additive, so any existing (non-McpClientTool) metadata isn't overwritten.