ChatSQL MCP Server
Enables natural language queries to PostgreSQL by converting questions to SQL using Google Gemini and executing via FastMCP.
README
💬 ChatSQL — Natural Language to SQL using Gemini & FastMCP
ChatSQL is a command-line tool that lets you query a PostgreSQL database using natural language. It uses Google Gemini to convert your questions into SQL, and FastMCP to execute them against your database.
🚀 Tech Stack
- Python 3.11+
- PostgreSQL (via
psycopg2) - FastMCP (Modular Composable Protocol)
- Google Gemini (for Natural Language to SQL conversion)
- Rich (for pretty command-line interface output)
- python-dotenv (for environment variable configuration)
🧠 Use Case
You ask a question in plain English, and ChatSQL generates and executes the SQL, then displays the results.
Input: "Get all employees earning more than 50000"
Generated SQL:
SELECT * FROM employees WHERE salary > 50000;
Output:
+----+---------+--------+------------+-----------+------------+
| id | name | salary | phone_no | address | department |
+----+---------+--------+------------+-----------+------------+
| 1 | Alice | 75000 | 9876543210 | New York | HR |
| 2 | Bob | 65000 | 1234567890 | Chicago | Finance |
+----+---------+--------+------------+-----------+------------+
⚙️ Setup Instructions
✅ 1. Clone the Repository & Configure Environment
> git clone https://github.com/thomasjerard/ChatSQL.git
> cd chatSQL
✅ 2. Prerequisites
- Bash shell is required (default on macOS/Linux).
- Python 3.11+ must be installed and accessible via your terminal. If not installed,
For macOS:
brew install python@3.11
For Linux:
sudo apt install python3.11 python3.11-venv
✅ 3. Create a .env file in the root folder with the following content:
DB_NAME=chattosql
DB_USER=postgres
DB_PASS=yourpassword
DB_HOST=localhost
DB_PORT=5432
GEMINI_API_KEY=your-gemini-api-key
✅ 3. Run the Application
You’ll need two separate terminals:
🖥️ Terminal 1 — Start the Server
./run_server.sh
💬Terminal 2 — Start the Client
./run_client.sh
Once the client starts, you'll see a prompt like:
💬 ChatSQL (Gemini + FastMCP) 🗨️ Ask (NL):
🔧 What Happens Internally
-
Each script (run_server.sh / run_client.sh) performs the following:
-
Deletes any existing virtual environment and creates a fresh one.
-
Loads environment variables from the .env file.
-
Installs required Python dependencies from requirements.txt.
-
Sets up PostgreSQL:
-
Creates the database (chattosql)
-
Adds the user (postgres)
-
Creates a sample employees table
-
Starts the FastMCP server or the ChatSQL CLI client, depending on the script.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.