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

adk agent hangs when using MCPToolset to connect to a remote streamable HTTP MCP Server hosted in Cloud Run

Open davxiao opened this issue 1 year ago • 13 comments

Describe the bug Create a simple agent using MCPToolset to connect to a StreamableHttp MCP server hosted in Cloud Run. The Cloud Run is enabled "allow authentication only".

The following adk tests are done on a GCP VM which is hosted in the same GCP project that the Cloud Run MCP server is hosted. The VM also has an associated service account that has "cloud run invoker" role and all other GCP permissions.

Test 1: Test the agent with local run "adk web". The agent MCPToolset connects to the cloud run endpoint

In this test, the agent hangs when responding to the inputs. The agent logs shows the HTTP requests made to MCP server were successful with HTTP/200 OK, and the Cloud run log shows Warning Truncated response body. See below logs and code snippet for the agent.

agent.py

import urllib
import google.auth.transport.requests
import google.oauth2.id_token
mcp_cloudrun_aud = 'https://your-sample-mcp-server.us-central1.run.app'
auth_req = google.auth.transport.requests.Request()
id_token = google.oauth2.id_token.fetch_id_token(auth_req, mcp_cloudrun_aud)
logging.info('====Your id_token====' + id_token)

root_agent = LlmAgent(
    model=os.environ.get("GOOGLE_MODEL"),
    name='your_agent',
    instruction=os.environ.get("YOUR_AGENT_PROMPT"),
    tools=[
        MCPToolset(
          connection_params=StreamableHTTPConnectionParams(
            url="https://your-sample-mcp-server.us-central1.run.app/mcp",
            headers={'X-Serverless-Authorization': 'Bearer '+id_token},
            timeout=60,
          ),
        ),
    ],
)

adk web log

INFO:google_adk.google.adk.cli.utils.agent_loader:Found root_agent in your_agent.agent
INFO:httpx:HTTP Request: POST https://your-sample-mcp-server.us-central1.run.app/mcp "HTTP/1.1 307 Temporary Redirect"
INFO:httpx:HTTP Request: POST http://your-sample-mcp-server.us-central1.run.app/mcp/ "HTTP/1.1 302 Found"
INFO:httpx:HTTP Request: GET https://your-sample-mcp-server.us-central1.run.app/mcp/ "HTTP/1.1 200 OK"
(end of log)

cloud run log

DEFAULT 2025-08-19T19:37:01.664489Z INFO: 169.254.169.126:9032 - "GET /mcp/ HTTP/1.1" 200 OK
WARNING 2025-08-19T19:40:17.716013Z Truncated response body. Usually implies that the request timed out or the application exited before the response was finished.
WARNING 2025-08-19T19:42:03.891259Z Truncated response body. Usually implies that the request timed out or the application exited before the response was finished.
(end of log)

Test 2: Test the agent with local run "adk web". The agent MCPToolset connects to the local proxy that tunnels to the cloud run endpoint

The agent MCPToolset connects to the local proxy that tunnels to the cloud run endpoint. In this case everything works out fine, agent can generate responses and reasoning with the MCP server. This proofs that MCP server and Cloud Run is working as intended.

In test2, the main difference is that I use the following command to establish a local proxy. gcloud run services proxy your-mcp-server --region us-central1 --port=3000

agent.py

root_agent = LlmAgent(
    model=os.environ.get("GOOGLE_MODEL"),
    name='your_agent',
    instruction=os.environ.get("YOUR_AGENT_PROMPT"),
    tools=[
        MCPToolset(
          connection_params=StreamableHTTPConnectionParams(
            url="http://127.0.0.1:3000/mcp", ##for local proxy test
            timeout=60,
          ),
        ),
    ],
)

adk log

INFO:httpx:HTTP Request: POST http://127.0.0.1:3000/mcp "HTTP/1.1 307 Temporary Redirect"
INFO:httpx:HTTP Request: POST http://127.0.0.1:3000/mcp/ "HTTP/1.1 200 OK"
INFO:mcp.client.streamable_http:Negotiated protocol version: 2025-06-18
INFO:httpx:HTTP Request: POST http://127.0.0.1:3000/mcp "HTTP/1.1 307 Temporary Redirect"
INFO:httpx:HTTP Request: POST http://127.0.0.1:3000/mcp/ "HTTP/1.1 202 Accepted"
INFO:httpx:HTTP Request: POST http://127.0.0.1:3000/mcp "HTTP/1.1 307 Temporary Redirect"
INFO:httpx:HTTP Request: POST http://127.0.0.1:3000/mcp/ "HTTP/1.1 200 OK"
/Users/daxiao/code/your-mcp/src/adk_agent_your_mcp/venv_new/lib/python3.13/site-packages/google/adk/tools/mcp_tool/mcp_tool.py:87: UserWarning: [EXPERIMENTAL] BaseAuthenticatedTool: This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.
  super().__init__(
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_adk.google.adk.tools.base_authenticated_tool:auth_config or auth_config.auth_scheme is missing. Will skip authentication.Using FunctionTool instead if authentication is not required.
WARNING:google_genai._api_client:Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.
INFO:google_adk.google.adk.models.google_llm:Sending out request, model: gemini-2.5-flash, backend: GoogleLLMVariant.GEMINI_API, stream: False
INFO:google_genai.models:AFC is enabled with max remote calls: 10.
INFO:google_adk.google.adk.models.google_llm:Response received from the model.
WARNING:google_genai.types:Warning: there are non-text parts in the response: ['thought_signature'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.
INFO:     127.0.0.1:56537 - "GET /apps/your_agent/users/user/sessions/2956b8eb-7b71-4ff5-a453-2ea45a1cb6a4 HTTP/1.1" 200 OK
INFO:     127.0.0.1:56549 - "GET /debug/trace/session/2956b8eb-7b71-4ff5-a453-2ea45a1cb6a4 HTTP/1.1" 200 OK

To Reproduce Steps to reproduce the behavior:

  1. Deploy a sample MCP server on Cloud Run that supports streamable HTTP
  2. Run the code above in test 1 and test 2
  3. Test 1 will hang the agent and Test 2 will get through without hanging

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Python version(python -V):
  • ADK version(pip show google-adk): Name: google-adk Version: 1.10.0

Model Information: GOOGLE_MODEL=gemini-2.5-flash

davxiao avatar Aug 19 '25 22:08 davxiao

I'm experiencing the same if I have 2 or more requests at a time only the first request is handled all the others hang. I have a simple agent that uses an MCPToolset:

root_agent = LlmAgent(
    model=config.worker_model,
    generate_content_config=genai_types.GenerateContentConfig(temperature=0.7),
    name="terms_of_service",
    description=(
        "Analyzes the user's request and sends an answer."
    ),
    instruction="Analyze the user's request to determine if complies with the Terms of Service. Your response should be a text describing wether the request is valid or not.",
    tools=[
        MCPToolset(
            connection_params=StreamableHTTPConnectionParams(
                url=(
                    "https://google-maps-code-assist-mcp-abc.run.app/mcp"
                ),
                timeout=1,
            )
        )
    ],
)

The logs show this error: RuntimeError: Attempted to exit cancel scope in a different task than it was entered in

DEFAULT 2025-08-22T15:24:16.498929Z [12] ERROR: an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x3e097a553f40>
DEFAULT 2025-08-22T15:24:16.498938Z asyncgen: <async_generator object streamablehttp_client at 0x3e097a553f40>
DEFAULT 2025-08-22T15:24:16.498952Z + Exception Group Traceback (most recent call last):
DEFAULT 2025-08-22T15:24:16.498957Z | File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__
DEFAULT 2025-08-22T15:24:16.498961Z | raise BaseExceptionGroup(
DEFAULT 2025-08-22T15:24:16.498966Z | exceptiongroup.BaseExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
DEFAULT 2025-08-22T15:24:16.498969Z +-+---------------- 1 ----------------
DEFAULT 2025-08-22T15:24:16.498974Z | Traceback (most recent call last):
DEFAULT 2025-08-22T15:24:16.498979Z | File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/mcp/client/streamable_http.py", line 498, in streamablehttp_client
DEFAULT 2025-08-22T15:24:16.498981Z | yield (
DEFAULT 2025-08-22T15:24:16.498984Z | GeneratorExit
DEFAULT 2025-08-22T15:24:16.498987Z +------------------------------------
DEFAULT 2025-08-22T15:24:16.498991Z During handling of the above exception, another exception occurred:
ERROR 2025-08-22T15:24:16.499009Z Traceback (most recent call last): File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/mcp/client/streamable_http.py", line 474, in streamablehttp_client async with anyio.create_task_group() as tg: File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 778, in __aexit__ if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__): File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 457, in __exit__ raise RuntimeError( RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
  {
    "textPayload": "Traceback (most recent call last):\n  File \"/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/mcp/client/streamable_http.py\", line 474, in streamablehttp_client\n    async with anyio.create_task_group() as tg:\n  File \"/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 778, in __aexit__\n    if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):\n  File \"/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 457, in __exit__\n    raise RuntimeError(\nRuntimeError: Attempted to exit cancel scope in a different task than it was entered in",
    "insertId": "68a88ba000079d4119f7da96",
    "resource": {
      "type": "aiplatform.googleapis.com/ReasoningEngine",
      "labels": {
        "resource_container": "575926294736",
        "reasoning_engine_id": "6422418941653549056",
        "location": "us-central1"
      }
    },
    "timestamp": "2025-08-22T15:24:16.499009Z",
    "severity": "ERROR",
    "logName": "projects/fb-tools-dev/logs/aiplatform.googleapis.com%2Freasoning_engine_stderr",
    "receiveTimestamp": "2025-08-22T15:24:16.545213231Z"
  }

chalosalvador avatar Aug 22 '25 16:08 chalosalvador

although the transport is being phased out, an mcp server running on sse works properly in cloud run (as an alternative). the other alternatives is to probably use an actual vm, or k8s (never tried though).

capancheta avatar Sep 08 '25 00:09 capancheta

@davxiao thanks for reporting the issue :)

You tests did help. So the difference is the authorization header, did you see correct value for your id token log ? could you try directly use the value of gcloud auth print-identity-token ?

Also could you try 'Authorization' header ? I know 'X-Serverless-Authorization' should have higher priority, but just want to make sure it's not some issue on server handling 'X-Serverless-Authorization' header.

Another thing you can try is to increase the timeout, given server is complaining WARNING 2025-08-19T19:40:17.716013Z Truncated response body. Usually implies that the request timed out or the application exited before the response was finished.

thanks.

seanzhou1023 avatar Sep 17 '25 05:09 seanzhou1023

I can confirm all the logs shown HTTP 200 and so the header auth is fine. I also testeed giving 60s timeout --- the same Truncated response body shown after 60 seconds.

Please investigate. I see the other report in this thread mentioned it's reproducible with a simple MCP server so this likely a bug?

davxiao avatar Sep 17 '25 05:09 davxiao

Thanks for the information :) I will try to build a local MCP server that require auth to reproduce.

seanzhou1023 avatar Sep 17 '25 06:09 seanzhou1023

@seanzhou1023 I was able to reproduce the issue even without the MCP server requiring auth. I made my MCP server publicly available in Cloud Run and the concurrent requests still hang.

I have my agent deployed to VertexAI Agent Engine.

I think it may be related to MCPToolset session management.

Possible related issue: #3084, #2980

I'm experiencing the same if I have 2 or more requests at a time only the first request is handled all the others hang. I have a simple agent that uses an MCPToolset:

root_agent = LlmAgent( model=config.worker_model, generate_content_config=genai_types.GenerateContentConfig(temperature=0.7), name="terms_of_service", description=( "Analyzes the user's request and sends an answer." ), instruction="Analyze the user's request to determine if complies with the Terms of Service. Your response should be a text describing wether the request is valid or not.", tools=[ MCPToolset( connection_params=StreamableHTTPConnectionParams( url=( "https://google-maps-code-assist-mcp-abc.run.app/mcp" ), timeout=1, ) ) ], ) The logs show this error: RuntimeError: Attempted to exit cancel scope in a different task than it was entered in

DEFAULT 2025-08-22T15:24:16.498929Z [12] ERROR: an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x3e097a553f40>
DEFAULT 2025-08-22T15:24:16.498938Z asyncgen: <async_generator object streamablehttp_client at 0x3e097a553f40>
DEFAULT 2025-08-22T15:24:16.498952Z + Exception Group Traceback (most recent call last):
DEFAULT 2025-08-22T15:24:16.498957Z | File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__
DEFAULT 2025-08-22T15:24:16.498961Z | raise BaseExceptionGroup(
DEFAULT 2025-08-22T15:24:16.498966Z | exceptiongroup.BaseExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
DEFAULT 2025-08-22T15:24:16.498969Z +-+---------------- 1 ----------------
DEFAULT 2025-08-22T15:24:16.498974Z | Traceback (most recent call last):
DEFAULT 2025-08-22T15:24:16.498979Z | File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/mcp/client/streamable_http.py", line 498, in streamablehttp_client
DEFAULT 2025-08-22T15:24:16.498981Z | yield (
DEFAULT 2025-08-22T15:24:16.498984Z | GeneratorExit
DEFAULT 2025-08-22T15:24:16.498987Z +------------------------------------
DEFAULT 2025-08-22T15:24:16.498991Z During handling of the above exception, another exception occurred:
ERROR 2025-08-22T15:24:16.499009Z Traceback (most recent call last): File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/mcp/client/streamable_http.py", line 474, in streamablehttp_client async with anyio.create_task_group() as tg: File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 778, in __aexit__ if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__): File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 457, in __exit__ raise RuntimeError( RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
  {
    "textPayload": "Traceback (most recent call last):\n  File \"/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/mcp/client/streamable_http.py\", line 474, in streamablehttp_client\n    async with anyio.create_task_group() as tg:\n  File \"/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 778, in __aexit__\n    if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):\n  File \"/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 457, in __exit__\n    raise RuntimeError(\nRuntimeError: Attempted to exit cancel scope in a different task than it was entered in",
    "insertId": "68a88ba000079d4119f7da96",
    "resource": {
      "type": "aiplatform.googleapis.com/ReasoningEngine",
      "labels": {
        "resource_container": "575926294736",
        "reasoning_engine_id": "6422418941653549056",
        "location": "us-central1"
      }
    },
    "timestamp": "2025-08-22T15:24:16.499009Z",
    "severity": "ERROR",
    "logName": "projects/fb-tools-dev/logs/aiplatform.googleapis.com%2Freasoning_engine_stderr",
    "receiveTimestamp": "2025-08-22T15:24:16.545213231Z"
  }

chalosalvador avatar Oct 07 '25 19:10 chalosalvador

I can not reproduce the issue with local MCP server. below is my test codes :

Agent :

from google.adk.agents.llm_agent import Agent
from google.adk.tools.mcp_tool.mcp_session_manager import (
    StreamableHTTPConnectionParams,
)
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset

# Create MCP toolset connecting to HTTP server
# This uses StreamableHTTPConnectionParams to properly test issue #2615
# The server must be started separately: python mcp_http_server.py
mcp_toolset = McpToolset(
    connection_params=StreamableHTTPConnectionParams(
        url="http://localhost:3000/mcp",
        timeout=30,
        sse_read_timeout=60,
    ),
)

# Create the agent
root_agent = Agent(
    model= "gemini-2.5-flash",
    name="concurrent_mcp_test_agent",
    description="Agent for testing concurrent MCP tool calls",
    instruction=(
        "You are a helpful assistant that can use multiple tools. "
        "When asked to test concurrent calls, use MULTIPLE tools in parallel "
        "if the model supports it. Always report the results from all tools."
    ),
    tools=[mcp_toolset],
)

local mcp server:

#!/usr/bin/env python3
"""HTTP MCP server for testing StreamableHTTP concurrent requests.

This server implements the MCP protocol over HTTP with streaming support,
similar to what would be deployed on Cloud Run.

Run this server in a separate terminal:
    python mcp_http_server.py

Then connect to it using StreamableHTTPConnectionParams.
"""

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
import logging

from mcp.server.fastmcp import FastMCP

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Create FastMCP server (stateful HTTP mode to reproduce issue #2615)
# stateless_http=False ensures concurrent calls share the same session
mcp = FastMCP(
    "test-http-server", stateless_http=False, host="0.0.0.0", port=3000
)


@mcp.tool(description="A slow tool that takes 2 seconds to respond")
async def slow_tool_1(message: str) -> str:
  """Slow tool #1 - takes 2 seconds."""
  start_time = asyncio.get_event_loop().time()
  logger.info(
      f"[HTTP Server] slow_tool_1 STARTED at {start_time:.3f} with message:"
      f" {message}"
  )
  await asyncio.sleep(2)
  end_time = asyncio.get_event_loop().time()
  logger.info(
      f"[HTTP Server] slow_tool_1 COMPLETED at {end_time:.3f} (took"
      f" {end_time - start_time:.3f}s)"
  )
  return f"slow_tool_1 processed: {message}"


@mcp.tool(description="Another slow tool that takes 2 seconds")
async def slow_tool_2(message: str) -> str:
  """Slow tool #2 - takes 2 seconds."""
  start_time = asyncio.get_event_loop().time()
  logger.info(
      f"[HTTP Server] slow_tool_2 STARTED at {start_time:.3f} with message:"
      f" {message}"
  )
  await asyncio.sleep(2)
  end_time = asyncio.get_event_loop().time()
  logger.info(
      f"[HTTP Server] slow_tool_2 COMPLETED at {end_time:.3f} (took"
      f" {end_time - start_time:.3f}s)"
  )
  return f"slow_tool_2 processed: {message}"


@mcp.tool(description="A fast tool that responds immediately")
async def fast_tool(message: str) -> str:
  """Fast tool - responds immediately."""
  timestamp = asyncio.get_event_loop().time()
  logger.info(
      f"[HTTP Server] fast_tool EXECUTED at {timestamp:.3f} with message:"
      f" {message}"
  )
  return f"fast_tool processed: {message}"


if __name__ == "__main__":
  logger.info("=" * 80)
  logger.info("MCP HTTP Server Starting (StreamableHTTP)")
  logger.info("URL: http://localhost:3000/mcp")
  logger.info("This server simulates a Cloud Run MCP server")
  logger.info("Press Ctrl+C to stop")
  logger.info("=" * 80)

  # Run with streamable-http transport
  # Port and host are configured in the FastMCP constructor above
  mcp.run(transport="streamable-http")

and here is my test prompt :

prompt = """Please call ALL THREE of these tools and report their results:
- slow_tool_1 with message "First concurrent call"
- slow_tool_2 with message "Second concurrent call"
- fast_tool with message "Third concurrent call"

Make these calls and report back all the results.
"""

and I can see the tools are called concurrently from the mcp server log.

Could you share your mcp server codes, your agent codes and you test prompt for me to reproduce ?

Question:

  1. when you say two concurrent requests, do you mean you send a user query to agent and the agent call two tools in the MCPToolset parallely or you actually mean you create two ADK sessions and run the agent in those two sessions concurrently ? Could you specify in details how you send the two concurrent requests ?
  2. what MCP SDK version are you using ? uv pip show mcp

seanzhou1023 avatar Oct 10 '25 03:10 seanzhou1023

It works on adk web but does not work on Vertex AI Engine. Same problem for me.

kushalbhabra avatar Nov 04 '25 16:11 kushalbhabra

Hello @davxiao ,

We have released a new version i.e. google-adk==1.20.0. We recommend upgrading to this version and testing again.

llalitkumarrr avatar Dec 10 '25 11:12 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 Dec 18 '25 23:12 adk-bot

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

adk-bot avatar Dec 26 '25 06:12 adk-bot

I believe the issue is happening inside the MCP client library: the StreamableHTTP transport silently returns instead of raising an error when it exceeds the maximum reconnection attempts, leaving the agent waiting indefinitely on a dead read stream.

To fix, we may have to add a fix to MCP to raise on reconnection failure, which we can then propagate to the background session task

wukath avatar Jul 15 '26 21:07 wukath

Closing this issue as resolved in google-adk.

  1. Runtime hang fix: MCPSessionManager and SessionContext (google/adk/tools/mcp_tool/session_context.py and google/adk/tools/mcp_tool/mcp_session_manager.py) now enforce connection/handshake timeouts and race in-flight MCP calls against the background streamable HTTP transport task (SessionContext._run_guarded). When the underlying transport task exits or fails (such as after failed reconnection attempts or auth/redirect errors), ADK immediately cancels the pending wait and raises a ConnectionError instead of hanging until sse_read_timeout.
  2. Cloud Run URL tip: In the logs shared above (POST https://.../mcp ""HTTP/1.1 307 Temporary Redirect"" -> http://.../mcp/ -> 302 Found -> GET https://.../mcp/), FastAPI/Starlette redirects /mcp to /mcp/ (with a trailing slash) over http:// when proxy headers aren't trusted, which converts the POST into a GET and strips the Authorization header. Passing url=""https://<service>.run.app/mcp/"" (with the trailing slash) in StreamableHTTPConnectionParams avoids the 307/302 redirect chain.

wukath avatar Oct 07 '26 18:10 wukath