@mambasms/mcp-server 0.1.1 → 0.2.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.
Files changed (2) hide show
  1. package/index.js +70 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -37,6 +37,7 @@ async function callApi(path, body) {
37
37
  headers: {
38
38
  "Content-Type": "application/json",
39
39
  "X-Mamba-Access-Token": TOKEN,
40
+ "X-Mamba-Source": "mcp",
40
41
  },
41
42
  body: JSON.stringify(body ?? {}),
42
43
  });
@@ -91,23 +92,41 @@ server.tool(
91
92
 
92
93
  server.tool(
93
94
  "template_create",
94
- `创建邮件模板:传纯HTML(title+html),后端包装成平台编辑器结构,模板出现在后台「我的模板」,可被营销活动/自动化流程引用,也可在后台可视化微调。
95
- html 要求:完整邮件HTML、内联样式(客户端兼容)、必须含 {Unsubscribe} 退订占位符。
95
+ `创建邮件模板:两种方式二选一——
96
+ 1) html:传纯HTML(适合从零生成/迁移现有邮件);
97
+ 2) sections:语义化区块列表(推荐,支持购物车列表/浏览商品推荐等动态区块):
98
+ [{type:"html",html:"..."}, {type:"cart_list",buttonText:"Back to Cart",limit:3},
99
+ {type:"browse_list",buttonText:"TAKE ANOTHER LOOK",limit:2}, ...]
100
+ 动态区块在发送时自动填充该联系人的购物车/浏览商品数据。
101
+ html/sections 都要求页脚含 {Unsubscribe} 退订占位符。创建后出现在后台「我的模板」,可被营销活动/自动化流程引用,也可在后台可视化微调。
96
102
  ${PLACEHOLDER_GUIDE}`,
97
103
  {
98
104
  title: z.string().min(1).max(100).describe("模板标题"),
99
105
  html: z
100
106
  .string()
101
- .min(1)
102
107
  .max(500000)
103
- .describe("完整邮件HTML,内联样式,必须含 {Unsubscribe}"),
108
+ .optional()
109
+ .describe("完整邮件HTML(与 sections 二选一)"),
110
+ sections: z
111
+ .array(
112
+ z.object({
113
+ type: z.enum(["html", "cart_list", "browse_list"]).describe("区块类型"),
114
+ html: z.string().optional().describe("type=html 时的HTML内容"),
115
+ buttonText: z.string().optional().describe("动态区块按钮文案"),
116
+ buttonStyle: z.enum(["primaryButton", "secondaryButton"]).optional().describe("按钮样式"),
117
+ limit: z.number().int().min(1).max(10).optional().describe("动态区块展示商品数(1~10)"),
118
+ })
119
+ )
120
+ .max(20)
121
+ .optional()
122
+ .describe("语义化区块列表(与 html 二选一)"),
104
123
  summary: z.string().optional().describe("模板备注/摘要,可选"),
105
124
  },
106
- async ({ title, html, summary }) => {
107
- const body = { title, html };
108
- if (summary !== undefined) {
109
- body.summary = summary;
110
- }
125
+ async ({ title, html, sections, summary }) => {
126
+ const body = { title };
127
+ if (html !== undefined) body.html = html;
128
+ if (sections !== undefined) body.sections = sections;
129
+ if (summary !== undefined) body.summary = summary;
111
130
  const data = await callApi("/api/v1/template/create", body);
112
131
  return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
113
132
  }
@@ -115,24 +134,64 @@ ${PLACEHOLDER_GUIDE}`,
115
134
 
116
135
  server.tool(
117
136
  "template_update",
118
- `更新已有模板(id 必填;title/html/summary 至少传一个)。html 不传则保留原内容(可只改标题/摘要)。
137
+ `更新已有模板(id 必填;title/html/sections/summary 至少传一个)。html/sections 不传则保留原内容(可只改标题/摘要)。
119
138
  ${PLACEHOLDER_GUIDE}`,
120
139
  {
121
140
  id: z.string().min(1).describe("模板id"),
122
141
  title: z.string().min(1).max(100).optional().describe("新标题,可选"),
123
142
  html: z.string().min(1).max(500000).optional().describe("新HTML,可选;不传则保留原内容"),
143
+ sections: z
144
+ .array(
145
+ z.object({
146
+ type: z.enum(["html", "cart_list", "browse_list"]).describe("区块类型"),
147
+ html: z.string().optional().describe("type=html 时的HTML内容"),
148
+ buttonText: z.string().optional().describe("动态区块按钮文案"),
149
+ buttonStyle: z.enum(["primaryButton", "secondaryButton"]).optional().describe("按钮样式"),
150
+ limit: z.number().int().min(1).max(10).optional().describe("动态区块展示商品数(1~10)"),
151
+ })
152
+ )
153
+ .optional()
154
+ .describe("语义化区块列表(整体替换原内容)"),
124
155
  summary: z.string().optional().describe("新摘要,可选"),
125
156
  },
126
- async ({ id, title, html, summary }) => {
157
+ async ({ id, title, html, sections, summary }) => {
127
158
  const body = { id };
128
159
  if (title !== undefined) body.title = title;
129
160
  if (html !== undefined) body.html = html;
161
+ if (sections !== undefined) body.sections = sections;
130
162
  if (summary !== undefined) body.summary = summary;
131
163
  const data = await callApi("/api/v1/template/create", body);
132
164
  return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
133
165
  }
134
166
  );
135
167
 
168
+ server.tool(
169
+ "upload_image",
170
+ "上传图片到平台CDN,返回可直接用于模板HTML的图片URL。推荐用图片URL转存(商品图/图床图片);上传后把返回的 url 写进模板HTML的 <img src>。",
171
+ {
172
+ url: z.string().optional().describe("图片URL(http/https,jpg/jpeg/png/gif/webp,≤5MB)"),
173
+ },
174
+ async ({ url }) => {
175
+ if (url === undefined) {
176
+ throw new Error("url is required");
177
+ }
178
+ const data = await callApi("/api/v1/file/upload-from-url", { url });
179
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
180
+ }
181
+ );
182
+
183
+ server.tool(
184
+ "template_delete",
185
+ "删除模板。⚠️ 被营销活动/自动化流程引用中的模板无法删除(会返回引用数量)。删除前建议先和用户确认。",
186
+ {
187
+ id: z.string().min(1).describe("模板id"),
188
+ },
189
+ async ({ id }) => {
190
+ const data = await callApi("/api/v1/template/delete", { id });
191
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
192
+ }
193
+ );
194
+
136
195
  const transport = new StdioServerTransport();
137
196
  await server.connect(transport);
138
197
  console.error(`mambasms-mcp-server ready, api=${API_BASE}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mambasms/mcp-server",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "MCP server for MambaSMS email templates - create/manage templates from AI agents (Codex, Claude Desktop, Cursor)",
5
5
  "type": "module",
6
6
  "bin": {