Spaces:
Sleeping
Sleeping
File size: 1,837 Bytes
bd648ce 5b448dc bd648ce 5b448dc 5457bae bd648ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import asyncio
import sys
import json
from pathlib import Path
from google.adk.agents import LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters
try:
from test_failure_analysis.tfa_prompt import TFA_MCP_PROMPT
except ImportError:
from tfa_prompt import TFA_MCP_PROMPT
# Fix for Windows subprocess support
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
# Load JSON config
CONFIG_PATH = Path(__file__).resolve().parent / "mcp_config.json"
with open(CONFIG_PATH, "r") as f:
mcp_config = json.load(f)["mcpServers"]
# # Create a list of MCPToolset instances for each server
# toolsets = []
# for name, config in mcp_config.items():
# print(f"Adding MCP Server: {name}")
# toolsets.append(
# MCPToolset(
# connection_params=StdioServerParameters(
# command=config["command"],
# args=config["args"]
# )
# )
# )
# Create a list of MCPToolset instances for each server
toolsets = []
for name, config in mcp_config.items():
print(f"Adding MCP Server: {name}")
try:
toolset = MCPToolset(
connection_params=StdioServerParameters(
server_params={
"command": "python",
"args": ["sponge_mcp_server.py"]
}
)
)
print(f"→ Toolset created for {name}: {toolset}")
toolsets.append(toolset)
except Exception as e:
print(f"✗ Failed to create toolset for {name}: {e}")
continue
# Build the root agent with all MCP servers
root_agent = LlmAgent(
model="gemini-2.5-flash",
name="test_failure_analysis_agent",
instruction=TFA_MCP_PROMPT,
tools=toolsets # Multiple MCP servers
)
|