Basic information

Category
License
MIT
Transports
stdio
Author
freakynit
Submitted by
Community
Quality
25

About Postgres Mcp Server

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.

Postgres Mcp is a MCP server in the Databases category listed in the AddMCP.net directory, published by freakynit. It exposes 4 tools, including list_tables, describe_tables, execute_raw_query, switch_database. Supported transport: stdio. License: MIT. Source code is hosted on github.com. Related topics: best, database, postgre, postgres.

Setup

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

Postgres Mcp 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>"
            }
        }
    }
}

Postgres Mcp tools

  • list_tables — List all user tables in the database
    (no parameters)
  • describe_tables — Get comprehensive table information for one or more tables including columns, indexes, triggers, foreign keys, and constraints
    table_names:array*, table_schema:string
  • execute_raw_query — Execute a SQL query. The system will automatically detect the required permission level and request user approval for write operations and dangerous DDL commands.
    dry_run:boolean, sql:string*
  • switch_database — 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
    database_name:string*

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

Frequently asked questions

1 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.

2 Can I run a query without actually executing it?

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

3 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.

4 What tools does Postgres Mcp provide?

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

5 Can I switch databases during a session?

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

Comments

No comments yet

Be the first to share feedback about this listing. Sign in to leave a comment.

Sign In

Feedback 💬