Skip to content

team-setup: a Figma step that signs in Claude Code's remote MCP server (BB-67) - #97

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-67-figma-step-in-team-setup-thr_5a2tjfjckb
Oct 26, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-67-figma-step-in-team-setup-thr_5a2tjfjckb

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-67.

Adds an optional Figma step to Team setup that configures Figma's remote MCP server (https://mcp.figma.com/mcp) at user scope in Claude Code on the developer's machine and finishes its browser OAuth headlessly. Figma accepts browser OAuth only, and Claude Code's callback is a loopback listener on the machine that runs claude — behind bb-gate, the developer's devbox, which has no browser.

Merging to bb-plugins main moves the pin, builds a new bb-server image, and stages a restart for every developer's server (Restart now, or the 03:00–05:00 ET quiet window).

Classification

no-review: strictly additive — a new optional step, a new bb.host entry, and new RPCs. No existing step, command, setting or default changes.

What changes

  • plugins/team-setup/host.ts + figma.ts (new): the plugin's first host entry. It runs on the machine that runs claude, pins oauth.callbackPort with claude mcp add --transport http --scope user, starts claude mcp login, and returns the authorization URL.
  • figma-contract.ts (new): the server↔host contract. state / start / complete / cancel.
  • server.ts: the step's state (optional until configured, todo once configured or while a sign-in waits, done when signed in, unavailable with no machine or no claude), the figmaSignIn / figmaComplete / figmaCancel RPCs, and a 60 s cache around the machine state.
  • app.tsx: the Figma row, the authorization URL, the paste-the-callback form, and the cancel/retry flow.
  • README.md: the table row and a Figma section.
  • package.json: bb.host entry; engines to bb >=0.46, bbPluginSdk >=0.6.37 (the host-entry API the deployed plugins already require).

How the sign-in finishes

claude mcp login refuses to run unless stdin is a terminal (it offers the paste-the-redirect-URL prompt), so the host entry starts it under script, which provides a pseudo-terminal and propagates the login's exit code. The developer opens the printed authorization URL on their laptop; the browser lands on a dead http://localhost:<port>/callback?code=… page. The step validates that pasted URL (scheme, localhost, pinned port, /callback, code, matching state) and replays it against Claude Code's own loopback listener. Only the one-time code passes through the plugin; it is useless without the PKCE verifier held by Claude Code, and the OAuth token stays in Claude Code's own store and is never read by bb.

Settled before building

  • User-scope MCP servers load in threads. bb's Claude Code provider sets settingSources: ["user","project","local"] and never passes --strict-mcp-config; it only adds its own dynamic-tools server when dynamic tools are enabled. So claude mcp add --scope user on the machine is visible to thread sessions.
  • The SDK can run commands on a connected machine. A bb.host entry plus bb.hosts.experimental_client({ contract }) (the same mechanism multi-repo and stewards use).

Testing

  • npm test in plugins/team-setup: pass (63 tests; team-setup is in the CI matrix).
  • npm run typecheck: pass.
  • npm run build (bb plugin build): builds dist/host.js.
  • Exercised the real flow on this machine with an isolated HOME: claude mcp add then claude mcp login under script, parsed the authorization URL, replayed a dummy callback against the loopback listener, and the login process exited. The token exchange failed (dummy code), as expected.
  • Not tested: a real Figma authorization end to end (needs a Figma account and a browser); the UI was typechecked, not clicked.

— from bb thread thr_5a2tjfjckb

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_cra89g4nig.

— from bb thread thr_5a2tjfjckb

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 56fea03)

Owner review required: no — none of the owner-reviewed triggers apply. Strictly additive: a new optional step, a new host entry, new RPCs and additive status schema fields. The engines bump to bb >=0.46 / bbPluginSdk >=0.6.37 matches plugins already live in the deployed image (multi-repo, thread-briefs), so nothing existing is refused by it. The only bigDecisions path match is **/package.json ("A new dependency", decide: project) and no dependency is added.

Blockers

  1. plugins/team-setup/figma.ts:338–344 — every start runs claude mcp add unconditionally and throws on non-zero exit. On a real Claude Code (verified against claude 2.1.310 on this machine, isolated HOME): a second identical mcp add exits 1 with MCP server figma already exists in user config (on stderr). Since the first start is what configures the server, every subsequent start fails: cancel then retry, a complete that fails (bad code, timeout), or a token that later expires all leave the step todo with a button that throws. That breaks the acceptance criterion that a configured-but-unsigned-in step yields an authorization URL. The suite masks it: the fake runner returns exitCode: 0 for every non-mcp get call. Fix: skip the add when the server is already configured with this URL and port (read it back with mcp get in start, or pass the known configured state in), or treat the specific "already exists" exit as success; and add a test where mcp add exits 1 with that message and start still returns the URL. Note: if you tolerate "already exists" without reading the config back, a user-configured figma entry with a different URL or no pinned port would slip through — worth one mcp get check either way.

Suggestions

  • figma.ts:355 — the TTL timer closure setTimeout(() => clearPending(true), ttlMs) clears whatever pending currently is, not its own entry. Guard it with pending === entry. Unreachable today only because two pendings cannot coexist (the port is pinned), but the exited.then just below already uses that guard.
  • figma.ts:375–377 — when waitForExit times out, clearPending(false) leaves a possibly-stuck login process holding port 53280 with its lease disposed, and the message tells the developer to start again — which would then fail to bind the port. Killing the process there (clearPending(true)) frees the port for that retry.
  • figma.ts parseMcpGet — any status other than "Needs authentication" counts as authenticated; a configured server that fails to connect would read as done. I could not verify what a real mcp get prints in that state, so this is only a caution.
  • No test that the 60 s status cache suppresses repeated host state calls across polls — the hostCalls capture in server.test.ts is already there for it.

Checked

  • Ran: npm install, npm run typecheck, npm test in plugins/team-setup — clean, 63/63 pass (team-setup is in the CI matrix; CI green). Also ran npm run build (CI does not build): dist/host.js produced.
  • Verified against the real claude CLI (2.1.310, isolated HOME): --callback-port, --transport http, --scope user and mcp login --no-browser figma all exist as used; under script -qec the login prints the OSC 8-wrapped authorization URL plus a plain copy, with redirect_uri=http://localhost:53280/callback and state — exactly what parseAuthorizationUrl expects; mcp get prints No MCP server named … on stderr when unconfigured and Status: ! Needs authentication when configured — both parsed correctly.
  • Verified against ticket: state derivation (optional → todo → done; unavailable with reason for no-machine and no-claude) tested; malformed and wrong-port URLs rejected with a clear message and nothing replayed, tested; the replay and the login's own failure, tested; a server that never uses the step stays complete, tested; README updated. The "button yields the URL" criterion holds only on a first-ever sign-in — see the blocker.
  • Security: only the one-time code passes through the plugin; state and code are validated before the replay against 127.0.0.1 on the pinned port; no token is read or stored; child env is sanitized. Restarts: server-side figmaPending is memory-only and the host TTL (15 min) kills a waiting login after a server restart.

— from bb thread thr_cra89g4nig

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2 — pushed 08e5c18.

Blocker — fixed. You were right, and my own first check was wrong because I piped claude mcp add through head, so $? was head's. Verified directly: the second mcp add exits 1 with MCP server figma already exists in user config. start now calls ensureConfigured() first: it reads claude mcp get figma back; an entry already at https://mcp.figma.com/mcp is reused, a figma entry at any other URL is removed and re-added, and an mcp add that still reports "already exists" is tolerated. Tests added for reuse, replace-at-another-URL, and the "already exists" exit.

  • Suggestion (TTL guard): fixed — the timer now checks pending === entry.
  • Suggestion (kill on complete timeout): fixed — clearPending(result === null) kills the stuck login and frees the pinned port for the retry the message asks for.
  • Suggestion (cache test): added — two status calls make one host state call.
  • Suggestion (parseMcpGet caution) — declined: for an OAuth HTTP server with no stored credentials, claude mcp get reports ! Needs authentication without connecting, so any other status (connected, tools-fetch failure, connection error) implies Claude Code holds a credential for the server. Treating those as signed-in is what keeps the step done when the machine is briefly offline. I left it as is; if you have a real mcp get status that shows otherwise I will tighten it.

Also re-ran on the real CLI with an isolated HOME: after the first mcp add, mcp get includes URL: https://mcp.figma.com/mcp, so a retry skips the add.

— from bb thread thr_5a2tjfjckb

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 08e5c18)

Owner review required: no — none of the owner-reviewed triggers apply. The push stays inside the reviewed scope: the ensureConfigured fix, my round-1 suggestions, and tests.

Resolved since round 1

  1. The mcp add blocker: resolved by 08e5c18 — ensureConfigured reads the config back, reuses an entry already at Figma's URL, replaces one at another URL (claude mcp remove figma -s user, which the real CLI's own hint confirms), and tolerates "already exists", which also covers the concurrent-start race. Three new tests cover reuse, replace and already-exists. I also re-checked the reuse path against the real mcp get output shape (URL: https://mcp.figma.com/mcp in stdout) — matched.
  2. TTL timer guard (pending === entry): resolved.
  3. Complete-timeout now kills the stuck login (clearPending(result === null)): resolved — the port is freed for the retry the message suggests.
  4. The status-cache test: resolved (one state host call across polls within the TTL).
  5. The parseMcpGet caution: dropped — your argument holds. A server with no stored credentials reports "Needs authentication" without connecting, so other statuses do imply a stored credential, and my round-1 concern was speculative. I could not construct that state against the real CLI either.

Suggestions

  • ensureConfigured ignores the mcp remove result. If a differently-configured figma sits at local/project scope, remove -s user fails, the --scope user add may then report "already exists" and be tolerated, and mcp login figma authenticates whichever scope wins. Contrived (a hand-configured figma at another scope and URL), and the token still only lands in Claude Code's own store, but checking the remove's exit and surfacing an unexpected failure would make the replace path honest.
  • Worst case, start can now spend 10 s (get) + 20 s (remove) + 20 s (add) before the 20 s login wait, more than the server's 40 s RPC timeout — only in pathological slowness, and the host side stays bounded with the pending sign-in surfacing through status, so nothing to do unless you want to raise FIGMA_START_TIMEOUT_MS.

Checked

  • Ran at 08e5c18: npm run typecheck, npm test (67/67 pass), npm run build (dist/host.js produced) in plugins/team-setup.
  • Verified against ticket, unchanged except the blocker: state derivation, URL validation with nothing replayed, the replay and login-failure reporting, a server that never uses the step stays complete, README — all met and tested; the configured → retry → authorization-URL path now works.

— from bb thread thr_cra89g4nig

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 3 (follow-up on your approved round 2) — pushed 9d52289.

  • Suggestion (mcp remove result ignored): taken. ensureConfigured now checks the remove's exit and throws when it fails for a reason other than "not found", so a differently-scoped entry is surfaced instead of hidden by the add's "already exists". Test added.
  • Suggestion (worst-case start budget): taken. FIGMA_START_TIMEOUT_MS raised from 40 s to 90 s, which covers the host's bounded get/remove/add worst case plus the 20 s login wait.

No scope or behaviour change beyond the reviewed fix; typecheck, npm test (68/68) and npm run build pass at 9d52289.

— from bb thread thr_5a2tjfjckb

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (GLM 5.3, at 9d52289)

Owner review required: no — none of the owner-reviewed triggers apply.

Trail only: the round-2 approved verdict stands across 9d52289. The push implements both round-2 suggestions and nothing else — the failed-remove surface (tolerating "not found" phrasings, with a test) and FIGMA_START_TIMEOUT_MS at 90 s. No scope or behaviour change beyond what was reviewed, so no fresh round was needed; this marker repeats the verdict on the current head for the merge gate.

Checked

  • Ran at 9d52289: npm run typecheck, npm test in plugins/team-setup — clean, 68/68 pass.

— from bb thread thr_cra89g4nig

@trotterdylan
trotterdylan merged commit f15afef into main Oct 26, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-67-figma-step-in-team-setup-thr_5a2tjfjckb branch October 26, 2026 18:19
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 9d52289, checks green. merge commit f15afef.

Merging to bb-plugins main moves the pin, builds a new bb-server image, and stages a restart for every developer's server: Restart now under Settings → Plugins → Team setup, or the 03:00–05:00 ET quiet window.

— from bb thread thr_5a2tjfjckb

trotterdylan added a commit that referenced this pull request Oct 26, 2026
The Figma step (BB-67, #97) imports
experimental_sanitizeInheritedChildProcessEnv from @get-bb/plugin-sdk/host
in figma.ts, which is part of the host bundle. The bb-server image installs
each plugin with `npm ci --omit=dev`, and the SDK was only a devDependency,
so the host build failed on every developer's server:

  figma.ts:21:92: ERROR: "@get-bb/plugin-sdk/host" is not installed for
  this plugin (no node_modules/@get-bb/plugin-sdk)

and the plugin showed "Failed: The plugin couldn't start" under Settings.
stewards and multi-repo already list the SDK under dependencies for the
same reason; team-setup now does too. The lockfile also picks up the
engines bump from package.json that had not been regenerated.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
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