Critical Runtime Crash: RuntimeError: Attempted to exit cancel scope... when using MCPToolset on Vertex AI Agent Engine
Description
I am unable to run a custom ADK agent on the Vertex AI Agent Engine due to a concurrency crash occurring during the MCP client setup/teardown. This prevents the agent from processing user queries and, crucially, blocks the required OAuth consent flow from being triggered.
Environment Details
- Platform: Vertex AI Agent Engine (deployed via
agent_engines.create()), linked to Gemini Enterprise. - Agent Configuration:
LlmAgentusingLocalMCPToolsetWrapper(MCPToolset). - Connection:
StdioConnectionParams(StdioServerParameters). - Goal: Trigger the OAuth flow (which relies on
get_tools()returning[]).
Steps Taken
- Deployed Agent (after fixing the initial Node.js token check crash).
- Sent a user query (e.g., "list contacts") that forces a tool call.
Observed Failure (Full Traceback Snippet)
{...}
File "/home/appuser/.cache/pypoetry/.../site-packages/mcp/client/stdio/__init__.py", line 183, in stdio_client
anyio.create_task_group() as tg,
File "/home/appuser/.cache/pypoetry/.../site-packages/anyio/_backends/_asyncio.py", line 778, in __aexit__
if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
Consequences (Key Issue)
- The agent process crashes immediately when attempting to connect to the MCP server.
- This crash prevents the Python tool code's OAuth trigger logic (
if not access_token: return []) from executing, meaning the user is never prompted for HubSpot authorization.
Request
We require guidance on a stable version combination for the google-adk, mcp, and anyio dependencies that is compatible with the Vertex AI Agent Engine runtime, or a fix for this concurrency bug in the latest release.
Any progress on this? It has completely blocked our ability to use our remote mcp servers with agents deployed to agent engine
Also running into this issue
Same issue https://github.com/google/adk-python/issues/3950 it applies to any mcp it seems
Hello,
PR (#4025) related to this issue has been merged, kindly update to latest version to test this issue again.
This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
This has been automatically closed because it has been marked as stale for over 7 days.