mashrur950's picture
refactor: Remove FastAPI root endpoint and related code for Hugging Face Space integration
ed7f1c2
raw
history blame
3.93 kB
"""
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
# ============================================================================
# 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")
# ============================================================================
# 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://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/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("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://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/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:
# Run MCP server in SSE mode for HuggingFace Space
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