An open API service indexing awesome lists of open source software.

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.

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.



npm version


npm downloads


MIT license


---

## โœจ 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!