pg-insight-mcp
Provides read-only access to PostgreSQL databases for schema discovery, safe analytical SQL queries, row sampling, and execution plan inspection, including schema allow-listing and query guardrails.
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-insight-mcp show me the schema for the orders table and its indexes"
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-insight-mcp
A read-only PostgreSQL server for the Model Context Protocol. It lets any MCP client (Claude Desktop, VS Code, Cursor, custom agents) explore a database schema, run analytical queries and inspect execution plans, without any chance of changing data.
Features
Schema discovery: schemas, tables, views, columns, constraints, indexes and incoming foreign keys
Safe querying: every statement runs inside a
READ ONLYtransaction with a statement timeoutQuery guard: SQL is checked before it reaches the database. Only one statement is allowed, writes and DDL are rejected,
EXPLAIN ANALYZEand dangerous functions such aspg_sleep,pg_read_file,dblinkandset_configare blocked, andSELECT ... INTOis refusedRow caps: results are limited to a configurable row count and flagged as
truncatedwhen more rows existPlans without execution:
explain_queryreturns the JSON plan plus a readable summary treeSchema allow-list: restrict the server to selected schemas; system schemas are never exposed
Structured tool output, an MCP resource with the full schema overview, and a prompt for guided analysis
Related MCP server: PostgreSQL MCP Server
Tools
Tool | Description |
| User schemas with table and view counts |
| Tables and views in a schema with estimated rows and size |
| Columns, types, defaults, constraints, indexes, referencing tables |
| First N rows of a table |
| Run a read-only SQL statement |
| Execution plan without running the query |
Resource: schema://overview. Prompt: analyse(question).
Quick start
Requires Python 3.11+ and Docker (for the sample database).
docker compose up -d
python -m venv .venv
.venv/bin/pip install -e ".[dev]"On Windows the virtual environment's tools are in .venv\Scripts\ instead of .venv/bin/.
The sample shop database (200 customers, 12 products, 1,500 orders) is created and seeded automatically on
port 5434.
Run the server over stdio:
DATABASE_URL=postgresql://shop:shop@localhost:5434/shop pg-insight-mcpPowerShell:
$env:DATABASE_URL = "postgresql://shop:shop@localhost:5434/shop"
.venv\Scripts\pg-insight-mcpOr over HTTP:
pg-insight-mcp --transport streamable-httpTry it interactively with the MCP Inspector:
DATABASE_URL=postgresql://shop:shop@localhost:5434/shop npx @modelcontextprotocol/inspector .venv/bin/pg-insight-mcpClick Connect, open the Tools tab and try:
Tool | Input | Expected |
|
| customers, products, orders, order_items |
|
| columns, primary and foreign keys, indexes |
|
| order counts per status |
|
| rejected: only read-only queries are allowed |
|
| plan using the customer index |
Claude Desktop
Add the server to claude_desktop_config.json:
{
"mcpServers": {
"pg-insight": {
"command": "/path/to/pg-insight-mcp/.venv/bin/pg-insight-mcp",
"env": {
"DATABASE_URL": "postgresql://shop:shop@localhost:5434/shop"
}
}
}
}On Windows the file is %APPDATA%\Claude\claude_desktop_config.json and the command is
C:\\path\\to\\pg-insight-mcp\\.venv\\Scripts\\pg-insight-mcp.exe. Restart Claude Desktop after editing it.
Then ask questions such as "Which product category brought in the most revenue last quarter?".
Configuration
Variable | Default | Description |
| required | PostgreSQL connection string |
|
| Maximum rows returned per query |
|
| Per-statement timeout |
| all | Comma-separated schema allow-list |
For production databases, also connect with a dedicated role that only has SELECT privileges. The server's
checks are a second layer of defence, not a replacement for database permissions.
Project layout
src/pg_insight/
config.py settings from environment variables
guard.py SQL validation
database.py catalog queries and read-only execution
server.py MCP tools, resource and prompt
seed/ sample schema and data
tests/ guard unit tests and end-to-end MCP testsTests
docker compose up -d
pytest
ruff check src testsThe end-to-end tests connect an in-memory MCP client to the server and run against the sample database. They are skipped when the database is not reachable.
Stop the sample database with docker compose down.
License
MIT
Available Tools
6 toolsdescribe_tableDescribe tableBRead-onlyIdempotent
Columns, constraints, indexes and incoming foreign keys of a table.
Inputs: table (required), schema. Returns: object
explain_queryExplain queryARead-onlyIdempotent
Show the PostgreSQL execution plan for a read-only query without running it.
Inputs: sql (required). Returns: object
list_schemasList schemasBRead-onlyIdempotent
List user schemas with table and view counts.
Inputs: no named parameters. Returns: object
list_tablesList tablesARead-onlyIdempotent
List tables and views in a schema with estimated row counts and sizes.
Inputs: schema. Returns: object
run_queryRun queryARead-onlyIdempotent
Run a single read-only SQL statement inside a read-only transaction. Results are capped and marked as truncated when more rows exist.
Inputs: sql (required), max_rows. Returns: object
sample_rowsSample rowsBRead-onlyIdempotent
Return the first rows of a table to see what the data looks like.
Inputs: table (required), limit, schema. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool maps to a distinct exploration step (schemas, tables, table detail, plan, sample, ad-hoc query), so selection is generally obvious. Mild overlap exists: sample_rows and simple exploration could be done via run_query, but the descriptions make the intended specialization clear.
All six names follow a consistent snake_case verb_noun pattern (list_schemas, list_tables, describe_table, explain_query, sample_rows, run_query). No mixed conventions or vague one-word names.
Six tools is well-scoped for a read-only PostgreSQL inspection server, and each tool earns its place in the exploration workflow. No bloat or awkwardly thin surface.
The surface covers the core read-only workflow: enumerate schemas and tables, describe structure, inspect plans, sample data, and run arbitrary SELECTs. Minor gaps like searching for tables/columns by name or listing indexes/extensions across the database are workarounds via run_query rather than dead ends.
Maintenance
Related MCP Connectors
Managed Postgres MCP: projects, SQL, docs search, and storage buckets via OAuth.
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Read-only MCP access to sessions, funnels, campaigns, errors, live visitors, and anomalies.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables interaction with PostgreSQL databases through MCP, allowing users to explore database structures, inspect table schemas, and execute read-only SQL queries.-
- -licenseNot gradedqualityNot gradedmaintenanceEnables users to perform SQL query execution, schema exploration, and performance analysis on PostgreSQL databases through any MCP-compatible client. It prioritizes security with read-only protection by default and provides guided workflows for database documentation and optimization.-
- FlicenseAqualityCmaintenanceEnables read-only access to a PostgreSQL database, allowing users to inspect schema, generate SQL from natural language, and execute read-only queries via MCP.5-
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to safely explore PostgreSQL schemas, inspect sample rows, draft queries, and read EXPLAIN plans through a read-only enforced interface for MCP clients.MIT