@honest-magic/mail-mcp 1.0.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/LICENSE +21 -0
- package/README.md +178 -0
- package/dist/cli/accounts.d.ts +7 -0
- package/dist/cli/accounts.js +171 -0
- package/dist/cli/accounts.js.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +48 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +658 -0
- package/dist/index.js +556 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/imap.d.ts +29 -0
- package/dist/protocol/imap.js +255 -0
- package/dist/protocol/imap.js.map +1 -0
- package/dist/protocol/smtp.d.ts +8 -0
- package/dist/protocol/smtp.js +56 -0
- package/dist/protocol/smtp.js.map +1 -0
- package/dist/security/keychain.d.ts +3 -0
- package/dist/security/keychain.js +18 -0
- package/dist/security/keychain.js.map +1 -0
- package/dist/security/oauth2.d.ts +9 -0
- package/dist/security/oauth2.js +51 -0
- package/dist/security/oauth2.js.map +1 -0
- package/dist/services/mail.d.ts +45 -0
- package/dist/services/mail.js +200 -0
- package/dist/services/mail.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/markdown.d.ts +1 -0
- package/dist/utils/markdown.js +11 -0
- package/dist/utils/markdown.js.map +1 -0
- package/package.json +53 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
import { getAccounts } from './config.js';
|
|
7
|
+
import { handleAccountsCommand } from './cli/accounts.js';
|
|
8
|
+
import { MailService } from './services/mail.js';
|
|
9
|
+
const WRITE_TOOLS = new Set([
|
|
10
|
+
'send_email',
|
|
11
|
+
'create_draft',
|
|
12
|
+
'move_email',
|
|
13
|
+
'modify_labels',
|
|
14
|
+
'register_oauth2_account',
|
|
15
|
+
'batch_operations',
|
|
16
|
+
]);
|
|
17
|
+
export class MailMCPServer {
|
|
18
|
+
readOnly;
|
|
19
|
+
server;
|
|
20
|
+
services = new Map();
|
|
21
|
+
constructor(readOnly = false) {
|
|
22
|
+
this.readOnly = readOnly;
|
|
23
|
+
this.server = new Server({
|
|
24
|
+
name: 'mail-mcp-server',
|
|
25
|
+
version: '0.1.0',
|
|
26
|
+
}, {
|
|
27
|
+
capabilities: {
|
|
28
|
+
tools: {},
|
|
29
|
+
},
|
|
30
|
+
...(this.readOnly ? {
|
|
31
|
+
instructions: 'This server is running in read-only mode. Write operations (send_email, create_draft, move_email, modify_labels, batch_operations, register_oauth2_account) are disabled.',
|
|
32
|
+
} : {}),
|
|
33
|
+
});
|
|
34
|
+
this.setupToolHandlers();
|
|
35
|
+
this.server.onerror = (error) => console.error('[MCP Error]', error);
|
|
36
|
+
}
|
|
37
|
+
async getService(accountId) {
|
|
38
|
+
if (this.services.has(accountId)) {
|
|
39
|
+
return this.services.get(accountId);
|
|
40
|
+
}
|
|
41
|
+
const accounts = getAccounts();
|
|
42
|
+
const account = accounts.find(a => a.id === accountId);
|
|
43
|
+
if (!account) {
|
|
44
|
+
throw new Error(`Account ${accountId} not found in configuration.`);
|
|
45
|
+
}
|
|
46
|
+
const service = new MailService(account, this.readOnly);
|
|
47
|
+
await service.connect();
|
|
48
|
+
this.services.set(accountId, service);
|
|
49
|
+
return service;
|
|
50
|
+
}
|
|
51
|
+
getTools(readOnly) {
|
|
52
|
+
const allTools = [
|
|
53
|
+
{
|
|
54
|
+
name: 'list_accounts',
|
|
55
|
+
description: 'List configured mail accounts',
|
|
56
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'list_emails',
|
|
64
|
+
description: 'List recent emails from a specific folder',
|
|
65
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
70
|
+
folder: { type: 'string', description: 'The folder to list emails from (default: INBOX)' },
|
|
71
|
+
count: { type: 'number', description: 'The number of emails to retrieve (default: 10)' }
|
|
72
|
+
},
|
|
73
|
+
required: ['accountId']
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'search_emails',
|
|
78
|
+
description: 'Search for emails based on various criteria',
|
|
79
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
84
|
+
folder: { type: 'string', description: 'The folder to search in (default: INBOX)' },
|
|
85
|
+
from: { type: 'string', description: 'Filter by sender' },
|
|
86
|
+
subject: { type: 'string', description: 'Filter by subject' },
|
|
87
|
+
since: { type: 'string', description: 'Filter by date (ISO format)' },
|
|
88
|
+
before: { type: 'string', description: 'Filter by date (ISO format)' },
|
|
89
|
+
keywords: { type: 'string', description: 'Filter by keywords in body' },
|
|
90
|
+
count: { type: 'number', description: 'The number of emails to retrieve (default: 10)' }
|
|
91
|
+
},
|
|
92
|
+
required: ['accountId']
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'read_email',
|
|
97
|
+
description: 'Read the content of a specific email',
|
|
98
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
99
|
+
inputSchema: {
|
|
100
|
+
type: 'object',
|
|
101
|
+
properties: {
|
|
102
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
103
|
+
uid: { type: 'string', description: 'The UID of the email to read' },
|
|
104
|
+
folder: { type: 'string', description: 'The folder containing the email (default: INBOX)' }
|
|
105
|
+
},
|
|
106
|
+
required: ['accountId', 'uid']
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'send_email',
|
|
111
|
+
description: 'Send an email and save it to the Sent folder',
|
|
112
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
113
|
+
inputSchema: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
properties: {
|
|
116
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
117
|
+
to: { type: 'string', description: 'Recipient email address' },
|
|
118
|
+
subject: { type: 'string', description: 'Email subject' },
|
|
119
|
+
body: { type: 'string', description: 'Email body content' },
|
|
120
|
+
isHtml: { type: 'boolean', description: 'Whether the body is HTML (default: false)' },
|
|
121
|
+
cc: { type: 'string', description: 'CC recipients' },
|
|
122
|
+
bcc: { type: 'string', description: 'BCC recipients' }
|
|
123
|
+
},
|
|
124
|
+
required: ['accountId', 'to', 'subject', 'body']
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'create_draft',
|
|
129
|
+
description: 'Create a draft email in the Drafts folder',
|
|
130
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
131
|
+
inputSchema: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
properties: {
|
|
134
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
135
|
+
to: { type: 'string', description: 'Recipient email address' },
|
|
136
|
+
subject: { type: 'string', description: 'Email subject' },
|
|
137
|
+
body: { type: 'string', description: 'Email body content' },
|
|
138
|
+
isHtml: { type: 'boolean', description: 'Whether the body is HTML (default: false)' },
|
|
139
|
+
cc: { type: 'string', description: 'CC recipients' },
|
|
140
|
+
bcc: { type: 'string', description: 'BCC recipients' }
|
|
141
|
+
},
|
|
142
|
+
required: ['accountId', 'to', 'subject', 'body']
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'list_folders',
|
|
147
|
+
description: 'List all available IMAP folders',
|
|
148
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
149
|
+
inputSchema: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {
|
|
152
|
+
accountId: { type: 'string', description: 'The ID of the account to use' }
|
|
153
|
+
},
|
|
154
|
+
required: ['accountId']
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'move_email',
|
|
159
|
+
description: 'Move an email from one folder to another',
|
|
160
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
161
|
+
inputSchema: {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
165
|
+
uid: { type: 'string', description: 'The UID of the email to move' },
|
|
166
|
+
sourceFolder: { type: 'string', description: 'The current folder of the email' },
|
|
167
|
+
targetFolder: { type: 'string', description: 'The destination folder' }
|
|
168
|
+
},
|
|
169
|
+
required: ['accountId', 'uid', 'sourceFolder', 'targetFolder']
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'modify_labels',
|
|
174
|
+
description: 'Add or remove IMAP flags/labels on an email',
|
|
175
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
176
|
+
inputSchema: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
180
|
+
uid: { type: 'string', description: 'The UID of the email' },
|
|
181
|
+
folder: { type: 'string', description: 'The folder containing the email' },
|
|
182
|
+
addLabels: { type: 'array', items: { type: 'string' }, description: 'Labels to add (e.g. \\Seen, \\Flagged)' },
|
|
183
|
+
removeLabels: { type: 'array', items: { type: 'string' }, description: 'Labels to remove' }
|
|
184
|
+
},
|
|
185
|
+
required: ['accountId', 'uid', 'folder']
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'get_thread',
|
|
190
|
+
description: 'Get all emails in a specific conversation/thread',
|
|
191
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
192
|
+
inputSchema: {
|
|
193
|
+
type: 'object',
|
|
194
|
+
properties: {
|
|
195
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
196
|
+
threadId: { type: 'string', description: 'The ID of the thread to retrieve' },
|
|
197
|
+
folder: { type: 'string', description: 'The folder containing the thread (default: INBOX)' }
|
|
198
|
+
},
|
|
199
|
+
required: ['accountId', 'threadId']
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: 'get_attachment',
|
|
204
|
+
description: 'Download an attachment from a specific email',
|
|
205
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
206
|
+
inputSchema: {
|
|
207
|
+
type: 'object',
|
|
208
|
+
properties: {
|
|
209
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
210
|
+
uid: { type: 'string', description: 'The UID of the email' },
|
|
211
|
+
filename: { type: 'string', description: 'The name of the attachment file' },
|
|
212
|
+
folder: { type: 'string', description: 'The folder containing the email (default: INBOX)' }
|
|
213
|
+
},
|
|
214
|
+
required: ['accountId', 'uid', 'filename']
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'extract_attachment_text',
|
|
219
|
+
description: 'Extract text content from a PDF or text attachment',
|
|
220
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
221
|
+
inputSchema: {
|
|
222
|
+
type: 'object',
|
|
223
|
+
properties: {
|
|
224
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
225
|
+
uid: { type: 'string', description: 'The UID of the email' },
|
|
226
|
+
filename: { type: 'string', description: 'The name of the attachment file' },
|
|
227
|
+
folder: { type: 'string', description: 'The folder containing the email (default: INBOX)' }
|
|
228
|
+
},
|
|
229
|
+
required: ['accountId', 'uid', 'filename']
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'register_oauth2_account',
|
|
234
|
+
description: 'Store OAuth2 credentials for an account in the keychain',
|
|
235
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
236
|
+
inputSchema: {
|
|
237
|
+
type: 'object',
|
|
238
|
+
properties: {
|
|
239
|
+
accountId: { type: 'string', description: 'The ID of the account' },
|
|
240
|
+
clientId: { type: 'string', description: 'OAuth2 Client ID' },
|
|
241
|
+
clientSecret: { type: 'string', description: 'OAuth2 Client Secret' },
|
|
242
|
+
refreshToken: { type: 'string', description: 'OAuth2 Refresh Token' },
|
|
243
|
+
tokenEndpoint: { type: 'string', description: 'OAuth2 Token Endpoint URL' }
|
|
244
|
+
},
|
|
245
|
+
required: ['accountId', 'clientId', 'clientSecret', 'refreshToken', 'tokenEndpoint']
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'batch_operations',
|
|
250
|
+
description: 'Perform batch operations (move, delete, label) on multiple emails',
|
|
251
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
252
|
+
inputSchema: {
|
|
253
|
+
type: 'object',
|
|
254
|
+
properties: {
|
|
255
|
+
accountId: { type: 'string', description: 'The ID of the account to use' },
|
|
256
|
+
uids: { type: 'array', items: { type: 'string' }, description: 'Array of email UIDs to operate on (max 100)' },
|
|
257
|
+
folder: { type: 'string', description: 'The folder containing the emails' },
|
|
258
|
+
action: { type: 'string', enum: ['move', 'delete', 'label'], description: 'The batch action to perform' },
|
|
259
|
+
targetFolder: { type: 'string', description: 'Target folder (required for move action)' },
|
|
260
|
+
addLabels: { type: 'array', items: { type: 'string' }, description: 'Labels to add (for label action)' },
|
|
261
|
+
removeLabels: { type: 'array', items: { type: 'string' }, description: 'Labels to remove (for label action)' }
|
|
262
|
+
},
|
|
263
|
+
required: ['accountId', 'uids', 'folder', 'action']
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
];
|
|
267
|
+
return readOnly ? allTools.filter(t => !WRITE_TOOLS.has(t.name)) : allTools;
|
|
268
|
+
}
|
|
269
|
+
async dispatchTool(name, readOnly, args) {
|
|
270
|
+
if (readOnly && WRITE_TOOLS.has(name)) {
|
|
271
|
+
return {
|
|
272
|
+
content: [{
|
|
273
|
+
type: 'text',
|
|
274
|
+
text: `Tool '${name}' is not available: server is running in read-only mode. Use a server without --read-only to perform write operations.`,
|
|
275
|
+
}],
|
|
276
|
+
isError: true,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
if (name === 'list_accounts') {
|
|
280
|
+
const accounts = getAccounts();
|
|
281
|
+
return {
|
|
282
|
+
content: [{
|
|
283
|
+
type: 'text',
|
|
284
|
+
text: JSON.stringify(accounts.map((a) => ({ id: a.id, name: a.name, user: a.user })), null, 2),
|
|
285
|
+
}],
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
// For test purposes — other tools require a real service connection
|
|
289
|
+
throw new McpError(ErrorCode.MethodNotFound, `Tool not found: ${name}`);
|
|
290
|
+
}
|
|
291
|
+
setupToolHandlers() {
|
|
292
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
293
|
+
tools: this.getTools(this.readOnly),
|
|
294
|
+
}));
|
|
295
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
296
|
+
try {
|
|
297
|
+
const toolName = request.params.name;
|
|
298
|
+
if (this.readOnly && WRITE_TOOLS.has(toolName)) {
|
|
299
|
+
return {
|
|
300
|
+
content: [{
|
|
301
|
+
type: 'text',
|
|
302
|
+
text: `Tool '${toolName}' is not available: server is running in read-only mode. Use a server without --read-only to perform write operations.`,
|
|
303
|
+
}],
|
|
304
|
+
isError: true,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
if (request.params.name === 'list_accounts') {
|
|
308
|
+
const accounts = getAccounts();
|
|
309
|
+
return {
|
|
310
|
+
content: [
|
|
311
|
+
{
|
|
312
|
+
type: 'text',
|
|
313
|
+
text: JSON.stringify(accounts.map((a) => ({ id: a.id, name: a.name, user: a.user })), null, 2),
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
if (request.params.name === 'list_emails') {
|
|
319
|
+
const args = request.params.arguments;
|
|
320
|
+
const service = await this.getService(args.accountId);
|
|
321
|
+
const messages = await service.listEmails(args.folder, args.count);
|
|
322
|
+
return {
|
|
323
|
+
content: [
|
|
324
|
+
{
|
|
325
|
+
type: 'text',
|
|
326
|
+
text: JSON.stringify(messages, null, 2)
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
if (request.params.name === 'search_emails') {
|
|
332
|
+
const args = request.params.arguments;
|
|
333
|
+
const service = await this.getService(args.accountId);
|
|
334
|
+
const messages = await service.searchEmails({
|
|
335
|
+
from: args.from,
|
|
336
|
+
subject: args.subject,
|
|
337
|
+
since: args.since,
|
|
338
|
+
before: args.before,
|
|
339
|
+
keywords: args.keywords
|
|
340
|
+
}, args.folder, args.count);
|
|
341
|
+
return {
|
|
342
|
+
content: [
|
|
343
|
+
{
|
|
344
|
+
type: 'text',
|
|
345
|
+
text: JSON.stringify(messages, null, 2)
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
if (request.params.name === 'read_email') {
|
|
351
|
+
const args = request.params.arguments;
|
|
352
|
+
const service = await this.getService(args.accountId);
|
|
353
|
+
const content = await service.readEmail(args.uid, args.folder);
|
|
354
|
+
return {
|
|
355
|
+
content: [
|
|
356
|
+
{
|
|
357
|
+
type: 'text',
|
|
358
|
+
text: content
|
|
359
|
+
}
|
|
360
|
+
]
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
if (request.params.name === 'send_email') {
|
|
364
|
+
const args = request.params.arguments;
|
|
365
|
+
const service = await this.getService(args.accountId);
|
|
366
|
+
await service.sendEmail(args.to, args.subject, args.body, args.isHtml, args.cc, args.bcc);
|
|
367
|
+
return {
|
|
368
|
+
content: [
|
|
369
|
+
{
|
|
370
|
+
type: 'text',
|
|
371
|
+
text: `Email successfully sent to ${args.to} and saved to Sent folder.`
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (request.params.name === 'create_draft') {
|
|
377
|
+
const args = request.params.arguments;
|
|
378
|
+
const service = await this.getService(args.accountId);
|
|
379
|
+
await service.createDraft(args.to, args.subject, args.body, args.isHtml, args.cc, args.bcc);
|
|
380
|
+
return {
|
|
381
|
+
content: [
|
|
382
|
+
{
|
|
383
|
+
type: 'text',
|
|
384
|
+
text: `Draft successfully created in Drafts folder.`
|
|
385
|
+
}
|
|
386
|
+
]
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
if (request.params.name === 'list_folders') {
|
|
390
|
+
const args = request.params.arguments;
|
|
391
|
+
const service = await this.getService(args.accountId);
|
|
392
|
+
const folders = await service.listFolders();
|
|
393
|
+
return {
|
|
394
|
+
content: [
|
|
395
|
+
{
|
|
396
|
+
type: 'text',
|
|
397
|
+
text: JSON.stringify(folders, null, 2)
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
if (request.params.name === 'move_email') {
|
|
403
|
+
const args = request.params.arguments;
|
|
404
|
+
const service = await this.getService(args.accountId);
|
|
405
|
+
await service.moveMessage(args.uid, args.sourceFolder, args.targetFolder);
|
|
406
|
+
return {
|
|
407
|
+
content: [
|
|
408
|
+
{
|
|
409
|
+
type: 'text',
|
|
410
|
+
text: `Email ${args.uid} moved from ${args.sourceFolder} to ${args.targetFolder}.`
|
|
411
|
+
}
|
|
412
|
+
]
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
if (request.params.name === 'modify_labels') {
|
|
416
|
+
const args = request.params.arguments;
|
|
417
|
+
const service = await this.getService(args.accountId);
|
|
418
|
+
await service.modifyLabels(args.uid, args.folder, args.addLabels || [], args.removeLabels || []);
|
|
419
|
+
return {
|
|
420
|
+
content: [
|
|
421
|
+
{
|
|
422
|
+
type: 'text',
|
|
423
|
+
text: `Labels updated for email ${args.uid} in ${args.folder}.`
|
|
424
|
+
}
|
|
425
|
+
]
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (request.params.name === 'get_thread') {
|
|
429
|
+
const args = request.params.arguments;
|
|
430
|
+
const service = await this.getService(args.accountId);
|
|
431
|
+
const messages = await service.getThread(args.threadId, args.folder);
|
|
432
|
+
return {
|
|
433
|
+
content: [
|
|
434
|
+
{
|
|
435
|
+
type: 'text',
|
|
436
|
+
text: JSON.stringify(messages, null, 2)
|
|
437
|
+
}
|
|
438
|
+
]
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
if (request.params.name === 'get_attachment') {
|
|
442
|
+
const args = request.params.arguments;
|
|
443
|
+
const service = await this.getService(args.accountId);
|
|
444
|
+
const { content, contentType } = await service.downloadAttachment(args.uid, args.filename, args.folder);
|
|
445
|
+
return {
|
|
446
|
+
content: [
|
|
447
|
+
{
|
|
448
|
+
type: 'text',
|
|
449
|
+
text: `Attachment "${args.filename}" downloaded successfully (${contentType}, ${content.length} bytes). Content (base64):\n\n${content.toString('base64')}`
|
|
450
|
+
}
|
|
451
|
+
]
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
if (request.params.name === 'extract_attachment_text') {
|
|
455
|
+
const args = request.params.arguments;
|
|
456
|
+
const service = await this.getService(args.accountId);
|
|
457
|
+
const text = await service.extractAttachmentText(args.uid, args.filename, args.folder);
|
|
458
|
+
return {
|
|
459
|
+
content: [
|
|
460
|
+
{
|
|
461
|
+
type: 'text',
|
|
462
|
+
text: text
|
|
463
|
+
}
|
|
464
|
+
]
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (request.params.name === 'register_oauth2_account') {
|
|
468
|
+
const args = request.params.arguments;
|
|
469
|
+
const { saveCredentials } = await import('./security/keychain.js');
|
|
470
|
+
const tokens = {
|
|
471
|
+
clientId: args.clientId,
|
|
472
|
+
clientSecret: args.clientSecret,
|
|
473
|
+
refreshToken: args.refreshToken,
|
|
474
|
+
tokenEndpoint: args.tokenEndpoint
|
|
475
|
+
};
|
|
476
|
+
await saveCredentials(args.accountId, JSON.stringify(tokens));
|
|
477
|
+
return {
|
|
478
|
+
content: [
|
|
479
|
+
{
|
|
480
|
+
type: 'text',
|
|
481
|
+
text: `OAuth2 credentials successfully saved for account ${args.accountId}.`
|
|
482
|
+
}
|
|
483
|
+
]
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
if (request.params.name === 'batch_operations') {
|
|
487
|
+
const args = request.params.arguments;
|
|
488
|
+
const service = await this.getService(args.accountId);
|
|
489
|
+
let operation;
|
|
490
|
+
if (args.action === 'move') {
|
|
491
|
+
if (!args.targetFolder) {
|
|
492
|
+
throw new Error('targetFolder is required for move action');
|
|
493
|
+
}
|
|
494
|
+
operation = { type: 'move', targetFolder: args.targetFolder };
|
|
495
|
+
}
|
|
496
|
+
else if (args.action === 'delete') {
|
|
497
|
+
operation = { type: 'delete' };
|
|
498
|
+
}
|
|
499
|
+
else if (args.action === 'label') {
|
|
500
|
+
operation = { type: 'label', addLabels: args.addLabels, removeLabels: args.removeLabels };
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
throw new Error(`Unknown action: ${args.action}`);
|
|
504
|
+
}
|
|
505
|
+
const result = await service.batchOperations(args.uids, args.folder, operation);
|
|
506
|
+
return {
|
|
507
|
+
content: [
|
|
508
|
+
{
|
|
509
|
+
type: 'text',
|
|
510
|
+
text: `Batch ${args.action} completed. ${result.processed} email(s) processed.`
|
|
511
|
+
}
|
|
512
|
+
]
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
throw new McpError(ErrorCode.MethodNotFound, `Tool not found: ${request.params.name}`);
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
return {
|
|
519
|
+
content: [
|
|
520
|
+
{
|
|
521
|
+
type: 'text',
|
|
522
|
+
text: `Error: ${error.message}`
|
|
523
|
+
}
|
|
524
|
+
],
|
|
525
|
+
isError: true
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
async run() {
|
|
531
|
+
const transport = new StdioServerTransport();
|
|
532
|
+
await this.server.connect(transport);
|
|
533
|
+
console.error('Mail MCP server running on stdio');
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
async function main() {
|
|
537
|
+
const args = process.argv.slice(2);
|
|
538
|
+
// Check for CLI subcommands before starting MCP server
|
|
539
|
+
const handled = await handleAccountsCommand(args);
|
|
540
|
+
if (handled) {
|
|
541
|
+
process.exit(0);
|
|
542
|
+
}
|
|
543
|
+
// No CLI subcommand — start MCP server
|
|
544
|
+
const { values } = parseArgs({
|
|
545
|
+
args,
|
|
546
|
+
options: { 'read-only': { type: 'boolean', default: false } },
|
|
547
|
+
strict: false,
|
|
548
|
+
});
|
|
549
|
+
const server = new MailMCPServer(values['read-only'] ?? false);
|
|
550
|
+
server.run().catch(console.error);
|
|
551
|
+
}
|
|
552
|
+
main().catch((err) => {
|
|
553
|
+
console.error(err);
|
|
554
|
+
process.exit(1);
|
|
555
|
+
});
|
|
556
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,SAAS,EACT,QAAQ,GACT,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC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AC;IACpD,CAAC;CACF;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnC,uDAAuD;IACvD,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,uCAAuC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;QAC3B,IAAI;QACJ,OAAO,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAC7D,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAI,aAAa,CAAE,MAAM,CAAC,WAAW,CAAyB,IAAI,KAAK,CAAC,CAAC;IACxF,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EmailAccount } from '../types/index.js';
|
|
2
|
+
import { ParsedMail } from 'mailparser';
|
|
3
|
+
export interface MessageMetadata {
|
|
4
|
+
id: string;
|
|
5
|
+
uid: number;
|
|
6
|
+
subject?: string;
|
|
7
|
+
from?: string;
|
|
8
|
+
date?: Date;
|
|
9
|
+
snippet?: string;
|
|
10
|
+
threadId?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class ImapClient {
|
|
13
|
+
private client;
|
|
14
|
+
private account;
|
|
15
|
+
constructor(account: EmailAccount);
|
|
16
|
+
connect(): Promise<void>;
|
|
17
|
+
disconnect(): Promise<void>;
|
|
18
|
+
listMessages(folder?: string, count?: number): Promise<MessageMetadata[]>;
|
|
19
|
+
searchMessages(criteria: any, folder?: string, count?: number): Promise<MessageMetadata[]>;
|
|
20
|
+
fetchMessageBody(uid: string, folder?: string): Promise<ParsedMail>;
|
|
21
|
+
fetchThreadMessages(threadId: string, folder?: string): Promise<MessageMetadata[]>;
|
|
22
|
+
appendMessage(folder: string, rawMessage: string | Buffer, flags?: string[]): Promise<void>;
|
|
23
|
+
listFolders(): Promise<string[]>;
|
|
24
|
+
moveMessage(uid: string, sourceFolder: string, targetFolder: string): Promise<void>;
|
|
25
|
+
modifyLabels(uid: string, folder: string, addLabels: string[], removeLabels: string[]): Promise<void>;
|
|
26
|
+
batchMoveMessages(uids: string[], sourceFolder: string, targetFolder: string): Promise<void>;
|
|
27
|
+
batchDeleteMessages(uids: string[], folder: string): Promise<void>;
|
|
28
|
+
batchModifyLabels(uids: string[], folder: string, addLabels: string[], removeLabels: string[]): Promise<void>;
|
|
29
|
+
}
|