create_mailbox
Create a new mailbox folder in a Mail.app account. Specify the account name if multiple accounts are configured.
Instructions
Create a new mailbox (folder) in a Mail.app account.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name for the new mailbox/folder | |
| account | No | Account name to create it in. Required when multiple accounts are configured; use name from list_accounts_and_mailboxes. |
Implementation Reference
- src/tools/create_mailbox.ts:31-40 (handler)Handler function that executes the create_mailbox tool logic. Takes name (required) and account (optional), runs AppleScript to create a new mailbox in Mail.app.
async ({ name, account }) => { const result = await runAppleScript({ script: SCRIPT, args: { theMailboxName: name, theAcct: account ?? "", }, }); return { content: [{ type: "text", text: result }] }; }, - src/tools/create_mailbox.ts:5-8 (schema)Zod schema defining the input parameters: name (required string) and account (optional string).
const schema = { name: z.string().describe("Name for the new mailbox/folder"), account: z.string().optional().describe("Account name to create it in. Required when multiple accounts are configured; use name from list_accounts_and_mailboxes."), }; - src/tools/create_mailbox.ts:25-42 (registration)Registration function that registers the tool with the MCP server using server.tool().
export function register(server: McpServer): void { server.tool( "create_mailbox", "Create a new mailbox (folder) in a Mail.app account.", schema, { title: "Create Mailbox", readOnlyHint: false, destructiveHint: false }, async ({ name, account }) => { const result = await runAppleScript({ script: SCRIPT, args: { theMailboxName: name, theAcct: account ?? "", }, }); return { content: [{ type: "text", text: result }] }; }, ); } - src/server.ts:34-38 (registration)Call site in server.ts that invokes registerCreateMailbox to register the tool.
registerCreateMailbox(server); registerBulkMarkRead(server); registerGetUnsubscribeLink(server); registerListSenders(server); registerEmptyMailbox(server); - src/lib/applescript.ts:22-46 (helper)Helper utility that writes AppleScript to a temp file and executes it via osascript, securely passing arguments through argv.
export async function runAppleScript(opts: RunAppleScriptOptions): Promise<string> { const { script, args = {}, timeoutMs = 30_000 } = opts; const argNames = Object.keys(args); const argValues = argNames.map((n) => args[n]!); const bindings = argNames .map((name, i) => ` set ${name} to item ${i + 1} of argv`) .join("\n"); const wrapped = `on run argv\n${bindings}\n${script}\nend run\n`; const dir = await mkdtemp(path.join(tmpdir(), "mail-mcp-")); const scriptPath = path.join(dir, "script.applescript"); try { await writeFile(scriptPath, wrapped, "utf8"); const { stdout } = await execFileP("osascript", [scriptPath, ...argValues], { timeout: timeoutMs, maxBuffer: 10 * 1024 * 1024, }); return stdout.trimEnd(); } finally { await rm(dir, { recursive: true, force: true }).catch(() => {}); } }