clipboard_set
Writes a string to the X11 CLIPBOARD selection, making it accessible for pasting in other applications.
Instructions
Write a string to the X11 CLIPBOARD selection.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes |
Implementation Reference
- server.js:314-330 (handler)Handler function that writes a string to the X11 CLIPBOARD selection using xclip. Spawns xclip detached with stdin piped, sends the text, and resolves after 150ms to let xclip become the selection owner.
function clipboardSet(args) { const missing = requireBin('xclip'); if (missing) return Promise.resolve(errorResult(missing)); if (typeof args.text !== 'string') return Promise.resolve(errorResult('text is required (string)')); return new Promise((resolve) => { const child = spawn(BIN.xclip, ['-selection', 'clipboard', '-i'], { detached: true, stdio: ['pipe', 'ignore', 'ignore'], }); child.on('error', (e) => resolve(errorResult(`clipboard_set failed: ${e.message}`))); child.unref(); try { child.stdin.end(args.text); } catch (_) {} // xclip forks once it has stdin; give it ~150ms to become the selection owner. setTimeout(() => resolve(textResult({ length: args.text.length })), 150); }); } - server.js:518-527 (schema)Tool definition/input schema for clipboard_set. Specifies name, description, annotations (destructiveHint: true), and inputSchema expecting a required 'text' string.
{ name: 'clipboard_set', description: 'Write a string to the X11 CLIPBOARD selection.', annotations: { title: 'Write clipboard', destructiveHint: true }, inputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'], }, }, - server.js:553-567 (registration)HANDLERS map that registers the clipboardSet function under the 'clipboard_set' key for JSON-RPC dispatch.
const HANDLERS = { screenshot, list_windows: listWindows, focus_window: focusWindow, move_window: moveWindow, close_window: closeWindow, mouse_move: mouseMove, mouse_click: mouseClick, mouse_drag: mouseDrag, mouse_scroll: mouseScroll, type_text: typeText, key_press: keyPress, clipboard_get: clipboardGet, clipboard_set: clipboardSet, launch_app: launchApp, - server.js:57-62 (helper)Helper function that checks if a required system binary is available. Used by clipboardSet to verify xclip is installed before proceeding.
function requireBin(name) { if (!BIN[name]) { return `Required system tool "${name}" is not installed. Install with: sudo apt install ${name === 'gnomeShot' ? 'gnome-screenshot' : name === 'xclip' ? 'xclip' : name === 'xdotool' ? 'xdotool' : 'wmctrl'}`; } return null; }