Python: Add origin-scoped headers for MCP connect authentication - #7892
Draft
Shivani . (Shivani767) wants to merge 2 commits into
Draft
Python: Add origin-scoped headers for MCP connect authentication#7892Shivani . (Shivani767) wants to merge 2 commits into
Shivani . (Shivani767) wants to merge 2 commits into
Conversation
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:06 — with
GitHub Actions
Active
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:06 — with
GitHub Actions
Active
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:07 — with
GitHub Actions
Active
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:07 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
Pull request overview
Adds origin-scoped static headers to authenticate MCP initialization while retaining per-call header overlays.
Changes:
- Adds
headers=support and header resolution. - Adds ambient, overlay, redirect, and initialize tests.
- Documents connect-time versus per-call authentication.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Implements static header injection. |
python/packages/core/tests/core/test_mcp.py |
Adds authentication regression tests. |
python/packages/core/agent_framework/security.py |
Updates proxy guidance. |
python/packages/core/AGENTS.md |
Documents header behavior. |
python/samples/02-agents/mcp/mcp_api_key_auth.py |
Explains handshake authentication. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:15 — with
GitHub Actions
Active
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:16 — with
GitHub Actions
Active
Shivani . (Shivani767)
force-pushed
the
fix/7841-mcp-connect-headers
branch
from
August 26, 2026 19:25
f2482d9 to
cafe2da
Compare
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:25 — with
GitHub Actions
Active
Allow MCPStreamableHTTPTool to authenticate initialize/handshake with static headers while keeping header_provider for per-call overlays, so kwargs-only providers no longer leave connect unauthenticated.
Track headers injected by the MCP request hook and remove them on redirected cross-origin requests, route SecureMCPToolProxy through headers=, and harden the redirect regression tests with X-API-Key.
Shivani . (Shivani767)
force-pushed
the
fix/7841-mcp-connect-headers
branch
from
August 26, 2026 19:26
cafe2da to
7d6952d
Compare
Shivani . (Shivani767)
deployed
to
github-app-auth
August 26, 2026 19:26 — with
GitHub Actions
Active
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.
Motivation & Context
MCPStreamableHTTPTool.connect()can still reach servers that authenticate the initialize handshake without credentials when auth comes only from a kwargs-dependentheader_provider. Per-call kwargs are not available untilcall_tool(), so those servers get a 401 (or hang) before any tool call runs.#7305 already delivers
header_providerheaders across transport tasks and authenticates ambient requests for static providers. This PR covers the remaining connect-time gap for servers that require handshake auth.Description & Review Guide
What are the major changes?
headers=constructor argument onMCPStreamableHTTPTool.header_provideras a per-call overlay on top ofheaders=.X-API-Keythat HTTPX would otherwise copy).SecureMCPToolProxyURL mode throughheaders=instead of baking tokens intoAsyncClient.What is the impact of these changes?
connect()without baking tokens into a customhttpx.AsyncClient.header_providersetups can still authenticate the handshake viaheaders=while using dynamic tokens for tool calls.header_provider/ custom-client behavior is unchanged for callers that already worked.What do you want reviewers to focus on?
headers=is the right connect-time contract vs changing ambientheader_provider({})behavior.Related Issue
Fixes #7841
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.