apple-mail-mcp 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +565 -206
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -77,6 +77,41 @@ const ATTACHMENTS_SCHEMA = z
|
|
|
77
77
|
.optional()
|
|
78
78
|
.describe("Files to attach: absolute paths (e.g. '/Users/me/report.pdf') and/or " +
|
|
79
79
|
"inline {filename, contentBase64} objects for content not on disk.");
|
|
80
|
+
// =============================================================================
|
|
81
|
+
// Shared Output Schemas (MCP outputSchema)
|
|
82
|
+
//
|
|
83
|
+
// Every tool below declares an MCP `outputSchema` so clients can know and
|
|
84
|
+
// validate the output shape. The SDK requires `structuredContent` on every
|
|
85
|
+
// success result once an outputSchema is present and validates it against the
|
|
86
|
+
// schema, so these schemas are intentionally PERMISSIVE — fields are optional
|
|
87
|
+
// unless they are provably always present on every success path, no `.strict()`
|
|
88
|
+
// is used (extra keys pass), and rows that vary across the AppleScript and IMAP
|
|
89
|
+
// backends use loose element types. Error responses are exempt from validation.
|
|
90
|
+
// =============================================================================
|
|
91
|
+
/** A message row in a list/search result. Loose: the AppleScript path emits a
|
|
92
|
+
* messageSummary while the IMAP path emits its own record, so allow any keys. */
|
|
93
|
+
const MESSAGE_ROW_SCHEMA = z.object({}).passthrough();
|
|
94
|
+
/** Shape returned by list/search style tools (messages + count + optional
|
|
95
|
+
* partial-coverage diagnostics). Diagnostics only appear on the AppleScript
|
|
96
|
+
* path, so they are optional. */
|
|
97
|
+
const LIST_OUTPUT_SCHEMA = {
|
|
98
|
+
messages: z.array(MESSAGE_ROW_SCHEMA).optional(),
|
|
99
|
+
count: z.number().optional(),
|
|
100
|
+
partial: z.boolean().optional(),
|
|
101
|
+
skippedLargeMailboxes: z.array(z.string()).optional(),
|
|
102
|
+
notSearchedMailboxes: z.array(z.string()).optional(),
|
|
103
|
+
timedOutAccounts: z.array(z.string()).optional(),
|
|
104
|
+
};
|
|
105
|
+
/** Shape returned by the batch count tools. */
|
|
106
|
+
const BATCH_COUNT_OUTPUT_SCHEMA = {
|
|
107
|
+
ok: z.boolean().optional(),
|
|
108
|
+
success: z.number().optional(),
|
|
109
|
+
failed: z.number().optional(),
|
|
110
|
+
mailbox: z.string().optional(),
|
|
111
|
+
};
|
|
112
|
+
/** A health/doctor check item — loose to accept both health-check
|
|
113
|
+
* ({name, passed, message}) and doctor ({name, status, detail}) items. */
|
|
114
|
+
const CHECK_ITEM_SCHEMA = z.object({}).passthrough();
|
|
80
115
|
// Read version from package.json to keep it in sync
|
|
81
116
|
const require = createRequire(import.meta.url);
|
|
82
117
|
const { version } = require("../package.json");
|
|
@@ -132,23 +167,27 @@ async function hybridBatchCounts(ids, appleFn, imapFn) {
|
|
|
132
167
|
// Message Tools
|
|
133
168
|
// =============================================================================
|
|
134
169
|
// --- search-messages ---
|
|
135
|
-
server.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.string()
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
.string()
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
170
|
+
server.registerTool("search-messages", {
|
|
171
|
+
description: "Use when: finding messages by query/sender/subject/date/read/flag filters and you need their ids for follow-up operations.\nReturns: matching messages with id, date, subject, sender, and read state (plus partial-coverage diagnostics when some mailboxes were skipped).\nDo not use when: you want a plain mailbox listing without filters (use list-messages), already have an id and want the body (use get-message), or want a whole conversation (use get-thread).\nPrefer this first to obtain the message ids that get-message/mark-as-read/delete-message/move-message and the batch tools require.",
|
|
172
|
+
inputSchema: {
|
|
173
|
+
query: z.string().optional().describe("Text to search for in subject, sender, or content"),
|
|
174
|
+
from: z
|
|
175
|
+
.string()
|
|
176
|
+
.optional()
|
|
177
|
+
.describe("Filter by sender (substring match against the full sender string, i.e. display name + address — not an exact address match)"),
|
|
178
|
+
subject: z.string().optional().describe("Filter by subject line (substring match)"),
|
|
179
|
+
mailbox: z
|
|
180
|
+
.string()
|
|
181
|
+
.optional()
|
|
182
|
+
.describe("Mailbox to search in (e.g., 'INBOX'). Omit to search all mailboxes."),
|
|
183
|
+
account: z.string().optional().describe("Account to search in (omit to search all accounts)"),
|
|
184
|
+
isRead: z.boolean().optional().describe("Filter by read status"),
|
|
185
|
+
isFlagged: z.boolean().optional().describe("Filter by flagged status"),
|
|
186
|
+
dateFrom: DATE_FILTER_SCHEMA.describe("Start date filter (e.g., 'January 1, 2026')"),
|
|
187
|
+
dateTo: DATE_FILTER_SCHEMA.describe("End date filter (e.g., 'March 1, 2026')"),
|
|
188
|
+
limit: z.number().optional().describe("Maximum number of results (default: 50)"),
|
|
189
|
+
},
|
|
190
|
+
outputSchema: LIST_OUTPUT_SCHEMA,
|
|
152
191
|
}, withErrorHandling(async ({ query, mailbox, account, limit = 50, dateFrom, dateTo, from, subject, isRead, isFlagged, }) => {
|
|
153
192
|
// IMAP backend (issue #43): server-side search when this account is
|
|
154
193
|
// explicitly configured for IMAP; otherwise fall through to AppleScript.
|
|
@@ -193,12 +232,21 @@ server.tool("search-messages", "Use when: finding messages by query/sender/subje
|
|
|
193
232
|
return successResponse(`Found ${messages.length} message(s):\n${messageList}${coverageBlock}`, structured);
|
|
194
233
|
}, "Error searching messages"));
|
|
195
234
|
// --- get-message ---
|
|
196
|
-
server.
|
|
197
|
-
id:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
235
|
+
server.registerTool("get-message", {
|
|
236
|
+
description: "Use when: reading the full body of one message whose id you already have (numeric or imap:…); set preferHtml to get the HTML body instead of plain text.\nReturns: the message subject and body (plain text by default, HTML when preferHtml is true).\nDo not use when: you don't yet have an id (use search-messages or list-messages first), or you want the whole conversation (use get-thread).",
|
|
237
|
+
inputSchema: {
|
|
238
|
+
id: MESSAGE_ID_SCHEMA,
|
|
239
|
+
preferHtml: z
|
|
240
|
+
.boolean()
|
|
241
|
+
.optional()
|
|
242
|
+
.describe("Return the HTML body (extracted from the message source) instead of plain text"),
|
|
243
|
+
},
|
|
244
|
+
outputSchema: {
|
|
245
|
+
id: z.string().optional(),
|
|
246
|
+
subject: z.string().optional(),
|
|
247
|
+
body: z.string().optional(),
|
|
248
|
+
isHtml: z.boolean().optional(),
|
|
249
|
+
},
|
|
202
250
|
}, withErrorHandling(({ id, preferHtml }) => routeMessage(id, {
|
|
203
251
|
// IMAP id (imap:…) → fetch via IMAP (#43 Phase 3); else AppleScript.
|
|
204
252
|
imap: () => imapGetMessage(id, preferHtml === true),
|
|
@@ -233,11 +281,20 @@ server.tool("get-message", "Use when: reading the full body of one message whose
|
|
|
233
281
|
fail: `Message with ID "${id}" not found`,
|
|
234
282
|
}), "Error retrieving message"));
|
|
235
283
|
// --- get-thread ---
|
|
236
|
-
server.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
284
|
+
server.registerTool("get-thread", {
|
|
285
|
+
description: "Use when: you have one message id and want the whole conversation it belongs to, oldest-first. With an imap: id it threads by References/Message-ID; otherwise it groups by normalized subject.\nReturns: the thread's normalized subject and its messages (id, date, subject, sender, read state).\nDo not use when: you only need the single message (use get-message) or are searching by arbitrary criteria (use search-messages).",
|
|
286
|
+
inputSchema: {
|
|
287
|
+
id: MESSAGE_ID_SCHEMA.describe("A message ID in the conversation (numeric or imap:…)"),
|
|
288
|
+
account: z.string().optional().describe("Account to search (omit to search all)"),
|
|
289
|
+
mailbox: z.string().optional().describe("Mailbox to search (omit to search all)"),
|
|
290
|
+
limit: z.number().optional().describe("Max messages in the thread (default 50)"),
|
|
291
|
+
},
|
|
292
|
+
outputSchema: {
|
|
293
|
+
subject: z.string().optional(),
|
|
294
|
+
messages: z.array(MESSAGE_ROW_SCHEMA).optional(),
|
|
295
|
+
count: z.number().optional(),
|
|
296
|
+
partial: z.boolean().optional(),
|
|
297
|
+
},
|
|
241
298
|
}, withErrorHandling(async ({ id, account, mailbox, limit = 50 }) => {
|
|
242
299
|
// True threading via References/Message-ID when we have an imap: id (I5);
|
|
243
300
|
// falls through to subject grouping if the server lacks HEADER search or
|
|
@@ -296,16 +353,20 @@ server.tool("get-thread", "Use when: you have one message id and want the whole
|
|
|
296
353
|
return successResponse(`Thread "${base}" — ${ordered.length} message(s), oldest first:\n${list}${coverageBlock}`, structured);
|
|
297
354
|
}, "Error retrieving thread"));
|
|
298
355
|
// --- list-messages ---
|
|
299
|
-
server.
|
|
300
|
-
mailbox:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
356
|
+
server.registerTool("list-messages", {
|
|
357
|
+
description: "Use when: browsing a mailbox's recent messages (optionally filtered by sender or unread-only) with pagination via limit/offset, and you need their ids.\nReturns: messages with id, date, subject, and sender (plus partial-coverage diagnostics when some mailboxes were skipped).\nDo not use when: you have specific search criteria like subject/date/flags (use search-messages) or already have an id and want the body (use get-message).\nLike search-messages, use this to obtain the ids that read/mark/delete/move and batch tools require.",
|
|
358
|
+
inputSchema: {
|
|
359
|
+
mailbox: z
|
|
360
|
+
.string()
|
|
361
|
+
.optional()
|
|
362
|
+
.describe("Mailbox to list messages from. Omit to list from all mailboxes."),
|
|
363
|
+
account: z.string().optional().describe("Account to list messages from"),
|
|
364
|
+
limit: z.number().optional().describe("Maximum number of messages (default: 50)"),
|
|
365
|
+
offset: z.number().optional().describe("Number of messages to skip (for pagination)"),
|
|
366
|
+
from: z.string().optional().describe("Filter by sender email address or name"),
|
|
367
|
+
unreadOnly: z.boolean().optional().describe("Only show unread messages"),
|
|
368
|
+
},
|
|
369
|
+
outputSchema: LIST_OUTPUT_SCHEMA,
|
|
309
370
|
}, withErrorHandling(async ({ mailbox, account, limit = 50, offset = 0, from, unreadOnly }) => {
|
|
310
371
|
// IMAP backend (issue #43): server-side listing when this account is
|
|
311
372
|
// explicitly configured for IMAP; otherwise fall through to AppleScript.
|
|
@@ -339,20 +400,29 @@ server.tool("list-messages", "Use when: browsing a mailbox's recent messages (op
|
|
|
339
400
|
return successResponse(`Found ${messages.length} message(s):\n${messageList}${coverageBlock}`, structured);
|
|
340
401
|
}, "Error listing messages"));
|
|
341
402
|
// --- send-email ---
|
|
342
|
-
server.
|
|
343
|
-
to:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
403
|
+
server.registerTool("send-email", {
|
|
404
|
+
description: "Use when: the user has explicitly confirmed they want to send a single email now to the given recipients (to/cc/bcc are arrays), optionally with attachments and a chosen transport.\nReturns: a confirmation naming the recipients and attachment count.\nDo not use when: the user wants to review first (use create-draft), is replying to or forwarding an existing message (use reply-to-message / forward-message), or wants per-recipient personalized copies (use send-serial-email).\nSafety: this SENDS real email immediately and it cannot be unsent — require explicit user confirmation of the exact recipients, subject, and body before calling. Prefer create-draft when there is any doubt.",
|
|
405
|
+
inputSchema: {
|
|
406
|
+
to: z.array(z.string()).min(1, "At least one recipient is required"),
|
|
407
|
+
subject: z.string().min(1, "Subject is required"),
|
|
408
|
+
body: z.string().min(1, "Body is required"),
|
|
409
|
+
cc: z.array(z.string()).optional().describe("CC recipients"),
|
|
410
|
+
bcc: z.array(z.string()).optional().describe("BCC recipients"),
|
|
411
|
+
account: z.string().optional().describe("Account to send from"),
|
|
412
|
+
attachments: ATTACHMENTS_SCHEMA,
|
|
413
|
+
transport: z
|
|
414
|
+
.enum(["applescript", "smtp"])
|
|
415
|
+
.optional()
|
|
416
|
+
.describe("Send transport. 'applescript' (default) sends through Mail.app. " +
|
|
417
|
+
"'smtp' submits clean MIME directly via SMTP, avoiding the macOS 15+ " +
|
|
418
|
+
"Mail.app <blockquote> wrapping (issue #12); requires APPLE_MAIL_MCP_SMTP_* env config."),
|
|
419
|
+
},
|
|
420
|
+
outputSchema: {
|
|
421
|
+
ok: z.boolean().optional(),
|
|
422
|
+
recipients: z.array(z.string()).optional(),
|
|
423
|
+
attachmentCount: z.number().optional(),
|
|
424
|
+
transport: z.string().optional(),
|
|
425
|
+
},
|
|
356
426
|
}, withErrorHandling(async ({ to, subject, body, cc, bcc, account, attachments, transport }) => {
|
|
357
427
|
const attachInfo = attachments?.length ? ` with ${attachments.length} attachment(s)` : "";
|
|
358
428
|
const attachmentCount = attachments?.length ?? 0;
|
|
@@ -380,32 +450,49 @@ server.tool("send-email", "Use when: the user has explicitly confirmed they want
|
|
|
380
450
|
});
|
|
381
451
|
}, "Error sending email"));
|
|
382
452
|
// --- send-serial-email ---
|
|
383
|
-
server.
|
|
384
|
-
recipients:
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
453
|
+
server.registerTool("send-serial-email", {
|
|
454
|
+
description: "Use when: the user has confirmed a mail-merge — sending individually personalized copies to many recipients (max 100), with {{Key}} placeholders in subject/body replaced per-recipient from each recipient's variables. Recipients do not see each other.\nReturns: a per-recipient sent/failed report with counts.\nDo not use when: sending one message to a shared recipient list (use send-email) or saving for review (use create-draft).\nSafety: this SENDS many real emails immediately and they cannot be unsent — require explicit user confirmation of the recipient list, the subject/body template, and the placeholder substitutions before calling.",
|
|
455
|
+
inputSchema: {
|
|
456
|
+
recipients: z
|
|
457
|
+
.array(z.object({
|
|
458
|
+
email: z.string().min(1, "Recipient email is required"),
|
|
459
|
+
variables: z
|
|
460
|
+
.record(z.string())
|
|
461
|
+
.describe("Placeholder values, e.g. { Name: 'Alice', Company: 'Acme' }"),
|
|
462
|
+
}))
|
|
463
|
+
.min(1, "At least one recipient is required")
|
|
464
|
+
.max(100, "Cannot send to more than 100 recipients in a single batch")
|
|
465
|
+
.describe("List of recipients with personalization variables (max 100)"),
|
|
466
|
+
subject: z
|
|
467
|
+
.string()
|
|
468
|
+
.min(1, "Subject is required")
|
|
469
|
+
.describe("Subject line — use {{Key}} for placeholders"),
|
|
470
|
+
body: z
|
|
471
|
+
.string()
|
|
472
|
+
.min(1, "Body is required")
|
|
473
|
+
.describe("Email body — use {{Key}} for placeholders"),
|
|
474
|
+
account: z.string().optional().describe("Account to send from"),
|
|
475
|
+
delayMs: z
|
|
476
|
+
.number()
|
|
477
|
+
.min(0)
|
|
478
|
+
.max(10000)
|
|
479
|
+
.optional()
|
|
480
|
+
.describe("Delay between sends in ms (default: 500, max: 10000)"),
|
|
481
|
+
},
|
|
482
|
+
outputSchema: {
|
|
483
|
+
ok: z.boolean().optional(),
|
|
484
|
+
sent: z.number().optional(),
|
|
485
|
+
failed: z.number().optional(),
|
|
486
|
+
results: z
|
|
487
|
+
.array(z
|
|
488
|
+
.object({
|
|
489
|
+
email: z.string().optional(),
|
|
490
|
+
success: z.boolean().optional(),
|
|
491
|
+
error: z.string().optional(),
|
|
492
|
+
})
|
|
493
|
+
.passthrough())
|
|
494
|
+
.optional(),
|
|
495
|
+
},
|
|
409
496
|
}, withErrorHandling(({ recipients, subject, body, account, delayMs }) => {
|
|
410
497
|
const results = mailManager.sendSerialEmail(recipients, subject, body, account, delayMs);
|
|
411
498
|
const successCount = results.filter((r) => r.success).length;
|
|
@@ -430,14 +517,22 @@ server.tool("send-serial-email", "Use when: the user has confirmed a mail-merge
|
|
|
430
517
|
}
|
|
431
518
|
}, "Error sending serial emails"));
|
|
432
519
|
// --- create-draft ---
|
|
433
|
-
server.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
520
|
+
server.registerTool("create-draft", {
|
|
521
|
+
description: "Use when: composing an email the user should review in Mail.app before sending — the safe default for any new message (to/cc/bcc are arrays, optional attachments).\nReturns: a confirmation that the draft was created, with recipients and attachment count.\nDo not use when: the user has already confirmed they want it sent now (use send-email).\nSafety: low risk — creates a draft only and sends nothing; the user must open Mail.app and send it themselves.",
|
|
522
|
+
inputSchema: {
|
|
523
|
+
to: z.array(z.string()).min(1, "At least one recipient is required"),
|
|
524
|
+
subject: z.string().min(1, "Subject is required"),
|
|
525
|
+
body: z.string().min(1, "Body is required"),
|
|
526
|
+
cc: z.array(z.string()).optional().describe("CC recipients"),
|
|
527
|
+
bcc: z.array(z.string()).optional().describe("BCC recipients"),
|
|
528
|
+
account: z.string().optional().describe("Account to create draft in"),
|
|
529
|
+
attachments: ATTACHMENTS_SCHEMA,
|
|
530
|
+
},
|
|
531
|
+
outputSchema: {
|
|
532
|
+
ok: z.boolean().optional(),
|
|
533
|
+
recipients: z.array(z.string()).optional(),
|
|
534
|
+
attachmentCount: z.number().optional(),
|
|
535
|
+
},
|
|
441
536
|
}, withErrorHandling(({ to, subject, body, cc, bcc, account, attachments }) => {
|
|
442
537
|
const success = mailManager.createDraft(to, subject, body, cc, bcc, account, attachments);
|
|
443
538
|
if (!success) {
|
|
@@ -452,11 +547,23 @@ server.tool("create-draft", "Use when: composing an email the user should review
|
|
|
452
547
|
});
|
|
453
548
|
}, "Error creating draft"));
|
|
454
549
|
// --- reply-to-message ---
|
|
455
|
-
server.
|
|
456
|
-
id:
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
550
|
+
server.registerTool("reply-to-message", {
|
|
551
|
+
description: "Use when: replying to an existing message by id, preserving its threading headers. Set replyAll for all recipients; set send=false to save as a draft instead of sending.\nReturns: a confirmation that the reply was sent or saved as a draft.\nDo not use when: composing a brand-new message (use send-email / create-draft) or forwarding to new recipients (use forward-message).\nSafety: with the default send=true this SENDS real email immediately and cannot be unsent — require explicit user confirmation of the recipients and body, or pass send=false to let the user review.",
|
|
552
|
+
inputSchema: {
|
|
553
|
+
id: MESSAGE_ID_SCHEMA,
|
|
554
|
+
body: z.string().min(1, "Reply body is required"),
|
|
555
|
+
replyAll: z.boolean().optional().default(false).describe("Reply to all recipients"),
|
|
556
|
+
send: z
|
|
557
|
+
.boolean()
|
|
558
|
+
.optional()
|
|
559
|
+
.default(true)
|
|
560
|
+
.describe("Send immediately (false = save as draft)"),
|
|
561
|
+
},
|
|
562
|
+
outputSchema: {
|
|
563
|
+
ok: z.boolean().optional(),
|
|
564
|
+
sent: z.boolean().optional(),
|
|
565
|
+
id: z.string().optional(),
|
|
566
|
+
},
|
|
460
567
|
}, withErrorHandling(({ id, body, replyAll, send }) => {
|
|
461
568
|
const success = mailManager.replyToMessage(id, body, replyAll, send);
|
|
462
569
|
if (!success) {
|
|
@@ -469,11 +576,24 @@ server.tool("reply-to-message", "Use when: replying to an existing message by id
|
|
|
469
576
|
});
|
|
470
577
|
}, "Error replying to message"));
|
|
471
578
|
// --- forward-message ---
|
|
472
|
-
server.
|
|
473
|
-
id:
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
579
|
+
server.registerTool("forward-message", {
|
|
580
|
+
description: "Use when: forwarding an existing message (by id) to new recipients (to is an array), with an optional body to prepend. Set send=false to save as a draft.\nReturns: a confirmation that the message was forwarded or saved as a draft.\nDo not use when: replying to the sender/recipients (use reply-to-message) or composing a new message (use send-email / create-draft).\nSafety: with the default send=true this SENDS real email immediately and cannot be unsent — require explicit user confirmation of the recipients and any prepended body, or pass send=false to let the user review.",
|
|
581
|
+
inputSchema: {
|
|
582
|
+
id: MESSAGE_ID_SCHEMA,
|
|
583
|
+
to: z.array(z.string()).min(1, "At least one recipient is required"),
|
|
584
|
+
body: z.string().optional().describe("Optional message to prepend"),
|
|
585
|
+
send: z
|
|
586
|
+
.boolean()
|
|
587
|
+
.optional()
|
|
588
|
+
.default(true)
|
|
589
|
+
.describe("Send immediately (false = save as draft)"),
|
|
590
|
+
},
|
|
591
|
+
outputSchema: {
|
|
592
|
+
ok: z.boolean().optional(),
|
|
593
|
+
sent: z.boolean().optional(),
|
|
594
|
+
recipients: z.array(z.string()).optional(),
|
|
595
|
+
id: z.string().optional(),
|
|
596
|
+
},
|
|
477
597
|
}, withErrorHandling(({ id, to, body, send }) => {
|
|
478
598
|
const success = mailManager.forwardMessage(id, to, body, send);
|
|
479
599
|
if (!success) {
|
|
@@ -482,8 +602,12 @@ server.tool("forward-message", "Use when: forwarding an existing message (by id)
|
|
|
482
602
|
return successResponse(send ? `Message forwarded to ${to.join(", ")}` : "Forward saved as draft", { ok: true, sent: send, recipients: to, id });
|
|
483
603
|
}, "Error forwarding message"));
|
|
484
604
|
// --- mark-as-read ---
|
|
485
|
-
server.
|
|
486
|
-
id:
|
|
605
|
+
server.registerTool("mark-as-read", {
|
|
606
|
+
description: "Use when: marking a single message (by id) as read.\nReturns: a confirmation that the message was marked read.\nDo not use when: marking several at once (use batch-mark-as-read) or marking unread (use mark-as-unread). Get the id from search-messages or list-messages first.",
|
|
607
|
+
inputSchema: {
|
|
608
|
+
id: MESSAGE_ID_SCHEMA,
|
|
609
|
+
},
|
|
610
|
+
outputSchema: { ok: z.boolean().optional(), id: z.string().optional() },
|
|
487
611
|
}, withErrorHandling(({ id }) => routeMessage(id, {
|
|
488
612
|
imap: () => imapMarkRead(id),
|
|
489
613
|
apple: () => mailManager.markAsRead(id)
|
|
@@ -494,8 +618,12 @@ server.tool("mark-as-read", "Use when: marking a single message (by id) as read.
|
|
|
494
618
|
structured: { ok: true, id },
|
|
495
619
|
}), "Error marking message as read"));
|
|
496
620
|
// --- mark-as-unread ---
|
|
497
|
-
server.
|
|
498
|
-
id:
|
|
621
|
+
server.registerTool("mark-as-unread", {
|
|
622
|
+
description: "Use when: marking a single message (by id) as unread.\nReturns: a confirmation that the message was marked unread.\nDo not use when: marking several at once (use batch-mark-as-unread) or marking read (use mark-as-read). Get the id from search-messages or list-messages first.",
|
|
623
|
+
inputSchema: {
|
|
624
|
+
id: MESSAGE_ID_SCHEMA,
|
|
625
|
+
},
|
|
626
|
+
outputSchema: { ok: z.boolean().optional(), id: z.string().optional() },
|
|
499
627
|
}, withErrorHandling(({ id }) => routeMessage(id, {
|
|
500
628
|
imap: () => imapMarkUnread(id),
|
|
501
629
|
apple: () => mailManager.markAsUnread(id)
|
|
@@ -506,8 +634,12 @@ server.tool("mark-as-unread", "Use when: marking a single message (by id) as unr
|
|
|
506
634
|
structured: { ok: true, id },
|
|
507
635
|
}), "Error marking message as unread"));
|
|
508
636
|
// --- flag-message ---
|
|
509
|
-
server.
|
|
510
|
-
id:
|
|
637
|
+
server.registerTool("flag-message", {
|
|
638
|
+
description: "Use when: flagging a single message (by id).\nReturns: a confirmation that the message was flagged.\nDo not use when: flagging several at once (use batch-flag-messages) or removing a flag (use unflag-message). Get the id from search-messages or list-messages first.",
|
|
639
|
+
inputSchema: {
|
|
640
|
+
id: MESSAGE_ID_SCHEMA,
|
|
641
|
+
},
|
|
642
|
+
outputSchema: { ok: z.boolean().optional(), id: z.string().optional() },
|
|
511
643
|
}, withErrorHandling(({ id }) => routeMessage(id, {
|
|
512
644
|
imap: () => imapFlagMessage(id),
|
|
513
645
|
apple: () => mailManager.flagMessage(id)
|
|
@@ -518,8 +650,12 @@ server.tool("flag-message", "Use when: flagging a single message (by id).\nRetur
|
|
|
518
650
|
structured: { ok: true, id },
|
|
519
651
|
}), "Error flagging message"));
|
|
520
652
|
// --- unflag-message ---
|
|
521
|
-
server.
|
|
522
|
-
id:
|
|
653
|
+
server.registerTool("unflag-message", {
|
|
654
|
+
description: "Use when: removing the flag from a single message (by id).\nReturns: a confirmation that the message was unflagged.\nDo not use when: unflagging several at once (use batch-unflag-messages) or adding a flag (use flag-message). Get the id from search-messages or list-messages first.",
|
|
655
|
+
inputSchema: {
|
|
656
|
+
id: MESSAGE_ID_SCHEMA,
|
|
657
|
+
},
|
|
658
|
+
outputSchema: { ok: z.boolean().optional(), id: z.string().optional() },
|
|
523
659
|
}, withErrorHandling(({ id }) => routeMessage(id, {
|
|
524
660
|
imap: () => imapUnflagMessage(id),
|
|
525
661
|
apple: () => mailManager.unflagMessage(id)
|
|
@@ -530,8 +666,12 @@ server.tool("unflag-message", "Use when: removing the flag from a single message
|
|
|
530
666
|
structured: { ok: true, id },
|
|
531
667
|
}), "Error unflagging message"));
|
|
532
668
|
// --- delete-message ---
|
|
533
|
-
server.
|
|
534
|
-
id:
|
|
669
|
+
server.registerTool("delete-message", {
|
|
670
|
+
description: "Use when: deleting a single message by id (moves it to Trash).\nReturns: a confirmation that the message was deleted.\nDo not use when: deleting several at once (use batch-delete-messages) or just filing it away (use move-message).\nSafety: destructive — require explicit user confirmation, and search-messages/list-messages first to confirm you have the right id before deleting.",
|
|
671
|
+
inputSchema: {
|
|
672
|
+
id: MESSAGE_ID_SCHEMA,
|
|
673
|
+
},
|
|
674
|
+
outputSchema: { ok: z.boolean().optional(), id: z.string().optional() },
|
|
535
675
|
}, withErrorHandling(({ id }) => routeMessage(id, {
|
|
536
676
|
imap: () => imapDeleteMessageById(id),
|
|
537
677
|
apple: () => {
|
|
@@ -545,10 +685,18 @@ server.tool("delete-message", "Use when: deleting a single message by id (moves
|
|
|
545
685
|
structured: { ok: true, id },
|
|
546
686
|
}), "Error deleting message"));
|
|
547
687
|
// --- move-message ---
|
|
548
|
-
server.
|
|
549
|
-
id:
|
|
550
|
-
|
|
551
|
-
|
|
688
|
+
server.registerTool("move-message", {
|
|
689
|
+
description: "Use when: moving a single message (by id) into another mailbox/folder, e.g. archiving or filing.\nReturns: a confirmation naming the destination mailbox.\nDo not use when: moving several at once (use batch-move-messages) or deleting (use delete-message). Use list-mailboxes to confirm the destination name exists.\nSafety: moves a real message between folders — confirm the destination mailbox, and search-messages/list-messages first to confirm the id.",
|
|
690
|
+
inputSchema: {
|
|
691
|
+
id: MESSAGE_ID_SCHEMA,
|
|
692
|
+
mailbox: z.string().min(1, "Destination mailbox is required"),
|
|
693
|
+
account: z.string().optional().describe("Account containing the destination mailbox"),
|
|
694
|
+
},
|
|
695
|
+
outputSchema: {
|
|
696
|
+
ok: z.boolean().optional(),
|
|
697
|
+
id: z.string().optional(),
|
|
698
|
+
mailbox: z.string().optional(),
|
|
699
|
+
},
|
|
552
700
|
}, withErrorHandling(({ id, mailbox, account }) => routeMessage(id, {
|
|
553
701
|
imap: () => imapMoveMessageById(id, mailbox),
|
|
554
702
|
apple: () => {
|
|
@@ -562,8 +710,12 @@ server.tool("move-message", "Use when: moving a single message (by id) into anot
|
|
|
562
710
|
structured: { ok: true, id, mailbox },
|
|
563
711
|
}), "Error moving message"));
|
|
564
712
|
// --- batch-delete-messages ---
|
|
565
|
-
server.
|
|
566
|
-
ids:
|
|
713
|
+
server.registerTool("batch-delete-messages", {
|
|
714
|
+
description: "Use when: deleting multiple messages in one call (1–100 ids; moves them to Trash).\nReturns: counts of how many were deleted and how many failed.\nDo not use when: deleting just one (use delete-message) or filing messages away (use batch-move-messages).\nSafety: destructive and applies to many messages at once — require explicit user confirmation, and search-messages/list-messages first to confirm every id is correct before deleting.",
|
|
715
|
+
inputSchema: {
|
|
716
|
+
ids: BATCH_IDS_SCHEMA,
|
|
717
|
+
},
|
|
718
|
+
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
567
719
|
}, withErrorHandling(async ({ ids }) => {
|
|
568
720
|
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchDeleteMessages(n), (im) => imapBatchDelete(im));
|
|
569
721
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount };
|
|
@@ -578,10 +730,14 @@ server.tool("batch-delete-messages", "Use when: deleting multiple messages in on
|
|
|
578
730
|
}
|
|
579
731
|
}, "Error batch deleting messages"));
|
|
580
732
|
// --- batch-move-messages ---
|
|
581
|
-
server.
|
|
582
|
-
ids:
|
|
583
|
-
|
|
584
|
-
|
|
733
|
+
server.registerTool("batch-move-messages", {
|
|
734
|
+
description: "Use when: moving multiple messages (1–100 ids) into the same destination mailbox/folder in one call, e.g. bulk archiving.\nReturns: counts of how many were moved and how many failed.\nDo not use when: moving just one (use move-message) or deleting (use batch-delete-messages). Use list-mailboxes to confirm the destination name exists.\nSafety: moves many real messages at once — confirm the destination mailbox, and search-messages/list-messages first to confirm the ids.",
|
|
735
|
+
inputSchema: {
|
|
736
|
+
ids: BATCH_IDS_SCHEMA,
|
|
737
|
+
mailbox: z.string().min(1, "Destination mailbox is required"),
|
|
738
|
+
account: z.string().optional().describe("Account containing the destination mailbox"),
|
|
739
|
+
},
|
|
740
|
+
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
585
741
|
}, withErrorHandling(async ({ ids, mailbox, account }) => {
|
|
586
742
|
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchMoveMessages(n, mailbox, account), (im) => imapBatchMove(im, mailbox, { account }));
|
|
587
743
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount, mailbox };
|
|
@@ -596,8 +752,12 @@ server.tool("batch-move-messages", "Use when: moving multiple messages (1–100
|
|
|
596
752
|
}
|
|
597
753
|
}, "Error batch moving messages"));
|
|
598
754
|
// --- batch-mark-as-read ---
|
|
599
|
-
server.
|
|
600
|
-
ids:
|
|
755
|
+
server.registerTool("batch-mark-as-read", {
|
|
756
|
+
description: "Use when: marking multiple messages (1–100 ids) as read in one call.\nReturns: counts of how many were marked read and how many failed.\nDo not use when: marking just one (use mark-as-read) or marking unread (use batch-mark-as-unread). Get the ids from search-messages or list-messages first.",
|
|
757
|
+
inputSchema: {
|
|
758
|
+
ids: BATCH_IDS_SCHEMA,
|
|
759
|
+
},
|
|
760
|
+
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
601
761
|
}, withErrorHandling(async ({ ids }) => {
|
|
602
762
|
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchMarkAsRead(n), (im) => imapBatchMarkRead(im));
|
|
603
763
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount };
|
|
@@ -612,8 +772,12 @@ server.tool("batch-mark-as-read", "Use when: marking multiple messages (1–100
|
|
|
612
772
|
}
|
|
613
773
|
}, "Error batch marking messages as read"));
|
|
614
774
|
// --- batch-mark-as-unread ---
|
|
615
|
-
server.
|
|
616
|
-
ids:
|
|
775
|
+
server.registerTool("batch-mark-as-unread", {
|
|
776
|
+
description: "Use when: marking multiple messages (1–100 ids) as unread in one call.\nReturns: counts of how many were marked unread and how many failed.\nDo not use when: marking just one (use mark-as-unread) or marking read (use batch-mark-as-read). Get the ids from search-messages or list-messages first.",
|
|
777
|
+
inputSchema: {
|
|
778
|
+
ids: BATCH_IDS_SCHEMA,
|
|
779
|
+
},
|
|
780
|
+
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
617
781
|
}, withErrorHandling(async ({ ids }) => {
|
|
618
782
|
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchMarkAsUnread(n), (im) => imapBatchMarkUnread(im));
|
|
619
783
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount };
|
|
@@ -628,8 +792,12 @@ server.tool("batch-mark-as-unread", "Use when: marking multiple messages (1–10
|
|
|
628
792
|
}
|
|
629
793
|
}, "Error batch marking messages as unread"));
|
|
630
794
|
// --- batch-flag-messages ---
|
|
631
|
-
server.
|
|
632
|
-
ids:
|
|
795
|
+
server.registerTool("batch-flag-messages", {
|
|
796
|
+
description: "Use when: flagging multiple messages (1–100 ids) in one call.\nReturns: counts of how many were flagged and how many failed.\nDo not use when: flagging just one (use flag-message) or removing flags (use batch-unflag-messages). Get the ids from search-messages or list-messages first.",
|
|
797
|
+
inputSchema: {
|
|
798
|
+
ids: BATCH_IDS_SCHEMA,
|
|
799
|
+
},
|
|
800
|
+
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
633
801
|
}, withErrorHandling(async ({ ids }) => {
|
|
634
802
|
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchFlagMessages(n), (im) => imapBatchFlag(im));
|
|
635
803
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount };
|
|
@@ -644,8 +812,12 @@ server.tool("batch-flag-messages", "Use when: flagging multiple messages (1–10
|
|
|
644
812
|
}
|
|
645
813
|
}, "Error batch flagging messages"));
|
|
646
814
|
// --- batch-unflag-messages ---
|
|
647
|
-
server.
|
|
648
|
-
ids:
|
|
815
|
+
server.registerTool("batch-unflag-messages", {
|
|
816
|
+
description: "Use when: removing flags from multiple messages (1–100 ids) in one call.\nReturns: counts of how many were unflagged and how many failed.\nDo not use when: unflagging just one (use unflag-message) or adding flags (use batch-flag-messages). Get the ids from search-messages or list-messages first.",
|
|
817
|
+
inputSchema: {
|
|
818
|
+
ids: BATCH_IDS_SCHEMA,
|
|
819
|
+
},
|
|
820
|
+
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
649
821
|
}, withErrorHandling(async ({ ids }) => {
|
|
650
822
|
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchUnflagMessages(n), (im) => imapBatchUnflag(im));
|
|
651
823
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount };
|
|
@@ -660,8 +832,15 @@ server.tool("batch-unflag-messages", "Use when: removing flags from multiple mes
|
|
|
660
832
|
}
|
|
661
833
|
}, "Error batch unflagging messages"));
|
|
662
834
|
// --- list-attachments ---
|
|
663
|
-
server.
|
|
664
|
-
id:
|
|
835
|
+
server.registerTool("list-attachments", {
|
|
836
|
+
description: "Use when: enumerating a message's attachments (by id) to discover their names, MIME types, and sizes — typically before saving or fetching one.\nReturns: each attachment's name, MIME type, and size, plus a count.\nDo not use when: you want the bytes (use fetch-attachment for inline base64, or save-attachment to write to disk). Get the message id from search-messages or list-messages first.",
|
|
837
|
+
inputSchema: {
|
|
838
|
+
id: MESSAGE_ID_SCHEMA,
|
|
839
|
+
},
|
|
840
|
+
outputSchema: {
|
|
841
|
+
attachments: z.array(z.object({}).passthrough()).optional(),
|
|
842
|
+
count: z.number().optional(),
|
|
843
|
+
},
|
|
665
844
|
}, withErrorHandling(async ({ id }) => {
|
|
666
845
|
// IMAP (I1): BODYSTRUCTURE enumerates parts (incl. MIME attachments
|
|
667
846
|
// AppleScript can't see) without downloading the message.
|
|
@@ -686,10 +865,18 @@ server.tool("list-attachments", "Use when: enumerating a message's attachments (
|
|
|
686
865
|
return successResponse(`Found ${attachments.length} attachment(s):\n${attachmentList}`, structured);
|
|
687
866
|
}, "Error listing attachments"));
|
|
688
867
|
// --- save-attachment ---
|
|
689
|
-
server.
|
|
690
|
-
id:
|
|
691
|
-
|
|
692
|
-
|
|
868
|
+
server.registerTool("save-attachment", {
|
|
869
|
+
description: "Use when: writing one of a message's attachments to disk, by message id and attachmentName, into the savePath directory (saved as savePath/attachmentName).\nReturns: a confirmation of the saved file path.\nDo not use when: you don't know the attachment name (use list-attachments first) or want the bytes inline rather than on disk (use fetch-attachment).\nSafety: writes a file to disk — savePath must be a directory inside the configured allowed roots, and attachmentName may not contain path separators or '..'; calls outside those constraints are rejected.",
|
|
870
|
+
inputSchema: {
|
|
871
|
+
id: MESSAGE_ID_SCHEMA,
|
|
872
|
+
attachmentName: z.string().min(1, "Attachment name is required"),
|
|
873
|
+
savePath: z.string().min(1, "Save directory path is required"),
|
|
874
|
+
},
|
|
875
|
+
outputSchema: {
|
|
876
|
+
ok: z.boolean().optional(),
|
|
877
|
+
attachmentName: z.string().optional(),
|
|
878
|
+
savedPath: z.string().optional(),
|
|
879
|
+
},
|
|
693
880
|
}, withErrorHandling(async ({ id, attachmentName, savePath }) => {
|
|
694
881
|
// IMAP (I1): fetch the part's bytes via IMAP, then write into savePath (a
|
|
695
882
|
// directory) as savePath/attachmentName — mirroring the AppleScript path,
|
|
@@ -725,9 +912,18 @@ server.tool("save-attachment", "Use when: writing one of a message's attachments
|
|
|
725
912
|
});
|
|
726
913
|
}, "Error saving attachment"));
|
|
727
914
|
// --- fetch-attachment ---
|
|
728
|
-
server.
|
|
729
|
-
id:
|
|
730
|
-
|
|
915
|
+
server.registerTool("fetch-attachment", {
|
|
916
|
+
description: "Use when: retrieving an attachment's raw bytes inline as base64 (by message id and attachmentName), e.g. to process its contents without touching disk.\nReturns: the attachment's bytes base64-encoded, with its size and (for IMAP) MIME type.\nDo not use when: you don't know the attachment name (use list-attachments first) or you just want it saved to disk (use save-attachment).",
|
|
917
|
+
inputSchema: {
|
|
918
|
+
id: MESSAGE_ID_SCHEMA,
|
|
919
|
+
attachmentName: z.string().min(1, "Attachment name is required"),
|
|
920
|
+
},
|
|
921
|
+
outputSchema: {
|
|
922
|
+
attachmentName: z.string().optional(),
|
|
923
|
+
bytes: z.number().optional(),
|
|
924
|
+
mimeType: z.string().optional(),
|
|
925
|
+
contentBase64: z.string().optional(),
|
|
926
|
+
},
|
|
731
927
|
}, withErrorHandling(async ({ id, attachmentName }) => {
|
|
732
928
|
// Returns the attachment bytes as base64 (B4) — the read counterpart to
|
|
733
929
|
// sending inline base64 content. IMAP (I1) fetches the part directly; numeric
|
|
@@ -749,8 +945,15 @@ server.tool("fetch-attachment", "Use when: retrieving an attachment's raw bytes
|
|
|
749
945
|
// Mailbox Tools
|
|
750
946
|
// =============================================================================
|
|
751
947
|
// --- list-mailboxes ---
|
|
752
|
-
server.
|
|
753
|
-
|
|
948
|
+
server.registerTool("list-mailboxes", {
|
|
949
|
+
description: "Use when: discovering the mailbox/folder names (and unread/message counts) available in an account, e.g. before moving messages or searching a specific mailbox.\nReturns: each mailbox's name with its unread (and, for IMAP, total message) count, plus a count.\nDo not use when: you want the messages inside a mailbox (use list-messages or search-messages) or the list of accounts (use list-accounts).",
|
|
950
|
+
inputSchema: {
|
|
951
|
+
account: z.string().optional().describe("Account to list mailboxes from"),
|
|
952
|
+
},
|
|
953
|
+
outputSchema: {
|
|
954
|
+
mailboxes: z.array(z.object({}).passthrough()).optional(),
|
|
955
|
+
count: z.number().optional(),
|
|
956
|
+
},
|
|
754
957
|
}, withErrorHandling(async ({ account }) => {
|
|
755
958
|
// IMAP (I6): LIST + per-mailbox STATUS — sees the true server hierarchy and
|
|
756
959
|
// authoritative counts; falls back to AppleScript for non-IMAP accounts.
|
|
@@ -778,9 +981,17 @@ server.tool("list-mailboxes", "Use when: discovering the mailbox/folder names (a
|
|
|
778
981
|
return successResponse(`Found ${mailboxes.length} mailbox(es):\n${mailboxList}`, structured);
|
|
779
982
|
}, "Error listing mailboxes"));
|
|
780
983
|
// --- get-unread-count ---
|
|
781
|
-
server.
|
|
782
|
-
|
|
783
|
-
|
|
984
|
+
server.registerTool("get-unread-count", {
|
|
985
|
+
description: "Use when: you only need the number of unread messages (optionally scoped to one mailbox and/or account), without listing the messages themselves.\nReturns: the unread count for the requested scope.\nDo not use when: you need the actual unread messages and their ids (use list-messages with unreadOnly, or search-messages with isRead=false) or broader totals (use get-mail-stats).",
|
|
986
|
+
inputSchema: {
|
|
987
|
+
mailbox: z.string().optional().describe("Mailbox to check (default: all)"),
|
|
988
|
+
account: z.string().optional().describe("Account to check"),
|
|
989
|
+
},
|
|
990
|
+
outputSchema: {
|
|
991
|
+
unread: z.number().optional(),
|
|
992
|
+
mailbox: z.string().optional(),
|
|
993
|
+
account: z.string().optional(),
|
|
994
|
+
},
|
|
784
995
|
}, withErrorHandling(async ({ mailbox, account }) => {
|
|
785
996
|
// IMAP (I4): STATUS (UNSEEN) is authoritative and fast even on huge
|
|
786
997
|
// mailboxes; falls back to AppleScript for non-IMAP accounts.
|
|
@@ -795,9 +1006,16 @@ server.tool("get-unread-count", "Use when: you only need the number of unread me
|
|
|
795
1006
|
});
|
|
796
1007
|
}, "Error getting unread count"));
|
|
797
1008
|
// --- create-mailbox ---
|
|
798
|
-
server.
|
|
799
|
-
|
|
800
|
-
|
|
1009
|
+
server.registerTool("create-mailbox", {
|
|
1010
|
+
description: "Use when: creating a new mailbox/folder in an account.\nReturns: a confirmation that the mailbox was created.\nDo not use when: renaming an existing one (use rename-mailbox) or deleting one (use delete-mailbox). Use list-mailboxes to see what already exists.\nSafety: creates a real folder in the mail account — confirm the name and target account first.",
|
|
1011
|
+
inputSchema: {
|
|
1012
|
+
name: z.string().min(1, "Mailbox name is required"),
|
|
1013
|
+
account: z.string().optional().describe("Account to create the mailbox in"),
|
|
1014
|
+
},
|
|
1015
|
+
outputSchema: {
|
|
1016
|
+
ok: z.boolean().optional(),
|
|
1017
|
+
name: z.string().optional(),
|
|
1018
|
+
},
|
|
801
1019
|
}, withErrorHandling(async ({ name, account }) => {
|
|
802
1020
|
// IMAP backend (issue #43, Phase 2): server-side folder op when this account
|
|
803
1021
|
// is IMAP-configured; otherwise AppleScript.
|
|
@@ -814,9 +1032,16 @@ server.tool("create-mailbox", "Use when: creating a new mailbox/folder in an acc
|
|
|
814
1032
|
return successResponse(`Mailbox "${name}" created`, { ok: true, name });
|
|
815
1033
|
}, "Error creating mailbox"));
|
|
816
1034
|
// --- delete-mailbox ---
|
|
817
|
-
server.
|
|
818
|
-
|
|
819
|
-
|
|
1035
|
+
server.registerTool("delete-mailbox", {
|
|
1036
|
+
description: "Use when: deleting a mailbox/folder from an account.\nReturns: a confirmation that the mailbox was deleted.\nDo not use when: renaming it (use rename-mailbox) or deleting messages within it (use delete-message / batch-delete-messages).\nSafety: destructive — deleting a mailbox removes the folder and any messages it contains. Require explicit user confirmation and use list-mailboxes first to confirm the exact name.",
|
|
1037
|
+
inputSchema: {
|
|
1038
|
+
name: z.string().min(1, "Mailbox name is required"),
|
|
1039
|
+
account: z.string().optional().describe("Account containing the mailbox"),
|
|
1040
|
+
},
|
|
1041
|
+
outputSchema: {
|
|
1042
|
+
ok: z.boolean().optional(),
|
|
1043
|
+
name: z.string().optional(),
|
|
1044
|
+
},
|
|
820
1045
|
}, withErrorHandling(async ({ name, account }) => {
|
|
821
1046
|
if (isImapAccount(account)) {
|
|
822
1047
|
const r = await imapDeleteMailbox(name, { account });
|
|
@@ -831,10 +1056,18 @@ server.tool("delete-mailbox", "Use when: deleting a mailbox/folder from an accou
|
|
|
831
1056
|
return successResponse(`Mailbox "${name}" deleted`, { ok: true, name });
|
|
832
1057
|
}, "Error deleting mailbox"));
|
|
833
1058
|
// --- rename-mailbox ---
|
|
834
|
-
server.
|
|
835
|
-
oldName:
|
|
836
|
-
|
|
837
|
-
|
|
1059
|
+
server.registerTool("rename-mailbox", {
|
|
1060
|
+
description: "Use when: renaming an existing mailbox/folder from oldName to newName within an account.\nReturns: a confirmation naming the old and new mailbox names.\nDo not use when: creating a new folder (use create-mailbox) or deleting one (use delete-mailbox). Use list-mailboxes to confirm the current name.\nSafety: renames a real folder in the mail account — confirm oldName matches exactly (case-sensitive) before calling.",
|
|
1061
|
+
inputSchema: {
|
|
1062
|
+
oldName: z.string().min(1, "Current mailbox name is required"),
|
|
1063
|
+
newName: z.string().min(1, "New mailbox name is required"),
|
|
1064
|
+
account: z.string().optional().describe("Account containing the mailbox"),
|
|
1065
|
+
},
|
|
1066
|
+
outputSchema: {
|
|
1067
|
+
ok: z.boolean().optional(),
|
|
1068
|
+
oldName: z.string().optional(),
|
|
1069
|
+
newName: z.string().optional(),
|
|
1070
|
+
},
|
|
838
1071
|
}, withErrorHandling(async ({ oldName, newName, account }) => {
|
|
839
1072
|
if (isImapAccount(account)) {
|
|
840
1073
|
const r = await imapRenameMailbox(oldName, newName, { account });
|
|
@@ -861,7 +1094,14 @@ server.tool("rename-mailbox", "Use when: renaming an existing mailbox/folder fro
|
|
|
861
1094
|
// Account Tools
|
|
862
1095
|
// =============================================================================
|
|
863
1096
|
// --- list-accounts ---
|
|
864
|
-
server.
|
|
1097
|
+
server.registerTool("list-accounts", {
|
|
1098
|
+
description: "Use when: discovering the configured Mail accounts (e.g. iCloud, Gmail) so you can pass an exact account name to other tools.\nReturns: the account names and a count.\nDo not use when: you want the folders within an account (use list-mailboxes) or messages (use list-messages / search-messages).",
|
|
1099
|
+
inputSchema: {},
|
|
1100
|
+
outputSchema: {
|
|
1101
|
+
accounts: z.array(z.object({}).passthrough()).optional(),
|
|
1102
|
+
count: z.number().optional(),
|
|
1103
|
+
},
|
|
1104
|
+
}, withErrorHandling(() => {
|
|
865
1105
|
const accounts = mailManager.listAccounts();
|
|
866
1106
|
const structured = { accounts, count: accounts.length };
|
|
867
1107
|
if (accounts.length === 0) {
|
|
@@ -874,7 +1114,14 @@ server.tool("list-accounts", "Use when: discovering the configured Mail accounts
|
|
|
874
1114
|
// Mail Rules Tools
|
|
875
1115
|
// =============================================================================
|
|
876
1116
|
// --- list-rules ---
|
|
877
|
-
server.
|
|
1117
|
+
server.registerTool("list-rules", {
|
|
1118
|
+
description: "Use when: discovering the Mail rules that exist and whether each is enabled or disabled, e.g. before enabling/disabling/deleting one.\nReturns: each rule's name and enabled/disabled state.\nDo not use when: you want to change a rule (use enable-rule / disable-rule / create-rule / delete-rule).",
|
|
1119
|
+
inputSchema: {},
|
|
1120
|
+
outputSchema: {
|
|
1121
|
+
rules: z.array(z.object({}).passthrough()).optional(),
|
|
1122
|
+
count: z.number().optional(),
|
|
1123
|
+
},
|
|
1124
|
+
}, withErrorHandling(() => {
|
|
878
1125
|
const rules = mailManager.listRules();
|
|
879
1126
|
const structured = {
|
|
880
1127
|
rules: rules.map((r) => ({ name: r.name, enabled: r.enabled })),
|
|
@@ -889,8 +1136,16 @@ server.tool("list-rules", "Use when: discovering the Mail rules that exist and w
|
|
|
889
1136
|
return successResponse(`Found ${rules.length} rule(s):\n${ruleList}`, structured);
|
|
890
1137
|
}, "Error listing rules"));
|
|
891
1138
|
// --- enable-rule ---
|
|
892
|
-
server.
|
|
893
|
-
name:
|
|
1139
|
+
server.registerTool("enable-rule", {
|
|
1140
|
+
description: "Use when: turning on an existing Mail rule by name.\nReturns: a confirmation that the rule was enabled.\nDo not use when: turning a rule off (use disable-rule), creating one (use create-rule), or deleting one (use delete-rule). Use list-rules to confirm the exact rule name.",
|
|
1141
|
+
inputSchema: {
|
|
1142
|
+
name: z.string().min(1, "Rule name is required"),
|
|
1143
|
+
},
|
|
1144
|
+
outputSchema: {
|
|
1145
|
+
ok: z.boolean().optional(),
|
|
1146
|
+
name: z.string().optional(),
|
|
1147
|
+
enabled: z.boolean().optional(),
|
|
1148
|
+
},
|
|
894
1149
|
}, withErrorHandling(({ name }) => {
|
|
895
1150
|
const success = mailManager.setRuleEnabled(name, true);
|
|
896
1151
|
if (!success) {
|
|
@@ -899,8 +1154,16 @@ server.tool("enable-rule", "Use when: turning on an existing Mail rule by name.\
|
|
|
899
1154
|
return successResponse(`Rule "${name}" enabled`, { ok: true, name, enabled: true });
|
|
900
1155
|
}, "Error enabling rule"));
|
|
901
1156
|
// --- disable-rule ---
|
|
902
|
-
server.
|
|
903
|
-
name:
|
|
1157
|
+
server.registerTool("disable-rule", {
|
|
1158
|
+
description: "Use when: turning off an existing Mail rule by name (without deleting it).\nReturns: a confirmation that the rule was disabled.\nDo not use when: turning a rule on (use enable-rule), creating one (use create-rule), or removing it permanently (use delete-rule). Use list-rules to confirm the exact rule name.",
|
|
1159
|
+
inputSchema: {
|
|
1160
|
+
name: z.string().min(1, "Rule name is required"),
|
|
1161
|
+
},
|
|
1162
|
+
outputSchema: {
|
|
1163
|
+
ok: z.boolean().optional(),
|
|
1164
|
+
name: z.string().optional(),
|
|
1165
|
+
enabled: z.boolean().optional(),
|
|
1166
|
+
},
|
|
904
1167
|
}, withErrorHandling(({ name }) => {
|
|
905
1168
|
const success = mailManager.setRuleEnabled(name, false);
|
|
906
1169
|
if (!success) {
|
|
@@ -909,28 +1172,35 @@ server.tool("disable-rule", "Use when: turning off an existing Mail rule by name
|
|
|
909
1172
|
return successResponse(`Rule "${name}" disabled`, { ok: true, name, enabled: false });
|
|
910
1173
|
}, "Error disabling rule"));
|
|
911
1174
|
// --- create-rule ---
|
|
912
|
-
server.
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
.
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
.enum(["
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1175
|
+
server.registerTool("create-rule", {
|
|
1176
|
+
description: "Use when: creating a new Mail rule with one or more conditions (field/operator/value) and at least one action (markRead, markFlagged, delete, or moveTo). Set matchAll to require all conditions vs. any.\nReturns: a confirmation naming the rule and its condition count.\nDo not use when: toggling an existing rule (use enable-rule / disable-rule) or removing one (use delete-rule). Use list-rules to avoid duplicating an existing rule.\nSafety: creates a rule that automatically acts on real mail (including delete/move actions) on an ongoing basis — confirm the conditions and actions with the user before calling.",
|
|
1177
|
+
inputSchema: {
|
|
1178
|
+
name: z.string().min(1, "Rule name is required"),
|
|
1179
|
+
conditions: z
|
|
1180
|
+
.array(z.object({
|
|
1181
|
+
field: z.enum(["from", "to", "cc", "subject", "content"]),
|
|
1182
|
+
operator: z
|
|
1183
|
+
.enum(["contains", "notContains", "equals", "beginsWith", "endsWith"])
|
|
1184
|
+
.default("contains"),
|
|
1185
|
+
value: z.string().min(1, "Condition value is required"),
|
|
1186
|
+
}))
|
|
1187
|
+
.min(1, "At least one condition is required"),
|
|
1188
|
+
actions: z
|
|
1189
|
+
.object({
|
|
1190
|
+
markRead: z.boolean().optional(),
|
|
1191
|
+
markFlagged: z.boolean().optional(),
|
|
1192
|
+
delete: z.boolean().optional(),
|
|
1193
|
+
moveTo: z.string().optional(),
|
|
1194
|
+
moveToAccount: z.string().optional(),
|
|
1195
|
+
})
|
|
1196
|
+
.refine((a) => a.markRead || a.markFlagged || a.delete || a.moveTo, "At least one action is required (markRead, markFlagged, delete, or moveTo)"),
|
|
1197
|
+
matchAll: z.boolean().default(true),
|
|
1198
|
+
enabled: z.boolean().default(true),
|
|
1199
|
+
},
|
|
1200
|
+
outputSchema: {
|
|
1201
|
+
name: z.string().optional(),
|
|
1202
|
+
created: z.boolean().optional(),
|
|
1203
|
+
},
|
|
934
1204
|
}, withErrorHandling((args) => {
|
|
935
1205
|
const result = mailManager.createRule(args);
|
|
936
1206
|
if (!result.success) {
|
|
@@ -939,8 +1209,15 @@ server.tool("create-rule", "Use when: creating a new Mail rule with one or more
|
|
|
939
1209
|
return successResponse(`Rule "${args.name}" created with ${args.conditions.length} condition(s).`, { name: args.name, created: true });
|
|
940
1210
|
}, "Error creating rule"));
|
|
941
1211
|
// --- delete-rule ---
|
|
942
|
-
server.
|
|
943
|
-
name:
|
|
1212
|
+
server.registerTool("delete-rule", {
|
|
1213
|
+
description: "Use when: permanently removing a Mail rule by name.\nReturns: a confirmation that the rule was deleted.\nDo not use when: you only want to pause it (use disable-rule) or create one (use create-rule).\nSafety: destructive — the rule is removed permanently. Require explicit user confirmation and use list-rules first to confirm the exact name.",
|
|
1214
|
+
inputSchema: {
|
|
1215
|
+
name: z.string().min(1, "Rule name is required"),
|
|
1216
|
+
},
|
|
1217
|
+
outputSchema: {
|
|
1218
|
+
name: z.string().optional(),
|
|
1219
|
+
deleted: z.boolean().optional(),
|
|
1220
|
+
},
|
|
944
1221
|
}, withErrorHandling(({ name }) => {
|
|
945
1222
|
const success = mailManager.deleteRule(name);
|
|
946
1223
|
if (!success) {
|
|
@@ -952,8 +1229,15 @@ server.tool("delete-rule", "Use when: permanently removing a Mail rule by name.\
|
|
|
952
1229
|
// Contacts Tools
|
|
953
1230
|
// =============================================================================
|
|
954
1231
|
// --- search-contacts ---
|
|
955
|
-
server.
|
|
956
|
-
|
|
1232
|
+
server.registerTool("search-contacts", {
|
|
1233
|
+
description: "Use when: looking up a person in Contacts.app by name to find their email address(es) before composing or sending mail.\nReturns: matching contacts with their names and email addresses.\nDo not use when: searching email messages (use search-messages) — this queries Contacts, not the mailbox.",
|
|
1234
|
+
inputSchema: {
|
|
1235
|
+
query: z.string().min(1, "Search query is required"),
|
|
1236
|
+
},
|
|
1237
|
+
outputSchema: {
|
|
1238
|
+
contacts: z.array(z.object({}).passthrough()).optional(),
|
|
1239
|
+
count: z.number().optional(),
|
|
1240
|
+
},
|
|
957
1241
|
}, withErrorHandling(({ query }) => {
|
|
958
1242
|
const contacts = mailManager.searchContacts(query);
|
|
959
1243
|
const structured = {
|
|
@@ -975,13 +1259,21 @@ server.tool("search-contacts", "Use when: looking up a person in Contacts.app by
|
|
|
975
1259
|
// Email Template Tools
|
|
976
1260
|
// =============================================================================
|
|
977
1261
|
// --- save-template ---
|
|
978
|
-
server.
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1262
|
+
server.registerTool("save-template", {
|
|
1263
|
+
description: "Use when: creating a reusable email template (name, subject, body, optional default to/cc), or updating one by passing its existing id. Subject/body may contain placeholders for later use.\nReturns: the saved template's name and id (reuse the id with use-template / get-template / delete-template).\nDo not use when: composing a one-off message (use create-draft / send-email) or filling in a template to send (use use-template).\nSafety: writes the template to the on-disk templates store (APPLE_MAIL_MCP_TEMPLATES_FILE) and persists across restarts; passing an existing id overwrites that template.",
|
|
1264
|
+
inputSchema: {
|
|
1265
|
+
name: z.string().min(1, "Template name is required"),
|
|
1266
|
+
subject: z.string().min(1, "Subject is required"),
|
|
1267
|
+
body: z.string().min(1, "Body is required"),
|
|
1268
|
+
to: z.array(z.string()).optional().describe("Default recipients"),
|
|
1269
|
+
cc: z.array(z.string()).optional().describe("Default CC recipients"),
|
|
1270
|
+
id: z.string().optional().describe("Template ID (for updating existing template)"),
|
|
1271
|
+
},
|
|
1272
|
+
outputSchema: {
|
|
1273
|
+
ok: z.boolean().optional(),
|
|
1274
|
+
id: z.string().optional(),
|
|
1275
|
+
name: z.string().optional(),
|
|
1276
|
+
},
|
|
985
1277
|
}, withErrorHandling(({ name, subject, body, to, cc, id }) => {
|
|
986
1278
|
const template = mailManager.saveTemplate(name, subject, body, to, cc, id);
|
|
987
1279
|
return successResponse(`Template "${template.name}" saved with ID: ${template.id}`, {
|
|
@@ -991,7 +1283,14 @@ server.tool("save-template", "Use when: creating a reusable email template (name
|
|
|
991
1283
|
});
|
|
992
1284
|
}, "Error saving template"));
|
|
993
1285
|
// --- list-templates ---
|
|
994
|
-
server.
|
|
1286
|
+
server.registerTool("list-templates", {
|
|
1287
|
+
description: "Use when: discovering the saved email templates and their ids, e.g. before using or editing one.\nReturns: each template's id, name, and subject.\nDo not use when: you want a single template's full body (use get-template) or want to apply one (use use-template).",
|
|
1288
|
+
inputSchema: {},
|
|
1289
|
+
outputSchema: {
|
|
1290
|
+
templates: z.array(z.object({}).passthrough()).optional(),
|
|
1291
|
+
count: z.number().optional(),
|
|
1292
|
+
},
|
|
1293
|
+
}, withErrorHandling(() => {
|
|
995
1294
|
const templates = mailManager.listTemplates();
|
|
996
1295
|
const structured = {
|
|
997
1296
|
templates: templates.map((t) => ({ id: t.id, name: t.name, subject: t.subject })),
|
|
@@ -1006,8 +1305,19 @@ server.tool("list-templates", "Use when: discovering the saved email templates a
|
|
|
1006
1305
|
return successResponse(`Found ${templates.length} template(s):\n${templateList}`, structured);
|
|
1007
1306
|
}, "Error listing templates"));
|
|
1008
1307
|
// --- get-template ---
|
|
1009
|
-
server.
|
|
1010
|
-
id:
|
|
1308
|
+
server.registerTool("get-template", {
|
|
1309
|
+
description: "Use when: reading the full contents of one saved template by id — its name, subject, default to/cc, and body.\nReturns: the template's name, subject, default recipients, and body text.\nDo not use when: you don't have the id (use list-templates first) or want to apply the template into a draft (use use-template).",
|
|
1310
|
+
inputSchema: {
|
|
1311
|
+
id: z.string().min(1, "Template ID is required"),
|
|
1312
|
+
},
|
|
1313
|
+
outputSchema: {
|
|
1314
|
+
id: z.string().optional(),
|
|
1315
|
+
name: z.string().optional(),
|
|
1316
|
+
subject: z.string().optional(),
|
|
1317
|
+
to: z.array(z.string()).optional(),
|
|
1318
|
+
cc: z.array(z.string()).optional(),
|
|
1319
|
+
body: z.string().optional(),
|
|
1320
|
+
},
|
|
1011
1321
|
}, withErrorHandling(({ id }) => {
|
|
1012
1322
|
const template = mailManager.getTemplate(id);
|
|
1013
1323
|
if (!template) {
|
|
@@ -1032,8 +1342,15 @@ server.tool("get-template", "Use when: reading the full contents of one saved te
|
|
|
1032
1342
|
});
|
|
1033
1343
|
}, "Error getting template"));
|
|
1034
1344
|
// --- delete-template ---
|
|
1035
|
-
server.
|
|
1036
|
-
id:
|
|
1345
|
+
server.registerTool("delete-template", {
|
|
1346
|
+
description: "Use when: permanently removing a saved email template by id.\nReturns: a confirmation that the template was deleted.\nDo not use when: you only want to view it (use get-template) or update it (use save-template with the existing id).\nSafety: destructive — removes the template from the on-disk store permanently. Require explicit user confirmation and use list-templates first to confirm the id.",
|
|
1347
|
+
inputSchema: {
|
|
1348
|
+
id: z.string().min(1, "Template ID is required"),
|
|
1349
|
+
},
|
|
1350
|
+
outputSchema: {
|
|
1351
|
+
ok: z.boolean().optional(),
|
|
1352
|
+
id: z.string().optional(),
|
|
1353
|
+
},
|
|
1037
1354
|
}, withErrorHandling(({ id }) => {
|
|
1038
1355
|
const success = mailManager.deleteTemplate(id);
|
|
1039
1356
|
if (!success) {
|
|
@@ -1042,12 +1359,19 @@ server.tool("delete-template", "Use when: permanently removing a saved email tem
|
|
|
1042
1359
|
return successResponse(`Template "${id}" deleted`, { ok: true, id });
|
|
1043
1360
|
}, "Error deleting template"));
|
|
1044
1361
|
// --- use-template ---
|
|
1045
|
-
server.
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1362
|
+
server.registerTool("use-template", {
|
|
1363
|
+
description: "Use when: composing a new draft from a saved template (by id), optionally overriding the recipients, subject, or body. Creates a draft in Mail.app for the user to review and send.\nReturns: a confirmation that a draft was created from the template.\nDo not use when: you want to inspect the template without composing (use get-template) or send immediately without a draft (use send-email).",
|
|
1364
|
+
inputSchema: {
|
|
1365
|
+
id: z.string().min(1, "Template ID is required"),
|
|
1366
|
+
to: z.array(z.string()).optional().describe("Override recipients"),
|
|
1367
|
+
cc: z.array(z.string()).optional().describe("Override CC recipients"),
|
|
1368
|
+
subject: z.string().optional().describe("Override subject"),
|
|
1369
|
+
body: z.string().optional().describe("Override body"),
|
|
1370
|
+
},
|
|
1371
|
+
outputSchema: {
|
|
1372
|
+
ok: z.boolean().optional(),
|
|
1373
|
+
id: z.string().optional(),
|
|
1374
|
+
},
|
|
1051
1375
|
}, withErrorHandling(({ id, to, cc, subject, body }) => {
|
|
1052
1376
|
const success = mailManager.useTemplate(id, { to, cc, subject, body });
|
|
1053
1377
|
if (!success) {
|
|
@@ -1059,7 +1383,14 @@ server.tool("use-template", "Use when: composing a new draft from a saved templa
|
|
|
1059
1383
|
// Diagnostics Tools
|
|
1060
1384
|
// =============================================================================
|
|
1061
1385
|
// --- health-check ---
|
|
1062
|
-
server.
|
|
1386
|
+
server.registerTool("health-check", {
|
|
1387
|
+
description: "Use when: doing a quick check that Mail.app is reachable and the server's basic checks pass.\nReturns: an overall healthy/unhealthy status with a pass/fail line per check.\nDo not use when: you need detailed permission/account/IMAP/SMTP diagnostics with remediation steps (use doctor).",
|
|
1388
|
+
inputSchema: {},
|
|
1389
|
+
outputSchema: {
|
|
1390
|
+
healthy: z.boolean().optional(),
|
|
1391
|
+
checks: z.array(CHECK_ITEM_SCHEMA).optional(),
|
|
1392
|
+
},
|
|
1393
|
+
}, withErrorHandling(() => {
|
|
1063
1394
|
const result = mailManager.healthCheck();
|
|
1064
1395
|
const statusIcon = result.healthy ? "✓" : "✗";
|
|
1065
1396
|
const statusText = result.healthy ? "All checks passed" : "Issues detected";
|
|
@@ -1072,18 +1403,36 @@ server.tool("health-check", "Use when: doing a quick check that Mail.app is reac
|
|
|
1072
1403
|
return successResponse(`${statusIcon} ${statusText}\n\n${checkLines}`, { ...result });
|
|
1073
1404
|
}, "Error running health check"));
|
|
1074
1405
|
// --- doctor ---
|
|
1075
|
-
server.
|
|
1406
|
+
server.registerTool("doctor", {
|
|
1407
|
+
description: "Use when: troubleshooting setup problems — diagnoses Mail.app automation permissions, account state, and the IMAP/SMTP backends with actionable remediation messages.\nReturns: a detailed diagnostic report (formatted text plus structured checks).\nDo not use when: you just want a quick up/down status (use health-check) or message counts (use get-mail-stats).",
|
|
1408
|
+
inputSchema: {},
|
|
1409
|
+
outputSchema: {
|
|
1410
|
+
healthy: z.boolean().optional(),
|
|
1411
|
+
checks: z.array(CHECK_ITEM_SCHEMA).optional(),
|
|
1412
|
+
},
|
|
1413
|
+
}, withErrorHandling(async () => {
|
|
1076
1414
|
// Diagnoses Mail.app permission, account state, and the IMAP/SMTP backends
|
|
1077
1415
|
// with actionable messages (C3). structuredContent carries the raw checks.
|
|
1078
1416
|
const report = await runDoctor(mailManager);
|
|
1079
1417
|
return successResponse(formatDoctorReport(report), { ...report });
|
|
1080
1418
|
}, "Error running doctor"));
|
|
1081
1419
|
// --- get-mail-stats ---
|
|
1082
|
-
server.
|
|
1083
|
-
account:
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1420
|
+
server.registerTool("get-mail-stats", {
|
|
1421
|
+
description: "Use when: you want aggregate mailbox statistics — total and unread message counts, recently-received counts (last 24h/7d/30d), and (for the all-accounts path) a per-account breakdown.\nReturns: totals, unread counts, recent-activity counts, and per-account figures.\nDo not use when: you only need a single unread number (use get-unread-count) or want to list the messages themselves (use list-messages / search-messages).",
|
|
1422
|
+
inputSchema: {
|
|
1423
|
+
account: z
|
|
1424
|
+
.string()
|
|
1425
|
+
.optional()
|
|
1426
|
+
.describe("Limit to one account; uses fast IMAP STATUS if that account is IMAP-configured"),
|
|
1427
|
+
},
|
|
1428
|
+
outputSchema: {
|
|
1429
|
+
account: z.string().optional(),
|
|
1430
|
+
totalMessages: z.number().optional(),
|
|
1431
|
+
totalUnread: z.number().optional(),
|
|
1432
|
+
accounts: z.array(z.object({}).passthrough()).optional(),
|
|
1433
|
+
recentlyReceived: z.object({}).passthrough().optional(),
|
|
1434
|
+
recent: z.object({}).passthrough().optional(),
|
|
1435
|
+
},
|
|
1087
1436
|
}, withErrorHandling(async ({ account }) => {
|
|
1088
1437
|
// IMAP (I3): for a named IMAP account, STATUS gives authoritative counts and
|
|
1089
1438
|
// SEARCH SINCE gives recent activity — fast even on huge mailboxes.
|
|
@@ -1125,7 +1474,17 @@ server.tool("get-mail-stats", "Use when: you want aggregate mailbox statistics
|
|
|
1125
1474
|
return successResponse(lines.join("\n"), { ...stats });
|
|
1126
1475
|
}, "Error getting mail statistics"));
|
|
1127
1476
|
// --- get-sync-status ---
|
|
1128
|
-
server.
|
|
1477
|
+
server.registerTool("get-sync-status", {
|
|
1478
|
+
description: "Use when: checking whether Mail.app is running and actively syncing, e.g. to explain why new mail hasn't appeared yet.\nReturns: whether Mail.app is running and whether sync activity was detected.\nDo not use when: you need message counts (use get-mail-stats) or a full setup diagnosis (use doctor).",
|
|
1479
|
+
inputSchema: {},
|
|
1480
|
+
outputSchema: {
|
|
1481
|
+
syncDetected: z.boolean().optional(),
|
|
1482
|
+
pendingUpload: z.number().optional(),
|
|
1483
|
+
recentActivity: z.boolean().optional(),
|
|
1484
|
+
secondsSinceLastChange: z.number().optional(),
|
|
1485
|
+
error: z.string().optional(),
|
|
1486
|
+
},
|
|
1487
|
+
}, withErrorHandling(() => {
|
|
1129
1488
|
const status = mailManager.getSyncStatus();
|
|
1130
1489
|
const lines = [];
|
|
1131
1490
|
lines.push(`🔄 Mail Sync Status`);
|
package/package.json
CHANGED