move_email
Moves a message to a destination mailbox using its RFC message-ID. Requires the exact mailbox name from list_accounts_and_mailboxes.
Instructions
Move a message to a different mailbox by RFC message-id. Use list_accounts_and_mailboxes to get exact mailbox names.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message_id | Yes | RFC message-id (with or without angle brackets) | |
| destination_mailbox | Yes | Exact mailbox name from list_accounts_and_mailboxes (slash-pathed for nested, e.g. 'Folders/Amtrak') | |
| destination_account | No | Account name to disambiguate if multiple accounts share the mailbox name |
Implementation Reference
- src/tools/move.ts:29-53 (handler)The main handler function that registers the 'move_email' tool on the MCP server. It receives message_id, destination_mailbox, and optional destination_account, then calls findMessageAndAct with an AppleScript action that moves the found message to the target mailbox.
export function register(server: McpServer): void { server.tool( "move_email", "Move a message to a different mailbox by RFC message-id. Use list_accounts_and_mailboxes to get exact mailbox names.", schema, { title: "Move Email", readOnlyHint: false, destructiveHint: false }, async ({ message_id, destination_mailbox, destination_account }) => { const result = await findMessageAndAct({ messageId: message_id, action: ACTION, extraArgs: { destMailbox: destination_mailbox, destAcct: destination_account ?? "", }, }); if (result === MESSAGE_NOT_FOUND) { return { content: [{ type: "text", text: `No message found with id ${message_id}` }], isError: true, }; } return { content: [{ type: "text", text: result }] }; }, ); } - src/tools/move.ts:5-9 (schema)Input schema for move_email tool: message_id (required string), destination_mailbox (required string), destination_account (optional string).
const schema = { message_id: z.string().describe("RFC message-id (with or without angle brackets)"), destination_mailbox: z.string().describe("Exact mailbox name from list_accounts_and_mailboxes (slash-pathed for nested, e.g. 'Folders/Amtrak')"), destination_account: z.string().optional().describe("Account name to disambiguate if multiple accounts share the mailbox name"), }; - src/tools/move.ts:13-27 (helper)The AppleScript snippet executed to perform the move. After findMessageAndAct binds the found message to 'foundMsg', this script searches accounts for the destination mailbox and moves the message.
const ACTION = ` set destMb to missing value repeat with acct in accounts if destAcct is "" or (name of acct) contains destAcct then try set destMb to mailbox destMailbox of acct exit repeat end try end if end repeat if destMb is missing value then return "destination not found" move foundMsg to destMb return "ok" `; - src/server.ts:12-18 (registration)Import and registration of the move_email tool in the main server file.
import { register as registerMove } from "./tools/move.js"; import { register as registerTrash } from "./tools/trash.js"; import { register as registerCreateMailbox } from "./tools/create_mailbox.js"; import { register as registerBulkMarkRead } from "./tools/bulk_mark_read.js"; import { register as registerGetUnsubscribeLink } from "./tools/get_unsubscribe_link.js"; import { register as registerListSenders } from "./tools/list_senders.js"; import { register as registerEmptyMailbox } from "./tools/empty_mailbox.js";