SQL Guardian MCP
Supports Databricks model serving as an OpenAI-compatible endpoint for natural-language SQL generation.
Supports local OpenAI-compatible Ollama endpoints for natural-language SQL generation.
Supports using an OpenAI-compatible API endpoint to translate natural-language questions into SQL, with validation and a self-repair loop for rejected queries.
Provides read-only, guarded SQL access to a SQLite database, including listing tables, describing schemas, and running policy-constrained SELECT queries with row limits and timeouts.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
SQL Guardian MCP
Read-only, guarded SQL access for AI agents, served over the Model Context Protocol (MCP).
LLM agents are good at writing SQL, but a query written by a model is untrusted input. SQL Guardian sits between an agent and a database. It lets agents explore and query data while making writes, data leaks and runaway queries impossible by construction.
MCP client (Claude Desktop, Cursor, VS Code agent, custom agent)
│ list_tables / describe_schema / run_query / ask_database
▼
┌──────────────── SQL Guardian ────────────────┐
│ 1. single-statement check │
│ 2. SQLite authorizer: SELECT/READ only, │
│ table allow-list, column block-list, │
│ blocked functions, no system tables │
│ 3. read-only connection (mode=ro, query_only)│
│ 4. row cap + wall-clock timeout │
│ 5. bound parameters, never string-building │
└──────────────────────────────────────────────┘
▼
SQLite databaseWhy the guardrails don't rely on regex
Most "safe SQL" filters pattern-match keywords like DROP or DELETE, and they're easy to bypass. SQL Guardian asks the database engine instead. Every statement is compiled with EXPLAIN while a SQLite authorizer callback inspects each action the engine would perform. Anything other than reading an allowed table is denied before a single row is touched. The connection is also opened read-only at the file level, so even a bug in the policy can't write.
Related MCP server: PgSafe MCP
Features
MCP server with four tools:
list_tables,describe_schema,run_query, andask_database. The last one appears when an LLM is configured.Natural language → SQL with self-repair. If a generated query is rejected, the rejection reason goes back to the model so it can fix its own query, for up to 3 attempts.
Policy controls: a table allow-list, a sensitive-column block-list, a row cap and a timeout.
Works with any OpenAI-compatible endpoint (OpenAI, Databricks model serving, vLLM, Ollama) using only the standard library.
21 tests covering injection attempts, stacked statements, writes, PRAGMA/ATTACH, system tables, timeouts and the repair loop.
Quick start
git clone https://github.com/<you>/sql-guardian-mcp && cd sql-guardian-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
python examples/seed_demo_db.py # creates examples/demo.db
pytest -q # 21 passedRun the server (the salaries table and customer emails stay hidden):
python -m sql_guardian.server --db examples/demo.db \
--tables customers,products,orders --block-columns customers.emailTurn on natural-language questions by setting an OpenAI-compatible endpoint:
export OPENAI_API_KEY=... # or a dummy value for Ollama
export OPENAI_BASE_URL=http://localhost:11434/v1 # optional, e.g. Ollama
export LLM_MODEL=llama3.1 # optionalUse it from Claude Desktop or another MCP client
{
"mcpServers": {
"sql-guardian": {
"command": "python",
"args": ["-m", "sql_guardian.server", "--db", "/abs/path/examples/demo.db",
"--tables", "customers,products,orders"]
}
}
}Use it as a library
from sql_guardian import SqlGuard, GuardPolicy, GuardError
guard = SqlGuard("examples/demo.db", GuardPolicy(allowed_tables={"orders", "products"}, max_rows=100))
guard.run("SELECT category, SUM(price) FROM products GROUP BY category")
guard.run("SELECT * FROM orders WHERE customer_id = ?", (42,)) # parameters are bound
guard.run("DELETE FROM orders") # -> GuardError: Query rejected: operation not permittedProject layout
sql_guardian/
guard.py # authorizer-based validation + guarded execution
nl2sql.py # NL → SQL with validate-and-repair loop
llm.py # dependency-free OpenAI-compatible client + scripted test client
server.py # MCP server (stdio or streamable HTTP)
examples/seed_demo_db.py
tests/Roadmap
Postgres and Databricks SQL backends, using
EXPLAINplans plus read-only rolesQuery-cost estimates before execution
An audit log of every query an agent runs
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
The all-in-one data stack for agents. Upload files, run SQL, evolve tables, and render charts.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely query and explore SQLite databases through read-only, guard-protected tools that block writes, sensitive table access, and runaway queries.1MIT
- AlicenseAqualityBmaintenanceEnables AI agents to inspect database schemas and run strictly read-only SQL queries with guardrails against destructive statements, multi-statement chaining, and unbounded scans. Supports SQLite natively and PostgreSQL optionally.4137 PyPIMIT
- AlicenseAqualityCmaintenanceEnables AI agents to explore and query SQLite databases through read-only, sandboxed tools for listing tables, describing schemas, fetching DDL, and running a single capped SELECT statement. Also supports plain-English questions that are converted to SQL and routed through the same sandbox.4MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely explore and query SQLite or PostgreSQL databases through read-only, guarded SELECT queries with column masking, row limits, timeouts, and audit logging.MIT