Connect ChatGPT to a SQL database

ChatGPT can query your real database over MCP — read-only, logged and revocable. Here's how to wire it up without handing it your production credentials.

People increasingly ask ChatGPT to write SQL — and then wish it could just run the query against their actual data. With ChatGPT's developer-mode MCP connectors, it can. The question is how to do that without giving a general-purpose chatbot unrestricted access to a database that matters.

The AI2SQL Gateway is the safe path: ChatGPT connects to a hosted MCP endpoint that enforces read-only access, caps and times out queries, logs every call, and authenticates with a revocable key instead of your credentials.

Set it up in 3 steps

  1. Connect your database in the AI2SQL Gateway. Credentials are encrypted and stay server-side.
  2. Generate a gateway key — the wizard gives you the key and connection id.
  3. Add the MCP server in ChatGPT under Settings › Connectors › Advanced › Developer mode:
ChatGPT — Settings › Connectors › Developer mode
URL:    https://builder.ai2sql.io/api/mcp
Header: x-ai2sql-key: $AI2SQL_KEY
Header: x-ai2sql-connection: $CONNECTION_ID
✓ ai2sql connected — 3 tools available
  run_query · describe_schema · list_connections

Get $AI2SQL_KEY and $CONNECTION_ID from the AI2SQL Gateway — connect a database and the setup wizard generates both for you.

Now ChatGPT can call describe_schema to learn your tables and run_query to answer questions about your data — and nothing else.

What ChatGPT can't do through the gateway

Why a gateway instead of a direct connection

A general assistant like ChatGPT is exactly the case where you don't want a raw, unrestricted database connection: the output can be confidently wrong, and a chat surface makes it easy to run a query nobody reviewed. Read-only enforcement, bounded results and an audit trail turn "connect ChatGPT to my database" from a risky idea into a safe one. More on the trade-offs in is it safe to connect AI to your production database?

Frequently asked

Can ChatGPT connect to a SQL database? +

Yes — via MCP. ChatGPT's developer-mode connectors let you add a remote MCP server, and the AI2SQL Gateway is one. Once added, ChatGPT can read your schema and run read-only queries against your PostgreSQL database.

Is it safe to connect ChatGPT to my database? +

Through the gateway, yes: access is read-only (writes are blocked before they run), results are capped, queries time out, and every call is logged. ChatGPT authenticates with a revocable key, never your database password.

Do I need a ChatGPT paid plan? +

Developer-mode MCP connectors are a ChatGPT feature and availability depends on your plan and settings. The gateway side works the same regardless — any MCP-capable client can connect.

Which databases are supported? +

PostgreSQL is live today. MySQL, SQL Server and others in the AI2SQL connector set are rolling out to the gateway.

Give your agent a database it can't break

Connect a database, grab a key, paste one config. Read-only, logged and revocable from the first query.

Start free →

Related guides