@kbzowski/mcp-inbox 0.1.1 → 0.2.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/dist/cache/queries.d.ts +10 -0
- package/dist/imap/search.d.ts +28 -14
- package/dist/index.js +383 -91
- package/dist/index.js.map +4 -4
- package/dist/tools/emails/delete-multiple.d.ts +6 -0
- package/dist/tools/emails/mark-read-multiple.d.ts +9 -0
- package/dist/tools/emails/move-multiple.d.ts +6 -0
- package/dist/tools/emails/search-emails.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -564,12 +564,33 @@ function countEmailsInFolder(db, folder) {
|
|
|
564
564
|
function setEmailFlags(db, folder, uid, flags) {
|
|
565
565
|
db.update(emails).set({ flags }).where(and(eq(emails.folder, folder), eq(emails.uid, uid))).run();
|
|
566
566
|
}
|
|
567
|
+
function mutateEmailFlagsForUids(db, folder, uids, mutate) {
|
|
568
|
+
if (uids.length === 0) return;
|
|
569
|
+
db.transaction((tx) => {
|
|
570
|
+
const rows = tx.select({ uid: emails.uid, flags: emails.flags }).from(emails).where(and(eq(emails.folder, folder), inArray(emails.uid, uids))).all();
|
|
571
|
+
for (const row of rows) {
|
|
572
|
+
const next = mutate(row.flags);
|
|
573
|
+
if (flagsEqual(row.flags, next)) continue;
|
|
574
|
+
tx.update(emails).set({ flags: next }).where(and(eq(emails.folder, folder), eq(emails.uid, row.uid))).run();
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function flagsEqual(a, b) {
|
|
579
|
+
if (a.length !== b.length) return false;
|
|
580
|
+
const setB = new Set(b);
|
|
581
|
+
for (const f of a) if (!setB.has(f)) return false;
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
567
584
|
function deleteEmailsByFolder(db, folder) {
|
|
568
585
|
db.delete(emails).where(eq(emails.folder, folder)).run();
|
|
569
586
|
}
|
|
570
587
|
function deleteEmail(db, folder, uid) {
|
|
571
588
|
db.delete(emails).where(and(eq(emails.folder, folder), eq(emails.uid, uid))).run();
|
|
572
589
|
}
|
|
590
|
+
function deleteEmailsByUids(db, folder, uids) {
|
|
591
|
+
if (uids.length === 0) return;
|
|
592
|
+
db.delete(emails).where(and(eq(emails.folder, folder), inArray(emails.uid, uids))).run();
|
|
593
|
+
}
|
|
573
594
|
function getEmailBody(db, folder, uid) {
|
|
574
595
|
const row = db.select({
|
|
575
596
|
bodyText: emails.bodyText,
|
|
@@ -864,7 +885,7 @@ import {
|
|
|
864
885
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
865
886
|
|
|
866
887
|
// src/tools/registry.ts
|
|
867
|
-
import { z as
|
|
888
|
+
import { z as z21 } from "zod";
|
|
868
889
|
|
|
869
890
|
// src/tools/folders/list-folders.ts
|
|
870
891
|
import { z as z2 } from "zod";
|
|
@@ -1227,6 +1248,10 @@ function buildImapSearch(c) {
|
|
|
1227
1248
|
if (c.since) q.since = c.since;
|
|
1228
1249
|
if (c.before) q.before = c.before;
|
|
1229
1250
|
if (c.unseen === true) q.seen = false;
|
|
1251
|
+
if (c.larger_than_bytes !== void 0) q.larger = c.larger_than_bytes;
|
|
1252
|
+
if (c.smaller_than_bytes !== void 0) q.smaller = c.smaller_than_bytes;
|
|
1253
|
+
if (c.or !== void 0 && c.or.length > 0) q.or = c.or.map(buildImapSearch);
|
|
1254
|
+
if (c.not !== void 0) q.not = buildImapSearch(c.not);
|
|
1230
1255
|
if (Object.keys(q).length === 0) {
|
|
1231
1256
|
q.all = true;
|
|
1232
1257
|
}
|
|
@@ -1234,6 +1259,21 @@ function buildImapSearch(c) {
|
|
|
1234
1259
|
}
|
|
1235
1260
|
|
|
1236
1261
|
// src/tools/emails/search-emails.ts
|
|
1262
|
+
var Criteria = z5.lazy(
|
|
1263
|
+
() => z5.object({
|
|
1264
|
+
subject: z5.string().min(1).optional(),
|
|
1265
|
+
from: z5.string().min(1).optional(),
|
|
1266
|
+
to: z5.string().min(1).optional(),
|
|
1267
|
+
body: z5.string().min(1).optional(),
|
|
1268
|
+
unseen: z5.boolean().optional(),
|
|
1269
|
+
since: z5.coerce.date().optional(),
|
|
1270
|
+
before: z5.coerce.date().optional(),
|
|
1271
|
+
larger_than_bytes: z5.number().int().positive().optional(),
|
|
1272
|
+
smaller_than_bytes: z5.number().int().positive().optional(),
|
|
1273
|
+
or: z5.array(Criteria).min(2).optional(),
|
|
1274
|
+
not: Criteria.optional()
|
|
1275
|
+
})
|
|
1276
|
+
);
|
|
1237
1277
|
var Input4 = z5.object({
|
|
1238
1278
|
folder: z5.string().min(1).default("INBOX"),
|
|
1239
1279
|
subject: z5.string().min(1).optional(),
|
|
@@ -1243,16 +1283,24 @@ var Input4 = z5.object({
|
|
|
1243
1283
|
unseen: z5.boolean().optional(),
|
|
1244
1284
|
since_date: z5.string().date().optional(),
|
|
1245
1285
|
before_date: z5.string().date().optional(),
|
|
1286
|
+
larger_than_bytes: z5.number().int().positive().optional().describe("Only match messages larger than this many bytes."),
|
|
1287
|
+
smaller_than_bytes: z5.number().int().positive().optional().describe("Only match messages smaller than this many bytes."),
|
|
1288
|
+
or: z5.array(Criteria).min(2).optional().describe(
|
|
1289
|
+
'Array of >=2 sub-criteria; at least one must match. Combines as AND with top-level fields: `{subject: "X", or: [{from: "a"}, {from: "b"}]}` means `subject=X AND (from=a OR from=b)`.'
|
|
1290
|
+
),
|
|
1291
|
+
not: Criteria.optional().describe(
|
|
1292
|
+
'Sub-criteria that must NOT match. Useful for excluding auto-generated mail, e.g. `{not: {from: "noreply"}}`.'
|
|
1293
|
+
),
|
|
1246
1294
|
limit: z5.number().int().min(1).max(100).default(20),
|
|
1247
1295
|
max_staleness_seconds: z5.number().int().min(0).default(60),
|
|
1248
1296
|
response_format: z5.enum(["markdown", "json"]).default("markdown")
|
|
1249
1297
|
}).refine(
|
|
1250
|
-
(v) => v.subject ?? v.from ?? v.to ?? v.body ?? v.unseen ?? v.since_date ?? v.before_date,
|
|
1298
|
+
(v) => v.subject ?? v.from ?? v.to ?? v.body ?? v.unseen ?? v.since_date ?? v.before_date ?? v.larger_than_bytes ?? v.smaller_than_bytes ?? v.or ?? v.not,
|
|
1251
1299
|
{ message: "At least one search criterion must be provided." }
|
|
1252
1300
|
);
|
|
1253
1301
|
var searchEmailsTool = defineTool({
|
|
1254
1302
|
name: "imap_search_emails",
|
|
1255
|
-
description:
|
|
1303
|
+
description: 'Search a folder for messages matching subject/from/to/body text, flag, date window, or size. Supports boolean combinators: `or: [...]` for "any of these match", `not: {...}` for exclusion. Runs IMAP SEARCH on the server (body text search is server-side), then returns cached envelopes for the matching UIDs. Results are newest-first.',
|
|
1256
1304
|
annotations: {
|
|
1257
1305
|
readOnlyHint: true,
|
|
1258
1306
|
destructiveHint: false,
|
|
@@ -1269,7 +1317,13 @@ var searchEmailsTool = defineTool({
|
|
|
1269
1317
|
...args.body !== void 0 && { body: args.body },
|
|
1270
1318
|
...args.unseen !== void 0 && { unseen: args.unseen },
|
|
1271
1319
|
...args.since_date !== void 0 && { since: new Date(args.since_date) },
|
|
1272
|
-
...args.before_date !== void 0 && { before: new Date(args.before_date) }
|
|
1320
|
+
...args.before_date !== void 0 && { before: new Date(args.before_date) },
|
|
1321
|
+
...args.larger_than_bytes !== void 0 && { larger_than_bytes: args.larger_than_bytes },
|
|
1322
|
+
...args.smaller_than_bytes !== void 0 && {
|
|
1323
|
+
smaller_than_bytes: args.smaller_than_bytes
|
|
1324
|
+
},
|
|
1325
|
+
...args.or !== void 0 && { or: args.or },
|
|
1326
|
+
...args.not !== void 0 && { not: args.not }
|
|
1273
1327
|
});
|
|
1274
1328
|
let matchingUids;
|
|
1275
1329
|
const imap = await ctx.imap.connection();
|
|
@@ -1385,12 +1439,98 @@ var markUnreadTool = defineTool({
|
|
|
1385
1439
|
}
|
|
1386
1440
|
});
|
|
1387
1441
|
|
|
1388
|
-
// src/tools/emails/
|
|
1442
|
+
// src/tools/emails/mark-read-multiple.ts
|
|
1389
1443
|
import { z as z7 } from "zod";
|
|
1390
1444
|
var Input6 = z7.object({
|
|
1391
|
-
folder: z7.string().min(1).describe("
|
|
1392
|
-
|
|
1393
|
-
|
|
1445
|
+
folder: z7.string().min(1).describe("Folder containing the messages."),
|
|
1446
|
+
uids: z7.array(z7.number().int().positive()).min(1).max(500).describe(
|
|
1447
|
+
"UIDs of messages to flip. Max 500 per call - chunk your own list for larger batches."
|
|
1448
|
+
)
|
|
1449
|
+
});
|
|
1450
|
+
async function updateSeenFlagBulk(ctx, folder, uids, want) {
|
|
1451
|
+
const imap = await ctx.imap.connection();
|
|
1452
|
+
const lock = await imap.getMailboxLock(folder);
|
|
1453
|
+
try {
|
|
1454
|
+
if (want === "add") {
|
|
1455
|
+
await imap.messageFlagsAdd(uids, ["\\Seen"], { uid: true });
|
|
1456
|
+
} else {
|
|
1457
|
+
await imap.messageFlagsRemove(uids, ["\\Seen"], { uid: true });
|
|
1458
|
+
}
|
|
1459
|
+
} catch (err) {
|
|
1460
|
+
throw mapImapError(err);
|
|
1461
|
+
} finally {
|
|
1462
|
+
lock.release();
|
|
1463
|
+
}
|
|
1464
|
+
mutateEmailFlagsForUids(
|
|
1465
|
+
ctx.db,
|
|
1466
|
+
folder,
|
|
1467
|
+
uids,
|
|
1468
|
+
(flags) => want === "add" ? flags.includes("\\Seen") ? flags : [...flags, "\\Seen"] : flags.filter((f) => f !== "\\Seen")
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
var markReadMultipleTool = defineTool({
|
|
1472
|
+
name: "imap_mark_read_multiple",
|
|
1473
|
+
description: "Mark multiple messages as read in a single IMAP round-trip. Idempotent - already-read UIDs are unchanged. Use this when you have a concrete list of UIDs (e.g. from a search) instead of calling imap_mark_read N times.",
|
|
1474
|
+
annotations: {
|
|
1475
|
+
readOnlyHint: false,
|
|
1476
|
+
destructiveHint: false,
|
|
1477
|
+
idempotentHint: true,
|
|
1478
|
+
openWorldHint: true
|
|
1479
|
+
},
|
|
1480
|
+
inputSchema: Input6,
|
|
1481
|
+
handler: async (args, ctx) => {
|
|
1482
|
+
await updateSeenFlagBulk(ctx, args.folder, args.uids, "add");
|
|
1483
|
+
return {
|
|
1484
|
+
content: [
|
|
1485
|
+
{
|
|
1486
|
+
type: "text",
|
|
1487
|
+
text: `Marked ${String(args.uids.length)} message(s) as read in ${args.folder}.`
|
|
1488
|
+
}
|
|
1489
|
+
],
|
|
1490
|
+
structuredContent: {
|
|
1491
|
+
folder: args.folder,
|
|
1492
|
+
uids: args.uids,
|
|
1493
|
+
count: args.uids.length,
|
|
1494
|
+
seen: true
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
var markUnreadMultipleTool = defineTool({
|
|
1500
|
+
name: "imap_mark_unread_multiple",
|
|
1501
|
+
description: "Mark multiple messages as unread in a single IMAP round-trip. Idempotent.",
|
|
1502
|
+
annotations: {
|
|
1503
|
+
readOnlyHint: false,
|
|
1504
|
+
destructiveHint: false,
|
|
1505
|
+
idempotentHint: true,
|
|
1506
|
+
openWorldHint: true
|
|
1507
|
+
},
|
|
1508
|
+
inputSchema: Input6,
|
|
1509
|
+
handler: async (args, ctx) => {
|
|
1510
|
+
await updateSeenFlagBulk(ctx, args.folder, args.uids, "remove");
|
|
1511
|
+
return {
|
|
1512
|
+
content: [
|
|
1513
|
+
{
|
|
1514
|
+
type: "text",
|
|
1515
|
+
text: `Marked ${String(args.uids.length)} message(s) as unread in ${args.folder}.`
|
|
1516
|
+
}
|
|
1517
|
+
],
|
|
1518
|
+
structuredContent: {
|
|
1519
|
+
folder: args.folder,
|
|
1520
|
+
uids: args.uids,
|
|
1521
|
+
count: args.uids.length,
|
|
1522
|
+
seen: false
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
// src/tools/emails/move-to-folder.ts
|
|
1529
|
+
import { z as z8 } from "zod";
|
|
1530
|
+
var Input7 = z8.object({
|
|
1531
|
+
folder: z8.string().min(1).describe("Current folder of the message."),
|
|
1532
|
+
uid: z8.number().int().positive().describe("IMAP UID of the message to move."),
|
|
1533
|
+
destination: z8.string().min(1).describe(
|
|
1394
1534
|
"Target folder path. Use imap_list_folders to discover valid destinations. Must exist on the server."
|
|
1395
1535
|
)
|
|
1396
1536
|
});
|
|
@@ -1404,7 +1544,7 @@ var moveToFolderTool = defineTool({
|
|
|
1404
1544
|
idempotentHint: false,
|
|
1405
1545
|
openWorldHint: true
|
|
1406
1546
|
},
|
|
1407
|
-
inputSchema:
|
|
1547
|
+
inputSchema: Input7,
|
|
1408
1548
|
handler: async (args, ctx) => {
|
|
1409
1549
|
const imap = await ctx.imap.connection();
|
|
1410
1550
|
const lock = await imap.getMailboxLock(args.folder);
|
|
@@ -1441,12 +1581,64 @@ var moveToFolderTool = defineTool({
|
|
|
1441
1581
|
}
|
|
1442
1582
|
});
|
|
1443
1583
|
|
|
1584
|
+
// src/tools/emails/move-multiple.ts
|
|
1585
|
+
import { z as z9 } from "zod";
|
|
1586
|
+
var Input8 = z9.object({
|
|
1587
|
+
folder: z9.string().min(1).describe("Current folder of the messages."),
|
|
1588
|
+
uids: z9.array(z9.number().int().positive()).min(1).max(500).describe("UIDs to move. Max 500 per call."),
|
|
1589
|
+
destination: z9.string().min(1).describe("Target folder. Must exist on the server.")
|
|
1590
|
+
});
|
|
1591
|
+
var moveMultipleTool = defineTool({
|
|
1592
|
+
name: "imap_move_multiple",
|
|
1593
|
+
description: "Move multiple messages to another folder in a single IMAP round-trip. Uses IMAP MOVE when the server supports it, otherwise ImapFlow falls back to COPY + EXPUNGE transparently.",
|
|
1594
|
+
annotations: {
|
|
1595
|
+
readOnlyHint: false,
|
|
1596
|
+
destructiveHint: true,
|
|
1597
|
+
idempotentHint: false,
|
|
1598
|
+
openWorldHint: true
|
|
1599
|
+
},
|
|
1600
|
+
inputSchema: Input8,
|
|
1601
|
+
handler: async (args, ctx) => {
|
|
1602
|
+
const imap = await ctx.imap.connection();
|
|
1603
|
+
const lock = await imap.getMailboxLock(args.folder);
|
|
1604
|
+
try {
|
|
1605
|
+
const ok = await imap.messageMove(args.uids, args.destination, { uid: true });
|
|
1606
|
+
if (!ok) {
|
|
1607
|
+
throw new ImapError(
|
|
1608
|
+
"IMAP_UNKNOWN",
|
|
1609
|
+
`Server rejected the move from ${args.folder} to ${args.destination}. Verify the destination folder exists.`
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
} catch (err) {
|
|
1613
|
+
if (err instanceof ImapError) throw err;
|
|
1614
|
+
throw mapImapError(err);
|
|
1615
|
+
} finally {
|
|
1616
|
+
lock.release();
|
|
1617
|
+
}
|
|
1618
|
+
deleteEmailsByUids(ctx.db, args.folder, args.uids);
|
|
1619
|
+
return {
|
|
1620
|
+
content: [
|
|
1621
|
+
{
|
|
1622
|
+
type: "text",
|
|
1623
|
+
text: `Moved ${String(args.uids.length)} message(s) from ${args.folder} to ${args.destination}.`
|
|
1624
|
+
}
|
|
1625
|
+
],
|
|
1626
|
+
structuredContent: {
|
|
1627
|
+
folder: args.folder,
|
|
1628
|
+
uids: args.uids,
|
|
1629
|
+
count: args.uids.length,
|
|
1630
|
+
destination: args.destination
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1444
1636
|
// src/tools/emails/delete-email.ts
|
|
1445
|
-
import { z as
|
|
1446
|
-
var
|
|
1447
|
-
folder:
|
|
1448
|
-
uid:
|
|
1449
|
-
hard_delete:
|
|
1637
|
+
import { z as z10 } from "zod";
|
|
1638
|
+
var Input9 = z10.object({
|
|
1639
|
+
folder: z10.string().min(1).describe("Folder containing the message to delete."),
|
|
1640
|
+
uid: z10.number().int().positive().describe("IMAP UID of the message to delete."),
|
|
1641
|
+
hard_delete: z10.boolean().default(false).describe(
|
|
1450
1642
|
"When false (default), the message is moved to the Trash folder and can be recovered by the user. When true, the message is permanently expunged from the server."
|
|
1451
1643
|
)
|
|
1452
1644
|
});
|
|
@@ -1459,7 +1651,7 @@ var deleteEmailTool = defineTool({
|
|
|
1459
1651
|
idempotentHint: false,
|
|
1460
1652
|
openWorldHint: true
|
|
1461
1653
|
},
|
|
1462
|
-
inputSchema:
|
|
1654
|
+
inputSchema: Input9,
|
|
1463
1655
|
handler: async (args, ctx) => {
|
|
1464
1656
|
const imap = await ctx.imap.connection();
|
|
1465
1657
|
if (args.hard_delete) {
|
|
@@ -1526,16 +1718,103 @@ var deleteEmailTool = defineTool({
|
|
|
1526
1718
|
}
|
|
1527
1719
|
});
|
|
1528
1720
|
|
|
1721
|
+
// src/tools/emails/delete-multiple.ts
|
|
1722
|
+
import { z as z11 } from "zod";
|
|
1723
|
+
var Input10 = z11.object({
|
|
1724
|
+
folder: z11.string().min(1).describe("Folder containing the messages to delete."),
|
|
1725
|
+
uids: z11.array(z11.number().int().positive()).min(1).max(500).describe("UIDs to delete. Max 500 per call."),
|
|
1726
|
+
hard_delete: z11.boolean().default(false).describe(
|
|
1727
|
+
"When false (default), messages move to the server Trash and can be recovered. When true, they are permanently expunged."
|
|
1728
|
+
)
|
|
1729
|
+
});
|
|
1730
|
+
var deleteMultipleTool = defineTool({
|
|
1731
|
+
name: "imap_delete_multiple",
|
|
1732
|
+
description: "Delete multiple messages in a single IMAP round-trip. Default soft-deletes (moves to \\Trash); `hard_delete=true` permanently expunges. Mirrors imap_delete_email's per-UID semantics but handles a whole batch at once.",
|
|
1733
|
+
annotations: {
|
|
1734
|
+
readOnlyHint: false,
|
|
1735
|
+
destructiveHint: true,
|
|
1736
|
+
idempotentHint: false,
|
|
1737
|
+
openWorldHint: true
|
|
1738
|
+
},
|
|
1739
|
+
inputSchema: Input10,
|
|
1740
|
+
handler: async (args, ctx) => {
|
|
1741
|
+
const imap = await ctx.imap.connection();
|
|
1742
|
+
if (args.hard_delete) {
|
|
1743
|
+
const lock2 = await imap.getMailboxLock(args.folder);
|
|
1744
|
+
try {
|
|
1745
|
+
await imap.messageDelete(args.uids, { uid: true });
|
|
1746
|
+
} catch (err) {
|
|
1747
|
+
throw mapImapError(err);
|
|
1748
|
+
} finally {
|
|
1749
|
+
lock2.release();
|
|
1750
|
+
}
|
|
1751
|
+
deleteEmailsByUids(ctx.db, args.folder, args.uids);
|
|
1752
|
+
return {
|
|
1753
|
+
content: [
|
|
1754
|
+
{
|
|
1755
|
+
type: "text",
|
|
1756
|
+
text: `Permanently deleted ${String(args.uids.length)} message(s) from ${args.folder}.`
|
|
1757
|
+
}
|
|
1758
|
+
],
|
|
1759
|
+
structuredContent: {
|
|
1760
|
+
folder: args.folder,
|
|
1761
|
+
uids: args.uids,
|
|
1762
|
+
count: args.uids.length,
|
|
1763
|
+
action: "hard_delete"
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
const trashFolder = await resolveSpecialFolder(ctx, "\\Trash");
|
|
1768
|
+
if (trashFolder === args.folder) {
|
|
1769
|
+
throw new ImapError(
|
|
1770
|
+
"IMAP_UNKNOWN",
|
|
1771
|
+
`Messages are already in the Trash folder (${args.folder}). Use hard_delete=true to permanently expunge.`
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
const lock = await imap.getMailboxLock(args.folder);
|
|
1775
|
+
try {
|
|
1776
|
+
const ok = await imap.messageMove(args.uids, trashFolder, { uid: true });
|
|
1777
|
+
if (!ok) {
|
|
1778
|
+
throw new ImapError(
|
|
1779
|
+
"IMAP_UNKNOWN",
|
|
1780
|
+
`Server rejected the move from ${args.folder} to ${trashFolder}.`
|
|
1781
|
+
);
|
|
1782
|
+
}
|
|
1783
|
+
} catch (err) {
|
|
1784
|
+
if (err instanceof ImapError) throw err;
|
|
1785
|
+
throw mapImapError(err);
|
|
1786
|
+
} finally {
|
|
1787
|
+
lock.release();
|
|
1788
|
+
}
|
|
1789
|
+
deleteEmailsByUids(ctx.db, args.folder, args.uids);
|
|
1790
|
+
return {
|
|
1791
|
+
content: [
|
|
1792
|
+
{
|
|
1793
|
+
type: "text",
|
|
1794
|
+
text: `Moved ${String(args.uids.length)} message(s) from ${args.folder} to ${trashFolder} (Trash).`
|
|
1795
|
+
}
|
|
1796
|
+
],
|
|
1797
|
+
structuredContent: {
|
|
1798
|
+
folder: args.folder,
|
|
1799
|
+
uids: args.uids,
|
|
1800
|
+
count: args.uids.length,
|
|
1801
|
+
action: "moved_to_trash",
|
|
1802
|
+
trash_folder: trashFolder
|
|
1803
|
+
}
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1529
1808
|
// src/tools/drafts/list-drafts.ts
|
|
1530
|
-
import { z as
|
|
1531
|
-
var
|
|
1532
|
-
folder:
|
|
1809
|
+
import { z as z12 } from "zod";
|
|
1810
|
+
var Input11 = z12.object({
|
|
1811
|
+
folder: z12.string().min(1).optional().describe(
|
|
1533
1812
|
"Optional explicit Drafts folder path. If omitted, mcp-inbox auto-detects via RFC 6154 SPECIAL-USE."
|
|
1534
1813
|
),
|
|
1535
|
-
limit:
|
|
1536
|
-
offset:
|
|
1537
|
-
max_staleness_seconds:
|
|
1538
|
-
response_format:
|
|
1814
|
+
limit: z12.number().int().min(1).max(100).default(20),
|
|
1815
|
+
offset: z12.number().int().min(0).default(0),
|
|
1816
|
+
max_staleness_seconds: z12.number().int().min(0).default(60),
|
|
1817
|
+
response_format: z12.enum(["markdown", "json"]).default("markdown")
|
|
1539
1818
|
});
|
|
1540
1819
|
var listDraftsTool = defineTool({
|
|
1541
1820
|
name: "imap_list_drafts",
|
|
@@ -1546,7 +1825,7 @@ var listDraftsTool = defineTool({
|
|
|
1546
1825
|
idempotentHint: true,
|
|
1547
1826
|
openWorldHint: true
|
|
1548
1827
|
},
|
|
1549
|
-
inputSchema:
|
|
1828
|
+
inputSchema: Input11,
|
|
1550
1829
|
handler: async (args, ctx) => {
|
|
1551
1830
|
const folder = await resolveSpecialFolder(ctx, "\\Drafts", args.folder);
|
|
1552
1831
|
const didSync = await syncIfStale(ctx, folder, args.max_staleness_seconds);
|
|
@@ -1573,12 +1852,12 @@ ${formatEmailListMarkdown(rows)}`;
|
|
|
1573
1852
|
});
|
|
1574
1853
|
|
|
1575
1854
|
// src/tools/drafts/get-draft.ts
|
|
1576
|
-
import { z as
|
|
1577
|
-
var
|
|
1578
|
-
uid:
|
|
1579
|
-
folder:
|
|
1580
|
-
max_staleness_seconds:
|
|
1581
|
-
response_format:
|
|
1855
|
+
import { z as z13 } from "zod";
|
|
1856
|
+
var Input12 = z13.object({
|
|
1857
|
+
uid: z13.number().int().positive().describe("IMAP UID of the draft in the Drafts folder. Use imap_list_drafts to discover UIDs."),
|
|
1858
|
+
folder: z13.string().min(1).optional().describe("Optional explicit Drafts folder path. Auto-detected from SPECIAL-USE when omitted."),
|
|
1859
|
+
max_staleness_seconds: z13.number().int().min(0).default(60),
|
|
1860
|
+
response_format: z13.enum(["markdown", "json"]).default("markdown")
|
|
1582
1861
|
});
|
|
1583
1862
|
var getDraftTool = defineTool({
|
|
1584
1863
|
name: "imap_get_draft",
|
|
@@ -1589,7 +1868,7 @@ var getDraftTool = defineTool({
|
|
|
1589
1868
|
idempotentHint: true,
|
|
1590
1869
|
openWorldHint: true
|
|
1591
1870
|
},
|
|
1592
|
-
inputSchema:
|
|
1871
|
+
inputSchema: Input12,
|
|
1593
1872
|
handler: async (args, ctx) => {
|
|
1594
1873
|
const folder = await resolveSpecialFolder(ctx, "\\Drafts", args.folder);
|
|
1595
1874
|
const envelope = await ensureEnvelopeCached(ctx, folder, args.uid, args.max_staleness_seconds);
|
|
@@ -1624,7 +1903,7 @@ function formatDraftMarkdown(d) {
|
|
|
1624
1903
|
}
|
|
1625
1904
|
|
|
1626
1905
|
// src/tools/drafts/create-draft.ts
|
|
1627
|
-
import { z as
|
|
1906
|
+
import { z as z14 } from "zod";
|
|
1628
1907
|
|
|
1629
1908
|
// src/imap/mime-builder.ts
|
|
1630
1909
|
import MailComposer from "nodemailer/lib/mail-composer/index.js";
|
|
@@ -1647,18 +1926,18 @@ async function buildRawMessage(input) {
|
|
|
1647
1926
|
}
|
|
1648
1927
|
|
|
1649
1928
|
// src/tools/drafts/create-draft.ts
|
|
1650
|
-
var AddressList =
|
|
1651
|
-
var
|
|
1929
|
+
var AddressList = z14.union([z14.string().min(1), z14.array(z14.string().min(1)).min(1)]);
|
|
1930
|
+
var Input13 = z14.object({
|
|
1652
1931
|
to: AddressList.describe("Recipient email address or array of addresses."),
|
|
1653
|
-
subject:
|
|
1654
|
-
body:
|
|
1655
|
-
html:
|
|
1932
|
+
subject: z14.string(),
|
|
1933
|
+
body: z14.string().optional().describe("Plain-text body."),
|
|
1934
|
+
html: z14.string().optional().describe("HTML body (combined with text via multipart/alternative)."),
|
|
1656
1935
|
cc: AddressList.optional(),
|
|
1657
1936
|
bcc: AddressList.optional(),
|
|
1658
|
-
from:
|
|
1937
|
+
from: z14.string().min(1).optional().describe(
|
|
1659
1938
|
"Sender address. Defaults to IMAP_USER. Some providers reject mismatched From headers."
|
|
1660
1939
|
),
|
|
1661
|
-
folder:
|
|
1940
|
+
folder: z14.string().min(1).optional().describe("Explicit Drafts folder. Auto-resolves via SPECIAL-USE when omitted.")
|
|
1662
1941
|
});
|
|
1663
1942
|
var createDraftTool = defineTool({
|
|
1664
1943
|
name: "imap_create_draft",
|
|
@@ -1669,7 +1948,7 @@ var createDraftTool = defineTool({
|
|
|
1669
1948
|
idempotentHint: false,
|
|
1670
1949
|
openWorldHint: true
|
|
1671
1950
|
},
|
|
1672
|
-
inputSchema:
|
|
1951
|
+
inputSchema: Input13,
|
|
1673
1952
|
handler: async (args, ctx) => {
|
|
1674
1953
|
const folder = await resolveSpecialFolder(ctx, "\\Drafts", args.folder);
|
|
1675
1954
|
const raw = await buildRawMessage({
|
|
@@ -1709,18 +1988,18 @@ var createDraftTool = defineTool({
|
|
|
1709
1988
|
});
|
|
1710
1989
|
|
|
1711
1990
|
// src/tools/drafts/update-draft.ts
|
|
1712
|
-
import { z as
|
|
1713
|
-
var AddressList2 =
|
|
1714
|
-
var
|
|
1715
|
-
uid:
|
|
1991
|
+
import { z as z15 } from "zod";
|
|
1992
|
+
var AddressList2 = z15.union([z15.string().min(1), z15.array(z15.string().min(1)).min(1)]);
|
|
1993
|
+
var Input14 = z15.object({
|
|
1994
|
+
uid: z15.number().int().positive().describe("UID of the existing draft to replace. Use imap_list_drafts to find it."),
|
|
1716
1995
|
to: AddressList2,
|
|
1717
|
-
subject:
|
|
1718
|
-
body:
|
|
1719
|
-
html:
|
|
1996
|
+
subject: z15.string(),
|
|
1997
|
+
body: z15.string().optional(),
|
|
1998
|
+
html: z15.string().optional(),
|
|
1720
1999
|
cc: AddressList2.optional(),
|
|
1721
2000
|
bcc: AddressList2.optional(),
|
|
1722
|
-
from:
|
|
1723
|
-
folder:
|
|
2001
|
+
from: z15.string().min(1).optional(),
|
|
2002
|
+
folder: z15.string().min(1).optional()
|
|
1724
2003
|
});
|
|
1725
2004
|
var updateDraftTool = defineTool({
|
|
1726
2005
|
name: "imap_update_draft",
|
|
@@ -1732,7 +2011,7 @@ var updateDraftTool = defineTool({
|
|
|
1732
2011
|
idempotentHint: false,
|
|
1733
2012
|
openWorldHint: true
|
|
1734
2013
|
},
|
|
1735
|
-
inputSchema:
|
|
2014
|
+
inputSchema: Input14,
|
|
1736
2015
|
handler: async (args, ctx) => {
|
|
1737
2016
|
const folder = await resolveSpecialFolder(ctx, "\\Drafts", args.folder);
|
|
1738
2017
|
const raw = await buildRawMessage({
|
|
@@ -1804,7 +2083,7 @@ var updateDraftTool = defineTool({
|
|
|
1804
2083
|
});
|
|
1805
2084
|
|
|
1806
2085
|
// src/tools/send/send-email.ts
|
|
1807
|
-
import { z as
|
|
2086
|
+
import { z as z16 } from "zod";
|
|
1808
2087
|
|
|
1809
2088
|
// src/tools/send/shared.ts
|
|
1810
2089
|
function normalizeAddrs(value) {
|
|
@@ -1846,15 +2125,15 @@ function flattenCompose(args) {
|
|
|
1846
2125
|
}
|
|
1847
2126
|
|
|
1848
2127
|
// src/tools/send/send-email.ts
|
|
1849
|
-
var AddressList3 =
|
|
1850
|
-
var
|
|
2128
|
+
var AddressList3 = z16.union([z16.string().min(1), z16.array(z16.string().min(1)).min(1)]);
|
|
2129
|
+
var Input15 = z16.object({
|
|
1851
2130
|
to: AddressList3.describe("Recipient email address or array of addresses."),
|
|
1852
|
-
subject:
|
|
1853
|
-
body:
|
|
1854
|
-
html:
|
|
2131
|
+
subject: z16.string(),
|
|
2132
|
+
body: z16.string().optional().describe("Plain-text body."),
|
|
2133
|
+
html: z16.string().optional().describe("HTML body (sent as multipart/alternative with text)."),
|
|
1855
2134
|
cc: AddressList3.optional(),
|
|
1856
2135
|
bcc: AddressList3.optional(),
|
|
1857
|
-
from:
|
|
2136
|
+
from: z16.string().min(1).optional().describe(
|
|
1858
2137
|
"Sender address. Defaults to IMAP_USER. Providers like Gmail and Fastmail reject mismatched From unless the address is a verified alias."
|
|
1859
2138
|
)
|
|
1860
2139
|
});
|
|
@@ -1867,7 +2146,7 @@ var sendEmailTool = defineTool({
|
|
|
1867
2146
|
idempotentHint: false,
|
|
1868
2147
|
openWorldHint: true
|
|
1869
2148
|
},
|
|
1870
|
-
inputSchema:
|
|
2149
|
+
inputSchema: Input15,
|
|
1871
2150
|
handler: async (args, ctx) => {
|
|
1872
2151
|
const compose = flattenCompose({
|
|
1873
2152
|
...args.from !== void 0 && { from: args.from },
|
|
@@ -1914,11 +2193,11 @@ var sendEmailTool = defineTool({
|
|
|
1914
2193
|
});
|
|
1915
2194
|
|
|
1916
2195
|
// src/tools/send/send-draft.ts
|
|
1917
|
-
import { z as
|
|
2196
|
+
import { z as z17 } from "zod";
|
|
1918
2197
|
import { simpleParser as simpleParser2 } from "mailparser";
|
|
1919
|
-
var
|
|
1920
|
-
uid:
|
|
1921
|
-
folder:
|
|
2198
|
+
var Input16 = z17.object({
|
|
2199
|
+
uid: z17.number().int().positive().describe("UID of the draft to send."),
|
|
2200
|
+
folder: z17.string().min(1).optional().describe("Explicit Drafts folder. Auto-resolves via SPECIAL-USE when omitted.")
|
|
1922
2201
|
});
|
|
1923
2202
|
var sendDraftTool = defineTool({
|
|
1924
2203
|
name: "imap_send_draft",
|
|
@@ -1929,7 +2208,7 @@ var sendDraftTool = defineTool({
|
|
|
1929
2208
|
idempotentHint: false,
|
|
1930
2209
|
openWorldHint: true
|
|
1931
2210
|
},
|
|
1932
|
-
inputSchema:
|
|
2211
|
+
inputSchema: Input16,
|
|
1933
2212
|
handler: async (args, ctx) => {
|
|
1934
2213
|
const folder = await resolveSpecialFolder(ctx, "\\Drafts", args.folder);
|
|
1935
2214
|
const imap = await ctx.imap.connection();
|
|
@@ -2031,20 +2310,20 @@ function addressList(field) {
|
|
|
2031
2310
|
}
|
|
2032
2311
|
|
|
2033
2312
|
// src/tools/send/reply.ts
|
|
2034
|
-
import { z as
|
|
2035
|
-
var AddressList4 =
|
|
2036
|
-
var
|
|
2037
|
-
folder:
|
|
2038
|
-
uid:
|
|
2039
|
-
body:
|
|
2040
|
-
html:
|
|
2313
|
+
import { z as z18 } from "zod";
|
|
2314
|
+
var AddressList4 = z18.union([z18.string().min(1), z18.array(z18.string().min(1)).min(1)]);
|
|
2315
|
+
var Input17 = z18.object({
|
|
2316
|
+
folder: z18.string().min(1).describe("Folder of the original message."),
|
|
2317
|
+
uid: z18.number().int().positive().describe("UID of the message being replied to."),
|
|
2318
|
+
body: z18.string().optional(),
|
|
2319
|
+
html: z18.string().optional(),
|
|
2041
2320
|
cc: AddressList4.optional(),
|
|
2042
2321
|
bcc: AddressList4.optional(),
|
|
2043
|
-
reply_all:
|
|
2322
|
+
reply_all: z18.boolean().default(false).describe(
|
|
2044
2323
|
"When true, CC the original To + Cc recipients (minus the sender). When false, reply only to the original From."
|
|
2045
2324
|
),
|
|
2046
|
-
from:
|
|
2047
|
-
max_staleness_seconds:
|
|
2325
|
+
from: z18.string().min(1).optional(),
|
|
2326
|
+
max_staleness_seconds: z18.number().int().min(0).default(60)
|
|
2048
2327
|
});
|
|
2049
2328
|
var replyTool = defineTool({
|
|
2050
2329
|
name: "imap_reply",
|
|
@@ -2055,7 +2334,7 @@ var replyTool = defineTool({
|
|
|
2055
2334
|
idempotentHint: false,
|
|
2056
2335
|
openWorldHint: true
|
|
2057
2336
|
},
|
|
2058
|
-
inputSchema:
|
|
2337
|
+
inputSchema: Input17,
|
|
2059
2338
|
handler: async (args, ctx) => {
|
|
2060
2339
|
const original = await ensureEnvelopeCached(
|
|
2061
2340
|
ctx,
|
|
@@ -2147,19 +2426,19 @@ function dedupeAddrs(addrs, exclude) {
|
|
|
2147
2426
|
}
|
|
2148
2427
|
|
|
2149
2428
|
// src/tools/send/forward.ts
|
|
2150
|
-
import { z as
|
|
2151
|
-
var AddressList5 =
|
|
2152
|
-
var
|
|
2153
|
-
folder:
|
|
2154
|
-
uid:
|
|
2429
|
+
import { z as z19 } from "zod";
|
|
2430
|
+
var AddressList5 = z19.union([z19.string().min(1), z19.array(z19.string().min(1)).min(1)]);
|
|
2431
|
+
var Input18 = z19.object({
|
|
2432
|
+
folder: z19.string().min(1).describe("Folder of the original message."),
|
|
2433
|
+
uid: z19.number().int().positive().describe("UID of the message to forward."),
|
|
2155
2434
|
to: AddressList5.describe("Recipient(s) to forward to."),
|
|
2156
|
-
body:
|
|
2435
|
+
body: z19.string().optional().describe(
|
|
2157
2436
|
'Optional prefix body (e.g. "FYI, thought you should see this."). Quoted original follows.'
|
|
2158
2437
|
),
|
|
2159
2438
|
cc: AddressList5.optional(),
|
|
2160
2439
|
bcc: AddressList5.optional(),
|
|
2161
|
-
from:
|
|
2162
|
-
max_staleness_seconds:
|
|
2440
|
+
from: z19.string().min(1).optional(),
|
|
2441
|
+
max_staleness_seconds: z19.number().int().min(0).default(60)
|
|
2163
2442
|
});
|
|
2164
2443
|
var forwardTool = defineTool({
|
|
2165
2444
|
name: "imap_forward",
|
|
@@ -2170,7 +2449,7 @@ var forwardTool = defineTool({
|
|
|
2170
2449
|
idempotentHint: false,
|
|
2171
2450
|
openWorldHint: true
|
|
2172
2451
|
},
|
|
2173
|
-
inputSchema:
|
|
2452
|
+
inputSchema: Input18,
|
|
2174
2453
|
handler: async (args, ctx) => {
|
|
2175
2454
|
const original = await ensureEnvelopeCached(
|
|
2176
2455
|
ctx,
|
|
@@ -2248,16 +2527,16 @@ function escapeHtml(s) {
|
|
|
2248
2527
|
}
|
|
2249
2528
|
|
|
2250
2529
|
// src/tools/attachments/get-attachment.ts
|
|
2251
|
-
import { z as
|
|
2530
|
+
import { z as z20 } from "zod";
|
|
2252
2531
|
import { simpleParser as simpleParser3 } from "mailparser";
|
|
2253
|
-
var
|
|
2254
|
-
folder:
|
|
2255
|
-
uid:
|
|
2256
|
-
filename:
|
|
2532
|
+
var Input19 = z20.object({
|
|
2533
|
+
folder: z20.string().min(1).describe("Folder containing the message."),
|
|
2534
|
+
uid: z20.number().int().positive().describe("IMAP UID of the message."),
|
|
2535
|
+
filename: z20.string().min(1).optional().describe(
|
|
2257
2536
|
"Filename of the attachment to fetch. First match wins if the message has multiple attachments with the same name - use part_id to disambiguate."
|
|
2258
2537
|
),
|
|
2259
|
-
part_id:
|
|
2260
|
-
max_inline_mb:
|
|
2538
|
+
part_id: z20.string().min(1).optional().describe('MIME part ID (e.g. "1.2"). Use when multiple parts share a filename.'),
|
|
2539
|
+
max_inline_mb: z20.number().int().min(1).max(50).default(5).describe(
|
|
2261
2540
|
"Maximum attachment size to return inline, in MB. Attachments larger than this are rejected with a clear error. Cap exists to avoid blowing up MCP response size."
|
|
2262
2541
|
)
|
|
2263
2542
|
}).refine((v) => v.filename !== void 0 || v.part_id !== void 0, {
|
|
@@ -2272,7 +2551,7 @@ var getAttachmentTool = defineTool({
|
|
|
2272
2551
|
idempotentHint: true,
|
|
2273
2552
|
openWorldHint: true
|
|
2274
2553
|
},
|
|
2275
|
-
inputSchema:
|
|
2554
|
+
inputSchema: Input19,
|
|
2276
2555
|
handler: async (args, ctx) => {
|
|
2277
2556
|
const imap = await ctx.imap.connection();
|
|
2278
2557
|
const lock = await imap.getMailboxLock(args.folder);
|
|
@@ -2412,6 +2691,11 @@ var tools = [
|
|
|
2412
2691
|
markUnreadTool,
|
|
2413
2692
|
moveToFolderTool,
|
|
2414
2693
|
deleteEmailTool,
|
|
2694
|
+
// Bulk variants of the same (one IMAP round-trip for N UIDs)
|
|
2695
|
+
markReadMultipleTool,
|
|
2696
|
+
markUnreadMultipleTool,
|
|
2697
|
+
moveMultipleTool,
|
|
2698
|
+
deleteMultipleTool,
|
|
2415
2699
|
// Drafts (compose)
|
|
2416
2700
|
createDraftTool,
|
|
2417
2701
|
updateDraftTool,
|
|
@@ -2430,7 +2714,15 @@ function listToolEntries() {
|
|
|
2430
2714
|
return tools.map((t) => ({
|
|
2431
2715
|
name: t.name,
|
|
2432
2716
|
description: t.description,
|
|
2433
|
-
|
|
2717
|
+
// `unrepresentable: 'any'` is needed because some schemas use
|
|
2718
|
+
// `z.coerce.date()` (which has no JSON Schema equivalent). With
|
|
2719
|
+
// this setting, such types become `{}` (matches anything) in the
|
|
2720
|
+
// exposed inputSchema, and the real validation still happens on
|
|
2721
|
+
// the Zod side inside the CallTool dispatcher.
|
|
2722
|
+
inputSchema: z21.toJSONSchema(t.inputSchema, {
|
|
2723
|
+
target: "draft-7",
|
|
2724
|
+
unrepresentable: "any"
|
|
2725
|
+
}),
|
|
2434
2726
|
annotations: t.annotations
|
|
2435
2727
|
}));
|
|
2436
2728
|
}
|