fix: await async MCP header providers#6105
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Closes: #6090
Problem:
header_provideris 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 withTypeError: 'coroutine' object is not iterableand leaves the coroutine unawaited.Solution:
Await awaitable
header_providerresults before merging headers in both MCP paths:McpToolset._execute_with_session, used while creating sessions forget_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:
header_providercoverage forMcpToolset.get_tools().header_providercoverage forMcpTool._run_async_impl().PYTHONPATH=src python -m pytest tests/unittests/tools/mcp_tool/test_mcp_tool.py tests/unittests/tools/mcp_tool/test_mcp_toolset.py -qAdditional checks:
python -m py_compile src/google/adk/tools/mcp_tool/mcp_tool.py src/google/adk/tools/mcp_tool/mcp_toolset.pypython -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.pypython -m ruff check src/google/adk/tools/mcp_tool/mcp_tool.py src/google/adk/tools/mcp_tool/mcp_toolset.pygit diff --checkManual E2E was not run; the changed behavior is covered by the MCP unit tests above.