npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@freakynit/postgres-mcp

v2.0.1

Published

A lightweight MCP server built to query Postgres database using SQL or plain English

Readme

Postgres MCP

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

Features

Smart Query Permission Handling

  • Read-only queries: Automatically approved (SELECT, EXPLAIN, SHOW, VALUES)
  • Read-write queries: User confirmation required (INSERT, UPDATE, DELETE, MERGE)
  • Admin/DDL queries: Elevated permission required (CREATE, ALTER, DROP, etc.)
  • Dry-run mode: Validate queries without execution

Comprehensive Table Introspection

  • Column definitions with types and constraints
  • Primary and foreign key relationships
  • Index definitions
  • Triggers and check constraints

Database Management

  • Multiple database switching capability
  • Robust error handling and rollback

Available Tools

| Tool | Description | | ----------------------- | -------------------------------------------------------- | | execute_raw_query | Execute SQL queries with permission validation and dry-run support | | list_tables | List all non-system tables | | describe_tables | Get comprehensive table information including columns, indexes, triggers, and constraints | | switch_database | Switch the active database connection |

Minimum needed environment variables

  1. POSTGRES_HOST
  2. POSTGRES_USER
  3. POSTGRES_PASSWORD
  4. POSTGRES_DATABASE

Other environment variables

  1. POSTGRES_PORT
  2. POSTGRES_SSL (boolean)
  3. POSTGRES_VERIFY (boolean)
  4. POSTGRES_SEND_RECEIVE_TIMEOUT (in seconds)
  5. POSTGRES_CONNECT_TIMEOUT (in seconds)

Configuring using mcpServers json

For Mac and Linux

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

For Windows

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

Development Docs

Prerequisites

  • Node.js
  • A PostgreSQL server

Installation

npm i -g @freakynit/postgres-mcp

OR

git clone https://github.com/freakynit/postgres-mcp.git
cd postgres-mcp
npm install

Configuration

Create a .env file in the project root with the following variables:

# PostgreSQL
POSTGRES_HOST=your-db-host
POSTGRES_PORT=5432                      # Optional, default 5432
POSTGRES_USER=your-username
POSTGRES_PASSWORD=your-password
POSTGRES_DATABASE=your-database

# SSL settings (optional)
POSTGRES_SSL=false                      # Or true
POSTGRES_VERIFY=false                   # Verify server cert if SSL true

# Timeouts (optional, seconds)
POSTGRES_SEND_RECEIVE_TIMEOUT=60        # Query timeout
POSTGRES_CONNECT_TIMEOUT=60             # Connection timeout

Usage

Local Development

Start the server (Starts in stdio mode):

node src/index.js

With MCP Inspector

For debugging and development:

npx @modelcontextprotocol/inspector node src/index.js

Debugging with MCP inspector

npx @modelcontextprotocol/inspector node src/index.js

License

This project is licensed under the MIT License. See LICENSE for details.