Skip to content

feat: implement dynamic MCP HTTP headers via header factory - #3583

Merged
dgageot merged 4 commits into
docker:mainfrom
Piyush0049:feat/dynamic-mcp-headers
Jul 15, 2026
Merged

dgageot merged 4 commits into
docker:mainfrom
Piyush0049:feat/dynamic-mcp-headers

Conversation

@Piyush0049

Copy link
Copy Markdown
Contributor

Description

This PR refactors NewHeaderTransport in the upstream transport layer to use a headerFactory (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

  • Windows Test Flakes: Fixed pre-existing Windows-specific test flakes in pkg/tools/mcp/keyringstore/tokenstore_test.go. The test assertions were updated to expect 0666 file permissions on Windows instead of Unix-style 0600. Go's os.Stat always reports ACLs as 0666 or 0444 natively on Windows, regardless of the mode passed to os.WriteFile. This keeps the test suite completely green for Windows contributors without weakening application security.

Testing

  • Tested locally with task test
  • Verified Windows file permission test failures are resolved
  • Verified go build and go vet are completely clean

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.
@Piyush0049
Piyush0049 requested a review from a team as a code owner July 10, 2026 17:22
@aheritier aheritier added area/a2a Agent-to-Agent protocol, A2A server, inter-agent communication area/mcp MCP protocol, MCP tool servers, integration kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jul 10, 2026
# Conflicts:
#	pkg/tools/mcp/mcp.go
#	pkg/tools/mcp/oauth_helpers.go
#	pkg/tools/mcp/oauth_test.go
#	pkg/tools/mcp/remote.go
#	pkg/tools/mcp/remote_test.go
#	pkg/upstream/headers.go
@Sayt-0

Sayt-0 commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

The underlying TODO has since been resolved on main by ef6d626 (chore(mcp): resolve OAuth TODOs and expand headers per request), which covers per-request header expansion with a backward-compatible HeaderResolver design, so the usefulness of this PR now seems doubtful.

@Piyush0049

Copy link
Copy Markdown
Contributor Author

I see that ef6d626 covers MCP but it missed A2A toolsets. In main pkg/tools/a2a/a2a.go still evaluates headers statically at connection startup. My PR fixes this so A2A also gets per request expansion. It also includes a Windows file permission fix for the tokenstore tests. Should I update this PR to apply the new HeaderResolver pattern to a2a.go and keep the Windows fix?

@Sayt-0

Sayt-0 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Yes to both: apply NewHeaderTransportWithResolver to pkg/tools/a2a/a2a.go (it still resolves headers once in Start()), and keep the Windows fix but use t.Skip on Windows instead of asserting 0o666, matching atomicfile_test.go/runregistry_test.go.

@dgageot
dgageot merged commit d8d035c into docker:main Jul 15, 2026
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
docker-agent 1.110.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>This release adds dynamic MCP HTTP headers, new shell safety policies, per-model custom pricing, and cache-stable dynamic prompts, along with fixes for elicitation delivery and session cost tracking.

## What's New

- Adds dynamic MCP HTTP headers via a header factory, enabling context-aware HTTP header resolution instead of static headers fixed at startup
- Adds a `safe-auto` safety policy for shell operations, providing a middle ground between prompting for every tool call and `--yolo` mode; safe calls beyond shell are auto-approved under this policy, with an opt-in `safer` mode available via `approve-safer` resume
- Adds an optional `cost` block to model configuration, allowing explicit per-model token pricing for custom, locally-hosted, or uncatalogued models
- Adds opt-in cache-stable dynamic prompts (`cache_stable_prompts` user setting), persisting frozen instruction snapshots and appending chronological updates when trusted context changes

## Bug Fixes

- Fixes elicitation requests from concurrent background jobs being silently dropped and blocking the requesting handler indefinitely
- Fixes session cost dropping after compaction (e.g., from $49 to $12) by keeping cost monotonic across compaction and preserving cost accounting across reload
---

## What's Changed
* feat: implement dynamic MCP HTTP headers via header factory by @Piyush0049 in docker/docker-agent#3583
* fix(runtime): reliable, correlation-safe, non-blocking elicitation delivery (#3584) by @aheritier in docker/docker-agent#3587
* docs: update CHANGELOG.md for v1.109.0 by @docker-read-write[bot] in docker/docker-agent#3661
* Add opt-in cache-stable dynamic prompts by @rumpl in docker/docker-agent#3662
* fix(session): keep cost monotonic across compaction by @Sayt-0 in docker/docker-agent#3663
* feat(safer_shell): add safe-auto safety policy by @trungutt in docker/docker-agent#3647
* feat(config): declare explicit per-model token pricing with cost by @dgageot in docker/docker-agent#3664


**Full Changelog**: docker/docker-agent@v1.109.0...v1.110.0
</pre>
  <p>View the full release notes at <a href="https://github.com/docker/docker-agent/releases/tag/v1.110.0">https://github.com/docker/docker-agent/releases/tag/v1.110.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!14319
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/a2a Agent-to-Agent protocol, A2A server, inter-agent communication area/mcp MCP protocol, MCP tool servers, integration kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants