Postgres MCP server: connect AI agents to PostgreSQL without installing anything

A Postgres MCP server lets Claude, Cursor, ChatGPT or your own agent read your PostgreSQL schema and run SQL. AI2SQL runs one for you: hosted, read-only by default, logged, and set up with one URL and an OAuth sign-in.

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:

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

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.

Frequently asked

What is a Postgres MCP server? +

A server that speaks the Model Context Protocol (MCP) and exposes a PostgreSQL database to an AI assistant as tools, typically one to read the schema and one to run SQL. Claude, Cursor, ChatGPT and other MCP clients call those tools to answer questions about your data.

Do I need to install anything to use AI2SQL as a Postgres MCP server? +

No. It is a hosted MCP endpoint over HTTP. You add the URL to your AI client and sign in with OAuth; there is no npm or Python package, no Docker container and no local process to keep running.

Is it read-only? +

Yes. Every statement is classified before it runs and INSERT, UPDATE, DELETE, DDL and dangerous functions are blocked. Queries also run inside a read-only transaction with a row limit and a timeout. We still recommend a read-only Postgres role so the database enforces it too.

Does it work with Supabase, Neon, RDS or a local Postgres? +

Any PostgreSQL that AI2SQL can reach over the network works, including Supabase, Neon, Amazon RDS, Aurora, Cloud SQL and Azure. A database on localhost or a private network connects through the AI2SQL Connector desktop app.

Which MCP tools does it expose? +

list_connections, describe_schema and run_query (read-only) for live data, plus generate_sql, fix_sql, optimize_sql, explain_sql and convert_sql for writing and checking SQL.

Is it free? +

Signing in, listing connections, reading schemas, the demo_shop sample database 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.

When should I self-host an open-source Postgres MCP server instead? +

When data must never leave your network, when you want it free and open source, or when you need index tuning and health checks. Postgres MCP Pro and DBHub are good options there; see the comparison page for the trade-offs.

Give your AI assistant read-only access to Postgres

Add the database once, paste one URL into Claude, Cursor or ChatGPT, and ask questions about your real data.

Start free →

Try it first on the demo_shop sample database; it works on the free plan.

Related guides