MCP-Server-data
by nishant264
README.md
# ⨠Gemini + MCP Playground
An AI agent that uses **Google Gemini** and the **Model Context Protocol (MCP)** to securely interact with data and tools.
Built with **Streamlit**, **Gemini**, **Agno**, and a custom **MCP server** ā no Docker needed!
---
## š Why This Project?
This showcases **AI Engineering** skills:
| Skill | How It's Shown |
|-------|---------------|
| **AI Agent Architecture** | Google Gemini + Agno agent that decides which tools to call |
| **MCP Protocol** | Custom MCP server with read-only SQL tools + security guardrails |
| **Security Engineering** | Guards blocking dangerous queries (DELETE, DROP, etc.) |
| **Full-Stack AI** | Streamlit UI + AI backend + local database |
| **Practical Features** | One-click CSV/JSON/Markdown export |
---
## ⨠Features
- **Natural Language Queries** ā Ask questions in plain English about a sample e-commerce database
- **Custom MCP Server** ā A local server that translates AI requests into safe database queries
- **š Security Guardrails** ā Only SELECT queries allowed; all modifications blocked
- **Multiple Export Formats** ā Download results as CSV, JSON, or Markdown with one click
- **AI-Assisted Export** ā Just say *"export this as CSV"* and the AI handles it
- **Tool Transparency** ā See exactly which tools the AI calls and what SQL it writes
---
## š§ How It Works
```
You: "Show me all products over $50"
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Streamlit Web App (github_agent.py) ā
ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā Gemini (Google AI) ā ā
ā ā ⢠Understands your question ā ā
ā ā ⢠Decides which tool to call ā ā
ā ā ⢠Formats the answer ā ā
ā āāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāā ā
ā ā MCP Protocol ā
ā ā¼ ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā MCP Server (db_mcp_server.py) ā ā
ā ā ⢠Validates query (read-only?) ā ā
ā ā ⢠Runs SELECT on SQLite DB ā ā
ā ā ⢠Returns formatted results ā ā
ā āāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāā ā
ā ā ā
ā ā¼ ā
ā āāāāāāāāāāāāāāāā ā
ā ā store.db ā (SQLite file) ā
ā āāāāāāāāāāāāāāāā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
```
---
## š Quick Start
### Requirements
- **Python 3.8+**
- **Gemini API Key** ā Get one free at [aistudio.google.com/apikey](https://aistudio.google.com/apikey)
> No Docker. No GitHub token. No OpenAI key.
### Installation
```bash
# 1. Install dependencies
pip install -r requirements.txt
# 2. Generate the sample database
python seed_db.py
# 3. Start the app
streamlit run github_agent.py
```
### Usage
1. **Enter your Gemini API key** in the sidebar (get one free at [aistudio.google.com/apikey](https://aistudio.google.com/apikey))
2. **Type a question** about the store data ā e.g., *"Show me all products under $50"*
3. **Click "Run Query"** and watch the AI work!
4. **Export results** using the download buttons below the response
---
## š¬ Example Queries
Try asking the AI:
```
š "Show me all products sorted by price"
š "Which customers have placed the most orders?"
š "What's the total revenue from last month?"
š "Show me orders that haven't shipped yet"
š "Export all products as CSV"
š "How many customers do we have from each city?"
```
---
## š Project Structure
| File | Purpose |
|------|---------|
| `github_agent.py` | Main Streamlit app ā UI + AI agent connection |
| `db_mcp_server.py` | Custom MCP server ā read-only SQL tools + export |
| `seed_db.py` | Script to generate the sample database |
| `store.db` | SQLite database with sample e-commerce data |
| `requirements.txt` | Python dependencies |
| `exports/` | Folder where exported files are saved (created on first export) |
---
## šļø Database Schema
The sample database (`store.db`) contains 5 tables with 30 orders, 25 products, and 10 customers:
| Table | Description |
|-------|-------------|
| `categories` | Product categories (Electronics, Clothing, Books, etc.) |
| `products` | Items for sale with prices and stock |
| `customers` | Customer information |
| `orders` | Orders placed with status (delivered, shipped, etc.) |
| `order_items` | Individual products within each order |
---
## š Security Guardrails
The MCP server has layers of protection:
1. **Keyword blocking** ā Queries starting with `DELETE`, `DROP`, `INSERT`, `UPDATE`, etc. are rejected
2. **Multi-statement detection** ā Multiple SQL statements separated by `;` are individually checked
3. **Result limiting** ā Maximum 100 rows returned per query
4. **Read-only export** ā Export tool also validates queries before writing files
---
## š ļø Tech Stack
| Technology | Role |
|-----------|------|
| **[Streamlit](https://streamlit.io/)** | Web UI framework |
| **[Google Gemini](https://ai.google.dev/)** | AI model (via `google-generativeai`) |
| **[Agno](https://github.com/agno-agi/agno)** | AI agent framework |
| **[MCP](https://modelcontextprotocol.io/)** | Model Context Protocol (tool communication standard) |
| **[SQLite](https://www.sqlite.org/)** | Local database (built into Python) |
---
## š License
This project is for educational purposes. Built as a demonstration of AI Agent + MCP architecture.
This server cannot be deployed
Maintenance
ActivitySlowing
ResponsivenessNo issues