Skip to content

fix: add clipboard fallback for non-secure contexts#1404

Open
xlyoung wants to merge 1 commit into
modelcontextprotocol:mainfrom
xlyoung:fix/clipboard-fallback
Open

fix: add clipboard fallback for non-secure contexts#1404
xlyoung wants to merge 1 commit into
modelcontextprotocol:mainfrom
xlyoung:fix/clipboard-fallback

Conversation

@xlyoung
Copy link
Copy Markdown

@xlyoung xlyoung commented Jun 1, 2026

Problem

Clicking 'Copy Servers File' or 'Copy Server Entry' buttons fails when Inspector is hosted over HTTP (not HTTPS) on a local network, such as Docker compose deployments.

Root cause: navigator.clipboard.writeText() requires a secure context (HTTPS or localhost). When accessed via HTTP on a LAN IP, the Clipboard API throws a DOMException, and the error toast shows the raw exception message.

Fix

Add a copyToClipboard utility that:

  1. Uses the Clipboard API when available (navigator.clipboard + window.isSecureContext)
  2. Falls back to a temporary <textarea> + document.execCommand('copy') otherwise

This is the same fallback pattern used by many popular libraries (e.g., clipboard-polyfill).

Testing

  • Verified the fallback path works in Chrome 142 over HTTP on a LAN IP
  • Existing Clipboard API path unchanged for secure contexts

Fixes #913

navigator.clipboard.writeText() requires a secure context (HTTPS or
localhost). When running Inspector in Docker on a local network over
HTTP, the Clipboard API throws a DOMException, causing the 'Copy
Servers File' and 'Copy Server Entry' buttons to fail.

This adds a fallback that uses a temporary textarea element with
document.execCommand('copy') when the Clipboard API is unavailable.

Fixes modelcontextprotocol#913
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.

Servers File Export is Broken

1 participant