list_accounts_and_mailboxes
Retrieve all Mail.app accounts and their mailboxes, including unread email counts, to monitor inbox activity at a glance.
Instructions
List all configured Mail.app accounts and their mailboxes with unread counts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/accounts.ts:43-57 (handler)The register function defines the 'list_accounts_and_mailboxes' tool on the McpServer. It runs an AppleScript to iterate all Mail.app accounts and mailboxes, parses the output, and returns JSON with account names, user names, mailbox names, and unread counts.
export function register(server: McpServer): void { server.tool( "list_accounts_and_mailboxes", "List all configured Mail.app accounts and their mailboxes with unread counts.", {}, { title: "List Accounts and Mailboxes", readOnlyHint: true, destructiveHint: false }, async () => { const raw = await runAppleScript({ script: SCRIPT }); const accounts = parse(raw); return { content: [{ type: "text", text: JSON.stringify(accounts, null, 2) }], }; }, ); } - src/tools/accounts.ts:4-15 (helper)The AppleScript SCRIPT that lists all accounts and their mailboxes with unread counts, tab-separated, line-by-line.
const SCRIPT = ` set buf to "" tell application "Mail" repeat with acct in accounts set buf to buf & "ACCOUNT" & tab & (name of acct) & tab & (user name of acct) & linefeed repeat with mb in mailboxes of acct set buf to buf & "MAILBOX" & tab & (name of mb) & tab & ((unread count of mb) as string) & linefeed end repeat end repeat end tell return buf `; - src/tools/accounts.ts:27-41 (helper)The parse() function that converts the tab-separated AppleScript output into structured Account[] objects with nested Mailbox arrays.
function parse(raw: string): Account[] { const accounts: Account[] = []; let current: Account | null = null; for (const line of raw.split("\n")) { if (!line) continue; const [kind, a, b] = line.split("\t"); if (kind === "ACCOUNT") { current = { name: a ?? "", user: b ?? "", mailboxes: [] }; accounts.push(current); } else if (kind === "MAILBOX" && current) { current.mailboxes.push({ name: a ?? "", unread: Number(b) || 0 }); } } return accounts; } - src/tools/accounts.ts:17-25 (schema)TypeScript interfaces defining the Account and Mailbox shapes returned by the tool.
interface Mailbox { name: string; unread: number; } interface Account { name: string; user: string; mailboxes: Mailbox[]; } - src/server.ts:7-7 (registration)Import of the register function from accounts.ts.
import { register as registerAccounts } from "./tools/accounts.js"; - src/server.ts:27-27 (registration)Registration call that hooks the tool into the MCP server.
registerAccounts(server);