Skip to content

fix: await async MCP header providers#6105

Closed
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/adk-async-mcp-header-provider
Closed

fix: await async MCP header providers#6105
he-yufeng wants to merge 1 commit 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 mcp [Component] This issues is related to MCP support request clarification [Status] The maintainer need clarification or more information from the author labels 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.

@he-yufeng
he-yufeng force-pushed the fix/adk-async-mcp-header-provider branch 2 times, most recently from 1be8161 to e22ef16 Compare June 18, 2026 06:15
@he-yufeng
he-yufeng force-pushed the fix/adk-async-mcp-header-provider branch from e22ef16 to 4f7ccb5 Compare June 18, 2026 10:14
@GWeale GWeale added the import label Jun 19, 2026
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #6105

## Summary
- await async/awaitable MCP header providers in async execution paths.
- add unit tests verifying the async header provider functionality.

Fixes #6090

Co-authored-by: Kathy Wu <wukathy@google.com>
COPYBARA_INTEGRATE_REVIEW=#6105 from he-yufeng:fix/await-async-header-provider 086d352
PiperOrigin-RevId: 941317964
@adk-bot

adk-bot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Thank you @he-yufeng for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit c01e538.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jul 1, 2026
@adk-bot adk-bot closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

import mcp [Component] This issues is related to MCP support merged [Status] This PR is merged 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

5 participants