Repository navigation
🛡️ KacaSQL v1.1.0 — Production Guardrails & Performance Protection
Safe enough to point directly at production read-replicas without risking resource exhaustion or accidental data leaks.
v1.1.0 upgrades KacaSQL from strict read-only query enforcement into a production-ready database MCP server with multi-layer guardrails across both PostgreSQL and MySQL.
✨ What's New
1. Execution Resource Caps & Streaming Payload Truncation
- Millisecond Timeouts (
timeout_ms): Enforced directly at the database session level (SET LOCAL statement_timeouton PostgreSQL,SET SESSION max_execution_timeon MySQL). - Hard Payload Byte Cap (
max_payload_bytes, default51200/ 50 KB): Prevents LLM context-window blowups on wide result sets via streaming row assembly. - Structured
_metaTruncation Hints: Whenever results are capped bymax_rowsormax_payload_bytes, KacaSQL appends actionable_metahints so AI agents know whether to narrow columns, tightenWHEREfilters, or lowerLIMIT.
2. Granular Access Control (allowed_schemas & blocked_tables)
- 2-Layer Enforcement: Applied consistently across all discovery/inspection tools (
list_schemas,list_tables,search_schema,describe_table,get_table_relationships,get_table_sample),db://{connection_id}/overview, andsqlglotAST table/schema checks. - Supports exact table names, schema-qualified names (
private.billing_tokens), and glob patterns (audit_*,private.*) while safely ignoring local CTE aliases.
3. Full PII Protection (Column-Name + Value-Level Regex)
- Column-Name Masking: Global
masked_columnsmerged with per-connectioncustom_pii_columns. - Value-Level PII Redaction: Built-in ReDoS-safe presets (
credit_card,jwt,id_nik,id_npwp,email) plus user-definedcustom_pii_value_patterns(validated fail-fast at config load) to redact sensitive values leaked inside free-text orJSONBcolumns.
4. EXPLAIN-First Full Table Scan Blocker (block_full_table_scan)
- Environment-Aware Safe Default: Automatically enabled (
true) whenenvironment: prodandfalseforlocal/dev/staging(always explicitly overridable). - PostgreSQL: Detects
Seq ScanandParallel Seq Scan(accounting forWorkers Planned) abovescan_row_threshold(default100,000), with a limit-aware exception so simple peeks likeSELECT * FROM orders LIMIT 5(without filters/sorts) are not falsely blocked. - MySQL: Detects
ALLandindexfull scans exceedingscan_row_threshold. - Returns a compact
offending_scanssummary + rewrite hint so the AI can self-correct using indexed columns.
5. Privacy-First Local JSONL Audit Trail
- Opt-in persistent JSONL log via
defaults.audit_log_pathorKACASQL_AUDIT_LOG(e.g.,~/.kacasql/audit.jsonl). - Default SQL Literal Redaction (
audit_redact_sql_literals: true): Replaces string & numeric literals with placeholders viasqlglotAST (preventing audit logs from becoming a shadow PII store) and recordssql_hash(SHA-256). - Enforces
0600file permissions on POSIX, size-capped rotation (audit_max_bytes, default 10 MB), and fail-safe writes.
6. Declarative guardrails: YAML Block & CLI --version
- Clean
guardrails:configuration block (100% backward-compatible withv1.0flat fields; strictlydsn_env-only). - Added
kacasql --versionCLI flag.
📦 Quick Upgrade (uvx)
Update your MCP client config (~/.gemini/config/mcp_config.json or Claude Desktop) to @v1.1.0:
{
"mcpServers": {
"kacasql": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/halovina/kacasql.git@v1.1.0",
"kacasql"
],
"env": {
"KACASQL_CONFIG": "/path/to/connections.yaml",
"KACASQL_AUDIT_LOG": "~/.kacasql/audit.jsonl",
"PROD_REPLICA_PG_DSN": "postgresql://readonly_user:password@prod-replica:5432/app"
}
}
}
}✅ Verification
- 112 tests passed (
103unit tests +9live Docker PostgreSQL 16 & MySQL 8.4 integration & multi-scenario stress tests). - Verified under 80 concurrent mixed adversarial/valid/timeout/payload-cap calls and 100-query burst pool saturation (
223.5 QPS, 0 pool errors, 0 credential/PII leaks).
Full Changelog: v1.0.1...v1.1.0