-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
agent engine[Component] This issue is related to Agent Engine deployment[Component] This issue is related to Agent Engine deploymentbot triaged[Bot] This issue is triaged by ADK bot[Bot] This issue is triaged by ADK botmcp[Component] Issues about MCP support[Component] Issues about MCP supportneed attention[Status] This issue is important but the maintainers haven't started working on it[Status] This issue is important but the maintainers haven't started working on it
Milestone
Description
Issue Description
Deploying an ADK agent with MCPToolset to Vertex AI Agent Engine fails with TypeError: cannot pickle 'TextIOWrapper' instances
. The agent works perfectly in local development but cannot be deployed due to serialization issues during the deepcopy process.
Steps to reproduce the behavior:
- Create an ADK agent with MCPToolset using SseServerParams
- Wrap the agent with reasoning_engines.AdkApp
- Deploy to Agent Engine using agent_engines.create()
- See error:
TypeError: cannot pickle 'TextIOWrapper' instances
Code to reproduce:
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
from google.adk.tools.mcp_tool.mcp_session_manager import SseServerParams
from google.adk.agents import LlmAgent
import vertexai
from vertexai import agent_engines
from vertexai.preview import reasoning_engines
PROJECT_ID = "your-project-id"
LOCATION = "your-deployment-location"
STAGING_BUCKET = "gs://your-staging-bucket"
vertexai.init(
project=PROJECT_ID,
location=LOCATION,
staging_bucket=STAGING_BUCKET,
)
root_agent = LlmAgent(
name="WikipediaQueryAgent",
model="gemini-2.0-flash",
description="An AI agent that can query Wikipedia",
instruction="You are a helpful agent who can answer user questions.",
tools=[
MCPToolset(
connection_params=SseServerParams(
url="<your-MCP-Server-URL>/sse"
)
)
]
)
app = reasoning_engines.AdkApp(
agent=root_agent,
enable_tracing=False,
)
# This line fails with serialization error
remote_app = agent_engines.create(
agent_engine=app,
requirements=[
"google-cloud-aiplatform[adk,agent_engines]",
"google-adk[mcp]"
]
)
Expected behavior
The agent should deploy successfully to Agent Engine. MCPToolset is documented as a supported tool type for ADK agents, so deployment should work without serialization errors.
Screenshots
Error traceback:
Deploying to Agent Engine...
Traceback (most recent call last):
File "agent1.py", line 47, in <module>
remote_app = agent_engines.create(
^^^^^^^^^^^^^^^^^^^^^
File ".../vertexai/agent_engines/__init__.py", line 148, in create
return AgentEngine.create(
^^^^^^^^^^^^^^^^^^^
File ".../vertexai/agent_engines/_agent_engines.py", line 422, in create
agent_engine = _validate_agent_engine_or_raise(agent_engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../vertexai/agent_engines/_agent_engines.py", line 863, in _validate_agent_engine_or_raise
agent_engine = agent_engine.clone()
^^^^^^^^^^^^^^^^^^^^
File ".../vertexai/preview/reasoning_engines/templates/adk.py", line 418, in clone
agent=copy.deepcopy(self._tmpl_attrs.get("agent")),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../copy.py", line 151, in deepcopy
rv = reductor(4)
^^^^^^^^^^^
TypeError: cannot pickle 'TextIOWrapper' instances
Versions
- OS: macOS
- ADK version: latest (installed via
pip install google-adk[mcp]
) - Python version: 3.12.7
Additional context
- The MCP server is deployed on Cloud Run and is publicly accessible
- The same agent works perfectly when run locally with
adk run
oradk web
- This blocks production deployment of any ADK agents using MCP tools
- Attempted workarounds:
- Using AdkApp wrapper (shown in code above) - still fails
- Downgrading from Python 3.13 to 3.12.7 - still fails
Is there a recommended pattern for deploying agents with MCPToolset to Agent Engine? The current behavior seems to make it impossible to deploy any agent using MCP tools.
Metadata
Metadata
Assignees
Labels
agent engine[Component] This issue is related to Agent Engine deployment[Component] This issue is related to Agent Engine deploymentbot triaged[Bot] This issue is triaged by ADK bot[Bot] This issue is triaged by ADK botmcp[Component] Issues about MCP support[Component] Issues about MCP supportneed attention[Status] This issue is important but the maintainers haven't started working on it[Status] This issue is important but the maintainers haven't started working on it