Skip to content

Commit ec9a592

Browse files
committed
fix: handle SSE streaming in HTTP test script
HTTP server returns text/event-stream responses, not plain JSON. Updated test script to: - Send Accept: text/event-stream header - Parse SSE format (data: prefix) - Stream response and extract JSON-RPC result - Handle health endpoint SSE requirement This matches the actual HTTP server implementation which uses SSE streaming for all responses.
1 parent 93cfb69 commit ec9a592

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

test_http_agentic_tools.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,69 @@
139139
def check_server():
140140
"""Check if HTTP server is running."""
141141
try:
142-
response = requests.get(f"{BASE_URL}/health", timeout=2)
142+
# Health endpoint requires Accept: text/event-stream header
143+
response = requests.get(
144+
f"{BASE_URL}/health",
145+
headers={"Accept": "text/event-stream"},
146+
timeout=2
147+
)
143148
if response.status_code == 200:
144149
print(f"✓ Server is running at {BASE_URL}")
145150
return True
151+
else:
152+
print(f"\n⚠️ Server responded with status {response.status_code}")
153+
print(f"Response: {response.text}")
154+
return False
146155
except requests.exceptions.RequestException as e:
147156
print(f"\n❌ Server not running at {BASE_URL}")
148157
print(f"Error: {e}")
149158
print("\nStart server with:")
150-
print(f" ./start_http_server.sh")
159+
print(f" codegraph start http --port {HTTP_PORT}")
151160
print(f" OR")
152-
print(f" ./target/release/codegraph start http --port {HTTP_PORT}")
161+
print(f" ./start_http_server.sh")
153162
return False
154163

155164
def send_mcp_request(payload, timeout=60):
156-
"""Send MCP request via HTTP POST and wait for response."""
165+
"""Send MCP request via HTTP POST and wait for SSE response."""
157166
try:
158167
start_time = time.time()
159168

169+
# HTTP server returns SSE stream - need to accept text/event-stream
160170
response = requests.post(
161171
f"{BASE_URL}/mcp",
162-
headers={"Content-Type": "application/json"},
172+
headers={
173+
"Content-Type": "application/json",
174+
"Accept": "text/event-stream"
175+
},
163176
json=payload,
164-
timeout=timeout
177+
timeout=timeout,
178+
stream=True
165179
)
166180

167181
duration = time.time() - start_time
168182

169183
if response.status_code == 200:
170-
return response.json(), duration
184+
# Parse SSE stream for JSON-RPC responses
185+
result_data = None
186+
for line in response.iter_lines(decode_unicode=True):
187+
if not line or line.startswith(':'):
188+
continue
189+
if line.startswith('data: '):
190+
data = line[6:] # Remove 'data: ' prefix
191+
try:
192+
event = json.loads(data)
193+
# Look for the final result
194+
if "result" in event:
195+
result_data = event
196+
break
197+
except json.JSONDecodeError:
198+
continue
199+
200+
if result_data:
201+
return result_data, time.time() - start_time
202+
else:
203+
print(f"⚠️ No result found in SSE stream")
204+
return None, time.time() - start_time
171205
else:
172206
print(f"❌ HTTP {response.status_code}: {response.text[:200]}")
173207
return None, duration

0 commit comments

Comments
 (0)