Skip to main content
Glama
dbbroker-mcp
by natogalvez

dbbroker-mcp

Let AI agents query your databases without ever seeing a password. A local broker holds the credentials in an admin-only vault; the MCP only gets query results. Writes need your approval.

Supported today: SQL Server (Windows). Next: PostgreSQL, with a per-engine adapter design.

[broker window: elevated, -NoProfile]       [your window]
dbbroker ◄──── 127.0.0.1 + HMAC ────► dbbroker-mcp (MCP) ◄── stdio ──► Claude
 │ vault (.kdbx + key file) → server, user, password
 │ connects to the database and discards the credentials
 └ approves writes in this window
  • You open the broker before opening Claude. It is the only process that ever sees the credentials: it opens the vault, connects, and stays connected.

  • The vault is a .kdbx file (KeePass format) unlocked with a key file, so there is no password to type. Each entry is one connection.

  • The MCP holds no secrets: it only forwards queries to the broker.

  • The broker never reveals the credentials. The protocol has no operation that returns them, not the server and nothing else from the vault. Claude only sees each connection's name and database.

  • Reads run inside a transaction that is always rolled back.

  • Writes are approved in the broker window.

Layout

dbbroker-mcp/
├─ dbbroker_mcp/server.py        the MCP (what Claude uses)
└─ broker/                       EVERYTHING broker-related lives in here
   ├─ dbbroker/                  code
   ├─ config/
   │   ├─ broker.example.toml    behavior (optional): write_policy, max_rows…
   │   └─ connections.example.toml  template for importing connections with -From
   ├─ start-broker.ps1           you run it: starts the broker or creates the vault
   ├─ install-protected.ps1      protected mode (optional)
   ├─ vault/                     INSECURE vault, if you use one (gitignored)
   ├─ .python/ .venv/ .uv-cache/ created on first run (gitignored)
   └─ pyproject.toml, uv.lock    broker dependencies (pykeepass, pyodbc), with hashes

Related MCP server: mcp-sqlserver

Setup

You need Windows, uv and the ODBC Driver 18 for SQL Server. The examples assume the repo is cloned at C:\src\dbbroker-mcp; adjust the path to yours.

1. Create the vault

C:\src\dbbroker-mcp\broker\start-broker.ps1 -NewVault              # secure (default): UAC prompt
C:\src\dbbroker-mcp\broker\start-broker.ps1 -NewVault -Insecure    # insecure: not elevated

You can skip this step: the first time you start the broker without a vault, it offers to create one right there and then starts.

A broker editor window opens. It works like Notepad. In it you can:

  • paste a connection string as is (ODBC or ADO.NET) and give it a name (dev, prod…); or

  • fill in one or more connections using the template (server, port, database, user, password…).

Press Save (or Ctrl+S) and you're done. The server can be written host,1433 or host:1433; the broker converts the second form, which SQL Server itself doesn't understand. What you type goes from the window into the vault without touching the disk: there is no file to delete, and nothing is left in a cache the way the Windows 11 Notepad does. The window runs elevated, so a non-elevated program can't read its contents. When it closes, the clipboard is cleared. If clipboard history (Win+V) is on, the broker reminds you to clear it by hand.

To add more connections later, run the same command. A connection with an existing name replaces the old one after asking. If you'd rather not use the window, -Console asks for the data in the console, with the password hidden.

Secure (default)

-Insecure

Where

C:\ProgramData\dbbroker-vault\

broker\vault\

Who can read the vault and key file

only SYSTEM and Administrators

any process running as you

Could Claude read it?

No (it runs non-elevated)

Yes, if it tried

The broker runs

elevated (UAC)

non-elevated: elevating adds nothing if the vault is already readable

Importing from a file (optional): copy broker\config\connections.example.toml, fill it in, and run

C:\src\dbbroker-mcp\broker\start-broker.ps1 -NewVault -From C:\path\connections.toml

The broker imports it and then overwrites it with zeros and deletes it. While the file exists, any process running as you can read it. Also, some editors, like the Windows 11 Notepad or VS Code, keep copies in a cache inside your profile. That's why the broker window is the recommended way.

Backup: if you lose the key file (.keyx), you lose the vault, though you can just create it again. KeePassXC can open it: Open database → no password → key file.

2. Register the MCP with Claude

claude mcp add --scope user dbbroker '--' uv run --directory C:\src\dbbroker-mcp dbbroker-mcp

In PowerShell, the -- must be quoted. Otherwise PowerShell swallows it and claude treats --directory as one of its own options (error: unknown option '--directory').

Daily use

C:\src\dbbroker-mcp\broker\start-broker.ps1     # opens the broker window
claude                                             # in your usual window, once it says "Listening"
  • With no options it uses the secure vault if there is one (UAC prompt), otherwise the insecure one (non-elevated). To force one: -Secure or -Insecure.

  • By default it connects all connections in the vault. For only some: -Connection dev or -Connection dev,prod. Claude picks among the connected ones by name.

  • Several vaults: -NewVault -VaultName clients to create one, then start-broker.ps1 -VaultName clients to use it. Without -VaultName the vault is called default. A parameter the script doesn't know (such as -Name) is an error, so a typo can't silently land your connections in the wrong vault.

  • start-broker.ps1 -ListVaults shows which vaults exist: name, secure or insecure, connections, and whether they still exist. It reads the registry broker\config\vaults.json, which the broker updates whenever it creates or changes a vault (names only, no secrets), and checks it against what's on disk. On purpose, it neither shows nor stores paths. Secure vaults can only be verified when elevated, because a non-elevated process can't look inside their folder.

The first time, start-broker.ps1 downloads Python and the dependencies into broker\, verified against the hashes in uv.lock. Claude must not run this script: everything is typed into the broker window, never into Claude's.

Keys in the broker window

Key

Action

t

Auto-approve writes for 30 min

s

Auto-approve writes for the whole session

r

Revoke auto-approval

c

Reconnect dropped connections (re-reads the vault)

l

Connection status

q

Quit

When a write arrives, the broker shows it in full and asks [y] Yes [n] No [t] Yes + 30 min [s] Yes + whole session. If you don't answer within confirm_timeout, it is rejected. Auto-approval can only be turned on from the broker's keyboard. By design, Claude can't turn it on.

Broker config (optional)

broker\config\broker.toml (a copy of broker.example.toml) tunes behavior, not connections:

  • write_policy per connection: confirm (default), trust (always approve), or deny (read-only);

  • driver, max_rows, query_timeout, the default connection;

  • a vault of your own, such as a group exported with KeeShare from your KeePassXC, instead of the one -NewVault creates.

Normal mode and protected mode

There are two things to protect: the vault (where the passwords are) and the broker code (what reads them).

Code in the repo (normal)

Code in Program Files (protected)

Setup

none

install-protected.ps1 as admin

The broker never reveals credentials

✅

✅

No non-elevated process can modify the broker so that it does

❌

✅

With a secure vault, Claude can't read the passwords directly. But in normal mode, an agent could modify the broker so that, when it runs elevated, it copies them somewhere else. Secure vault + protected code closes both paths. On startup, the broker tells you which situation you're in.

Why protected mode needs Program Files

Protecting a folder isn't enough: every folder above it has to be protected too. If you own the parent folder, as with C:\Users\you, C:\Projects, or the repo, Windows lets you rename or delete what's inside, whatever its permissions. A program running as you could swap the broker right after it was verified. Program Files is the only location that comes protected top to bottom by default. The secure vault doesn't have this problem because C:\ProgramData isn't yours.

Enabling protected mode

# PowerShell AS ADMINISTRATOR
powershell -NoProfile -ExecutionPolicy Bypass -File C:\src\dbbroker-mcp\broker\install-protected.ps1

What it installs. Everything goes into C:\Program Files\dbbroker:

  • the broker\ folder from the last commit (git archive), not from loose files;

  • the config, which it shows you before copying;

  • bin\uv.exe, a copy of your uv;

  • .python\ and .venv\, verified against the hashes in uv.lock;

  • a dbbroker shortcut in the Start menu.

What it doesn't do: it creates no services, scheduled tasks, or autostart, and it doesn't touch the registry or PATH. The broker exists only while its window is open, and it only listens on 127.0.0.1.

Updating or uninstalling: use the installed copy of the installer, because the repo copy can be edited without elevation.

powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\dbbroker\install-protected.ps1"              # code
powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\dbbroker\install-protected.ps1" -ConfigOnly  # config only
powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\dbbroker\install-protected.ps1" -Uninstall   # uninstall

Initial trust: the first install uses the repo's installer and your uv.exe, and both can be edited without elevation. Review them before that first run.

Protections that always apply

Risk

Mitigation

Claude reads the broker's memory

The broker runs elevated: a non-elevated process can't open its memory.

Your PowerShell profile runs in the elevated window

start-broker.ps1 opens the window with -NoProfile.

User environment variables (PYTHONPATH, COMSPEC, PROGRAMDATA, UV_*…)

Python runs with -I, the broker doesn't use os.system, system paths come from the Windows API, and the script clears UV_*/PYTHON*.

Tampered packages

uv sync --frozen --no-build installs only what's in uv.lock, with its hashes and without building anything.

The secure vault ends up with weak permissions

On startup, the broker checks that only administrators can read it; otherwise it won't open it.

Claude talks to the broker directly

It can, with the key in %LOCALAPPDATA%\dbbroker\broker.json. It gets the same power as the MCP and the same approval rules.

Not covered: processes that are already administrators, such as any program you approve through UAC, and keyloggers. In Python, strings can't be overwritten in memory: "discarding the credentials" means dropping the references.

Claude Code rules (.claude/settings.json)

The repo ships rules that Claude Code enforces when you work inside this repo:

Rules

Purpose

Read(./broker/config/broker.toml), connections.toml, broker/vault/**

Claude doesn't read the config, the import template, or the insecure vault.

Edit/Write(./broker/**)

Claude doesn't modify the broker: code, dependencies, config.

Edit/Write(./.claude/**)

Claude can't remove these rules by editing the file.

Bash/PowerShell(*start-broker*)

Claude doesn't launch the broker: its prompts would show up in Claude's window.

To change the broker with Claude's help, you have to remove the rules by hand and put them back afterwards.

Limits:

  • Read, Edit and Write rules are firm: Claude Code applies them to its file tools (Read, Edit, Write, Grep, Glob), even if Claude is tricked through prompt injection.

  • Bash and PowerShell rules match the command text. They block any command that mentions start-broker, even a legitimate one, and a command written to avoid that text gets through. That's why there are no Bash rules for broker.toml: they got in the way more than they protected.

  • They only apply in this repo and only Claude Code honors them. Other agents ignore them. What really protects you is the secure vault, which is enforced by the operating system and doesn't depend on any agent.

  • So that nobody can remove them, copy them into an administrator managed-settings.json, which takes precedence over everything else (on Windows, C:\Program Files\ClaudeCode\; check the path in the Claude Code documentation).

Upgrading from sqlmcp

This project used to be called sqlmcp. The first time the new broker runs elevated, it moves the secure vault folder C:\ProgramData\sqlmcp-vault to C:\ProgramData\dbbroker-vault and takes full control of its permissions again; a vault called sqlmcp is renamed to default. It never overwrites: if both exist, it tells you and leaves the old one alone. Re-register the MCP under its new name:

claude mcp remove sqlserver
claude mcp add --scope user dbbroker '--' uv run --directory C:\src\dbbroker-mcp dbbroker-mcp

If you used protected mode, uninstall it from C:\Program Files\sqlmcp-broker (install-protected.ps1 -Uninstall from there) and install it again: it now lives in C:\Program Files\dbbroker.

Development

uv run pytest        # no SQL Server needed; one test uses keepassxc-cli, if present, to check compatibility

License

Apache-2.0

Available Tools

5 tools
describe_tableB

Columns of a table/view: type, length, nullability, default, and whether it is part of the PK.

Args: table: 'schema.table' or 'table' (dbo schema by default).

Inputs: table (required), connection. Returns: result

list_connectionsA

List the connections configured in the broker (name, database, write policy, status) and whether write auto-approval is active.

Inputs: no named parameters. Returns: result

list_databasesC

List the databases on the server.

Inputs: connection. Returns: result

list_tablesB

List tables and views in the connection's current database, optionally filtered by schema.

Inputs: schema, connection. Returns: result

queryA

Run SQL on a connection (today every connection is SQL Server: T-SQL).

  • Reads (SELECT/WITH...): run inside a transaction that is always rolled back.

  • Writes (INSERT/UPDATE/DELETE/MERGE/DDL/EXEC...): the user must approve them in the broker window (this may take a while). They are committed only if approved and successful. Returns JSON with one or more result sets: {columns, rows, truncated} or {rowcount}.

Args: sql: T-SQL batch (no GO). connection: connection name; omit for the default one (see list_connections). max_rows: maximum rows per result set (the broker enforces its own cap).

Inputs: sql (required), max_rows, connection. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool targets a distinct resource or action: listing connections, databases, tables, describing a table, and executing SQL. The one potentially broad tool, query, is clearly the execution path, and the listing tools are separated by scope (broker connections vs. server databases vs. tables/views).

    Naming Consistency4/5

    All names use snake_case with predictable verb-first phrasing: list_tables, list_connections, list_databases, describe_table, query. The only minor deviation is query being a bare verb without a noun, but it remains clear and consistent enough.

    Tool Count5/5

    Five tools is well-scoped for a database broker: three discovery tools, one schema inspection tool, and one SQL execution tool. Nothing feels redundant or missing at the count level.

    Completeness4/5

    The surface covers connection discovery, database/table discovery, table description, and arbitrary read/write SQL execution, which is strong lifecycle coverage for a DB broker. Minor gaps include no explicit schema listing, no search for tables/columns, and limited constraint/index detail beyond primary-key membership.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Enables LLM agents to query databases with read-only access, while requiring human approval for writes through a token-based confirmation system.
      6
      GPL 3.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to securely query and administer SQL Server databases, with read-only access by default and permission-based write capabilities.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Gives AI coding tools reviewed access to PostgreSQL, MySQL, SQL Server, and SQLite databases, letting read-only queries run instantly while every data or schema change pauses for human approval in a review dialog. It also exposes schema introspection for agents and a way to open the connection manager.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI coding agents to safely inspect and mutate relational databases through AST-level SQL guardrails, isolated dry-run rollback previews, automatic PII masking, and virtual schema hiding. Sensitive mutations are gated behind human sign-off via Slack, Microsoft Teams, or a live web approval feed.
      12
      67 npm
      1
      MIT