PostgreSQL MCP Server

PostgreSQL database integration for SQL operations, data querying, and database management tasks.

Database DatabaseSQLPostgreSQL

Configuration

MCP Settings Configuration

{
  "postgres": {
    "stdio": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "{{POSTGRES_ADDRESS}}"
      ]
    }
  }
}

Available Tools & Methods

query(sql)
Execute read-only SQL queries against the connected database
Parameters: sql (string) - The SQL query to execute
Note: All queries are executed within a READ ONLY transaction

Installation Guide

# Installation ## Claude Desktop Configuration ### Docker (Recommended) **Note**: When running Docker on macOS, use `host.docker.internal` if the PostgreSQL server is running on the host network (e.g., localhost). Username/password can be added to the PostgreSQL URL with `postgresql://user:password@host:port/db-name`. ```json { "mcpServers": { "postgres": { "command": "docker", "args": [ "run", "-i", "--rm", "mcp/postgres", "postgresql://host.docker.internal:5432/mydb" ] } } } ``` ### NPX ```json { "mcpServers": { "postgres": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb" ] } } } ``` Replace `mydb` with your database name. ## VS Code Configuration ### Docker **Note**: When using Docker and connecting to a PostgreSQL server on your host machine, use `host.docker.internal` instead of `localhost` in the connection URL. ```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}" ] } } } } ``` ### NPX ```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}" ] } } } } ``` ## Connection URL Format The PostgreSQL connection URL should follow this format: ``` postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...] ``` Examples: - `postgresql://localhost/mydb` - `postgresql://user:password@localhost:5432/mydb` - `postgresql://user@host.docker.internal:5432/mydb` ## Security Notes - This server provides **read-only** access to PostgreSQL databases - All queries are executed within a READ ONLY transaction - Schema information is automatically discovered and exposed as resources - Ensure your database user has appropriate read permissions