Skip to the content.

MCPg v0.5.0 — release notes

Released: 2026-05-27 Tool surface: 74 → 107 (+33) Tests: 874 pass / 106 skipped CI: PG 14 / 15 / 16 / 17 / 18

This release closes the entire docs/feature-shortlist.md — every pick from Tier A, Tier B, and Tier C — plus a natural-language → SQL helper that was in the “Defer for now” bucket. Six PRs landed on top of v0.4.0:

PR Theme Tools added
#18 Tier A: HTTP auth + Prometheus + TimescaleDB + pgvector + composites + advisors +16
#19 Tier B: PII heuristic + N+1 detector + migration validation + SET ROLE multi-tenancy +3 + runtime
#20 Tier C: catalog readers + naming linter + FK cascade graph + parallel select + server-side cursors + RLS tester + test-data factory +13
#21 NL → SQL via Anthropic / OpenAI / Gemini +1

Headlines

NL → SQL (translate_nl_to_sql)

The headline new capability. Send a natural-language question; MCPg gathers a compact schema brief (tables, columns, foreign keys), asks the configured LLM provider to translate, parses the JSON response, and — when execute=true — passes the generated SQL through the existing SafeSqlDriver safety allowlist before running it.

translate_nl_to_sql(question="how many orders shipped last week?",
                    schema="app",
                    execute=true)

Pluggable provider: MCPG_NL2SQL_PROVIDER=anthropic|openai|gemini. HTTPS calls go through httpx directly — no SDK dependencies. The OpenAI path accepts MCPG_NL2SQL_BASE_URL so it can target Ollama, vLLM, LM Studio, OpenRouter, or any other OpenAI-compatible gateway.

Safety: hard 16384 max_tokens cap; identifier-validated schema / table filter; writes / DDL / multi-statement input rejected at the execution layer regardless of what the model produced.

Per-request SET ROLE multi-tenancy

One MCPg process now serves N tenants from one connection pool. Two paths:

The tenant middleware sits above the bearer-auth middleware in the stack so unauthenticated requests can’t reach the role parser.

HTTP transport bearer-token auth + Prometheus /metrics

MCPG_HTTP_AUTH_TOKEN gates the streamable-http / sse transports. Missing or wrong token → 401 with WWW-Authenticate: Bearer realm="mcpg". /metrics, /healthz, /readyz are exempt so Prometheus / load balancer / k8s probes don’t need the MCP token.

/metrics emits the standard text-exposition format (v0.0.4) with three series:

Zero runtime dependency — the format is rendered in-process. get_metrics_exposition returns the same payload over MCP for stdio deployments.

Server-side cursors

Four tools — open_cursor / fetch_cursor / close_cursor / list_cursors — let an agent page through millions of rows without loading them all. Each open cursor holds a dedicated psycopg connection (NOT a pool checkout) so N long-lived cursors can’t starve the pool other tools use. SQL validated by the same allowlist as run_select; opened in a READ ONLY transaction.

Per-cursor asyncio.Lock serialises concurrent fetch / close on the same cursor — psycopg AsyncConnection isn’t safe for concurrent task access. Hard cap of 16 concurrent cursors; default 5-minute idle TTL with lazy sweep.

TimescaleDB

Five new tools — read (list_hypertables, list_chunks) plus DDL writes (create_hypertable, add_compression_policy, add_retention_policy). Every interval / identifier is allowlist-validated before being inlined into SQL. Each tool degrades to available=false when the extension is missing.

Composite + advisor tools

Tier-B + Tier-C surface (+17 tools)

New env vars

Variable Purpose
MCPG_HTTP_AUTH_TOKEN Bearer token enforced on HTTP transports.
MCPG_DEFAULT_ROLE Static PG role applied to every query.
MCPG_ALLOWED_ROLES Comma-separated allowlist for X-MCPG-Role + default.
MCPG_NL2SQL_PROVIDER One of anthropic, openai, gemini.
MCPG_NL2SQL_API_KEY API key (or vendor-conventional fallback).
MCPG_NL2SQL_MODEL Override the default model id.
MCPG_NL2SQL_BASE_URL Self-hosted gateway for OpenAI-compatible.
MCPG_NL2SQL_MAX_TOKENS Per-call budget (≤ 16384).

Backwards compatibility

Test plan

Acknowledgements

Gemini Code Assist reviewed every PR in this release and surfaced several real issues that were fixed before merge — notably the hybrid_search row-key bug, the TimescaleDB case-folding hazard, the cursor concurrency hazard, the NL→SQL parse-non-dict crash, and the brace-in-question format crash. Two findings (RLS bypass + multi- statement result failure) were verified empirically and replied to on-thread.