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-mcpshow 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
This server cannot be deployed
Maintenance
Related MCP Connectors
- WoWSQLOAuthcom.wowsql
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