-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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:
- Deploy a sample MCP server on Cloud Run that supports streamable HTTP
- Run the code above in test 1 and test 2
- 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