Skip to content

fix: await async MCP header providers#6105

Open
he-yufeng wants to merge 3 commits into
google:mainfrom
he-yufeng:fix/adk-async-mcp-header-provider
Open

fix: await async MCP header providers#6105
he-yufeng wants to merge 3 commits into
google:mainfrom
he-yufeng:fix/adk-async-mcp-header-provider

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Closes: #6090

Problem:

header_provider is called from async MCP execution paths, but async providers were not awaited. Passing an async provider therefore left a coroutine object in the header merge path, which fails with TypeError: 'coroutine' object is not iterable and leaves the coroutine unawaited.

Solution:

Await awaitable header_provider results before merging headers in both MCP paths:

  • McpToolset._execute_with_session, used while creating sessions for get_tools() / resources.
  • McpTool._run_async_impl, used when an individual MCP tool call creates a session.

The existing sync provider behavior is unchanged.

Testing Plan

Unit Tests:

  • Added async header_provider coverage for McpToolset.get_tools().
  • Added async header_provider coverage for McpTool._run_async_impl().
  • Passed locally:
    • PYTHONPATH=src python -m pytest tests/unittests/tools/mcp_tool/test_mcp_tool.py tests/unittests/tools/mcp_tool/test_mcp_toolset.py -q

Additional checks:

  • python -m py_compile src/google/adk/tools/mcp_tool/mcp_tool.py src/google/adk/tools/mcp_tool/mcp_toolset.py
  • python -m pyink --check src/google/adk/tools/mcp_tool/mcp_tool.py src/google/adk/tools/mcp_tool/mcp_toolset.py tests/unittests/tools/mcp_tool/test_mcp_tool.py tests/unittests/tools/mcp_tool/test_mcp_toolset.py
  • python -m ruff check src/google/adk/tools/mcp_tool/mcp_tool.py src/google/adk/tools/mcp_tool/mcp_toolset.py
  • git diff --check

Manual E2E was not run; the changed behavior is covered by the MCP unit tests above.

@rohityan rohityan self-assigned this Jun 15, 2026
@wukath wukath assigned wukath and unassigned rohityan Jun 16, 2026
@rohityan rohityan added the mcp [Component] Issues about MCP support label Jun 17, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Jun 17, 2026
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @he-yufeng , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing mypy-diff tests.

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 request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

McpToolset: support async header_provider

3 participants