Skip to content

Commit 6026538

Browse files
authored
add streamable http + fix sse (#8)
* feat: streamable http transport * fix: sse
1 parent e9445d6 commit 6026538

File tree

9 files changed

+1468
-78
lines changed

9 files changed

+1468
-78
lines changed

examples/proxy-anaconda/Makefile

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ help:
77
@echo "Available targets:"
88
@echo " install - Install mcp-compose and dependencies"
99
@echo " setup-auth - Check Anaconda authentication setup"
10-
@echo " install-agent - Install pydantic-ai for agent support"
11-
@echo " start-echo-sse - Start the echo MCP server in SSE mode (port 8081)"
12-
@echo " start - Start the MCP Compose with authentication"
10+
@echo " install-agent - Install pydantic-ai for agent support"
11+
@echo " start-echo-streamable-http - Start the echo MCP server in HTTP streaming mode (port 8082)"
12+
@echo " start-echo-sse - Start the echo MCP server in SSE mode (port 8081)"
13+
@echo " start - Start the MCP Compose with authentication"
1314
@echo " agent - Run the AI agent (requires composer running)"
1415
@echo " stop - Stop the MCP Compose"
1516
@echo " clean - Clean up temporary files"
@@ -31,12 +32,13 @@ install:
3132
@echo "This example demonstrates Anaconda authentication at the composer level."
3233
@echo ""
3334
@echo "Backend servers:"
34-
@echo " • mcp1.py - Calculator tools (add, subtract, multiply, divide)"
35-
@echo " • mcp2.py - Echo tools (ping, echo, reverse, uppercase, etc.)"
35+
@echo " • mcp1.py - Calculator tools (add, subtract, multiply, divide)"
36+
@echo " • mcp2_http.py - Echo tools with HTTP streaming (JSON Lines)"
37+
@echo " • mcp2_sse.py - Echo tools with SSE (alternative)"
3638
@echo ""
3739
@echo "Next steps:"
38-
@echo " 1. Set up authentication: make setup-auth"
39-
@echo " 2. Start the composer: make start"
40+
@echo " 1. Start echo server: make start-echo-streamable-http"
41+
@echo " 2. Start the composer: make start (in another terminal)"
4042
@echo " 3. Use the AI agent: make install-agent && make agent"
4143

4244
# Check authentication setup
@@ -73,6 +75,26 @@ install-agent:
7375
@echo " 1. Start composer: make start"
7476
@echo " 2. In another terminal: make agent"
7577

78+
# Start the echo MCP server in HTTP streaming mode
79+
start-echo-streamable-http:
80+
@echo "Starting Echo MCP Server in HTTP Streaming mode..."
81+
@echo ""
82+
@echo "Configuration:"
83+
@echo " • Transport: HTTP Streaming (JSON Lines)"
84+
@echo " • Port: 8082"
85+
@echo " • Endpoint: http://localhost:8082/stream"
86+
@echo " • Protocol: JSON Lines (newline-delimited JSON)"
87+
@echo ""
88+
@echo "Available endpoints:"
89+
@echo " • GET /stream - Stream MCP messages"
90+
@echo " • POST /stream - Send MCP messages"
91+
@echo " • GET /health - Health check"
92+
@echo ""
93+
@echo "Note: Keep this running in a separate terminal"
94+
@echo " Then run 'make start' to start the composer"
95+
@echo ""
96+
python mcp2_http.py
97+
7698
# Start the echo MCP server in SSE mode
7799
start-echo-sse:
78100
@echo "Starting Echo MCP Server in SSE mode..."
@@ -97,7 +119,8 @@ start:
97119
@echo " • Port: 8080"
98120
@echo ""
99121
@echo "Prerequisites:"
100-
@echo " 1. Echo SSE server must be running: make start-echo-sse"
122+
@echo " 1. Echo HTTP server must be running: make start-echo-streamable-http"
123+
@echo " (or use SSE: make start-echo-sse - requires config change)"
101124
@echo ""
102125
@echo "Note: Server starts without requiring ANACONDA_API_KEY."
103126
@echo " Clients must provide valid Anaconda bearer tokens."

examples/proxy-anaconda/README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ This configuration launches two simple Python MCP servers behind an authenticate
1818

1919
1. **Calculator Server** (`mcp1.py`) - Math operations (add, subtract, multiply, divide)
2020
- Transport: **STDIO** (managed by composer)
21-
2. **Echo Server** (`mcp2_sse.py`) - String operations (ping, echo, reverse, uppercase, lowercase, count_words)
22-
- Transport: **SSE** (standalone HTTP server on port 8081)
21+
2. **Echo Server** (`mcp2_http.py`) - String operations (ping, echo, reverse, uppercase, lowercase, count_words)
22+
- Transport: **HTTP Streaming** with JSON Lines protocol (standalone HTTP server on port 8082)
23+
- Alternative: `mcp2_sse.py` for SSE transport (port 8081)
2324

2425
Both servers:
2526
- Run in **proxy mode** (STDIO and SSE transports)
@@ -94,15 +95,22 @@ This will install:
9495
- `fastmcp` (for the demo MCP servers)
9596
- `anaconda-auth` (for token validation)
9697

97-
### 2. Start the Echo SSE Server
98+
### 2. Start the Echo HTTP Server
9899

99-
First, start the echo server in SSE mode (in a separate terminal):
100+
First, start the echo server in HTTP streaming mode (in a separate terminal):
100101

101102
```bash
102-
make start-echo-sse
103+
python mcp2_http.py
103104
```
104105

105-
This will start the echo MCP server on port 8081 with SSE transport.
106+
This will start the echo MCP server on port 8082 with HTTP streaming transport using JSON Lines protocol.
107+
108+
**Alternative: SSE Transport**
109+
```bash
110+
python mcp2_sse.py
111+
```
112+
113+
This starts the echo MCP server on port 8081 with SSE transport (uncomment the SSE config in `mcp_compose.toml` to use this).
106114

107115
### 3. Start the Composer
108116

@@ -133,10 +141,11 @@ Starting 1 server(s)...
133141
Command: python mcp1.py
134142
Status: ✓ Started
135143
136-
Connecting to 1 SSE server(s)...
144+
Connecting to 1 HTTP streaming server(s)...
137145
138146
• echo
139-
URL: http://localhost:8081/sse
147+
URL: http://localhost:8082/stream
148+
Protocol: lines
140149
Status: ✓ Connected
141150
```
142151

@@ -314,10 +323,18 @@ name = "calculator"
314323
command = ["python", "mcp1.py"]
315324
restart_policy = "never"
316325

317-
[[servers.proxied.stdio]]
326+
# HTTP Streaming transport (new!)
327+
[[servers.proxied.http]]
318328
name = "echo"
319-
command = ["python", "mcp2.py"]
320-
restart_policy = "never"
329+
url = "http://localhost:8082/stream"
330+
protocol = "lines" # Options: lines, chunked, poll
331+
timeout = 30
332+
keep_alive = true
333+
reconnect_on_failure = true
334+
max_reconnect_attempts = 10
335+
poll_interval = 2
336+
health_check_enabled = false
337+
mode = "proxy"
321338
```
322339

323340
### Key Configuration Points

0 commit comments

Comments
 (0)