feat: implement dynamic MCP HTTP headers via header factory#3583
Open
Piyush0049 wants to merge 1 commit into
Open
feat: implement dynamic MCP HTTP headers via header factory#3583Piyush0049 wants to merge 1 commit into
Piyush0049 wants to merge 1 commit into
Conversation
Refactors NewHeaderTransport to use a header factory instead of a static map. This allows for dynamic context-aware resolution of HTTP headers per-request, which is critical for refreshing OAuth tokens. Also fixes pre-existing Windows file permission test failures in tokenstore_test.go.
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.
Description
This PR refactors
NewHeaderTransportin the upstream transport layer to use aheaderFactory(func(context.Context) map[string]string) instead of a static map for HTTP headers.Currently, the MCP remote client initializes with a static
map[string]string. This means whatever headers are present at startup are permanently hardcoded into the HTTP client for its lifespan. By migrating to a header factory, this PR enables dynamic, context-aware resolution of HTTP headers per-request.This is a critical architectural improvement that allows the agent to securely fetch fresh, short-lived tokens (like OAuth tokens) on every single request and pass dynamic execution metadata during MCP sessions.
Additional Fixes
pkg/tools/mcp/keyringstore/tokenstore_test.go. The test assertions were updated to expect0666file permissions on Windows instead of Unix-style0600. Go'sos.Statalways reports ACLs as0666or0444natively on Windows, regardless of the mode passed toos.WriteFile. This keeps the test suite completely green for Windows contributors without weakening application security.Testing
task testgo buildandgo vetare completely clean