Skip to main content
Glama

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

validate_sql

Validates a statement against your schema → safe / review / blocked verdict, issue codes, fix suggestions, plain-English explanation

explain_sql

Explains what a statement does in plain English (no verdict — for understanding before deciding)

guard_query

Pre-execution go/no-go hook → allow / review / block with a human-readable reason

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/presql

That 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/presql

Schema 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/UPDATE without WHERE → blocked

  • DESTRUCTIVE_UNBOUNDED — DROP, TRUNCATE → blocked

  • UNKNOWN_TABLE / UNKNOWN_COLUMN — with Levenshtein did-you-mean suggestions

  • TYPE_MISMATCH, AMBIGUOUS_COLUMN, IMPLICIT_CROSS_JOIN, CROSS_JOIN

  • PII_ACCESS — flags selects over PII-ish columns (name-heuristic)

  • SELECT_STAR, MISSING_LIMIT — hygiene nudges

  • PARSE_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 / sqlite parse 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 stdio

The 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 tools
explain_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

    A3.8/5.0

    Scored across 3 tools

    Disambiguation3/5

    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.

    Naming Consistency5/5

    All three tools follow a clean verb_noun snake_case pattern (validate_sql, explain_sql, guard_query) with no mixing of conventions.

    Tool Count4/5

    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.

    Completeness4/5

    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

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enforces safety and governance for SQL queries executed by AI agents, providing read-only enforcement, cost estimation, and audit trails.
      Apache 2.0
    • A
      license
      A
      quality
      C
      maintenance
      Enables 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.
      9
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables 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
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables 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