imap-mcp 0.1.1 → 0.1.3
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 +42 -30
- package/dist/tools/create-draft.js +44 -8
- package/dist/tools/create-draft.test.js +70 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://langmail.me/?ref=imap-mcp">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/langmail/.github/main/assets/wordmark-dark.svg">
|
|
5
|
+
<img alt="Langmail" src="https://raw.githubusercontent.com/langmail/.github/main/assets/wordmark-light.svg" width="120">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<h1 align="center">imap-mcp</h1>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<b>An MCP server that lets your AI agent save email drafts to any IMAP mailbox.</b><br>
|
|
14
|
+
It gives your agent one tool, <code>create-draft</code>, which saves a message to your Drafts folder for you to review and send. It works with any IMAP server that accepts a password login and with any MCP client that starts local servers, such as Claude Desktop, Claude Code or Cursor.
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="https://www.npmjs.com/package/imap-mcp"><img alt="npm" src="https://img.shields.io/npm/v/imap-mcp?style=flat-square"></a>
|
|
19
|
+
<a href="https://github.com/langmail/imap-mcp/actions/workflows/release.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/langmail/imap-mcp/release.yml?branch=main&style=flat-square&label=CI"></a>
|
|
20
|
+
<a href="https://github.com/langmail/imap-mcp#license"><img alt="License" src="https://img.shields.io/npm/l/imap-mcp?style=flat-square"></a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
<a href="https://discord.gg/CabhN3xuyk"><img alt="Join us on Discord" src="https://img.shields.io/badge/Join%20us%20on%20Discord-5865F2?style=for-the-badge&logo=discord&logoColor=white" height="40"></a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<a href="#available-tools">Tools</a> ·
|
|
29
|
+
<a href="https://github.com/langmail/imap-mcp/blob/main/CHANGELOG.md">Changelog</a> ·
|
|
30
|
+
<a href="https://langmail.me/?ref=imap-mcp">Hosted version</a>
|
|
31
|
+
</p>
|
|
2
32
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
📧 An IMAP Model Context Protocol (MCP) server to expose IMAP operations as tools for AI assistants.
|
|
6
|
-
|
|
7
|
-
[](https://choosealicense.com/licenses/mit/)
|
|
8
|
-
[](https://github.com/prettier/prettier)
|
|
9
|
-
[](https://modelcontextprotocol.io)
|
|
10
|
-
[](https://github.com/semantic-release/semantic-release)
|
|
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
|
-
|
|
14
|
-
</div>
|
|
15
|
-
|
|
16
|
-
## ✨ Features
|
|
17
|
-
|
|
18
|
-
- **Email Draft Creation**: Create draft emails that are saved to your IMAP server's drafts folder
|
|
19
|
-
- **IMAP Integration**: Connect to any IMAP-compatible email server (Gmail, Outlook, etc.)
|
|
20
|
-
- **Secure Authentication**: Uses environment variables for secure credential management
|
|
21
|
-
- **MCP Compatible**: Works with Claude and other AI assistants that support the Model Context Protocol
|
|
22
|
-
- **TypeScript**: Full TypeScript support with proper type definitions
|
|
23
|
-
|
|
24
|
-
## Setup
|
|
25
|
-
|
|
26
|
-
```
|
|
33
|
+
```json
|
|
27
34
|
{
|
|
28
35
|
"mcpServers": {
|
|
29
|
-
...,
|
|
30
36
|
"imap": {
|
|
31
37
|
"command": "npx",
|
|
32
|
-
"args": [
|
|
33
|
-
"imap-mcp"
|
|
34
|
-
],
|
|
38
|
+
"args": ["imap-mcp"],
|
|
35
39
|
"env": {
|
|
36
40
|
"IMAP_HOST": "<IMAP host>",
|
|
37
41
|
"IMAP_PORT": "<IMAP port>",
|
|
@@ -44,6 +48,14 @@ Maintained by the team behind Langmail. Want mail, calendar and contacts for you
|
|
|
44
48
|
}
|
|
45
49
|
```
|
|
46
50
|
|
|
51
|
+
## ✨ Features
|
|
52
|
+
|
|
53
|
+
- **Email Draft Creation**: Create draft emails that are saved to your IMAP server's drafts folder
|
|
54
|
+
- **IMAP Integration**: Connect to any IMAP-compatible email server (Gmail, Outlook, etc.)
|
|
55
|
+
- **Secure Authentication**: Uses environment variables for secure credential management
|
|
56
|
+
- **MCP Compatible**: Works with Claude and other AI assistants that support the Model Context Protocol
|
|
57
|
+
- **TypeScript**: Full TypeScript support with proper type definitions
|
|
58
|
+
|
|
47
59
|
## Usage
|
|
48
60
|
|
|
49
61
|
1. Compile TypeScript to JavaScript:
|
|
@@ -78,7 +90,7 @@ Creates a draft email message and saves it to the IMAP server's drafts folder.
|
|
|
78
90
|
}
|
|
79
91
|
```
|
|
80
92
|
|
|
81
|
-
The tool
|
|
93
|
+
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`.
|
|
82
94
|
|
|
83
95
|
## License
|
|
84
96
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
2
|
export function registerCreateDraft(client, server) {
|
|
3
3
|
server.tool("create-draft", "Creates a draft email message", {
|
|
4
4
|
to: z.string(),
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imap-mcp",
|
|
3
3
|
"mcpName": "io.github.langmail/imap-mcp",
|
|
4
|
-
"description": "
|
|
5
|
-
"version": "0.1.
|
|
4
|
+
"description": "An MCP server that lets your AI agent save email drafts to any IMAP mailbox.",
|
|
5
|
+
"version": "0.1.3",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"author": "Dominik Grusemann",
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
38
38
|
"dotenv": "^16.5.0",
|
|
39
39
|
"imap": "^0.8.19",
|
|
40
40
|
"zod": "^3.25.67"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"eslint-config-prettier": "^10.1.5",
|
|
52
52
|
"husky": "^9.1.7",
|
|
53
53
|
"lint-staged": "^16.1.2",
|
|
54
|
-
"prettier": "3.
|
|
54
|
+
"prettier": "3.10.1",
|
|
55
55
|
"semantic-release": "^25.0.9",
|
|
56
56
|
"shx": "^0.4.0",
|
|
57
57
|
"typescript": "^5.8.3",
|