Skip to content

feat(mcp): configure registry credential headers - #8433

Open
yang0228 wants to merge 1 commit into
google:mainfrom
yang0228:codex/6814-registry-mcp-credential-headers
Open

yang0228 wants to merge 1 commit into
google:mainfrom
yang0228:codex/6814-registry-mcp-credential-headers

Conversation

@yang0228

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

An Agent Registry binding can supply a token through X-Api-Key while the registered MCP endpoint expects Authorization: Bearer <token>. Callers can now choose the outbound credential header on a registry-resolved binding:

tools = registry.get_mcp_toolset(
    mcp_server_name,
    header_name="Authorization",
    token_prefix="Bearer",
)

A header name alone sends the raw token. Both the Agent Identity and legacy IAM Connector credential services use the override, including when a deployment resolves its binding again. Omitting the options keeps the provider's legacy formatting. The override requires an automatically resolved binding. The fetched token goes only in the chosen credential header.

MCP's built-in HTTP debug and experimental telemetry records redact managed credential headers by name. HTTP requests carrying a non-Authorization credential header can follow same-origin redirects. Cross-origin redirects are rejected before a follow-up request is sent.

Testing Plan

Unit Tests

  • I have added or updated unit tests for my change.
  • All unit tests pass locally. The same 13 tests per version also fail on unchanged main in this environment.

The regressions cover successful immediate and polled credentials from both services, format validation, old serialized schemes, binding resolution and rebind, credential-key isolation, and HTTP redaction and redirect handling. The redirect regression and registry/header tests were also exercised against MCP SDK 1.x and 2.x.

Python 3.12 affected suites (Agent Identity, Agent Registry, MCP, auth): 1,014 passed
Same suites from the built wheel in an independent environment:          1,014 passed
uv build (wheel and sdist):                                             passed
pre-commit (changed files):                                             all applicable hooks passed
mypy (changed source modules):                                         5 matching baseline diagnostics, no new diagnostics

Full repository tox matrix using the four configured uv-venv-lock-runner environments, the test extra, and the project's dependency lock policy. Each environment ran pytest tests/unittests -n 2 -p no:cacheprovider --tb=short.

Environment Passed Failed Skipped Xfailed Xpassed
py311 26,545 13 118 63 2
py312 26,536 13 119 63 2
py313 26,536 13 119 63 2
py314 26,538 13 117 63 2

The same 13 failed test IDs reproduced on unchanged main (bee78e7) with the matching interpreter, dependencies, and local permissions. The failures are 9 OpenAPI tests, 3 load_web_page tests, and 1 MCP Google-auth HTTP transport test affected by macOS system proxy discovery. The main comparison re-ran those failed tests rather than the entire main suite. No new failures appeared in the full patch runs. The affected suite above ran separately without that system proxy and passed all 1,014 cases.

Full-suite failure IDs reproduced on main
tests/unittests/tools/mcp_tool/test_mcp_session_manager.py::TestMCPSessionManager::test_google_auth_async_transport_handle_request
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_allows_public_url_and_pins_ip_host_and_sni
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_does_not_retry_on_read_timeout
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_overwrites_case_insensitive_host_header
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_pins_idn_hostname_with_punycode_host_header
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_pins_ipv6_and_preserves_userinfo
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_returns_error_on_unresolvable_host
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_tries_next_address_on_connect_failure
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRequestSsrfProtection::test_request_with_client_cert_pins_mtls_googleapis_host
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRestApiTool::test_call_serializes_non_string_parameters_and_omits_none
tests/unittests/tools/test_load_web_page.py::test_load_web_page_allows_public_nat64_ip
tests/unittests/tools/test_load_web_page.py::test_load_web_page_fetches_public_urls_by_pinning_the_resolved_ip
tests/unittests/tools/test_load_web_page.py::test_load_web_page_tries_another_resolved_address_after_connect_error

Manual End-to-End (E2E) Tests

I ran ADK's Runner with a scripted BaseLlm and a loopback Streamable HTTP MCP server. The server handled initialize, notifications/initialized, tools/list, and tools/call, and rejected requests whose credential headers differed from the expected set. The Agent Registry API and credentials response were stubbed with one synthetic token. I ran the same probe against source and against the installed wheel outside the checkout.

Default API key       x-api-key, x-goog-api-key    list + call passed
Configured Bearer    authorization only          list + call passed
Custom raw token      x-service-token only        list + call passed
Built-in HTTP telemetry records                  4 redacted records per case

The probe used a real local HTTP connection. The Runner completed each call and returned the scripted final response. Regression tests also exercise the IAM Connector response path and deployment rebind with fixture data. Cloud-service and model requests were stubbed.

Checklist

  • I have read the contribution guide.
  • I have reviewed the change and tested the relevant behavior.
  • I added regressions and exercised the change end-to-end.
  • All repository tests pass locally. The same 13 tests per version also fail on unchanged main in this environment.

The public usage guide is updated in the companion docs PR. mkdocs build --strict passed there.

Let an auto-resolved Agent Registry auth provider send its token in an explicit header with an optional prefix. Preserve the override when the deployed toolset resolves its binding again.

Redact credential headers in MCP debug and telemetry records and prevent non-Authorization credential headers from following cross-origin redirects.

Closes google#6814
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom header names for MCP servers secured with Auth Providers

1 participant