SQLGenius - AI-Powered SQL Assistant

SQLGenius - AI-Powered SQL Assistant

SQLGenius is an AI-powered SQL assistant that converts natural language to SQL queries using Vertex AI's Gemini Pro. Built with MCP and Streamlit, it provides an intuitive interface for BigQuery data exploration with real-time visualization and schema management.

pawankumar94

Research & Data
Visit Server

README

SQLGenius - AI-Powered SQL Assistant

SQLGenius is an intelligent SQL assistant that helps you query your BigQuery database using natural language. Built with MCP (Model Context Protocol), Vertex AI's Gemini Pro, and Streamlit.

🌟 Features

  • Natural language to SQL conversion using Gemini Pro
  • Interactive Streamlit UI with multiple tabs
  • Real-time query execution and visualization
  • Database schema explorer
  • Query history tracking
  • Safe query validation
  • BigQuery integration
  • MCP-based architecture

🎥 Demo

Watch SQLGenius in action! Here's a quick demo of how to use the application:

SQLGenius Demo

In this demo, you can see:

  1. Natural language query conversion to SQL
  2. Interactive data visualization
  3. Schema exploration
  4. Query history tracking

🚀 Installation

  1. Clone the repository and navigate to the project directory:
cd sql_mcp_server
  1. Install dependencies:
pip install -r requirements.txt
  1. Copy the .env.example file to .env and fill in your configuration:
cp .env.example .env
  1. Set up your environment variables in .env:
PROJECT_ID=your-project-id
DATASET_ID=your-dataset-id
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service-account.json
VERTEX_AI_LOCATION=us-central1

🎮 Usage

  1. Start the application:
streamlit run streamlit_app.py
  1. The MCP server will start automatically when the Streamlit app launches

  2. Use the tabs to:

    • Ask natural language questions about your data
    • Write SQL queries directly
    • Explore your database schema

📊 Interface Tabs

💬 Natural Language Query

Ask questions in plain English and get SQL results:

  • "Show me the top 5 customers by revenue"
  • "What products have the highest sales in January?"
  • "How many orders were placed last month?"

📊 SQL Query

Write and execute SQL queries directly:

SELECT * FROM orders 
WHERE order_date > '2023-01-01' 
ORDER BY total_amount DESC
LIMIT 10

📋 Database Explorer

  • Browse available tables
  • View table schemas
  • See sample data from any table

🔒 Security Features

  • Only SELECT queries are permitted
  • Query validation to prevent dangerous operations
  • Secure credential management
  • Error handling and input validation

🛠️ Architecture

SQLGenius uses the Model Context Protocol (MCP) to expose tools that enable:

  1. Natural Language Processing: Convert English questions to SQL
  2. Data Exploration: Fetch schema information and sample data
  3. SQL Execution: Run validated queries against your database

The architecture consists of:

  • MCP Server: Handles DB connection and provides tools
  • Streamlit Frontend: User interface for interacting with the system
  • Vertex AI (Gemini Pro): Powers natural language understanding
  • BigQuery: Executes SQL queries on your data

📝 MCP Tools

The following MCP tools are available:

  1. execute_nl_query: Execute a natural language query
  2. execute_sql_query: Execute a raw SQL query
  3. list_tables: List all available tables
  4. get_table_schema: Get schema for a specific table

📚 Advanced Usage

To add custom tools to the MCP server:

  1. Edit the register_tools() method in sql_mcp_server.py
  2. Add your custom tool using the @self.tool() decorator
  3. Restart the server

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Recommended Servers

Crypto Price & Market Analysis MCP Server

Crypto Price & Market Analysis MCP Server

A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.

Featured
TypeScript
MCP PubMed Search

MCP PubMed Search

Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.

Featured
Python
dbt Semantic Layer MCP Server

dbt Semantic Layer MCP Server

A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.

Featured
TypeScript
mixpanel

mixpanel

Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.

Featured
TypeScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Featured
Python
Nefino MCP Server

Nefino MCP Server

Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.

Official
Python
Vectorize

Vectorize

Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.

Official
JavaScript
Mathematica Documentation MCP server

Mathematica Documentation MCP server

A server that provides access to Mathematica documentation through FastMCP, enabling users to retrieve function documentation and list package symbols from Wolfram Mathematica.

Local
Python
kb-mcp-server

kb-mcp-server

An MCP server aimed to be portable, local, easy and convenient to support semantic/graph based retrieval of txtai "all in one" embeddings database. Any txtai embeddings db in tar.gz form can be loaded

Local
Python
Research MCP Server

Research MCP Server

The server functions as an MCP server to interact with Notion for retrieving and creating survey data, integrating with the Claude Desktop Client for conducting and reviewing surveys.

Local
Python