Skip to main content

pgsafe-mcp

PyPI CI Python 3.10+ MCP Compliant License: MIT Support on Ko-fi

pgsafe-mcp MCP server

PgSafe MCP is a read-only Model Context Protocol server for PostgreSQL and SQLite that enables AI coding agents in Claude Desktop, Cursor, Windsurf, and Antigravity to inspect schemas, run bounded analytical SQL queries with automatic PII masking, and test DML statements inside rolled-back SQLite transactions.


Quickstart

Run directly via uvx:

uvx pgsafe-mcp

Claude Desktop / Cursor configuration:

{
  "mcpServers": {
    "pgsafe-mcp": {
      "command": "uvx",
      "args": ["pgsafe-mcp"],
      "env": {
        "DATABASE_URL": "postgresql://readonly_user:password@localhost:5432/analytics_db"
      }
    }
  }
}

For SQLite databases:

{
  "mcpServers": {
    "pgsafe-mcp": {
      "command": "uvx",
      "args": ["pgsafe-mcp"],
      "env": {
        "DATABASE_URL": "sqlite:///path/to/database.db"
      }
    }
  }
}

For PostgreSQL support when installing from source:

pip install "pgsafe-mcp[postgres]"

Core Capabilities

  1. Lexer-Aware Read-Only SQL Guard: Tokenizes SQL comments and string/dollar-quoted literals before validating statement boundaries, blocking DROP, TRUNCATE, DELETE, UPDATE, INSERT, ALTER, COPY, VACUUM, ATTACH, EXPLAIN ANALYZE, and semicolon chaining.
  2. Engine-Level Read-Only Enforcement: Configures PostgreSQL sessions with SET default_transaction_read_only = on and SQLite connections with ?mode=ro plus sqlite3.Connection.set_authorizer.
  3. Top-Level Row Limit Enforcement: Applies LIMIT bounds to outer SELECT and WITH queries without corrupting PRAGMA, EXPLAIN, OFFSET, or trailing SQL comments.
  4. Live PII Redaction: Masks emails, payment card numbers, phone numbers, password hashes, and sensitive column values before returning rows to the LLM context.
  5. SQLite Dry-Run Mutation Harness: Simulates single-statement INSERT, UPDATE, or DELETE changes inside an immediate transaction with authorizer restrictions and automatic ROLLBACK.
  6. Heuristic Query & Index Inspection: Flags missing WHERE clauses, unconstrained joins, and candidate filter columns for indexing.

MCP Tools

Tool Parameters Description
list_tables (none) Lists user tables in the connected PostgreSQL or SQLite database
describe_table table_name Returns column names, types, nullability, defaults, and primary key metadata
safe_query query, limit, mask_pii Validates read-only SQL, enforces row limits, executes query, and masks PII
dry_run_mutation mutation_sql Simulates a single DML statement on SQLite inside an auto-rolled-back transaction
analyze_query query Evaluates read-only safety and full-scan / Cartesian join risk heuristics
recommend_indexes query Suggests candidate indexes from WHERE and ORDER BY predicates
get_security_status (none) Reports active guard status and credential-redacted DATABASE_URL

Package Description Repository
genesis-blackbox Runtime flight recorder and AST blast-radius crash compiler GitHub
crawlengine-mcp HTTP web extraction, clean Markdown conversion, and proxy rotation GitHub
browserbridge-mcp Session-pooled HTTP DOM inspection and SHA-256 action trail receipts GitHub
omnibridge-mcp Multi-channel notification bus with SQLite retry queue GitHub
sysflow-mcp Linux resource inspection, systemd unit generator, and log tailer GitHub
fastmcp-forge MCP server framework and project scaffolder GitHub

Support

If this project is useful in your workflow, you can support ongoing maintenance on Ko-fi.

License

MIT License. Copyright (c) 2026 Johann Schiffer.

Metadata

Release files for pgsafe-mcp 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgsafe-mcp 2.0.1
File Size Uploaded Provenance Actions
pgsafe_mcp-2.0.1.tar.gz 22.4 kB Without provenance Details for pgsafe_mcp-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pgsafe-mcp 2.0.1
File Interpreter ABI Platform Actions
pgsafe_mcp-2.0.1-py3-none-any.whl Python 3 none any Details for pgsafe_mcp-2.0.1-py3-none-any.whl

Total release size: 42.8 kB

Release files / pgsafe_mcp-2.0.1.tar.gz

Download URL pgsafe_mcp-2.0.1.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f4c5b6fab0f7e2b54195a1f465f3c40fe16a73b9b60f0692001e5866e4bf0222
BLAKE2b-256 checksum
How to use checksums
edbedd197d0502fb197d9a6ba6291ce38df7d757ec49fc2d74c215327e85f52c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / pgsafe_mcp-2.0.1-py3-none-any.whl

Download URL pgsafe_mcp-2.0.1-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ceb0b0385f6ce33a00612b5ebb40b66673ad95450c3d44447de9967401324d2
BLAKE2b-256 checksum
How to use checksums
ab54c9de2bce69772a793a4baccb35cb4ce9fa76318992ab1508b92f8c93ee0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for pgsafe-mcp 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page