pg-migration-guard
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., "@pg-migration-guard before I run this, check it for locks: CREATE INDEX idx_orders_customer ON orders (customer_id);"
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.
pg-migration-guard
An MCP server and CLI that stops AI coding agents (and humans) from shipping Postgres migrations that lock production tables.
AI coding tools are great at migration syntax. They don't know your table has 40 million rows, that CREATE INDEX blocks every write until it finishes, or that a "harmless" ALTER TABLE waiting on a lock queues every query behind it. The migration finishes in 10 ms on a laptop and takes the checkout API down in production.
pg-migration-guard gives the agent that missing knowledge. Connect it to Claude Code, Claude Desktop, Cursor or any MCP client, and the agent can check a migration before it runs it. Each finding comes with the safer rewrite.
[HIGH] line 6 create-index-not-concurrently
CREATE INDEX idx_orders_customer ON orders (customer_id)
Why: CREATE INDEX takes a SHARE lock: reads keep working, but every INSERT, UPDATE and
DELETE on the table waits until the index is built. On a large table that can be minutes.
Fix: Use `CREATE INDEX CONCURRENTLY` (outside a transaction).Zero runtime dependencies. The MCP protocol layer (JSON-RPC 2.0 over stdio) is implemented directly. Nothing to audit in your supply chain.
Deterministic. Rules, not a model. Same SQL in, same answer out. That makes it safe to use as a gate.
Works in CI too. The CLI exits non-zero on high-severity findings.
What it checks
Severity | Rule | Why it hurts |
high |
|
|
high |
|
|
high |
| Blocks writes, and reads that use the index |
high |
| Volatile default, serial, or stored generated column rewrites every row (any default before PG 11) |
high |
| Full scan under |
high |
| Usually a full table and index rewrite |
high |
| Scans while holding |
high |
| Builds a unique index under |
high |
|
|
medium |
| A blocked |
medium |
| Full scan under |
medium |
| Fails on any non-empty table |
medium |
|
|
medium |
| Breaks app instances still running the old code |
Tables created earlier in the same migration are exempt, because they are empty.
Related MCP server: MigrationPilot
Use it from an AI agent (MCP)
git clone https://github.com/saimulhasnain-dev/pg-migration-guard && cd pg-migration-guard
npm install && npm run buildClaude Code
claude mcp add pg-migration-guard -- node /absolute/path/to/pg-migration-guard/dist/src/server.jsClaude Desktop / Cursor (claude_desktop_config.json or .cursor/mcp.json)
{
"mcpServers": {
"pg-migration-guard": {
"command": "node",
"args": ["/absolute/path/to/pg-migration-guard/dist/src/server.js"]
}
}
}Then add one line to your project's CLAUDE.md / agent rules:
Before running or committing any Postgres migration, call
analyze_migrationand apply its fixes.
Tools
Tool | Input | Returns |
|
| Readable report + |
| none | All rules and severities |
Use it in CI
node dist/src/cli.js migrations/*.sql # fail on high
node dist/src/cli.js --fail-on medium --tx --pg 15 db/migrate/*.sql
node dist/src/cli.js --json migrations/2026_add_index.sql--tx tells it your tool wraps each file in a transaction (Rails, Django, Prisma and Knex do by default), so CONCURRENTLY inside one gets flagged.
Try it
npm run build
node dist/src/cli.js examples/risky.sql # 5 high, 2 medium
node dist/src/cli.js examples/safe.sql # the same changes, done safely: clean
npm test # 19 tests, including a real MCP stdio sessionLimitations
It's pattern-based, not a full SQL parser. It doesn't look inside DO blocks or function bodies, and it can't know your table sizes. A finding on a 200-row lookup table may be fine to ignore. Treat it as a reviewer that never forgets the lock rules, not as a replacement for knowing your data.
License
MIT
Available Tools
2 toolsanalyze_migrationCheck a Postgres migration for lock and safety risksARead-only
Analyzes Postgres migration SQL and reports statements that lock tables, rewrite them, or break running code (CREATE INDEX without CONCURRENTLY, volatile defaults, SET NOT NULL, foreign keys without NOT VALID, renames, missing lock_timeout, ...). Call this before running or committing any migration. Each finding includes a safer rewrite.
Inputs: sql (required), postgres_version, assume_transaction.
list_rulesList the checksARead-only
Lists every rule pg-migration-guard checks, with its severity.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools have clearly distinct roles: analyze_migration performs SQL analysis, while list_rules only enumerates available rules and severities. There is no plausible overlap or risk of misselection.
Both names follow the same snake_case verb_noun convention: analyze_migration and list_rules. The pattern is predictable and immediately readable.
Two tools is slightly below the typical 3-15 range, but the server has a very narrow purpose and both tools earn their place. It is well-scoped rather than padded or trivially thin.
The core workflow is covered: analyze a migration and discover what rules exist. Minor gaps remain, such as retrieving detailed per-rule documentation or configuring/ignoring rules, but agents can work without them.
Related MCP Connectors
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Detects database migration table locks, terraform cost leaks, and OWASP API flaws.
Review your AI agent's database changes on your schema, with plain-language risk, before they run.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Related MCP Servers
- AlicenseAqualityDmaintenanceAnalyzes database migrations for risks like lock contention and data loss before they run. Supports Flyway and Liquibase formats, providing risk scores and rollback generation.643 npmMIT
- AlicenseAqualityBmaintenanceBlocks unsafe PostgreSQL migrations before an AI agent writes or runs them. check_before_apply returns a pass/fail gate; reads the real Postgres parser, classifies the lock each statement takes, checks 112 safety rules. Runs offline, no database required.72,459 npm10MIT
- AlicenseNot gradedqualityBmaintenanceEnables checking Postgres migration SQL against a table-size estate snapshot and safety policy before apply, returning approve/block verdicts with lock details and remediation guidance, plus tools to explain locks and list policy rules.1MIT
- AlicenseNot gradedqualityBmaintenanceExposes read-only tools that let AI assistants detect schema drift, analyze lock impact, verify data with checksums, and plan safe PostgreSQL migrations that are validated by deterministic checks and shadow runs.67 npmApache 2.0