""" FleetMind MCP Server - Hugging Face Space Entry Point (Track 1) This file serves as the entry point for HuggingFace Space deployment. Exposes 29 MCP tools via Server-Sent Events (SSE) endpoint for AI clients. Architecture: User → MCP Client (Claude Desktop, Continue, etc.) → SSE Endpoint (this file) → FleetMind MCP Server (server.py) → Tools (chat/tools.py) → Database (PostgreSQL) For Track 1: Building MCP Servers - Enterprise Category https://huggingface.co/MCP-1st-Birthday Compatible with: - Claude Desktop (via SSE transport) - Continue.dev (VS Code extension) - Cline (VS Code extension) - Any MCP client supporting SSE protocol """ import os import sys import logging from pathlib import Path # Add project root to path sys.path.insert(0, str(Path(__file__).parent)) # Configure logging for HuggingFace Space logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()] ) logger = logging.getLogger(__name__) # Import the MCP server instance from server import mcp # ============================================================================ # HUGGING FACE SPACE CONFIGURATION # ============================================================================ # HuggingFace Space default port # NOTE: When using proxy.py, FastMCP runs on 7861 (internal port) # The proxy runs on 7860 (public) and forwards requests here HF_SPACE_PORT = int(os.getenv("PORT", 7861)) HF_SPACE_HOST = os.getenv("HOST", "0.0.0.0") # ============================================================================ # MAIN ENTRY POINT # ============================================================================ if __name__ == "__main__": logger.info("=" * 70) logger.info("FleetMind MCP Server - HuggingFace Space (Track 1)") logger.info("=" * 70) logger.info("MCP Server: FleetMind Dispatch Coordinator v1.0.0") logger.info("Protocol: Model Context Protocol (MCP)") logger.info("Transport: Server-Sent Events (SSE)") logger.info(f"SSE Endpoint: https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse") logger.info("=" * 70) logger.info("Features:") logger.info(" ✓ 29 AI Tools (Order + Driver + Assignment Management)") logger.info(" ✓ 2 Real-Time Resources (orders://all, drivers://all)") logger.info(" ✓ Gemini 2.0 Flash AI - Intelligent Assignment") logger.info(" ✓ Google Maps API Integration (Routes + Geocoding)") logger.info(" ✓ Weather-Aware Routing (OpenWeatherMap)") logger.info(" ✓ PostgreSQL Database (Neon)") logger.info("=" * 70) logger.info("Compatible Clients:") logger.info(" • Claude Desktop") logger.info(" • Continue.dev (VS Code)") logger.info(" • Cline (VS Code)") logger.info(" • Any MCP-compatible client") logger.info("=" * 70) logger.info("How to Connect (Claude Desktop):") logger.info(' Add to claude_desktop_config.json:') logger.info(' {') logger.info(' "mcpServers": {') logger.info(' "fleetmind": {') logger.info(' "command": "npx",') logger.info(' "args": [') logger.info(' "mcp-remote",') logger.info(' "https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse"') logger.info(' ]') logger.info(' }') logger.info(' }') logger.info(' }') logger.info("=" * 70) logger.info(f"Starting SSE server on {HF_SPACE_HOST}:{HF_SPACE_PORT}...") logger.info("Waiting for MCP client connections...") logger.info("=" * 70) try: # Add web routes for landing page and API key generation from starlette.responses import HTMLResponse, JSONResponse from starlette.requests import Request from database.api_keys import generate_api_key as db_generate_api_key # ===================================================================== # PROXY-BASED AUTHENTICATION # Authentication is handled by proxy.py (port 7860) # The proxy captures API keys from SSE connections and injects them # into tool requests before forwarding to FastMCP (port 7861) # ===================================================================== logger.info("[Auth] Using proxy-based authentication") logger.info("[Auth] Proxy captures API keys and injects into tool requests") @mcp.custom_route("/", methods=["GET"]) async def landing_page(request): """Landing page with MCP connection information""" return HTMLResponse("""
Enterprise Model Context Protocol Server for AI-Powered Delivery Dispatch
MCP 1st Birthday Hackathon Track 1: Building MCP Enterprise Category
https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse
Click the button above to generate your unique API key. You'll need this to authenticate with the server.
Add this to your claude_desktop_config.json file:
{
"mcpServers": {
"fleetmind": {
"command": "npx",
"args": [
"mcp-remote",
"https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse?api_key=fm_your_api_key_here"
]
}
}
}
💡 Important: Add your API key as a query parameter (?api_key=...) in the URL, not in the env section!
claude_desktop_config.json filefm_your_api_key_here with your actual API key in the URLuser_{MD5(email)[:12]}?api_key=fm_...
FleetMind v1.0 - Built for MCP 1st Birthday Hackathon
29 AI Tools | 2 Real-Time Resources | Enterprise-Ready
Create your FleetMind MCP Server API key
fm_xxxxx... (show once, copy immediately!)user_xxxxx (deterministic from your email)📧 Email: {result["email"]}
👤 Name: {result["name"]}
🆔 User ID: {result["user_id"]}
{result["api_key"]}
Your user_id ({result["user_id"]}) ensures complete data isolation:
✅ You will only see your own orders, drivers, and assignments
✅ All database operations automatically filter by your user_id
✅ Your user_id is deterministic - same email always gets same ID
✅ Even if you regenerate your API key, your user_id stays the same
Add this to your claude_desktop_config.json:
{{
"mcpServers": {{
"fleetmind": {{
"command": "npx",
"args": [
"mcp-remote",
"https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse?api_key={result["api_key"]}"
]
}}
}}
}}
💡 Important: The API key is included in the URL as a query parameter (?api_key=...)
{result["user_id"]}