File size: 10,489 Bytes
d69447e 6eba330 0fef185 6eba330 d69447e 6eba330 d69447e 6eba330 d69447e 6eba330 d69447e 6eba330 d69447e 6eba330 982515c 6eba330 0fef185 6eba330 0fef185 6eba330 ed7f1c2 982515c ed7f1c2 6eba330 d132a19 982515c d132a19 982515c d132a19 982515c d132a19 982515c d132a19 982515c d132a19 982515c 6eba330 982515c 6eba330 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
"""
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
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://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 landing page using custom_route decorator
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")
# Run MCP server with SSE transport (includes both /sse and custom routes)
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
|