You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print(f"Connected to npx mermaid MCP server. Found {len(mermaid_tools)} tools.")
142
+
fortoolsetin_ACTIVE_TOOLSETS:
143
+
try:
144
+
awaittoolset.close()
145
+
print("MCP toolset connection closed.")
146
+
exceptasyncio.CancelledError:
147
+
print("MCP cleanup cancelled - this is normal")
148
+
exceptExceptionase:
149
+
print(f"Warning: Error during toolset cleanup: {e}")
92
150
93
-
# Combine tools from both servers
94
-
all_tools=local_tools+mermaid_tools
95
-
print(f"Total tools available: {len(all_tools)}")
151
+
_ACTIVE_TOOLSETS= []
96
152
97
-
returnall_tools, toolsets
153
+
154
+
# Define a before_agent_callback to attach tools
155
+
asyncdefattach_tools_callback(callback_context):
156
+
"""Callback to attach tools to the agent before it runs.
157
+
158
+
Args:
159
+
callback_context: The callback context from ADK.
160
+
161
+
Returns:
162
+
None: The callback doesn't modify the content.
163
+
"""
164
+
awaitensure_tools_attached()
165
+
returnNone
166
+
167
+
168
+
# This is the agent that will be imported by the ADK web UI
169
+
root_agent=LlmAgent(
170
+
model="gemini-2.0-flash",
171
+
name="multi_mcp_adk_assistant",
172
+
instruction="You are an assistant that uses multiple MCP servers to help users. You have access to both a Python MCP server with time tools and a Mermaid diagram validator.",
173
+
before_agent_callback=attach_tools_callback, # This ensures tools are attached
174
+
)
175
+
176
+
177
+
# Function to dynamically attach tools to the agent
178
+
asyncdefensure_tools_attached():
179
+
"""Ensures that tools are attached to the agent before it's used."""
180
+
globalTOOLS_ATTACHED
181
+
182
+
ifnotTOOLS_ATTACHED:
183
+
try:
184
+
tools, _=awaitget_tools_async()
185
+
print(f"✓ Connected to MCP servers. Found {len(tools)} tools.")
0 commit comments