PostgreSQL MCP Server

PostgreSQL database operations for AI models including querying and schema inspection.

Data last scanned last week · Reviewed last month

01 dangerous tool6 tools16JavaScriptMIT

Overview

This server provides a set of tools that allow AI models to interact directly with PostgreSQL databases. Users can connect to their database instances using environment variables or explicit tool arguments, enabling data retrieval and manipulation through a standardized interface. Capabilities include executing SELECT, INSERT, UPDATE, and DELETE queries with support for parameter placeholders. Additionally, the server facilitates database discovery by providing tools to list schemas, list tables, and describe table structures.

Our verdict

With a security score of 18/100, this tool is classified as high-risk. The repository has not seen a code update in over 473 days and is maintained by a single contributor with no independent editorial review of its connection or authentication handling. Given these factors, it is recommended only for local development or non-sensitive, isolated environments where database access risks can be strictly managed.

  • Supports both PostgreSQL and MySQL-style query parameter placeholders.
  • Small footprint with only three direct dependencies.
  • Provides built-in schema and table exploration tools.
  • No code updates for over 473 days.
  • High bus-factor risk due to single-contributor maintenance.
  • Authentication and read-only modes lack third-party security review.

Setup

Claude Desktop
{
  "mcpServers": {
    "mcp-postgres-server": {
      "args": [
        "-y",
        "mcp-postgres-server"
      ],
      "command": "npx"
    }
  }
}

Paste into ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows), then restart Claude Desktop. Some servers require API keys or tokens as environment variables — check the project's README and add an "env" object if needed.

  • No read-only mode — running this grants full read/write access.
  • No built-in authentication — anyone with access to this config can invoke every tool it exposes.

Tools

ToolDescriptionRisk
connect_dbEstablish connection to PostgreSQL database using provided credentials.medium
queryExecute SELECT queries with optional prepared statement parameters.low
executeExecute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.high
list_schemasList all schemas in the connected database.low
list_tablesList tables in the connected database.low
describe_tableGet the structure of a specific table.low

Compatibility

ClientLocalDockerRemoteRead-only
ChatGPT
Claude Desktop
Cursor
VS Code
Windsurf

Frequently asked questions

What environment variables are required to configure the server?

You must define PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, and PG_DATABASE in your environment configuration.

Can I connect to a specific database schema?

Yes, tools like list_tables and describe_table accept an optional schema parameter, which defaults to 'public' if not provided.

Does the server support parameterized queries?

Yes, it supports both PostgreSQL-style ($1, $2) and MySQL-style (?) parameter placeholders to help prevent SQL injection.

How is the database connection managed?

The server includes automatic connection management and automatically closes connections when operations are finished.

Are there specific tools for data manipulation versus data retrieval?

Yes, the query tool is intended for SELECT operations, while the execute tool is designed for INSERT, UPDATE, or DELETE operations.

Alternatives

Badge

PostgreSQL MCP Server security score, rated on RepoAI

Maintain this server? Add the live badge to your README.