You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
908 B
908 B
Multi MCP Execution Example
This example demonstrates using a list of MCP servers with an Agent
.
Start the example servers in separate terminals:
python examples/tools/mcp_examples/servers/weather_server.py
python examples/tools/mcp_examples/servers/news_server.py
import os
import json
from swarms import Agent
# Configure multiple MCP URLs
os.environ["MCP_URLS"] = "http://localhost:8000/sse,http://localhost:9001/sse"
agent = Agent(
agent_name="Multi-MCP-Agent",
model_name="gpt-4o-mini",
max_loops=1,
)
# Example JSON payloads produced by your model
response = json.dumps([
{"function_name": "get_weather", "server_url": "http://localhost:8000/sse", "payload": {"city": "London"}},
{"function_name": "get_news", "server_url": "http://localhost:9001/sse", "payload": {"topic": "ai"}},
])
agent.handle_multiple_mcp_tools(agent.mcp_urls, response)