Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions client/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ const Sidebar = ({
[toast],
);

// Fallback clipboard copy for non-secure contexts (HTTP, not HTTPS/localhost)
// navigator.clipboard.writeText() requires a secure context
const copyToClipboard = useCallback(async (text: string) => {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text);
return;
}
// Fallback: use a temporary textarea element
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.left = "-9999px";
textarea.style.top = "-9999px";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
}, []);

// Shared utility function to generate server config
const generateServerConfig = useCallback(() => {
if (transportType === "stdio") {
Expand Down Expand Up @@ -183,8 +206,7 @@ const Sidebar = ({
const handleCopyServerEntry = useCallback(() => {
try {
const configJson = generateMCPServerEntry();
navigator.clipboard
.writeText(configJson)
copyToClipboard(configJson)
.then(() => {
setCopiedServerEntry(true);

Expand Down Expand Up @@ -213,8 +235,7 @@ const Sidebar = ({
const handleCopyServerFile = useCallback(() => {
try {
const configJson = generateMCPServerFile();
navigator.clipboard
.writeText(configJson)
copyToClipboard(configJson)
.then(() => {
setCopiedServerFile(true);

Expand Down