@mambasms/mcp-server 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 +65 -2
- package/index.js +138 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mambasms/mcp-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MambaSMS 邮件模板 MCP server(stdio)。让 AI 工具(Codex / Claude Desktop / Cursor)直接创建和管理 MambaSMS 邮件模板。
|
|
4
|
+
|
|
5
|
+
## 能力
|
|
6
|
+
|
|
7
|
+
| Tool | 说明 |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `template_list` | 列出店铺全部邮件模板(id+标题) |
|
|
10
|
+
| `template_get` | 模板详情(返回变量已替换成示例数据的渲染预览) |
|
|
11
|
+
| `template_create` | 传纯 HTML 创建模板,自动出现在后台「我的模板」,可被营销活动/自动化流程引用,可在后台可视化微调 |
|
|
12
|
+
| `template_update` | 更新模板(id 必填,title/html/summary 至少传一个;html 不传保留原内容) |
|
|
13
|
+
|
|
14
|
+
创建时后端自动做两类校验(非阻断,以 `warnings` 返回给 AI 自纠):
|
|
15
|
+
- 缺少退订占位符 `{Unsubscribe}`
|
|
16
|
+
- `{{ }}` 花括号混用(引擎只支持单花括号,混用会导致发送失败)
|
|
17
|
+
|
|
18
|
+
## 配置
|
|
19
|
+
|
|
20
|
+
环境变量:
|
|
21
|
+
|
|
22
|
+
| 变量 | 说明 | 默认 |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `MAMBA_ACCESS_TOKEN` | 店铺 API 密钥(**必填**,后台「店铺设置 → API 密钥」获取) | — |
|
|
25
|
+
| `MAMBA_API_BASE` | API 域名 | `https://api.mambasms.com`(测试环境 `https://olapapi.mambasend.com`) |
|
|
26
|
+
|
|
27
|
+
### Codex
|
|
28
|
+
|
|
29
|
+
`~/.codex/config.toml`(字段名以你的 Codex 版本文档为准):
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
[mcp_servers.mambasms]
|
|
33
|
+
command = "npx"
|
|
34
|
+
args = ["-y", "@mambasms/mcp-server"]
|
|
35
|
+
env = { "MAMBA_API_BASE" = "https://api.mambasms.com", "MAMBA_ACCESS_TOKEN" = "shop_xxx" }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Claude Desktop / Cursor
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"mambasms": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": ["-y", "@mambasms/mcp-server"],
|
|
46
|
+
"env": { "MAMBA_API_BASE": "https://api.mambasms.com", "MAMBA_ACCESS_TOKEN": "shop_xxx" }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 安全提示
|
|
53
|
+
|
|
54
|
+
`MAMBA_ACCESS_TOKEN` 等同店铺全权密钥(可推送事件、修改数据)。请仅从官方渠道获取本包,不要使用第三方仿冒包;不要把密钥提交进代码仓库。
|
|
55
|
+
|
|
56
|
+
## 变量占位符速查
|
|
57
|
+
|
|
58
|
+
模板 HTML 内可用(也会随 MCP instructions 下发):
|
|
59
|
+
|
|
60
|
+
- 退订链接(必须):`{Unsubscribe}` —— 放在邮件页脚
|
|
61
|
+
- 联系人加密ID:`{ContactEncryption}` —— 拼接退订/个性化链接
|
|
62
|
+
- 订单变量(自动化):`${order.number}` `${order.total_price}` `${order.created_at}` `${order.address1}`
|
|
63
|
+
- 订单商品循环:`[#list order.products as p] ... ${p.title} ${p.quantity} ${p.price} ... [/#list]`
|
|
64
|
+
- 商品数量:`${order.products?size}`
|
|
65
|
+
- 空值兜底(强烈建议):`${order.address1?default('')}`
|
|
66
|
+
- 只用单花括号,禁止 `{{ }}` 混用
|
package/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MambaSMS MCP server (stdio)
|
|
4
|
+
*
|
|
5
|
+
* 环境变量:
|
|
6
|
+
* MAMBA_API_BASE API 域名(默认 https://api.mambasms.com;测试环境 https://olapapi.mambasend.com)
|
|
7
|
+
* MAMBA_ACCESS_TOKEN 店铺 API 密钥(后台「店铺设置 → API 密钥」获取,必填)
|
|
8
|
+
*
|
|
9
|
+
* Codex 配置示例(~/.codex/config.toml):
|
|
10
|
+
* [mcp_servers.mambasms]
|
|
11
|
+
* command = "npx"
|
|
12
|
+
* args = ["-y", "@mambasms/mcp-server"]
|
|
13
|
+
* env = { "MAMBA_API_BASE" = "https://api.mambasms.com", "MAMBA_ACCESS_TOKEN" = "shop_xxx" }
|
|
14
|
+
*/
|
|
15
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
16
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
|
|
19
|
+
const API_BASE = (process.env.MAMBA_API_BASE || "https://api.mambasms.com").replace(/\/+$/, "");
|
|
20
|
+
const TOKEN = process.env.MAMBA_ACCESS_TOKEN;
|
|
21
|
+
|
|
22
|
+
const PLACEHOLDER_GUIDE = `## 变量占位符速查(模板 HTML 内可用)
|
|
23
|
+
- 退订链接(必须): {Unsubscribe} —— 放在邮件页脚,缺失时 template_create 会返回 warning
|
|
24
|
+
- 联系人加密ID: {ContactEncryption} —— 拼接退订/个性化链接用
|
|
25
|
+
- 订单变量(自动化场景): \${order.number} \${order.total_price} \${order.created_at} \${order.address1}
|
|
26
|
+
- 订单商品循环: [#list order.products as p] ... \${p.title} \${p.quantity} \${p.price} ... [/#list]
|
|
27
|
+
- 商品数量: \${order.products?size}
|
|
28
|
+
- 空值兜底(强烈建议): \${order.address1?default('')} —— 取不到值时给默认,避免渲染失败
|
|
29
|
+
- 花括号规范: 只用单花括号,禁止 {{ }} 混用(引擎只认单花括号,混用会导致发送失败)`;
|
|
30
|
+
|
|
31
|
+
async function callApi(path, body) {
|
|
32
|
+
if (!TOKEN) {
|
|
33
|
+
throw new Error("MAMBA_ACCESS_TOKEN env var is not set");
|
|
34
|
+
}
|
|
35
|
+
const resp = await fetch(`${API_BASE}${path}`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"X-Mamba-Access-Token": TOKEN,
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(body ?? {}),
|
|
42
|
+
});
|
|
43
|
+
const text = await resp.text();
|
|
44
|
+
let json = null;
|
|
45
|
+
try {
|
|
46
|
+
json = JSON.parse(text);
|
|
47
|
+
} catch {
|
|
48
|
+
json = null;
|
|
49
|
+
}
|
|
50
|
+
if (!resp.ok || (json && json.success === false)) {
|
|
51
|
+
const msg = json ? (json.message || JSON.stringify(json)) : text.slice(0, 300);
|
|
52
|
+
throw new Error(`API ${resp.status} ${path}: ${msg}`);
|
|
53
|
+
}
|
|
54
|
+
return json ? (json.data !== undefined ? json.data : json) : text;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const server = new McpServer(
|
|
58
|
+
{ name: "mambasms-mcp-server", version: "0.1.0" },
|
|
59
|
+
{
|
|
60
|
+
instructions: `MambaSMS 邮件模板管理(店铺级,鉴权用 MAMBA_ACCESS_TOKEN)。
|
|
61
|
+
工作流: template_create 传纯 HTML 创建模板(后端自动包装成后台编辑器结构) → 模板出现在后台「我的模板」列表 → 可被营销活动/自动化流程引用(后台编辑器里点"从我的模板选择"),也可在后台可视化微调。
|
|
62
|
+
${PLACEHOLDER_GUIDE}`,
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
server.tool(
|
|
67
|
+
"template_list",
|
|
68
|
+
"列出当前店铺的全部邮件模板(id+标题),用于查询已有模板/确认创建结果",
|
|
69
|
+
{
|
|
70
|
+
page_number: z.number().int().min(1).default(1).describe("页码,从1开始"),
|
|
71
|
+
page_size: z.number().int().min(1).max(500).default(50).describe("每页条数,最大500"),
|
|
72
|
+
},
|
|
73
|
+
async ({ page_number, page_size }) => {
|
|
74
|
+
const data = await callApi("/api/v1/template/list", {
|
|
75
|
+
page: 1,
|
|
76
|
+
pager: { pageNumber: page_number, pageSize: page_size },
|
|
77
|
+
});
|
|
78
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
server.tool(
|
|
83
|
+
"template_get",
|
|
84
|
+
"获取模板详情。注意:返回的是变量已替换成示例数据的渲染预览HTML(适合确认视觉效果),原始模板中的占位符会被替换,不要把预览当原模板再改回去",
|
|
85
|
+
{ id: z.string().min(1).describe("模板id(template_list 返回的 id)") },
|
|
86
|
+
async ({ id }) => {
|
|
87
|
+
const data = await callApi("/api/v1/template/details", [id]);
|
|
88
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
server.tool(
|
|
93
|
+
"template_create",
|
|
94
|
+
`创建邮件模板:传纯HTML(title+html),后端包装成平台编辑器结构,模板出现在后台「我的模板」,可被营销活动/自动化流程引用,也可在后台可视化微调。
|
|
95
|
+
html 要求:完整邮件HTML、内联样式(客户端兼容)、必须含 {Unsubscribe} 退订占位符。
|
|
96
|
+
${PLACEHOLDER_GUIDE}`,
|
|
97
|
+
{
|
|
98
|
+
title: z.string().min(1).max(100).describe("模板标题"),
|
|
99
|
+
html: z
|
|
100
|
+
.string()
|
|
101
|
+
.min(1)
|
|
102
|
+
.max(500000)
|
|
103
|
+
.describe("完整邮件HTML,内联样式,必须含 {Unsubscribe}"),
|
|
104
|
+
summary: z.string().optional().describe("模板备注/摘要,可选"),
|
|
105
|
+
},
|
|
106
|
+
async ({ title, html, summary }) => {
|
|
107
|
+
const body = { title, html };
|
|
108
|
+
if (summary !== undefined) {
|
|
109
|
+
body.summary = summary;
|
|
110
|
+
}
|
|
111
|
+
const data = await callApi("/api/v1/template/create", body);
|
|
112
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
server.tool(
|
|
117
|
+
"template_update",
|
|
118
|
+
`更新已有模板(id 必填;title/html/summary 至少传一个)。html 不传则保留原内容(可只改标题/摘要)。
|
|
119
|
+
${PLACEHOLDER_GUIDE}`,
|
|
120
|
+
{
|
|
121
|
+
id: z.string().min(1).describe("模板id"),
|
|
122
|
+
title: z.string().min(1).max(100).optional().describe("新标题,可选"),
|
|
123
|
+
html: z.string().min(1).max(500000).optional().describe("新HTML,可选;不传则保留原内容"),
|
|
124
|
+
summary: z.string().optional().describe("新摘要,可选"),
|
|
125
|
+
},
|
|
126
|
+
async ({ id, title, html, summary }) => {
|
|
127
|
+
const body = { id };
|
|
128
|
+
if (title !== undefined) body.title = title;
|
|
129
|
+
if (html !== undefined) body.html = html;
|
|
130
|
+
if (summary !== undefined) body.summary = summary;
|
|
131
|
+
const data = await callApi("/api/v1/template/create", body);
|
|
132
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const transport = new StdioServerTransport();
|
|
137
|
+
await server.connect(transport);
|
|
138
|
+
console.error(`mambasms-mcp-server ready, api=${API_BASE}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mambasms/mcp-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for MambaSMS email templates - create/manage templates from AI agents (Codex, Claude Desktop, Cursor)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"mambasms-mcp-server": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "node index.js"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
21
|
+
"zod": "^3.24.0"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"mcp",
|
|
25
|
+
"mambasms",
|
|
26
|
+
"email",
|
|
27
|
+
"template",
|
|
28
|
+
"model-context-protocol"
|
|
29
|
+
],
|
|
30
|
+
"license": "UNLICENSED"
|
|
31
|
+
}
|