A LangGraph-based AI agent that connects with a custom MCP server to provide natural language database interactions. SQL Pilot enables users to query, manipulate, and manage SQLite databases through conversational AI.
- Natural Language Queries: Ask questions about your database in plain English
- Database Operations: Read, insert, update, delete, and create tables
- Schema Management: View table structures and relationships
- Authentication & Security: Built-in user authentication with consent management
- Web Interface: Clean Gradio-based UI for easy interaction
- Session Memory: Maintains conversation context and database schema awareness
- List all tables in the database
- Read data with filtering, limits, and ordering
- Insert new records with validation
- Update existing records with WHERE clauses
- Delete records with safety constraints
- Create new tables with custom schemas
- Drop tables (with consent)
- Intelligent query parsing and operation planning
- Context-aware follow-up questions
- Automatic parameter mapping and validation
- Error handling and fallback mechanisms
- Session-based memory and learning
- Python 3.8+
- OpenAI API key (set in environment variables)
-
Clone the repository
git clone https://github.com/chandraprvkvsh/SQL-Pilot.git cd SQL-Pilot
-
Install dependencies
pip install -r requirements.txt cd Query-MCP pip install -r requirements.txt
-
Set environment variables
export OPENAI_API_KEY="your-openai-api-key"
-
Start the MCP Server
cd Query-MCP (github.com/chandraprvkvsh/Query-MCP) python server.py
-
Start the Web Interface (in a new terminal)
python ui.py
-
Access the Interface
- Open
http://localhost:7860
in your browser - Upload a SQLite database or create a sample database
- Start chatting with your database!
- Open
"Show me all tables in the database"
"List all users with their email addresses"
"Add a new user named 'Alice' with email 'alice@example.com'"
"Update the user with id 1 to have name 'Bob'"
"Create a new table called 'products' with columns id, name, and price"
"Show me the schema of the users table"
"What was the last operation I performed?"
- LangGraph Agent: Orchestrates the conversation flow and decision making
- Query-MCP Server: Custom MCP server handling database operations
- FastMCP Framework: Enables tool calling and resource management
- Gradio UI: Provides the web interface for user interaction
- SQLite Database: Stores and manages your data
- Persistent Agent Memory: Stores user context, session history, and schema awareness for intelligent multi-turn conversations
- Consent-based destructive operations
- Parameterized queries preventing SQL injection
- Input validation and sanitization
- Session timeout and cleanup