Repository navigation
mcp: avoid mutating client request parameters - #1473
Merged
guglielmo-san merged 2 commits intoOct 29, 2026
Merged
guglielmo-san merged 2 commits into
guglielmo-san merged 2 commits into
Conversation
Reusing request params across ClientSession calls could send the first session's metadata on subsequent calls, and concurrent calls sharing params raced when CallTool set default Arguments or injectRequestMeta updated Meta. Shallow-copy the request struct before setting default Arguments or Meta, and clone params.GetMeta() with maps.Clone before injecting per-request metadata. Explicit caller metadata overrides are preserved. Fixes modelcontextprotocol#1472 Signed-off-by: ar8327 <ar8327@outlook.com>
Comment on lines
+1
to
+5
| // Copyright 2025 The Go MCP SDK Authors. All rights reserved. | ||
| // Use of this source code is governed by the license | ||
| // that can be found in the LICENSE file. | ||
|
|
||
| package mcp |
Contributor
There was a problem hiding this comment.
lets not create a separate file for this, can you add the test to @client_test ?
Contributor
Author
There was a problem hiding this comment.
Done — moved the tests to mcp/client_test.go and removed mcp/client_params_test.go in 1e119a5.
Signed-off-by: ar8327 <ar8327@outlook.com>
guglielmo-san
approved these changes
Oct 29, 2026
Contributor
|
@ar8327 thank you for the contribution! |
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.
Reusing
CallToolParams(or other request params) acrossClientSessioncalls can send the first client's_metafields on subsequent calls, becauseinjectRequestMetaonly populates missing keys. Concurrent calls sharing a request struct also race whenCallToolinitializes a nilArgumentsmap orinjectRequestMetawrites toMeta.Shallow-copy the request struct before setting default
ArgumentsorMeta, and cloneparams.GetMeta()withmaps.Clonebefore injecting per-request metadata. Explicit caller metadata overrides are preserved.Tests in
mcp/client_params_test.gocoverinjectRequestMetaownership and sequential/concurrentCallToolreuse across sessions on both2025-11-25and2026-07-28.go test -race -count=1 ./...passesgo vet ./...passesUsed an AI coding assistant to help write the reproduction test and fix; reviewed and verified locally.
Fixes #1472