Skip to content

An AI agent for real-time SQL database interaction, powered by a custom MCP server for efficient data operations.

License

Notifications You must be signed in to change notification settings

chandraprvkvsh/SQL-Pilot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Pilot

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.

Features

  • 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

Capabilities

Database Operations

  • 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)

AI-Powered Features

  • 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

Quick Start

Prerequisites

  • Python 3.8+
  • OpenAI API key (set in environment variables)

Installation

  1. Clone the repository

    git clone https://github.com/chandraprvkvsh/SQL-Pilot.git
    cd SQL-Pilot
  2. Install dependencies

    pip install -r requirements.txt
    cd Query-MCP
    pip install -r requirements.txt
  3. Set environment variables

    export OPENAI_API_KEY="your-openai-api-key"

Running the System

  1. Start the MCP Server

    cd Query-MCP (github.com/chandraprvkvsh/Query-MCP)
    python server.py
  2. Start the Web Interface (in a new terminal)

    python ui.py
  3. Access the Interface

    • Open http://localhost:7860 in your browser
    • Upload a SQLite database or create a sample database
    • Start chatting with your database!

Usage Examples

"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?"

Architecture

  • 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

Security Features

  • Consent-based destructive operations
  • Parameterized queries preventing SQL injection
  • Input validation and sanitization
  • Session timeout and cleanup

About

An AI agent for real-time SQL database interaction, powered by a custom MCP server for efficient data operations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages