-
Notifications
You must be signed in to change notification settings - Fork 586
WithMeta for McpClientTool #1027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
0c79f20 to
08c7b99
Compare
08c7b99 to
71b84ab
Compare
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.