Skip to content

fix(mcp): make Copy token work on HTTP deployments (#148) - #154

Merged
LeoStehlik merged 3 commits into
masterfrom
fix/148-copy-token
Nov 21, 2026
Merged

LeoStehlik merged 3 commits into
masterfrom
fix/148-copy-token

Conversation

@LeoStehlik

@LeoStehlik LeoStehlik commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #148

Fixes: clicking Copy token in the once-only agent-token dialog did nothing on HTTP deployments (e.g. http://kobe:3000).

Root cause

AgentConnections imported CopyButton from @mantine/core, which uses navigator.clipboard directly. navigator.clipboard is only exposed in secure contexts, so on plain-HTTP, non-localhost origins the click threw inside the handler and nothing was copied or reported. Every other copy surface in WrenLore already uses the shared polyfilled CopyButton (components/common/copy-button → useClipboard → execCommandCopy fallback); this page was the only one that didn't.

Changes

  • agent-connections.tsx now uses the shared CopyButton (both the token dialog and the OpenCode config button).
  • Shared useClipboard/CopyButton gained an onError hook; the page shows an actionable red notification on failure ("select the text and copy with the keyboard") and only shows Copied when a copy actually succeeded.
  • execCommandCopy (editor-ext) now checks the document.execCommand("copy") return value and throws when the browser refuses, instead of silently reporting success; copyToClipboard stays best-effort/non-throwing for its editor callers.
  • Once-only display preserved; the secret is only held in component state, never logged or written to storage.

Verification (disposable stack on kobe:3210, HTTP, isSecureContext=false, navigator.clipboard absent)

  • Repro (v0.1.10 build): click → button stays "Copy token", keyboard-paste into a textarea yields nothing.
  • Fixed build, Chromium and WebKit: click → "Copied", Ctrl+V pastes the exact 84-char token; token absent from localStorage/sessionStorage.
  • Failure path (browser refuses execCommand): no false "Copied", notification shown, token still selectable for manual copy.
  • pnpm --filter @wrenlore/editor-ext test: 35/35 pass, incl. 4 new clipboard regression tests.

Limitations

document.execCommand("copy") is deprecated but remains the only synchronous fallback for insecure contexts; when browsers remove it, HTTP deployments will need the manual-copy path (already supported) or HTTPS.

Review follow-up: clear stale Copied status immediately when a later attempt fails; handle an unavailable clipboard method. The clipboard fixture now uses a generic test hostname.

The Agent connections token dialog used Mantine's CopyButton directly,
which relies on navigator.clipboard. That API is unavailable on
non-secure (HTTP) origins such as kobe:3000, so clicking Copy token
threw silently and nothing was copied.

Switch the page to the shared polyfilled CopyButton (execCommand
fallback), report real failures via the new onError hook, and make
execCommandCopy throw when the browser rejects the copy so success is
only shown when copying actually succeeded. Manual selection-based
copying remains possible and the token is still shown once and never
persisted.

Refs #148

Signed-off-by: Leo Stehlik <[email protected]>
Signed-off-by: Leo Stehlik <[email protected]>

# Conflicts:
#	apps/client/src/wrenlore/mcp/agent-connections.tsx
@LeoStehlik
LeoStehlik merged commit 3f6044b into master Nov 21, 2026
3 checks passed
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.

Agent connections: Copy token button does not copy the token

1 participant