Fix agent0 connectivity test to use health + key check
Use GET /api/health (instant, no LLM call) for reachability and POST /api/api_reset_chat to verify the API key is accepted. Sending a real message blocks for the full LLM round-trip (>30s). Also switch from MCP streamable-http to REST API (X-API-KEY header). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+33
-13
@@ -21,8 +21,8 @@ Configuration via environment variables (or a local .env file):
|
||||
LM_STUDIO_URL — LM Studio base URL (default: http://localhost:1234)
|
||||
LM_STUDIO_MODEL — model to use (default: first available)
|
||||
HERMES_URL — Hermes dashboard URL (default: http://localhost:50007)
|
||||
AGENT0_URL — Agent Zero base URL
|
||||
AGENT0_MCP_KEY — Agent Zero MCP token
|
||||
AGENT0_URL — Agent Zero base URL (e.g. http://localhost:50003)
|
||||
AGENT0_API_KEY — Agent Zero X-API-KEY from the agent's dashboard
|
||||
|
||||
Usage:
|
||||
python test_connectivity.py
|
||||
@@ -287,27 +287,47 @@ async def test_hermes():
|
||||
# ── Agent Zero ────────────────────────────────────────────────────────────────
|
||||
|
||||
async def test_agent0():
|
||||
section("Agent Zero (MCP)")
|
||||
section("Agent Zero (REST)")
|
||||
base_url = os.environ.get("AGENT0_URL", "")
|
||||
mcp_key = os.environ.get("AGENT0_MCP_KEY", "")
|
||||
api_key = os.environ.get("AGENT0_API_KEY", "")
|
||||
|
||||
if not base_url or not mcp_key:
|
||||
skip("MCP endpoint", "AGENT0_URL and AGENT0_MCP_KEY not set")
|
||||
if not base_url or not api_key:
|
||||
skip("api_message endpoint", "AGENT0_URL and AGENT0_API_KEY not set")
|
||||
return
|
||||
|
||||
mcp_url = f"{base_url.rstrip('/')}/mcp/t-{mcp_key}/http"
|
||||
url = f"{base_url.rstrip('/')}/api/api_message"
|
||||
|
||||
health_url = f"{base_url.rstrip('/')}/api/health"
|
||||
|
||||
import httpx
|
||||
try:
|
||||
# Step 1: health check (no auth needed, fast)
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
r = await client.get(mcp_url, headers={"Accept": "application/json"})
|
||||
rh = await client.get(health_url)
|
||||
|
||||
if r.status_code in (200, 405):
|
||||
ok("MCP endpoint reachable", f"HTTP {r.status_code} at {mcp_url}")
|
||||
elif r.status_code == 401:
|
||||
fail("Bad MCP key", f"HTTP {r.status_code}")
|
||||
if rh.status_code != 200:
|
||||
fail("Health endpoint", f"HTTP {rh.status_code}")
|
||||
return
|
||||
|
||||
info = rh.json()
|
||||
version = info.get("gitinfo", {}).get("version", "unknown")
|
||||
ok(f"Reachable ({version})", health_url)
|
||||
|
||||
# Step 2: verify API key is accepted via api_reset_chat (fast, no LLM call)
|
||||
reset_url = f"{base_url.rstrip('/')}/api/api_reset_chat"
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
rk = await client.post(
|
||||
reset_url,
|
||||
headers={"X-API-KEY": api_key, "Content-Type": "application/json"},
|
||||
json={},
|
||||
)
|
||||
|
||||
if rk.status_code == 200:
|
||||
ok("API key accepted", f"HTTP {rk.status_code}")
|
||||
elif rk.status_code in (401, 403):
|
||||
fail("Bad API key", f"HTTP {rk.status_code}")
|
||||
else:
|
||||
ok("MCP endpoint reachable", f"HTTP {r.status_code}")
|
||||
ok("API key accepted", f"HTTP {rk.status_code}")
|
||||
|
||||
except httpx.ConnectError as e:
|
||||
fail("Not reachable", str(e)[:120])
|
||||
|
||||
Reference in New Issue
Block a user