mashrur950 commited on
Commit
982515c
Β·
1 Parent(s): b3ae1c3

feat: Update Dockerfile and app.py to enhance MCP server with landing page and updated SSE endpoint

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. app.py +164 -9
Dockerfile CHANGED
@@ -30,5 +30,5 @@ EXPOSE 7860
30
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
31
  CMD python -c "import requests; requests.get('http://localhost:7860')" || exit 1
32
 
33
- # Run the MCP server via app.py (SSE mode)
34
  CMD ["python", "app.py"]
 
30
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
31
  CMD python -c "import requests; requests.get('http://localhost:7860')" || exit 1
32
 
33
+ # Run the MCP server with landing page
34
  CMD ["python", "app.py"]
app.py CHANGED
@@ -59,7 +59,7 @@ if __name__ == "__main__":
59
  logger.info("MCP Server: FleetMind Dispatch Coordinator v1.0.0")
60
  logger.info("Protocol: Model Context Protocol (MCP)")
61
  logger.info("Transport: Server-Sent Events (SSE)")
62
- logger.info(f"SSE Endpoint: https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse")
63
  logger.info("=" * 70)
64
  logger.info("Features:")
65
  logger.info(" βœ“ 29 AI Tools (Order + Driver + Assignment Management)")
@@ -83,7 +83,7 @@ if __name__ == "__main__":
83
  logger.info(' "command": "npx",')
84
  logger.info(' "args": [')
85
  logger.info(' "mcp-remote",')
86
- logger.info(' "https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse"')
87
  logger.info(' ]')
88
  logger.info(' }')
89
  logger.info(' }')
@@ -94,14 +94,169 @@ if __name__ == "__main__":
94
  logger.info("=" * 70)
95
 
96
  try:
97
- # Run MCP server in SSE mode for HuggingFace Space
98
- mcp.run(
99
- transport="sse",
100
- host=HF_SPACE_HOST,
101
- port=HF_SPACE_PORT
102
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  except Exception as e:
104
- logger.error(f"Failed to start MCP server: {e}")
105
  logger.error("Check that:")
106
  logger.error(" 1. Database connection is configured (DB_HOST, DB_USER, etc.)")
107
  logger.error(" 2. Google Maps API key is set (GOOGLE_MAPS_API_KEY)")
 
59
  logger.info("MCP Server: FleetMind Dispatch Coordinator v1.0.0")
60
  logger.info("Protocol: Model Context Protocol (MCP)")
61
  logger.info("Transport: Server-Sent Events (SSE)")
62
+ logger.info(f"SSE Endpoint: https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse")
63
  logger.info("=" * 70)
64
  logger.info("Features:")
65
  logger.info(" βœ“ 29 AI Tools (Order + Driver + Assignment Management)")
 
83
  logger.info(' "command": "npx",')
84
  logger.info(' "args": [')
85
  logger.info(' "mcp-remote",')
86
+ logger.info(' "https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse"')
87
  logger.info(' ]')
88
  logger.info(' }')
89
  logger.info(' }')
 
94
  logger.info("=" * 70)
95
 
96
  try:
97
+ # Create FastAPI app with landing page
98
+ from fastapi import FastAPI
99
+ from fastapi.responses import HTMLResponse
100
+ import uvicorn
101
+ import threading
102
+
103
+ # Create FastAPI app
104
+ app = FastAPI(title="FleetMind MCP Server")
105
+
106
+ # Add landing page
107
+ @app.get("/", response_class=HTMLResponse)
108
+ async def landing_page():
109
+ """Landing page with MCP connection information"""
110
+ return """
111
+ <!DOCTYPE html>
112
+ <html>
113
+ <head>
114
+ <title>FleetMind MCP Server</title>
115
+ <style>
116
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; max-width: 1000px; margin: 50px auto; padding: 20px; background: #f9fafb; }
117
+ .container { background: white; padding: 40px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
118
+ h1 { color: #1f2937; margin-top: 0; }
119
+ h2 { color: #374151; border-bottom: 2px solid #e5e7eb; padding-bottom: 10px; }
120
+ h3 { color: #4b5563; }
121
+ code { background: #f3f4f6; padding: 3px 8px; border-radius: 4px; font-family: 'Courier New', monospace; }
122
+ pre { background: #1f2937; color: #f9fafb; padding: 20px; border-radius: 8px; overflow-x: auto; }
123
+ .endpoint { background: #eff6ff; padding: 15px; margin: 15px 0; border-left: 4px solid #3b82f6; border-radius: 4px; }
124
+ .feature { background: #f0fdf4; padding: 15px; margin: 10px 0; border-left: 4px solid #10b981; border-radius: 4px; }
125
+ .badge { display: inline-block; background: #3b82f6; color: white; padding: 4px 12px; border-radius: 12px; font-size: 12px; margin: 5px; }
126
+ a { color: #3b82f6; text-decoration: none; }
127
+ a:hover { text-decoration: underline; }
128
+ ol { line-height: 1.8; }
129
+ ul { line-height: 1.8; }
130
+ </style>
131
+ </head>
132
+ <body>
133
+ <div class="container">
134
+ <h1>🚚 FleetMind MCP Server</h1>
135
+ <p><strong>Enterprise Model Context Protocol Server for AI-Powered Delivery Dispatch</strong></p>
136
+ <p><span class="badge">MCP 1st Birthday Hackathon</span> <span class="badge">Track 1: Building MCP</span> <span class="badge">Enterprise Category</span></p>
137
+
138
+ <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;">
139
+
140
+ <h2>πŸ”Œ MCP Server Connection</h2>
141
+
142
+ <div class="endpoint">
143
+ <strong>SSE Endpoint URL:</strong><br>
144
+ <code>https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse</code>
145
+ </div>
146
+
147
+ <h3>βš™οΈ Claude Desktop Configuration</h3>
148
+ <p>Add this to your <code>claude_desktop_config.json</code> file:</p>
149
+ <pre>{
150
+ "mcpServers": {
151
+ "fleetmind": {
152
+ "command": "npx",
153
+ "args": [
154
+ "mcp-remote",
155
+ "https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse"
156
+ ]
157
+ }
158
+ }
159
+ }</pre>
160
+
161
+ <h3>πŸ“‹ How to Connect</h3>
162
+ <ol>
163
+ <li>Install <a href="https://claude.ai/download" target="_blank">Claude Desktop</a></li>
164
+ <li>Locate your <code>claude_desktop_config.json</code> file</li>
165
+ <li>Add the configuration shown above</li>
166
+ <li>Restart Claude Desktop</li>
167
+ <li>Look for "FleetMind" in the πŸ”Œ tools menu</li>
168
+ </ol>
169
+
170
+ <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;">
171
+
172
+ <h2>πŸ› οΈ Available Tools (29 Total)</h2>
173
+
174
+ <div class="feature">
175
+ <strong>πŸ“ Geocoding & Routing (3 tools):</strong><br>
176
+ geocode_address, calculate_route, calculate_intelligent_route
177
+ </div>
178
+
179
+ <div class="feature">
180
+ <strong>πŸ“¦ Order Management (8 tools):</strong><br>
181
+ create_order, count_orders, fetch_orders, get_order_details, search_orders, get_incomplete_orders, update_order, delete_order
182
+ </div>
183
+
184
+ <div class="feature">
185
+ <strong>πŸ‘₯ Driver Management (8 tools):</strong><br>
186
+ create_driver, count_drivers, fetch_drivers, get_driver_details, search_drivers, get_available_drivers, update_driver, delete_driver
187
+ </div>
188
+
189
+ <div class="feature">
190
+ <strong>πŸ”— Assignment Management (8 tools):</strong><br>
191
+ create_assignment, <strong>auto_assign_order</strong>, <strong>intelligent_assign_order</strong>, get_assignment_details, update_assignment, unassign_order, complete_delivery, fail_delivery
192
+ </div>
193
+
194
+ <div class="feature">
195
+ <strong>πŸ—‘οΈ Bulk Operations (2 tools):</strong><br>
196
+ delete_all_orders, delete_all_drivers
197
+ </div>
198
+
199
+ <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;">
200
+
201
+ <h2>⭐ Key Features</h2>
202
+ <ul>
203
+ <li><strong>🧠 Gemini 2.0 Flash AI</strong> - Intelligent order assignment with detailed reasoning</li>
204
+ <li><strong>🌦️ Weather-Aware Routing</strong> - Safety-first delivery planning with OpenWeatherMap</li>
205
+ <li><strong>🚦 Real-Time Traffic</strong> - Google Routes API integration with live traffic data</li>
206
+ <li><strong>πŸ“Š SLA Tracking</strong> - Automatic on-time performance monitoring</li>
207
+ <li><strong>πŸ—„οΈ PostgreSQL Database</strong> - Production-grade data storage (Neon)</li>
208
+ <li><strong>πŸš€ Multi-Client Support</strong> - Works with Claude Desktop, Continue, Cline, any MCP client</li>
209
+ </ul>
210
+
211
+ <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;">
212
+
213
+ <h2>πŸ“š Resources</h2>
214
+ <ul>
215
+ <li><strong>GitHub:</strong> <a href="https://github.com/mashrur-rahman-fahim/fleetmind-mcp" target="_blank">mashrur-rahman-fahim/fleetmind-mcp</a></li>
216
+ <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>
217
+ <li><strong>MCP Protocol Docs:</strong> <a href="https://modelcontextprotocol.io" target="_blank">modelcontextprotocol.io</a></li>
218
+ </ul>
219
+
220
+ <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;">
221
+
222
+ <p style="text-align: center; color: #6b7280; font-size: 14px;">
223
+ FleetMind v1.0 - Built for MCP 1st Birthday Hackathon<br>
224
+ 29 AI Tools | 2 Real-Time Resources | Enterprise-Ready
225
+ </p>
226
+ </div>
227
+ </body>
228
+ </html>
229
+ """
230
+
231
+ logger.info("[OK] Landing page added at /")
232
+
233
+ # Start MCP SSE server in background thread
234
+ def run_mcp_sse():
235
+ logger.info("[STARTING] MCP SSE endpoint in background...")
236
+ mcp.run(transport="sse", host="0.0.0.0", port=7861) # Different port temporarily
237
+
238
+ mcp_thread = threading.Thread(target=run_mcp_sse, daemon=True)
239
+ mcp_thread.start()
240
+ logger.info("[OK] MCP SSE server started on port 7861")
241
+
242
+ # Add proxy route for /sse that forwards to port 7861
243
+ @app.get("/sse")
244
+ @app.post("/sse")
245
+ async def mcp_sse_proxy():
246
+ """Proxy to MCP SSE server on port 7861"""
247
+ import httpx
248
+ async with httpx.AsyncClient() as client:
249
+ response = await client.get("http://localhost:7861/sse", timeout=None)
250
+ return response
251
+
252
+ logger.info("[OK] SSE proxy added at /sse")
253
+
254
+ # Run FastAPI app
255
+ logger.info(f"[STARTING] Unified server on {HF_SPACE_HOST}:{HF_SPACE_PORT}")
256
+ uvicorn.run(app, host=HF_SPACE_HOST, port=HF_SPACE_PORT, log_level="info")
257
+
258
  except Exception as e:
259
+ logger.error(f"Failed to start server: {e}")
260
  logger.error("Check that:")
261
  logger.error(" 1. Database connection is configured (DB_HOST, DB_USER, etc.)")
262
  logger.error(" 2. Google Maps API key is set (GOOGLE_MAPS_API_KEY)")