Skip to content

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

Closed

Description

@priyayarrabolu-boop

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.

Activity

  1. added
    mcp[Component] This issues is related to MCP support
    on Nov 27, 2025
  2. added theissue type on Nov 27, 2025
  3. added
    agent engine[Component] This issue is related to Vertex AI Agent Engine
    on Dec 2, 2025
  4. yukthiwgeotab commented on Dec 8, 2025

    @yukthiwgeotab

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

  5. timjonez commented on Dec 12, 2025

    @timjonez

    Also running into this issue

  6. rrondir commented on Dec 17, 2025

    @rrondir

    Same issue #3950 it applies to any mcp it seems

  7. llalitkumarrr commented on Feb 3, 2026

    @llalitkumarrr
    Collaborator

    Hello,

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

  8. self-assigned this
    on Feb 3, 2026
  9. added
    answered[Status] This issue has been answered by the maintainer
    on Feb 3, 2026
  10. adk-bot commented on Feb 11, 2026

    @adk-bot
    Collaborator

    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.

  11. added
    stale[Status] Issues which have been marked inactive since there is no user response
    request clarification[Status] The maintainer need clarification or more information from the author
    on Feb 11, 2026
  12. adk-bot commented on Feb 19, 2026

    @adk-bot
    Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent engine[Component] This issue is related to Vertex AI Agent Engineanswered[Status] This issue has been answered by the maintainermcp[Component] This issues is related to MCP supportrequest clarification[Status] The maintainer need clarification or more information from the authorstale[Status] Issues which have been marked inactive since there is no user response

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions