Skip to content

feat(mcp): fix bitwarden MCP server vault session resolution - #448

Merged
growlf merged 2 commits into
mainfrom
fix/bitwarden-mcp-session
Oct 20, 2026
Merged

growlf merged 2 commits into
mainfrom
fix/bitwarden-mcp-session

Conversation

@growlf

@growlf growlf commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Problem

The Bitwarden MCP server aborts in OpenCode with Tool execution interrupted.

Root cause

OpenCode's config launched it as a bare npx -y @bitwarden/mcp-server with
BW_SESSION: {env:BW_SESSION}, but no OpenCode process has BW_SESSION
in its environment
— it's a desktop app, not a shell. The server starts fine
(lists 59 tools), but any real vault read (like list items) causes the bw
CLI to block on a hidden password prompt on stdin, which hangs forever.
OpenCode eventually aborts it as "interrupted".

Fix (3 parts)

1. mcp-run.sh — new needs_vault_session flag for external servers

External servers that ARE the vault client (bitwarden) get their session from
the resolver (bw_session.py), not from a vault item. This flag tells
the launcher to resolve and export BW_SESSION before launching, and skips
the vault-map entry check (no entry needed).

2. mcp/external-servers.json — declare bitwarden

Registers bitwarden so the launcher knows how to start it:

"bitwarden": {
  "command": ["npx", "-y", "@bitwarden/mcp-server"],
  "install": "npm install -g @bitwarden/mcp-server",
  "needs_vault_session": true
}

3. check-mcp-wiring.py — detect this drift

Two new checks:

  • Warn if an external-servers.json entry is NOT routed through mcp-run.sh in opencode.json
  • Suggest adding undeclared package-runner entries

Verification

$ bin/mcp-run.sh bitwarden --check
✓ external: npx -y @bitwarden/mcp-server
✓ command  /usr/.../npx
✓ bw CLI   /usr/.../bw
✓ BW_SESSION unlocked (from /home/netyeti/.cache/opskit/bw-session)
✓ session  external server (resolved from /home/netyeti/.cache/opskit/bw-session)
Launch path OK.

Also fix in opencode.json

This PR handles OpsKit-side changes. The opencode.json config will be updated
separately to route bitwarden through mcp-run.sh.

The bitwarden MCP server needs BW_SESSION but its session comes from
the resolver (bw_session.py), not from a vault item. This is the only
server class where this matters — the vault client itself.

Add needs_vault_session to mcp/external-servers.json and a matching
flag in mcp-run.sh that:
  - Forces NEEDS_SECRETS=1 so load_session_file() is called
  - Skips the vault-map entry check (no entry needed)
  - Reports session source in --check output

Declare bitwarden in external-servers.json with the npx command and
needs_vault_session: true.

Enhance check-mcp-wiring.py to:
  - Verify external-servers.json entries are routed through mcp-run.sh
  - Suggest adding undeclared package-runner entries
  - Catch the bitwarden drift pattern where opencode.json bypasses
    the launcher (#386)

Fixes: bitwarden MCP server aborts in OpenCode ("Tool execution
interrupted") because BW_SESSION is never resolved.
The external-servers.json catalog is advisory, not policy — users may
run the MCP server with a different vault solution (or none at all).
Change the 'declared but not routed through mcp-run.sh' check to an
INFO print instead of a WARNING, and update the check() return type
to (errors, warnings, infos) to keep the function pure.

Add test_declared_external_server_produces_info to explicitly verify
the INFO behavior. Remove bitwarden from test_foreign_servers_are_ignored
since it is now a declared server.

Fixes: PR #448 test failure
@growlf
growlf merged commit f55f11e into main Oct 20, 2026
9 checks passed
@growlf
growlf deleted the fix/bitwarden-mcp-session branch October 20, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant