MCP Server Archived reference Limited info

PostgreSQL

MCP server giving LLMs read-only PostgreSQL access: run SQL in READ ONLY transactions and inspect per-table schemas as JSON resources.

docker build -t mcp/postgres -f src/postgres/Dockerfile .
PostgreSQL preview image

What it is

A Model Context Protocol server that provides read-only access to PostgreSQL databases. It lets LLMs inspect database schemas and execute read-only queries. It exposes one tool, query, and schema resources for each table, discovered automatically from database metadata.

Who it's for

  • Developers who want an LLM client such as Claude Desktop or VS Code to inspect a PostgreSQL schema
  • Users who want an LLM to run read-only SQL queries against a PostgreSQL database

Requirements

Requirements

  • A PostgreSQL connection URL (e.g. postgresql://localhost/mydb)
  • Either Docker (image mcp/postgres) or NPX (@modelcontextprotocol/server-postgres) to run the server
  • An MCP client such as Claude Desktop or VS Code
  • When running Docker on macOS against a database on the host, use host.docker.internal instead of localhost

Setup

  1. Claude Desktop with Docker

    Add this to the "mcpServers" section of claude_desktop_config.json. On macOS, use host.docker.internal if the database is on the host network. Username/password can be added to the URL as postgresql://user:password@host:port/db-name.

    json
    {
      "mcpServers": {
        "postgres": {
          "command": "docker",
          "args": [
            "run", 
            "-i", 
            "--rm", 
            "mcp/postgres", 
            "postgresql://host.docker.internal:5432/mydb"]
        }
      }
    }
  2. Claude Desktop with NPX

    Add this to the "mcpServers" section of claude_desktop_config.json. Replace /mydb with your database name.

    json
    {
      "mcpServers": {
        "postgres": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-postgres",
            "postgresql://localhost/mydb"
          ]
        }
      }
    }
  3. VS Code with NPX (manual)

    Add this block to your User Settings (JSON) file (Ctrl + Shift + P, then Preferences: Open User Settings (JSON)), or to .vscode/mcp.json in your workspace to share it with others. The mcp key is not needed in .vscode/mcp.json.

    json
    {
      "mcp": {
        "inputs": [
          {
            "type": "promptString",
            "id": "pg_url",
            "description": "PostgreSQL URL (e.g. postgresql://user:pass@localhost:5432/mydb)"
          }
        ],
        "servers": {
          "postgres": {
            "command": "npx",
            "args": [
              "-y",
              "@modelcontextprotocol/server-postgres",
              "${input:pg_url}"
            ]
          }
        }
      }
    }
  4. Build the Docker image

    Build the image locally.

    bash
    docker build -t mcp/postgres -f src/postgres/Dockerfile .

Examples

VS Code with Docker

json
json
{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "pg_url",
        "description": "PostgreSQL URL (e.g. postgresql://user:pass@host.docker.internal:5432/mydb)"
      }
    ],
    "servers": {
      "postgres": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "mcp/postgres",
          "${input:pg_url}"
        ]
      }
    }
  }
}

What it does: VS Code prompts for the PostgreSQL URL and passes it to the mcp/postgres container. Use host.docker.internal when the database is on the host machine.

Table schema resource URI

text
text
postgres://<host>/<table>/schema

What it does: Each table's schema is exposed as a resource in this form, returning JSON with column names and data types.

Pros & cons

Pros

  • Pro:All queries run inside a READ ONLY transaction, limiting the risk of modifying data
  • Pro:Table schemas (column names and data types) are exposed automatically from database metadata
  • Pro:Supports both Docker and NPX, with configuration for Claude Desktop and VS Code
  • Pro:MIT licensed

Cons

  • Con:Read-only: the only tool is query, so it cannot write data
  • Con:The repository is in the servers-archived location, so it may no longer be actively maintained
  • Con:Schema resources are documented as column names and data types only

Images