
DBShield Database Guardrail & Sandboxing MCP Server
io.github.RitualDev-Lab由 GitHub 账号 RitualDev-Lab 发布v0.2.1更新于 Nov 7, 2026
Safety-first Database Guardrail & Sandboxing MCP Server for AI Coding Agents
概览
本地 MCP 服务器,在 AI 编程代理与 PostgreSQL、MySQL 或 SQLite 数据库之间加一层安全防护,拦截高风险 SQL 并遮蔽敏感数据。
- 可以做什么
- 查看网关状态、安全等级与数据库统计信息
- 在不读取数据行的前提下查看表、列、约束与关系
- 执行读取与写入查询,带 PII 脱敏、成本闸门与 DDL 检查
- 在自动回滚事务中试运行变更,再用签名授权令牌提交
- 分析查询计划、校验迁移脚本、检查结构漂移并比对意图与 SQL
- 跨多个存储模拟并提交,读取已脱敏的审计日志
- 适用场景
- 当 AI 代理需要访问数据库,但你希望防止无约束删除、破坏性 DDL、超量变更以及 PII 流入模型上下文时使用。适合本地开发与预发布环境,生产环境应配合最小权限数据库角色使用。
- 运行要求
- 以 npm 包形式通过 stdio 在本地运行,通常用 npx 启动。需要通过 DBSHIELD_DB_URL 提供目标数据库连接地址或文件路径,并通过 DBSHIELD_DIALECT 指定方言(postgres、mysql 或 sqlite)。可选配置文件用于设置安全等级、行数上限与 PII 脱敏。代理、仪表盘及 Docker/Helm 模式需要本地端口和访问上游数据库的网络。
安装
在 SourceWeft 中
- 打开 控制台中的 DBShield Database Guardrail & Sandboxing MCP Server,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
🛡️ DBShield
The Safety-First Database Guardrail & Sandboxing MCP Server for AI Coding Agents
[License: MIT] [npm version] [OpenSSF Scorecard] [SOC 2 Audit Ready] [Website] [Documentation Guide] [Threat Model] [IDE Extension] [MCP Protocol] [TypeScript] [Node.js] [CI] [Docker Image] [Helm Chart] [Prometheus] [Biome]
Protect your databases from accidental bulk deletes, catastrophic drops, locks, and PII leaks when paired with Cursor, Claude Desktop, Antigravity, or Windsurf.
[DBShield Terminal Interactive Demo]
⚡ The Problem: AI Agents Writing Raw SQL
When autonomous AI coding agents interact directly with databases:
- Accidental Destruction: A missing
WHEREclause turns a targeted fix into an unrecoverableDELETE FROM users;orUPDATE orders SET status = 'cancelled';. - Catastrophic DDL: Agents dropping staging or production tables (
DROP TABLE,TRUNCATE) instead of running non-destructive migrations. - PII & Credential Leaks: Customer emails, passwords, SSNs, and API keys are streamed in plaintext directly into model contexts and chat transcripts.
- Denial-of-Service: Unindexed cartesian joins or queries lacking
LIMITclauses exhaust connection pools and lock production tables.
DBShield sits between your AI Agent and your Database as an intelligent, zero-overhead safety firewall.
🤖 Frequently Answered Questions (AEO & AI Search Reference)
What is DBShield?
DBShield is an open-source database guardrail, virtual schema masking proxy, and MCP server designed to protect relational databases (PostgreSQL, SQLite, MySQL) from accidental bulk mutations, schema corruption, and PII leaks when queried by autonomous AI coding agents.
How does DBShield prevent accidental data deletion?
DBShield operates with a Two-Phase Distributed Dry-Run Engine:
- When an agent submits a mutation (
UPDATE,DELETE,DROP), DBShield intercepts the query and executes it in an isolated transaction rollback block (BEGIN ... ROLLBACK). - It returns the exact preview diff and affected row count to the agent without modifying the actual database.
- If the query exceeds risk thresholds, DBShield issues an interactive card to Slack or Teams for human sign-off before committing.
What is Virtual Schema Masking?
When AI coding agents run introspection queries like SELECT * FROM information_schema.tables, DBShield intercepts the wire protocol and rewrites catalog responses. Sensitive internal tables (credentials, sessions, api_keys) and restricted columns are hidden entirely from the agent's view.
🚀 Key Capabilities
- 🔍 SQL AST-Level Guardrail Engine: Inspects query syntax trees before execution. Intercepts dangerous mutations, tautologies (
WHERE 1=1), and unconstrained deletes. - 🧪 Dry-Run Auto-Rollback Sandboxing: Executes writes in an isolated transaction block (
BEGIN ... ROLLBACK). Previews exact row impacts without altering the real database state. - 🔒 Dynamic Zero-Leak PII Masking: Automatically detects sensitive fields (passwords, emails, phone numbers, tokens) and masks them before streaming back to LLM context.
- 📐 Safe Schema Introspection: Exposes rich table definitions, foreign keys, and indexes without exposing data rows.
- 🎛️ Granular Safety Tiers: Choose between
STRICT(read-only / 1-row limits),BALANCED(production guardrails), orPERMISSIVE(custom rules). - 🎭 Virtual Schema Masking & Column-Level RBAC: Hides sensitive internal tables (
credentials,internal_audit,admin_*) frominformation_schema/ catalog introspection and masks restricted columns from agent context. - ⚡ Missing Index & Query Plan Regressive Advisor: Detects full-table sequential scans on unindexed tables and automatically synthesizes optimal
CREATE INDEX [CONCURRENTLY]DDL statements with cost regression alerting. - 📺 Real-time Live Query Approval Feed: Zero-dependency web dashboard (
:3100) streaming live agent queries, risk scores, and PII redactions, featuring 1-click "Approve / Reject" buttons for sensitive mutations. - 🌐 Multi-Store Distributed Dry-Run: Extends the two-phase commit token manager to coordinate atomic simulations and commits across distributed multi-store stacks (PostgreSQL + Redis + SQLite).
- 🔌 Universal MCP Protocol: Drop-in compatible with Claude Desktop, Cursor, Antigravity, Windsurf, and custom Agent frameworks.
📦 Quickstart
1. Claude Desktop Setup (1-Click)
Run the auto-installer to configure your local Claude Desktop:
Or manually add to claude_desktop_config.json:
2. Cursor IDE Setup (1-Click)
Run inside your workspace to create or update .cursor/mcp.json:
3. PostgreSQL Wire-Protocol Proxy (Zero Client Config)
Run DBShield as a transparent TCP wire proxy on :5433 (or :5432). Any ORM (Prisma, Drizzle, SQLAlchemy), AI agent, or CLI connects directly:
In your application or .env:
4. Terminal CLI & Status
5. Live Query Approval Feed & Web Dashboard
Start the real-time query approval web interface (:3100):
Open http://localhost:3100 to inspect live agent queries, risk scores, PII redactions, and 1-click "Approve / Reject" buttons for sensitive mutations.
⚙️ Configuration (dbshield.config.json)
Safety Tiers
🛠️ MCP Tools Reference
🛡️ Matrix of Supported SQL & Enforced Guarantees
DBShield enforces rigorous runtime guarantees across the SQL lifecycle. Guarantees are verified transactionally, ensuring mutations never exceed approved scope even if database state drifts:
Enforced Guarantees Breakdown
- Parameter-Bound Commit Invariance (B1):
- Commit authorization tokens are cryptographically signed (HMAC-SHA256) binding the exact normalized SQL query text, typed parameters (
params), database identity (storagePath), safety tier, and simulated affected row count. - Any query tampering, bound parameter alteration, or cross-database replay attempt is instantly rejected (
PARAMS_MISMATCH,QUERY_TAMPERED).
- Commit authorization tokens are cryptographically signed (HMAC-SHA256) binding the exact normalized SQL query text, typed parameters (
- Hard Mutation Ceilings & Transactional Rollbacks (B2):
- Exceeding
maxRowsPerMutationis a hard safety limit across all safety tiers (STRICT,BALANCED,PERMISSIVE), immediately refusing dry-run authorization (EXCESSIVE_BLAST_RADIUS). - Mutations executed directly or committed through
db_commitrun inside an atomic transaction block: if actual row modifications exceed the authorized ceiling, DBShield immediately executesROLLBACK;and aborts.
- Exceeding
- Simulation Delta Drift Prevention (B2):
- Protects against concurrent modifications between dry run and commit: if underlying database rows change such that actual affected rows differ from simulated rows (
simulatedAffectedRows != actualChanges), DBShield rolls back the transaction with[SIMULATION_DELTA_DRIFT].
- Protects against concurrent modifications between dry run and commit: if underlying database rows change such that actual affected rows differ from simulated rows (
- Audit Log & Error Message Sanitization (B3):
- Raw SQL strings have sensitive literals (passwords, tokens, API keys, emails, phone numbers, SSNs, credit cards) masked before being written to disk or the in-memory circular buffer.
- Database engine errors (e.g., SQLite constraint failures) are sanitized prior to returning to the agent or storing in audit records.
db_audit_logreturns strictly sanitized compliance records.
- Memory-Safe Streaming Read Row Capping (B4):
- SQLite row reads are streamed lazily using Node.js
stmt.iterate(). - Results are capped at
maxRowsPerReadwithout buffering the full dataset into Node.js heap memory, returning agent-friendly pagination metadata (totalReturned,isTruncated,maxAllowedRows,hasMore,warning).
- SQLite row reads are streamed lazily using Node.js
- Robust Statement Classification & CTE Support (B5):
- Replaced naive string prefix checks with SQLite prepared-statement column metadata (
stmt.columns() > 0) and recursive AST extraction. - Complex CTEs (
WITH active AS (...) SELECT ...) and leading single-line (--) or multi-line (/* */) comments are correctly classified and executed without error.
- Replaced naive string prefix checks with SQLite prepared-statement column metadata (
🔒 Production Deployment & Least-Privilege Guide
For production and shared environments, DBShield should be paired with database-level least privilege:
1. SQLite Filesystem Hardening
- File Permissions: Restrict database file permissions so only the DBShield process UID has access:
- Read-Only Connections: For read-only agent workloads, mount SQLite with read-only flags or initialize with SQLite read-only mode:
2. Relational Database Least Privilege (PostgreSQL / MySQL)
- Create a dedicated database role for DBShield with minimal necessary grants:
3. Policy Enforcement vs Human Approval
- Deterministic Policy Enforcement: DBShield's dry-run authorization token guarantees that a query adheres to automated safety policies (blast radius thresholds, tautology checks, parameter binding).
- Human Approval Hand-Off: In sensitive production workflows,
db_dry_runoutputs can be piped to an external human-in-the-loop review system (Slack, Teams, or ticketing webhook) before the token is submitted todb_commit.
🐳 Docker & Kubernetes Helm Packaging
DBShield is packaged as an enterprise container with an unprivileged non-root user (UID 10001), native Prometheus metrics exporter, and a production Kubernetes Helm chart:
1. Docker Compose (Zero-Config Full Stack)
Launch PostgreSQL, DBShield Wire Proxy, and Prometheus in one command:
- PostgreSQL Proxy:
127.0.0.1:5433(Targeting PostgreSQL on:5432) - Prometheus Dashboard:
http://localhost:9091 - Metrics Endpoint:
http://localhost:9090/metrics - Health Endpoint:
http://localhost:9090/healthz
2. Standalone Docker Container
3. Kubernetes Deployment via Helm
Deploy high-availability DBShield replicas (with HorizontalPodAutoscaler and Prometheus ServiceMonitor):
Metrics Exponent in Prometheus (/metrics)
dbshield_up: Proxy health status (1 = healthy)dbshield_connections_active: Real-time active client connectionsdbshield_queries_total{status, safety_tier, operation}: Total queries evaluateddbshield_queries_blocked_total{rule, severity}: Queries intercepted and preventeddbshield_query_duration_seconds: Histogram measuring query evaluation latencydbshield_cost_savings_dollars_total: Estimated cloud spend saved from blocked runaway queries
🏛️ Enterprise Compliance & SLA Guarantees
DBShield provides deterministic, zero-data-custody database protection backed by enterprise contractual assurances:
- Formal Enterprise Service Level Agreement: ENTERPRISE_SLA.md
Guaranteed response times: < 1 hour for P1 critical outages (24/7/365 coverage), < 4 hours for P2 high severity, 99.95% availability SLA. - SOC 2 Type II & ISO/IEC 27001:2022 Readiness Matrix: SOC2_ISO27001_COMPLIANCE.md
Comprehensive AICPA Trust Services Criteria (CC1–CC9, A1, C1, PI1, P1–P8) and ISO 27001 Annex A mapping for enterprise procurement audits. - Autonomous AI Coding Agent Skill Definition: SKILL.md
Standardized instructions and tool-calling directives for Antigravity, Cursor, Windsurf, and Claude Code. - GitHub Action CI/CD Migration Gate: action.yml
Pre-merge migration validation and unindexed cascade lock detection (uses: RitualDev-Lab/[email protected]).
Enterprise Contact & Incident Triage
- Security & SOC 2 Packages:
[email protected] - Commercial & SLA Support:
[email protected] - Technical Architecture Review:
[email protected] - Trust & Security Portal: https://ritualdev.in/trust
📄 License
MIT © RitualDev Lab
来源:README.md,提交 d609629
工具
0版本历史
1- v0.2.1最新Nov 7, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分