Skip to main content
Glama
deepan2003

Database-MCP

by deepan2003
README.md
# šŸ¢ Company Database AI Manager

## šŸ“– Overview
The Company Database AI Manager is a natural language interface for a corporate database. Instead of writing complex SQL queries to insert, update, or retrieve data, users can simply type commands in plain English (e.g., "Add an IT department and assign 5 employees to it"). 

The system uses the **Model Context Protocol (MCP)** to securely connect a Groq-powered LangGraph agent to a local Python database server. The AI autonomously reasons through the user's prompt, selects the correct database tools, executes the SQL operations, and returns the result in a clean Streamlit web interface.

## āš™ļø Architecture & How It Works
This project separates the database logic from the AI logic using a true Server/Client architecture:

1. **The Server (`server.py` & `models.py`)**: Runs an independent FastMCP server that hosts SQLite database tools (`setup_database`, `add_record`, `search_database`). 
2. **The Client (`client.py` & `app.py`)**: Runs a LangGraph agent powered by Groq's `llama-3.3-70b-versatile` or `openai/gpt-oss-120b`. 
3. **The Protocol (MCP)**: The client connects to the server securely via standard input/output (stdio). It asks the server for available tools, passes them to the LangGraph agent, and triggers the Python functions without directly importing them.

## šŸ“‚ Folder Structure

```text
šŸ“¦ llm-db-mcp
 ┣ šŸ“œ .env                # Stores secure API keys (Do NOT commit to GitHub)
 ┣ šŸ“œ .gitignore          # Prevents sensitive files from being pushed to Git
 ┣ šŸ“œ app.py              # The Streamlit web UI for interacting with the AI
 ┣ šŸ“œ client.py           # The terminal-based LangGraph agent script
 ┣ šŸ“œ company.db          # The automatically generated SQLite database file
 ┣ šŸ“œ models.py           # SQLAlchemy schemas (Departments, Roles, Employees, Projects)
 ┣ šŸ“œ requirements.txt    # Project dependencies and version numbers
 ā”— šŸ“œ server.py           # The FastMCP server hosting the database tools
```

## šŸš€ Setup & Installation

### 1. Prerequisites

Python 3.10 or higher.

A free Groq API Key.

### 2. Environment Setup

Create and activate a virtual environment (Conda is recommended):

```
conda create -n db_mcp python=3.11
conda activate db_mcp
```

### 3. Install Dependencies

Install all required packages from the requirements.txt file:

```
pip install -r requirements.txt
```

### 4. Configure API Keys

Create a .env file in the root directory and add your Groq API key:

```
GROQ_API_KEY=gsk_your_api_key_here
```

## šŸ–„ļø Usage

### Option 1: Run the Web UI (Recommended)
To launch the interactive chat interface, run:

```
streamlit run app.py
```

### Option 2: Run the Terminal Client
To run the agent strictly through the command line:

## šŸ› ļø Example Prompts to Try
Once the app is running, try typing these prompts into the chat:

"Set up the database tables." (Run this first!)

"Add an IT department."

"Add a new employee named John Doe with a salary of 75000 in the IT department."

"Show me all employees who make more than 50000."

## šŸ”’ Security Notes
Never commit your .env file or API keys to version control.

The .gitignore file is pre-configured to block .env and company.db from being uploaded to GitHub.