https://github.com/mergisi/ai2sql-mcp
AI2SQL MCP Server - Generate, explain, optimize and fix SQL queries from natural language inside Claude Code. Supports PostgreSQL, MySQL, SQL Server, Snowflake, Oracle, SQLite.
https://github.com/mergisi/ai2sql-mcp
ai2sql claude claude-code database developer-tools mcp mysql postgresql sql text-to-sql
Last synced: 13 days ago
JSON representation
AI2SQL MCP Server - Generate, explain, optimize and fix SQL queries from natural language inside Claude Code. Supports PostgreSQL, MySQL, SQL Server, Snowflake, Oracle, SQLite.
- Host: GitHub
- URL: https://github.com/mergisi/ai2sql-mcp
- Owner: mergisi
- License: mit
- Created: 2026-06-02T21:27:59.000Z (21 days ago)
- Default Branch: main
- Last Pushed: 2026-06-02T21:32:13.000Z (21 days ago)
- Last Synced: 2026-06-02T22:06:22.230Z (21 days ago)
- Topics: ai2sql, claude, claude-code, database, developer-tools, mcp, mysql, postgresql, sql, text-to-sql
- Language: JavaScript
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
๐ค AI2SQL MCP Server
Write SQL 10ร faster โ inside Claude Code
Generate, explain, optimize, and fix SQL queries from natural language.
Supports PostgreSQL, MySQL, SQL Server, Snowflake, Oracle & SQLite.
---
## โจ What is this?
**AI2SQL MCP** turns plain English into SQL โ right inside your Claude Code terminal. No tab-switching, no Stack Overflow, no "WHERE clause syntax" rabbit holes.
```bash
# Instead of writing this yourself:
SELECT u.name, COUNT(o.id) as order_count, SUM(o.total) as revenue
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE o.created_at >= NOW() - INTERVAL '30 days'
AND u.status = 'active'
GROUP BY u.name
HAVING SUM(o.total) > 1000
ORDER BY revenue DESC
LIMIT 10;
# You just type: "Show me active users who spent >$1000 in the last 30 days"
# AI2SQL generates the query. You run it.
```
---
## ๐ Quick Start (30 seconds)
Add this to your `~/.cursor/mcp.json` or Claude Code settings:
```json
{
"mcpServers": {
"ai2sql": {
"command": "npx",
"args": ["-y", "ai2sql-mcp"]
}
}
}
```
That's it. Restart Claude Code and you're ready.
---
## ๐ ๏ธ Tools
### `generate_sql` โ Text โ SQL
```markdown
> Generate a query to find top 10 customers by revenue last month
โ AI2SQL generates the perfect SQL with correct joins, aggregations, and filters
```
### `explain_sql` โ What does this query do?
```markdown
> Explain this query: SELECT ... (pastes complex SQL)
โ "This query joins the users and orders tables, filters for last quarter..."
```
### `optimize_sql` โ Make it faster
```markdown
> Optimize this query for PostgreSQL: SELECT * FROM orders WHERE ...
โ "Added index hints, rewrote subquery as JOIN, removed unnecessary columns"
```
### `fix_sql_error` โ Debug mode
```markdown
> Fix this query: SELECT ... (broken SQL)
> Error: column "status" does not exist
โ "Added missing column reference, fixed the GROUP BY clause"
```
### `list_schemas` โ Know your database (Pro)
```markdown
> Show me my database schemas
โ Returns all your saved tables, columns, and types from AI2SQL
```
---
## ๐ Pro Features
Get unlimited queries and schema-aware generation with an API key:
```json
{
"mcpServers": {
"ai2sql": {
"command": "npx",
"args": ["-y", "ai2sql-mcp"],
"env": {
"AI2SQL_API_KEY": "your-api-key-here"
}
}
}
}
```
**How to get your API key:**
1. Sign up at [ai2sql.io](https://ai2sql.io)
2. Go to **Dashboard โ API Keys**
3. Click **Generate New Key**
4. Copy and add to your config above
Without an API key you get **5 free queries per session** โ enough to try it out.
---
## ๐๏ธ Supported Databases
| Database | Dialect Name |
|----------|-------------|
| PostgreSQL | `postgres` |
| MySQL | `mysql` |
| SQL Server | `sqlserver` |
| Snowflake | `snowflake` |
| Oracle | `oracle` |
| SQLite | `sqlite` |
---
## ๐ก Use Cases
- **Data analysts** โ Stop writing JOINs from memory. Describe what you need.
- **Backend developers** โ Debug SQL errors without Googling error messages.
- **Database migrations** โ Generate ALTER TABLE, CREATE INDEX queries in seconds.
- **Learning SQL** โ See how natural language translates to real SQL queries.
- **Team onboarding** โ New devs can query production databases immediately.
---
## ๐ป Works With
| Platform | Setup |
|----------|-------|
| **Claude Code** | Add MCP config (see Quick Start) |
| **Cursor IDE** | Add to `~/.cursor/mcp.json` |
| **Windsurf** | Add to MCP settings |
| **Continue.dev** | Add to config.json |
| **Any MCP client** | Use `npx -y ai2sql-mcp` |
---
## ๐ฆ Installation (alternative)
```bash
# Run directly without installing
npx -y ai2sql-mcp
# Or install globally
npm install -g ai2sql-mcp
ai2sql-mcp
```
---
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Claude Code โโโโโโบโ ai2sql-mcp โโโโโโบโ AI2SQL API โ
โ (MCP client) โ โ (MCP server) โ โ (cloud) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ
โโโโโโโโโดโโโโโโโโ
โ SQL Generator โ
โ AI Engine โ
โโโโโโโโโโโโโโโโโ
```
---
## ๐ Changelog
See [releases](https://github.com/mergisi/ai2sql-mcp/releases).
---
## ๐ค Contributing
PRs welcome! Check the [issues](https://github.com/mergisi/ai2sql-mcp/issues) for feature requests and bugs.
---
## ๐ License
MIT ยฉ [Mustafa Ergisi](https://ai2sql.io)
---
๐ Website ยท
๐ฆ GitHub ยท
๐ฅ npm ยท
๐ฆ Twitter
โญ Star us on GitHub โ it helps other developers discover this tool!