adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Critical Runtime Crash: RuntimeError: Attempted to exit cancel scope... when using MCPToolset on Vertex AI Agent Engine

Open priyayarrabolu-boop opened this issue 1 year ago • 6 comments

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: LlmAgent using LocalMCPToolsetWrapper(MCPToolset).
  • Connection: StdioConnectionParams (StdioServerParameters).
  • Goal: Trigger the OAuth flow (which relies on get_tools() returning []).

Steps Taken

  1. Deployed Agent (after fixing the initial Node.js token check crash).
  2. 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)

  1. The agent process crashes immediately when attempting to connect to the MCP server.
  2. 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.

priyayarrabolu-boop avatar Nov 27 '25 02:11 priyayarrabolu-boop

Any progress on this? It has completely blocked our ability to use our remote mcp servers with agents deployed to agent engine

yukthiwgeotab avatar Dec 08 '25 17:12 yukthiwgeotab

Also running into this issue

timjonez avatar Dec 12 '25 17:12 timjonez

Same issue https://github.com/google/adk-python/issues/3950 it applies to any mcp it seems

rrondir avatar Dec 17 '25 13:12 rrondir

Hello,

PR (#4025) related to this issue has been merged, kindly update to latest version to test this issue again.

llalitkumarrr avatar Feb 03 '26 07:02 llalitkumarrr

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.

adk-bot avatar Feb 11 '26 06:02 adk-bot

This has been automatically closed because it has been marked as stale for over 7 days.

adk-bot avatar Feb 19 '26 06:02 adk-bot