File size: 5,531 Bytes
d69447e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b34b01
 
 
 
 
d69447e
 
 
 
 
 
 
 
 
0e59aa0
d69447e
6b34b01
d69447e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: FleetMind AI Dispatch Coordinator
emoji: 🚚
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.9.0
app_file: app.py
pinned: false
tags:
  - mcp
  - mcp-in-action-track-01
  - model-context-protocol
  - multi-agent
  - autonomous-ai
  - gemini-2.0-flash
  - delivery-management
  - postgresql
---

# FleetMind MCP - Autonomous Dispatch Coordinator

**πŸ† MCP 1st Birthday Hackathon Submission - Track: MCP in Action**

An autonomous AI coordinator that handles delivery exceptions using multi-agent orchestration powered by Google Gemini 2.0 Flash and the Model Context Protocol (MCP).

**πŸ”— Links:**
- **GitHub Repository:** https://github.com/mashrur-rahman-fahim/fleetmind-mcp
- **Hugging Face Space:** https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai
- **Auto-Sync:** Every push to GitHub automatically updates HF Space via GitHub Actions ✨

---

## πŸ‘₯ Team

**Team Name:** [Your Team Name]

**Team Members:**
- **[Your Name]** - [@your-hf-username](https://huggingface.co/your-hf-username) - Lead Developer & Repository Manager
- **[Partner 2 Name]** - [@partner2-username](https://huggingface.co/partner2-username) - [Role - e.g., Backend Developer, Testing]


**Collaboration:** Team collaborates via GitHub repository (https://github.com/mashrur-rahman-fahim/fleetmind-mcp) with automatic sync to HF Space via GitHub Actions.

*(Note: Replace placeholders with actual team member information. All members must have Hugging Face accounts and be listed here for valid hackathon submission.)*

---

## πŸš€ Quick Start

### 1. Install PostgreSQL

**Windows:**
- Download from https://www.postgresql.org/download/windows/
- Install with default settings
- Remember your postgres password

**macOS:**
```bash
brew install postgresql
brew services start postgresql
```

**Linux:**
```bash
sudo apt-get install postgresql postgresql-contrib
sudo systemctl start postgresql
```

### 2. Create Database

```bash
# Login to PostgreSQL
psql -U postgres

# Create the database
CREATE DATABASE fleetmind;

# Exit
\q
```

### 3. Set Up Environment

```bash
# Install Python dependencies
pip install -r requirements.txt

# Copy environment template
cp .env.example .env

# Edit .env with your database credentials
# DB_HOST=localhost
# DB_PORT=5432
# DB_NAME=fleetmind
# DB_USER=postgres
# DB_PASSWORD=your_password_here
```

### 4. Initialize Database Schema

```bash
# Run database initialization script
python scripts/init_db.py
```

This will create all necessary tables in the PostgreSQL database.

### 3. Run Application

```bash
# Start the Gradio UI (coming soon)
python ui/app.py
```

## πŸ“ Project Structure

```
fleetmind-mcp/
β”œβ”€β”€ database/               # Database connection and schema
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ connection.py      # Database connection utilities
β”‚   └── schema.py          # Database schema definitions
β”œβ”€β”€ data/                  # Database and data files
β”‚   └── fleetmind.db      # SQLite database (auto-generated)
β”œβ”€β”€ mcp_server/           # MCP server implementation
β”œβ”€β”€ agents/               # Multi-agent system
β”œβ”€β”€ workflows/            # Orchestration workflows
β”œβ”€β”€ ui/                   # Gradio interface
β”œβ”€β”€ tests/                # Test suite
β”œβ”€β”€ scripts/              # Utility scripts
β”‚   └── init_db.py       # Database initialization
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ .env.example         # Environment variables template
└── README.md            # This file
```

## πŸ“Š Database Schema (PostgreSQL)

The system uses PostgreSQL with the following tables:

### Orders Table

The `orders` table stores all delivery order information:

| Column | Type | Description |
|--------|------|-------------|
| order_id | VARCHAR(50) | Primary key |
| customer_name | VARCHAR(255) | Customer name |
| customer_phone | VARCHAR(20) | Contact phone |
| customer_email | VARCHAR(255) | Contact email |
| delivery_address | TEXT | Delivery address |
| delivery_lat/lng | DECIMAL(10,8) | GPS coordinates |
| time_window_start/end | TIMESTAMP | Delivery time window |
| priority | VARCHAR(20) | standard/express/urgent |
| weight_kg | DECIMAL(10,2) | Package weight |
| status | VARCHAR(20) | pending/assigned/in_transit/delivered/failed/cancelled |
| assigned_driver_id | VARCHAR(50) | Assigned driver |
| created_at | TIMESTAMP | Creation timestamp |
| updated_at | TIMESTAMP | Auto-updated timestamp |

### Additional Tables

- **drivers** - Driver information and status
- **assignments** - Order-driver assignments with routing
- **exceptions** - Exception tracking and resolution
- **agent_decisions** - AI agent decision logging
- **metrics** - Performance metrics and analytics

## πŸ”§ Development

### Database Operations

```python
from database.connection import get_db_connection, execute_query, execute_write

# Get all pending orders (note: PostgreSQL uses %s for parameters)
orders = execute_query("SELECT * FROM orders WHERE status = %s", ("pending",))

# Create new order
order_id = execute_write(
    "INSERT INTO orders (order_id, customer_name, delivery_address, status) VALUES (%s, %s, %s, %s)",
    ("ORD-001", "John Doe", "123 Main St", "pending")
)

# Test connection
from database.connection import test_connection
if test_connection():
    print("Database connected successfully!")
```

## πŸ“ License

MIT License

## 🀝 Contributing

Contributions welcome! Please read the contributing guidelines first.