anil988 commited on
Commit
fc85e52
·
1 Parent(s): 2f2eb08

Fix: Added X-Accel-Buffering: no to resolve MCP SSE timeout on HF Spaces

Browse files
Files changed (1) hide show
  1. backend/main.py +3 -2
backend/main.py CHANGED
@@ -91,9 +91,9 @@ async def mcp_discovery(req: Request):
91
 
92
  @app.get("/mcp/sse")
93
  async def mcp_sse_stream(req: Request):
94
- """Handshake with manual CORS headers for SSE"""
95
  async def event_generator():
96
- # Immediate endpoint event with relative path
97
  yield f"event: endpoint\ndata: /mcp/invoke\n\n"
98
  while True:
99
  await asyncio.sleep(20)
@@ -103,6 +103,7 @@ async def mcp_sse_stream(req: Request):
103
  response.headers["Access-Control-Allow-Origin"] = "*"
104
  response.headers["Cache-Control"] = "no-cache"
105
  response.headers["Connection"] = "keep-alive"
 
106
  return response
107
 
108
  @app.post("/mcp/invoke")
 
91
 
92
  @app.get("/mcp/sse")
93
  async def mcp_sse_stream(req: Request):
94
+ """Handshake with manual CORS and Proxy Fixes"""
95
  async def event_generator():
96
+ # Immediate endpoint event
97
  yield f"event: endpoint\ndata: /mcp/invoke\n\n"
98
  while True:
99
  await asyncio.sleep(20)
 
103
  response.headers["Access-Control-Allow-Origin"] = "*"
104
  response.headers["Cache-Control"] = "no-cache"
105
  response.headers["Connection"] = "keep-alive"
106
+ response.headers["X-Accel-Buffering"] = "no" # Fix for Hugging Face/Nginx buffering
107
  return response
108
 
109
  @app.post("/mcp/invoke")