Skip to the content.

ADR-0007: First-party SQL-safety kernel (de-vendor crystaldba/postgres-mcp)

Context

ADR-0001 chose to hard-fork MCPg from crystaldba/postgres-mcp and vendor its sql/ subpackage — the pglast-AST SQL-safety allowlist validator plus the async connection pool / driver — near-verbatim under src/mcpg/_vendor/sql/ (MIT, pinned commit 07eb329). That was the right call to ship fast, but it left two standing costs:

  1. ~1.3k lines of security-critical code outside every quality gate. The vendored kernel — including the SQL allowlist itself — was excluded from the coverage gate, mypy --strict, ruff, and bandit (pyproject.toml carve-outs).
  2. Manual re-syncs. Upstream changes had to be re-applied by hand with local modifications tracked in a vendor README.

It was also the last third-party runtime code MCPg shipped. Roadmap 18.1 set out to own it.

Decision

Replace the vendored kernel with a first-party src/mcpg/sql/ package, re-authored from the MIT-licensed original (attribution retained in NOTICE). Recon showed three of the vendored modules (bind_params.py, extension_utils.py, index.py) had no consumer outside _vendor/, so they were deleted, not rebuilt. The kernel is re-architected to separate policy from mechanism:

The public seam (SqlDriver, SafeSqlDriver, DbConnPool, obfuscate_password) is unchanged, so the ~74 consuming modules only changed an import path.

Faithful re-author, not a redesign. The security behaviour is pinned identical to the vendored validator:

Consequences

Alternatives considered