Skip to content

AppleScript with Memory Integration

Henry edited this page Sep 17, 2025 · 1 revision

Context Example: AppleScript with Memory Integration

The Context Provider can be extended to support any MCP tool. Here's a real-world example of how we created context rules for [peakmojo/applescript-mcp](https://github.com/peakmojo/applescript-mcp) that integrates with the [MCP Memory Service](https://github.com/doobidoo/mcp-memory-service).

Use Case

AppleScript MCP provides maximum flexibility by allowing execution of any AppleScript code. By adding context rules that integrate with memory, we created an intelligent script management system that:

  • Searches for existing scripts before creating new ones
  • Stores successful scripts for reuse
  • Maintains consistency across sessions
  • Reduces token usage

Context File: applescript_context.json

Create this file in your /contexts directory:

{
  "tool_category": "applescript",
  "description": "AppleScript execution context with memory integration for reusable script management",
  "auto_convert": true,
  "memory_integration": {
    "workflow": {
      "step1": "Search memory for existing scripts: search_by_tag(['applescript', '<app>', '<action>'])",
      "step2": "Adapt found scripts or create new ones",
      "step3": "Store successful scripts with rich metadata",
      "step4": "Tag frequently used scripts as 'high-priority'"
    },
    "storage_pattern": {
      "content": "The AppleScript code with PARAMETER placeholders",
      "metadata": {
        "tags": ["applescript", "app:<n>", "action:<type>", "category:<category>"],
        "type": "applescript-template",
        "description": "Clear description of functionality",
        "parameters": ["list", "of", "replaceable", "parameters"]
      }
    },
    "tag_taxonomy": {
      "app_tags": ["app:calendar", "app:finder", "app:messages", "app:notes"],
      "action_tags": ["action:create", "action:read", "action:update", "action:delete"],
      "category_tags": ["category:productivity", "category:communication", "category:system"]
    }
  },
  "common_patterns": {
    "calendar_event": {
      "template": "tell application \"Calendar\"\n  tell calendar \"CALENDAR_NAME\"\n    make new event with properties {summary:\"EVENT_TITLE\"}\n  end tell\nend tell",
      "parameters": ["CALENDAR_NAME", "EVENT_TITLE"]
    }
  },
  "best_practices": {
    "security": {
      "no_hardcoded_passwords": true,
      "validate_file_paths": true,
      "check_permissions": true
    }
  },
  "metadata": {
    "version": "1.0.0",
    "applies_to_tools": ["execute_applescript", "applescript:*", "memory:*"],
    "dependencies": ["mcp-memory-service"]
  }
}

How It Works

  1. On Claude Desktop startup: Context is loaded automatically
  2. When user requests Mac automation: Claude checks memory for existing scripts
  3. Scripts are reused and adapted: Reducing token usage and maintaining consistency
  4. New scripts are stored: Building a personal automation library

Benefits

  • Cross-session persistence: Context survives Claude Desktop restarts
  • Intelligent automation: Scripts are reused rather than recreated
  • Growing knowledge base: Library expands based on actual usage
  • Token efficiency: Dramatic reduction in token usage for repeated tasks

Setup Instructions

  1. Install both MCP servers:

  2. Add the applescript_context.json file to your contexts directory

  3. Configure Claude Desktop to load both MCP servers

  4. Restart Claude Desktop

Example Workflow

User: "Create a calendar event for tomorrow at 2pm"
Claude: 
  1. Searches memory: search_by_tag(["applescript", "app:calendar", "action:create"])
  2. Finds existing template
  3. Adapts parameters for specific request
  4. Executes via execute_applescript
  5. Stores any new patterns discovered

This pattern can be adapted for any MCP tool that would benefit from memory-based template management and persistent context rules!