Postgres MCP Server

Enables AI models to interact with PostgreSQL databases through a standardized Model Context Protocol interface.

Local serverstdioTypeScript 13

What is the Postgres MCP server?

Enables AI models to interact with PostgreSQL databases through a standardized Model Context Protocol interface. That is what the postgres mcp server brings to an AI assistant: the same capability, reachable through the Model Context Protocol rather than a separate app or dashboard.

The short version

  • Secure connection handling with automatic cleanup
  • Prepared statement support for query parameters
  • Support for both PostgreSQL-style ($1, $2) and MySQL-style (?) parameter placeholders
  • Comprehensive error handling and validation
  • TypeScript support
  • Automatic connection management

Getting it running

Installation goes through your MCP client rather than a global install: point it at mcp-postgres-server on npm and it is fetched when the client starts. The copy-paste blocks for Claude Desktop, Claude Code and Cursor are further down this page.

What it needs from you

Configuration is passed through the environment: PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, PG_DATABASE. Treat anything key-shaped as a real credential — scope it to the minimum the server needs, and rotate it if it ever lands in a shared config.

How it compares

Plenty of database access servers cover similar ground. The differences that matter in practice are scope of access and how much setup stands between you and a working tool call. It is maintained by antonorlov; worth a glance at recent repository activity before you build anything load-bearing on it.

SyncDev reviews every entry in this directory against the project's own documentation before publishing, and revisits them as servers change.

Things to watch

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • Keep per-call confirmation enabled while you learn its behaviour; it is the cheapest safeguard you have.

How to install the Postgres MCP server

{
  "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"
      }
    }
  }
}

Configuration as documented by the project. Restart the client after saving.

Configuration

VariableDescriptionRequired
PG_HOSTEndpoint or connection string the server talks to.Optional
PG_PORTConfiguration value read at startup.Optional
PG_USERConfiguration value read at startup.Optional
PG_PASSWORDConfiguration value read at startup.Optional
PG_DATABASEConfiguration value read at startup.Optional

Frequently asked questions

Postgres utilizes prepared statements for query parameters, ensuring that user inputs are properly sanitized and preventing malicious SQL code from being executed.