schema-gate
Checks Django ORM Model.objects...update() and .delete() writes against schema-boundary rules.
Checks Drizzle db.update().set() and db.delete() calls against schema-boundary rules.
Checks Prisma model mutations such as update, updateMany, upsert, delete, and deleteMany against schema-boundary rules.
Checks SQLAlchemy update/delete operations and query(Model).update() writes against schema-boundary rules.
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.
schema-gate
Fail-Closed Schema-Boundary Contract Gate for AI Coding Agents
(Zero-dependency Python 3 library, CLI, Claude Code Hook, MCP stdio server, SARIF CI gate & Runtime DB-API SQL Proxy)
Why AGENTS.md and Import Linters Are Not Enough
Your CI blocks risk from importing auth. Your AGENTS.md politely tells AI coding agents not to couple domains. Then an agent gets a sprint ticket "freeze high-risk users" and writes:
UPDATE users SET status = 'risk_locked' WHERE id = :entity_idZero forbidden imports. Unit tests pass. Yet this single line breaks three architectural invariants at once:
Concept Compression (
G2) — stuffs fraud-risk state intoauth's account-lifecycle column;Foreign-Writer Coupling (
G3) — mutates a table column owned by another module behind its back;Domain Pollution (
G5) — injects an undeclared magic string'risk_locked'that silently breaks downstreambilling/fulfillmentswitch statements.
Or an agent inside billing runs an in-place UPDATE payment_intents SET intent_state = 'reconciled' on an AppendOnlyFact audit table (G4), permanently erasing intent history so cross-system reconciliation becomes mathematically impossible.
In controlled live coding-agent trials (120 symmetric trials on the original 40-task suite), both AGENTS.md soft rules and executable import linters allowed 73.33% (22/30) of unsafe schema-boundary mutations. SchemaGate cut unsafe deliveries to 0.00% (0/30) ($p = 4.77 \times 10^{-7}$), drove 100% (20/20) single-turn agent self-repair via structured diagnostics, had 0/10 false blocks, and ran in ~1.08 ms at 4,096 contracted columns.
In a strictly disjoint cross-vendor, multi-language external holdout (5 unseen domains × Python & TypeScript/Prisma × Claude Sonnet 5.5, Kimi K3, DeepSeek Chat = 180 arm evaluations), AGENTS.md and import linters still let 62.22% (28/45) of unsafe patches slip through (Claude 86.7%, Kimi 80.0%, DeepSeek 20.0%; Python 58.3%, TypeScript/Prisma 66.7%). SchemaGate cut unsafe deliveries to 0.00% (0/45) ($p = 7.45 \times 10^{-9}$), achieved 100% (28/28) 1-turn auto-repair across all three vendors and both languages, with 0/15 false blocks.
Related MCP server: sqlproctor
Five Enforced Invariants (G1–G5)
Formally verified in Isabelle/HOL 2026 (session RC_SchemaBoundary, zero sorry):
Gate | Invariant | What It Blocks |
G1 | Syntactic Import Compliance | Forbidden cross-module |
G2 | Concept Decompression | Overloading one column with multiple domain concepts |
G3 | Single-Writer Ownership | Foreign modules writing to a column owned by another module |
G4 | Append-Only History Integrity | Destructive |
G5 | Domain Closure | Writing undeclared sentinel/magic tags outside a column's |
Supported Languages & Surfaces
Python (
.py): AST imports, raw & parameterized SQL (:name,%(name)s,%s,?,$1), f-strings / string concat, SQLAlchemy (update(Table).values(...),delete(Table),query(Model).update(...)), Django ORM (Model.objects...update(...),.delete()), attribute/subscript writes (user.status = ...).TypeScript / JavaScript (
.ts,.tsx,.js,.mjs,.cjs): ES/CJS imports, raw SQL strings & template literals, Prisma (prisma.<model>.update/updateMany/upsert/delete/deleteMany), Drizzle (db.update(tbl).set(...),db.delete(tbl)).SQL Migrations (
.sql):UPDATE,DELETE,REPLACE,INSERT,ALTER TABLE ... DROP COLUMN.Runtime DB-API 2.0 SQL Proxy:
wrap_dbapi_connection(conn, contract, module_name)intercepts dynamically constructed SQL at test/staging runtime using the exact sameschema-contract.json.
Installation
Zero third-party dependencies (Python 3.10+ stdlib only):
pip install schema-boundary-gateOr from source:
pip install -e .Quickstart
1. CLI & CI Gate (Text / JSON / SARIF)
# Generate starter schema-contract.json
schema-gate init
# Check repository (exit 0 on PASS, exit 2 on BLOCK with repair hints)
schema-gate check --contract schema-contract.json src/
# Check only staged git files or PR diff against main
schema-gate check --contract schema-contract.json --staged
schema-gate check --contract schema-contract.json --diff origin/main --format sarifRun the interactive multi-language + runtime-proxy demo:
bash examples/demo.sh2. Claude Code PreToolUse Hook (1-Turn Auto-Repair)
Add to .claude/settings.json (see examples/claude-code-settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "schema-gate hook claude-code --contract schema-contract.json"
}
]
}
]
}
}When Claude Code attempts a shortcut mutation, schema-gate exits 2 before disk write with exact rule codes and repair hints so the agent automatically decompresses the write into an owned column on the next turn.
3. MCP Stdio Server (Claude Code / Cursor / Any MCP Agent)
{
"mcpServers": {
"schema-gate": {
"command": "schema-gate",
"args": ["mcp", "--contract", "schema-contract.json"]
}
}
}Exposed MCP tools:
schema_gate_inspect_contract— inspect table owners, concepts, append-only tables, and allowed enum tags before codingschema_gate_check_patch— dry-run check a Python / TypeScript / SQL patch against G1–G5schema_gate_check_files— scan files or directoriesschema_gate_validate_sql— check a raw SQL statement + parameters
4. Runtime SQL Proxy (Dynamic SQL Protection in Tests)
import sqlite3
from schema_gate import SchemaContract, wrap_dbapi_connection
contract = SchemaContract.from_json_file("schema-contract.json")
conn = wrap_dbapi_connection(sqlite3.connect(":memory:"), contract, module_name="risk")
# Any dynamic SQL violating G2-G5 raises SchemaBoundaryViolationError before execution!5. Pre-commit Hook
repos:
- repo: https://github.com/iannil/schema-gate
rev: v0.1.0
hooks:
- id: schema-gateRunning Tests
python3 -m unittest discover -s tests -vPaper & Formal Proofs
Paper: Tao Shi (Zhurong), Data as the Boundary: Schema-Boundary Contract Gates Against Silent Semantic Coupling in AI Coding Agents, https://zhurongshuo.com/en/papers/schema-boundary-gate/
Isabelle/HOL 2026 Proofs (
RC_SchemaBoundary, zerosorry) & Benchmark Archive (Zenodo): 10.5281/zenodo.24459632
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
Review your AI agent's database changes on your schema, with plain-language risk, before they run.
Enforces architectural invariants and code quality rules inside your AI agent's edit loop.
AI agents propose database changes as reviewable requests — no direct write access.
Security reviews for coding agents: diffs checked against your org policy and live infrastructure.
Related MCP Servers
AlicenseNot gradedqualityCmaintenanceEnables AI agents to query architecture context, data contracts, and blast radius to prevent cross-repo architectural breakage before merging.22Apache 2.0- AlicenseNot gradedqualityCmaintenanceEnables deterministic semantic verification of agent-generated SQL queries against a git-versioned contract, blocking incorrect queries and returning structured feedback for self-correction.MIT
- AlicenseDqualityBmaintenanceEnables AI agents to inspect, draft, validate, and locally verify contract changes against frozen policies, with separate input and output roots and no approval or verified-signing capability.10MIT
- AlicenseNot gradedqualityBmaintenanceEnables agents to inspect dbt model semantics, retrieve contracts and lineage, and verify that edits do not change what models mean.Apache 2.0