GUIDE

How to connect Cursor to a Postgres database

Updated

Add Kaiva Postgres MCP to Cursor's mcp.json with your database's connection URL. It is a free, open-source MCP server that runs on your machine and lets Cursor's agent list your tables, read their columns and run read-only queries. No account is needed.

Step by step

  1. Open mcp.json.cursor/mcp.json in your project folder applies to that project; ~/.cursor/mcp.json applies to every project. Create the file if it is not there.
  2. Add the serverPaste the entry below under mcpServers with your own connection URL, keeping any servers already in the file. Cursor starts the server itself. Node.js 18 or later must be installed.
  3. Check it worksIn Cursor's settings, under MCP, postgres should be listed with its four tools. Then ask the agent which tables the database has.
  4. 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:

Terminal
npx -y @kaiva/postgres-mcp postgresql://localhost/mydb --check

Cursor mcp.json for Postgres

If the project's .cursor/mcp.json is committed, put an entry whose URL holds a password in ~/.cursor/mcp.json instead.

.cursor/mcp.json
{
  "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.