Skip to main content
Glama
adexxhh

Database Auditor MCP

by adexxhh

MCP Database Auditor

Inspect database schemas, profile tables and review SQL query plans through the Model Context Protocol.

The auditor gives an MCP client structured access to SQLite and PostgreSQL metadata and read-only queries. SQL policy checks, database permissions and execution deadlines help keep exploratory database work controlled.

Features

  • Schema exploration: tables, columns, keys, indexes and relationships exposed as MCP resources.

  • Read-only queries: SQLGlot AST validation, function policies and bounded result limits.

  • Table profiling: sampled column statistics, including JSON and decimal values.

  • Query-plan inspection: EXPLAIN output with scan and indexing observations.

  • Audit records: JSONL events with execution outcomes and normalized query fingerprints.

  • Schema comparison: changes between successive in-process snapshots.

Related MCP server: Postgres Analytics MCP Server

Architecture

flowchart LR
  Client[MCP client] --> Tools[FastMCP tools and resources]
  Tools --> Policy[SQL AST validation]
  Policy --> Database[Read-only SQLite or PostgreSQL]
  Database --> Results[Rows, schema and query plans]
  Results --> Output[Profiles, audit events and responses]

MCP tool

Purpose

execute_safe_query

Validate and execute a read-only query

profile_table

Summarize a sample of table data

get_database_health

Report connection and database information

analyze_query_plan

Inspect the database query plan

schema_changes

Compare the current schema with the previous snapshot

Schema resources: schema://current and schema://table/{table_name}.

Quick start

python -m venv .venv
# Activate the environment, then install:
pip install -e ".[dev]"
python scripts/seed_demo_db.py
python server.py

In another terminal with the environment activated:

python client_test.py

The default transport is stdio. DATABASE_URL selects a database connection; the default configuration initializes a local SQLite demo. AUDIT_LOG_PATH selects the JSONL audit destination.

For local SSE:

python server.py --transport sse --host 127.0.0.1 --port 8000

Use least-privilege database roles. A hosted SSE deployment also needs an authentication layer.

PostgreSQL

The Compose configuration separates the database owner from a SELECT-only reader:

docker compose up --build

Use the disposable reader URL from docker-compose.yml for TEST_POSTGRES_URL when running the PostgreSQL integration test:

python -m pytest tests/test_postgres_integration.py -q

Validation and performance

python -m pytest -q
python benchmark.py --repeats 30 --output benchmark-results.json

The local suite passes 58 tests. Linux CI also passes the PostgreSQL integration job and the SQLite/MCP checks.

Operation

Median

p95

Schema reflection

14.80 ms

15.80 ms

SQL policy validation

0.445 ms

0.591 ms

Measurements use 30 runs on a seeded five-table local SQLite database. Benchmark samples ? CI results

Profiles summarize the first 100 returned rows. Schema comparison state lasts for the server process, and query-plan observations should be interpreted alongside the database workload.

Demo

Database auditor terminal walkthrough

PNG ? Command transcript

Regenerate the terminal walkthrough with requirements-demo.txt and python scripts/render_demo.py.

Development

Engineering guide ? CPU service-check notebook ? Continuation notes

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables an AI assistant to run guarded, read-only SQL queries against a Postgres database with enforced limits and validation.
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables AI assistants to safely inspect and query PostgreSQL databases with read-only enforcement, row/timeout limits, and audit logging, providing tools for schema/table listing, read-only queries, query explanations, and table statistics.
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Lets an AI assistant explore and query Postgres, DuckDB, or Snowflake with read-only SQL, table and schema discovery, sampling, and explainable guardrails.
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.
    MIT