Skip to main content
Glama
arslankhanali

Apple Notes MCP Server

update_note

Modify existing Apple Notes content by specifying the note name and providing new text, optionally selecting the account where the note is stored.

Instructions

Update the content of an existing note.

Args:
    note_name: Name of the note to update
    new_content: New content for the note
    account: Optional account name where the note is located

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
note_nameYes
new_contentYes
accountNo

Implementation Reference

  • The @mcp.tool() decorator registers and defines the handler for the 'update_note' tool. It escapes the note name and content, constructs an AppleScript to find and update the note's body (searching all accounts if no account specified), executes it via subprocess, and returns success/error messages.
    @mcp.tool()
    async def update_note(note_name: str, new_content: str, account: Optional[str] = None) -> str:
        """Update the content of an existing note.
        
        Args:
            note_name: Name of the note to update
            new_content: New content for the note
            account: Optional account name where the note is located
        """
        escaped_name = escape_applescript_string(note_name)
        escaped_content = escape_applescript_string(new_content)
        
        if account:
            script = f'''
            tell application "Notes"
                set accountName to "{escape_applescript_string(account)}"
                set noteName to "{escaped_name}"
                try
                    set targetAccount to account accountName
                    set targetNote to note noteName of targetAccount
                    set body of targetNote to "{escaped_content}"
                    return "SUCCESS"
                on error errMsg
                    return "ERROR: " & errMsg
                end try
            end tell
            '''
        else:
            script = f'''
            tell application "Notes"
                set noteName to "{escaped_name}"
                repeat with anAccount in accounts
                    try
                        set targetNote to note noteName of anAccount
                        set body of targetNote to "{escaped_content}"
                        return "SUCCESS"
                    end try
                end repeat
                return "ERROR: Note not found"
            end tell
            '''
        
        output, success = run_applescript(script)
        if not success or "ERROR" in output:
            return output if output else f"Failed to update note '{note_name}'."
        
        return f"Successfully updated note '{note_name}'."
  • Helper function used by update_note to execute AppleScript commands via subprocess and handle errors/timeouts.
    def run_applescript(script: str) -> tuple[str, bool]:
        """Run an AppleScript command and return the output."""
        try:
            result = subprocess.run(
                ["osascript", "-e", script],
                capture_output=True,
                text=True,
                timeout=30
            )
            if result.returncode == 0:
                return result.stdout.strip(), True
            else:
                error_msg = result.stderr.strip() or result.stdout.strip()
                return f"Error: {error_msg}", False
        except subprocess.TimeoutExpired:
            return "Error: AppleScript execution timed out", False
        except Exception as e:
            return f"Error: {str(e)}", False
  • Helper function used by update_note to properly escape strings for safe insertion into AppleScript.
    def escape_applescript_string(text: str) -> str:
        """Escape special characters for AppleScript strings."""
        # Replace backslashes, quotes, and newlines
        text = text.replace("\\", "\\\\")
        text = text.replace('"', '\\"')
        text = text.replace("\n", "\\n")
        return text

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/arslankhanali/apple-notes-mcp'

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