MCP server for PostgreSQL analytics — schema health, row counts, ingestion monitoring, multi-env support
Project description
pg-analytics-mcp
An MCP server for PostgreSQL analytics — gives any MCP client (Claude Code, Cursor, etc.) instant visibility into schema health, row counts, ingestion monitoring, and multi-environment comparison.
What it does
Exposes 7 read-only tools that let you inspect and monitor one or more PostgreSQL databases:
- Schema scanning — row counts for every table, grouped by schema
- Table health — row count, last
inserted_at/updated_atfor a specific table - Ingestion monitoring — recent failures and failure summaries from a
pipeline.ingestion_failurestable - Multi-env comparison — compare row counts across DEV / STG / PROD
- Empty table detection — quickly find tables with 0 rows
Quick start
Prerequisites
- Python 3.12+
- uv (recommended) or pip
- One or more PostgreSQL instances
Install
Option A — run directly with uvx (no clone needed):
uvx pg-analytics-mcp
Option B — clone and run:
git clone https://github.com/fabdendev/pg-analytics-mcp.git
cd pg-analytics-mcp
uv sync
Configure
Set environment variables for each PostgreSQL environment (at least one is required):
| Variable | Description | Required |
|---|---|---|
PG_DEV_URL |
PostgreSQL DSN for DEV | At least one URL |
PG_STG_URL |
PostgreSQL DSN for STG | Optional |
PG_PROD_URL |
PostgreSQL DSN for PROD | Optional |
PG_READ_ONLY |
Reserved for future write tools (not yet used) | Optional |
export PG_DEV_URL="postgresql://user:pass@host:5432/dbname"
export PG_STG_URL="postgresql://user:pass@host:5432/dbname" # optional
export PG_PROD_URL="postgresql://user:pass@host:5432/dbname" # optional
Supports postgresql+asyncpg:// URLs (the driver prefix is stripped automatically).
Add to Claude Code
Add to your Claude Code MCP settings (~/.claude/settings.json or .mcp.json):
If using uvx:
{
"mcpServers": {
"pg-analytics": {
"command": "uvx",
"args": ["pg-analytics-mcp"],
"env": {
"PG_DEV_URL": "postgresql://user:pass@host:5432/dbname",
"PG_STG_URL": "postgresql://user:pass@host:5432/dbname"
}
}
}
}
If installed from clone:
{
"mcpServers": {
"pg-analytics": {
"command": "uv",
"args": ["run", "--directory", "/path/to/pg-analytics-mcp", "pg-analytics-mcp"],
"env": {
"PG_DEV_URL": "postgresql://user:pass@host:5432/dbname"
}
}
}
}
Tools
| Tool | Description |
|---|---|
scan_schemas |
Row counts for all tables, grouped by schema |
table_health |
Row count + last inserted_at/updated_at for a specific table |
ingestion_failures |
Recent records from pipeline.ingestion_failures (filterable by asset) |
ingestion_failures_summary |
Failures grouped by table + error reason with counts |
compare_envs |
Compare row counts for a table across all configured environments |
list_empty_tables |
All tables with 0 rows in a given environment |
list_environments |
List which environments are configured |
All tools are read-only. No data is ever modified.
How it works
The server connects to each configured PostgreSQL instance using psycopg2 and runs read-only queries against information_schema and your application tables. Internal schemas (TimescaleDB, pg_catalog, information_schema, public) are filtered out by default.
The ingestion_failures and ingestion_failures_summary tools expect a pipeline.ingestion_failures table — if it doesn't exist in your database, they return a clear error message instead of failing.
Multi-environment support
Configure up to 3 environments (DEV, STG, PROD). The first configured environment becomes the default. Use compare_envs to quickly spot row count differences across environments — useful for verifying that ETL pipelines are running consistently.
Development
uv sync --extra dev
uv run ruff check pg_analytics_mcp/ # lint
uv run python -m pg_analytics_mcp # start server locally
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pg_analytics_mcp-0.1.0.tar.gz.
File metadata
- Download URL: pg_analytics_mcp-0.1.0.tar.gz
- Upload date:
- Size: 66.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2e65931a92b7124ad5d611e82ef587b9c34c6f8ef45c6fa2df9e351286f8ea3
|
|
| MD5 |
1150e43ba61809ce769620d9ab5bdd17
|
|
| BLAKE2b-256 |
4885a7f9243775acd59df6e020071708dd39bc128f5019ba6b615d90e29b5bde
|
File details
Details for the file pg_analytics_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pg_analytics_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a44e64dd31a3a5d1b1ff1ada6340e1e6afe7a75383df89e82709cb4ca52e4266
|
|
| MD5 |
ccf57c1806a477014b60629da8f39c03
|
|
| BLAKE2b-256 |
8272452914bdff482ce64da5b9e9393d5cddf14f28a5170c096ffe6e425ff7e7
|