How to connect Claude Desktop to a Postgres database
Updated
Add Kaiva Postgres MCP to claude_desktop_config.json with your database's connection URL, then restart Claude Desktop. It is a free, open-source MCP server that runs on your machine and lets Claude list your tables, read their columns and run read-only queries. No account is needed.
Step by step
- Open the config fileIn Claude Desktop, open Settings, then Developer, and click Edit Config. The file is claude_desktop_config.json, in ~/Library/Application Support/Claude on macOS and %APPDATA%\Claude on Windows.
- Add the serverPaste the entry below with your own connection URL, keeping any servers already in the file. Node.js 18 or later must be installed.
- Restart and checkQuit Claude Desktop completely and open it again; it starts the server itself. Settings, then Developer, should show postgres as running. Then ask Claude which tables the database has.
- Use a login that can only read (recommended)PostgreSQL then refuses any write, whatever is sent. The guide to a read-only Postgres login, linked at the end of this page, has the SQL. To see what a login can do, run the command with --check: it connects once, reports whether the login is a superuser and whether it can change data, and exits.
To see what a login can do, from a terminal:
npx -y @kaiva/postgres-mcp postgresql://localhost/mydb --checkclaude_desktop_config.json for Postgres
If you used @modelcontextprotocol/server-postgres, this is the same entry with one package name changed.
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@kaiva/postgres-mcp", "postgresql://localhost/mydb"]
}
}
}The four tools
query runs one read-only SQL statement (SELECT, WITH, VALUES, TABLE, SHOW or EXPLAIN) and returns the rows as JSON. list_tables lists the tables and views the login can read. describe_table shows one table's columns, keys and indexes. database_health shows the largest tables and indexes, indexes that are never used, the slowest queries (with their values hidden) and the cache hit rate.
Other ways to do it
- Kaiva Bridge, for Claude.ai, ChatGPT or a teamWant this database in Claude.ai, ChatGPT or any other AI client, or for your team? If it's on Neon, Supabase or any other address on the internet, Kaiva Bridge serves it with one command, run where DATABASE_URL is set: npx @kaiva/cli bridge push mydb --db.
Questions
- Is it free?
- Yes. Kaiva Postgres MCP is open source under the MIT licence, and needs no account.
- Can the AI change my data?
- Not through this server: one read-only statement per call, in a transaction that is always rolled back. A view or function already in your database runs with the login's rights, so use a login that can only read.