ChatSQL MCP Server
Converts natural language questions into SQL queries using Google Gemini.
Executes generated SQL queries against a PostgreSQL database and returns results.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ChatSQL MCP ServerShow me all employees with salary over 50000"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
π¬ 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.11For 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.shOnce 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.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/thomasjerard/ChatSQL'
If you have feedback or need assistance with the MCP directory API, please join our Discord server