Skip to main content
Glama

clipboard_get_clipboard

Retrieve text or file paths from the macOS clipboard using AppleScript commands. Access clipboard content directly within applications.

Instructions

[Clipboard management operations] Get current clipboard content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeNoType of clipboard content to gettext

Implementation Reference

  • Input schema for the clipboard_get_clipboard tool, specifying the optional 'type' parameter (text or file_paths).
    schema: {
      type: "object",
      properties: {
        type: {
          type: "string",
          enum: ["text", "file_paths"],
          description: "Type of clipboard content to get",
          default: "text",
        },
      },
    },
  • Handler function that generates the appropriate AppleScript code to retrieve clipboard content based on the input 'type'. For 'file_paths', it processes file URLs into POSIX paths; otherwise, returns text content.
    script: (args) => {
      if (args?.type === "file_paths") {
        return `
          tell application "System Events"
            try
              set theClipboard to the clipboard
              if theClipboard starts with "file://" then
                set AppleScript's text item delimiters to linefeed
                set filePaths to {}
                repeat with aPath in paragraphs of (the clipboard as string)
                  if aPath starts with "file://" then
                    set end of filePaths to (POSIX path of (aPath as alias))
                  end if
                end repeat
                return filePaths as string
              else
                return "No file paths in clipboard"
              end if
            on error errMsg
              return "Failed to get clipboard: " & errMsg
            end try
          end tell
        `;
      } else {
        return `
          tell application "System Events"
            try
              return (the clipboard as text)
            on error errMsg
              return "Failed to get clipboard: " & errMsg
            end try
          end tell
        `;
      }
    },
  • src/index.ts:28-28 (registration)
    Registers the clipboard category (imported from src/categories/clipboard.ts), which defines the get_clipboard script used as clipboard_get_clipboard tool.
    server.addCategory(clipboardCategory);
  • Tool name construction logic that creates 'clipboard_get_clipboard' from category 'clipboard' and script 'get_clipboard' when listing available tools.
    name: `${category.name}_${script.name}`, // Changed from dot to underscore
  • General tool execution handler that resolves 'clipboard_get_clipboard' to the clipboard category and get_clipboard script, invokes the handler function, executes the generated AppleScript, and returns the result.
    // Handle tool execution
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const toolName = request.params.name;
      this.log("info", "Tool execution requested", { 
        tool: toolName,
        hasArguments: !!request.params.arguments
      });
      
      try {
        // Split on underscore instead of dot
        const [categoryName, ...scriptNameParts] =
          toolName.split("_");
        const scriptName = scriptNameParts.join("_"); // Rejoin in case script name has underscores
    
        const category = this.categories.find((c) => c.name === categoryName);
        if (!category) {
          this.log("warning", "Category not found", { categoryName });
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Category not found: ${categoryName}`,
          );
        }
    
        const script = category.scripts.find((s) => s.name === scriptName);
        if (!script) {
          this.log("warning", "Script not found", { 
            categoryName, 
            scriptName 
          });
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Script not found: ${scriptName}`,
          );
        }
    
        this.log("debug", "Generating script content", { 
          categoryName, 
          scriptName,
          isFunction: typeof script.script === "function"
        });
        
        const scriptContent =
          typeof script.script === "function"
            ? script.script(request.params.arguments)
            : script.script;
    
        const result = await this.executeScript(scriptContent);
        
        this.log("info", "Tool execution completed successfully", { 
          tool: toolName,
          resultLength: result.length
        });
    
        return {
          content: [
            {
              type: "text",
              text: result,
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) {
          this.log("error", "MCP error during tool execution", { 
            tool: toolName,
            errorCode: error.code,
            errorMessage: error.message
          });
          throw error;
        }
    
        let errorMessage = "Unknown error occurred";
        if (error && typeof error === "object") {
          if ("message" in error && typeof error.message === "string") {
            errorMessage = error.message;
          } else if (error instanceof Error) {
            errorMessage = error.message;
          }
        } else if (typeof error === "string") {
          errorMessage = error;
        }
    
        this.log("error", "Error during tool execution", { 
          tool: toolName,
          errorMessage
        });
    
        return {
          content: [
            {
              type: "text",
              text: `Error: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Get') but doesn't describe what happens if the clipboard is empty, whether it requires specific permissions, or what format the content is returned in. For a tool with no annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just one sentence, front-loading the core action ('Get current clipboard content') without any wasted words. The bracketed context '[Clipboard management operations]' is minimal and doesn't detract from clarity. Every part of the description earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple tool (1 parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavioral aspects like error handling or return format. For a read operation with no annotations, it should ideally provide more context about what 'Get' entails (e.g., returns text or file paths as specified).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'type' parameter fully documented (enum values and default). The description adds no additional parameter semantics beyond what the schema provides, such as explaining the difference between 'text' and 'file_paths' content types. Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('current clipboard content'), making the purpose immediately understandable. It distinguishes from sibling tools like clipboard_clear_clipboard and clipboard_set_clipboard by focusing on retrieval rather than modification. However, it doesn't explicitly differentiate from other read operations like finder_get_selected_files or notes_get.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose this over other clipboard tools (e.g., clipboard_set_clipboard for writing) or other data retrieval tools. The context is implied (clipboard management), but no explicit usage scenarios or exclusions are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/joshrutkowski/applescript-mcp'

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