Skip to content

"Vibe-Trading: Your Personal Trading Agent"

feat(mcp): add Streamable HTTP transport for modern clients

HUANG Cheng06d742c4b687
diff --git a/README.md b/README.md
index 5f4e75120..3b6c45f35 100644
--- a/README.md
+++ b/README.md
@@ -967,10 +967,18 @@ profile. `run_swarm` requires an LLM key.
<summary><b>Cursor / Windsurf / other MCP clients</b></summary>
```bash
-vibe-trading-mcp # stdio (default)
-vibe-trading-mcp --transport sse # SSE for web clients
+vibe-trading-mcp # stdio (default)
+vibe-trading-mcp --transport http # Streamable HTTP (current MCP spec default) at http://127.0.0.1:8900/mcp
+vibe-trading-mcp --transport sse # legacy SSE (deprecated) for older clients
```
+For HTTP clients (QwenPaw, and any client that negotiates by POSTing an
+`InitializeRequest`), use `--transport http` and point the client at the single
+`/mcp` endpoint — e.g. `http://127.0.0.1:8900/mcp`. Do **not** point an HTTP
+client at `/sse`; that path belongs to the deprecated two-endpoint SSE transport
+and will return `405 Method Not Allowed` on `POST`. Override the bind address
+with `--host` / `--port`.
+
</details>
**MCP tools exposed (54):** `list_skills`, `load_skill`, `start_research_goal`, `get_research_goal`, `add_goal_evidence`, `update_research_goal_status`, `backtest`, `factor_analysis`, `analyze_options`, `pattern_recognition`, `read_url`, `read_document`, `web_search`, `write_file`, `read_file`, `trading_connections`, `trading_select_connection`, `trading_check`, `trading_account`, `trading_positions`, `trading_orders`, `trading_quote`, `trading_history`, `list_swarm_presets`, `run_swarm`, `get_market_data`, `get_fund_flow`, `get_dragon_tiger`, `get_northbound_flow`, `get_margin_trading`, `get_block_trades`, `get_shareholder_count`, `get_lockup_expiry`, `get_sector_info`, `get_research_reports`, `get_stock_news`, `get_sec_filings`, `get_financial_statements`, `get_options_chain`, `get_stock_profile`, `screen_market`, `search_symbol`, `get_macro_series`, `iwencai_search`, `get_swarm_status`, `get_run_result`, `list_runs`, `reap_stale_runs`, `retry_run`, `analyze_trade_journal`, `extract_shadow_strategy`, `run_shadow_backtest`, `render_shadow_report`, `scan_shadow_signals`.
diff --git a/README_ar.md b/README_ar.md
index 4fa35abb2..bf5066710 100644
--- a/README_ar.md
+++ b/README_ar.md
@@ -934,8 +934,9 @@ skills:
<summary><b>Cursor / Windsurf / عملاء MCP آخرون</b></summary>
```bash
-vibe-trading-mcp # stdio (default)
-vibe-trading-mcp --transport sse # SSE for web clients
+vibe-trading-mcp # stdio (default)
+vibe-trading-mcp --transport http # Streamable HTTP (spec default) at /mcp
+vibe-trading-mcp --transport sse # legacy SSE (deprecated)
```
</details>
diff --git a/README_ja.md b/README_ja.md
index aa6f629e1..d81a2cd44 100644
--- a/README_ja.md
+++ b/README_ja.md
@@ -931,8 +931,9 @@ skills:
<summary><b>Cursor / Windsurf / other MCP clients</b></summary>
```bash
-vibe-trading-mcp # stdio (default)
-vibe-trading-mcp --transport sse # SSE for web clients
+vibe-trading-mcp # stdio (default)
+vibe-trading-mcp --transport http # Streamable HTTP (spec default) at /mcp
+vibe-trading-mcp --transport sse # legacy SSE (deprecated)
```
</details>
diff --git a/README_ko.md b/README_ko.md
index eb7fae91a..a017ab741 100644
--- a/README_ko.md
+++ b/README_ko.md
@@ -934,8 +934,9 @@ skills:
<summary><b>Cursor / Windsurf / 기타 MCP clients</b></summary>
```bash
-vibe-trading-mcp # stdio (default)
-vibe-trading-mcp --transport sse # SSE for web clients
+vibe-trading-mcp # stdio (default)
+vibe-trading-mcp --transport http # Streamable HTTP (spec default) at /mcp
+vibe-trading-mcp --transport sse # legacy SSE (deprecated)
```
</details>
diff --git a/README_zh.md b/README_zh.md
index d1ba4a5b8..54212824d 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -928,8 +928,9 @@ skills:
<summary><b>Cursor / Windsurf / other MCP clients</b></summary>
```bash
-vibe-trading-mcp # stdio (default)
-vibe-trading-mcp --transport sse # SSE for web clients
+vibe-trading-mcp # stdio (default)
+vibe-trading-mcp --transport http # Streamable HTTP (spec default) at /mcp
+vibe-trading-mcp --transport sse # legacy SSE (deprecated)
```
</details>
diff --git a/agent/mcp_server.py b/agent/mcp_server.py
index 7befdb1da..5a4e7218a 100644
--- a/agent/mcp_server.py
+++ b/agent/mcp_server.py
@@ -19,7 +19,14 @@ order-cancelling tool is ever surfaced via MCP.
Usage:
python mcp_server.py # stdio transport (default)
- python mcp_server.py --transport sse # SSE transport for web clients
+ python mcp_server.py --transport sse # legacy SSE transport (GET /sse + POST /messages/)
+ python mcp_server.py --transport http # Streamable HTTP transport (single POST/GET /mcp endpoint)
+
+The ``http`` (Streamable HTTP) transport is the current MCP spec default
+(2025-03-26+). Modern clients (e.g. QwenPaw, and clients that negotiate by
+POSTing an InitializeRequest) require it; the legacy ``sse`` transport is
+deprecated. The single endpoint is served at ``/mcp``, so point HTTP clients
+at ``http://<host>:<port>/mcp`` (NOT ``/sse``, which is a legacy-SSE artifact).
OpenClaw config (~/.openclaw/config.yaml):
skills:
@@ -1895,8 +1902,21 @@ def main():
import argparse
parser = argparse.ArgumentParser(description="Vibe-Trading MCP Server")
- parser.add_argument("--transport", choices=["stdio", "sse"], default="stdio", help="MCP transport (default: stdio)")
- parser.add_argument("--port", type=int, default=8900, help="SSE port (only used with --transport sse)")
+ parser.add_argument(
+ "--transport",
+ choices=["stdio", "sse", "http"],
+ default="stdio",
+ help="MCP transport (default: stdio). 'http' = Streamable HTTP (current spec default), "
+ "served at POST/GET /mcp. 'sse' = legacy deprecated SSE (GET /sse + POST /messages/).",
+ )
+ parser.add_argument(
+ "--host",
+ default="127.0.0.1",
+ help="Streamable HTTP bind host, --transport http only (default: 127.0.0.1)",
+ )
+ parser.add_argument(
+ "--port", type=int, default=8900, help="SSE/HTTP port (default: 8900)"
+ )
args = parser.parse_args()
_include_shell_tools = True if args.transport == "stdio" else _env_shell_tools_enabled()
_registry = None
@@ -1904,6 +1924,11 @@ def main():
if args.transport == "sse":
mcp.run(transport="sse", port=args.port)
+ elif args.transport == "http":
+ # Streamable HTTP (MCP spec 2025-03-26+): single endpoint at /mcp that
+ # accepts POST (requests) and GET (notification stream). Replaces the
+ # deprecated two-endpoint SSE transport for modern clients.
+ mcp.run(transport="streamable-http", host=args.host, port=args.port)
else:
mcp.run()
diff --git a/agent/tests/test_mcp_server_http_transport.py b/agent/tests/test_mcp_server_http_transport.py
new file mode 100644
index 000000000..c913e972d
--- /dev/null
+++ b/agent/tests/test_mcp_server_http_transport.py
@@ -0,0 +1,137 @@
+"""Integration test for the Vibe-Trading MCP server's Streamable HTTP transport.
+
+Spawns the real ``mcp_server.py --transport http`` and verifies the single
+``/mcp`` endpoint behaves per the MCP Streamable HTTP transport:
+
+1. POST ``initialize`` returns a valid JSON-RPC InitializeResult with an
+ ``MCP-Session-Id`` header.
+2. The legacy ``/sse`` path is not mounted by this transport (it is only
+ exposed by the separate ``--transport sse`` legacy mode).
+
+This is intentionally scoped to the server-side transport; the client-side
+adapter path is already covered by ``test_mcp_streamable_http_integration.py``.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+import socket
+import subprocess
+import sys
+import time
+from pathlib import Path
+
+import pytest
+import requests
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+AGENT_DIR = REPO_ROOT / "agent"
+
+INIT_TIMEOUT = 60.0
+
+
+def _wait_port(host: str, port: int, timeout: float) -> bool:
+ deadline = time.time() + timeout
+ while time.time() < deadline:
+ s = socket.socket()
+ s.settimeout(0.5)
+ try:
+ if s.connect_ex((host, port)) == 0:
+ s.close()
+ return True
+ finally:
+ s.close()
+ time.sleep(0.5)
+ return False
+
+
+def test_mcp_server_http_transport() -> None:
+ env = os.environ.copy()
+ env["PYTHONPATH"] = str(AGENT_DIR) + os.pathsep + env.get("PYTHONPATH", "")
+ env["PYTHONUNBUFFERED"] = "1"
+
+ # Reserve an ephemeral loopback port for the server.
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ sock.bind(("127.0.0.1", 0))
+ port = int(sock.getsockname()[1])
+
+ proc = subprocess.Popen(
+ [
+ sys.executable,
+ str(AGENT_DIR / "mcp_server.py"),
+ "--transport",
+ "http",
+ "--port",
+ str(port),
+ ],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ text=True,
+ env=env,
+ cwd=str(AGENT_DIR),
+ )
+ try:
+ assert _wait_port(
+ "127.0.0.1", port, INIT_TIMEOUT
+ ), f"HTTP MCP server did not bind 127.0.0.1:{port} within {INIT_TIMEOUT}s"
+
+ ep = f"http://127.0.0.1:{port}/mcp"
+ headers = {
+ "Content-Type": "application/json",
+ "Accept": "application/json, text/event-stream",
+ }
+ r = requests.post(
+ ep,
+ headers=headers,
+ json={
+ "jsonrpc": "2.0",
+ "id": 1,
+ "method": "initialize",
+ "params": {
+ "protocolVersion": "2025-03-26",
+ "capabilities": {},
+ "clientInfo": {"name": "test-mcp-server-http", "version": "1"},
+ },
+ },
+ timeout=15.0,
+ )
+ assert (
+ r.status_code == 200
+ ), f"POST /mcp initialize returned {r.status_code}: {r.text[:300]}"
+ assert (
+ "mcp-session-id" in r.headers
+ ), "server did not return an MCP-Session-Id header"
+ assert r.headers.get("content-type", "") in (
+ "application/json",
+ "text/event-stream",
+ ), f"unexpected content-type: {r.headers.get('content-type')}"
+ body = r.text
+ if "text/event-stream" in r.headers.get("content-type", ""):
+ for line in body.splitlines():
+ if line.startswith("data:"):
+ body = line[5:].strip()
+ break
+ data = json.loads(body)
+ assert "result" in data, f"initialize response missing result: {data}"
+ server_info = data["result"].get("serverInfo", {})
+ assert server_info.get("name") == "Vibe-Trading", server_info
+
+ # The legacy SSE path is not mounted by the streamable-http transport.
+ legacy = requests.post(
+ f"http://127.0.0.1:{port}/sse",
+ headers=headers,
+ json={"jsonrpc": "2.0", "id": 9, "method": "initialize", "params": {}},
+ timeout=5.0,
+ )
+ assert (
+ legacy.status_code == 404
+ ), f"legacy /sse path should not be mounted by streamable-http, got {legacy.status_code}"
+ finally:
+ try:
+ proc.terminate()
+ proc.wait(timeout=5)
+ except subprocess.TimeoutExpired:
+ proc.kill()
+ proc.wait(timeout=5)