Skip to main content
Glama

mail_create_email

Generate and send a new email via Mail.app by specifying the recipient, subject, and body using AppleScript automation for macOS applications.

Instructions

[Mail operations] Create a new email in Mail.app

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bodyYesEmail body
recipientYesEmail recipient
subjectYesEmail subject

Implementation Reference

  • Handler function that generates AppleScript to create a new email draft in Apple Mail using a mailto URL with properly URL-encoded subject and body. Includes a custom urlEncode handler for safe encoding.
    script: (args) => ` set recipient to "${args.recipient}" set subject to "${args.subject}" set body to "${args.body}" -- URL encode subject and body set encodedSubject to my urlEncode(subject) set encodedBody to my urlEncode(body) -- Construct the mailto URL set mailtoURL to "mailto:" & recipient & "?subject=" & encodedSubject & "&body=" & encodedBody -- Use Apple Mail's 'mailto' command to create the email tell application "Mail" mailto mailtoURL activate end tell -- Handler to URL-encode text on urlEncode(theText) set theEncodedText to "" set theChars to every character of theText repeat with aChar in theChars set charCode to ASCII number aChar if charCode = 32 then set theEncodedText to theEncodedText & "%20" -- Space else if (charCode ≥ 48 and charCode ≤ 57) or (charCode ≥ 65 and charCode ≤ 90) or (charCode ≥ 97 and charCode ≤ 122) or charCode = 45 or charCode = 46 or charCode = 95 or charCode = 126 then -- Allowed characters: A-Z, a-z, 0-9, -, ., _, ~ set theEncodedText to theEncodedText & aChar else -- Convert to %HH format set hexCode to do shell script "printf '%02X' " & charCode set theEncodedText to theEncodedText & "%" & hexCode end if end repeat return theEncodedText end urlEncode `,
  • JSON Schema defining the input parameters for the mail_create_email tool: recipient, subject, and body as required strings.
    schema: { type: "object", properties: { recipient: { type: "string", description: "Email recipient", }, subject: { type: "string", description: "Email subject", }, body: { type: "string", description: "Email body", }, }, required: ["recipient", "subject", "body"], },
  • src/index.ts:31-31 (registration)
    Registers the 'mail' category (containing create_email script) with the MCP server framework.
    server.addCategory(mailCategory);
  • In the ListTools handler, constructs tool names as '{category}_{script}' e.g., 'mail_create_email'.
    category.scripts.map((script) => ({ name: `${category.name}_${script.name}`, // Changed from dot to underscore
  • In the CallTool handler, parses tool name 'mail_create_email' by splitting on '_' to find 'mail' category and 'create_email' script, then executes the script with arguments.
    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);

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