forked from Zagot-byte/ThrustGuard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.py
More file actions
44 lines (34 loc) · 1.01 KB
/
serve.py
File metadata and controls
44 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from flask import Flask, Response, request, jsonify
from mcp_server import mcp
app = Flask(__name__)
# health endpoint
@app.route("/")
def root():
return jsonify({"status": "running"})
@app.route("/mcp/sse")
def mcp_sse():
"""
SSE stream endpoint required by MCP clients.
"""
# validate SSE header
accept = request.headers.get("Accept", "")
if "text/event-stream" not in accept:
return "Invalid Accept header", 400
def event_stream():
try:
# FastMCP provides generator for SSE events
for event in mcp.sse():
yield f"event: message\ndata: {event}\n\n"
except Exception as e:
yield f"event: error\ndata: {str(e)}\n\n"
return Response(
event_stream(),
mimetype="text/event-stream",
headers={
"Cache-Control": "no-cache",
"Connection": "keep-alive",
},
)
if __name__ == "__main__":
# bind to LAN
app.run(host="0.0.0.0", port=8001, threaded=True)