[SSE -> STREAMABLE HTTP MIGRATION]

pull/1083/head
Kye Gomez 4 weeks ago
parent 3ca31670f0
commit 807b0b8990

@ -33705,7 +33705,7 @@ The **Model Context Protocol (MCP)** integration enables Swarms agents to dynami
agent_name="Financial-Analysis-Agent",
agent_description="AI-powered financial advisor",
max_loops=1,
mcp_url="http://localhost:8000/sse", # Your MCP server
mcp_url="http://localhost:8000/mcp", # Your MCP server
output_type="all",
)
@ -33729,7 +33729,7 @@ The **Model Context Protocol (MCP)** integration enables Swarms agents to dynami
agent_description="Comprehensive market analysis agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=3,
mcp_url="http://production-server:8000/sse",
mcp_url="http://production-server:8000/mcp",
output_type="json",
# Additional parameters for production
temperature=0.1,
@ -33805,7 +33805,7 @@ graph TD
| Parameter | Type | Description | Default | Example |
|-----------|------|-------------|---------|---------|
| `mcp_url` | `str` | MCP server endpoint | `None` | `"http://localhost:8000/sse"` |
| `mcp_url` | `str` | MCP server endpoint | `None` | `"http://localhost:8000/mcp"` |
| `output_type` | `str` | Response format | `"str"` | `"json"`, `"all"`, `"dict"` |
| `max_loops` | `int` | Execution iterations | `1` | `3` |
| `temperature` | `float` | Response creativity | `0.1` | `0.1-1.0` |
@ -33826,7 +33826,7 @@ graph TD
agent_name="Crypto-Trading-Agent",
agent_description="Real-time cryptocurrency market analyzer",
max_loops=2,
mcp_url="http://crypto-server:8000/sse",
mcp_url="http://crypto-server:8000/mcp",
output_type="json",
temperature=0.1,
)
@ -33853,7 +33853,7 @@ graph TD
agent_description="Comprehensive financial market analyst",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=4,
mcp_url="http://finance-api:8000/sse",
mcp_url="http://finance-api:8000/mcp",
output_type="all",
temperature=0.2,
)
@ -33881,7 +33881,7 @@ graph TD
agent_name="Healthcare-Data-Agent",
agent_description="Medical data analysis and research assistant",
max_loops=3,
mcp_url="http://medical-api:8000/sse",
mcp_url="http://medical-api:8000/mcp",
output_type="dict",
system_prompt="""
You are a healthcare data analyst. Use available medical databases
@ -34008,14 +34008,14 @@ graph TD
from swarms.schemas.mcp_schemas import MCPConnection
mcp_config = MCPConnection(
url="http://server:8000/sse",
url="http://server:8000/mcp",
headers={"Authorization": "Bearer token"},
timeout=30,
retry_attempts=3
)
# ✅ Use direct URL instead
mcp_url = "http://server:8000/sse"
mcp_url = "http://server:8000/mcp"
```
### 🚧 Single Server Limitation
@ -34025,12 +34025,12 @@ graph TD
```python
# ❌ Multiple servers not supported
mcp_servers = [
"http://server1:8000/sse",
"http://server2:8000/sse"
"http://server1:8000/mcp",
"http://server2:8000/mcp"
]
# ✅ Single server only
mcp_url = "http://primary-server:8000/sse"
mcp_url = "http://primary-server:8000/mcp"
```
### 🚧 Sequential Execution
@ -34056,7 +34056,7 @@ graph TD
**Solutions**:
```bash
# Check server status
curl -I http://localhost:8000/sse
curl -I http://localhost:8000/mcp
# Verify port is open
netstat -tulpn | grep :8000
@ -34125,7 +34125,7 @@ graph TD
```python
# Increase timeout
agent = Agent(
mcp_url="http://server:8000/sse",
mcp_url="http://server:8000/mcp",
timeout=60, # seconds
)
@ -34158,7 +34158,7 @@ graph TD
agent = Agent(
agent_name="Debug-Agent",
mcp_url="http://localhost:8000/sse",
mcp_url="http://localhost:8000/mcp",
verbose=True, # Enable verbose output
output_type="all", # Get full execution trace
)
@ -34213,7 +34213,7 @@ graph TD
# Environment variables (.env file)
"""
MCP_SERVER_URL=https://secure-server.company.com/sse
MCP_SERVER_URL=https://secure-server.company.com/mcp
MCP_API_KEY=your-secure-api-key
MCP_TIMEOUT=30
"""
@ -34353,7 +34353,7 @@ graph TD
agent = Agent(
agent_name="Your-Agent",
mcp_url="http://localhost:8000/sse",
mcp_url="http://localhost:8000/mcp",
output_type="json",
max_loops=2
)
@ -53166,7 +53166,7 @@ def get_okx_crypto_volume(symbol: str) -> str:
```python
if __name__ == "__main__":
# Run the MCP server with SSE (Server-Sent Events) transport
# Server will be available at http://localhost:8001/sse
# Server will be available at http://localhost:8001/mcp
mcp.run(transport="sse")
```
@ -53176,7 +53176,7 @@ if __name__ == "__main__":
from swarms import Agent
# Method 2: Using direct URL (simpler for development)
mcp_url = "http://0.0.0.0:8001/sse"
mcp_url = "http://0.0.0.0:8001/mcp"
# Initialize agent with MCP tools
agent = Agent(
@ -58363,7 +58363,7 @@ async def swarm_completion():
"""Connect to a server over SSE and fetch available swarms."""
async with Client(
transport="http://localhost:8000/sse"
transport="http://localhost:8000/mcp"
) as client:
# Basic connectivity testing
# print("Ping check:", await client.ping())
@ -68979,7 +68979,7 @@ let agent = client
.add_stdio_mcp_server("uvx", ["mcp-hn"])
.await
// Add SSE MCP server
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/sse")
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/mcp")
.await
.build();
```
@ -69016,7 +69016,7 @@ async fn main() -> Result<()> {
.await
// Add filesystem tool
// To set up: uvx mcp-proxy --sse-port=8000 -- npx -y @modelcontextprotocol/server-filesystem ~
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/sse")
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/mcp")
.await
.retry_attempts(2)
.max_loops(3)

@ -93,7 +93,7 @@ The **Model Context Protocol (MCP)** integration enables Swarms agents to dynami
agent_name="Financial-Analysis-Agent",
agent_description="AI-powered financial advisor",
max_loops=1,
mcp_url="http://localhost:8000/sse", # Your MCP server
mcp_url="http://localhost:8000/mcp", # Your MCP server
output_type="all",
)
@ -117,7 +117,7 @@ The **Model Context Protocol (MCP)** integration enables Swarms agents to dynami
agent_description="Comprehensive market analysis agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=3,
mcp_url="http://production-server:8000/sse",
mcp_url="http://production-server:8000/mcp",
output_type="json",
# Additional parameters for production
temperature=0.1,
@ -193,7 +193,7 @@ graph TD
| Parameter | Type | Description | Default | Example |
|-----------|------|-------------|---------|---------|
| `mcp_url` | `str` | MCP server endpoint | `None` | `"http://localhost:8000/sse"` |
| `mcp_url` | `str` | MCP server endpoint | `None` | `"http://localhost:8000/mcp"` |
| `output_type` | `str` | Response format | `"str"` | `"json"`, `"all"`, `"dict"` |
| `max_loops` | `int` | Execution iterations | `1` | `3` |
| `temperature` | `float` | Response creativity | `0.1` | `0.1-1.0` |
@ -214,7 +214,7 @@ graph TD
agent_name="Crypto-Trading-Agent",
agent_description="Real-time cryptocurrency market analyzer",
max_loops=2,
mcp_url="http://crypto-server:8000/sse",
mcp_url="http://crypto-server:8000/mcp",
output_type="json",
temperature=0.1,
)
@ -241,7 +241,7 @@ graph TD
agent_description="Comprehensive financial market analyst",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=4,
mcp_url="http://finance-api:8000/sse",
mcp_url="http://finance-api:8000/mcp",
output_type="all",
temperature=0.2,
)
@ -269,7 +269,7 @@ graph TD
agent_name="Healthcare-Data-Agent",
agent_description="Medical data analysis and research assistant",
max_loops=3,
mcp_url="http://medical-api:8000/sse",
mcp_url="http://medical-api:8000/mcp",
output_type="dict",
system_prompt="""
You are a healthcare data analyst. Use available medical databases
@ -396,14 +396,14 @@ graph TD
from swarms.schemas.mcp_schemas import MCPConnection
mcp_config = MCPConnection(
url="http://server:8000/sse",
url="http://server:8000/mcp",
headers={"Authorization": "Bearer token"},
timeout=30,
retry_attempts=3
)
# ✅ Use direct URL instead
mcp_url = "http://server:8000/sse"
mcp_url = "http://server:8000/mcp"
```
### 🚧 Single Server Limitation
@ -413,12 +413,12 @@ graph TD
```python
# ❌ Multiple servers not supported
mcp_servers = [
"http://server1:8000/sse",
"http://server2:8000/sse"
"http://server1:8000/mcp",
"http://server2:8000/mcp"
]
# ✅ Single server only
mcp_url = "http://primary-server:8000/sse"
mcp_url = "http://primary-server:8000/mcp"
```
### 🚧 Sequential Execution
@ -444,7 +444,7 @@ graph TD
**Solutions**:
```bash
# Check server status
curl -I http://localhost:8000/sse
curl -I http://localhost:8000/mcp
# Verify port is open
netstat -tulpn | grep :8000
@ -513,7 +513,7 @@ graph TD
```python
# Increase timeout
agent = Agent(
mcp_url="http://server:8000/sse",
mcp_url="http://server:8000/mcp",
timeout=60, # seconds
)
@ -546,7 +546,7 @@ graph TD
agent = Agent(
agent_name="Debug-Agent",
mcp_url="http://localhost:8000/sse",
mcp_url="http://localhost:8000/mcp",
verbose=True, # Enable verbose output
output_type="all", # Get full execution trace
)
@ -601,7 +601,7 @@ graph TD
# Environment variables (.env file)
"""
MCP_SERVER_URL=https://secure-server.company.com/sse
MCP_SERVER_URL=https://secure-server.company.com/mcp
MCP_API_KEY=your-secure-api-key
MCP_TIMEOUT=30
"""
@ -741,7 +741,7 @@ graph TD
agent = Agent(
agent_name="Your-Agent",
mcp_url="http://localhost:8000/sse",
mcp_url="http://localhost:8000/mcp",
output_type="json",
max_loops=2
)

@ -477,7 +477,7 @@ def get_okx_crypto_volume(symbol: str) -> str:
```python
if __name__ == "__main__":
# Run the MCP server with SSE (Server-Sent Events) transport
# Server will be available at http://localhost:8001/sse
# Server will be available at http://localhost:8001/mcp
mcp.run(transport="sse")
```
@ -487,7 +487,7 @@ if __name__ == "__main__":
from swarms import Agent
# Method 2: Using direct URL (simpler for development)
mcp_url = "http://0.0.0.0:8001/sse"
mcp_url = "http://0.0.0.0:8001/mcp"
# Initialize agent with MCP tools
agent = Agent(

@ -198,7 +198,7 @@ let agent = client
.add_stdio_mcp_server("uvx", ["mcp-hn"])
.await
// Add SSE MCP server
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/sse")
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/mcp")
.await
.build();
```
@ -235,7 +235,7 @@ async fn main() -> Result<()> {
.await
// Add filesystem tool
// To set up: uvx mcp-proxy --sse-port=8000 -- npx -y @modelcontextprotocol/server-filesystem ~
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/sse")
.add_sse_mcp_server("file-browser", "http://127.0.0.1:8000/mcp")
.await
.retry_attempts(2)
.max_loops(3)

@ -3,13 +3,13 @@ from swarms.schemas.mcp_schemas import MCPConnection
mcp_config = MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
# headers={"Authorization": "Bearer 1234567890"},
timeout=5,
)
mcp_url = "http://0.0.0.0:8000/sse"
mcp_url = "http://0.0.0.0:8000/mcp"
# Initialize the agent
agent = Agent(

@ -39,8 +39,8 @@ agent = Agent(
dynamic_temperature_enabled=True,
output_type="all",
mcp_urls=[
"http://0.0.0.0:8000/sse",
"http://0.0.0.0:8001/sse",
"http://0.0.0.0:8000/mcp",
"http://0.0.0.0:8001/mcp",
],
)

@ -40,7 +40,7 @@ agent = Agent(
max_loops=2,
tools_list_dictionary=tools,
output_type="final",
mcp_url="http://0.0.0.0:8000/sse",
mcp_url="http://0.0.0.0:8000/mcp",
)
out = agent.run(

@ -44,7 +44,7 @@ agent = Agent(
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=1,
# tools_list_dictionary=tools,
# mcp_servers=["http://localhost:8000/sse"],
# mcp_servers=["http://localhost:8000/mcp"],
# output_type="dict-all-except-first",
# "dict-final",
# "dict-all-except-first",

@ -21,25 +21,25 @@ def example_sync_execution():
# Example server URLs (replace with your actual MCP server URLs)
urls = [
"http://localhost:8000/sse", # Server 1
"http://localhost:8001/sse", # Server 2
"http://localhost:8002/sse", # Server 3
"http://localhost:8000/mcp", # Server 1
"http://localhost:8001/mcp", # Server 2
"http://localhost:8002/mcp", # Server 3
]
# Optional: Create connection objects for each server
connections = [
MCPConnection(
url="http://localhost:8000/sse",
url="http://localhost:8000/mcp",
authorization_token="token1", # if needed
timeout=10,
),
MCPConnection(
url="http://localhost:8001/sse",
url="http://localhost:8001/mcp",
authorization_token="token2", # if needed
timeout=10,
),
MCPConnection(
url="http://localhost:8002/sse",
url="http://localhost:8002/mcp",
authorization_token="token3", # if needed
timeout=10,
),
@ -111,9 +111,9 @@ async def example_async_execution():
# Example server URLs
urls = [
"http://localhost:8000/sse",
"http://localhost:8001/sse",
"http://localhost:8002/sse",
"http://localhost:8000/mcp",
"http://localhost:8001/mcp",
"http://localhost:8002/mcp",
]
# Example responses with multiple tool calls in a single response
@ -190,9 +190,9 @@ def example_get_tools_from_multiple_servers():
"""Example of getting tools from multiple servers."""
urls = [
"http://localhost:8000/sse",
"http://localhost:8001/sse",
"http://localhost:8002/sse",
"http://localhost:8000/mcp",
"http://localhost:8001/mcp",
"http://localhost:8002/mcp",
]
print("\n=== Getting Tools from Multiple Servers ===")

@ -14,8 +14,8 @@ def test_async_multiple_tools_execution():
)
urls = [
"http://localhost:8000/sse",
"http://localhost:8001/sse",
"http://localhost:8000/mcp",
"http://localhost:8001/mcp",
]
# Mock responses with multiple tool calls

@ -7,10 +7,10 @@ import json
if __name__ == "__main__":
tools = get_mcp_tools_sync(
server_path="http://0.0.0.0:8000/sse",
server_path="http://0.0.0.0:8000/mcp",
format="openai",
connection=MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
headers={"Authorization": "Bearer 1234567890"},
timeout=10,
),

@ -13,12 +13,12 @@ response = {
}
connection = MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
headers={"Authorization": "Bearer 1234567890"},
timeout=10,
)
url = "http://0.0.0.0:8000/sse"
url = "http://0.0.0.0:8000/mcp"
if __name__ == "__main__":
tools = asyncio.run(

@ -7,10 +7,10 @@ from swarms.tools.mcp_client_tools import (
if __name__ == "__main__":
tools = get_mcp_tools_sync(
server_path="http://0.0.0.0:8000/sse",
server_path="http://0.0.0.0:8000/mcp",
format="openai",
connection=MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
headers={"Authorization": "Bearer 1234567890"},
timeout=10,
),

@ -5,12 +5,12 @@ from swarms.schemas.mcp_schemas import MCPConnection
mcp_config = MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
# headers={"Authorization": "Bearer 1234567890"},
timeout=5,
)
urls = ["http://0.0.0.0:8000/sse", "http://0.0.0.0:8001/sse"]
urls = ["http://0.0.0.0:8000/mcp", "http://0.0.0.0:8001/mcp"]
out = get_tools_for_multiple_mcp_servers(
urls=urls,

@ -13,7 +13,7 @@ Prerequisites:
npm run build
npm start
2. The server will start on http://localhost:3000/sse
2. The server will start on http://localhost:3000/mcp
Features:
- Automatic tool discovery from MCP server
@ -41,7 +41,7 @@ class StagehandMCPAgent:
def __init__(
self,
agent_name: str = "StagehandMCPAgent",
mcp_server_url: str = "http://localhost:3000/sse",
mcp_server_url: str = "http://localhost:3000/mcp",
model_name: str = "gpt-4o-mini",
max_loops: int = 1,
):
@ -91,7 +91,7 @@ class MultiSessionBrowserSwarm:
def __init__(
self,
mcp_server_url: str = "http://localhost:3000/sse",
mcp_server_url: str = "http://localhost:3000/mcp",
num_agents: int = 3,
):
"""
@ -165,7 +165,7 @@ if __name__ == "__main__":
print("Stagehand MCP Server Integration Examples")
print("=" * 70)
print(
"\nMake sure the Stagehand MCP server is running on http://localhost:3000/sse"
"\nMake sure the Stagehand MCP server is running on http://localhost:3000/mcp"
)
print("Run: cd stagehand-mcp-server && npm start\n")
@ -175,7 +175,7 @@ if __name__ == "__main__":
mcp_agent = StagehandMCPAgent(
agent_name="WebResearchAgent",
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
)
# Research task using MCP tools
@ -196,7 +196,7 @@ if __name__ == "__main__":
parallel_agent = StagehandMCPAgent(
agent_name="ParallelBrowserAgent",
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
)
result2 = parallel_agent.run(
@ -217,7 +217,7 @@ if __name__ == "__main__":
# Create a swarm of specialized browser agents
browser_swarm = MultiSessionBrowserSwarm(
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
num_agents=3,
)
@ -242,7 +242,7 @@ if __name__ == "__main__":
workflow_agent = StagehandMCPAgent(
agent_name="WorkflowAgent",
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
max_loops=2, # Allow more complex reasoning
)

@ -86,7 +86,7 @@ from examples.stagehand.stagehand_mcp_agent import StagehandMCPAgent
# Connect to Stagehand MCP server
mcp_agent = StagehandMCPAgent(
agent_name="WebResearchAgent",
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
)
# Use MCP tools including multi-session management

@ -271,12 +271,12 @@ class TestStagehandMCP:
mcp_agent = StagehandMCPAgent(
agent_name="TestMCPAgent",
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
model_name="gpt-4o-mini",
)
assert mcp_agent.agent.agent_name == "TestMCPAgent"
assert mcp_agent.agent.mcp_url == "http://localhost:3000/sse"
assert mcp_agent.agent.mcp_url == "http://localhost:3000/mcp"
assert mcp_agent.agent.model_name == "gpt-4o-mini"
def test_multi_session_swarm_creation(self):
@ -286,7 +286,7 @@ class TestStagehandMCP:
)
swarm = MultiSessionBrowserSwarm(
mcp_server_url="http://localhost:3000/sse",
mcp_server_url="http://localhost:3000/mcp",
num_agents=3,
)

@ -3,12 +3,12 @@ from swarms.structs.aop import AOP
aop = AOP(
name="example_system",
description="A simple example of tools, agents, and swarms",
url="http://localhost:8000/sse",
url="http://localhost:8000/mcp",
)
# print(
# aop.call_tool_or_agent(
# url="http://localhost:8000/sse",
# url="http://localhost:8000/mcp",
# name="calculator",
# arguments={"operation": "add", "x": 1, "y": 2},
# output_type="list",
@ -18,7 +18,7 @@ aop = AOP(
# print(
# aop.call_tool_or_agent_batched(
# url="http://localhost:8000/sse",
# url="http://localhost:8000/mcp",
# names=["calculator", "calculator"],
# arguments=[{"operation": "add", "x": 1, "y": 2}, {"operation": "multiply", "x": 3, "y": 4}],
# output_type="list",
@ -28,7 +28,7 @@ aop = AOP(
# print(
# aop.call_tool_or_agent_concurrently(
# url="http://localhost:8000/sse",
# url="http://localhost:8000/mcp",
# names=["calculator", "calculator"],
# arguments=[{"operation": "add", "x": 1, "y": 2}, {"operation": "multiply", "x": 3, "y": 4}],
# output_type="list",
@ -42,7 +42,7 @@ aop = AOP(
# print(aop.list_swarms())
# print(aop.list_all(url="http://localhost:8000/sse"))
# print(aop.list_all(url="http://localhost:8000/mcp"))
# print(any_to_str(aop.list_all()))

Loading…
Cancel
Save