@mambasms/mcp-server 0.2.0 → 0.4.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 CHANGED
@@ -9,7 +9,13 @@ MambaSMS 邮件模板 MCP server(stdio)。让 AI 工具(Codex / Claude Desktop /
9
9
  | `template_list` | 列出店铺全部邮件模板(id+标题) |
10
10
  | `template_get` | 模板详情(返回变量已替换成示例数据的渲染预览) |
11
11
  | `template_create` | 传纯 HTML 创建模板,自动出现在后台「我的模板」,可被营销活动/自动化流程引用,可在后台可视化微调 |
12
- | `template_update` | 更新模板(id 必填,title/html/summary 至少传一个;html 不传保留原内容) |
12
+ | `template_update` | 更新模板(id 必填,title/html/sections/summary 至少传一个) |
13
+ | `template_create_from_design` | **首选**:结构化 emailDesign 生成(先 catalog_query 查规范) |
14
+ | `template_list_system` / `template_get_system` / `template_system_categories` | 系统模板库参考 |
15
+ | `catalog_query` / `block_library_query` | 规范目录 / 预置区块库 |
16
+ | `template_preview` / `template_send_test` | 渲染预览+免登链接 / 发测试邮件 |
17
+ | `template_export` / `template_import` | .mambatpl 导出 / 从 URL 导入(.mambatpl 或 zipHtml) |
18
+ | `template_snippets` | 页头/页脚 HTML 片段(含社交图标) |
13
19
 
14
20
  创建时后端自动做两类校验(非阻断,以 `warnings` 返回给 AI 自纠):
15
21
  - 缺少退订占位符 `{Unsubscribe}`
package/index.js CHANGED
@@ -56,10 +56,17 @@ async function callApi(path, body) {
56
56
  }
57
57
 
58
58
  const server = new McpServer(
59
- { name: "mambasms-mcp-server", version: "0.1.0" },
59
+ { name: "mambasms-mcp-server", version: "0.4.0" },
60
60
  {
61
61
  instructions: `MambaSMS 邮件模板管理(店铺级,鉴权用 MAMBA_ACCESS_TOKEN)。
62
- 工作流: template_create 传纯 HTML 创建模板(后端自动包装成后台编辑器结构) → 模板出现在后台「我的模板」列表 → 可被营销活动/自动化流程引用(后台编辑器里点"从我的模板选择"),也可在后台可视化微调。
62
+ 四条创建路径,按场景选(另有一组只读洞察工具:活动/流程/分组/联系人/报表/余额):
63
+ A) template_create_from_design —— 首选。传结构化 emailDesign(JSON:style/theme/hero/intro/products/offer/cta/social),系统渲染引擎生成合规可编辑组件树。写之前先用 catalog_query(topic=emailDesign) 查规范;要版式骨架用 catalog_query(topic=layouts) 后传 layoutSkeleton;想套用已有模板传 templateId(template_list_system 的 id)。
64
+ B) template_create(html) —— 迁移现成 HTML / 精细控制时用。
65
+ C) template_create(sections) —— 动态区块(购物车/浏览商品列表),发送时自动填充该联系人的数据。
66
+ D) template_import —— 从外部迁移:mambatpl 平台模板文件,或 zipHtml(设计工具导出的 zip,含图片转存 CDN)。
67
+ 参考面:template_list_system / template_get_system(系统模板库结构与文案)、block_library_query(预置区块)、catalog_query(规范目录)、template_snippets(页头/页脚 HTML 片段,含社交图标)。
68
+ 效果确认:template_preview(返回 HTML + 免登永久预览链接)、template_send_test(发测试邮件,≤10 个收件人,店铺级 2 分钟限频)。
69
+ 页脚与社交链接:不要自己发明图标地址,用 template_snippets(type=footer-social) 的片段,图标走 https://link.mambasms.com/dynamicImage/{platform}/{size}/{shape}/{color};平台 key 大小写敏感(youTube/linkedIn/soundCloud)。退订必须 {Unsubscribe}。
63
70
  ${PLACEHOLDER_GUIDE}`,
64
71
  }
65
72
  );
@@ -192,6 +199,548 @@ server.tool(
192
199
  }
193
200
  );
194
201
 
202
+ server.tool(
203
+ "template_list_system",
204
+ "列出系统模板库(平台公共模板,campaigns/automation)。返回标题、摘要、分类、contentSummary(板块+核心文案)。用于让 AI 参考结构与风格,或在 template_create_from_design 里以 templateId 直接套用。",
205
+ {
206
+ template_type: z.enum(["campaigns", "automation"]).optional().describe("campaigns=营销活动模板,automation=自动化流程模板"),
207
+ category_id: z.string().optional().describe("分类id(先调 template_system_categories 获取)"),
208
+ keyword: z.string().optional().describe("标题模糊筛选"),
209
+ trigger_key: z
210
+ .string()
211
+ .optional()
212
+ .describe("自动化场景:join_cart/abandon=弃单, order_paid=订单确认, order_fulfilled=发货, subscribe/customer_created=订阅欢迎, viewed_product=浏览商品"),
213
+ limit: z.number().int().min(1).max(30).default(15).describe("返回条数,最大30"),
214
+ },
215
+ async ({ template_type, category_id, keyword, trigger_key, limit }) => {
216
+ const body = { limit };
217
+ if (template_type) body.templateType = template_type;
218
+ if (category_id) body.categoryId = category_id;
219
+ if (keyword) body.keyword = keyword;
220
+ if (trigger_key) body.triggerKey = trigger_key;
221
+ const data = await callApi("/api/v1/template/system/list", body);
222
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
223
+ }
224
+ );
225
+
226
+ server.tool(
227
+ "template_get_system",
228
+ "读系统模板详情:板块摘要 + textNodes(可定位的文案节点)+ 渲染 HTML。用于学习结构,或配合 template_create_from_design 的 templateId/textOverrides 精确改写文案。",
229
+ {
230
+ id: z.string().min(1).describe("系统模板id(template_list_system 返回)"),
231
+ },
232
+ async ({ id }) => {
233
+ const data = await callApi("/api/v1/template/system/get", { id });
234
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
235
+ }
236
+ );
237
+
238
+ server.tool(
239
+ "template_system_categories",
240
+ "列出系统模板分类(campaigns 或 automation),用于 template_list_system 的 category_id 筛选。",
241
+ {
242
+ template_type: z.enum(["campaigns", "automation"]).default("campaigns").describe("模板类型"),
243
+ },
244
+ async ({ template_type }) => {
245
+ const data = await callApi("/api/v1/template/system/categories", { templateType: template_type });
246
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
247
+ }
248
+ );
249
+
250
+ server.tool(
251
+ "catalog_query",
252
+ "查创建规范目录(唯一真源): emailDesign(内容结构全文)/styles(4风格+行业配色)/layouts(6种骨架)/components(倒计时等额外组件)/discount/variants(多版本)/templateOverlay(套模板步骤)/handwriteHtml。不传 topic 返回目录清单。写 emailDesign 前必查。",
253
+ {
254
+ topic: z
255
+ .enum(["emailDesign", "styles", "layouts", "components", "discount", "variants", "templateOverlay", "handwriteHtml"])
256
+ .optional()
257
+ .describe("规范主题,不传返回清单"),
258
+ },
259
+ async ({ topic }) => {
260
+ const data = await callApi("/api/v1/template/catalog", topic ? { topic } : {});
261
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
262
+ }
263
+ );
264
+
265
+ server.tool(
266
+ "block_library_query",
267
+ "查编辑器预置区块库:不传 category_id 返回分类清单;传了返回区块明细(blockId + textNodes)。区块可作为 template_create_from_design 的 blocks 参数插入。",
268
+ {
269
+ category_id: z.string().optional().describe("区块分类id(不传返回分类清单)"),
270
+ keyword: z.string().optional().describe("按标题筛选"),
271
+ limit: z.number().int().min(1).max(40).default(20).describe("条数,最大40"),
272
+ offset: z.number().int().min(0).default(0).describe("翻页偏移"),
273
+ },
274
+ async ({ category_id, keyword, limit, offset }) => {
275
+ const body = { limit, offset };
276
+ if (category_id) body.categoryId = category_id;
277
+ if (keyword) body.keyword = keyword;
278
+ const data = await callApi("/api/v1/template/block-library", body);
279
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
280
+ }
281
+ );
282
+
283
+ server.tool(
284
+ "template_create_from_design",
285
+ `用结构化 emailDesign 生成模板(首选路径)。字段规范先查 catalog_query(topic=emailDesign)。
286
+ emailDesign 示例:{"style":"bold","theme":{"primaryColor":"#0f3460","accentColor":"#00adb5"},"announcement":"BLACK FRIDAY · 48H","preheader":"Up to 40% off","hero":{"title":"BLACK FRIDAY SALE","subtitle":"UP TO 40% OFF"},"intro":"...","products":[{"name":"Earbuds Pro","price":"$59.00","originalPrice":"$99.00"}],"offer":{"headline":"40% OFF","code":"{DiscountCode}"},"cta":{"text":"SHOP NOW","link":"{SiteUrl}"},"social":["instagram","facebook"]}
287
+ 买家可见文案一律英文;商品位会尽量匹配店铺真实商品图。`,
288
+ {
289
+ title: z.string().min(1).max(100).describe("模板标题"),
290
+ email_design: z.string().min(1).describe("emailDesign JSON 字符串(数组可传1-3版,首版落库)"),
291
+ template_id: z.string().optional().describe("套用的系统模板 id(优先于 layout_skeleton)"),
292
+ layout_skeleton: z
293
+ .enum(["promo-hero", "promo-flash", "single-spotlight", "new-arrival", "newsletter", "win-back"])
294
+ .optional()
295
+ .describe("版式骨架(不套模板时用;与 text_overrides/component_overrides 互斥)"),
296
+ category_id: z.string().optional().describe("自动匹配模板时的行业分类"),
297
+ scene_keyword: z.string().optional().describe("自动匹配模板时的场景关键词(如 弃单/新品/圣诞)"),
298
+ text_overrides: z
299
+ .array(z.object({ node_id: z.string(), text: z.string() }))
300
+ .optional()
301
+ .describe("按节点改文案(套模板时用,template_get_system 的 textNodes 提供 node_id)"),
302
+ component_overrides: z
303
+ .array(z.object({ node_id: z.string(), settings: z.record(z.any()) }))
304
+ .optional()
305
+ .describe("按节点覆盖字段(链接/图片/颜色等)"),
306
+ components: z
307
+ .array(z.record(z.any()))
308
+ .max(4)
309
+ .optional()
310
+ .describe("额外组件(如 [{type:'countdown',endTime:'2026-12-01 23:59:59'}],规范查 catalog_query(topic=components))"),
311
+ blocks: z
312
+ .array(z.record(z.any()))
313
+ .max(4)
314
+ .optional()
315
+ .describe("预置区块([{blockId, textOverrides:[{nodeId,text}]}],来自 block_library_query)"),
316
+ summary: z.string().optional().describe("模板备注"),
317
+ },
318
+ async (a) => {
319
+ const body = { title: a.title, emailDesign: a.email_design };
320
+ for (const [k, v] of [
321
+ ["templateId", a.template_id],
322
+ ["layoutSkeleton", a.layout_skeleton],
323
+ ["categoryId", a.category_id],
324
+ ["sceneKeyword", a.scene_keyword],
325
+ ["textOverrides", a.text_overrides?.map((x) => ({ nodeId: x.node_id, text: x.text }))],
326
+ ["componentOverrides", a.component_overrides?.map((x) => ({ nodeId: x.node_id, settings: x.settings }))],
327
+ ["components", a.components],
328
+ ["blocks", a.blocks],
329
+ ["summary", a.summary],
330
+ ]) {
331
+ if (v !== undefined) body[k] = v;
332
+ }
333
+ const data = await callApi("/api/v1/template/create-from-design", body);
334
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
335
+ }
336
+ );
337
+
338
+ server.tool(
339
+ "template_preview",
340
+ "预览模板:返回渲染好的 HTML(可视化确认)和免登永久预览链接(可直接发给同事/客户在浏览器打开)。",
341
+ {
342
+ id: z.string().min(1).describe("模板id"),
343
+ },
344
+ async ({ id }) => {
345
+ const data = await callApi("/api/v1/template/preview", { id });
346
+ const text = `预览链接(免登):${API_BASE}${data.url}\n\n渲染HTML(${(data.html || "").length} 字符):\n${(data.html || "").slice(0, 4000)}${(data.html || "").length > 4000 ? "\n...(已截断,完整内容请打开预览链接)" : ""}`;
347
+ return { content: [{ type: "text", text }] };
348
+ }
349
+ );
350
+
351
+ server.tool(
352
+ "template_send_test",
353
+ "发送测试邮件(主题前缀 MambaSend Preview,1~10 个收件人,同店铺 2 分钟内只能发一次)。用于看真实收件箱效果。",
354
+ {
355
+ id: z.string().min(1).describe("模板id"),
356
+ emails: z.array(z.string()).min(1).max(10).describe("收件邮箱,最多10个"),
357
+ },
358
+ async ({ id, emails }) => {
359
+ const data = await callApi("/api/v1/template/send-test", { id, emails });
360
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
361
+ }
362
+ );
363
+
364
+ server.tool(
365
+ "template_export",
366
+ "导出模板为 .mambatpl 平台模板文件(加密),返回 CDN 下载地址。可用于备份或跨店铺迁移。",
367
+ {
368
+ id: z.string().min(1).describe("模板id"),
369
+ },
370
+ async ({ id }) => {
371
+ const data = await callApi("/api/v1/template/export", { id });
372
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
373
+ }
374
+ );
375
+
376
+ server.tool(
377
+ "template_import",
378
+ "从 URL 导入模板。source_type=mambatpl:平台导出的加密模板文件;source_type=zipHtml:外部设计工具导出的 zip(后端解包并把图片转存 CDN)。",
379
+ {
380
+ url: z.string().url().describe("文件下载地址(http/https)"),
381
+ source_type: z.enum(["mambatpl", "zipHtml"]).default("mambatpl").describe("文件类型"),
382
+ title: z.string().optional().describe("新模板标题(不传则用文件内的标题)"),
383
+ },
384
+ async ({ url, source_type, title }) => {
385
+ const body = { url, sourceType: source_type };
386
+ if (title !== undefined) body.title = title;
387
+ const data = await callApi("/api/v1/template/import", body);
388
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
389
+ }
390
+ );
391
+
392
+ server.tool(
393
+ "template_snippets",
394
+ "取页头/页脚 HTML 参考片段(可直接嵌进模板 HTML,已是邮件客户端兼容的内联样式表格)。页脚含 LOGO/链接列/联系方式/退订;footer-social 含社交图标(平台动态图服务)。",
395
+ {
396
+ type: z.enum(["header-basic", "footer-basic", "footer-social"]).describe("片段类型"),
397
+ },
398
+ async ({ type }) => {
399
+ const { readFile } = await import("node:fs/promises");
400
+ const { fileURLToPath } = await import("node:url");
401
+ const { dirname, join } = await import("node:path");
402
+ const here = dirname(fileURLToPath(import.meta.url));
403
+ const html = await readFile(join(here, "snippets", `${type}.html`), "utf8");
404
+ return { content: [{ type: "text", text: html }] };
405
+ }
406
+ );
407
+
408
+ // ==================== 2A:只读洞察(分页 + 180 天默认窗口) ====================
409
+
410
+ async function callAssistantTool(tool, args) {
411
+ return callApi("/api/v1/assistant/tool", { tool, arguments: args ?? {} });
412
+ }
413
+
414
+ const PAGE_PARAMS = {
415
+ page: z.number().int().min(1).default(1).describe("页码,从1开始"),
416
+ page_size: z.number().int().min(1).max(100).default(20).describe("每页条数,最大100"),
417
+ };
418
+
419
+ const WINDOW_PARAMS = {
420
+ start_date: z.string().optional().describe("开始日期 yyyy-MM-dd(UTC),默认最近180天"),
421
+ end_date: z.string().optional().describe("结束日期 yyyy-MM-dd(UTC),默认今天"),
422
+ };
423
+
424
+ server.tool(
425
+ "campaign_list",
426
+ "营销活动列表(分页):标题/类型/状态/发送数与打开点击退订投诉计数。默认最近180天,可传时间覆盖。",
427
+ {
428
+ ...PAGE_PARAMS,
429
+ start_time: z.string().optional().describe("开始时间 yyyy-MM-dd HH:mm:ss"),
430
+ end_time: z.string().optional().describe("结束时间 yyyy-MM-dd HH:mm:ss"),
431
+ },
432
+ async ({ page, page_size, start_time, end_time }) => {
433
+ const body = { page, pageSize: page_size };
434
+ if (start_time) body.startTime = start_time;
435
+ if (end_time) body.endTime = end_time;
436
+ const data = await callApi("/api/v1/campaign/list", body);
437
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
438
+ }
439
+ );
440
+
441
+ server.tool(
442
+ "campaign_report",
443
+ "单活动效果报告:发送/成功/打开/点击/退订/投诉与送达率、打开率、点击率(附口径说明)。不传 id 时可用 campaign_name。",
444
+ {
445
+ campaigns_id: z.string().optional().describe("活动id(优先)"),
446
+ campaign_name: z.string().optional().describe("活动标题(模糊匹配,取最新)"),
447
+ },
448
+ async ({ campaigns_id, campaign_name }) => {
449
+ const args = {};
450
+ if (campaigns_id) args.campaignsId = campaigns_id;
451
+ if (campaign_name) args.campaignName = campaign_name;
452
+ const data = await callAssistantTool("query_campaign_report", args);
453
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
454
+ }
455
+ );
456
+
457
+ server.tool(
458
+ "campaign_link_report",
459
+ "单活动链接级点击报告(分页,默认180天):每个链接的点击数/唯一用户数。",
460
+ {
461
+ campaigns_id: z.string().min(1).describe("活动id"),
462
+ ...PAGE_PARAMS,
463
+ ...WINDOW_PARAMS,
464
+ },
465
+ async ({ campaigns_id, page, page_size, start_date, end_date }) => {
466
+ const body = { campaignsId: campaigns_id, page, pageSize: page_size };
467
+ if (start_date) body.startDate = start_date;
468
+ if (end_date) body.endDate = end_date;
469
+ const data = await callApi("/api/v1/insight/campaign/link-report", body);
470
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
471
+ }
472
+ );
473
+
474
+ server.tool(
475
+ "campaign_abtest_result",
476
+ "活动 A/B 测试结果:各版本标题/主题/状态/发送状态/目标分组/赢家。",
477
+ {
478
+ campaigns_id: z.string().optional().describe("活动id(优先)"),
479
+ campaign_name: z.string().optional().describe("活动标题"),
480
+ },
481
+ async ({ campaigns_id, campaign_name }) => {
482
+ const args = {};
483
+ if (campaigns_id) args.campaignsId = campaigns_id;
484
+ if (campaign_name) args.campaignName = campaign_name;
485
+ const data = await callAssistantTool("query_abtest_result", args);
486
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
487
+ }
488
+ );
489
+
490
+ server.tool(
491
+ "campaign_content",
492
+ "读活动当前内容(主题/预览文本/发件人/受众设置/内容摘要/质量信号),用于审核或作为改写依据。",
493
+ {
494
+ campaigns_id: z.string().optional().describe("活动id(优先)"),
495
+ campaign_name: z.string().optional().describe("活动标题"),
496
+ include_full_content: z.boolean().default(false).describe("是否返回完整正文(默认只给摘要)"),
497
+ },
498
+ async ({ campaigns_id, campaign_name, include_full_content }) => {
499
+ const args = { includeFullContent: include_full_content };
500
+ if (campaigns_id) args.campaignsId = campaigns_id;
501
+ if (campaign_name) args.campaignName = campaign_name;
502
+ const data = await callAssistantTool("query_campaign_content", args);
503
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
504
+ }
505
+ );
506
+
507
+ server.tool(
508
+ "flow_list",
509
+ "自动化流程列表(分页):名称/状态(enabled/disabled/draft)/触发事件/增改时间。",
510
+ {
511
+ ...PAGE_PARAMS,
512
+ keyword: z.string().optional().describe("流程名模糊筛选"),
513
+ status: z.enum(["enabled", "disabled", "draft"]).optional().describe("按状态筛选"),
514
+ },
515
+ async ({ page, page_size, keyword, status }) => {
516
+ const body = { page, pageSize: page_size };
517
+ if (keyword) body.keyword = keyword;
518
+ if (status) body.status = status;
519
+ const data = await callApi("/api/v1/insight/flow/list", body);
520
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
521
+ }
522
+ );
523
+
524
+ server.tool(
525
+ "flow_report",
526
+ "单流程效果报告(默认180天):进入/退出/完成/挂起/发送/成功/失败/打开/点击/销售与完成率、漏斗。不传则汇总全店。",
527
+ {
528
+ flow_id: z.string().optional().describe("流程id(优先)"),
529
+ flow_name: z.string().optional().describe("流程名"),
530
+ },
531
+ async ({ flow_id, flow_name }) => {
532
+ const args = {};
533
+ if (flow_id) args.flowId = flow_id;
534
+ if (flow_name) args.flowName = flow_name;
535
+ const data = await callAssistantTool("query_flow_report", args);
536
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
537
+ }
538
+ );
539
+
540
+ server.tool(
541
+ "flow_send_failure",
542
+ "单流程发送失败明细(最近20条)+ 失败原因 Top5。",
543
+ {
544
+ flow_id: z.string().optional().describe("流程id(优先)"),
545
+ flow_name: z.string().optional().describe("流程名"),
546
+ },
547
+ async ({ flow_id, flow_name }) => {
548
+ const args = {};
549
+ if (flow_id) args.flowId = flow_id;
550
+ if (flow_name) args.flowName = flow_name;
551
+ const data = await callAssistantTool("query_flow_send_failure", args);
552
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
553
+ }
554
+ );
555
+
556
+ server.tool(
557
+ "flow_content",
558
+ "读流程结构与节点内容(触发器/延迟/条件/邮件或短信节点),用于审核或作为改写依据。",
559
+ {
560
+ flow_id: z.string().optional().describe("流程id(优先)"),
561
+ flow_name: z.string().optional().describe("流程名"),
562
+ },
563
+ async ({ flow_id, flow_name }) => {
564
+ const args = {};
565
+ if (flow_id) args.flowId = flow_id;
566
+ if (flow_name) args.flowName = flow_name;
567
+ const data = await callAssistantTool("query_flow_content", args);
568
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
569
+ }
570
+ );
571
+
572
+ server.tool(
573
+ "flow_triggers",
574
+ "自动化触发器定义目录:不传 trigger_key 返回全部触发器(含说明);传了返回其筛选项/分流项定义。",
575
+ {
576
+ trigger_key: z.string().optional().describe("触发器key,如 join_cart/order_paid/subscribe"),
577
+ },
578
+ async ({ trigger_key }) => {
579
+ const args = {};
580
+ if (trigger_key) args.triggerKey = trigger_key;
581
+ const data = await callAssistantTool("query_flow_trigger", args);
582
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
583
+ }
584
+ );
585
+
586
+ server.tool(
587
+ "group_list",
588
+ "用户分组列表(分页,不含平台自动分组):名称/人数/动态状态/来源。",
589
+ {
590
+ ...PAGE_PARAMS,
591
+ keyword: z.string().optional().describe("分组名模糊筛选"),
592
+ },
593
+ async ({ page, page_size, keyword }) => {
594
+ const body = { page, pageSize: page_size };
595
+ if (keyword) body.keyword = keyword;
596
+ const data = await callApi("/api/v1/insight/group/list", body);
597
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
598
+ }
599
+ );
600
+
601
+ server.tool(
602
+ "group_catalog",
603
+ "用户分组条件目录(唯一真源):不传 nested_path 返回可用数据域清单;传了返回该域的字段与条件规则。建分组前必查。",
604
+ {
605
+ nested_path: z.string().optional().describe("数据域,如 aggregation_time_order / audience_address"),
606
+ },
607
+ async ({ nested_path }) => {
608
+ const args = {};
609
+ if (nested_path) args.nestedPath = nested_path;
610
+ const data = await callAssistantTool("query_group_catalog", args);
611
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
612
+ }
613
+ );
614
+
615
+ server.tool(
616
+ "group_members",
617
+ "指定分组的成员列表(分页,自动区分手动/条件分组):邮箱/手机/姓名/国家/订阅状态。",
618
+ {
619
+ group_id: z.string().min(1).describe("分组id(group_list 返回)"),
620
+ ...PAGE_PARAMS,
621
+ },
622
+ async ({ group_id, page, page_size }) => {
623
+ const data = await callApi("/api/v1/insight/group/members", {
624
+ groupId: group_id,
625
+ page,
626
+ pageSize: page_size,
627
+ });
628
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
629
+ }
630
+ );
631
+
632
+ server.tool(
633
+ "contact_get",
634
+ "精确查单个联系人(email/phone/originId 三选一,不支持模糊搜):订阅状态、标签外的画像与订单汇总(已排除取消单)。",
635
+ {
636
+ email: z.string().optional().describe("完整邮箱(精确匹配)"),
637
+ phone: z.string().optional().describe("完整手机号(精确匹配)"),
638
+ origin_id: z.string().optional().describe("平台顾客id(精确匹配)"),
639
+ },
640
+ async ({ email, phone, origin_id }) => {
641
+ const body = {};
642
+ if (email) body.email = email;
643
+ if (phone) body.phone = phone;
644
+ if (origin_id) body.originId = origin_id;
645
+ const data = await callApi("/api/v1/insight/contact/get", body);
646
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
647
+ }
648
+ );
649
+
650
+ server.tool(
651
+ "contact_send_status",
652
+ "某联系人收到过的邮件/短信及其送达、打开、点击、退订状态(可限定活动或流程)。",
653
+ {
654
+ keyword: z.string().min(1).describe("完整邮箱或手机号"),
655
+ campaigns_id: z.string().optional().describe("限定活动id"),
656
+ flow_id: z.string().optional().describe("限定流程id"),
657
+ },
658
+ async ({ keyword, campaigns_id, flow_id }) => {
659
+ const args = { keyword };
660
+ if (campaigns_id) args.campaignsId = campaigns_id;
661
+ if (flow_id) args.flowId = flow_id;
662
+ const data = await callAssistantTool("query_contact_send_status", args);
663
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
664
+ }
665
+ );
666
+
667
+ server.tool(
668
+ "audience_growth",
669
+ "受众增长趋势(按天):新增联系人/邮件订阅/短信订阅。默认30天(上限90)。",
670
+ {
671
+ days: z.number().int().min(1).max(90).default(30).describe("回推天数,最大90"),
672
+ },
673
+ async ({ days }) => {
674
+ const data = await callAssistantTool("query_audience_growth", { days });
675
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
676
+ }
677
+ );
678
+
679
+ server.tool(
680
+ "form_performance",
681
+ "表单表现:不传 forms_id 返回表单清单(浏览/登记);传了返回该表单按国家/设备的明细。",
682
+ {
683
+ forms_id: z.string().optional().describe("表单id"),
684
+ days: z.number().int().min(1).max(180).default(30).describe("传 forms_id 时的统计天数"),
685
+ },
686
+ async ({ forms_id, days }) => {
687
+ const args = { days };
688
+ if (forms_id) args.formsId = forms_id;
689
+ const data = await callAssistantTool("query_form_performance", args);
690
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
691
+ }
692
+ );
693
+
694
+ server.tool(
695
+ "domain_health",
696
+ "发件域名健康度:各域的 DKIM/CNAME/SPF/DMARC/MX/追踪状态与需关注清单。",
697
+ {},
698
+ async () => {
699
+ const data = await callAssistantTool("query_sender_domain_health", {});
700
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
701
+ }
702
+ );
703
+
704
+ server.tool(
705
+ "store_overview",
706
+ "店铺经营概览(默认180天):订单数、已支付订单数、已支付收入、有归因订单数。已排除取消单。",
707
+ {
708
+ ...WINDOW_PARAMS,
709
+ },
710
+ async ({ start_date, end_date }) => {
711
+ const body = {};
712
+ if (start_date) body.startDate = start_date;
713
+ if (end_date) body.endDate = end_date;
714
+ const data = await callApi("/api/v1/insight/store/overview", body);
715
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
716
+ }
717
+ );
718
+
719
+ server.tool(
720
+ "order_stats",
721
+ "订单统计(默认180天):下单数、已支付单数、已支付金额、含币种提示。已排除取消单,金额跨币种不折算。",
722
+ {
723
+ ...WINDOW_PARAMS,
724
+ },
725
+ async ({ start_date, end_date }) => {
726
+ const body = {};
727
+ if (start_date) body.startDate = start_date;
728
+ if (end_date) body.endDate = end_date;
729
+ const data = await callApi("/api/v1/insight/order/stats", body);
730
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
731
+ }
732
+ );
733
+
734
+ server.tool(
735
+ "account_balance",
736
+ "店铺账户余额(美元,group 级;同 group 多店共享)。",
737
+ {},
738
+ async () => {
739
+ const data = await callApi("/api/v1/insight/balance", {});
740
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
741
+ }
742
+ );
743
+
195
744
  const transport = new StdioServerTransport();
196
745
  await server.connect(transport);
197
746
  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.2.0",
3
+ "version": "0.4.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": {
@@ -16,7 +16,8 @@
16
16
  },
17
17
  "files": [
18
18
  "index.js",
19
- "README.md"
19
+ "README.md",
20
+ "snippets"
20
21
  ],
21
22
  "engines": {
22
23
  "node": ">=18"
@@ -0,0 +1,34 @@
1
+ <table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background-color:#1a1a1a;">
2
+ <tbody>
3
+ <tr>
4
+ <td align="center" style="padding:32px 24px;">
5
+ <table width="600" border="0" cellpadding="0" cellspacing="0" role="presentation">
6
+ <tbody>
7
+ <tr>
8
+ <td width="34%" valign="top" style="padding-right:16px;">
9
+ <p style="margin:0 0 8px;font-family:Arial,sans-serif;font-size:18px;letter-spacing:4px;color:#ffffff;">LOGO</p>
10
+ <p style="margin:0 0 16px;font-family:Arial,sans-serif;font-size:11px;color:#9a9a9a;">Add your logo image</p>
11
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:13px;line-height:1.6;color:#d0d0d0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
12
+ </td>
13
+ <td width="33%" valign="top" style="padding-right:16px;">
14
+ <p style="margin:0 0 12px;font-family:Arial,sans-serif;font-size:15px;font-weight:700;color:#ffffff;">Links</p>
15
+ <p style="margin:0 0 8px;font-family:Arial,sans-serif;font-size:13px;"><a href="{SiteUrl}/collections/jewellery" style="color:#ffffff;text-decoration:none;">Jewellery</a></p>
16
+ <p style="margin:0 0 8px;font-family:Arial,sans-serif;font-size:13px;"><a href="{SiteUrl}/collections/watches" style="color:#ffffff;text-decoration:none;">Watches</a></p>
17
+ <p style="margin:0 0 8px;font-family:Arial,sans-serif;font-size:13px;"><a href="{SiteUrl}" style="color:#ffffff;text-decoration:none;">Webshop</a></p>
18
+ <p style="margin:0 0 8px;font-family:Arial,sans-serif;font-size:13px;"><a href="{SiteUrl}/collections/sale" style="color:#ffffff;text-decoration:none;">Sale</a></p>
19
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:13px;"><a href="{Unsubscribe}" style="color:#ffffff;text-decoration:none;">Unsubscribe</a></p>
20
+ </td>
21
+ <td width="33%" valign="top">
22
+ <p style="margin:0 0 12px;font-family:Arial,sans-serif;font-size:15px;font-weight:700;color:#ffffff;">Contact</p>
23
+ <p style="margin:0 0 8px;font-family:Arial,sans-serif;font-size:13px;"><a href="mailto:info@company.com" style="color:#ffffff;text-decoration:none;">Info@company.com</a></p>
24
+ <p style="margin:0 0 16px;font-family:Arial,sans-serif;font-size:13px;"><a href="{SiteUrl}/pages/help-center" style="color:#ffffff;text-decoration:none;">Help Center</a></p>
25
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:12px;line-height:1.6;color:#9a9a9a;">Copyright &copy; {SiteName}</p>
26
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:12px;line-height:1.6;color:#9a9a9a;">{SiteAddress}, {SiteCity}, {SiteCountry}</p>
27
+ </td>
28
+ </tr>
29
+ </tbody>
30
+ </table>
31
+ </td>
32
+ </tr>
33
+ </tbody>
34
+ </table>
@@ -0,0 +1,29 @@
1
+ <table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background-color:#1a1a1a;">
2
+ <tbody>
3
+ <tr>
4
+ <td align="center" style="padding:28px 24px;">
5
+ <table width="600" border="0" cellpadding="0" cellspacing="0" role="presentation">
6
+ <tbody>
7
+ <tr>
8
+ <td align="center" style="padding-bottom:16px;">
9
+ <a href="https://instagram.com/yourbrand" target="_blank" style="text-decoration:none;"><img src="https://link.mambasms.com/dynamicImage/instagram/28/100/default" width="28" height="28" alt="instagram" style="display:inline-block;margin:0 8px;border:0;"></a>
10
+ <a href="https://facebook.com/yourbrand" target="_blank" style="text-decoration:none;"><img src="https://link.mambasms.com/dynamicImage/facebook/28/100/default" width="28" height="28" alt="facebook" style="display:inline-block;margin:0 8px;border:0;"></a>
11
+ <a href="https://x.com/yourbrand" target="_blank" style="text-decoration:none;"><img src="https://link.mambasms.com/dynamicImage/twitter/28/100/default" width="28" height="28" alt="x" style="display:inline-block;margin:0 8px;border:0;"></a>
12
+ <a href="https://linkedin.com/company/yourbrand" target="_blank" style="text-decoration:none;"><img src="https://link.mambasms.com/dynamicImage/linkedIn/28/100/default" width="28" height="28" alt="linkedin" style="display:inline-block;margin:0 8px;border:0;"></a>
13
+ <a href="https://tiktok.com/@yourbrand" target="_blank" style="text-decoration:none;"><img src="https://link.mambasms.com/dynamicImage/tiktok/28/100/default" width="28" height="28" alt="tiktok" style="display:inline-block;margin:0 8px;border:0;"></a>
14
+ <a href="https://youtube.com/@yourbrand" target="_blank" style="text-decoration:none;"><img src="https://link.mambasms.com/dynamicImage/youTube/28/100/default" width="28" height="28" alt="youtube" style="display:inline-block;margin:0 8px;border:0;"></a>
15
+ </td>
16
+ </tr>
17
+ <tr>
18
+ <td align="center" style="padding-bottom:12px;">
19
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:12px;line-height:1.7;color:#9a9a9a;">Copyright &copy; {SiteName} &nbsp;|&nbsp; {SiteAddress}, {SiteCity}, {SiteCountry}</p>
20
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:12px;line-height:1.7;color:#9a9a9a;">This email was sent to {ContactEmail} because you've subscribed on our site or made a purchase.</p>
21
+ <p style="margin:0;font-family:Arial,sans-serif;font-size:12px;line-height:1.7;color:#9a9a9a;"><a href="{Unsubscribe}" style="color:#9a9a9a;text-decoration:underline;">Unsubscribe</a></p>
22
+ </td>
23
+ </tr>
24
+ </tbody>
25
+ </table>
26
+ </td>
27
+ </tr>
28
+ </tbody>
29
+ </table>
@@ -0,0 +1,22 @@
1
+ <table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background-color:#ffffff;">
2
+ <tbody>
3
+ <tr>
4
+ <td align="center" style="padding:24px 24px 8px;">
5
+ <table width="600" border="0" cellpadding="0" cellspacing="0" role="presentation">
6
+ <tbody>
7
+ <tr>
8
+ <td align="left" valign="middle">
9
+ <a href="{SiteUrl}" target="_blank" style="text-decoration:none;"><img src="https://via.placeholder.com/120x32?text=LOGO" width="120" height="32" alt="{SiteName}" style="display:block;border:0;"></a>
10
+ </td>
11
+ <td align="right" valign="middle" style="font-family:Arial,sans-serif;font-size:13px;">
12
+ <a href="{SiteUrl}/collections/new" style="color:#333333;text-decoration:none;margin-left:16px;">New In</a>
13
+ <a href="{SiteUrl}/collections/all" style="color:#333333;text-decoration:none;margin-left:16px;">Shop</a>
14
+ <a href="{SiteUrl}/pages/help-center" style="color:#333333;text-decoration:none;margin-left:16px;">Help</a>
15
+ </td>
16
+ </tr>
17
+ </tbody>
18
+ </table>
19
+ </td>
20
+ </tr>
21
+ </tbody>
22
+ </table>