zerolock-mcp
# `zerolock-mcp` — PostgreSQL & MySQL Zero-Downtime DDL Migration Lock Auditor (MCP Server + CLI + GitHub Action)
[](https://glama.ai/mcp/servers/z121245017-ai/zerolock-mcp)
Zero-dependency, 100% offline **Model Context Protocol (`MCP`) Server**, **CLI**, and **`node20` GitHub Action** enabling AI coding agents (Claude Desktop, Cursor, Windsurf, Antigravity) and pull-request CI pipelines to catch catastrophic PostgreSQL (`14–17`) and MySQL (`8.0` / `8.4`) `ACCESS EXCLUSIVE` lock queues, full table rewrites, non-concurrent index builds, unvalidated foreign keys, and missing `lock_timeout` guards before deployment.
## Why Production Migrations Fail in Seconds
1. **FIFO `ACCESS EXCLUSIVE` Lock Queue Pileups**: Even a 5ms `ALTER TABLE` without `SET LOCAL lock_timeout = '2s'` waiting behind one active slow query forms a lock queue that blocks **100% of subsequent `SELECT` and `INSERT` queries**, exhausting connection pools immediately.
2. **ORM Default Migrations Block Writes or Abort at Runtime**: Prisma, Drizzle, Flyway, and Alembic frequently emit synchronous `CREATE INDEX` (without `CONCURRENTLY`), wrap `CONCURRENTLY` inside `BEGIN...COMMIT`, add volatile defaults (`DEFAULT gen_random_uuid()`), rewrite 20M+ rows on `ALTER COLUMN TYPE`, scan full tables under `SET NOT NULL`, or omit MySQL `ALGORITHM=INPLACE, LOCK=NONE`.
## MCP Tools Exposed (`stdio` — NDJSON & `Content-Length`)
| Tool | Purpose | Safety Annotations |
| :--- | :--- | :--- |
| `audit_sql_migration_locks` | Audits PostgreSQL 14–17 & MySQL 8.0 DDL statements across 16 deterministic lock-queue and table-rewrite rules while honoring fast-path metadata exceptions (`PG 11+` constant defaults, `varchar -> text` widening, pre-validated `CHECK` before `SET NOT NULL`). | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
| `generate_zero_downtime_ddl` | Rewrites hazardous SQL migrations into multi-phase **Phase 1 (Expand / `CONCURRENTLY` / `NOT VALID` / `ALGORITHM=INSTANT`)**, **Phase 2 (`VALIDATE CONSTRAINT` / Contract)**, and **Emergency Rollback** scripts. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
| `estimate_ddl_blast_radius` | Estimates lock duration in seconds, connection-pool exhaustion risk, and blocked `SELECT` / `WRITE` query counts given row count and production QPS. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
| `audit_migration_directory` | Recursively scans Prisma (`prisma/migrations`), Drizzle (`drizzle`), Flyway (`sql`), or raw `.sql` migration directories for deployment hazards. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
## Quick Start (MCP Client & Local CLI)
```bash
# Start MCP server over stdio (supports both NDJSON and LSP Content-Length framing)
npx -y github:z121245017-ai/zerolock-mcp
# List MCP tool schemas
npx -y github:z121245017-ai/zerolock-mcp --list
# Scan a Prisma or Flyway migration directory directly from terminal
npx -y github:z121245017-ai/zerolock-mcp --scan ./prisma/migrations
# Generate a zero-downtime Expand/Contract rewrite from CLI
npx -y github:z121245017-ai/zerolock-mcp --cli generate_zero_downtime_ddl '{"sql":"CREATE INDEX idx_orders_user ON orders (user_id);"}'
```
### Claude Desktop / Cursor / Windsurf / Antigravity Config
```json
{
"mcpServers": {
"zerolock": {
"command": "npx",
"args": ["-y", "github:z121245017-ai/zerolock-mcp"]
}
}
}
```
### Docker (`node:22-alpine`, non-root `USER node`)
```bash
docker build -t zerolock-mcp .
docker run -i --rm zerolock-mcp
```
## GitHub Action (`z121245017-ai/zerolock-mcp@v1`)
Block `CRITICAL` database lock-queue and table-rewrite hazards in pull requests with inline `::error` annotations on exact SQL lines plus a Markdown Step Summary:
```yaml
name: ZeroLock SQL Migration Gate
on:
pull_request:
paths:
- 'prisma/migrations/**'
- 'drizzle/**'
- 'migrations/**'
- '**/*.sql'
permissions:
contents: read
jobs:
sql-lock-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Audit SQL migrations for production lockouts
uses: z121245017-ai/zerolock-mcp@v1
with:
paths: 'prisma/migrations'
dialect: 'pg'
table-rows: '15000000'
qps: '1200'
fail-on-critical: 'true'
fail-on-high: 'false'
```
### Action Inputs & Outputs
| Name | Kind | Default | Description |
| :--- | :--- | :--- | :--- |
| `paths` | Input | `.` | Newline- or comma-separated `.sql` files or migration directories to scan. |
| `dialect` | Input | `auto` | SQL dialect override (`auto`, `pg`, or `mysql`). |
| `table-rows` | Input | `10000000` | Assumed production row count for lock duration simulation. |
| `qps` | Input | `800` | Assumed peak production QPS for blocked query simulation. |
| `fail-on-critical` | Input | `true` | Exit `1` and emit `::error` annotations when `CRITICAL` lock/rewrite hazards are found. |
| `fail-on-high` | Input | `false` | Also exit `1` when `HIGH` hazards (such as missing `lock_timeout`) are found. |
| `ignore` | Input | `node_modules,.git,dist,build,coverage,vendor,test,tests` | Comma-separated directory names skipped during recursive workspace scan. |
| `scanned-files` | Output | — | Number of `.sql` migration files audited. |
| `critical-hazards` | Output | — | Total `CRITICAL` lock or table-rewrite findings. |
| `high-hazards` | Output | — | Total `HIGH` findings. |
| `worst-safety-score` | Output | — | Lowest `0–100` safety score across scanned migrations. |
| `status` | Output | — | Gate verdict (`PASS` or `BLOCKED`). |
| `report-json` | Output | — | Structured JSON summary of findings and blast-radius metrics. |
## Verification
```bash
npm test
```
## License
MIT License — `0` external npm dependencies, `0` network calls, `100%` local execution.
TDQS
Scored across 4 tools
Each tool targets a distinct input/action pair: auditing raw DDL statements, generating a zero-downtime rewrite, estimating runtime blast radius from row counts/QPS, and recursively scanning a migration directory. The two 'audit' tools are separated cleanly by input type (inline SQL vs. a directory path), so misselection risk is minimal.
All four names follow a verb_noun snake_case pattern (audit_/generate_/estimate_ + domain object) and use the same vocabulary (ddl, migration, lock) as the descriptions. No mixed casing or verb-style drift.
Four tools is a tight, purposeful surface for a migration-safety domain: analyze, rewrite, quantify risk, and batch-scan. Nothing is redundant and each tool maps to a distinct stage of the workflow.
The surface covers the core lifecycle — detect hazard, rewrite safely, estimate impact, and sweep a directory — with rollback generation folded into the rewrite tool. Minor gaps remain, such as validating or re-checking an already-applied migration and no explicit support beyond PostgreSQL/MySQL, but these are workable around existing tools.