Repository avatar
AI Tools
v0.3.2
active

vaultwarden-mcp

io.github.metodex-tech/vaultwarden-mcp

Security-first Bitwarden/Vaultwarden secrets for AI agents: allowlists, use-without-reveal, approval

Documentation

vaultwarden-mcp

npm MCP Registry CI License: MIT Node.js >= 20 MCP

Let AI agents use your Vaultwarden / Bitwarden secrets — without giving them your vault.

A self-hosted MCP server for anyone who wants an AI agent (GitHub Copilot, Claude, Cursor, VS Code, Codex…) to work with credentials stored in Vaultwarden or Bitwarden. Nothing is readable by default: you allow individual fields, and with use_secret the agent can call an API with a secret it never sees. Optional per-request approval, use limits and an audit log without values.

flowchart LR
    A["AI agent"] -- "use_secret(id, field, request)" --> M["vaultwarden-mcp<br/>policy · approval · audit"]
    M -- "bw get" --> B["Bitwarden CLI"] --> V[("Vaultwarden /<br/>Bitwarden")]
    M -- "request with the secret" --> API["Allowlisted API"]
    API -- "response" --> M
    M -- "response, secret masked" --> A

Русская версия

Quick start

Local install from source, for one person on one computer. About 10 minutes.

[!NOTE] Prefer npm? The package is on npm as @metodex/vaultwarden-mcp: npm install -g @metodex/vaultwarden-mcp (Windows: npm.cmd), then vaultwarden-mcp init instead of node src/cli.js init in steps 3–7 — or run it without installing via npx -y @metodex/vaultwarden-mcp init. The steps below install from source. The Docker image is not public yet: build it locally (Other ways to run it).

You need: a Vaultwarden or Bitwarden account and its personal API key (it exists only in the web vault — your server's website opened in a browser, e.g. https://vault.example.com or https://vault.bitwarden.com; the browser extension and the apps don't have it. Path: Settings → Security → Keys tab → View API key, details in step 4), plus git and Node.js ≥ 20. No account yet? Start with From scratch.

Windows: run the Windows commands below in PowerShell (Windows PowerShell 5.1 or PowerShell 7) — they use $env:, $HOME and Set-Content, which don't work in cmd.exe; Git Bash: see Troubleshooting. By default PowerShell scripts are disabled (ExecutionPolicy Restricted), so plain npm, npx and an npm-installed bw fail with "npm.ps1 cannot be loaded because running scripts is disabled". Type npm.cmd, npx.cmd and bw.cmd instead (as in the Windows commands below), or allow local scripts once: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.

1. Install the Bitwarden CLI

Linux / macOS:

npm install -g @bitwarden/cli
bw --version

Windows (PowerShell, not cmd.exe):

npm.cmd install -g @bitwarden/cli
bw.cmd --version

✅ Prints a version, e.g. 2025.x.x.

2. Get the server

git clone https://github.com/metodex-tech/vaultwarden-mcp
cd vaultwarden-mcp
npm ci --omit=dev        # Windows PowerShell: npm.cmd ci --omit=dev

✅ Ends with added … packages. Keep this folder: the client will run the server from it.

3. Create the data directory

node src/cli.js init

✅ ✓ Wrote starter policy (deny-all): …/.config/vaultwarden-mcp/policy.json, followed by the next steps with exact commands for your OS. The data dir is ~/.config/vaultwarden-mcp (Windows: %USERPROFILE%\.config\vaultwarden-mcp).

4. Log in and unlock (the commands init printed, shown here for the default data dir)

[!IMPORTANT] Run all of these in one terminal window. The first line sets BITWARDENCLI_APPDATA_DIR only for this window; in a new window bw uses its default profile, which points at bitwarden.com.

Linux / macOS:

export BITWARDENCLI_APPDATA_DIR=~/.config/vaultwarden-mcp/bw
bw config server https://vault.example.com      # your server, see below
bw status                                       # check "serverUrl"
bw login --apikey                               # client_id + client_secret
bw unlock --raw > ~/.config/vaultwarden-mcp/session && chmod 600 ~/.config/vaultwarden-mcp/session

Windows (PowerShell, not cmd.exe):

$env:BITWARDENCLI_APPDATA_DIR = "$HOME\.config\vaultwarden-mcp\bw"
bw.cmd config server https://vault.example.com  # your server, see below
bw.cmd status                                   # check "serverUrl"
bw.cmd login --apikey                           # client_id + client_secret
bw.cmd unlock --raw | Set-Content -NoNewline -Encoding ascii "$HOME\.config\vaultwarden-mcp\session"

Server URL: your Vaultwarden address, or https://vault.bitwarden.com / https://vault.bitwarden.eu for Bitwarden cloud (US / EU).

API key (client_id + client_secret): it is shown only in the web vault. Open your server's address in a browser; the browser extension and the desktop/mobile apps don't have it. There: Settings → Security → Keys tab → View API key, then enter your master password (also when you log in with SSO). You see client_id like user.xxxxxxxx-… and client_secret, a long random string; bw login --apikey asks for both.

✅ bw status shows "serverUrl":"https://vault.example.com" — your server. If it shows null and you are not on Bitwarden US cloud, BITWARDENCLI_APPDATA_DIR isn't set in this window: run the first line again. bw login says You are logged in!; bw unlock asks for the master password and prints nothing. The session file now holds the session key — the server never sees your master password.

5. Connect your AI client

node src/cli.js config claude-desktop --data-dir ~/.config/vaultwarden-mcp

Replace claude-desktop with copilot, claude-code, cursor, vscode or codex (on Windows use --data-dir "$HOME\.config\vaultwarden-mcp").

✅ Prints a JSON snippet and the file it goes into. Paste it there and restart the client. More clients and formats: docs/clients.md.

6. Check it works

Ask the agent: “Call the vault_status tool of the vaultwarden server.”

✅ It answers {"status":"unlocked"}. If not, see Troubleshooting.

7. Allow your first secret

The policy denies everything, so the agent can see item names but no values. Ask it to call list_item_metadata to get item ids (or open the item in the web vault: the URL contains itemId=<id>), then add a rule to policy.json — the recipe below is a good start. Edits apply immediately, no restart.

From scratch: no vault yet

You need a Bitwarden-compatible server and an account on it. Two options:

  • Bitwarden cloud (free plan is enough): create an account at vault.bitwarden.com or vault.bitwarden.eu. Nothing to host; the server talks to it through the official bw CLI.
  • Your own Vaultwarden: one Docker container, but it must be reachable over HTTPS.

Then: create the account and a master password, turn on two-step login, add a test item, copy the personal API key (web vault in a browser: Settings → Security → Keys → View API key), and continue with the Quick start. Step by step, with caveats: docs/getting-started-from-scratch.md.

Other ways to run it

SetupWhenGuide
Local, DockerYou don't want Node.js / bw on your machinedocs/deployment.md#local-docker
Remote, over SSH (stdio)Vault access lives on a server; no HTTP exposeddocs/deployment.md#ssh-stdio
Remote, HTTP + bearer tokenShared server, clients with Streamable HTTPdocs/deployment.md#http-with-docker-compose
Remote, HTTP + OIDC, multi-userChatGPT / Claude.ai connectors, a team. Experimental: unit-tested, not yet verified in productiondocs/oidc.md

Installed from npm instead of source? Use --launch npx (npx -y @metodex/vaultwarden-mcp serve) instead of node /path/to/vaultwarden-mcp/src/cli.js. Once the image is public, vaultwarden-mcp:local can become ghcr.io/metodex-tech/vaultwarden-mcp:latest.

Recipe: one API key, never revealed

  1. Store the key in a vault item, e.g. as the password of a login item, and get its id.

  2. Put a use rule in policy.json (not an items entry, so get_secret stays denied):

    {
      "items": {},
      "use": {
        "<item-id>": {
          "password": {
            "http": { "allowedUrls": ["https://api.example.com/v1/"], "methods": ["GET"] },
            "approval": "never",
            "maxUses": 100,
            "expiresAt": "2026-12-31T23:59:59Z"
          }
        }
      }
    }
    
  3. Tell the agent: “Call use_secret with id <item-id>, field password, and put {{secret}} where the key goes”, e.g. "headers": { "Authorization": "Bearer {{secret}}" }. It gets the API response with the key masked; it can't read the key or send it anywhere else.

Set VW_STATE_DIR so maxUses survives restarts. For per-call confirmation use "approval": "always" — but see the autopilot note in Policy.

Tools

ToolWhat the agent getsGated by
vault_statusunlocked, locked or unauthenticated—
list_item_metadataid, name, type of every item— (no values)
get_secret(id, field)The value of one allowed field (password, username, totp, notes, sshPrivateKey, sshPublicKey, field:<name>)items + approval
use_secret(id, field, request)The response of an HTTP request with {{secret}} substituted — maskeduse: URLs, methods, expiresAt, maxUses, approval

Prefer use_secret: the value never enters the model context, the transcript or the client's logs.

Policy

A JSON file (policy.json in the data dir, set by VW_POLICY), re-read on every call. Missing file = deny everything.

  • items — fields readable via get_secret (disclosed to the model).
  • use — fields usable via use_secret (not readable), bound to URL prefixes and methods, with optional maxUses / expiresAt.
  • approval — "never" or "always", per tool or per grant.

[!IMPORTANT] Approval is an MCP elicitation form: pick Approve once and press Accept. In autopilot / non-interactive modes clients auto-cancel these forms, so approval: "always" means every call is denied. For unattended agents use "never" with tight allowedUrls, maxUses and expiresAt.

Full reference: docs/policy.md · Example: examples/policy.example.json.

Troubleshooting

SymptomFix
npm.ps1 cannot be loaded because running scripts is disabled (Windows)PowerShell's default execution policy blocks npm's .ps1 shims (npm, npx, npm-installed bw). Use npm.cmd, npx.cmd, bw.cmd, or run once Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. MCP clients start the server directly, so client configs are not affected.
'$env:BITWARDENCLI_APPDATA_DIR' is not recognized…, 'Set-Content' is not recognized… (Windows)You're in cmd.exe; the Windows commands are PowerShell. Open PowerShell, or translate: set BITWARDENCLI_APPDATA_DIR=%USERPROFILE%\.config\vaultwarden-mcp\bw, bw unlock --raw > "%USERPROFILE%\.config\vaultwarden-mcp\session" (cmd writes plain ASCII, which is fine).
The token '&&' is not a valid statement separator / line breaks with \ fail (Windows)Windows PowerShell 5.1 has no && (PowerShell 7 has); use ; or separate lines. Line continuation is \ in bash, ` in PowerShell, ^ in cmd — don't paste bash multi-line commands into PowerShell. chmod doesn't exist on Windows; skip it.
Files written by > in PowerShell 5.1> / Out-File write UTF-16 with a BOM (PowerShell 7 writes UTF-8). The server reads UTF-16 and UTF-8-with-BOM session and policy.json, but other tools may not — prefer Set-Content -Encoding ascii / an editor.
Git Bash on WindowsThe Linux/macOS commands work, but ~ is /c/Users/you, while client configs need Windows paths: pass --data-dir "$(cygpath -w ~/.config/vaultwarden-mcp)" to config and use C:\\Users\\you\\… in JSON. chmod 600 has no effect on NTFS. PowerShell is the tested path.
Can't find View API keyYou're probably looking in the browser extension or the desktop app. The key is only in the web vault: open your server's address in a browser, then Settings → Security → Keys (the last tab) → View API key.
bw login → SSO sign-in is requiredFirst run bw status: if serverUrl isn't your server, bw is talking to another one (see the next row). If it is, your account is in an organization that requires SSO: log in with the API key — bw login --apikey works even then — or bw login --sso.
You are not logged in right after logging in, or bw status shows "serverUrl": nullBITWARDENCLI_APPDATA_DIR isn't set in this terminal window, so bw uses its default profile (bitwarden.com). Set it again in the same window (step 4, first line), check bw status, then log in and unlock in that window.
vault_status → lockedThe session file is missing, empty or expired. Repeat the bw unlock line from step 4; the file is re-read on every call, no restart needed.
vault_status → unauthenticatedbw isn't logged in for this data dir. Check that BITWARDENCLI_APPDATA_DIR in the client config points to <data dir>/bw, then repeat step 4.
Decryption failed / cli_failed on readsThe session key doesn't match the local bw state (unlocked with a different BITWARDENCLI_APPDATA_DIR, or after a password / key change). Unlock again with the right directory; if it persists, bw logout, then repeat step 4.
not_allowedThe item/field isn't in the policy. Check the id and the field name (custom fields are field:<name>).
A new vault item isn't foundThe server runs bw sync automatically (VW_SYNC_INTERVAL, default 300 s); wait or run bw sync yourself.
approval_declined although nobody was askedThe client runs in autopilot / non-interactive mode and auto-cancels approvals. Use approval: "never" with tight limits, or an interactive mode.
approval_unavailableThe client doesn't support elicitation. Same options as above.
Tools disappeared after restarting / recreating the server containerThe client's stdio connection is gone. Restart the client or reconnect the MCP server.
the port is already in useAnother process listens on the HTTP port. Stop it or set VW_HTTP_PORT.
The client can't start the serverRun the command + args from your client config in a terminal: it must start and wait silently. bw must be on the client's PATH (or set BW_CLI_PATH). On Windows the npm-installed bw.cmd is found automatically; BW_CLI_PATH may point to bw.exe or to …\node_modules\@bitwarden\cli\build\bw.js.

Documentation

docs/getting-started-from-scratch.mdNo vault yet: Bitwarden cloud or Vaultwarden, account, API key
docs/clients.mdConfig snippets for every client, launch modes
docs/deployment.mdDocker, SSH, HTTP, reverse proxy, systemd, hardening
docs/policy.mdPolicy reference, approval, limits
docs/configuration.mdAll environment variables and CLI commands
docs/security-model.mdThreat model, limitations, comparison with @bitwarden/mcp-server
docs/oidc.mdOAuth via OIDC, multi-user (experimental)
CHANGELOG.mdRelease notes

Roadmap

  • Telegram / webhook approval channel (for clients without elicitation)
  • use_secret for local commands (inject into the env of an allowlisted command)
  • Persistent use counters (VW_STATE_DIR)
  • Additional unlock providers: Bitwarden Secrets Manager, TPM-sealed session key
  • Publish to npm and the MCP Registry (0.3.1)
  • Public GHCR image (until then build the image locally)

Development

npm ci
npm run lint
npm test                       # node --test, uses a mock bw (fixtures/mock-bw.js)
BW_CLI_PATH=fixtures/mock-bw.js npm run smoke

On Windows PowerShell use npm.cmd instead of npm (see Troubleshooting).

PRs welcome — see CONTRIBUTING.md. Changes that widen what an agent can see must come with tests and a threat-model note. Security problems: please report privately, see SECURITY.md.

License

MIT © metodex-tech. Not affiliated with Bitwarden, Inc. or the Vaultwarden project.

NPM
@metodex/vaultwarden-mcp
Install Command
npm install @metodex/vaultwarden-mcp