PostgreSQL MCP reference server (archived)

Archived read-only PostgreSQL reference server for SQL queries and schema resources; no longer maintained.

Local (stdio)CredentialArchived upstream

Archived upstream. This server is no longer maintained by its authors and receives no fixes or security updates. The configuration below is kept for existing users; review the upstream notice before installing it. For new setups, see the maintained MCP Toolbox for PostgreSQL listing.

Set up PostgreSQL

Configuration examples, not tested connections. Replace placeholders and review the upstream documentation before use.

Claude Code

Run in your terminal.

claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres "postgresql://localhost/REPLACE_WITH_DATABASE"

Cursor

Merge into ~/.cursor/mcp.json

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/REPLACE_WITH_DATABASE"
      ]
    }
  }
}

Codex

Run in your terminal.

codex mcp add postgres -- npx -y @modelcontextprotocol/server-postgres "postgresql://localhost/REPLACE_WITH_DATABASE"

Gemini CLI

Merge into ~/.gemini/settings.json

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/REPLACE_WITH_DATABASE"
      ]
    }
  }
}

OpenCode

Merge into ~/.config/opencode/opencode.jsonc

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "postgres": {
      "type": "local",
      "command": [
        "npx",
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/REPLACE_WITH_DATABASE"
      ],
      "enabled": true
    }
  }
}

VS Code

Merge into .vscode/mcp.json

{
  "servers": {
    "postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/REPLACE_WITH_DATABASE"
      ]
    }
  }
}

Step-by-step setup guides: Claude Code and Codex CLI, Cursor and VS Code. In Claude Desktop, the Cursor JSON goes in claude_desktop_config.json. This is a local server that runs on your machine; see remote vs local servers and authentication and security basics.

Overview

The PostgreSQL server was one of the original Model Context Protocol reference implementations, published as @modelcontextprotocol/server-postgres. It is now in the servers-archived repository, which says the archived servers are no longer maintained, receive no bug fixes or security updates, and should be used at your own risk.

It gives an agent read-only access to one PostgreSQL database. A single tool, query, runs SQL that you or the model write, and every query is wrapped in a READ ONLY transaction. The server also publishes each table's schema as a resource at postgres://<host>/<table>/schema, with column names and data types read from the database metadata, so a client can show the model what tables exist before it writes a query. That made it handy for exploring an unfamiliar schema, answering ad-hoc questions about data, or drafting reports without risking writes.

Setup caveats: the server takes a PostgreSQL connection string as its only argument; the snippets below use postgresql://localhost/ and a placeholder database name to replace. Any credentials in the URL appear in your client configuration, so connect with a dedicated database role that has only the read permissions you intend. The read-only transaction protects data, but long or expensive queries can still load the database. Because the package is unmaintained, consider it for local or disposable databases only, and check the Model Context Protocol servers repository for maintained alternatives before using it with production data.

Example tools

  • query

Tool names are upstream examples. The server's live tool list can differ.

Browse Database servers

Sources

This page was written from the upstream documentation below and last reviewed on 11 October 2026. Listing is not a security or compatibility endorsement. Report a correction through the contact page.