Skip to main content
Glama

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText to write to the clipboard.

Implementation Reference

  • 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,
            }),
          },
        ],
      };
    }
  • Input schema validation for clipboard_write.
    const ClipboardWriteInputSchema = z.object({
      text: z.string().max(100_000).describe("Text to write to the clipboard."),
    });
  • Tool definition for clipboard_write registration.
    {
      name: "clipboard_write",
      description: "Write text to the macOS clipboard.",
      inputSchema: zodToToolInputSchema(ClipboardWriteInputSchema),
      annotations: {
        readOnlyHint: false,
        destructiveHint: false,
      },
    },
  • 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();
      });
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/antbotlab/mac-use-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server