Skip to content

Python: avoid MCP header injection on redirects#5867

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/mcp-header-redirect-origin
Open

Python: avoid MCP header injection on redirects#5867
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/mcp-header-redirect-origin

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #5820.

Summary

  • only inject MCP header_provider headers for requests that stay on the configured MCP server origin
  • preserve same-origin header injection for the existing streamable HTTP client path
  • add a real httpx redirect regression test that verifies Authorization is not re-applied to a cross-origin redirect target

To verify

  • python -m py_compile packages\\core\\agent_framework\\_mcp.py packages\\core\\tests\\core\\test_mcp.py
  • uv run ruff check packages\\core\\agent_framework\\_mcp.py packages\\core\\tests\\core\\test_mcp.py
  • uv run pytest packages\\core\\tests\\core\\test_mcp.py -q -k "header_provider_with_httpx_event_hook or header_provider_skips_cross_origin_redirect or header_provider_with_user_httpx_client" --basetemp .tmp\\pytest -p no:cacheprovider
  • git diff --check

Copilot AI review requested due to automatic review settings May 14, 2026 21:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@he-yufeng he-yufeng force-pushed the fix/mcp-header-redirect-origin branch from b8a1078 to 4d3bfb8 Compare May 15, 2026 05:53
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]: MCPStreamableHTTPTool re-injects header_provider headers on cross-origin redirects (latent until #4808 / mcp-sdk#2298 ship)

3 participants