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.

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

More MCP options

Compare MCP servers by category, or browse hosted MCP servers if you prefer an endpoint over a local process.

Maintainer setup documentation.

Recorded tools

Check the linked publisher documentation and your connected client's tool list. Names and availability can vary with the server version and account permissions.

ToolWhat it does
executeAlways (refuses writes unless PG_ALLOW_WRITE=true)
connect_dbOnly when PG_ENABLE_RUNTIME_CONNECT=true

How to install the Postgres MCP Server

{
  "mcpServers": {
    "postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres-server"
      ],
      "env": {
        "DATABASE_URL": "postgres://user:password@localhost:5432/mydb",
        "PG_ALLOW_WRITE": "false"
      }
    }
  }
}

From the project documentation. Replace placeholders and example paths before connecting.

Configuration

VariableDescriptionRequired
DATABASE_URLDeclared in the maintainer’s client configuration.Check documentation
PG_ALLOW_WRITEDeclared in the maintainer’s client configuration.Check documentation

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.