Back to blog

How to Set Up a Postgres MCP Server With ChatGPT

Spencer Pauly
Spencer Pauly
4 min read
How to Set Up a Postgres MCP Server With ChatGPT

Our head of marketing, Jenna, slacked me on a Tuesday with a single question: "How many active subscribers do we have right now? Churn feels weird this week." She wasn't asking me to write a dashboard. She just wanted a number. The problem was she already had ChatGPT open, she pays for it, her whole team uses it. What she didn't have was a way to actually ask it about our database.

This post walks through connecting a Postgres database to ChatGPT via QueryBear's MCP server, so people like Jenna can get answers without filing a SQL ticket.

Part of the Postgres MCP Server guide.

What you'll need

  • A Postgres database (read replica recommended, not your primary)
  • A QueryBear account (free to start at querybear.com)
  • ChatGPT Pro, Plus, Team, or Enterprise subscription

Why route through a gateway

You don't want to hand the agent your raw database URL. A gateway like QueryBear sits in between: its SQL parser rejects any DML or DDL before it reaches your database, an allowlist controls exactly which tables the agent can see, and every query goes into an audit log. The Postgres MCP Server guide covers this in detail if you want the full picture.

Connect QueryBear to your Postgres database

  1. Open the QueryBear dashboard and click "New connection."
  2. Choose Postgres, then paste your connection URL. A read replica with a role that has SELECT only is the right move here.
  3. Under "Allowed tables," pick the tables you want ChatGPT to be able to query. Leave out anything sensitive like auth_tokens or webhook_payloads.
  4. Under "Blocked columns," add anything you'd be uncomfortable seeing in a chat window: password_hash, totp_secret, ssn_last_4. Save.

QueryBear will reject any query that touches off-list objects at the parser level, before it ever reaches your database.

Install the QueryBear MCP server in ChatGPT

ChatGPT's MCP support is newer than most tools on this list and requires a couple of extra steps to reach. You'll need Developer Mode turned on.

  1. Open ChatGPT and go to Settings.
  2. Navigate to Connectors, then Advanced, then toggle on Developer mode.
  3. Click "Add new connector." Set the name to querybear and the URL to https://mcp.querybear.com/mcp.
  4. Authorize via OAuth when prompted.

Once that's done, ChatGPT has access to QueryBear's three tools: list_connections, get_schema, and run_query.

Ask your first question

With the connector active, I typed exactly what Jenna asked me:

I asked: "How many active subscriptions do we have right now?"

ChatGPT generated this query and ran it through QueryBear:

SELECT COUNT(*) AS active_subscriptions
FROM subscriptions
WHERE status = 'active'
  AND (canceled_at IS NULL OR canceled_at > now());

Got back 1,847. Took about two seconds including the round-trip.

That number went straight back to Jenna. No ticket. No SQL. She forwarded it to her team in about thirty seconds.

A ChatGPT-specific tip

Pin a custom GPT with the connector pre-selected. If your team is on ChatGPT Team, you can create a GPT, attach the QueryBear connector to it, and share the link with marketing, finance, whoever. Non-technical users click the link, the connector is already there, and they just type their question.

Developer Mode can shift around in the UI as OpenAI updates the product. If you can't find it, the connector URL (https://mcp.querybear.com/mcp) is always listed in your QueryBear dashboard under "MCP."

Using a different tool?

Querying a different database?

Database Access

Give Your AI Agents
Database Access. Securely.

Connect any database. Control permissions. Audit every query. All running locally on your machine.