
Db Gateway
io.github.4hmetuyarPublished by GitHub account 4hmetuyarv0.3.5Updated Oct 24, 2026
KVKK/GDPR-compliant LLM-to-database gateway: PII masking, RBAC, rate limiting, audit log
Overview
Local MCP gateway that sits between an AI assistant and a database, masking PII, enforcing role-based table access, rate limits and audit logging.
- What you can do
- List and describe accessible tables, with role restrictions and masking policy shown
- Query rows from a table, with sensitive fields masked or redacted automatically
- Inspect the gateway's own audit history, filtered by table, tool, operation, denied calls or time
- Check active configuration, roles and rate-limit status
- Optionally insert, update or delete rows when writes are explicitly enabled and permitted for both table and role
- When to use it
- Useful when an assistant needs read access to a real database but you want a guardrail layer: PII masking, per-role table allow/deny lists, query rate limits and an audit trail. Also fits teams that must show KVKK or GDPR-style controls over LLM database access.
- Requirements
- Runs locally as an npm package (Node.js) over stdio, typically configured in Claude Desktop. Needs a database connection: a DATABASE_URL for the CLI, or an existing Prisma, pg, mysql2, better-sqlite3 or MongoDB client passed to the server factory. The active role is set via GATEWAY_ROLE or config; optional settings include GATEWAY_PII_SCAN and GUARDBEE_TELEMETRY.
Installation
In SourceWeft
- Open Db Gateway in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
@guardbee/mcp-db-gateway
🇬🇧 English | 🇹🇷 Türkçe | 🇨🇳 中文 | 🇯🇵 日本語 | 🇰🇷 한국어 | 🇧🇷 Português | 🇪🇸 Español | 🇩🇪 Deutsch
[npm version] [npm downloads] [License: MIT] [Smithery]
A KVKK / GDPR-compliant MCP (Model Context Protocol) server — adds a security layer between an LLM and a database.
Instead of querying your database directly, Claude (or any other LLM) goes through this gateway. Sensitive fields are masked automatically, table access is role-controlled, and every query is written to an audit log.
Telemetry is off by default. With
GUARDBEE_TELEMETRY=1it sends the server, tool, success, duration and short parameter values such as a file path; longer strings and fields likecontent,tokenorpasswordare replaced with a placeholder. See@guardbee/mcp-telemetry.
Features
- PII Masking — Turkish national ID, IBAN, email, phone, password hashes, etc. are masked automatically
- Role-Based Access (RBAC) — Per-role table allow/deny lists and field rules
- Rate Limiting — Global and per-table request windows
- Audit Log — Writable to console, a file, or an HTTP webhook
- Prisma / Postgres / MySQL / SQLite / MongoDB Adapters — Plug in an existing
PrismaClient, apgPool, amysql2Pool, abetter-sqlite3Database, or a MongoDBDbdirectly - Write Support (optional) — insert/update/delete, off by default; gated by per-table + per-role permission, protected-field guarding, and a "don't touch the whole table" safety net
- 195 unit tests — masking, the pipeline, RBAC, the rate limiter, the audit log, and every adapter (read + write) are covered
Recent Changes (2026-09-15)
Three new steps in this package's AI Gateway growth work:
1. The query_audit_log tool
Previously the gateway's audit log was write-only — it landed in one of the console/file/http sinks, but Claude itself had no way to look back and ask "what just happened, which calls got denied." Now it can:
- How it works:
AuditLoggergained an always-on, in-memory ring buffer that's completely independent of the configured sink (audit.bufferSize, default 200). Even when the sink is"http"(a fire-and-forget webhook), history is still queryable through this buffer. The buffer resets when the process restarts, and is never populated whileaudit.enabled: false. - Filters:
table,tool(the MCP tool name, e.g."delete_row"),operation(read/insert/update/delete),deniedOnly(denied calls only),since(an ISO 8601 timestamp),limit(default 50, max 200). Results come back newest-first. - A real bug fixed along the way:
registerDbTools(read tools) andregisterWriteTools(write tools) previously each built their ownGatewayPipeline/AuditLoggerinstance. That meant audit events frominsert_row/update_row/delete_rowcalls would never have appeared in the buffer thatquery_audit_logreads — there were two separate, unaware-of-each-other buffers.server.tsnow builds a singleGatewayPipelineinstance and shares it across both tool groups. - Tests:
src/__tests__/audit-logger.test.ts(10 tests — buffer capping, every filter, ring-buffer behavior) plus 3 tests added topipeline.test.ts(verifying that reads and writes land in the same buffer, thatdeniedOnly+tablefilters compose correctly, and that the buffer stays empty whileaudit.enabled: false).
2. The SQLite adapter
The gateway now works with better-sqlite3 alongside Prisma/Postgres/MySQL:
- Same security pattern as pg/mysql: table/column names can't be parameterized, so they're validated before being embedded in SQL — here using SQLite's
PRAGMA table_info(table)instead ofinformation_schema. A name that fails the format check (e.g.users"; DROP TABLE users;--) or isn't in the live schema is rejected before any query reaches SQLite. better-sqlite3is only an optionalpeerDependency— it was not added to the package's owndevDependencies, since it requires a native binding; tests (like the pg/mysql tests) were written against a simple mock object matching theSqliteQueryableinterface, without importing the real package.lastInsertRowidinstead ofRETURNINGfor insert: since SQLite'sRETURNINGsupport is version-dependent, this follows the same approach as the MySQL adapter'sinsertId— if the table has anidcolumn and it's not already indata, the inserted row getslastInsertRowidattached.- Bonus fix: the
AuditEvent/AuditQueryFiltertypes were not exported from the package root (index.ts) at all — added for consumers who want to type their own calls toGatewayPipeline.queryAuditLog(). - Tests:
src/__tests__/sqlite-adapter.test.ts(21 tests) — the same scenario set aspg-adapter.test.ts: table listing, filtered/unfiltered queries, limits, unknown table/column rejection, injection-attempt rejection, insert (including id assignment), update, delete.
3. The MongoDB adapter
The gateway now also works with a Db instance from the mongodb driver:
- A different risk class — not SQL injection, but operator injection: for pg/mysql/sqlite the risk was a table/column name being embedded in SQL. MongoDB never embeds identifiers, but if a key in
filter/datais a Mongo operator like$where/$ne, or a value is an operator object like{ $ne: null }, the "simple key-value equality filter" a tool declares can silently turn into an arbitrary query. This adapter rejects all of the following up front:- any key starting with
$(in bothfilteranddata) - any key containing
.— a dotted path (e.g."passwordHash.reset") is both an operator-like risk and a way to bypassfindProtectedWriteFields's exact-name matching (outside of its glob support) - any non-scalar (object/array) filter value — including an operator-object bypass attempt like
{ status: { $ne: "active" } }
- any key starting with
mongodbis only an optionalpeerDependency— same as the SQLite adapter, tests were written against a mock object matching theMongoDatabaseinterface, without importing the real package.- "Table" = collection.
tables()maps tolistCollections(); insert attaches_id(the driver'sinsertedId) to the returned row; update runsupdateManywith{ $set: data }; delete runsdeleteMany. - Tests:
src/__tests__/mongo-adapter.test.ts(19 tests) — collection listing, filtered/unfiltered queries, limits, three operator-injection scenarios (a$-prefixed key, a dotted key, an operator-object value), insert/update/delete.
Quick Start
1. Connect with one click via Smithery
You can add this to Claude Desktop with one click via Smithery.
2. Connect to Claude Desktop via global install
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:~/.config/Claude/claude_desktop_config.json
Restart Claude Desktop. The demo database loads automatically, with PII masking active.
3. Use it in your project (Prisma)
If you don't use Prisma, you can also pass a raw pg or mysql2 connection directly:
Security note: unlike the Prisma adapter, the
pg/mysql2/better-sqlite3adapters generate raw SQL. Because table and column names can't be parameterized, they are validated against the live schema on every query (information_schema, orPRAGMA table_infofor SQLite) — a table/column name that isn't in the schema (e.g. an injection attempt) is rejected before it ever reaches SQL. The MongoDB adapter guards against a different risk ("operator injection" instead of SQL) — see Recent Changes.
MCP Tools
The gateway always exposes these 5 read tools to Claude:
When writesEnabled: true (see Write Support), 3 more write tools are added:
Configuration
Masking Strategies
Glob pattern support: *Password*, *Token*, *Secret*
PII inside text columns (piiScan)
Field rules go by column name, so a free-text column (notes, description) can still carry an e-mail, a TC kimlik or an API key. piiScan (off by default) masks those by value in every text field no field rule covers, nested objects and arrays included; an allow rule turns it off for that field. preset / enable / disable pick the detectors, with the same presets as the security proxy: ALL (default), KVKK, IDENTITY, IDENTIFIERS, SECRETS.
From the CLI: GATEWAY_PII_SCAN=true (every default detector) or GATEWAY_PII_SCAN=KVKK (a preset). An unknown preset or detector name fails at startup.
piiScan.blockPatterns and piiScan.allowPatterns add your own patterns, as in the security proxy: block masks your ids as <CATEGORY_n>, allow leaves a detected value whose whole text matches. A block pattern that runs over its 100 ms budget fails the query rather than return rows it may not have masked.
Role-Based Access (RBAC)
The role is set when the server starts, via the GATEWAY_ROLE env var or config.activeRole.
Each Claude Desktop profile or deployment can run with a different role.
Rule precedence (highest to lowest):
- Global
tableRulesdeny - Role
denyTables - Role
allowTables(a whitelist — if set, the table must be in this list) - Role
fieldRules→ globalfieldRules
Write Support (write/insert/update/delete)
The gateway is fully read-only by default. Letting the LLM modify data requires deliberately unlocking a few gates:
writesEnabled: true— the global kill-switch. Whilefalse(default),insert_row/update_row/delete_roware never visible to Claude.- Table permission —
tableRules[].write.{insert,update,delete}— per table, off by default for all. - Role permission (when a role is active) —
roles[].write.{insert,update,delete}. If a role never defineswrite(undefined), write is completely off for that role — even if the table permits it. To permit a write, both the table and the role must explicitly saytrue(AND logic — deliberately stricter than the "role overrides" logic used for masking rules).
Beyond these three gates, there are two more protections that cannot be disabled:
- Protected-field guarding — the LLM can never write a value into a field marked
redact/mask/hashinfieldRules(e.g.tcKimlik,passwordHash); ifinsert_row/update_rowsees such a field indata, the whole request is rejected. maxAffectedRowsPerWrite— beforeupdate_row/delete_rowruns, the filter is first tried as a read; if the matched row count exceeds this limit (default 10), the operation is rejected before touching anything.update_row/delete_rowalso always reject an empty filter — "update/delete the whole table" is never possible through this gateway.
Every write attempt (accepted or denied) is written to the audit log; only which fields were written is logged, never data itself (so the audit log itself can't become a PII leak point).
Prisma Adapter
Pass a PrismaClient directly — table name → model mapping is automatic:
Development
License
MIT — GuardBee
Feedback
Questions, ideas, or a false positive? Start a thread in GitHub Discussions or open an issue. If GuardBee is useful to you, a ⭐ on the repository helps others find it.
Source: packages/db-gateway/README.md at commit 040e072
Tools
0Version history
1- v0.3.5LatestSep 29, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts