-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
101 lines (90 loc) · 3.04 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import MailPace from "@mailpace/mailpace.js";
import minimist from "minimist";
const argv = minimist(process.argv.slice(2));
const token = argv.token || process.env.MAILPACE_API_TOKEN;
if (!token) {
console.error(
"No API key provided. Please set MAILPACE_API_TOKEN environment variable or use --token argument"
);
process.exit(1);
}
const client = new MailPace.DomainClient(token);
const server = new McpServer({
name: "transactional-email-sending-service",
version: "1.0.0",
});
// Define the email tool
server.tool(
"send-email",
{
from: z.string().email(),
to: z.string(),
subject: z.string().optional(),
htmlbody: z.string().optional(),
textbody: z.string().optional(),
cc: z.string().optional(),
bcc: z.string().optional(),
replyto: z.string().optional(),
inreplyto: z.string().optional(),
references: z.string().optional(),
list_unsubscribe: z.string().optional(),
attachments: z.array(z.object({
name: z.string(),
content: z.string(),
content_type: z.string(),
cid: z.string().optional()
})).optional(),
tags: z.union([z.string(), z.array(z.string())]).optional()
},
async (params, _extra) => {
try {
if (!params.textbody && !params.htmlbody) {
return {
content: [{ type: "text", text: "Either text or html content must be provided" }],
isError: true
};
}
// Send the email
const result = await client.sendEmail(params);
return {
content: [
{
type: "text",
text: JSON.stringify({
success: true,
message: "Email sent successfully",
data: { messageId: result.id, status: result.status }
}, null, 2)
}
]
};
} catch (error: any) {
console.error(`Error sending email: ${error.message}`);
return {
content: [
{
type: "text",
text: JSON.stringify({
success: false,
message: "Failed to send email",
error: error.message
}, null, 2)
}
],
isError: true
};
}
}
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("Email sending service MCP Server running on stdio");
}
main().catch((error) => {
console.error("Fatal error in main():", error);
process.exit(1);
});