prthm11 commited on
Commit
12909ca
·
verified ·
1 Parent(s): d5009cf

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +20 -3
server.py CHANGED
@@ -1,6 +1,7 @@
1
  from mcp.server.fastmcp import FastMCP
2
  import logging
3
  import os
 
4
 
5
  # Initialize the server
6
  mcp = FastMCP("Math-Education-Server")
@@ -57,6 +58,22 @@ async def generate_quiz(chapter_name: str, difficulty: str = "medium") -> str:
57
  )
58
 
59
  if __name__ == "__main__":
60
- # FastMCP handles the --transport sse argument automatically
61
- # if you use mcp.run()
62
- mcp.run()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from mcp.server.fastmcp import FastMCP
2
  import logging
3
  import os
4
+ from pathlib import Path
5
 
6
  # Initialize the server
7
  mcp = FastMCP("Math-Education-Server")
 
58
  )
59
 
60
  if __name__ == "__main__":
61
+ # For Docker/HF Spaces deployment, we need to run with HTTP transport
62
+ # The server will listen on the port specified by environment variable or default to 7860
63
+ import sys
64
+
65
+ # Check if we're running in deployment mode (Docker/HF Spaces)
66
+ port = int(os.getenv("PORT", "7860"))
67
+ host = os.getenv("HOST", "0.0.0.0")
68
+
69
+ logger.info(f"Starting MCP Server on {host}:{port}")
70
+
71
+ # For local development, use stdio
72
+ # For deployment, use SSE transport
73
+ if "--stdio" in sys.argv:
74
+ logger.info("Running in stdio mode for local development")
75
+ mcp.run(transport="stdio")
76
+ else:
77
+ logger.info(f"Running in SSE mode for deployment on {host}:{port}")
78
+ # Run with SSE transport for HTTP-based communication
79
+ mcp.run(transport="sse", host=host, port=port)