Skip to main content

SQLite Guard MCP

CI Python License

A read-only, security-hardened Model Context Protocol server for inspecting local SQLite databases. It leverages the official MCP Python SDK, SQLite's read-only URI mode, native SQLite authorizer enforcement, bounded query execution, and heuristic masking for sensitive columns and credentials.

Security note: This is defense in depth, not an operating-system sandbox. The process can read any database file its operating-system account can access and that the operator configures. Column-name masking is heuristic and is not a substitute for database-level access controls. See SECURITY.md.

Features

  • Standard MCP transports (stdio, sse, and streamable-http) through the official MCP Python SDK.
  • HTTP / SSE Bearer Token Authentication via BearerAuthMiddleware (--auth-token or SQLITE_GUARD_AUTH_TOKEN).
  • Read-only SELECT, WITH, and VALUES queries with strictly validated bound parameters.
  • Built-in schema inspection, database intelligence & safety laboratory:
    • list_database_tables: List tables and views.
    • describe_database_table: Detailed schema inspection with unindexed foreign keys and overlapping index diagnostics.
    • explain_read_query: Query plan diagnostics with structured observations and confidence metrics.
    • get_database_overview: High-level metrics (page count, schema version, table/index/view counts, approximate size).
    • search_database_schema: Bounded case-insensitive search across tables, views, columns, and indexes.
    • check_database_health: Quick integrity check, foreign key violation diagnostics, and index redundancy analysis.
    • simulate_candidate_index: Index Laboratory — safe execution and plan comparison on disposable in-memory snapshots without touching the source database.
    • profile_database_table: Privacy-preserving data profiling — null ratios, cardinality, distinct counts, safe min/max, and credential masking.
    • diff_database_schemas: Structural schema diffing between two databases, detecting breaking changes, dropped columns, and drift.
    • review_migration_script: Static safety inspection for migration scripts without executing SQL (checks drops, locks, transactions, and dangerous pragmas).
  • MCP Resources:
    • schema://summary: Zero-turn inspection of tables, views, and column definitions.
    • schema://snapshot: Canonical JSON snapshot of all tables, columns, indexes, and foreign keys.
  • CLI System Doctor & Policy Diagnostics:
    • sqlite-guard-mcp --doctor: Comprehensive health report of platform, Python, SQLite compilation options, and database integrity.
    • sqlite-guard-mcp --validate-policy --policy <file>: Validate TOML policy syntax and rules.
    • sqlite-guard-mcp --policy <file> --explain-policy-table <table_name> [--explain-policy-column <col>]: Explain access control decisions in structured JSON.
  • Granular Access Policy Engine (--policy / SQLITE_GUARD_POLICY): Fail-closed TOML access rules for table/column allow & deny lists, custom sensitive column masking, and feature toggles.
  • Tamper-evident Audit Logging (--audit-log / SQLITE_GUARD_AUDIT_LOG): Structured JSON Lines logging with SHA-256 query fingerprinting and privacy-safe metadata.
  • Native SQLite authorizer strictly denies write operations, database attachments, dangerous functions (load_extension, readfile, writefile, fsdir, eval, etc.), and unapproved PRAGMAs.
  • Database path introspection is blocked: PRAGMA database_list and pragma_database_list table-valued queries are denied at the authorizer boundary.
  • Schema DDL definitions in sqlite_schema / sqlite_master have their sql column masked as NULL to prevent secret leakage through CREATE TABLE defaults and check constraints.
  • Sensitive credential columns (password, api_key, access_key, secret, private_key, credit_card, etc.) are masked as NULL at SQLite's authorizer boundary.
  • Sensitive default values in table metadata (describe_database_table and schema://summary) are redacted (default_redacted: true, dflt_value: null) while safe defaults are preserved.
  • Usage token metrics (prompt_tokens, completion_tokens, total_tokens, etc.) are explicitly preserved.
  • Hard resource bounds: query timeout, SQLite VM-step budget, row cap, column cap, text cell length cap, aggregate parameter byte/count caps, and total response byte size cap.
  • BLOB values are returned as bounded Base64 previews rather than raw byte dumps.

Requirements

  • Python 3.11 or newer.
  • The package installs the official mcp SDK 2.x and pydantic automatically.
  • An existing SQLite database file readable by the current operating-system account.

Install from source

git clone https://github.com/AtharvaSiddhawar/sqlite-guard-mcp.git
cd sqlite-guard-mcp
python -m pip install .

For development:

python -m pip install -e ".[dev]"
ruff check .
ruff format --check .
pytest --cov --cov-report=term-missing
python -m build

Run

sqlite-guard-mcp --db "/absolute/path/to/database.sqlite"

Optional limits, policy, audit, and transport flags:

sqlite-guard-mcp --db "/path/to/database.sqlite" \
  --max-rows 250 \
  --timeout 2.0 \
  --max-vm-steps 250000 \
  --policy "/path/to/policy.toml" \
  --audit-log "/path/to/audit.jsonl" \
  --transport streamable-http \
  --host 127.0.0.1 \
  --port 8000 \
  --auth-token "your-bearer-secret"

You can also set environment variables:

  • SQLITE_GUARD_DB: Path to database file.
  • SQLITE_GUARD_POLICY: Path to TOML policy file.
  • SQLITE_GUARD_AUDIT_LOG: Path to JSONL audit log file.
  • SQLITE_GUARD_AUTH_TOKEN: Bearer token for HTTP/SSE transports.

Check version with sqlite-guard-mcp --version.

Access Policy (TOML)

Fine-grained access control can be specified in a TOML policy file:

[tables]
allow = ["customers", "orders", "products"]
deny = ["admin_users", "internal_migrations"]

[columns]
allow = ["customers.id", "customers.name", "customers.created_at"]
deny = ["*.internal_notes", "orders.margin"]

[privacy]
sensitive_columns = ["ssn_custom", "secret_pin", "tax_identifier"]

[features]
allow_explain_query = true
allow_schema_search = true
allow_health_check = true

Tools

Tool Purpose
read_query(sql, params?) Run one read-only SELECT, WITH, or VALUES query with bound parameters.
list_database_tables() List user-defined tables and views.
describe_database_table(table_name) Inspect columns, types, primary keys, indexes, foreign keys, unindexed FKs, and index overlap.
explain_read_query(sql, params?) Run EXPLAIN QUERY PLAN with structured observations and confidence scoring.
get_database_overview() Get safe database metrics: schema version, page size, page count, table/index/view counts.
search_database_schema(query, max_matches?) Search table names, column names, view names, and index names case-insensitively.
check_database_health() Run quick integrity check, check foreign key integrity, and report redundant indexes.
simulate_candidate_index(sql, candidate_indexes, params?) Index Laboratory: Test candidate indexes on isolated in-memory clone and measure latency/plan diff.
profile_database_table(table_name, max_sample_rows?) Privacy-preserving profiling: null ratios, cardinality, distinct counts, safe min/max, masking.
diff_database_schemas(target_db_path) Compare current schema against another database file to detect added, removed, or modified objects.
review_migration_script(migration_sql) Statically inspect migration SQL for risk, table drops, locks, and missing transactions.

params accepts a JSON object for named parameters or an array for positional parameters. Example: {"sql":"SELECT name FROM people WHERE id = ?","params":[7]}.

Resources

Resource URI Purpose
schema://summary Provides a complete JSON summary of all tables, views, and columns without requiring multiple tool calls.
schema://snapshot Provides a complete canonical JSON snapshot of all tables, columns, indexes, and foreign keys.

Masking behavior

The authorizer masks common credential and secret columns such as password, passwd, pwd, secret, api_key, access_key, auth_key, private_key, client_secret, ssn, social_security, credit_card, card_number, cvv, bank_account, and session tokens.

Common usage metrics such as prompt_tokens, completion_tokens, input_tokens, output_tokens, and total_tokens are intentionally not masked. These rules are name-based heuristics: review your schema and do not rely on them as an absolute data-loss-prevention system.

Limits and behavior

  • SELECT, WITH, and VALUES queries are accepted; mutations and write CTEs are rejected.
  • explain_read_query accepts read-only queries and prepends EXPLAIN QUERY PLAN safely.
  • The default row limit is 250, with a hard limit of 1,000.
  • Query execution is strictly bounded by wall-clock timeout and SQLite VM-step budget.
  • Text cells (4 KB max), BLOB previews (4 KB max), columns (100 max), and total serialized response size (1 MB max) are capped.
  • Multiple SQL statements in one call are rejected by SQLite's single-statement execution boundary.

Skill instructions

The agent-facing usage guide is in SKILL.md.

License

MIT. See LICENSE.

Metadata

Release files for sqlite-guard-mcp 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlite-guard-mcp 0.2.4
File Size Uploaded Provenance Actions
sqlite_guard_mcp-0.2.4.tar.gz 63.0 kB With provenance Details for sqlite_guard_mcp-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlite-guard-mcp 0.2.4
File Interpreter ABI Platform Actions
sqlite_guard_mcp-0.2.4-py3-none-any.whl Python 3 none any Details for sqlite_guard_mcp-0.2.4-py3-none-any.whl

Total release size: 106.3 kB

Release files / sqlite_guard_mcp-0.2.4.tar.gz

Download URL sqlite_guard_mcp-0.2.4.tar.gz
Size 63.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6108302e954683e161c512aacc8f35911085ec49f52fc79f9a6ea1834b11dc5c
BLAKE2b-256 checksum
How to use checksums
4bb1b9c1a415ccea7178f4163004b89cebc2ee802181bd173f5edc1525ceb882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / sqlite_guard_mcp-0.2.4-py3-none-any.whl

Download URL sqlite_guard_mcp-0.2.4-py3-none-any.whl
Size 43.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1537a3867c4f0a33610583fc1a525ecaaddb90fb94a7edbf82ec91a52392d919
BLAKE2b-256 checksum
How to use checksums
6355374411780d14aa60c1d42e4bafcb6201a849e1b58b4b5188515d816029e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for sqlite-guard-mcp 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sqlite_guard_mcp-0.2.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page