@teamnetwork-nz/smtp-mcp-server 1.2.0 → 1.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/README.md +9 -10
- package/dist/email.js +24 -5
- package/dist/index.js +43 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,11 +95,9 @@ Returns JSON with `filename`, `content_type`, and `content` (base64). Pass these
|
|
|
95
95
|
|
|
96
96
|
**Recommended workflow for attachments:**
|
|
97
97
|
```
|
|
98
|
-
|
|
99
|
-
→ { filename: "report.zip", content_type: "application/zip", content: "..." }
|
|
100
|
-
|
|
101
|
-
2. send_email({ ..., attachments: [{ filename, content_type, content }] })
|
|
98
|
+
send_email({ ..., attachments: [{ path: "/absolute/path/to/report.zip" }] })
|
|
102
99
|
```
|
|
100
|
+
The server reads, encodes, and detects the MIME type automatically. Binary data never passes through the agent's context.
|
|
103
101
|
|
|
104
102
|
---
|
|
105
103
|
|
|
@@ -132,13 +130,14 @@ Returns `isError: true` if the connection test fails, with the SMTP error messag
|
|
|
132
130
|
| `bcc` | string \| string[] | no | BCC recipient(s) |
|
|
133
131
|
| `attachments` | Attachment[] | no | Files to attach |
|
|
134
132
|
|
|
135
|
-
**Attachment object:**
|
|
133
|
+
**Attachment object — supply `path` or `content`, not both:**
|
|
136
134
|
|
|
137
|
-
| Field | Type | Description |
|
|
138
|
-
|
|
139
|
-
| `
|
|
140
|
-
| `content` | string | Base64-encoded file data |
|
|
141
|
-
| `
|
|
135
|
+
| Field | Type | Required | Description |
|
|
136
|
+
|---|---|---|---|
|
|
137
|
+
| `path` | string | if no `content` | Absolute path to file — server reads and encodes it |
|
|
138
|
+
| `content` | string | if no `path` | Base64-encoded file data (no `data:` URI prefix) |
|
|
139
|
+
| `filename` | string | if using `content` | Name shown to recipient; defaults to basename of `path` |
|
|
140
|
+
| `content_type` | string | if using `content` | MIME type; auto-detected from `path` extension if omitted |
|
|
142
141
|
|
|
143
142
|
---
|
|
144
143
|
|
package/dist/email.js
CHANGED
|
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createTransport = createTransport;
|
|
7
7
|
exports.verifyTransport = verifyTransport;
|
|
8
8
|
exports.sendEmail = sendEmail;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
9
11
|
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
12
|
+
const mime_js_1 = require("./mime.js");
|
|
10
13
|
const DATA_URI_PREFIX = /^data:[^;,]*(;[^,]*)?,/;
|
|
11
14
|
const BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
12
15
|
const MIME_TYPE_PATTERN = /^[\w!#$&\-^.+]+\/[\w!#$&\-^.+]+$/;
|
|
@@ -48,6 +51,26 @@ function createTransport(smtpConfig) {
|
|
|
48
51
|
async function verifyTransport(transport) {
|
|
49
52
|
await transport.verify();
|
|
50
53
|
}
|
|
54
|
+
function resolveAttachment(a) {
|
|
55
|
+
if (a.path) {
|
|
56
|
+
if (!fs_1.default.existsSync(a.path)) {
|
|
57
|
+
throw new Error(`Attachment file not found: ${a.path}`);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
filename: a.filename ?? path_1.default.basename(a.path),
|
|
61
|
+
content: fs_1.default.readFileSync(a.path),
|
|
62
|
+
contentType: a.content_type ?? (0, mime_js_1.mimeFromExtension)(a.path),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const content = a.content;
|
|
66
|
+
const filename = a.filename;
|
|
67
|
+
const content_type = a.content_type;
|
|
68
|
+
return {
|
|
69
|
+
filename,
|
|
70
|
+
content: Buffer.from(normalizeAndValidateBase64(content, filename), "base64"),
|
|
71
|
+
contentType: validateContentType(content_type, filename),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
51
74
|
async function sendEmail(transport, from, options) {
|
|
52
75
|
const message = {
|
|
53
76
|
from: `"${from.name}" <${from.address}>`,
|
|
@@ -55,11 +78,7 @@ async function sendEmail(transport, from, options) {
|
|
|
55
78
|
subject: options.subject,
|
|
56
79
|
cc: options.cc,
|
|
57
80
|
bcc: options.bcc,
|
|
58
|
-
attachments: options.attachments?.map((a) => (
|
|
59
|
-
filename: a.filename,
|
|
60
|
-
content: Buffer.from(normalizeAndValidateBase64(a.content, a.filename), "base64"),
|
|
61
|
-
contentType: validateContentType(a.content_type, a.filename),
|
|
62
|
-
})),
|
|
81
|
+
attachments: options.attachments?.map((a) => resolveAttachment(a)),
|
|
63
82
|
};
|
|
64
83
|
if (options.body_type === "html") {
|
|
65
84
|
message.html = options.body;
|
package/dist/index.js
CHANGED
|
@@ -44,15 +44,23 @@ const mime_js_1 = require("./mime.js");
|
|
|
44
44
|
const transport = (0, email_js_1.createTransport)(config_js_1.config.smtp);
|
|
45
45
|
const server = new mcp_js_1.McpServer({
|
|
46
46
|
name: "smtp-mcp",
|
|
47
|
-
version: "1.
|
|
47
|
+
version: "1.3.0",
|
|
48
48
|
});
|
|
49
49
|
// ---------------------------------------------------------------------------
|
|
50
50
|
// Shared schemas
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
|
-
const attachmentSchema = zod_1.z
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const attachmentSchema = zod_1.z
|
|
53
|
+
.object({
|
|
54
|
+
path: zod_1.z.string().optional().describe("Absolute path to the file on disk — server reads and encodes it"),
|
|
55
|
+
filename: zod_1.z.string().optional().describe("Override the filename shown to the recipient"),
|
|
56
|
+
content: zod_1.z.string().optional().describe("Base64-encoded file content (use path instead where possible)"),
|
|
57
|
+
content_type: zod_1.z.string().optional().describe("MIME type — auto-detected from path extension if omitted"),
|
|
58
|
+
})
|
|
59
|
+
.refine((a) => a.path || a.content, {
|
|
60
|
+
message: "Each attachment must include either 'path' (preferred) or 'content' (base64)",
|
|
61
|
+
})
|
|
62
|
+
.refine((a) => !a.content || (a.filename && a.content_type), {
|
|
63
|
+
message: "Attachments using 'content' must also include 'filename' and 'content_type'",
|
|
56
64
|
});
|
|
57
65
|
const recipientSchema = zod_1.z
|
|
58
66
|
.union([zod_1.z.string().email(), zod_1.z.array(zod_1.z.string().email()).min(1)])
|
|
@@ -106,9 +114,10 @@ server.registerTool("health", {
|
|
|
106
114
|
// Tool: encode_file
|
|
107
115
|
// ---------------------------------------------------------------------------
|
|
108
116
|
server.registerTool("encode_file", {
|
|
109
|
-
description: "Read a file from disk and return it base64-encoded
|
|
110
|
-
"
|
|
111
|
-
"
|
|
117
|
+
description: "Read a file from disk and return it base64-encoded. " +
|
|
118
|
+
"NOTE: prefer supplying 'path' directly in the send_email attachments array — " +
|
|
119
|
+
"the server will encode the file itself without passing binary data through the agent. " +
|
|
120
|
+
"Use encode_file only when you need to inspect or transform the content before sending.",
|
|
112
121
|
inputSchema: {
|
|
113
122
|
path: zod_1.z.string().min(1).describe("Absolute or relative path to the file"),
|
|
114
123
|
content_type: zod_1.z
|
|
@@ -271,10 +280,10 @@ encode_file
|
|
|
271
280
|
Optional
|
|
272
281
|
content_type string MIME type override. Auto-detected from extension if omitted.
|
|
273
282
|
|
|
274
|
-
Reads the file
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
Use
|
|
283
|
+
Reads the file and returns { filename, content_type, content } as JSON.
|
|
284
|
+
NOTE: for files on disk, prefer passing path directly in send_email attachments
|
|
285
|
+
instead — the server encodes the file itself without routing binary data through
|
|
286
|
+
the agent. Use encode_file only when you need to inspect the content first.
|
|
278
287
|
|
|
279
288
|
send_email
|
|
280
289
|
Required
|
|
@@ -288,24 +297,32 @@ send_email
|
|
|
288
297
|
bcc string | string[] Blind carbon copy recipients.
|
|
289
298
|
attachments Attachment[] Files to attach (see schema below).
|
|
290
299
|
|
|
291
|
-
Attachment schema
|
|
292
|
-
filename string Name shown to the recipient (e.g. "report.pdf").
|
|
293
|
-
content string File data encoded as base64. Use encode_file to produce this.
|
|
294
|
-
content_type string MIME type (e.g. "application/pdf", "image/png").
|
|
300
|
+
Attachment schema — provide EITHER path OR content for each attachment:
|
|
295
301
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
302
|
+
Path-based (preferred for files on disk):
|
|
303
|
+
path string Absolute path to the file. Server reads and encodes it.
|
|
304
|
+
filename string Optional. Defaults to the filename from the path.
|
|
305
|
+
content_type string Optional. Auto-detected from the file extension.
|
|
299
306
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
307
|
+
Content-based (for programmatically generated data):
|
|
308
|
+
content string Raw base64-encoded data. No data: URI prefix.
|
|
309
|
+
filename string Required when using content.
|
|
310
|
+
content_type string Required when using content.
|
|
303
311
|
|
|
304
|
-
|
|
305
|
-
|
|
312
|
+
ATTACHMENTS — RECOMMENDED APPROACH
|
|
313
|
+
-------------------------------------
|
|
314
|
+
Pass the file path directly in the attachments array and let the server handle
|
|
315
|
+
encoding. Binary data never passes through the agent's context:
|
|
306
316
|
|
|
307
|
-
|
|
308
|
-
|
|
317
|
+
send_email({
|
|
318
|
+
...,
|
|
319
|
+
attachments: [{ path: "/absolute/path/to/file.zip" }]
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
Only use content-based attachments when the data is generated at runtime
|
|
323
|
+
(e.g. a report built in memory) rather than read from an existing file.
|
|
324
|
+
If you do supply raw base64 content, ensure it has no "data:<type>;base64,"
|
|
325
|
+
prefix — provide the raw base64 string only.
|
|
309
326
|
|
|
310
327
|
TIPS
|
|
311
328
|
----
|