Skip to main content
Glama
egoring

sql-guard-mcp

by egoring

sql-guard-mcp

CI

Read-only SQL for AI agents, with layered safety guards.

Giving an LLM agent raw database access is a footgun. This MCP server opens a SQLite database to agents through four independent guard layers, so the worst an agent can do is read too slowly — and even that gets cut off.

한국어 문서: README.ko.md

Guard layers

Layer

What it stops

How

Query validation

Writes, schema changes, injection via stacked statements

Only single SELECT/WITH statements; forbidden-keyword scan (INSERT, DROP, PRAGMA, ATTACH, ...); multi-statement rejection

Table allowlist

Reading sensitive tables (PII, credentials)

FROM/JOIN identifiers checked against SQLGUARD_ALLOWED_TABLES; also filters list_tables/describe_table

Row cap

Context-window flooding

Every query is wrapped as a subquery with a server-side LIMIT — a user-supplied LIMIT 999999 cannot override it; truncation is flagged

Execution cap

Runaway queries (cartesian joins)

SQLite progress-handler watchdog aborts after N VM steps with an actionable message

OS-level read-only

Everything above failing

Connection opened with mode=ro — the last line of defense, enforced by SQLite itself

The design principle comes from building decision guards for a production LLM agent: don't trust the model to be careful — make carelessness impossible, and make every rejection message tell the agent what to do instead.

Related MCP server: sqlite-analyst

Tools

  • sql_list_tables — visible tables (allowlist applied)

  • sql_describe_table — columns, types, row count

  • sql_query — guarded read-only query

  • sql_guard_status — current guard configuration (transparency for debugging)

Demo

Connected to Claude Desktop, querying the bundled ad-campaign demo DB — and refusing a delete request:

sql-guard-mcp demo: CTR ranking answered, DELETE request refused

The agent freely explores and aggregates ("Which active campaign has the best CTR?"), but when asked to wipe the campaigns table, the guard rejects it and the agent explains why — read-only by design, enforced in code, not by prompt.

Setup

Zero dependencies beyond the MCP SDK — a synthetic ad-campaign demo DB is bundled and auto-created on first run.

pip install -e .

# optional configuration
export SQLGUARD_DB="/path/to/your.db"                      # default: bundled demo
export SQLGUARD_ALLOWED_TABLES="campaigns,daily_stats"     # default: all tables
export SQLGUARD_MAX_ROWS="200"

Claude Desktop

{
  "mcpServers": {
    "sql-guard-mcp": {
      "command": "sql-guard-mcp",
      "env": { "SQLGUARD_ALLOWED_TABLES": "campaigns,daily_stats" }
    }
  }
}

Then ask: "Which active campaign had the best CTR last week?" — the agent explores the schema and queries within the guardrails. Try asking it to delete something; read the refusal.

Test

pip install -e ".[dev]"
pytest   # guard validation + execution enforcement, no external DB needed

Tests include the adversarial cases: stacked statements, SELECT-prefixed writes, allowlist bypass via JOIN, user-supplied LIMIT override attempts, and a cartesian-join runaway aborted by the VM-step watchdog.

License

MIT

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI assistants to explore and query SQLite databases through read-only tools, with defense-in-depth sandboxing preventing any data modifications.
    MIT
  • F
    license
    A
    quality
    C
    maintenance
    Enables AI agents to safely explore and query a SQLite database in read-only mode, allowing them to inspect schema and run analytical SQL queries without risking data modification.
    3

View all related MCP servers

Related MCP Connectors

  • Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…

  • Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.

  • Read-only bank access for your AI agent. Connects Claude, ChatGPT, Cursor, Gemini, Codex.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/egoring/sql-guard-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server