Back to blog

How to Set Up a Postgres MCP Server With Claude Cowork

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

I was halfway through writing a board update last quarter when our head of growth pinged me asking for our revenue from new customers that month. Not the total. Just new customers. I knew the data was in Postgres. I also knew I wasn't going to open a terminal, open psql, remember the table name, write the query, format the result, and paste it back into a doc. Not in the middle of drafting something. So I typed the question into Claude Cowork instead and got the number in about eight seconds.

Here's how to set that up.

Part of the Postgres MCP Server guide.

What you'll need

  • A Postgres database (a read replica is recommended, but not required to start)
  • A QueryBear account
  • Claude Cowork installed on your Mac or Windows machine

Why route through a gateway

Pasting your DATABASE_URL directly into an AI tool is a bad idea. The agent gets full write access, every query escapes with your credentials in context, and there's no audit trail. QueryBear sits between Cowork and your database: it parses every SQL statement to reject DML and DDL, runs each query against an allowlist of permitted tables, strips blocked columns from results, enforces a row cap and statement timeout, and logs everything. The full reasoning is in the Postgres MCP Server guide.

Connect QueryBear to your Postgres database

  1. Open the QueryBear dashboard and click "New connection."
  2. Pick "Postgres" and paste your connection URL. If you have a read replica, use that URL instead of the primary.
  3. Under "Allowed tables," add the tables you want Cowork to see. Leave anything sensitive off the list.
  4. Under "Blocked columns," add any columns that shouldn't surface in AI context: password_hash, totp_secret, stripe_customer_id, whatever applies to your schema.
  5. Save. QueryBear will test the connection.

That's it for the database side.

Install the QueryBear MCP server in Claude Cowork

Open Claude Cowork and go to Settings → Connectors → Add custom connector.

Fill in:

  • Name: querybear
  • URL: https://mcp.querybear.com/mcp

Save and restart Cowork if it prompts you to. After that, Cowork will have three new tools available in every session: list_connections, get_schema, and run_query. All three route through QueryBear's gateway.

Ask your first question

Open a new Cowork session and type something like you'd say it out loud:

I asked: "What's our total revenue from new customers this month?"

Claude Cowork pulled the schema, figured out the relevant tables, and generated this query:

SELECT SUM(o.amount) AS total_revenue
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE u.created_at >= date_trunc('month', now())
  AND o.created_at >= date_trunc('month', now())
  AND o.status = 'paid';

The number came back in under a second. I pasted it straight into the board update and kept writing.

Cowork shows you the generated query before it runs (depending on your settings), so you can sanity-check the SQL if you want to. Usually you won't need to.

A Claude Cowork-specific tip

When Cowork returns a result table, you can copy it as a formatted table and paste it directly into a Google Doc or Notion page. The formatting comes through cleanly as a table, not as a blob of text. If you need to do any further manipulation, the "Open in spreadsheet" option in the result panel exports to a CSV that opens in Excel or Sheets. For a board update or a weekly report, this usually saves three or four extra steps compared to exporting from a SQL client.

The bigger point is that Cowork is where you're already writing. The answer lives in the same window as the paragraph that needs it.

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.