Skip to content

fix: await async MCP header providers#6105

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

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.

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.

McpToolset: support async header_provider

1 participant