PgSafe MCP
Based on the exposed server schema, this server provides read-only database inspection and SQL query safety analysis.
List all public database tables available for inspection and querying.
Describe a table’s columns, data types, nullability, and keys.
Execute strictly read-only SQL queries (SELECT/EXPLAIN) with automatic LIMIT enforcement (default 100, max 1000) and mutation blocking.
Analyze SQL queries for dangerous operations, unindexed scans, and Cartesian join risks without executing them.
Provides read-only SQL querying and schema inspection for PostgreSQL databases, with enforced LIMIT clauses and blocking of destructive statements to safely explore data.
Provides read-only SQL querying and schema inspection for SQLite databases, with enforced LIMIT clauses and blocking of destructive statements to safely explore data.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PgSafe MCP show me the schema for the orders table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pgsafe-mcp
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-mcpClaude 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]"Related MCP server: shop-mcp
Core Capabilities
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.Engine-Level Read-Only Enforcement: Configures PostgreSQL sessions with
SET default_transaction_read_only = onand SQLite connections with?mode=roplussqlite3.Connection.set_authorizer.Top-Level Row Limit Enforcement: Applies
LIMITbounds to outerSELECTandWITHqueries without corruptingPRAGMA,EXPLAIN,OFFSET, or trailing SQL comments.Live PII Redaction: Masks emails, payment card numbers, phone numbers, password hashes, and sensitive column values before returning rows to the LLM context.
SQLite Dry-Run Mutation Harness: Simulates single-statement
INSERT,UPDATE, orDELETEchanges inside an immediate transaction with authorizer restrictions and automaticROLLBACK.Heuristic Query & Index Inspection: Flags missing
WHEREclauses, unconstrained joins, and candidate filter columns for indexing.
MCP Tools
Tool | Parameters | Description |
| (none) | Lists user tables in the connected PostgreSQL or SQLite database |
|
| Returns column names, types, nullability, defaults, and primary key metadata |
|
| Validates read-only SQL, enforces row limits, executes query, and masks PII |
|
| Simulates a single DML statement on SQLite inside an auto-rolled-back transaction |
|
| Evaluates read-only safety and full-scan / Cartesian join risk heuristics |
|
| Suggests candidate indexes from |
| (none) | Reports active guard status and credential-redacted |
Related Open-Source MCP Servers
Package | Description | Repository |
genesis-blackbox | Runtime flight recorder and AST blast-radius crash compiler | |
crawlengine-mcp | HTTP web extraction, clean Markdown conversion, and proxy rotation | |
browserbridge-mcp | Session-pooled HTTP DOM inspection and SHA-256 action trail receipts | |
omnibridge-mcp | Multi-channel notification bus with SQLite retry queue | |
sysflow-mcp | Linux resource inspection, systemd unit generator, and log tailer | |
fastmcp-forge | MCP server framework and project scaffolder |
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.
Available Tools
4 toolsanalyze_queryA
Analyze a SQL query for dangerous operations, unindexed scans, and Cartesian join risks without executing it.
Inputs: query (required).
describe_tableA
Retrieve column definitions, data types, nullability, and keys for a specific table.
Inputs: table_name (required).
list_tablesB
List all public database tables available for inspection and querying.
Inputs: no named parameters.
safe_queryA
Execute a strictly read-only SQL query with automatic LIMIT enforcement and mutation blocking.
Inputs: query (required), limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool has a clearly distinct purpose: list_tables vs describe_table target different levels of schema introspection, while safe_query executes read-only queries and analyze_query performs static analysis without execution. There is no meaningful overlap that would cause misselection.
All names use snake_case, which is consistent. However, safe_query deviates slightly from the dominant verb_noun pattern seen in list_tables, describe_table, and analyze_query by using an adjective_noun construction.
Four tools is well-scoped for a read-only PostgreSQL safety server. Each tool covers a necessary capability: table discovery, schema inspection, safe execution, and query risk analysis.
The core read-only workflow is covered: discover tables, inspect their structure, query safely, and analyze query risk. Minor gaps exist, such as explicit schema/view listing or index introspection, but agents can work around these using safe_query against system catalogs.
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables safe, read-only SQL access to SQLite databases for AI agents, allowing schema exploration and SELECT queries with defense-in-depth protections.3MIT
- AlicenseAqualityCmaintenanceEnables AI agents to safely explore and query a SQLite database in read-only mode, allowing them to inspect schema and run analytical SQL queries without risking data modification.3MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to safely query and explore SQLite databases through read-only, guard-protected tools that block writes, sensitive table access, and runaway queries.1MIT
- AlicenseBqualityCmaintenanceEnables AI assistants to safely run read-only SQL against SQLite databases through whitelist-validated queries, capped result sets, and confined file paths. It also exposes schema inspection so models can discover tables and columns before querying.2MIT