imap-mcp 0.1.0 → 0.1.2
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/README.md +3 -1
- package/dist/tools/create-draft.js +43 -7
- package/dist/tools/create-draft.test.js +70 -3
- package/package.json +9 -7
- package/dist/tools/create-event.js +0 -29
- package/dist/tools/create-event.test.js +0 -4
- package/dist/tools/delete-event.js +0 -9
- package/dist/tools/index.js +0 -1
- package/dist/tools/list-calendars.js +0 -7
- package/dist/tools/list-events.js +0 -21
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
[](https://modelcontextprotocol.io)
|
|
10
10
|
[](https://github.com/semantic-release/semantic-release)
|
|
11
11
|
|
|
12
|
+
Maintained by the team behind Langmail. Want mail, calendar and contacts for your agent over one hosted MCP, with OAuth and nothing to run? → [langmail.me](https://langmail.me/?ref=imap-mcp)
|
|
13
|
+
|
|
12
14
|
</div>
|
|
13
15
|
|
|
14
16
|
## ✨ Features
|
|
@@ -76,7 +78,7 @@ Creates a draft email message and saves it to the IMAP server's drafts folder.
|
|
|
76
78
|
}
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
The tool
|
|
81
|
+
The tool saves the draft to the folder your server marks as the drafts folder (the `\Drafts` special-use attribute, RFC 6154), such as `[Gmail]/Drafts` on Gmail. If the server marks no folder that way, it tries `INBOX.Drafts`, then `Drafts`.
|
|
80
82
|
|
|
81
83
|
## License
|
|
82
84
|
|
|
@@ -8,20 +8,36 @@ export function registerCreateDraft(client, server) {
|
|
|
8
8
|
}, async ({ to, subject, body, from }) => {
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
10
|
client.once("ready", () => {
|
|
11
|
-
client.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
client.openBox(
|
|
15
|
-
if (
|
|
16
|
-
reject(new Error(`Failed to open drafts folder: ${
|
|
11
|
+
client.getBoxes((err, boxes) => {
|
|
12
|
+
const draftsPath = err ? undefined : findDraftsFolder(boxes);
|
|
13
|
+
if (draftsPath) {
|
|
14
|
+
client.openBox(draftsPath, false, (err) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
reject(new Error(`Failed to open drafts folder: ${err.message}`));
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
createDraftMessage();
|
|
20
20
|
});
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
openFallbackDraftsFolder();
|
|
24
24
|
});
|
|
25
|
+
function openFallbackDraftsFolder() {
|
|
26
|
+
client.openBox("INBOX.Drafts", false, (err) => {
|
|
27
|
+
if (err) {
|
|
28
|
+
// Try opening "Drafts" folder instead
|
|
29
|
+
client.openBox("Drafts", false, (err2) => {
|
|
30
|
+
if (err2) {
|
|
31
|
+
reject(new Error(`Failed to open drafts folder: ${err2.message}`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
createDraftMessage();
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
createDraftMessage();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
25
41
|
function createDraftMessage() {
|
|
26
42
|
const message = [
|
|
27
43
|
`From: ${from || process.env.IMAP_USERNAME || ""}`,
|
|
@@ -53,3 +69,23 @@ export function registerCreateDraft(client, server) {
|
|
|
53
69
|
});
|
|
54
70
|
});
|
|
55
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the full path of the folder the server marks with the `\Drafts`
|
|
74
|
+
* special-use attribute (RFC 6154), or undefined if none is marked.
|
|
75
|
+
*/
|
|
76
|
+
export function findDraftsFolder(boxes, parents = []) {
|
|
77
|
+
for (const [name, box] of Object.entries(boxes)) {
|
|
78
|
+
const segments = [...parents, name];
|
|
79
|
+
if (box.attribs?.some((a) => a.toLowerCase() === "\\drafts")) {
|
|
80
|
+
// A parent the server doesn't list has no delimiter of its own, so join
|
|
81
|
+
// with the matched folder's, the server's one hierarchy separator.
|
|
82
|
+
return segments.join(box.delimiter ?? "");
|
|
83
|
+
}
|
|
84
|
+
if (box.children) {
|
|
85
|
+
const found = findDraftsFolder(box.children, segments);
|
|
86
|
+
if (found)
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
@@ -1,4 +1,71 @@
|
|
|
1
|
-
import { describe, test } from "vitest";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { registerCreateDraft } from "./create-draft.js";
|
|
3
|
+
function box(attribs, children = null) {
|
|
4
|
+
return {
|
|
5
|
+
attribs,
|
|
6
|
+
delimiter: "/",
|
|
7
|
+
children: children,
|
|
8
|
+
parent: null,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function setup(boxes, existing) {
|
|
12
|
+
const listeners = {};
|
|
13
|
+
let openedBox;
|
|
14
|
+
const client = {
|
|
15
|
+
once: vi.fn((event, cb) => {
|
|
16
|
+
listeners[event] = cb;
|
|
17
|
+
}),
|
|
18
|
+
connect: vi.fn(() => listeners.ready()),
|
|
19
|
+
getBoxes: vi.fn((cb) => cb(null, boxes)),
|
|
20
|
+
openBox: vi.fn((name, _readOnly, cb) => {
|
|
21
|
+
if (existing.includes(name)) {
|
|
22
|
+
openedBox = name;
|
|
23
|
+
cb(null);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
cb(new Error(`Mailbox doesn't exist: ${name}`));
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
append: vi.fn((_msg, _opts, cb) => cb(null)),
|
|
30
|
+
};
|
|
31
|
+
let handler;
|
|
32
|
+
const server = {
|
|
33
|
+
tool: vi.fn((...args) => {
|
|
34
|
+
handler = args[args.length - 1];
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
registerCreateDraft(client, server);
|
|
38
|
+
const run = () => handler({ to: "jane@example.com", subject: "Hi", body: "Hello" });
|
|
39
|
+
return { client, run, openedBox: () => openedBox };
|
|
40
|
+
}
|
|
41
|
+
describe("create-draft", () => {
|
|
42
|
+
test("saves to the folder marked \\Drafts, whatever its name and nesting", async () => {
|
|
43
|
+
const { client, run, openedBox } = setup({
|
|
44
|
+
INBOX: box(["\\HasNoChildren"]),
|
|
45
|
+
"[Gmail]": box(["\\Noselect", "\\HasChildren"], {
|
|
46
|
+
"All Mail": box(["\\All"]),
|
|
47
|
+
Entwürfe: box(["\\HasNoChildren", "\\Drafts"]),
|
|
48
|
+
}),
|
|
49
|
+
Drafts: box([]),
|
|
50
|
+
}, ["[Gmail]/Entwürfe", "Drafts"]);
|
|
51
|
+
const result = await run();
|
|
52
|
+
expect(openedBox()).toBe("[Gmail]/Entwürfe");
|
|
53
|
+
expect(client.append).toHaveBeenCalledOnce();
|
|
54
|
+
expect(result.content[0].text).toBe("Draft created successfully for jane@example.com");
|
|
55
|
+
});
|
|
56
|
+
test("falls back to INBOX.Drafts or Drafts when no folder is marked \\Drafts", async () => {
|
|
57
|
+
const { client, run, openedBox } = setup({ INBOX: box([]), Drafts: box([]) }, ["Drafts"]);
|
|
58
|
+
await run();
|
|
59
|
+
expect(client.openBox.mock.calls.map((c) => c[0])).toEqual([
|
|
60
|
+
"INBOX.Drafts",
|
|
61
|
+
"Drafts",
|
|
62
|
+
]);
|
|
63
|
+
expect(openedBox()).toBe("Drafts");
|
|
64
|
+
expect(client.append).toHaveBeenCalledOnce();
|
|
65
|
+
});
|
|
66
|
+
test("fails when no drafts folder can be opened", async () => {
|
|
67
|
+
const { client, run } = setup({ INBOX: box([]) }, []);
|
|
68
|
+
await expect(run()).rejects.toThrow("Failed to open drafts folder");
|
|
69
|
+
expect(client.append).not.toHaveBeenCalled();
|
|
70
|
+
});
|
|
4
71
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imap-mcp",
|
|
3
|
+
"mcpName": "io.github.langmail/imap-mcp",
|
|
3
4
|
"description": "📧 An IMAP Model Context Protocol (MCP) server to expose IMAP operations as tools for AI assistants.",
|
|
4
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.2",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"bin": {
|
|
@@ -24,12 +25,12 @@
|
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
|
26
27
|
"type": "git",
|
|
27
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/langmail/imap-mcp.git"
|
|
28
29
|
},
|
|
29
30
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
31
|
+
"url": "https://github.com/langmail/imap-mcp/issues"
|
|
31
32
|
},
|
|
32
|
-
"homepage": "https://github.com/
|
|
33
|
+
"homepage": "https://github.com/langmail/imap-mcp#readme",
|
|
33
34
|
"author": "Dominik Grusemann",
|
|
34
35
|
"license": "MIT",
|
|
35
36
|
"dependencies": {
|
|
@@ -39,18 +40,19 @@
|
|
|
39
40
|
"zod": "^3.25.67"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@types/imap": "^0.8.42",
|
|
43
43
|
"@eslint/js": "^9.29.0",
|
|
44
44
|
"@semantic-release/changelog": "^6.0.3",
|
|
45
45
|
"@semantic-release/git": "^10.0.1",
|
|
46
|
-
"@semantic-release/github": "^
|
|
46
|
+
"@semantic-release/github": "^12.0.11",
|
|
47
|
+
"@semantic-release/npm": "^13.2.0",
|
|
48
|
+
"@types/imap": "^0.8.42",
|
|
47
49
|
"@types/node": "^24.0.4",
|
|
48
50
|
"eslint": "^9.29.0",
|
|
49
51
|
"eslint-config-prettier": "^10.1.5",
|
|
50
52
|
"husky": "^9.1.7",
|
|
51
53
|
"lint-staged": "^16.1.2",
|
|
52
54
|
"prettier": "3.6.1",
|
|
53
|
-
"semantic-release": "^
|
|
55
|
+
"semantic-release": "^25.0.9",
|
|
54
56
|
"shx": "^0.4.0",
|
|
55
57
|
"typescript": "^5.8.3",
|
|
56
58
|
"typescript-eslint": "^8.35.0",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
const recurrenceRuleSchema = z.object({
|
|
3
|
-
freq: z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).optional(),
|
|
4
|
-
interval: z.number().optional(),
|
|
5
|
-
count: z.number().optional(),
|
|
6
|
-
until: z.string().datetime().optional(), // ISO 8601 string
|
|
7
|
-
byday: z.array(z.string()).optional(), // e.g. ["MO", "TU"]
|
|
8
|
-
bymonthday: z.array(z.number()).optional(),
|
|
9
|
-
bymonth: z.array(z.number()).optional(),
|
|
10
|
-
});
|
|
11
|
-
export function registerCreateEvent(client, server) {
|
|
12
|
-
server.tool("create-event", "Creates an event in the calendar specified by its URL", {
|
|
13
|
-
summary: z.string(),
|
|
14
|
-
start: z.string().datetime(),
|
|
15
|
-
end: z.string().datetime(),
|
|
16
|
-
calendarUrl: z.string(),
|
|
17
|
-
recurrenceRule: recurrenceRuleSchema.optional(),
|
|
18
|
-
}, async ({ calendarUrl, summary, start, end, recurrenceRule }) => {
|
|
19
|
-
const event = await client.createEvent(calendarUrl, {
|
|
20
|
-
summary: summary,
|
|
21
|
-
start: new Date(start),
|
|
22
|
-
end: new Date(end),
|
|
23
|
-
recurrenceRule: recurrenceRule,
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
content: [{ type: "text", text: event.uid }],
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export function registerDeleteEvent(client, server) {
|
|
3
|
-
server.tool("delete-event", "Deletes an event in the calendar specified by its URL", { uid: z.string(), calendarUrl: z.string() }, async ({ uid, calendarUrl }) => {
|
|
4
|
-
await client.deleteEvent(calendarUrl, uid);
|
|
5
|
-
return {
|
|
6
|
-
content: [{ type: "text", text: "Event deleted" }],
|
|
7
|
-
};
|
|
8
|
-
});
|
|
9
|
-
}
|
package/dist/tools/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./create-draft.js";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export async function registerListCalendars(client, server) {
|
|
2
|
-
const calendars = await client.getCalendars();
|
|
3
|
-
server.tool("list-calendars", "List all calendars returning both name and URL", {}, async () => {
|
|
4
|
-
const data = calendars.map((c) => ({ name: c.displayName, url: c.url }));
|
|
5
|
-
return { content: [{ type: "text", text: JSON.stringify(data) }] };
|
|
6
|
-
});
|
|
7
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
const dateString = z.string().refine((val) => !isNaN(Date.parse(val)), {
|
|
3
|
-
message: "Invalid date string",
|
|
4
|
-
});
|
|
5
|
-
export function registerListEvents(client, server) {
|
|
6
|
-
server.tool("list-events", "List all events between start and end date in the calendar specified by its URL", { start: dateString, end: dateString, calendarUrl: z.string() }, async ({ calendarUrl, start, end }) => {
|
|
7
|
-
const options = {
|
|
8
|
-
start: new Date(start),
|
|
9
|
-
end: new Date(end),
|
|
10
|
-
};
|
|
11
|
-
const allEvents = await client.getEvents(calendarUrl, options);
|
|
12
|
-
const data = allEvents.map((e) => ({
|
|
13
|
-
summary: e.summary,
|
|
14
|
-
start: e.start,
|
|
15
|
-
end: e.end,
|
|
16
|
-
}));
|
|
17
|
-
return {
|
|
18
|
-
content: [{ type: "text", text: JSON.stringify(data) }],
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}
|