PostgreSQL

Provides read and write access to PostgreSQL databases for LLMs, enabling schema inspection, data manipulation, and schema management.
  • other

11

GitHub Stars

other

Language

6 months ago

First Indexed

2 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "garethcott-enhanced-postgres-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "mcp/postgres",
        "postgresql://host.docker.internal:5432/mydb"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES_HOST>",
        "POSTGRES_PORT": "<POSTGRES_PORT>"
      }
    }
  }
}

You can use the PostgreSQL MCP Server (Enhanced) to interface with PostgreSQL databases through a Model Context Protocol client. It provides both read and write access, enabling you to inspect schemas, run queries, modify data, and manage schema objects directly from an MCP-enabled workflow.

How to use

You can connect to the PostgreSQL MCP Server (Enhanced) using either a local, stdin-driven setup or a containerized approach via a command runner such as Docker or NPX. Once connected, you can perform read queries, modify data, and manage database schemas through the available commands. Use the read-only query tool to inspect data, and the modification tools to insert, update, delete, and manage schema objects like tables, functions, triggers, and indexes.

How to install

Prerequisites: ensure you have a runtime environment suitable for running containerized services or local Node/NPX commands, depending on your chosen setup.

# Prerequisites
- Docker installed and running
- Node.js and npm installed (for NPX-based usage)

# Docker-based run
# Start the MCP server using Docker. This runs a PostgreSQL MCP Server image and connects to your database URL.

Additional sections

Configuration and usage details are described here to help you deploy, run, and interact with the server in real-world scenarios.

Two practical ways to run the MCP server are shown below. Both approaches expose the server as a local process that you can query through your MCP client.

Configuration examples

{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "mcp/postgres",
        "postgresql://host.docker.internal:5432/mydb"
      ]
    }
  }
}
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/mydb"
      ]
    }
  }
}

Tools and capabilities

Here are the core tools you can use to interact with PostgreSQL via the MCP server. Each tool performs a specific operation on your database.

  • query — Execute read-only SQL queries within a read-only transaction to inspect data and schemas.
  • execute — Run SQL statements that modify data within a managed transaction with commit/rollback handling.
  • insert — Insert a new record into a table using a data object mapping column names to values.
  • update — Update existing records in a table using a data object for fields and a WHERE clause to identify targets.
  • delete — Delete records from a table based on a WHERE clause.
  • createTable — Create a new table with specified columns and optional constraints.
  • createFunction — Create a PostgreSQL function or procedure with defined parameters and body.
  • createTrigger — Create a trigger on a table to call a function under specified timing and events.
  • createIndex — Create an index on a table with options for uniqueness, type, and a where clause.
  • alterTable — Alter a table structure with specified operation and details.

Security considerations

All data modification operations are executed within transactions that ensure proper commit or rollback. Each operation returns the executed SQL for transparency. The server uses parameterized queries to defend against SQL injection. A security fix has been applied to improve prepared statement usage for read queries to prevent cross-statement injections.

Notes on schema information

The server exposes table schemas as JSON at a dedicated endpoint. You can retrieve column names and data types for each table as you design queries or modify schema. This schema information is automatically discovered from database metadata.

Example usage scenarios

Query data to inspect the top few rows of a table, then insert or update records based on results, and finally create or modify table structures as needed.

Building and runtime commands

To build and run the server locally using Docker you can pull and run the MCP image directly as shown in the configuration examples. If you prefer NPX, use the NPX command shown in the configuration examples to start the server in your environment.

Available tools

query

Execute read-only SQL queries within a read-only transaction to inspect data and schemas.

execute

Run SQL statements that modify data within a managed transaction with commit/rollback handling.

insert

Insert a new record into a table using a data object mapping column names to values.

update

Update existing records in a table using a data object for fields and a WHERE clause to identify targets.

delete

Delete records from a table based on a WHERE clause.

createTable

Create a new table with specified columns and optional constraints.

createFunction

Create a PostgreSQL function or procedure with defined parameters and body.

createTrigger

Create a trigger on a table to call a function under specified timing and events.

createIndex

Create an index on a table with options for uniqueness, type, and a where clause.

alterTable

Alter a table structure with specified operation and details.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational