Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

SQL_MCP_Server

MCP.Pizza Chef: pawankumar94

SQLGenius is an MCP server that leverages Vertex AI's Gemini Pro to convert natural language into SQL queries for BigQuery. It features an interactive Streamlit UI with real-time query execution, data visualization, schema exploration, and query history tracking. Built with MCP architecture, it ensures safe query validation and seamless integration with BigQuery for efficient data exploration.

Use This MCP server To

Convert natural language questions into BigQuery SQL queries Visualize query results in real-time within an interactive UI Explore database schema interactively to understand table structures Track and review historical SQL queries for auditing or reuse Validate SQL queries safely before execution to prevent errors Integrate with BigQuery for seamless data querying and analysis

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.

SQL_MCP_Server FAQ

How does SQLGenius convert natural language to SQL?
SQLGenius uses Vertex AI's Gemini Pro model to translate natural language inputs into accurate SQL queries.
Can I visualize query results directly in SQLGenius?
Yes, SQLGenius provides real-time data visualization within its Streamlit interface.
How does SQLGenius ensure query safety?
It includes safe query validation mechanisms to prevent execution of harmful or malformed SQL commands.
What databases does SQLGenius support?
Currently, SQLGenius integrates specifically with Google BigQuery for querying and data exploration.
Is SQLGenius built on MCP architecture?
Yes, SQLGenius is built using the Model Context Protocol for modular and secure AI integration.
How can I track my past queries?
SQLGenius maintains a query history tab where you can review and reuse previous SQL queries.
What technologies power SQLGenius?
SQLGenius uses Vertex AI's Gemini Pro, Streamlit for UI, and MCP for protocol management.
How do I install SQLGenius?
Clone the repository, install dependencies via pip, and configure environment variables as per the README instructions.