|
|
""" |
|
|
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 |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
|
|
|
logging.basicConfig( |
|
|
level=logging.INFO, |
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', |
|
|
handlers=[logging.StreamHandler()] |
|
|
) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
from server import mcp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HF_SPACE_PORT = int(os.getenv("PORT", 7860)) |
|
|
HF_SPACE_HOST = os.getenv("HOST", "0.0.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
from starlette.responses import HTMLResponse |
|
|
|
|
|
@mcp.custom_route("/", methods=["GET"]) |
|
|
async def landing_page(request): |
|
|
"""Landing page with MCP connection information""" |
|
|
return HTMLResponse(""" |
|
|
<!DOCTYPE html> |
|
|
<html> |
|
|
<head> |
|
|
<title>FleetMind MCP Server</title> |
|
|
<style> |
|
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; max-width: 1000px; margin: 50px auto; padding: 20px; background: #0f172a; color: #e2e8f0; } |
|
|
.container { background: #1e293b; padding: 40px; border-radius: 12px; box-shadow: 0 8px 16px rgba(0,0,0,0.4); } |
|
|
h1 { color: #f1f5f9; margin-top: 0; } |
|
|
h2 { color: #e2e8f0; border-bottom: 2px solid #334155; padding-bottom: 10px; } |
|
|
h3 { color: #cbd5e1; } |
|
|
code { background: #334155; color: #60a5fa; padding: 3px 8px; border-radius: 4px; font-family: 'Courier New', monospace; } |
|
|
pre { background: #0f172a; color: #f1f5f9; padding: 20px; border-radius: 8px; overflow-x: auto; border: 1px solid #334155; } |
|
|
.endpoint { background: #1e3a5f; padding: 15px; margin: 15px 0; border-left: 4px solid #3b82f6; border-radius: 4px; } |
|
|
.feature { background: #134e4a; padding: 15px; margin: 10px 0; border-left: 4px solid #10b981; border-radius: 4px; } |
|
|
.badge { display: inline-block; background: #3b82f6; color: white; padding: 4px 12px; border-radius: 12px; font-size: 12px; margin: 5px; } |
|
|
a { color: #60a5fa; text-decoration: none; } |
|
|
a:hover { text-decoration: underline; color: #93c5fd; } |
|
|
ol { line-height: 1.8; } |
|
|
ul { line-height: 1.8; } |
|
|
p { color: #cbd5e1; } |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<div class="container"> |
|
|
<h1>π FleetMind MCP Server</h1> |
|
|
<p><strong>Enterprise Model Context Protocol Server for AI-Powered Delivery Dispatch</strong></p> |
|
|
<p><span class="badge">MCP 1st Birthday Hackathon</span> <span class="badge">Track 1: Building MCP</span> <span class="badge">Enterprise Category</span></p> |
|
|
|
|
|
<hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;"> |
|
|
|
|
|
<h2>π MCP Server Connection</h2> |
|
|
|
|
|
<div class="endpoint"> |
|
|
<strong>SSE Endpoint URL:</strong><br> |
|
|
<code>https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse</code> |
|
|
</div> |
|
|
|
|
|
<h3>βοΈ Claude Desktop Configuration</h3> |
|
|
<p>Add this to your <code>claude_desktop_config.json</code> file:</p> |
|
|
<pre>{ |
|
|
"mcpServers": { |
|
|
"fleetmind": { |
|
|
"command": "npx", |
|
|
"args": [ |
|
|
"mcp-remote", |
|
|
"https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse" |
|
|
] |
|
|
} |
|
|
} |
|
|
}</pre> |
|
|
|
|
|
<h3>π How to Connect</h3> |
|
|
<ol> |
|
|
<li>Install <a href="https://claude.ai/download" target="_blank">Claude Desktop</a></li> |
|
|
<li>Locate your <code>claude_desktop_config.json</code> file</li> |
|
|
<li>Add the configuration shown above</li> |
|
|
<li>Restart Claude Desktop</li> |
|
|
<li>Look for "FleetMind" in the π tools menu</li> |
|
|
</ol> |
|
|
|
|
|
<hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;"> |
|
|
|
|
|
<h2>π οΈ Available Tools (29 Total)</h2> |
|
|
|
|
|
<div class="feature"> |
|
|
<strong>π Geocoding & Routing (3 tools):</strong><br> |
|
|
geocode_address, calculate_route, calculate_intelligent_route |
|
|
</div> |
|
|
|
|
|
<div class="feature"> |
|
|
<strong>π¦ Order Management (8 tools):</strong><br> |
|
|
create_order, count_orders, fetch_orders, get_order_details, search_orders, get_incomplete_orders, update_order, delete_order |
|
|
</div> |
|
|
|
|
|
<div class="feature"> |
|
|
<strong>π₯ Driver Management (8 tools):</strong><br> |
|
|
create_driver, count_drivers, fetch_drivers, get_driver_details, search_drivers, get_available_drivers, update_driver, delete_driver |
|
|
</div> |
|
|
|
|
|
<div class="feature"> |
|
|
<strong>π Assignment Management (8 tools):</strong><br> |
|
|
create_assignment, <strong>auto_assign_order</strong>, <strong>intelligent_assign_order</strong>, get_assignment_details, update_assignment, unassign_order, complete_delivery, fail_delivery |
|
|
</div> |
|
|
|
|
|
<div class="feature"> |
|
|
<strong>ποΈ Bulk Operations (2 tools):</strong><br> |
|
|
delete_all_orders, delete_all_drivers |
|
|
</div> |
|
|
|
|
|
<hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;"> |
|
|
|
|
|
<h2>β Key Features</h2> |
|
|
<ul> |
|
|
<li><strong>π§ Gemini 2.0 Flash AI</strong> - Intelligent order assignment with detailed reasoning</li> |
|
|
<li><strong>π¦οΈ Weather-Aware Routing</strong> - Safety-first delivery planning with OpenWeatherMap</li> |
|
|
<li><strong>π¦ Real-Time Traffic</strong> - Google Routes API integration with live traffic data</li> |
|
|
<li><strong>π SLA Tracking</strong> - Automatic on-time performance monitoring</li> |
|
|
<li><strong>ποΈ PostgreSQL Database</strong> - Production-grade data storage (Neon)</li> |
|
|
<li><strong>π Multi-Client Support</strong> - Works with Claude Desktop, Continue, Cline, any MCP client</li> |
|
|
</ul> |
|
|
|
|
|
<hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;"> |
|
|
|
|
|
<h2>π Resources</h2> |
|
|
<ul> |
|
|
<li><strong>GitHub:</strong> <a href="https://github.com/mashrur-rahman-fahim/fleetmind-mcp" target="_blank">mashrur-rahman-fahim/fleetmind-mcp</a></li> |
|
|
<li><strong>HuggingFace Space:</strong> <a href="https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai" target="_blank">MCP-1st-Birthday/fleetmind-dispatch-ai</a></li> |
|
|
<li><strong>MCP Protocol Docs:</strong> <a href="https://modelcontextprotocol.io" target="_blank">modelcontextprotocol.io</a></li> |
|
|
</ul> |
|
|
|
|
|
<hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;"> |
|
|
|
|
|
<p style="text-align: center; color: #6b7280; font-size: 14px;"> |
|
|
FleetMind v1.0 - Built for MCP 1st Birthday Hackathon<br> |
|
|
29 AI Tools | 2 Real-Time Resources | Enterprise-Ready |
|
|
</p> |
|
|
</div> |
|
|
</body> |
|
|
</html> |
|
|
""") |
|
|
|
|
|
logger.info("[OK] Landing page added at / route") |
|
|
logger.info("[OK] MCP SSE endpoint available at /sse") |
|
|
|
|
|
|
|
|
mcp.run( |
|
|
transport="sse", |
|
|
host=HF_SPACE_HOST, |
|
|
port=HF_SPACE_PORT |
|
|
) |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"Failed to start 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 |
|
|
|