MCP.so
Sign In

Postgres Mcp

@freakynit

About Postgres Mcp

A lightweight MCP (Model Context Protocol) server built to query Postgres database. It provides comprehensive tools for database operations, table introspection, and query execution with smart permission handling.

Basic information

Category

Databases

Transports

stdio

Publisher

freakynit

Submitted by

Nitin Bansal

Config

Add this server to your MCP-compatible client using the configuration below.

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@freakynit/postgres-mcp@latest"
      ],
      "env": {
        "POSTGRES_HOST": "<POSTGRES HOST>",
        "POSTGRES_USER": "<POSTGRES USER>",
        "POSTGRES_PASSWORD": "<POSTGRES PASSWORD>",
        "POSTGRES_DATABASE": "<POSTGRES DATABASE>"
      }
    }
  }
}

Tools

4

List all user tables in the database

Get comprehensive table information for one or more tables including columns, indexes, triggers, foreign keys, and constraints

Execute a SQL query. The system will automatically detect the required permission level and request user approval for write operations and dangerous DDL commands.

Switches the active database to the specified one. If an error occurs during the switch, the system automatically reverts back to the previous active database

Overview

What is Postgres Mcp?

Postgres Mcp is a lightweight MCP (Model Context Protocol) server for querying a Postgres database using SQL or plain English commands. It provides tools for database operations, table introspection, and query execution with smart permission handling, intended for use with MCP-enabled AI assistants.

How to use Postgres Mcp?

Configure the server in an mcpServers JSON block with environment variables POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DATABASE (and optionally POSTGRES_PORT, POSTGRES_SSL, etc.). On macOS/Linux use npx -y @freakynit/postgres-mcp@latest as the command; on Windows use cmd /k npx -y @freakynit/postgres-mcp@latest.

Key features of Postgres Mcp

  • Smart query permission handling (read-only, read-write, admin/DDL)
  • Dry-run mode to validate queries without execution
  • Comprehensive table introspection (columns, keys, indexes, triggers, constraints)
  • Multiple database switching capability
  • Robust error handling and rollback

Use cases of Postgres Mcp

  • Ask an AI assistant to list all tables and describe their schemas
  • Execute read-only queries (SELECT, EXPLAIN) with automatic approval
  • Run INSERT/UPDATE/DELETE queries after user confirmation
  • Switch between multiple Postgres databases in one session
  • Safely test SQL statements using dry-run mode

FAQ from Postgres Mcp

How does permission handling work?

Read-only queries (SELECT, EXPLAIN, SHOW, VALUES) are automatically approved. Read-write queries (INSERT, UPDATE, DELETE, MERGE) require user confirmation. Admin/DDL queries (CREATE, ALTER, DROP, etc.) require elevated permission.

Can I run a query without actually executing it?

Yes, dry-run mode lets you validate queries without execution.

What environment variables are needed?

Minimum four variables: POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DATABASE. Optionally set POSTGRES_PORT, POSTGRES_SSL, POSTGRES_VERIFY, POSTGRES_SEND_RECEIVE_TIMEOUT, and POSTGRES_CONNECT_TIMEOUT.

What tools does Postgres Mcp provide?

Four tools: execute_raw_query, list_tables, describe_tables, and switch_database.

Can I switch databases during a session?

Yes, the switch_database tool allows changing the active database connection.

Comments

More Databases MCP servers