Skip to content

Commit 33c1c3a

Browse files
committed
refactor: remove health check and rely on MCP session initialization
The /health endpoint has session authentication requirements that make it unsuitable for pre-connection testing. Instead, we now rely on the MCP session initialization itself to verify connectivity. This simplification: - Removes unnecessary health check step - Tests the actual MCP endpoint we care about - Provides better error messages when connection fails - Aligns with how the official MCP SDK is designed to be used The MCP SDK will handle connection errors gracefully and provide clear error messages if the server isn't reachable.
1 parent b2b2040 commit 33c1c3a

File tree

1 file changed

+9
-46
lines changed

1 file changed

+9
-46
lines changed

test_agentic_mcp.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -319,50 +319,8 @@ async def run_http_tests():
319319
print("\n🌐 Using HTTP/SSE transport")
320320

321321
mcp_url = f"http://{HTTP_HOST}:{HTTP_PORT}/mcp"
322-
print(f" URL: {mcp_url}")
323-
324-
# Quick check if server is reachable
325-
print(f"\nChecking HTTP server health...")
326-
print(f" Endpoint: http://{HTTP_HOST}:{HTTP_PORT}/health")
327-
328-
try:
329-
import httpx
330-
async with httpx.AsyncClient() as client:
331-
# Try health check with SSE headers (server may require them)
332-
response = await client.get(
333-
f"http://{HTTP_HOST}:{HTTP_PORT}/health",
334-
timeout=2.0,
335-
follow_redirects=True,
336-
headers={
337-
"Accept": "text/event-stream, application/json, */*"
338-
}
339-
)
340-
if response.status_code != 200:
341-
print(f"❌ Health check failed: HTTP {response.status_code}")
342-
print(f" Response: {response.text[:200] if response.text else 'empty'}")
343-
print(f"\n⚠️ Troubleshooting:")
344-
print(f" - Is the CodeGraph HTTP server running on port {HTTP_PORT}?")
345-
print(f" - Check: ps aux | grep codegraph")
346-
print(f" - Try: curl -H 'Accept: text/event-stream' http://{HTTP_HOST}:{HTTP_PORT}/health")
347-
print(f"\nStart HTTP server with:")
348-
print(f" ./target/release/codegraph start http --host {HTTP_HOST} --port {HTTP_PORT}")
349-
return 1
350-
print("✓ Server is reachable\n")
351-
except Exception as e:
352-
print(f"❌ Cannot reach server: {e}")
353-
print(f"\n⚠️ Troubleshooting:")
354-
print(f" - Is the server running? Check: ps aux | grep codegraph")
355-
print(f" - Wrong port? Common ports:")
356-
print(f" - 3000: Default HTTP server port")
357-
print(f" - 3003: Your configured port (CODEGRAPH_HTTP_PORT)")
358-
print(f" - 3004: SurrealDB (NOT for HTTP)")
359-
print(f" - Check firewall/network: curl http://{HTTP_HOST}:{HTTP_PORT}/health")
360-
print(f"\nExpected .env configuration:")
361-
print(f" CODEGRAPH_HTTP_HOST={HTTP_HOST}")
362-
print(f" CODEGRAPH_HTTP_PORT={HTTP_PORT}")
363-
print(f"\nStart HTTP server with:")
364-
print(f" ./target/release/codegraph start http --host {HTTP_HOST} --port {HTTP_PORT}")
365-
return 1
322+
print(f" Connecting to: {mcp_url}")
323+
print(f" (Server must be running: ./target/release/codegraph start http --port {HTTP_PORT})\n")
366324

367325
results = []
368326

@@ -464,8 +422,13 @@ async def run_http_tests():
464422

465423
except Exception as e:
466424
print(f"\n❌ Failed to connect via SSE: {e}")
467-
import traceback
468-
traceback.print_exc()
425+
print(f"\n⚠️ Troubleshooting:")
426+
print(f" - Is the server running? Check: ps aux | grep codegraph")
427+
print(f" - Verify server is listening on port {HTTP_PORT}")
428+
print(f" - Check server logs for errors")
429+
print(f"\nStart server with:")
430+
print(f" ./target/release/codegraph start http --host {HTTP_HOST} --port {HTTP_PORT}")
431+
print(f"\nIf you need detailed error info, run with RUST_LOG=debug")
469432
return 1
470433

471434
# Print summary

0 commit comments

Comments
 (0)