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

@fauzitech/mcp-postgres

v0.1.0

Published

Safe, read-only-by-default Model Context Protocol (MCP) server for PostgreSQL. Let AI agents inspect and query your database without fear of destructive writes.

Downloads

206

Readme

@fauzitech/mcp-postgres

A safe, read-only-by-default Model Context Protocol (MCP) server for PostgreSQL. Let AI agents like Claude, Cursor, and Windsurf inspect and query your database — without the risk of an accidental DROP TABLE.

npm MCP License Tests

Why

Connecting an AI agent directly to your database is powerful — it can explore schemas, write queries, and debug data for you. But handing an LLM write access to production is asking for trouble. One hallucinated DELETE and you're restoring from backups.

mcp-postgres is read-only by default and enforces it at two layers:

  1. SQL guard — parses each statement, strips comments and string literals, and rejects anything that isn't a pure read (SELECT, WITH, EXPLAIN, SHOW, …). It catches evasion tricks like data-modifying CTEs (WITH x AS (INSERT …)) and stacked statements.
  2. READ ONLY transaction — every query runs inside BEGIN TRANSACTION READ ONLY, so even if the guard were bypassed, PostgreSQL itself refuses the write.

Writes are only ever possible if you explicitly start the server with --write.

Features

  • Read-only by default — two-layer enforcement (SQL guard + read-only transaction)
  • Schema introspection — list schemas, tables, and describe columns
  • Safe query execution — statement timeout, row cap, single-statement enforcement
  • Write mode — opt in explicitly with --write when you actually need it
  • Zero config — point it at a connection string and go
  • Tiny — one dependency tree, stdio transport, works anywhere Node runs

Installation

No install needed — run it straight with npx:

npx @fauzitech/mcp-postgres "postgresql://user:pass@host:5432/dbname"

Or install globally:

npm install -g @fauzitech/mcp-postgres
mcp-postgres "postgresql://user:pass@host:5432/dbname"

Usage with Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@fauzitech/mcp-postgres",
        "postgresql://user:pass@host:5432/dbname"
      ]
    }
  }
}

Usage with Cursor

Add to .cursor/mcp.json in your project:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@fauzitech/mcp-postgres", "postgresql://user:pass@host:5432/dbname"]
    }
  }
}

Usage with Hermes Agent

Add to ~/.hermes/config.yaml:

mcp_servers:
  postgres:
    command: "npx"
    args: ["-y", "@fauzitech/mcp-postgres"]
    env:
      DATABASE_URL: "postgresql://user:pass@host:5432/dbname"

Configuration

The connection string can be passed as the first argument or via the DATABASE_URL environment variable.

| Flag | Default | Description | |------|---------|-------------| | --write | off | Allow data-modifying statements (INSERT, UPDATE, DELETE, DDL). Use with caution. | | --allow-multiple | off | Allow multiple ;-separated statements per query call | | --max-rows=N | 1000 | Maximum rows returned by a single query | | --statement-timeout=MS | 15000 | Per-statement timeout in milliseconds |

Example — write mode with a higher row cap:

mcp-postgres --write --max-rows=5000 "postgresql://..."

Tools

The server exposes four tools:

query

Execute a SQL query. In read-only mode (default), only read statements are allowed.

query(sql: string)

list_schemas

List all non-system schemas.

list_schemas()

list_tables

List tables and views in a schema.

list_tables(schema?: string = "public")

describe_table

Show columns, types, nullability, and defaults for a table.

describe_table(table: string, schema?: string = "public")

Security model

| Layer | Protection | |-------|-----------| | SQL guard | Rejects non-read statements before they reach the database. Comment- and string-aware, so SELECT 'drop table' is fine but DROP TABLE is blocked. | | CTE inspection | Blocks data-modifying CTEs like WITH x AS (INSERT … RETURNING *) SELECT * FROM x. | | Statement count | Rejects stacked statements (SELECT 1; DELETE …) unless --allow-multiple is set — and even then each statement is individually guarded. | | READ ONLY transaction | Every read query runs in BEGIN TRANSACTION READ ONLY. A database-level guarantee independent of the guard. | | Statement timeout | SET LOCAL statement_timeout prevents runaway queries. | | Row cap | Results are truncated to --max-rows to avoid flooding the agent's context. |

Note on credentials: the connection string contains your database password. Prefer passing it via the DATABASE_URL environment variable rather than as a command-line argument, since arguments can be visible in process listings. When configuring an MCP client, use a least-privilege database role — ideally one with only SELECT grants.

Development

git clone https://github.com/muhfauziazhar/mcp-postgres.git
cd mcp-postgres
npm install
npm run build
npm test                     # unit tests (guard logic)
DATABASE_URL=postgresql://... npm test   # + integration test

License

MIT © Muhammad Fauzi Azhar