Tutorial

How to Connect PostgreSQL to Claude via MCP

May 3, 2026 · 6 min read · by ApexMCP

Claude can query your PostgreSQL database, run reports, and answer questions about your data — if you give it the right tools via MCP. This guide shows you exactly how to do that, from connection string to first tool call, without writing a single line of custom server code.

What is MCP and Why Does It Matter for Postgres?

Model Context Protocol (MCP) is an open standard introduced by Anthropic that defines how AI agents discover and call external tools. Instead of copy-pasting query results into a chat window, an MCP-connected Claude can directly run SELECT queries, fetch schemas, and reason over live data.

Before MCP, connecting Claude to a database meant writing a custom backend, building your own tool definitions, and maintaining the integration every time the schema changed. MCP eliminates all of that with a standard protocol that any agent can speak.

What You Need

Step 1 — Add a PostgreSQL Connector

Log into the ApexMCP dashboard and navigate to Connectors → Add connector. Select PostgreSQL from the connector list.

Paste your connection string. ApexMCP runs schema discovery immediately — it introspects your tables, columns, and types, then builds accurate tool schemas automatically. You don't need to define tools manually.

Security note: Credentials are encrypted in HashiCorp Vault on write. Your connection string is never stored in plaintext or exposed in logs.

Choose a read-only mode if you only want Claude to query data (recommended for most use cases). You can also restrict which tables are visible per connector.

Step 2 — Provision Your MCP Endpoint

Go to Endpoints → New endpoint. Select your PostgreSQL connector and click Provision. ApexMCP generates an org-scoped MCP endpoint URL and an API key.

Your endpoint URL looks like:

https://mcp.apexmcp.ai/org/your-org-id/mcp

Every table in your database becomes a discoverable tool — query_users, query_orders, get_schema, and so on. The tool schemas are auto-generated from your Postgres column types, so Claude gets accurate parameter definitions without any manual config.

Step 3 — Connect Claude Desktop

Open your Claude Desktop config file. On macOS: ~/Library/Application Support/Claude/claude_desktop_config.json. On Windows: %APPDATA%\Claude\claude_desktop_config.json.

Add your ApexMCP endpoint:

{
  "mcpServers": {
    "apexmcp": {
      "url": "https://mcp.apexmcp.ai/org/your-org-id/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

Restart Claude Desktop. Claude will discover all available tools from your endpoint on startup.

Step 4 — Test It

Open a new Claude conversation and ask something like:

How many users signed up in the last 30 days?
What are the top 10 products by revenue this month?
Show me the schema of the orders table.

Claude will call your Postgres tools directly, run the queries, and return results — all without you writing SQL or copying data manually.

Connecting Cursor or Windsurf

The same endpoint works with Cursor and Windsurf. In Cursor, go to Settings → MCP Servers and add the same URL and API key. In Windsurf, add it under AI settings → Tool providers. The setup is identical — ApexMCP speaks standard MCP, so any compatible client works out of the box.

What Happens When Your Schema Changes?

ApexMCP re-runs schema discovery on demand. When you add a table or column, go to your connector settings and click Re-discover schema. Your MCP endpoint updates immediately — no reprovisioning, no downtime, no manual tool definition edits.

Rate Limiting and Audit Logs

Every query Claude makes through your MCP endpoint is logged: which tool was called, what parameters were passed, latency, and the result status. You can search and export these logs from the dashboard for compliance or debugging.

Rate limiting is enforced at the gateway — 5 requests per second on the free tier, scaling up with your plan. This protects your database from runaway agent loops.

Summary

  1. Add a PostgreSQL connector in ApexMCP — paste connection string, schema auto-discovered
  2. Provision an MCP endpoint — one click, one URL
  3. Drop the URL and API key into Claude Desktop, Cursor, or Windsurf config
  4. Ask Claude questions about your data in plain English

No custom server, no JSON-RPC boilerplate, no schema maintenance. The whole setup takes under 5 minutes.

Ready to connect your database?

ApexMCP is in private beta. Join the waitlist and get early access.

Join the waitlist