Zomato MCP Server
README.md
# š Zomato Voice Bot (MCP-Powered)
An interactive, voice-activated food ordering bot powered by the **Model Context Protocol (MCP 2.x)**. Users can speak naturally to search restaurants, build food carts, handle out-of-stock item replacements interactively, calculate the best discounts/coupons, and confirm the exact final best amount before placing the order.
---
## š Key Features
1. **Model Context Protocol (MCP 2.x) Integration**:
- Implements standard MCP tools:
- `search_restaurants`: Discover restaurants by cuisine, rating, budget, and location.
- `get_menu`: Browse categories, dishes, prices, and food details.
- `check_item_availability`: Real-time stock verification with automatic alternative recommendations.
- `add_to_cart`: Add items with quantity and customization options.
- `calculate_best_amount`: Evaluates all coupons (`ZOMATO50`, `FEAST150`, `GOLDDELIVERY`, `JUMBO200`), maximizes discounts, calculates delivery fees, taxes, and generates the voice confirmation phrase.
- `confirm_and_place_order`: Places order only after final user agreement, generating Order ID and payment QR.
- `track_order`: Live order tracking and delivery partner status.
- Dual-mode support: Runs with the built-in local MCP server or connects to the remote Zomato MCP endpoint (`https://mcp-server.zomato.com/mcp`).
2. **Interactive Voice Assistance (STT & TTS)**:
- **Speech Recognition**: Voice input via Web Speech API in the browser or terminal input.
- **Natural Voice Feedback**: Spoken audio replies (English with Indian accent `en-IN` / `gTTS` / SpeechSynthesis).
- **Visual Voice Orb**: Pulsing glowing voice orb with animated sound rings and waveform bars reacting to speech.
3. **Smart Missing & Out-of-Stock Handling**:
- If an item is unavailable (e.g. Garlic Naan at Paradise Biryani or Cheesy Dip at Domino's), the bot **does not fail or drop it silently**.
- It actively speaks:
> *"However, Garlic Naan is currently out of stock at Paradise Biryani. They have Butter Naan (ā¹45) and Tandoori Roti (ā¹30) available. Would you like me to add one of these instead, or skip it?"*
- Listens to the user's answer ("Yes, add butter naan instead" or "Skip it") and updates the order state seamlessly.
4. **Mandatory Final Best Amount Confirmation**:
- The bot automatically evaluates all coupons, applies the biggest discount, and speaks the exact final amount:
> *"You have 2x Chicken Dum Biryani and 1x Butter Naan from Paradise Biryani. The subtotal is ā¹605. With coupon FEAST150 applied saving ā¹150, including delivery and taxes, your final best amount is ā¹497. Should I confirm and place your order?"*
- Waits for the user's voice confirmation (*"Yes, place order"*).
5. **Production-Grade Persistence & Agent Memory**:
- **Database Architecture**: Async SQLAlchemy 2.0 with high-throughput SQLite (`journal_mode=WAL`) or PostgreSQL.
- **Persistent Active Cart**: Food items and pricing breakdown remain intact across browser tabs, reloads, and server restarts.
- **Long-term Agent Memory**: Autonomously learns dietary preferences (Veg/Non-Veg), preferred payment methods (UPI/Zomato Money/COD), favorite restaurants, and favorite dishes across voice sessions.
- **Order History & Audit Trail**: Real-time order records with tracking URLs and payment states (including live order `#8585879147`).
- **MCP Tool Call Auditing**: Every tool invocation is logged with execution duration (`duration_ms`), arguments, and status in `mcp_audit_logs`.
6. **Modern Web Voice Console & Terminal CLI**:
- **Web UI (`http://localhost:8000`)**: Full-screen foodie dark theme with live Cart sidebar, Best Offer badge, real-time MCP tool call inspector, Orders History modal, and Memory Profile manager.
- **Terminal CLI (`./run.sh cli`)**: Lightweight command-line interface with spoken audio.
---
## š Quick Start
### 1. Run the Web Voice Assistant
```bash
./run.sh
# or
./run.sh web
```
Open your browser at **`http://localhost:8000`**. Tap the microphone icon or say:
> *"Order 2 chickpea salads from Lulu Hypermarket"*
### 2. Run the Terminal Voice Assistant
```bash
./run.sh cli
```
### 3. Run the Automated Test Suite
```bash
./run.sh test
# or
.venv/bin/pytest -v tests/
```
### 4. Run the Zomato MCP Server directly via stdio
```bash
./run.sh mcp
```
---
## š Production REST API Endpoints
- **`GET /health`**: Production health check reporting uptime, database connectivity, and MCP server status.
- **`GET /api/orders`**: Retrieves historical and current orders with items, pricing, and live tracking links.
- **`GET /api/memory`**: Fetches long-term user preferences, favorite dishes, and dietary habits.
- **`POST /api/memory/preference`**: Explicitly updates dietary, payment, or restaurant preferences.
- **`GET /api/audit/logs`**: Audits all MCP tool executions with millisecond latency timings.
- **`GET /api/conversation/{session_id}`**: Retrieves chat history for multi-turn session persistence.
---
## š£ļø Example Voice Walkthrough
| User Voice Input | Bot Voice Response | MCP Tool Call |
| :--- | :--- | :--- |
| š¤ *"Order 2 chicken biryanis and garlic naan from Paradise Biryani"* | š *"I've added 2x Chicken Dum Biryani to your cart. However, Garlic Naan is currently not available at Paradise Biryani. They have Butter Naan (ā¹45) and Tandoori Roti (ā¹30) available. Would you like me to add one of these instead, or skip it?"* | `tools/call check_item_availability`<br>`tools/call add_to_cart` |
| š¤ *"Yes, add butter naan instead"* | š *"Added Butter Naan as replacement! You have 2x Chicken Dum Biryani, 1x Butter Naan from Paradise Biryani. The food subtotal is ā¹605. With coupon FEAST150 applied saving ā¹150, including delivery and taxes, your final best amount is ā¹497. Should I confirm and place your order?"* | `tools/call add_to_cart`<br>`tools/call calculate_best_amount` |
| š¤ *"Yes, place order"* | š *"Order placed successfully! Your Zomato Order ID is ZOM-0F7F4C. Arriving in approximately 30 to 35 minutes. Total amount of ā¹497 will be processed via UPI."* | `tools/call confirm_and_place_order` |
| š¤ *"What did I order earlier?"* | š *"You have 1 previous order on record: Order #8585879147 from Lulu Hypermarket for ā¹144.0. Track it here: https://zoma.to/t/GEAjkmaO"* | DB query `OrderRecord` |
---
## āļø Configuration (`.env`)
```env
# Database URL (SQLite WAL default or PostgreSQL)
DATABASE_URL=sqlite+aiosqlite:///./zomato_bot.db
# Optional: Gemini API Key
GEMINI_API_KEY=
GEMINI_MODEL=gemini-2.5-flash
# MCP Mode: "local" or "remote"
ZOMATO_MCP_MODE=remote
ZOMATO_MCP_REMOTE_URL=https://mcp-server.zomato.com/mcp
ZOMATO_MCP_AUTH_TOKEN=your_token_here
```
---
## š Project Structure
```
zomato_bot/
āāā zomato_bot/
ā āāā config.py # App, DB & MCP configuration
ā āāā audio.py # CLI text-to-speech audio engine
ā āāā cli.py # Terminal voice ordering console
ā āāā db/
ā ā āāā session.py # Async engine, connection pool & WAL pragmas
ā ā āāā models.py # SQLAlchemy 2.0 models (Session, Cart, Order, Memory, Audit)
ā āāā memory/
ā ā āāā service.py # Long-term preference learning & persistent cart/order CRUD
ā āāā mcp/
ā ā āāā server.py # Official MCP 2.x Server implementation
ā ā āāā client.py # MCP Client with async tool auditing
ā ā āāā tools.py # Restaurant, menu, cart & checkout logic
ā ā āāā data.py # Restaurant, menu, coupon data
ā āāā agent/
ā ā āāā bot.py # Unified agent interface
ā ā āāā nlp_fallback.py # Multi-turn voice conversation & intent manager
ā ā āāā prompts.py # System prompt & voice dialogue rules
ā āāā web/
ā āāā app.py # FastAPI REST & WebSocket endpoints with lifespan
ā āāā templates/
ā ā āāā index.html # Interactive Voice UI with Orders & Memory modals
ā āāā static/
ā āāā css/style.css # Zomato dark theme styling
ā āāā js/
ā āāā voice.js # Web Speech API STT/TTS engine
ā āāā app.js # UI, persistence syncing, Orders & Memory handlers
āāā tests/ # 16-test suite covering MCP, Agent, API & DB Persistence
āāā run.sh # Launcher script
āāā README.md
```
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues