home / mcp / mcp postgresql server

MCP PostgreSQL Server

MCP PostgreSQL Server

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "antonorlov-mcp-postgres-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres-server"
      ],
      "env": {
        "PG_HOST": "your_host",
        "PG_PORT": "5432",
        "PG_USER": "your_user",
        "PG_DATABASE": "your_database",
        "PG_PASSWORD": "your_password"
      }
    }
  }
}

You can use the MCP PostgreSQL Server to interact with PostgreSQL databases through a standardized interface. It handles secure connections, prepared statements, multi-schema operations, and convenient tooling to query, modify, and inspect database structures from an MCP client.

How to use

Connect your MCP client to the PostgreSQL MCP server using the provided connection configuration. Once connected, you can establish a database connection with connect_db, then perform read and write operations with query and execute. You can inspect the database structure with list_schemas, list_tables, and describe_table to understand schemas, tables, and their columns. These tools support prepared statements for safe parameter handling and allow you to work across multiple schemas.

How to install

Prerequisites: you need a recent Node.js environment (which includes npm). Install or run the MCP PostgreSQL Server as described below.

Option A: Install as a package in your project

- Run the following command to install locally in your project

npm install mcp-postgres-server

Option B: Run directly without installing

- Start the server using npx to run it on demand

npx mcp-postgres-server

Configuration and usage notes

{
  "mcpServers": {
    "postgres": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "mcp-postgres-server"],
      "env": {
        "PG_HOST": "your_host",
        "PG_PORT": "5432",
        "PG_USER": "your_user",
        "PG_PASSWORD": "your_password",
        "PG_DATABASE": "your_database"
      }
    }
  }
}

Available tools

connect_db

Establish a connection to the PostgreSQL database using the provided credentials.

query

Execute SELECT queries with optional prepared statement parameters. Supports both PostgreSQL-style ($n) and MySQL-style (?) placeholders.

execute

Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters. Supports both PostgreSQL-style ($n) and MySQL-style (?) placeholders.

list_schemas

List all schemas in the connected database.

list_tables

List tables in the connected database, with an optional schema parameter (defaults to public).

describe_table

Get the structure of a specific table, with an optional schema parameter (defaults to public).