Commit
·
d132a19
1
Parent(s):
8fb800a
feat: Refactor landing page implementation and update MCP server routing
Browse files- app.py +29 -52
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -94,39 +94,33 @@ if __name__ == "__main__":
|
|
| 94 |
logger.info("=" * 70)
|
| 95 |
|
| 96 |
try:
|
| 97 |
-
#
|
| 98 |
-
from
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
# Create FastAPI app
|
| 104 |
-
app = FastAPI(title="FleetMind MCP Server")
|
| 105 |
-
|
| 106 |
-
# Add landing page
|
| 107 |
-
@app.get("/", response_class=HTMLResponse)
|
| 108 |
-
async def landing_page():
|
| 109 |
"""Landing page with MCP connection information"""
|
| 110 |
-
return """
|
| 111 |
<!DOCTYPE html>
|
| 112 |
<html>
|
| 113 |
<head>
|
| 114 |
<title>FleetMind MCP Server</title>
|
| 115 |
<style>
|
| 116 |
-
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; max-width: 1000px; margin: 50px auto; padding: 20px; background: #
|
| 117 |
-
.container { background:
|
| 118 |
-
h1 { color: #
|
| 119 |
-
h2 { color: #
|
| 120 |
-
h3 { color: #
|
| 121 |
-
code { background: #
|
| 122 |
-
pre { background: #
|
| 123 |
-
.endpoint { background: #
|
| 124 |
-
.feature { background: #
|
| 125 |
.badge { display: inline-block; background: #3b82f6; color: white; padding: 4px 12px; border-radius: 12px; font-size: 12px; margin: 5px; }
|
| 126 |
-
a { color: #
|
| 127 |
-
a:hover { text-decoration: underline; }
|
| 128 |
ol { line-height: 1.8; }
|
| 129 |
ul { line-height: 1.8; }
|
|
|
|
| 130 |
</style>
|
| 131 |
</head>
|
| 132 |
<body>
|
|
@@ -226,34 +220,17 @@ if __name__ == "__main__":
|
|
| 226 |
</div>
|
| 227 |
</body>
|
| 228 |
</html>
|
| 229 |
-
"""
|
| 230 |
-
|
| 231 |
-
logger.info("[OK] Landing page added at /")
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
logger.info("[OK] MCP SSE server started on port 7861")
|
| 241 |
-
|
| 242 |
-
# Add proxy route for /sse that forwards to port 7861
|
| 243 |
-
@app.get("/sse")
|
| 244 |
-
@app.post("/sse")
|
| 245 |
-
async def mcp_sse_proxy():
|
| 246 |
-
"""Proxy to MCP SSE server on port 7861"""
|
| 247 |
-
import httpx
|
| 248 |
-
async with httpx.AsyncClient() as client:
|
| 249 |
-
response = await client.get("http://localhost:7861/sse", timeout=None)
|
| 250 |
-
return response
|
| 251 |
-
|
| 252 |
-
logger.info("[OK] SSE proxy added at /sse")
|
| 253 |
-
|
| 254 |
-
# Run FastAPI app
|
| 255 |
-
logger.info(f"[STARTING] Unified server on {HF_SPACE_HOST}:{HF_SPACE_PORT}")
|
| 256 |
-
uvicorn.run(app, host=HF_SPACE_HOST, port=HF_SPACE_PORT, log_level="info")
|
| 257 |
|
| 258 |
except Exception as e:
|
| 259 |
logger.error(f"Failed to start server: {e}")
|
|
|
|
| 94 |
logger.info("=" * 70)
|
| 95 |
|
| 96 |
try:
|
| 97 |
+
# Add landing page using custom_route decorator
|
| 98 |
+
from starlette.responses import HTMLResponse
|
| 99 |
+
|
| 100 |
+
@mcp.custom_route("/", methods=["GET"])
|
| 101 |
+
async def landing_page(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
"""Landing page with MCP connection information"""
|
| 103 |
+
return HTMLResponse("""
|
| 104 |
<!DOCTYPE html>
|
| 105 |
<html>
|
| 106 |
<head>
|
| 107 |
<title>FleetMind MCP Server</title>
|
| 108 |
<style>
|
| 109 |
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; max-width: 1000px; margin: 50px auto; padding: 20px; background: #0f172a; color: #e2e8f0; }
|
| 110 |
+
.container { background: #1e293b; padding: 40px; border-radius: 12px; box-shadow: 0 8px 16px rgba(0,0,0,0.4); }
|
| 111 |
+
h1 { color: #f1f5f9; margin-top: 0; }
|
| 112 |
+
h2 { color: #e2e8f0; border-bottom: 2px solid #334155; padding-bottom: 10px; }
|
| 113 |
+
h3 { color: #cbd5e1; }
|
| 114 |
+
code { background: #334155; color: #60a5fa; padding: 3px 8px; border-radius: 4px; font-family: 'Courier New', monospace; }
|
| 115 |
+
pre { background: #0f172a; color: #f1f5f9; padding: 20px; border-radius: 8px; overflow-x: auto; border: 1px solid #334155; }
|
| 116 |
+
.endpoint { background: #1e3a5f; padding: 15px; margin: 15px 0; border-left: 4px solid #3b82f6; border-radius: 4px; }
|
| 117 |
+
.feature { background: #134e4a; padding: 15px; margin: 10px 0; border-left: 4px solid #10b981; border-radius: 4px; }
|
| 118 |
.badge { display: inline-block; background: #3b82f6; color: white; padding: 4px 12px; border-radius: 12px; font-size: 12px; margin: 5px; }
|
| 119 |
+
a { color: #60a5fa; text-decoration: none; }
|
| 120 |
+
a:hover { text-decoration: underline; color: #93c5fd; }
|
| 121 |
ol { line-height: 1.8; }
|
| 122 |
ul { line-height: 1.8; }
|
| 123 |
+
p { color: #cbd5e1; }
|
| 124 |
</style>
|
| 125 |
</head>
|
| 126 |
<body>
|
|
|
|
| 220 |
</div>
|
| 221 |
</body>
|
| 222 |
</html>
|
| 223 |
+
""")
|
| 224 |
+
|
| 225 |
+
logger.info("[OK] Landing page added at / route")
|
| 226 |
+
logger.info("[OK] MCP SSE endpoint available at /sse")
|
| 227 |
+
|
| 228 |
+
# Run MCP server with SSE transport (includes both /sse and custom routes)
|
| 229 |
+
mcp.run(
|
| 230 |
+
transport="sse",
|
| 231 |
+
host=HF_SPACE_HOST,
|
| 232 |
+
port=HF_SPACE_PORT
|
| 233 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
except Exception as e:
|
| 236 |
logger.error(f"Failed to start server: {e}")
|
requirements.txt
CHANGED
|
@@ -10,7 +10,6 @@ pydantic>=2.8.2
|
|
| 10 |
# Web Framework (for landing page)
|
| 11 |
fastapi>=0.104.0
|
| 12 |
uvicorn>=0.24.0
|
| 13 |
-
httpx>=0.25.0
|
| 14 |
|
| 15 |
# Database
|
| 16 |
psycopg2-binary>=2.9.9
|
|
|
|
| 10 |
# Web Framework (for landing page)
|
| 11 |
fastapi>=0.104.0
|
| 12 |
uvicorn>=0.24.0
|
|
|
|
| 13 |
|
| 14 |
# Database
|
| 15 |
psycopg2-binary>=2.9.9
|