clipboard_write
Write text to the macOS clipboard for desktop automation tasks, enabling AI agents to copy data programmatically.
Instructions
Write text to the macOS clipboard.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>"
},
"name": "clipboard_write"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to write to the clipboard. |
Implementation Reference
- src/tools/clipboard.ts:56-73 (handler)The handler function that processes the clipboard_write tool request.
async function handleClipboardWrite( args: Record<string, unknown>, ): Promise<CallToolResult> { const parsed = ClipboardWriteInputSchema.parse(args); await clipboardWrite(parsed.text); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, length: parsed.text.length, }), }, ], }; } - src/tools/clipboard.ts:11-13 (schema)Input schema validation for clipboard_write.
const ClipboardWriteInputSchema = z.object({ text: z.string().max(100_000).describe("Text to write to the clipboard."), }); - src/tools/clipboard.ts:28-36 (registration)Tool definition for clipboard_write registration.
{ name: "clipboard_write", description: "Write text to the macOS clipboard.", inputSchema: zodToToolInputSchema(ClipboardWriteInputSchema), annotations: { readOnlyHint: false, destructiveHint: false, }, }, - src/helpers/clipboard.ts:28-51 (helper)Core utility that interfaces with macOS 'pbcopy' to write to the clipboard.
export async function clipboardWrite(text: string): Promise<void> { await new Promise<void>((resolve, reject) => { const proc = execFile( "pbcopy", [], { timeout: CLIPBOARD_TIMEOUT_MS }, (error: Error | null) => { if (error) { reject(error); } else { resolve(); } }, ); if (!proc.stdin) { reject(new Error("Failed to open stdin for pbcopy")); return; } proc.stdin.write(text); proc.stdin.end(); }); }