Repository navigation
First public release of MCP Postgres Analyst.
Highlights
- Seven MCP tools:
list_schemas,describe_table,sample_rows,run_query,explain_query,find_columns(by name or comment) andrun_saved_query, all with JSON schemas, structured output and read-only annotations - Resources:
schema://overview(Markdown data dictionary) andqueries://saved/queries://saved/{name}; prompts:analyse_tableandwrite_report - SQL guard built on sqlglot: one statement only,
SELECT/WITHonly, no data-modifying CTEs,SELECT INTO,FOR UPDATE,COPY,SET,PRAGMA; blocked functions (pg_sleep,dblink*,lo_*,pg_read_file,set_config,load_extension, ...) and system tables (pg_authid,pg_stat_activity, ...) - The database only ever receives SQL re-rendered from the validated AST, never the caller's raw text
- Automatic
LIMITinjection and clamping (also replacesLIMIT ALL, sub-query limits andFETCH FIRST), plus row and byte caps on the result - Statement timeout:
statement_timeouton PostgreSQL, a progress-handler interrupt on SQLite - Column masking from a YAML policy (
email,phone,last4,hash,redact) that follows aliases, expressions, CTEs and derived tables; blocked columns disappear even fromSELECT *; whole-row tricks likerow_to_json(c)are rejected - Per-tool token-bucket rate limits and an append-only JSONL audit log of every call (ok, rejected, timeout, rate limited)
- Both transports: stdio for desktop clients, Streamable HTTP with optional bearer token, DNS-rebinding protection and a
/healthendpoint - Deterministic demo database (fictional Bangladeshi online shop: customers, products, orders, bKash/Nagad/card/COD payments) seeded identically into SQLite or PostgreSQL
Getting started
- Quick start (Docker and local): see the README.
- Run it in your browser: Open in GitHub Codespaces
Quality
- Full test suite, lint and build run in CI on every push and pull request.
- MIT licensed.