Skip to content

PostgreSQL MCP Server

Query databases, read schemas, execute safe SQL, and fetch data. Analyze database structure and answer questions about data.

Capabilities
Query Schema Inspection Analytics
Maintained by
Community (Crystal DBA)
Hosting
Runs locally on your machine
Authentication
API key or credentials (environment variables)
Last checked

The MCP reference Postgres server was archived (moved to modelcontextprotocol/servers-archived); this is Postgres MCP Pro, use --access-mode=unrestricted to allow writes.

How to connect the PostgreSQL MCP server

Pick your AI client and paste the snippet. New to this? Our guide to how MCP clients and servers fit together explains what each piece does.

Claude Code

Terminal
claude mcp add --env DATABASE_URI=postgresql://USER:PASSWORD@HOST:5432/DBNAME --transport stdio postgresql \
  -- uvx postgres-mcp --access-mode=restricted
Full Claude Code setup guide →

Claude Desktop

claude_desktop_config.json (Settings → Developer → Edit Config)
{
  "mcpServers": {
    "postgresql": {
      "command": "uvx",
      "args": [
        "postgres-mcp",
        "--access-mode=restricted"
      ],
      "env": {
        "DATABASE_URI": "postgresql://USER:PASSWORD@HOST:5432/DBNAME"
      }
    }
  }
}

Fully quit and reopen Claude Desktop after saving.

Full Claude Desktop setup guide →

Cursor

~/.cursor/mcp.json (or .cursor/mcp.json in a project)
{
  "mcpServers": {
    "postgresql": {
      "command": "uvx",
      "args": [
        "postgres-mcp",
        "--access-mode=restricted"
      ],
      "env": {
        "DATABASE_URI": "postgresql://USER:PASSWORD@HOST:5432/DBNAME"
      }
    }
  }
}
Full Cursor setup guide →

VS Code

.vscode/mcp.json
{
  "servers": {
    "postgresql": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "postgres-mcp",
        "--access-mode=restricted"
      ],
      "env": {
        "DATABASE_URI": "postgresql://USER:PASSWORD@HOST:5432/DBNAME"
      }
    }
  }
}
Full VS Code setup guide →

Frequently asked questions

What is the PostgreSQL MCP server?

It is a Model Context Protocol (MCP) server — a small piece of software that gives AI assistants like Claude a secure, governed connection to PostgreSQL. Query databases, read schemas, execute safe SQL, and fetch data. Analyze database structure and answer questions about data.

Is there an official PostgreSQL MCP server?

Not from PostgreSQL itself. This one is community-maintained (Crystal DBA). It is widely used, but review the repository and pin a version before relying on it in production.

Is the PostgreSQL MCP server hosted, or do I run it myself?

It runs locally. Your AI client starts it on your own machine with uvx, and it talks to the client over standard input and output rather than the network.

Do I need an API key for the PostgreSQL MCP server?

Yes. The local server reads DATABASE_URI from its environment, so you create that credential first and add it to your client's config.

What can an AI assistant actually do with PostgreSQL?

Through this server an assistant can work with query, schema inspection, analytics — reading from and acting on PostgreSQL directly instead of you copy-pasting between windows. What you allow it to do is controlled by the permissions you grant.

How do I set this up for my business?

The setup section above has copy-paste config for Claude Code, Claude Desktop, Cursor and VS Code. Once it is running against real systems, the question becomes what catches it when it acts wrongly, which is what Crox's Safety Diagnostic looks at.

New to MCP? Start with our plain-English guide to the Model Context Protocol or see how to connect AI to your business tools without writing code .

Done-for-you integration

Already running this in production?

An agent with a live connection to your tools is a model that can act. Crox looks at what catches it when it acts wrongly: the layers around it, who can stop it, and where a near miss gets reported. Two days, one team, one model.