Skip to content

Python: Fix MCP header provider across transport tasks#6162

Open
kiwigitops wants to merge 1 commit into
microsoft:mainfrom
kiwigitops:fix-mcp-header-provider-runtime-headers
Open

Python: Fix MCP header provider across transport tasks#6162
kiwigitops wants to merge 1 commit into
microsoft:mainfrom
kiwigitops:fix-mcp-header-provider-runtime-headers

Conversation

@kiwigitops
Copy link
Copy Markdown

Fixes #4808.

MCPStreamableHTTPTool currently stores per-call header_provider output in a ContextVar that the httpx request hook reads later. With the streamable HTTP transport, outbound requests can be sent from a transport task that was created before call_tool() set that context, so the hook can see an empty value and skip the dynamic headers.

This keeps the active headers on the tool instance for the duration of the tool call, so the existing request hook reads the current header snapshot even when the transport sends from another task. The previous value is restored after the call completes.

Tested:

  • python -m pytest python/packages/core/tests/core/test_mcp.py -k header_provider -q
  • python -m ruff check python/packages/core/agent_framework/_mcp.py python/packages/core/tests/core/test_mcp.py
  • git diff --check

Copilot AI review requested due to automatic review settings May 28, 2026 18:42
@github-actions github-actions Bot changed the title Fix MCP header provider across transport tasks Python: Fix MCP header provider across transport tasks May 28, 2026
@kiwigitops kiwigitops force-pushed the fix-mcp-header-provider-runtime-headers branch 2 times, most recently from 2943e29 to 6811045 Compare June 1, 2026 21:53
Signed-off-by: kiwigitops <kiwisclubco@gmail.com>
@kiwigitops kiwigitops force-pushed the fix-mcp-header-provider-runtime-headers branch from 6811045 to a0f8bef Compare June 2, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Unable to pass AgentContext to MCPStreamableHTTPTool

2 participants