""" FleetMind MCP Server - Hugging Face Space Entry Point (Track 1) This file serves as the entry point for HuggingFace Space deployment. Exposes 18 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 from fastapi import FastAPI from fastapi.responses import HTMLResponse import uvicorn # ============================================================================ # HUGGING FACE SPACE CONFIGURATION # ============================================================================ # HuggingFace Space default port HF_SPACE_PORT = int(os.getenv("PORT", 7860)) HF_SPACE_HOST = os.getenv("HOST", "0.0.0.0") # Create FastAPI app with root endpoint app = FastAPI(title="FleetMind MCP Server") @app.get("/", response_class=HTMLResponse) async def root(): """Root endpoint with usage instructions""" return """ FleetMind MCP Server

🚚 FleetMind MCP Server

✅ Server Status: RUNNING

📡 MCP Endpoint

SSE Endpoint: https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse

🔧 How to Connect

From Claude Desktop:

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "fleetmind": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse"
      ]
    }
  }
}

From Continue (VS Code):

  1. Install Continue extension
  2. Add FleetMind MCP server in settings
  3. Use the SSE endpoint URL above

🛠️ Available Tools (18 Total)

Order Management:

Driver Management:

📊 Real-Time Resources (2 Total)

📖 Example Usage

After connecting via Claude Desktop, try:

🔗 Links

""" # Mount MCP SSE endpoint # FastMCP will handle the /sse endpoint when we call mcp.run() # ============================================================================ # 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"Endpoint: http://{HF_SPACE_HOST}:{HF_SPACE_PORT}/sse") logger.info("=" * 70) logger.info("Features:") logger.info(" ✓ 18 AI Tools (Order + Driver Management)") logger.info(" ✓ 2 Real-Time Resources (orders://all, drivers://all)") logger.info(" ✓ Google Maps API Integration (Geocoding + Routes)") 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(f"Starting SSE server on {HF_SPACE_HOST}:{HF_SPACE_PORT}...") logger.info("Waiting for MCP client connections...") logger.info("=" * 70) try: # Run MCP server in SSE mode for HuggingFace Space # This will automatically mount the /sse endpoint to our FastAPI app mcp.run( transport="sse", host=HF_SPACE_HOST, port=HF_SPACE_PORT, custom_app=app # Use our custom FastAPI app with root endpoint ) except TypeError: # Fallback if FastMCP doesn't support custom_app # Run both servers (not ideal but works) logger.warning("Running without custom root endpoint") mcp.run( transport="sse", host=HF_SPACE_HOST, port=HF_SPACE_PORT ) except Exception as e: logger.error(f"Failed to start MCP server: {e}") logger.error("Check that:") logger.error(" 1. Database connection is configured (DB_HOST, DB_USER, etc.)") logger.error(" 2. Google Maps API key is set (GOOGLE_MAPS_API_KEY)") logger.error(" 3. Port 7860 is available") raise