{"id":"b8ff85b5-48a0-4e79-995e-47f50ceb0f76","slug":"mcp-postgres-analytics","kind":"mcp","name":"mcp-postgres-analytics","summary":"Read-only PostgreSQL analytics agent exposed as an MCP server. Lets Claude / ChatGPT / Cursor inspect query plans, surface slow queries, audit index usage, detect table bloat, and report vacuum status","owner":"archimedes-market","repoUrl":"https://github.com/archimedes-market/mcp-postgres-analytics","license":"MIT","licenseTier":"permissive","trust":"community","stars":0,"match":null,"fewStars":true,"format":"mcp","createdAt":"2026-05-19T04:06:29.000Z","addedAt":"2026-10-21T04:35:03.019Z","logoUrl":"https://avatars.githubusercontent.com/u/285879992?v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["databases","cloud-infra","data-analytics"],"tags":["analytics","database","observability","postgres","read-only"],"runtime":"python","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-23T17:01:16.277Z","sample":false,"url":"https://conduits.dev/tools/mcp-postgres-analytics","language":"Python","transports":["stdio"],"install":{"pypi":"mcp-postgres-analytics"},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"[![Archimedes Trust Report — VERIFIED 92/100](https://img.shields.io/badge/Archimedes_Trust-VERIFIED_92%2F100-10B981?style=flat-square)](https://archimedes.market/assets/aa632521-f830-4adf-9828-7c6079e06a83)\n\n> Verified asset on [**Archimedes Market**](https://archimedes.market). View the full 4-dimension Trust Report (security · quality · license · complexity) and the curated catalog on the [asset page](https://archimedes.market/assets/aa632521-f830-4adf-9828-7c6079e06a83).\n\n---\n\n# MCP PostgreSQL Analytics\n\nRead-only PostgreSQL analytics agent exposed as an MCP server. Designed to drop into a production database safely — no DDL, no DML, no writes ever.\n\nEight tools cover the observability surface most teams reach for during incident response and capacity planning:\n\n- `query_plan` — `EXPLAIN (ANALYZE, BUFFERS, VERBOSE)` against a query string, with annotated cost hot spots\n- `slow_queries` — top N queries by mean time / total time / call count from `pg_stat_statements`\n- `index_usage` — index hit ratio, dead indexes, missing-index hints from `pg_stat_user_indexes`\n- `table_bloat` — bloat estimation per table using the pgstattuple-equivalent heuristic\n- `vacuum_status` — last vacuum / autovacuum / analyze per table, with wraparound risk flagged\n- `connection_stats` — active sessions, idle-in-transaction, longest-running transactions\n- `lock_waits` — blocked queries with the blocker chain resolved\n- `size_summary` — database/schema/table/index size, sorted\n\n## Safety guarantees\n\nThe MCP server connects as a role with `pg_read_all_stats` and `CONNECT` only. The connection string in `MCP_POSTGRES_DSN` is validated at startup to refuse any role that has `CREATE`, `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, `ALTER`, or `DROP` privileges on any schema. Refusal exits with a clear error rather than running with elevated rights.\n\n`query_plan` accepts a query string but executes it inside `EXPLAIN (...)` only — the query itself is never run.\n\n## Quick start\n\n```bash\npip install mcp-postgres-analytics\nexport MCP_POSTGRES_DSN=\"postgresql://reader@host:5432/db\"\nmcp-postgres-analytics serve\n```\n\nClaude Desktop config:\n\n```json\n{\n  \"mcpServers\": {\n    \"postgres-analytics\": {\n      \"command\": \"mcp-postgres-analytics\",\n      \"args\": [\"serve\"],\n      \"env\": {\n        \"MCP_POSTGRES_DSN\": \"postgresql://reader@host:5432/db\"\n      }\n    }\n  }\n}\n```\n\n## Typical agent workflow\n\n```\nAgent: \"Why is our /api/checkout endpoint slow this week?\"\n↓\n1. slow_queries → top 5 queries by mean time\n2. query_plan on the worst → spots a sequential scan\n3. index_usage → confirms missing index hint\n4. size_summary → confirms the table is 14GB\n5. Output: \"Index on orders(status, created_at) missing. ~150ms saved per call. Run during low-traffic window.\"\n```\n\n## What it does NOT do\n\n- No write operations of any kind\n- No connection to non-PostgreSQL databases (use the DuckDB MCP for Parquet/CSV)\n- No backup/restore (use pg_dump directly)\n- No replication topology management\n\nIf you need write access for an agent workflow, use a separate MCP server with explicit gates. Mixing read-only analytics with write operations is exactly the kind of conflated tooling that this server was built to avoid.\n\n## License\n\nMIT.\n"}