Short answer: you don't have to run a Postgres MCP server yourself. Add your
PostgreSQL database to AI2SQL with a read-only role, then add the hosted MCP URL
https://builder.ai2sql.io/api/claude-mcp to Claude (or https://builder.ai2sql.io/api/chatgpt-mcp to Cursor and ChatGPT) and sign in.
The assistant can then call describe_schema and run_query on your database.
Writes are blocked, results are capped, and every call is logged.
What a Postgres MCP server does
MCP (Model Context Protocol) is the standard way AI assistants call outside tools. A Postgres MCP server turns your database into a few tools the model can call: list the databases it can reach, read the tables and columns, and run a query. With those, the assistant writes SQL against your real schema instead of guessing column names, runs it, and answers from the rows.
There are two ways to get one:
- Self-host an open-source server (Postgres MCP Pro, DBHub and others). It runs on your machine or server, you put the connection string in its config, and you keep it running and secured.
- Use a hosted one like AI2SQL. Nothing to install: the client connects over HTTP, you sign in with OAuth, and your Postgres password stays encrypted on the server instead of in a config file.
For a side-by-side of the main options, see Postgres MCP server options compared.
Step 1: create a read-only Postgres role
CREATE ROLE ai_readonly LOGIN PASSWORD 'a-long-random-password';
GRANT CONNECT ON DATABASE app TO ai_readonly;
GRANT USAGE ON SCHEMA public TO ai_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO ai_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO ai_readonly;
ALTER ROLE ai_readonly SET default_transaction_read_only = on;
Grant SELECT on specific tables instead of ALL TABLES to keep sensitive ones
out of reach, and point it at a read replica if production is busy.
Step 2: add the database to AI2SQL
In the AI2SQL builder open Connections, choose PostgreSQL and enter
the host, port, database name and the ai_readonly role. Supabase, Neon, RDS, Aurora, Cloud
SQL and Azure all work. For a database on localhost or a private network, use the
AI2SQL Connector desktop app.
Step 3: add the MCP server to your AI client
claude.ai and Claude Desktop
Open Customize → Connectors, add AI2SQL from the directory or as a custom connector
with https://builder.ai2sql.io/api/claude-mcp, press Connect and sign in.
Claude Code
claude mcp add --transport http ai2sql https://builder.ai2sql.io/api/claude-mcp Then run /mcp, pick ai2sql and choose Authenticate.
Cursor
Click Add to Cursor on ai2sql.io/mcp, or add this to ~/.cursor/mcp.json and click Needs login in Settings → MCP:
{
"mcpServers": {
"ai2sql": {
"url": "https://builder.ai2sql.io/api/chatgpt-mcp"
}
}
} ChatGPT
Install the AI2SQL app, or in developer mode create a connector with https://builder.ai2sql.io/api/chatgpt-mcp and OAuth.
Details: connect ChatGPT to a SQL database.
Scripts, CI and custom agents
Use the API-key endpoint https://builder.ai2sql.io/api/mcp with the x-ai2sql-key and
x-ai2sql-connection headers. The Gateway setup wizard creates both.
Step 4: ask a question
Ask "which 10 customers spent the most in the last 90 days?" The assistant calls
describe_schema, sees your customers and orders tables, writes the
query and runs it through run_query:
SELECT c.customer_id, c.name, SUM(o.total) AS spent
FROM customers c
JOIN orders o ON o.customer_id = c.customer_id
WHERE o.created_at >= now() - interval '90 days'
GROUP BY c.customer_id, c.name
ORDER BY spent DESC
LIMIT 10; If the model tries an UPDATE, DELETE or DROP, the call is refused before it reaches Postgres.
What the assistant can and can't do
- Can: list connections, read tables, columns and relationships, run
SELECTqueries (up to 1,000 rows), and write, fix, explain, optimize or convert SQL. - Can't: insert, update or delete data, run DDL, call dangerous functions, run past the timeout, or see your database password.
Try it before connecting your database
Every account includes demo_shop, a sample store with customers, orders, order items and
products. Connect the MCP server, ask "what can AI2SQL do? show me on the demo database", and
the assistant runs real queries on it. It works on the free plan and does not use your daily allowance.