Skip to main content
Glama

messages_get_messages

Retrieve messages from macOS Messages app using AppleScript integration for LLM applications to access iMessage data.

Instructions

[iMessage operations] Get messages from the Messages app

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of messages to retrieve

Implementation Reference

  • Core implementation of messages_get_messages tool. Defines the 'get_messages' script in messages category, including input schema (limit parameter) and AppleScript generator that directly queries the iMessage SQLite database at ~/Library/Messages/chat.db to retrieve recent messages with sender, text, date, and chat info.
        {
          name: "get_messages",
          description: "Get messages from the Messages app",
          schema: {
            type: "object",
            properties: {
              limit: {
                type: "number",
                description: "Maximum number of messages to retrieve",
                default: 100
              }
            }
          },
          script: (args) => `
     on run
    	-- Path to the Messages database
    	set dbPath to (do shell script "echo ~/Library/Messages/chat.db")
    	
    	-- Create a temporary SQL file for our query
    	set tempFile to (do shell script "mktemp /tmp/imessage_query.XXXXXX")
    	
    	-- Write SQL query to temp file
    	do shell script "cat > " & quoted form of tempFile & " << 'EOF'
    SELECT
        datetime(message.date/1000000000 + strftime('%s', '2001-01-01'), 'unixepoch', 'localtime') as message_date,
        handle.id as sender,
        message.text as message_text,
        chat.display_name as chat_name
    FROM
        message
        LEFT JOIN handle ON message.handle_id = handle.ROWID
        LEFT JOIN chat_message_join ON message.ROWID = chat_message_join.message_id
        LEFT JOIN chat ON chat_message_join.chat_id = chat.ROWID
    ORDER BY
        message.date DESC
    LIMIT ${args.limit};
    EOF"
    	
    	-- Execute the query
    	set queryResult to do shell script "sqlite3 " & quoted form of dbPath & " < " & quoted form of tempFile
    	
    	-- Clean up temp file
    	do shell script "rm " & quoted form of tempFile
    	
    	-- Process and display results
    	set resultList to paragraphs of queryResult
    	set messageData to {}
    	
    	repeat with messageLine in resultList
    		set messageData to messageData & messageLine
    	end repeat
    	
    	return messageData
    end run
          `
        },
  • Dynamic registration of all category scripts as MCP tools in ListToolsRequestSchema handler, constructing tool name as `${category.name}_${script.name}` (e.g. messages_get_messages from messages.get_messages).
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: this.categories.flatMap((category) =>
        category.scripts.map((script) => ({
          name: `${category.name}_${script.name}`, // Changed from dot to underscore
          description: `[${category.description}] ${script.description}`,
          inputSchema: script.schema || {
            type: "object",
            properties: {},
          },
        })),
      ),
    }));
  • MCP CallToolRequestSchema execution handler for messages_get_messages. Parses tool name by splitting on '_', locates 'messages' category and 'get_messages' script, invokes script function with arguments to generate AppleScript, then executes via osascript.
    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);
  • src/index.ts:34-34 (registration)
    Registers the 'messages' ScriptCategory (containing get_messages script) with the AppleScriptFramework server, making messages_get_messages available as an MCP tool.
    server.addCategory(messagesCategory);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'iMessage operations' but doesn't specify permissions needed, rate limits, or what 'Get messages' entails (e.g., retrieval scope, format, or potential side effects). This leaves significant gaps for a tool that accesses personal data.

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

Conciseness4/5

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

The description is very concise with just one sentence, front-loading the core purpose. However, it could be more structured by explicitly separating the tool's scope from behavioral notes, though it avoids unnecessary verbosity.

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

Completeness2/5

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

Given the complexity of accessing personal messages and the lack of annotations or output schema, the description is insufficient. It doesn't cover critical aspects like data format, error handling, or privacy implications, making it incomplete for safe and effective use.

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 'limit' parameter fully documented. The description adds no additional parameter information beyond what's in the schema, so it meets the baseline score of 3 for high schema coverage.

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 ('messages from the Messages app'), making the purpose unambiguous. However, it doesn't differentiate from sibling tools like 'messages_list_chats' or 'messages_search_messages', which prevents a perfect score.

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?

No guidance is provided on when to use this tool versus alternatives like 'messages_list_chats' or 'messages_search_messages'. The description only states what it does, not when it's appropriate, leaving the agent to infer usage context.

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