File size: 21,942 Bytes
d69447e
6eba330
d69447e
 
 
6eba330
d69447e
 
0c00a27
d69447e
 
0fef185
d69447e
 
 
6eba330
0c00a27
6eba330
 
0fef185
 
 
d69447e
 
6eba330
d69447e
6eba330
d69447e
0c00a27
6eba330
 
 
 
 
 
 
 
d69447e
6b34b01
0c00a27
 
 
 
6b34b01
0fef185
 
 
 
 
 
d69447e
 
 
 
0fef185
 
 
6eba330
0fef185
 
 
0e59aa0
6eba330
d69447e
6eba330
d69447e
0c00a27
 
 
 
 
6eba330
 
 
0fef185
6eba330
0c00a27
6eba330
0c00a27
6eba330
d69447e
0fef185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d69447e
 
 
 
6eba330
d69447e
6eba330
d69447e
6eba330
 
0fef185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6eba330
 
 
 
0fef185
 
 
 
 
 
6eba330
 
 
d69447e
 
6eba330
 
 
 
0fef185
6eba330
0fef185
6eba330
 
 
 
 
 
 
 
 
 
 
 
 
0c00a27
6eba330
 
0fef185
6eba330
 
 
 
 
 
d69447e
 
6eba330
 
0fef185
6eba330
0fef185
6eba330
 
 
 
0fef185
 
 
 
 
 
 
 
6eba330
 
0fef185
6eba330
 
0fef185
 
6eba330
 
 
 
 
0fef185
6eba330
 
0fef185
6eba330
 
0fef185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fef185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6eba330
 
 
 
 
 
 
 
 
 
 
 
0fef185
6eba330
 
 
 
 
 
 
 
 
d69447e
 
6eba330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d69447e
 
6eba330
 
 
 
 
d69447e
 
6eba330
d69447e
6eba330
 
 
d69447e
6eba330
 
 
 
 
 
 
 
d69447e
 
6eba330
d69447e
 
6eba330
 
 
 
 
 
 
 
 
 
 
 
 
d69447e
 
6eba330
 
 
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d69447e
6eba330
 
 
 
 
 
 
d69447e
 
6eba330
 
 
d69447e
6eba330
d69447e
6eba330
0fef185
6eba330
 
 
 
d69447e
6eba330
d69447e
6eba330
 
 
 
 
d69447e
6eba330
d69447e
6eba330
 
 
 
 
 
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
 
 
 
 
d69447e
6eba330
d69447e
6eba330
d69447e
6eba330
 
 
 
 
 
d69447e
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
---
title: FleetMind MCP Server
emoji: 🚚
colorFrom: blue
colorTo: purple
sdk: docker
app_file: app.py
pinned: false
short_description: Enterprise MCP server with 29 AI tools and Gemini 2.0 Flash intelligent assignment
tags:
  - mcp
  - building-mcp-track-enterprise
  - model-context-protocol
  - delivery-management
  - postgresql
  - fastmcp
  - gradio
  - enterprise
  - logistics
  - gemini
  - google-maps
  - ai-routing
---

# 🚚 FleetMind MCP Server

**πŸ† MCP 1st Birthday Hackathon - Track 1: Building MCP Servers (Enterprise Category)**

Industry-standard Model Context Protocol server for AI-powered delivery dispatch management. Exposes **29 AI tools** (including Gemini 2.0 Flash intelligent assignment) and 2 real-time resources for managing delivery operations through any MCP-compatible client. Features a professional web landing page with connection instructions.

[![FastMCP](https://img.shields.io/badge/FastMCP-2.13.0-blue)](https://github.com/jlowin/fastmcp)
[![Python](https://img.shields.io/badge/Python-3.10%2B-brightgreen)](https://www.python.org/)
[![MCP](https://img.shields.io/badge/MCP-1.0-orange)](https://modelcontextprotocol.io)

---

## πŸ”— Links

- **GitHub Repository:** https://github.com/mashrur-rahman-fahim/fleetmind-mcp
- **HuggingFace Space (Landing Page):** https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai
- **Live Space URL:** https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space
- **MCP SSE Endpoint:** https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse
- **Note:** Visit the Space URL above to see connection instructions and tool documentation

## πŸ“Ί Demo & Submission

- **Demo Video:** [Coming Soon - Will showcase Gemini 2.0 Flash AI assignment in action]
- **Social Media Post:** [Will be added upon submission]
- **Submission Date:** November 2025

---

## πŸ‘₯ Team

**FleetMind Development Team**

This project is submitted as part of the **MCP 1st Birthday Hackathon** (Track 1: Building MCP - Enterprise Category).

**Team Information:**
- Team members and HuggingFace profile links will be added before final submission
- For collaboration inquiries, please open an issue on the GitHub repository

---

## 🎯 What is FleetMind MCP?

FleetMind is a production-ready **Model Context Protocol (MCP) server** that transforms delivery dispatch management into AI-accessible tools.

**Access Methods:**
- **Web Landing Page**: Professional HTML page with connection instructions and tool documentation
- **MCP SSE Endpoint**: Direct API access for Claude Desktop, Continue, Cline, or any MCP client

### Key Features

βœ… **29 AI Tools** - Order, Driver & Assignment Management (including Gemini 2.0 Flash AI)
βœ… **2 Real-Time Resources** - Live data feeds (orders://all, drivers://all)
βœ… **Google Maps Integration** - Geocoding & Route Calculation with traffic data
βœ… **PostgreSQL Database** - Production-grade data storage (Neon)
βœ… **SSE Endpoint** - Standard MCP protocol via Server-Sent Events
βœ… **Multi-Client Support** - Works with any MCP-compatible client

### ⭐ Unique Features

#### πŸ€– Gemini 2.0 Flash AI Assignment
- Latest Google Gemini 2.0 Flash model (`gemini-2.0-flash-exp`) analyzes 10+ parameters
- Considers order priority, driver skills, traffic, weather, and complex tradeoffs
- Returns detailed AI reasoning explaining why each driver was selected
- Confidence scoring for transparency and accountability

#### 🌦️ Weather-Aware Routing
- OpenWeatherMap API integration for real-time conditions
- Weather impact analysis for delivery planning and safety
- Safety-first routing during adverse conditions (rain, fog, snow)
- Vehicle-specific weather safety warnings (especially for motorcycles)

#### 🏍️ Vehicle-Specific Optimization
- Motorcycle (TWO_WHEELER), Bicycle, Car/Van/Truck routing modes
- Different route optimization for each vehicle type
- Toll detection and avoidance capabilities
- Highway and ferry avoidance options for cost optimization

#### πŸ“Š SLA & Performance Tracking
- Mandatory delivery deadlines with configurable grace periods
- Automatic on-time vs late vs very_late classification
- Structured failure reason tracking (9 categories: customer unavailable, wrong address, etc.)
- Delivery performance analytics for reporting and optimization

#### 🚦 Real-Time Traffic Integration
- Google Routes API with live traffic data
- Traffic delay breakdown and alternative routes
- Triple fallback system (Routes API β†’ Directions API β†’ Mock calculation)
- 17+ traffic segments analyzed per route

#### 🎯 Three Assignment Methods
1. **Manual Assignment** - Direct driver selection for specific needs
2. **Auto Assignment** - Nearest driver with capacity/skill validation
3. **Intelligent AI Assignment** - Gemini 2.0 Flash analyzes all parameters with detailed reasoning

---

## πŸ† Why Track 1: Building MCP Servers (Enterprise Category)?

FleetMind demonstrates **enterprise-grade MCP server development** with cutting-edge AI integration and production-ready architecture:

### πŸ€– Advanced AI Integration
- **Gemini 2.0 Flash** - Latest Google AI model for intelligent decision-making
- **Weather-Aware Routing** - OpenWeatherMap API integration for safety-first planning
- **Real-Time Traffic Analysis** - Google Routes API with live traffic data and delay predictions
- **AI Reasoning & Transparency** - Detailed explanations for every intelligent assignment decision

### 🏒 Enterprise-Ready Features
- **PostgreSQL Database** - Production-grade data storage with Neon serverless PostgreSQL
- **SLA Tracking & Analytics** - Automatic performance monitoring with grace periods and violation detection
- **Triple Fallback System** - Routes API β†’ Directions API β†’ Mock calculation for 99.9% uptime
- **Multi-Client Support** - Standard MCP protocol works with Claude Desktop, Continue, Cline, and custom clients
- **SSE Web Transport** - Server-Sent Events for web-based MCP connectivity

### πŸš€ Production Deployment
- **HuggingFace Space** - Live production deployment with public SSE endpoint
- **Docker Containerization** - Reproducible deployment with Python 3.11 slim base
- **Environment Management** - Secure API key handling for Google Maps, Gemini, and OpenWeatherMap
- **29 Production Tools** - Complete fleet management suite ready for real-world use

### πŸ“Š Innovation & Complexity
- **Vehicle-Specific Optimization** - Motorcycle/Bicycle/Car/Van/Truck routing with toll detection
- **Structured Failure Tracking** - 9 failure reason categories for analytics and reporting
- **Cascading Status Updates** - Order β†’ Assignment β†’ Driver state management with FK constraints
- **Three Assignment Methods** - Manual, Auto (distance-based), and Intelligent AI (parameter-based)

FleetMind isn't just an MCP serverβ€”it's a **blueprint for enterprise AI integration** showcasing how MCP can transform complex logistics workflows into AI-accessible tools.

---

## πŸš€ Quick Start

### Connect from Claude Desktop

1. **Install Claude Desktop** from https://claude.ai/download

2. **Configure MCP Server** - Edit your `claude_desktop_config.json`:

**For Production (HuggingFace Space):**
```json
{
  "mcpServers": {
    "fleetmind_Prod": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse"
      ]
    }
  }
}
```

**For Local Development:**
```json
{
  "mcpServers": {
    "fleetmind": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:7860/sse"
      ]
    }
  }
}
```

**Both (Production + Local):**
```json
{
  "mcpServers": {
    "fleetmind": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:7860/sse"]
    },
    "fleetmind_Prod": {
      "command": "npx",
      "args": ["mcp-remote", "https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse"]
    }
  }
}
```

3. **Restart Claude Desktop** - FleetMind tools will appear automatically!

4. **Try it out:**
   - "Create an urgent delivery order for Sarah at 456 Oak Ave, San Francisco"
   - "Use intelligent AI assignment to find the best driver for this order"
   - "Show me all available drivers"
   - "Calculate route from downtown SF to Oakland Airport with weather conditions"

### Connect from VS Code (Continue)

1. Install Continue extension
2. Add FleetMind to MCP servers in settings
3. Use tools directly in your editor

### Connect from Custom App

```python
import mcp

client = mcp.Client(
    url="https://mcp-1st-birthday-fleetmind-dispatch-ai.hf.space/sse"
)

# Use any of the 29 tools
result = client.call_tool("create_order", {
    "customer_name": "John Doe",
    "delivery_address": "123 Main St, SF CA 94102",
    "delivery_lat": 37.7749,
    "delivery_lng": -122.4194
})
```

---

## πŸ› οΈ Available Tools (29 Total)

### Geocoding & Routing (3 tools)

| Tool | Description | Example Use |
|------|-------------|-------------|
| `geocode_address` | Convert address to GPS coordinates | "Geocode 123 Main St, San Francisco" |
| `calculate_route` | Vehicle-specific routing with real-time traffic | "Route from SF City Hall to Oakland Airport for motorcycle" |
| `calculate_intelligent_route` | **AI-powered weather + traffic aware routing** | "Calculate smart route considering weather and traffic" |

### Order Management (8 tools)

| Tool | Description | Example Use |
|------|-------------|-------------|
| `create_order` | Create new delivery orders with mandatory deadlines | "Create delivery for Sarah at 456 Oak Ave" |
| `count_orders` | Count orders with filters | "How many urgent orders are pending?" |
| `fetch_orders` | Retrieve orders with pagination | "Show me the 10 most recent orders" |
| `get_order_details` | Get complete order information with SLA data | "Show details for order ORD-20251114..." |
| `search_orders` | Search by customer/ID | "Find orders for customer John Smith" |
| `get_incomplete_orders` | List active deliveries | "Show all orders not yet delivered" |
| `update_order` | Update order details with cascading | "Mark order ORD-... as delivered" |
| `delete_order` | Safely remove orders with checks | "Delete test order ORD-TEST-001" |

### Driver Management (8 tools)

| Tool | Description | Example Use |
|------|-------------|-------------|
| `create_driver` | Onboard new drivers with skills validation | "Add driver Mike with plate ABC-123, motorcycle, fragile_handler skill" |
| `count_drivers` | Count drivers with filters | "How many active drivers are online?" |
| `fetch_drivers` | Retrieve drivers with pagination | "List all drivers sorted by name" |
| `get_driver_details` | Get driver info + location with reverse geocoding | "Show details for driver DRV-..." |
| `search_drivers` | Search by name/plate/ID | "Find driver with plate XYZ-789" |
| `get_available_drivers` | List drivers ready for dispatch | "Show available drivers near downtown" |
| `update_driver` | Update driver information with validation | "Update driver DRV-... status to busy" |
| `delete_driver` | Safely remove drivers with assignment checks | "Remove driver DRV-TEST-001" |

### Assignment Management (8 tools) ⭐ NEW

| Tool | Description | Example Use |
|------|-------------|-------------|
| `create_assignment` | Manually assign order to specific driver | "Assign order ORD-... to driver DRV-..." |
| **`auto_assign_order`** | **Automatic nearest driver assignment with validation** | **"Auto-assign this order to nearest available driver"** |
| **`intelligent_assign_order`** | **πŸ€– Gemini 2.0 Flash AI-powered assignment with reasoning** | **"Use AI to find the best driver for this urgent fragile delivery"** |
| `get_assignment_details` | View assignment details with route data | "Show assignment details for ASN-..." |
| `update_assignment` | Update assignment status with cascading | "Mark assignment ASN-... as in_progress" |
| `unassign_order` | Remove driver assignment safely | "Unassign order ORD-... from current driver" |
| `complete_delivery` | Mark delivery complete + auto-update driver location | "Complete delivery for assignment ASN-..." |
| `fail_delivery` | Track failed deliveries with GPS + structured reason | "Mark delivery failed: customer not available at current location" |

### Bulk Operations (2 tools)

| Tool | Description | Example Use |
|------|-------------|-------------|
| `delete_all_orders` | Bulk delete orders by status with safety checks | "Delete all cancelled orders" |
| `delete_all_drivers` | Bulk delete drivers by status with assignment checks | "Delete all offline drivers" |

---

## πŸ“Š Real-Time Resources (2 Total)

### `orders://all`
Live orders dataset (last 30 days, max 1000 orders)

**Example:**
```
"What's the status of recent orders?"
```

Claude automatically accesses this resource to provide context-aware answers.

### `drivers://all`
Live drivers dataset with current locations

**Example:**
```
"Which drivers are currently available?"
```

---

## πŸ”§ Technology Stack

**MCP Framework:**
- FastMCP 2.13.0 - MCP server implementation
- Model Context Protocol 1.0 - Standardized AI tool protocol

**AI & APIs:**
- Google Gemini 2.0 Flash (gemini-2.0-flash-exp) - Intelligent assignment
- Google Routes API - Real-time traffic routing
- Google Directions API - Fallback routing
- Google Geocoding API - Address conversion
- OpenWeatherMap API - Weather data integration

**Backend:**
- Python 3.10+ - Server runtime
- PostgreSQL (Neon) - Production database
- SSE (Server-Sent Events) - Web transport
- Docker - Containerized deployment

---

## πŸ—οΈ Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   MCP Clients                           β”‚
β”‚   (Claude Desktop, Continue, Custom)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚ MCP Protocol (SSE)
                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   FleetMind MCP Server (HF Space)       β”‚
β”‚   β€’ app.py (SSE endpoint)               β”‚
β”‚   β€’ server.py (29 tools, 2 resources)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        ↓                    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Google Maps   β”‚    β”‚ PostgreSQL   β”‚
β”‚ Geocoding API β”‚    β”‚ Database     β”‚
β”‚ Directions APIβ”‚    β”‚ (Neon)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Benefits of MCP Architecture:**
- βœ… Multi-client support (use from Claude, VS Code, mobile apps)
- βœ… Standardized protocol (MCP is industry-standard)
- βœ… Real-time data access (resources provide live context)
- βœ… Tool composability (AI combines tools intelligently)
- βœ… Easy integration (any MCP client can connect)

---

## πŸ“– Usage Examples

### Example 1: Create & Assign Order

**Prompt:**
```
Create an urgent delivery for Sarah Johnson at 456 Oak Ave, San Francisco CA.
Phone: 555-1234. Then assign it to the nearest available driver.
```

**What happens:**
1. Claude calls `geocode_address("456 Oak Ave, San Francisco CA")`
2. Gets coordinates: `(37.7749, -122.4194)`
3. Calls `create_order(...)` with all details
4. Calls `get_available_drivers(limit=10)`
5. Calls `calculate_route(...)` for each driver to find nearest
6. Calls `update_order(...)` to assign driver
7. Returns: "Order ORD-... created and assigned to John Smith (DRV-...), 5.2 km away, ETA 12 mins"

### Example 2: Track Active Deliveries

**Prompt:**
```
Show me all urgent orders that are currently in transit, sorted by deadline.
```

**What happens:**
1. Claude calls `fetch_orders(status="in_transit", priority="urgent", sort_by="time_window_end")`
2. Returns formatted list with customer names, addresses, drivers, and ETAs

### Example 3: Driver Management

**Prompt:**
```
How many drivers do we have available right now? Where are they located?
```

**What happens:**
1. Claude accesses `drivers://all` resource automatically
2. Filters for `status="active"`
3. Calls `get_driver_details(...)` for location addresses
4. Returns summary with driver count and locations

---

## πŸ—„οΈ Database Schema

### Orders Table (26 columns)

```sql
CREATE TABLE orders (
    order_id VARCHAR(50) PRIMARY KEY,
    customer_name VARCHAR(255) NOT NULL,
    customer_phone VARCHAR(20),
    customer_email VARCHAR(255),
    delivery_address TEXT NOT NULL,
    delivery_lat DECIMAL(10,8),
    delivery_lng DECIMAL(11,8),
    status VARCHAR(20) CHECK (status IN ('pending','assigned','in_transit','delivered','failed','cancelled')),
    priority VARCHAR(20) CHECK (priority IN ('standard','express','urgent')),
    time_window_end TIMESTAMP,
    assigned_driver_id VARCHAR(50),
    weight_kg DECIMAL(10,2),
    special_instructions TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    -- ... additional fields
);
```

### Drivers Table (15 columns)

```sql
CREATE TABLE drivers (
    driver_id VARCHAR(50) PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    phone VARCHAR(20),
    email VARCHAR(255),
    status VARCHAR(20) CHECK (status IN ('active','busy','offline','unavailable')),
    vehicle_type VARCHAR(50),
    vehicle_plate VARCHAR(20),
    capacity_kg DECIMAL(10,2),
    current_lat DECIMAL(10,8),
    current_lng DECIMAL(11,8),
    last_location_update TIMESTAMP,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```

---

## πŸ”§ Local Development

### Prerequisites

- Python 3.10+
- PostgreSQL database (or use Neon serverless)
- Google Maps API key

### Setup

```bash
# Clone repository
git clone https://github.com/mashrur-rahman-fahim/fleetmind-mcp.git
cd fleetmind-mcp

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your credentials:
#   DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD
#   GOOGLE_MAPS_API_KEY

# Test server
python -c "import server; print('Server ready!')"

# Run locally (stdio mode for Claude Desktop)
python server.py

# Run locally (SSE mode for web clients)
python app.py
```

### Testing

```bash
# Test with MCP Inspector
npx @modelcontextprotocol/inspector python server.py

# Test with Claude Desktop
# Add to claude_desktop_config.json:
{
  "mcpServers": {
    "fleetmind-local": {
      "command": "python",
      "args": ["F:\\path\\to\\fleetmind-mcp\\server.py"]
    }
  }
}
```

---

## πŸš€ Deployment to HuggingFace Space

This project is designed for **Track 1: Building MCP Servers** deployment on HuggingFace Spaces.

### Automatic Deployment

1. **Fork this repository** to your GitHub account

2. **Create HuggingFace Space:**
   - Go to https://huggingface.co/new-space
   - Name: `fleetmind-mcp` (or your choice)
   - SDK: Docker
   - Link to GitHub repository

3. **Configure Secrets** in HF Space settings:
   - `DB_HOST` - PostgreSQL host
   - `DB_PORT` - PostgreSQL port (5432)
   - `DB_NAME` - Database name
   - `DB_USER` - Database user
   - `DB_PASSWORD` - Database password
   - `GOOGLE_MAPS_API_KEY` - Google Maps API key

4. **Push to GitHub** - Space auto-updates via GitHub Actions!

### Manual Deployment

Upload files directly to HF Space:
- `app.py` (entry point)
- `server.py` (MCP server)
- `requirements.txt`
- `chat/`, `database/` directories
- `.env` (configure secrets in HF Space settings instead)

---

## πŸ“ Environment Variables

Required:
```bash
# Database (PostgreSQL/Neon)
DB_HOST=your-postgres-host.neon.tech
DB_PORT=5432
DB_NAME=fleetmind
DB_USER=your_user
DB_PASSWORD=your_password

# Google Maps API
GOOGLE_MAPS_API_KEY=your_api_key
```

Optional:
```bash
# Server configuration
PORT=7860
HOST=0.0.0.0
LOG_LEVEL=INFO
```

---

## πŸ† Why FleetMind for Track 1?

### Production-Ready MCP Server βœ…

- **Real Business Value:** Solves actual delivery dispatch problems
- **29 Tools:** Comprehensive order, driver & assignment management (including Gemini 2.0 Flash AI)
- **2 Resources:** Live data feeds for contextual AI responses
- **Industry Standard:** Uses FastMCP framework and MCP protocol
- **Scalable:** PostgreSQL database, stateless design
- **Well-Documented:** Comprehensive API reference and examples

### Enterprise Category Perfect Fit βœ…

- **Complex Operations:** Order creation, assignment, routing, tracking
- **External Integrations:** Google Maps API (geocoding + directions)
- **Database Operations:** Production PostgreSQL with 6 tables
- **Real-Time Data:** Live resources for orders and drivers
- **Multi-Tool Workflows:** Tools compose together (geocode β†’ create β†’ assign)

### Technical Excellence βœ…

- **882 lines** of well-structured MCP server code
- **2,099 lines** of battle-tested tool handlers
- **Type hints** throughout for reliability
- **Error handling** with graceful fallbacks
- **Logging infrastructure** for debugging
- **SSE transport** for web connectivity

---

## πŸ“„ License

MIT License - see LICENSE file for details.

---

## 🀝 Contributing

Contributions welcome! Please:
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push and open a Pull Request

---

## πŸ“ž Support

- **Issues:** https://github.com/mashrur-rahman-fahim/fleetmind-mcp/issues
- **Hackathon:** https://huggingface.co/MCP-1st-Birthday

---

**Built with ❀️ using [FastMCP](https://github.com/jlowin/fastmcp) for the MCP 1st Birthday Hackathon**

**Track 1: Building MCP Servers - Enterprise Category**