PreSQL
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PreSQL Check if DELETE FROM orders; is safe to run"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PreSQL — a seatbelt for AI-generated SQL
An MCP server that validates SQL before it runs. Give it your schema; it gives your agents three tools:
Tool | What it does |
| Validates a statement against your schema → |
| Explains what a statement does in plain English (no verdict — for understanding before deciding) |
| Pre-execution go/no-go hook → |
Database MCP servers give agents access. PreSQL checks the SQL before it goes in. It composes with any of them — point your agent at both.
Zero network at runtime. Zero config to try. MIT licensed.
Quickstart
npx -y @k1sh0r3/presqlThat runs with a built-in demo e-commerce schema. To use your own:
npx -y @k1sh0r3/presql --schema ./schema.sql
# or
SQL_GUARD_SCHEMA=./schema.sql npx -y @k1sh0r3/presql
# or inline DDL:
SQL_GUARD_DDL="CREATE TABLE users (id INT, email VARCHAR(255));" npx -y @k1sh0r3/presqlSchema resolution order: --schema flag → SQL_GUARD_SCHEMA env → SQL_GUARD_DDL env → demo/schema.sql → built-in demo schema.
Related MCP server: Anumana
Connect your agent
Claude Desktop (claude_desktop_config.json) or Cursor:
{
"mcpServers": {
"presql": {
"command": "npx",
"args": ["-y", "@k1sh0r3/presql", "--schema", "/path/to/schema.sql"]
}
}
}Then: "Before running any SQL against the database, check it with presql's guard_query."
What it catches
Schema-aware validation powered by the SQL Sentinel engine (13 check codes):
DESTRUCTIVE_NO_WHERE—DELETE/UPDATEwithoutWHERE→ blockedDESTRUCTIVE_UNBOUNDED—DROP,TRUNCATE→ blockedUNKNOWN_TABLE/UNKNOWN_COLUMN— with Levenshtein did-you-mean suggestionsTYPE_MISMATCH,AMBIGUOUS_COLUMN,IMPLICIT_CROSS_JOIN,CROSS_JOINPII_ACCESS— flags selects over PII-ish columns (name-heuristic)SELECT_STAR,MISSING_LIMIT— hygiene nudgesPARSE_ERROR,SCHEMA_MISSING,MULTI_STATEMENT— honest meta-checks
Example:
> validate_sql("DELETE FROM orders;")
{
"verdict": "blocked",
"issues": [{
"code": "DESTRUCTIVE_NO_WHERE",
"severity": "error",
"message": "DELETE without WHERE affects every row in the table.",
"suggestion": "Add a WHERE clause — or run a SELECT with the same filter first to preview the blast radius."
}],
"explanation": "Deletes EVERY row from orders."
}Honest limits
Static analysis only. It can't know row counts or see your data.
CTE/subquery output columns are skipped, not faked — where certainty is impossible, it says so.
PII detection is name-heuristic only (column named
email≈ PII). Not a compliance tool on its own.One statement per call. Multi-statement input validates the first statement and warns (
MULTI_STATEMENT).AST-evasion hardening (quoted/unicode-escaped identifier tricks, cf. AWS's pglast guard) is a v1.1 target — not claimed as solved.
English error messages;
postgres/mysql/sqliteparse dialects.
Development
npm install
npm run build # tsc → dist/
npm test # build + node --test (41 tests: 30 engine + 11 MCP protocol)
npm start # run the server over stdioThe validator (src/vendor/validator.js) and SQL parser (src/vendor/node-sql-parser.umd.js) are copied verbatim from SQL Sentinel — the engine is shared, not forked.
License
MIT — see LICENSE.
Available Tools
3 toolsexplain_sqlA
Explain a SQL statement in plain English. No verdict, no judgment — for understanding what a query does before deciding whether to run it.
Inputs: sql (required), dialect.
guard_queryA
Pre-execution safety hook for AI-generated SQL. Returns a go/no-go decision (allow/review/block) with a human-readable reason and the underlying verdict. Designed to be called before handing SQL to a database MCP server or executing it.
Inputs: sql (required), dialect.
validate_sqlA
Validate a SQL statement against the configured schema. Returns a verdict (safe/review/blocked), a list of issues with codes, severities, messages and fix suggestions, plus a plain-English explanation. Call this before executing AI-generated SQL.
Inputs: sql (required), dialect.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
validate_sql and guard_query overlap heavily: both return a safety verdict (safe/review/blocked vs allow/review/block) with reasons, differing mainly in framing. explain_sql is clearly distinct (no judgment), but an agent could easily struggle to choose between validate and guard.
All three tools follow a clean verb_noun snake_case pattern (validate_sql, explain_sql, guard_query) with no mixing of conventions.
Three tools is well-scoped for a focused SQL safety server, though the overlap between validate_sql and guard_query makes one of them feel somewhat redundant rather than each earning a distinct place.
The domain (pre-execution SQL validation and understanding) is largely covered: validate, explain, and guard. Coverage is adequate, though the surface is thin and could benefit from e.g. schema-aware fix application or batch validation.
Maintenance
Related MCP Connectors
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
SQL validation, formatting, parsing, metadata extraction, linting, and security analysis.
Governed SQL access to your databases: redaction, query review and an audit log.
Review your AI agent's database changes on your schema, with plain-language risk, before they run.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnforces safety and governance for SQL queries executed by AI agents, providing read-only enforcement, cost estimation, and audit trails.Apache 2.0
- AlicenseAqualityCmaintenanceEnables AI coding agents to preflight SQL, NoSQL, graph, warehouse, and vector queries against real schemas or pasted DDL, estimating cost/risk, suggesting verified rewrites, and explaining plans before execution. It supports 12 database engines and catches costly query patterns without running the query.9MIT
- AlicenseNot gradedqualityCmaintenanceEnables 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
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely explore and query SQL databases through read-only, AST-checked SQL, database-enforced read-only transactions, timeouts, row caps, PII masking, and audit logging.MIT