Cursor MCP SQL Server: Query Your Database from Cursor

· · AI2SQL

Short answer: click Add to Cursor on ai2sql.io/mcp (or add https://builder.ai2sql.io/api/chatgpt-mcp to mcp.json), then click Needs login next to ai2sql in Settings → MCP and sign in with your AI2SQL account. Cursor’s agent can then read your real schema and run read-only SQL on PostgreSQL, MySQL or SQL Server while you code.

AI2SQL is a hosted MCP server for SQL databases. No API key or database password goes into Cursor’s config.

Why connect Cursor to your database

When Cursor can see your actual schema, it stops inventing table and column names. It writes migrations against tables that exist, generates queries that match your data, and answers questions like “how many rows in orders have a null customer_id?” from the database instead of guessing.

Setup

First connect your database in AI2SQL (Connections → Add database).

One click

  1. Click Add to Cursor on ai2sql.io/mcp or in the AI2SQL dashboard under AI agents → Cursor, and approve the server in Cursor.
  2. In Settings → MCP, click Needs login next to ai2sql.
  3. Sign in to AI2SQL and press Allow. The page tells you to go back to Cursor.

AI2SQL is also listed on Cursor Directory.

By hand

Add this to ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project):

{
  "mcpServers": {
    "ai2sql": {
      "url": "https://builder.ai2sql.io/api/chatgpt-mcp"
    }
  }
}

Then sign in from Settings → MCP as above.

Try it

Ask Cursor’s agent:

What tables are in my database, and what do they hold?

It calls list_connections and describe_schema, then answers from your real schema. For data questions it writes a SELECT and runs it with run_query.

Tools Cursor gets

ToolWhat it does
list_connectionsLists the databases you connected in AI2SQL
describe_schemaTables, columns and types for one connection
run_queryOne read-only SELECT / WITH, up to 1,000 rows
generate_sqlWrites SQL from a plain-English request
fix_sql, explain_sql, optimize_sql, convert_sqlRepair, explain, tune or translate a query

Safety

  • Read-only. The SQL guard blocks writes and DDL before they reach the database. More in is it safe to connect AI to a database.
  • No secrets in the repo. mcp.json holds only the URL.
  • Logged. Every call appears in Agent activity in the AI2SQL dashboard.

Supported databases

PostgreSQL, MySQL and SQL Server support live schema reads and queries. Postgres users can also follow connect Cursor to Postgres.

Other clients

Same gateway, different tool: Claude, ChatGPT, VS Code, Devin Desktop (Windsurf), Gemini CLI, n8n and your own agent.

Frequently asked questions

How do I add a SQL database MCP server to Cursor?

Click Add to Cursor on ai2sql.io/mcp, or add an ai2sql entry with the URL https://builder.ai2sql.io/api/chatgpt-mcp under mcpServers in ~/.cursor/mcp.json. Then click Needs login next to ai2sql in Settings → MCP and sign in with your AI2SQL account.

Do I put my database password or an API key in mcp.json?

No. Cursor signs in to AI2SQL with OAuth. Database credentials stay encrypted on the AI2SQL server, so mcp.json is safe to commit.

Can Cursor's agent run DELETE or DROP through AI2SQL?

No. run_query accepts one SELECT or WITH statement and blocks writes and DDL before they reach the database.

Which databases does it support?

PostgreSQL, MySQL and SQL Server support live schema reads and queries.

What is free?

Signing in, listing connections, reading schemas and a few SQL writing requests a day are free. Running queries on your own database needs Pro or Team, which start with a 7-day trial.

TRY IT — FREE, NO SIGNUP
Try one: