Safe SQL gateway for AI agents: SELECT-only validation, access policies, masking, audit trail, evals
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
Eval-driven SQL reliability for AI agents.
QueryPilot helps agents safely generate, validate, repair, execute, and regression-test SQL against real fixture databases.
Read-only SQL access for agents is becoming a commodity. Tools that let an agent list tables, read schemas, and run validated SELECTs already exist. What is much harder β and what QueryPilot focuses on β is making that access measurably reliable: proving the SQL the agent generates is correct, safe, fast, and not regressing.
Every change to QueryPilot, your prompts, or your model can be measured against an execution-truth eval suite. Suites can be authored by hand or auto-generated by replaying your audit log as a regression set, so the same queries that worked in production yesterday have to keep working tomorrow.
Sample output (abridged β see the full report at the top of this README):
The bundled suites/smoke.yaml runs against a tiny SQLite fixture (tests/fixtures/demo.db) so the harness works end-to-end without an LLM key. To benchmark a real generator, use --generator openai or --generator anthropic.
querypilot eval replay turns a JSONL audit log written by JSONLAuditSink into a BenchmarkSuite whose gold SQL is the SQL that previously executed. Re-running that suite gates accuracy regressions against your own production traffic β the unique-to-QueryPilot capability the eval positioning rests on.
Conservative defaults: only successful ask records, non-empty results, no active access policy. --include-failures, --include-masked, --include-empty relax each filter.
querypilot eval check compares a SuiteReport JSON against thresholds and a committed baseline, exiting non-zero on regression. A sample GitHub Actions workflow ships at .github/workflows/eval.yml:
When a regression is detected the output explains which cases regressed and how:
Refresh the baseline on main after a deliberate change:
Suites are YAML or JSON. Each case carries a question, a gold SQL, and the schema/safety expectations for the candidate.
Result-set correctness is scored by executing both the gold and candidate SQL against the same fixture database and comparing rows. Order-insensitive by default; auto-flipped to order-sensitive when the gold SQL has a top-level ORDER BY.
Natural-language ask() works offline for simple demo questions through a deterministic generator:
Runnable, self-contained examples live in examples/. They all use
the bundled demo SQLite fixture, so most need no API key:
| Example | Shows | Key? |
|---|---|---|
01_quickstart.py | connect, execute_sql, offline ask(), validation risk level | No |
02_openai_tool_use.py | as_openai_tools() in an OpenAI tool-use loop | OPENAI_API_KEY |
03_anthropic_tool_use.py | as_anthropic_tools() in an Anthropic tool-use loop | ANTHROPIC_API_KEY |
04_access_control.py | blocked columns, row filter, and masking | No |
05_custom_eval_suite/ | a custom YAML suite run with querypilot eval run/check | No |
06_mcp/ | run querypilot mcp + a paste-ready Claude MCP config | No |
See examples/README.md for setup and the full index.
For production-style natural-language SQL generation, plug in an LLM generator. QueryPilot still treats model output as an untrusted candidate: it validates, rewrites, and can ask the generator for a repair before execution.
Install optional provider dependencies:
OpenAI:
Anthropic:
Any OpenAI-compatible endpoint β Ollama, vLLM, LM Studio,
or llama.cpp's server β works through OpenAICompatibleSQLGenerator. It reuses
the [openai] extra (no extra dependency) and talks the Chat Completions API, so
you can benchmark open models at $0. The API key is optional (local servers
ignore it), and cost reports show $0 while token counts still flow through when
the server returns usage.
From the eval harness, add open models to the benchmark matrix with
--generator openai-compatible:
--base-url also reads $QUERYPILOT_BASE_URL, and defaults to Ollama's
http://localhost:11434/v1 when unset.
The safety loop is always:
The CLI is a thin wrapper around run_suite, which is also usable directly:
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/querypilot)<a href="https://allmcps.com/mcp/querypilot"><img src="https://allmcps.com/api/badge/querypilot?style=directory" alt="QueryPilot on AllMCPs" /></a>