pg-inspect-mcp
Provides read-only PostgreSQL schema inspection, allowing exploration of schemas, tables, indexes, sizes, sample data, and query plans.
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., "@pg-inspect-mcp show me the schema of the users 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.
pg-inspect-mcp
A read-only Postgres schema-inspection MCP server. Point an MCP client (Claude Desktop, Claude Code, or anything speaking MCP) at a database and explore schemas, tables, indexes, sizes, sample data and query plans in natural language.
Design principle: impossible, not forbidden
Most "read-only" AI database tools are read-only because a prompt says so. That is a warning label, not a constraint — prompt injection or model error walks straight through it.
This server enforces read-only access structurally, in two independent layers, neither of which trusts the model:
The connection itself is read-only. Every connection is opened with
default_transaction_read_only=on, so Postgres rejects any write — even one that somehow reaches the database.A SQL guard rejects writes before the database sees them. Free-form input (only accepted by
explain_query) must be a singleSELECT/WITHstatement; stacked statements, writing CTEs, and DDL/DML keywords are refused. All identifier inputs are validated against a strict pattern and quoted withpsycopg.sql.Identifier.
No amount of clever input produces a write, because no code path can perform one.
Related MCP server: PostgreSQL MCP Server
Tools
Tool | What it does |
| Non-system schemas |
| Tables/views in a schema with estimated row counts |
| Columns, types, nullability, defaults |
| Index definitions |
| On-disk size, index size, live/dead tuples, last vacuum/analyze |
| Up to 50 sample rows |
|
|
Setup
pip install -e .
export DATABASE_URL=postgresql://user:pass@host:5432/dbname
pg-inspect-mcpFor extra safety in shared environments, connect as a Postgres role that has only SELECT grants — then the least-privilege credential is a third independent layer.
Claude Desktop / Claude Code config
{
"mcpServers": {
"pg-inspect": {
"command": "pg-inspect-mcp",
"env": { "DATABASE_URL": "postgresql://user:pass@host:5432/dbname" }
}
}
}Local database for development
docker compose up -d
export DATABASE_URL=postgresql://postgres:postgres@localhost:5433/postgresTests
The safety layer is the point of the server, so it is what gets tested:
pip install pytest && pytestCovers identifier injection shapes, stacked statements, writing CTEs (WITH x AS (DELETE ...)), EXPLAIN DELETE, COPY, and the read-only connection option.
Failure modes considered
Prompt injection via table contents — sampled rows may contain hostile text; the guard doesn't care what the model wants, only what the connection can do.
Writing CTEs —
WITH x AS (DELETE ... RETURNING *)is valid SQL that begins with an allowed keyword; explicitly rejected.EXPLAIN ANALYZE— actually executes the query; this server only ever issues plainEXPLAIN.Stacked statements —
SELECT 1; DELETE ...refused before parsing.
License
MIT
Available Tools
7 toolsdescribe_tableA
Show columns, types, nullability and defaults for a table.
Inputs: table (required), schema. Returns: result
explain_queryA
Return the JSON query plan (EXPLAIN, no execution) for a SELECT/WITH query.
Inputs: query (required). Returns: result
list_indexesB
List indexes on a table with their definitions.
Inputs: table (required), schema. Returns: result
list_schemasA
List non-system schemas in the connected database.
Inputs: no named parameters. Returns: result
list_tablesA
List tables and views in a schema, with estimated row counts.
Inputs: schema. Returns: result
sample_rowsA
Fetch up to 50 sample rows from a table.
Inputs: table (required), limit, schema. Returns: result
table_statsB
Table size on disk, index size, and live/dead tuple estimates.
Inputs: table (required), schema. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct aspect of database inspection: schemas, tables, table structure, indexes, table statistics, sample data, and query plans. There is minimal overlap between them, and an agent can easily select the right tool based on the task.
The names mostly follow a consistent verb_noun pattern (list_schemas, list_tables, describe_table, list_indexes, sample_rows, explain_query). table_stats breaks the pattern slightly, being noun_noun rather than verb_noun, but it is still readable and predictable.
Seven tools is well-scoped for a PostgreSQL inspection server. Each tool serves a clear purpose without unnecessary redundancy, and the count fits comfortably within the ideal range.
The tool surface covers the primary inspection workflow: discovering schemas/tables, examining columns, viewing indexes, retrieving table statistics, sampling rows, and explaining queries. Minor gaps like constraint/foreign key information or listing database objects beyond tables exist, but they are not critical for basic inspection.
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Query your Postgres from ChatGPT or Claude without exposing the database or handing over credentials. Run npx boltschema connect next to your database and it dials out over HTTPS — no inbound firewall rule, no open port, works with localhost and VPC-private databases. Read-only is enforced by a SQL guard, a Postgres READ ONLY transaction, and a scoped role generated for you.
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceEnables secure read-only interactions with PostgreSQL databases through natural language. Provides database inspection, table listing, and SQL query execution with built-in security validation.-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.MIT
- AlicenseNot gradedqualityDmaintenanceProvides read-only access to PostgreSQL databases, enabling users to list tables, view table structures and statistics, and execute SELECT queries safely through natural language.153 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables secure read-only access to PostgreSQL databases, allowing users to list tables, query schemas, execute SELECT statements, and inspect table structures through natural language interactions.468 npm4MIT