Skip to main content
Glama

type_text

Type text at cursor position using clipboard paste with Unicode support. Temporarily replaces clipboard contents; for secure fields, use clipboard_write + cmd+v alternative.

Instructions

Type text at the current cursor position using clipboard paste. Supports full Unicode including CJK characters and emoji. Temporarily replaces clipboard contents. Non-text clipboard content (images, files) will be lost permanently. If secure input is active (e.g. password fields), returns a note suggesting clipboard_write + press_key("cmd+v") as an alternative.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText to type. Supports full Unicode including CJK and emoji.

Implementation Reference

  • The handler function for the 'type_text' tool, which performs a copy-to-clipboard and paste operation to simulate typing.
    async function handleTypeText(
      args: Record<string, unknown>,
    ): Promise<CallToolResult> {
      const parsed = TypeTextInputSchema.parse(args);
    
      // Save current clipboard contents (best-effort)
      let oldClipboard = "";
      try {
        oldClipboard = await clipboardRead();
      } catch {
        // Clipboard may be empty or contain non-text data
      }
    
      // Write target text to clipboard
      await clipboardWrite(parsed.text);
    
      // Paste via AppleScript Cmd+V
      await execFileAsync(
        "osascript",
        [
          "-e",
          `tell application "System Events" to key code ${KEY_CODES.v} using command down`,
        ],
        { timeout: APPLESCRIPT_TIMEOUT_MS },
      );
    
      // Brief delay for paste to settle before restoring clipboard
      await new Promise((resolve) => setTimeout(resolve, PASTE_SETTLE_MS));
    
      // Restore previous clipboard contents (best-effort)
      try {
        await clipboardWrite(oldClipboard);
      } catch {
        // Best-effort restore
      }
    
      return {
        content: [
          {
            type: "text" as const,
            text: JSON.stringify({
              success: true,
              typed_length: parsed.text.length,
            }),
          },
        ],
      };
    }
  • Zod input schema definition for the 'type_text' tool.
    const TypeTextInputSchema = z.object({
      text: z
        .string()
        .min(1)
        .max(100_000)
        .describe("Text to type. Supports full Unicode including CJK and emoji."),
    });
  • Registration of the 'type_text' tool definition.
    {
      name: "type_text",
      description:
        'Type text at the current cursor position using clipboard paste. Supports full Unicode including CJK characters and emoji. Temporarily replaces clipboard contents. Non-text clipboard content (images, files) will be lost permanently. If secure input is active (e.g. password fields), returns a note suggesting clipboard_write + press_key("cmd+v") as an alternative.',
      inputSchema: zodToToolInputSchema(TypeTextInputSchema),
      annotations: {
        readOnlyHint: false,
        destructiveHint: true,
      },
    },

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