How to Connect Claude to Your Postgres Database
April 2026 · 5 min read
Imagine asking Claude: "Show me the top 10 customers by revenue last month"and getting actual data from your database — not hallucinations, real rows.
That's what MCP (Model Context Protocol) servers do. They expose tools the AI can call. In this guide, we'll build one that queries your Postgres database, deploy it to IOX Cloud, and connect it to Claude Desktop.
What you'll build
A Postgres MCP server with these tools:
list_tables— show all tables in the databasedescribe_table— get columns, types, indexesrun_query— execute SELECT queries (read-only for safety)
Step 1: Create the project
Sign in to iox.cloud and click Create Project. Describe what you want:
"Build an MCP server that queries Postgres. Tools: list_tables, describe_table, run_query (SELECT only). Connection string via POSTGRES_URL env var."
Claude generates the code in ~10 seconds.
Step 2: Add your database URL
In project Settings → Environment Variables, add:
POSTGRES_URL=postgresql://user:pass@host/dbname
IOX encrypts this and injects it into your Worker on deploy. Your connection string is never exposed to the AI or stored in plain text.
Step 3: Deploy
Click Deploy. IOX provisions infrastructure and deploys to 300+ edge locations in ~15 seconds. You get a live URL:
https://my-postgres.iox.cloud/mcp
Step 4: Connect to Claude Desktop
Open Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"postgres": {
"url": "https://my-postgres.iox.cloud/mcp"
}
}
}Restart Claude Desktop. Now ask:
- "What tables exist in my database?"
- "Show me the schema for the users table"
- "How many orders were placed last week?"
Claude calls your MCP server, runs the query, returns real data.
Why this is safe
- Read-only enforcement — the AI-generated code validates queries start with SELECT
- Per-tenant isolation — your server runs in its own V8 sandbox on Cloudflare
- Encrypted env vars — connection string never appears in logs or code
- Rate limiting — prevent runaway queries
Extending it
Ask Claude to add more tools:
- "Add a tool that creates a new record in a given table"
- "Add a tool that explains query performance (EXPLAIN)"
- "Add aggregation helpers: sum, avg, count by group"
AI iterates on your server. You review and redeploy.