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
- Connect your database in the AI2SQL Gateway. Credentials are encrypted and stay server-side.
- Generate a gateway key — the wizard gives you the key and connection id.
- Add the MCP server in ChatGPT under Settings › Connectors › Advanced › 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
- Write anything. INSERT, UPDATE, DELETE and DDL are blocked at the gateway and queries run in a read-only transaction.
- See your password. It holds a scoped, revocable key — your real credentials never leave the encrypted store.
- Run unbounded queries. Row limits and timeouts keep a single call from overwhelming the database.
- Act unlogged. Every query is recorded on your gateway activity page.
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?