Protect the database MCP server you already use in one command
Español: es/PROTECT.md
pip install "sqlguardllm[mcp]" # YAML, SQLAlchemy and the proxy; add your database driver
sqlguardllm protect # dry run: what it found, the draft policy, the diff
sqlguardllm protect --apply # writes policy and map files and the new client config
sqlguardllm protect --undo # restores the backup
protect looks in your MCP client configs, recognises the database server you run, drafts a policy from the database and changes the entry so the client launches sqlguardllm proxy with the original command behind it.
What it does
- Finds client configs that exist: Claude Desktop (
claude_desktop_config.json), Cursor (~/.cursor/mcp.json,.cursor/mcp.json) and VS Code (.vscode/mcp.json, the usermcp.jsonandsettings.json). Files that are not plain JSON (VS Codesettings.jsonwith comments) are reported and left untouched. - Recognises dbhub (
--dsnorDSN), Postgres MCP Pro (URL argument orDATABASE_URI) and MCP Toolbox for Databases with the prebuiltpostgresconfig (POSTGRES_*variables). Any other server is reported and left untouched. - Drafts a policy with
Policy.from_database(): every table it finds,max_rows: 100, and columns whose names look personal or secret, in English and Spanish. Secrets (password,contrasena,token,api_key,card/tarjeta,iban,ssn,curp...) are hidden; personal data (email/correo,phone/telefono,birth/nacimiento,address/direccion...) is masked (redact). Each choice is printed with its reason. Names that only describe data (email_verified,token_count) are skipped. - Lints the draft with the same checks as
sqlguardllm lint --strictand shows the warnings. A tenant column such asbranch_idis reported, not guessed: add the row filter yourself. - Rewrites the entry to
sqlguardllm proxy --policy P --map M -- <original command and args>and keeps a timestamped backup (<config>.sqlguardllm-<time>.bak) beside it. The map exposes only the server's SQL tool (execute_sql, orqueryfor Postgres MCP Pro); everything else stays hidden and refused.
Policy and map files go to ~/.config/sqlguardllm/protect/ (--dir to change it). They hold names only, never credentials.
30-second demo
$ sqlguardllm protect
Cursor: /home/ana/.cursor/mcp.json
shop: recognised dbhub
tables exposed (2): customers, invoices
hidden customers.password_hash: looks like a secret or an identifier (password); hidden
masked customers.email: looks like personal data (email); masked
lint: clean (lint --strict would pass)
Dry run: nothing was written. Run `sqlguardllm protect --apply` to apply.
$ sqlguardllm protect --apply # Wrote .../mcp.json (backup: mcp.json.sqlguardllm-20261201-101500.bak)
$ sqlguardllm protect --undo # Restored .../mcp.json
(A text transcript; a recorded demo is not available yet.)
Safety
- Nothing is written without
--apply.--undorestores the newest backup beside each config. - Passwords in DSNs,
password=parameters and secret-looking environment values are masked in every output, including the diff and error messages. The only file that keeps the credentials is the client config itself, as before. - The policy is a starting point: the output lists every table it exposes. Review it, add row filters and run
sqlguardllm lint --strict. - Run the upstream with a read-only database user. Restart the client after applying.
- The database must be reachable from where you run
protect, with its driver installed (for examplepsycopg). - MCP Toolbox: the map in
examples/proxy/mcp-toolbox.yamlusesexecute_sqlwith argumentsql, checked against the source of Toolbox v1.18.0, not against a live run.