Skip to content

fix(mcp): Preserve existing auth in mTLS transport#6201

Open
h-tsuboi918 wants to merge 2 commits into
google:mainfrom
h-tsuboi918:fix/mcp-mtls-auth-header-case
Open

fix(mcp): Preserve existing auth in mTLS transport#6201
h-tsuboi918 wants to merge 2 commits into
google:mainfrom
h-tsuboi918:fix/mcp-mtls-auth-header-case

Conversation

@h-tsuboi918

@h-tsuboi918 h-tsuboi918 commented Jun 23, 2026

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

N/A

Problem:

The MCP mTLS auth bridge checked only for an exact Authorization header key before adding ADC credentials. httpx.Request.headers can be converted into a plain dict with lowercase authorization, so the existing user / 3LO Authorization header could be missed.

When that happens, ADK may inject ADC / runtime Service Account credentials into the same MCP request, causing the MCP server to observe the runtime principal instead of the intended user principal.

Solution:

Make _RefreshableAsyncCredentials.before_request() check for an existing Authorization header case-insensitively before refreshing and injecting credentials.

This matches HTTP header semantics and preserves existing behavior for correctly cased Authorization headers while also handling lowercase authorization from the httpx request path.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Passed locally:

uv run pytest tests/unittests/tools/mcp_tool/test_mcp_session_manager.py
51 passed, 8 warnings

Additional checks:

git diff --check
git diff --cached --check
uv run pyink --check src/google/adk/tools/mcp_tool/mcp_session_manager.py tests/unittests/tools/mcp_tool/test_mcp_session_manager.py
uv run isort --check-only src/google/adk/tools/mcp_tool/mcp_session_manager.py tests/unittests/tools/mcp_tool/test_mcp_session_manager.py

Manual End-to-End (E2E) Tests:

Not run. This is covered by a focused unit test for the credential injection guard. The changed behavior is isolated to preserving an existing lowercase authorization header before ADC refresh/injection.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

The issue is specific to the MCP mTLS transport path where ADK bridges httpx requests into google-auth-aio AsyncAuthorizedSession. The existing Authorization header may originate from MCP auth credential handling or a header provider, including user / 3LO token propagation.

No new code comments were added because the code change is limited to the existing Authorization header guard. There are no dependent downstream changes.

HTTP header names are case-insensitive, but the mTLS auth bridge only checked for an exact Authorization key before adding ADC credentials. httpx can pass the existing header as lowercase authorization, causing the user token to be missed.

Fixes google#6200
@h-tsuboi918 h-tsuboi918 force-pushed the fix/mcp-mtls-auth-header-case branch from 564cbe6 to c637b5f Compare June 23, 2026 17:14
@h-tsuboi918 h-tsuboi918 marked this pull request as ready for review June 23, 2026 17:14
@adk-bot adk-bot added the mcp [Component] Issues about MCP support label Jun 23, 2026
@h-tsuboi918 h-tsuboi918 marked this pull request as draft June 24, 2026 02:58
@h-tsuboi918 h-tsuboi918 marked this pull request as ready for review June 24, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp [Component] Issues about MCP support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP mTLS transport may inject ADC Authorization when an existing auth header is lowercase

2 participants