apimend-mail-mcp 0.0.0-stage → 0.1.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 +28 -2
- package/dist/index.js +124 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apimend Mail MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local stdio server for transactional email and status lookups. This package is
|
|
4
|
+
prepared for release but has not yet been published; confirm the package name
|
|
5
|
+
and ownership before publishing.
|
|
6
|
+
|
|
7
|
+
Set `APIMEND_API_KEY` in your MCP client's environment configuration. Use a Customer Sandbox key (`am_test_…`) to test agent workflows safely without contacting real recipients. Optionally set `APIMEND_BASE_URL` to use a different API server. Keep keys out of prompts and tool arguments.
|
|
8
|
+
|
|
9
|
+
The `send_email` tool queues real email and requires a stable idempotency key.
|
|
10
|
+
The read-only `debug_email` tool returns evidence-based status guidance and
|
|
11
|
+
never resends a message.
|
|
12
|
+
Your application and MCP client must enforce recipient authorization and any
|
|
13
|
+
human approval policy. `get_email_status` returns a privacy-minimized status.
|
|
14
|
+
Do not expose this local stdio server as a hosted service without separate
|
|
15
|
+
authentication, isolation, and abuse controls.
|
|
16
|
+
|
|
17
|
+
Requires Node.js 20 or later. Example configuration after publication:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"apimend-mail": {
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["-y", "apimend-mail-mcp"],
|
|
25
|
+
"env": { "APIMEND_API_KEY": "<your-api-key>" }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
export function createApimendMcpServer(options) {
|
|
7
|
+
const baseUrl = (options.baseUrl ?? "https://app.apimend.com").replace(/\/$/, "");
|
|
8
|
+
const fetcher = options.fetcher ?? fetch;
|
|
9
|
+
const server = new McpServer({
|
|
10
|
+
name: "apimend-mail",
|
|
11
|
+
version: "0.1.0",
|
|
12
|
+
});
|
|
13
|
+
async function request(path, init) {
|
|
14
|
+
const response = await fetcher(`${baseUrl}${path}`, {
|
|
15
|
+
method: init?.method ?? "GET",
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
18
|
+
...(init?.body ? { "Content-Type": "application/json" } : {}),
|
|
19
|
+
},
|
|
20
|
+
body: init?.body ? JSON.stringify(init.body) : undefined,
|
|
21
|
+
});
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
let result;
|
|
24
|
+
try {
|
|
25
|
+
result = text ? JSON.parse(text) : {};
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new Error(`Apimend API returned an invalid response (HTTP ${response.status})`);
|
|
29
|
+
}
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const message = result?.error;
|
|
32
|
+
throw new Error(message || `Apimend API request failed (HTTP ${response.status})`);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
server.registerTool("send_email", {
|
|
37
|
+
title: "Send transactional email",
|
|
38
|
+
description: "Queue a transactional email through Apimend Mail. Use only for a user-requested or application-authorized message. The sender must belong to a verified domain. Generate a stable idempotency_key for retry safety. The application remains responsible for recipient permissions and approval policy.",
|
|
39
|
+
inputSchema: {
|
|
40
|
+
from: z.string().email().describe("Sender email on a domain verified in this Apimend workspace."),
|
|
41
|
+
to: z.union([z.string().email(), z.array(z.string().email()).min(1).max(50)]).describe("One or more authorized recipient email addresses."),
|
|
42
|
+
subject: z.string().min(1).max(998).optional().describe("Required unless a template is supplied."),
|
|
43
|
+
html: z.string().optional(),
|
|
44
|
+
text: z.string().optional(),
|
|
45
|
+
template: z.string().optional().describe("Existing Apimend template ID, if using a template."),
|
|
46
|
+
template_data: z.record(z.string(), z.unknown()).optional(),
|
|
47
|
+
idempotency_key: z.string().min(1).max(200).describe("Stable key for this logical email action; reuse it when retrying."),
|
|
48
|
+
},
|
|
49
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true },
|
|
50
|
+
}, async ({ from, to, subject, html, text, template, template_data, idempotency_key }) => {
|
|
51
|
+
try {
|
|
52
|
+
const result = await request("/v1/send", {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: {
|
|
55
|
+
from,
|
|
56
|
+
to,
|
|
57
|
+
subject,
|
|
58
|
+
...(html !== undefined ? { html } : {}),
|
|
59
|
+
...(text !== undefined ? { text } : {}),
|
|
60
|
+
...(template ? { template } : {}),
|
|
61
|
+
...(template_data ? { templateData: template_data } : {}),
|
|
62
|
+
idempotencyKey: idempotency_key,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return { isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : "Unable to queue email" }] };
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
server.registerTool("get_email_status", {
|
|
72
|
+
title: "Get email status",
|
|
73
|
+
description: "Look up the processing status of an email previously queued in the authenticated Apimend workspace. Sent means provider acceptance, not confirmed inbox delivery. An uncertain outcome must be checked before retrying.",
|
|
74
|
+
inputSchema: { email_id: z.string().min(1) },
|
|
75
|
+
annotations: { readOnlyHint: true },
|
|
76
|
+
}, async ({ email_id }) => {
|
|
77
|
+
try {
|
|
78
|
+
const result = await request(`/v1/emails/${encodeURIComponent(email_id)}`);
|
|
79
|
+
return {
|
|
80
|
+
content: [{
|
|
81
|
+
type: "text",
|
|
82
|
+
text: JSON.stringify({ id: result.id, status: result.status, createdAt: result.createdAt, ...(result.error ? { error: result.error } : {}) }),
|
|
83
|
+
}],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return { isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : "Unable to read email status" }] };
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
server.registerTool("debug_email", {
|
|
91
|
+
title: "Diagnose an email",
|
|
92
|
+
description: "Return Apimend's evidence-based email diagnosis for a message in the authenticated workspace. Read-only: never resends. It distinguishes provider acceptance from delivery evidence and warns before retrying uncertain sends.",
|
|
93
|
+
inputSchema: { email_id: z.string().min(1) },
|
|
94
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
95
|
+
}, async ({ email_id }) => {
|
|
96
|
+
try {
|
|
97
|
+
const result = await request(`/v1/emails/${encodeURIComponent(email_id)}/diagnostics`);
|
|
98
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return { isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : "Unable to diagnose email" }] };
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return server;
|
|
105
|
+
}
|
|
106
|
+
export async function main() {
|
|
107
|
+
const apiKey = process.env.APIMEND_API_KEY?.trim();
|
|
108
|
+
if (!apiKey) {
|
|
109
|
+
console.error("APIMEND_API_KEY is required.");
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const server = createApimendMcpServer({
|
|
114
|
+
apiKey,
|
|
115
|
+
baseUrl: process.env.APIMEND_BASE_URL,
|
|
116
|
+
});
|
|
117
|
+
await server.connect(new StdioServerTransport());
|
|
118
|
+
}
|
|
119
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
120
|
+
main().catch((error) => {
|
|
121
|
+
console.error("Apimend Mail MCP server failed:", error);
|
|
122
|
+
process.exitCode = 1;
|
|
123
|
+
});
|
|
124
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apimend-mail-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local stdio MCP server for Apimend Mail",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "apimend-mail-mcp": "./dist/index.js" },
|
|
7
|
+
"files": ["dist", "README.md"],
|
|
8
|
+
"engines": { "node": ">=20" },
|
|
9
|
+
"homepage": "https://www.apimend.com/docs#agents",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/CoderSufiyan/apimend.git",
|
|
13
|
+
"directory": "mail/mcp"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/CoderSufiyan/apimend/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": ["apimend", "email", "mcp", "agents", "transactional"],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"test": "npm run build && node smoke.mjs",
|
|
22
|
+
"prepack": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
26
|
+
"zod": "^4.6.7"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"typescript": "^5.6.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT"
|
|
33
|
+
}
|