JC321 commited on
Commit
3e8894e
·
verified ·
1 Parent(s): f93e2e7

Upload mcp_server_fastmcp.py

Browse files
Files changed (1) hide show
  1. mcp_server_fastmcp.py +13 -8
mcp_server_fastmcp.py CHANGED
@@ -200,16 +200,21 @@ def advanced_search_company(company_input: str) -> dict:
200
  # For production deployment
201
  if __name__ == "__main__":
202
  import os
203
- import uvicorn
204
 
205
- # Get port from environment or use 7860 for HF Space
206
  port = int(os.getenv("PORT", "7860"))
207
  host = os.getenv("HOST", "0.0.0.0")
208
 
209
- # Run with uvicorn manually since mcp.run() defaults to port 8000
210
- # We create a simple ASGI app wrapper
211
- async def asgi_app(scope, receive, send):
212
- # Delegate to FastMCP's SSE handler
213
- await mcp._handle_sse_message(scope, receive, send)
 
 
 
 
 
214
 
215
- uvicorn.run(asgi_app, host=host, port=port)
 
 
200
  # For production deployment
201
  if __name__ == "__main__":
202
  import os
 
203
 
204
+ # Set port from environment (HF Space sets PORT=7860)
205
  port = int(os.getenv("PORT", "7860"))
206
  host = os.getenv("HOST", "0.0.0.0")
207
 
208
+ # Monkeypatch uvicorn.Config to use our port
209
+ import uvicorn
210
+ original_config_init = uvicorn.Config.__init__
211
+
212
+ def patched_init(self, *args, **kwargs):
213
+ kwargs['host'] = host
214
+ kwargs['port'] = port
215
+ return original_config_init(self, *args, **kwargs)
216
+
217
+ uvicorn.Config.__init__ = patched_init
218
 
219
+ # Run FastMCP with SSE transport (it will use our patched config)
220
+ mcp.run(transport="sse")