Skip to main content
Glama
grokbot-bitwarden MCP Companion

grokbot-bitwarden MCP Companion

by salir-se
README.md
# Grok Bot × Bitwarden (`grokbot-bitwarden`)

[![CI](https://github.com/salir-se/grokbot-bitwarden/actions/workflows/ci.yml/badge.svg)](https://github.com/salir-se/grokbot-bitwarden/actions/workflows/ci.yml)
[![E2E](https://github.com/salir-se/grokbot-bitwarden/actions/workflows/e2e.yml/badge.svg)](https://github.com/salir-se/grokbot-bitwarden/actions/workflows/e2e.yml)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)

**Zero-plaintext-to-LLM, per-login human-approved Bitwarden credential access for Grok Bot** — built on the open [Bitwarden Agent Access Protocol v0](https://github.com/bitwarden/agent-access), a **100% Bun + TypeScript** local-first monorepo, and **Cloudflare-first** edge infrastructure.

---

## Why This Project Exists

Grok Bot users who store logins in **Bitwarden** (including **Free accounts, EU cloud, self-hosted / Vaultwarden servers, and shared organization vaults**) have no native, approval-gated way to let agents sign into websites without pasting passwords into chat or duplicating them into Grok Bot Vault.

This repository provides:

- **Complete engineering specification (DRAFT v3)**, 14 Architecture Decision Records (`ADR-001..014`), a 6-pillar Well-Architected Framework review mapped to Cloudflare, a boundary-driven security audit, a 12-PR implementation roadmap, C4 hosting maps, and org-wide security/testing/migration standards.
- **Reusable, Apache-2.0 Bun + TypeScript monorepo** designed to run end-to-end on a single developer laptop (with zero cloud accounts) and deploy cleanly to Cloudflare Workers, Durable Objects, D1, and KV.

### Delivery Tracks & Current Status

| Track                                     | Scope                                                                                                                                                                                                                          | Hosting                                                                                  | Status                                                                                                                                                                                                              |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Track 1 — First-Party Native Provider** | Native `bitwarden` provider in `cursor.keychain`, hardened `ap-relay` (Cloudflare Durable Objects), and host-side Fill Controller plus restricted browser Extension Credential Receiver (`ADR-001..009`, `ADR-013`, `ADR-014`) | Cloudflare Edge (`ap-relay` + D1/KV), isolated host controller, managed receiver browser | **Foundations implemented; native receiver and fill remain planned** — Production activation requires SpaceXSI & Security Gates A–C; see [`12-requirements-resolution.md`](docs/spec/12-requirements-resolution.md) |
| **Track 2 — Public MCP Companion Plugin** | Streamable HTTP MCP endpoint for non-secret guidance and diagnostic redaction; plugin packaging and interactive cards remain planned                                                                                           | Cloudflare Workers, or local Wrangler behind an HTTPS tunnel                             | **MCP endpoint implemented; Grok Bot connection not yet verified.** No marketplace listing, plugin archive, OAuth service, or native autofill is supplied.                                                          |

---

## How Grok Bot Finds This Application

**Add the Track 2 MCP server by its HTTPS URL.** Grok Bot does not discover this repository automatically, and uploading a source archive does not register a connector or install the native Bitwarden provider.

| Goal                                                      | What to run or register                                                                                   | Current boundary                                                                                                                             |
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| Try the companion during development                      | Local MCP Worker + public HTTPS tunnel; enter `<tunnel-url>/mcp` in Grok Bot's custom connector dialog    | Synthetic, non-secret inputs only; no marketplace submission needed for this route                                                           |
| Share a stable companion endpoint                         | Host `packages/mcp-plugin` on Cloudflare Workers; users add its HTTPS `/mcp` URL                          | Deployment is operator-managed; this repository supplies no live service URL                                                                 |
| Appear in public app search                               | Submit an MCP server URL or public plugin repository for marketplace review                               | Separate publication step; no approved listing or install link exists for this project                                                       |
| Fill browser logins without exposing secrets to the model | Track 1: Cloudflare relay + restricted extension receiver + host controller + platform-native integration | **Unavailable today:** requires platform ownership and verified security gates; a public MCP connector cannot grant host-side browser access |

See the [connection and local-development guide](docs/grokbot-connection-guide.md) for exact steps, hosting responsibilities, discovery checks, and registration requirements. The platform documents [custom connectors](https://docs.grok.com/grok-bot/computer-and-apps) separately from [marketplace submission](https://grok.com/marketplace/submit-a-plugin).

### Try the Non-Secret Companion Locally

After the [development setup below](#local-development-quick-start-single-laptop-zero-cloud-required), start these in separate terminals:

```bash
wrangler dev --config packages/mcp-plugin/wrangler.toml --ip 127.0.0.1 --port 8787
```

```bash
# Install cloudflared separately; this temporary tunnel exposes only the companion Worker.
cloudflared tunnel --url http://127.0.0.1:8787
```

In Grok Bot desktop, open **Connect apps → Add a custom connector**, enter a name, choose **Remote HTTPS**, and enter `https://<generated-tunnel-host>/mcp`. Choose **Add plugin**, then check the three companion tools are available. Team policy may require admin approval. Keep both terminals running; update the connector when the tunnel URL changes.

The current endpoint has no authentication or live vault connection. Use only synthetic diagnostic text; do not send credentials, pairing tokens, or real logs containing secrets. A tunnel provides reachability, not authentication. Run `bitwarden_connection_status` to inspect guidance; it does not query an actual connection.

Native Bitwarden Settings entries, a secure pairing card, item discovery, and automatic browser fill remain **target behavior**, subject to [platform access and security activation gates](docs/spec/12-requirements-resolution.md). The earlier native setup walkthrough was a proposal, not an available installation path.

---

## High-Level Architecture (C4 System Context)

```mermaid
flowchart TB
  classDef person fill:#08427B,stroke:#052E56,color:#FFFFFF
  classDef our_sys fill:#1168BD,stroke:#0B4884,color:#FFFFFF
  classDef ext_sys fill:#999999,stroke:#6B6B6B,color:#FFFFFF

  OWNER["[Person] Vault Owner\nApproves each login in Bitwarden, manages Settings"]:::person
  AGENT["[External System] Grok Bot Agent (LLM + computerUse)\nHosted by SpaceXSI; sees opaque bwg_ grant IDs only"]:::ext_sys
  OUR_SYS["[Software System] grokbot-bitwarden\nTARGET: Cloudflare relay + restricted receiver + opaque host controller + Track 2 MCP"]:::our_sys
  BW_CLIENT["[External System] Bitwarden UserClient (aac listen + bw)\nRuns on User Device; unlocks vault & prompts human"]:::ext_sys
  BW_VAULT["[External System] Bitwarden Vault Server\nUS / EU Cloud or User Self-Hosted"]:::ext_sys
  TARGET["[External System] Target Sign-In Website\nHTTPS login form in Managed Chromium"]:::ext_sys

  OWNER -->|"Pairs once & reviews audit (HTTPS)"| OUR_SYS
  OWNER -->|"Approves/denies each login"| BW_CLIENT
  AGENT -->|"Tool calls (entry_id only)"| OUR_SYS
  OUR_SYS <-->|"Noise_NNpsk2 E2E ciphertext (WSS)"| BW_CLIENT
  BW_CLIENT <-->|"Encrypted vault sync"| BW_VAULT
  OUR_SYS -->|"Receiver inserts approved item and submits"| TARGET
```

The diagram describes the proposed native target, not working autofill. Reference findings and verification limits are in [the static analysis](docs/analysis/extension-autofill-reference-analysis.md).

See [docs/architecture-hosting-map.md](docs/architecture-hosting-map.md) for the full **C4 Level 1–3 + Local-First Deployment** diagrams and hosting ownership matrix.

---

## Core Security Invariants

- **Zero plaintext to the model (`SEC-1`, `INV-1`):** Usernames, passwords, TOTP seeds/codes, pairing tokens, and Bitwarden item IDs never appear in tool results, LLM transcripts, logs, metrics, DB rows, or audit records.
- **Fresh human approval (`SEC-2`, `INV-5`):** Every new item release requires an explicit human decision in Bitwarden; an already released item may serve the same origin-bound workflow only within its original TTL.
- **Browser isolation:** The proposed receiver owns decryption and input; the host controller carries opaque commands and receipts. Private worker control, browser files, screenshots, DOM and extension storage must be inaccessible to the agent. This replaces host plaintext fill as the target; see [the extension profile](docs/spec/13-extension-autofill-profile.md) and [proposed architecture decision](docs/adr/0016-extension-backed-approved-item-autofill.md). These capabilities remain unverified.
- **Ephemeral memory-only secrets (`INV-3`, `ADR-010`):** In the target receiver, approved items live in transient memory for a default 300 s, maximum 900 s absolute TTL, with best-effort buffer wiping and DOM cleanup or browser quarantine. JavaScript wiping does not guarantee removal of all heap copies.
- **Exact-origin + eTLD+1 binding (`SEC-6`, `SEC-7`):** `https://` only, exact active-tab origin verification before typing, and `submitted` is never conflated with `signed in`.
- **Permissive-license supply chain (`WA-SEC-06`):** Strictly Apache-2.0 / MIT / BSD dependencies (zero GPL/AGPL/LGPL), enforced on every commit and PR by `scripts/check-licenses.ts`.

---

## Local Development Quick Start (Single Laptop, Zero Cloud Required)

Prerequisites: [`mise`](https://mise.jdx.dev/) automatically installs and activates the pinned toolchain (`bun`, `wrangler`, `lefthook`, `sops`, `age`) from [`.mise.toml`](.mise.toml) on folder enter/trust. Direct **`bun` (`package.json` scripts)** is the primary task runner. Docker is **not** required for default development — only for the optional self-hosted Vaultwarden E2E container.

```bash
# 1. Clone and trust the project toolchain (mise installs pinned bun, wrangler, lefthook, sops, age)
git clone git@github.com:salir-se/grokbot-bitwarden.git
cd grokbot-bitwarden
mise trust .mise.toml && mise install

# 2. Install workspace dependencies and Git hooks
bun install --frozen-lockfile
mise run hooks:install

# 3. Run the full quality & security gate locally (~200 ms: fmt, typecheck, test --coverage >= 85%, pele Mermaid/docs, licenses, SOPS)
bun run verify
```

### Optional Real-Vault E2E (Local Self-Hosted Vaultwarden)

```bash
# Start a disposable local Bitwarden-compatible Vaultwarden server (~20 MB RAM, 127.0.0.1:8088)
mise run dev:e2e

# Run the E2E suite against it
bun run test:e2e

# Tear down the E2E container
mise run dev:down
```

### Encrypted Operator Secrets (`mise` + `sops` + `age`)

Operator infrastructure secrets (Cloudflare API tokens, Axiom OTLP tokens) use a **project-unique `age` key** stored in git-ignored `.secrets/age.key` and encrypted JSON files under `secrets/*.enc.json`. See [`secrets/README.md`](secrets/README.md) and [`docs/architecture/environment-and-secrets.md`](docs/architecture/environment-and-secrets.md).

---

## Tech Stack

| Concern                                        | Choice                                                                                    | Notes                                                                                                                                                                                        |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Runtime, Formatter, Typecheck, Test, Audit** | **100% Native Bun (`1.4.5`)**                                                             | `bun fmt`, `bun check`, `bun test`, `bun audit` configured via [`.bunfig.toml`](.bunfig.toml) — zero Biome, Prettier, or `tsc`                                                               |
| **Toolchain Guarantee**                        | **`mise`** ([`.mise.toml`](.mise.toml))                                                   | Auto-installs pinned `bun`, `wrangler`, `lefthook`, `sops`, `age` on folder enter and in CI (`jdx/mise-action`); primary task automation lives in `package.json` `scripts`                   |
| **Git Hooks**                                  | **`lefthook`** ([`.lefthook.yml`](.lefthook.yml))                                         | Parallel `pre-commit` (`~40 ms`) and `pre-push` quality & security gates                                                                                                                     |
| **Primary Cloud Infra**                        | **Cloudflare** ([`ADR-013`](docs/adr/0013-cloudflare-first-production-infrastructure.md)) | Workers, Durable Objects (WebSocket Hibernation), D1 (SQLite), KV, Workers Observability + optional Axiom OTLP                                                                               |
| **Browser E2E**                                | **Flashwright** + local **Vaultwarden**                                                   | Fast Chromium CDP E2E against `login-lab` and disposable self-hosted test vaults                                                                                                             |
| **CI/CD & Releases**                           | **GitHub Actions** + **`release-please`**                                                 | Path-filtered PR CI ([`ci.yml`](.github/workflows/ci.yml)), E2E ([`e2e.yml`](.github/workflows/e2e.yml)), automated SemVer & `CHANGELOG.md` ([`release.yml`](.github/workflows/release.yml)) |

---

## Repository Layout

```text
.
├── AGENTS.md                  # Engineering principles, TDD/BDD, coverage & working agreements
├── CONTRIBUTING.md            # Local setup, Conventional Commits & PR checklist
├── SECURITY.md                # Private vulnerability reporting & security architecture
├── .bunfig.toml               # Native Bun formatter, test coverage floor (>= 85%) & runtime config
├── .env.example               # Configuration registry index (.env.example.d/*.env)
├── .github/workflows/         # SHA-pinned CI, Vaultwarden E2E, Cloudflare deploy & release-please
├── .lefthook.yml              # Pre-commit & pre-push automated gates (direct bun calls)
├── .mise.toml                 # Pinned toolchain & non-Bun infra tasks (mise)
├── .sops.yaml                 # SOPS + age encryption rules for secrets/*.enc.json
├── docs/                      # Full documentation hub (specs, ADRs, Well-Architected, audit, PR-train)
├── infra/                     # Digest-pinned local Vaultwarden E2E compose file
├── migrations/                # Rollback-safe Cloudflare D1 / SQLite migrations (0001_initial_schema.sql)
├── packages/
│   ├── ap-relay/              # Cloudflare Workers + Durable Objects WebSocket Hibernation relay
│   ├── common/                # Shared ULIDs, ErrorCode, SecretBytes, token redactor, schema tests
│   ├── e2e-tests/             # E2E, SQLite migration & canary test suite
│   ├── fill-executor/         # Host controller contracts (runtime migration to opaque receiver pending)
│   └── mcp-plugin/            # Track 2 Cloudflare Workers Streamable HTTP MCP companion
├── schemas/                   # Canonical Draft 2020-12 JSON Schemas for tool contracts
├── scripts/                   # Docs/pele Mermaid validator, permissive-license audit, SOPS guard
└── secrets/                   # Encrypted operator JSON secrets & non-secret template
```

Every package in `packages/*` ships its own `README.md` with responsibilities, C4 architecture diagram, and test commands (enforced automatically in CI).

---

## Documentation Hub

- **[Documentation Index](docs/README.md)** — Complete map of all specifications, ADRs, and reviews
- **[Project Vocabulary](docs/vocabulary.md)** — Canonical naming authority, topic shards, and collision map
- **[C4 Architecture & Hosting Map](docs/architecture-hosting-map.md)** — L1–L3 + Local-First Deployment diagrams
- **[Engineering & Security Standards](docs/architecture/security-principles.md)** — OWASP ASVS 5.0 / CASA Tier 2, 190-principle catalogue, environment config, secrets runbook, D1/SQLite migrations, and testing strategy
- **[Specification Pack (DRAFT v3)](docs/spec/README.md)** — PRD, requirements (`FR`/`NFR`/`SEC`), user stories, JSON Schema tool contracts, architecture, test plan, gap analysis, and requirements resolution ([single-file v3](docs/bitwarden-grokbot-spec.md))
- **[Architecture Decision Records (`ADR-001..014`)](docs/adr/README.md)** — Technology Radar, Y-statements, and dependency graph
- **[Well-Architected 6-Pillar Review (Cloudflare-Mapped)](docs/well-architected/README.md)** — 43 design gaps mapped to Cloudflare Workers/DO/D1/KV and cross-pillar trade-offs
- **[Security Audit & Design Verification](docs/security-audit/design-and-foundation-verification.md)** — Boundary-driven verification via `cloudflare/security-audit-skill`
- **[PR-Train Implementation Roadmap (`v0.1.0-rc.1`)](docs/plan/pr-train-roadmap.md)** — Approved 4-wave, 12-PR build plan with dependency graph

---

## Contributing & Releases

Git hooks check changed Markdown at the repository root and in documentation and package directories. Install them with `mise run hooks:install`; normal pushes run the full configured quality gate.

1. Follow **Conventional Commits** (`feat:`, `fix:`, `docs:`, `chore:`, `ci:`, `test:`) so `release-please` generates accurate SemVer bumps and `CHANGELOG.md` entries.
2. Every new workspace package under `packages/*` must include a `README.md` (responsibilities, C4 Mermaid diagram, test commands) and follow [`docs/architecture/testing-strategy.md`](docs/architecture/testing-strategy.md).
3. All dependencies must use permissive open-source licenses (Apache-2.0, MIT, BSD).
4. **Security issues:** Never open a public issue with real credentials or exploitable vulnerabilities; report privately to the repository maintainers (or Bitwarden via `bitwarden/agent-access` `SECURITY.md` for upstream protocol flaws).

---

## License & Trademark Notice

Licensed under the **[Apache License 2.0](LICENSE)**.

_Bitwarden is a trademark or registered trademark of Bitwarden, Inc. in the United States and/or other countries. This project is an independent open-source integration specification and toolkit compatible with the open Bitwarden Agent Access protocol and is not officially affiliated with or endorsed by Bitwarden, Inc. or SpaceXSI._