@mambasms/mcp-server 0.3.0 → 0.5.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 (3) hide show
  1. package/README.md +7 -1
  2. package/index.js +616 -2
  3. package/package.json +1 -1
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,10 @@ async function callApi(path, body) {
56
56
  }
57
57
 
58
58
  const server = new McpServer(
59
- { name: "mambasms-mcp-server", version: "0.3.0" },
59
+ { name: "mambasms-mcp-server", version: "0.5.0" },
60
60
  {
61
61
  instructions: `MambaSMS 邮件模板管理(店铺级,鉴权用 MAMBA_ACCESS_TOKEN)。
62
- 四条创建路径,按场景选:
62
+ 四条创建路径,按场景选(另有一组只读洞察工具(活动/流程/分组/联系人/报表/余额)与一组写工具(活动/流程草稿、建分组;只建草稿不发送)):
63
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
64
  B) template_create(html) —— 迁移现成 HTML / 精细控制时用。
65
65
  C) template_create(sections) —— 动态区块(购物车/浏览商品列表),发送时自动填充该联系人的数据。
@@ -405,6 +405,620 @@ server.tool(
405
405
  }
406
406
  );
407
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
+
744
+ // ==================== 2B:写能力(只建草稿,不发送不启用) ====================
745
+
746
+ async function callWriteTool(tool, args) {
747
+ return callApi("/api/v1/assistant/tool", { tool, arguments: args ?? {} });
748
+ }
749
+
750
+ const DRAFT_NOTE = "⚠️本工具只创建/修改草稿,不会发送、不会启用、不扣费。发送需商家到后台活动/自动化页确认。";
751
+
752
+ server.tool(
753
+ "campaign_create_email",
754
+ `创建邮件营销活动草稿。${DRAFT_NOTE}
755
+ 正文必须用 email_design(结构化JSON):先用 catalog_query(topic=emailDesign) 查规范;想套用系统模板先 template_list_system → template_get_system,再把 template_id 一起传。`,
756
+ {
757
+ title: z.string().min(1).describe("活动名称"),
758
+ email_design: z.string().min(1).describe("邮件内容结构化 JSON 字符串(唯一正文来源;数组可传1-3版)"),
759
+ template_id: z.string().optional().describe("套用的系统模板 id(来自 template_list_system)"),
760
+ layout_skeleton: z
761
+ .enum(["promo-hero", "promo-flash", "single-spotlight", "new-arrival", "newsletter", "win-back"])
762
+ .optional()
763
+ .describe("版式骨架(不套模板时用)"),
764
+ subject_line: z.string().optional().describe("邮件主题(不传则按内容推导)"),
765
+ preheader: z.string().optional().describe("预览文本"),
766
+ send_name: z.string().optional().describe("发件人名称(不传用店铺名)"),
767
+ send_email: z.string().optional().describe("发件邮箱(不传用店铺默认已验证发件人)"),
768
+ communication_select: z.enum(["all", "tag"]).optional().describe("发送对象:all=全部订阅者,tag=指定分组"),
769
+ tag_id: z.string().optional().describe("分组id(communication_select=tag 时用)"),
770
+ non_send_tag_id: z.string().optional().describe("排除的分组id"),
771
+ text_overrides: z.array(z.object({ node_id: z.string(), text: z.string() })).optional().describe("按节点改文案(套模板时)"),
772
+ components: z.array(z.record(z.any())).max(4).optional().describe("额外组件(倒计时等,规范查 catalog_query(topic=components))"),
773
+ blocks: z.array(z.record(z.any())).max(4).optional().describe("预置区块(block_library_query 拿 blockId)"),
774
+ discount_type: z.enum(["percentage", "fixed"]).optional().describe("折扣类型"),
775
+ discount_value: z.string().optional().describe("折扣值"),
776
+ discount_code: z.string().optional().describe("折扣码"),
777
+ },
778
+ async (a) => {
779
+ const args = { title: a.title, emailDesign: a.email_design };
780
+ const map = {
781
+ templateId: a.template_id,
782
+ layoutSkeleton: a.layout_skeleton,
783
+ subjectLine: a.subject_line,
784
+ preheader: a.preheader,
785
+ sendName: a.send_name,
786
+ sendEmail: a.send_email,
787
+ communicationSelect: a.communication_select,
788
+ tagId: a.tag_id,
789
+ nonSendTagId: a.non_send_tag_id,
790
+ textOverrides: a.text_overrides?.map((x) => ({ nodeId: x.node_id, text: x.text })),
791
+ components: a.components,
792
+ blocks: a.blocks,
793
+ discountType: a.discount_type,
794
+ discountValue: a.discount_value,
795
+ discountCode: a.discount_code,
796
+ };
797
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
798
+ const data = await callWriteTool("create_campaign_email", args);
799
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
800
+ }
801
+ );
802
+
803
+ server.tool(
804
+ "campaign_create_sms",
805
+ `创建短信营销活动草稿。${DRAFT_NOTE} 文案建议英文≤160字符/中文≤70字。`,
806
+ {
807
+ title: z.string().min(1).describe("活动名称"),
808
+ message_text: z.string().min(1).describe("短信文案(可传 2-3 条候选的 JSON 数组字符串)"),
809
+ communication_select: z.enum(["all", "tag"]).optional().describe("发送对象"),
810
+ tag_id: z.string().optional().describe("分组id"),
811
+ non_send_tag_id: z.string().optional().describe("排除分组id"),
812
+ discount_type: z.enum(["percentage", "fixed"]).optional().describe("折扣类型"),
813
+ discount_value: z.string().optional().describe("折扣值"),
814
+ discount_code: z.string().optional().describe("折扣码"),
815
+ },
816
+ async (a) => {
817
+ const args = { title: a.title, messageText: a.message_text };
818
+ const map = {
819
+ communicationSelect: a.communication_select,
820
+ tagId: a.tag_id,
821
+ nonSendTagId: a.non_send_tag_id,
822
+ discountType: a.discount_type,
823
+ discountValue: a.discount_value,
824
+ discountCode: a.discount_code,
825
+ };
826
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
827
+ const data = await callWriteTool("create_campaign_sms", args);
828
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
829
+ }
830
+ );
831
+
832
+ server.tool(
833
+ "campaign_create_abtest",
834
+ `创建邮件 A/B 测试活动草稿。${DRAFT_NOTE}`,
835
+ {
836
+ title: z.string().min(1).describe("活动名称"),
837
+ subject_line: z.string().min(1).describe("A 版主题"),
838
+ ab_subject_line: z.string().min(1).describe("B 版主题"),
839
+ email_design: z.string().min(1).describe("邮件内容结构化 JSON"),
840
+ template_id: z.string().optional().describe("套用的系统模板 id"),
841
+ ab_test_ratio: z.number().int().min(1).max(99).optional().describe("测试人群比例(%)"),
842
+ calculation_type: z.enum(["clickRate", "openRate"]).optional().describe("赢家判定指标"),
843
+ number: z.number().int().min(1).optional().describe("测试时长数值"),
844
+ date_type: z.enum(["hour", "day"]).optional().describe("测试时长单位"),
845
+ communication_select: z.enum(["all", "tag"]).optional().describe("发送对象"),
846
+ tag_id: z.string().optional().describe("分组id"),
847
+ },
848
+ async (a) => {
849
+ const args = {
850
+ title: a.title,
851
+ subjectLine: a.subject_line,
852
+ abSubjectLine: a.ab_subject_line,
853
+ emailDesign: a.email_design,
854
+ };
855
+ const map = {
856
+ templateId: a.template_id,
857
+ abTestRatio: a.ab_test_ratio,
858
+ calculationType: a.calculation_type,
859
+ number: a.number,
860
+ dateType: a.date_type,
861
+ communicationSelect: a.communication_select,
862
+ tagId: a.tag_id,
863
+ };
864
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
865
+ const data = await callWriteTool("create_campaign_abtest", args);
866
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
867
+ }
868
+ );
869
+
870
+ server.tool(
871
+ "campaign_create_sms_abtest",
872
+ `创建短信 A/B 测试活动草稿。${DRAFT_NOTE}`,
873
+ {
874
+ title: z.string().min(1).describe("活动名称"),
875
+ sms_content_a: z.string().min(1).describe("A 版文案"),
876
+ sms_content_b: z.string().min(1).describe("B 版文案"),
877
+ test_ratio: z.number().int().min(1).max(99).optional().describe("测试人群比例(%)"),
878
+ winner_ratio: z.number().int().min(1).max(99).optional().describe("赢家放量比例(%)"),
879
+ calculation_type: z.enum(["clickRate", "openRate"]).optional().describe("赢家判定指标"),
880
+ number: z.number().int().min(1).optional().describe("测试时长数值"),
881
+ date_type: z.enum(["hour", "day"]).optional().describe("测试时长单位"),
882
+ communication_select: z.enum(["all", "tag"]).optional().describe("发送对象"),
883
+ tag_id: z.string().optional().describe("分组id"),
884
+ },
885
+ async (a) => {
886
+ const args = {
887
+ title: a.title,
888
+ smsContentA: a.sms_content_a,
889
+ smsContentB: a.sms_content_b,
890
+ };
891
+ const map = {
892
+ testRatio: a.test_ratio,
893
+ winnerRatio: a.winner_ratio,
894
+ calculationType: a.calculation_type,
895
+ number: a.number,
896
+ dateType: a.date_type,
897
+ communicationSelect: a.communication_select,
898
+ tagId: a.tag_id,
899
+ };
900
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
901
+ const data = await callWriteTool("create_campaign_smsabtest", args);
902
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
903
+ }
904
+ );
905
+
906
+ server.tool(
907
+ "campaign_update_content",
908
+ "修改活动草稿内容(主题/预览文本/正文)。⚠️仅 status=draft 的活动可改,已发送/已定时会被拒绝。",
909
+ {
910
+ campaigns_id: z.string().min(1).describe("活动id(campaign_list 返回)"),
911
+ subject_line: z.string().optional().describe("新主题"),
912
+ preheader: z.string().optional().describe("新预览文本"),
913
+ email_design: z.string().optional().describe("新的 emailDesign JSON(与 message_text 互斥)"),
914
+ layout_skeleton: z
915
+ .enum(["promo-hero", "promo-flash", "single-spotlight", "new-arrival", "newsletter", "win-back"])
916
+ .optional()
917
+ .describe("重建时使用的版式骨架"),
918
+ message_text: z.string().optional().describe("短信新文案"),
919
+ variant: z.enum(["A", "B"]).optional().describe("AB 测试时指定改哪一版"),
920
+ },
921
+ async (a) => {
922
+ const args = { campaignsId: a.campaigns_id };
923
+ const map = {
924
+ subjectLine: a.subject_line,
925
+ preheader: a.preheader,
926
+ emailDesign: a.email_design,
927
+ layoutSkeleton: a.layout_skeleton,
928
+ messageText: a.message_text,
929
+ variant: a.variant,
930
+ };
931
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
932
+ const data = await callWriteTool("update_campaign_content", args);
933
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
934
+ }
935
+ );
936
+
937
+ server.tool(
938
+ "flow_create",
939
+ `创建自动化流程草稿。${DRAFT_NOTE}
940
+ 先用 flow_triggers 查触发器定义(trigger_key 与筛选项),邮件节点正文用 email_design;可选多步骤 steps。`,
941
+ {
942
+ flow_name: z.string().min(1).describe("流程名称"),
943
+ trigger_key: z.string().min(1).describe("触发事件,如 join_cart/order_paid/subscribe/viewed_product(用 flow_triggers 查全部)"),
944
+ channel: z.enum(["Email", "SMS"]).default("Email").describe("主节点渠道"),
945
+ delay_minutes: z.number().int().min(0).optional().describe("首个动作延迟(数值)"),
946
+ delay_unit: z.enum(["minute", "hour", "day"]).optional().describe("延迟单位"),
947
+ send_name: z.string().optional().describe("发件人名称"),
948
+ send_email: z.string().optional().describe("发件邮箱"),
949
+ email_subject: z.string().optional().describe("邮件主题"),
950
+ email_design: z.string().optional().describe("邮件内容结构化 JSON(Email 渠道建议必传)"),
951
+ template_id: z.string().optional().describe("套用的自动化模板 id"),
952
+ email_content: z.string().optional().describe("手写 HTML(不推荐,优先 email_design)"),
953
+ sms_content: z.string().optional().describe("短信文案(SMS 渠道必传)"),
954
+ steps: z.array(z.record(z.any())).optional().describe("多步骤:[{delayMinutes,delayUnit,channel,emailSubject,emailDesign,smsContent}]"),
955
+ exit_conditions: z.array(z.string()).optional().describe("退出条件(如 order_placed/checkout_started)"),
956
+ trigger_filters: z.array(z.record(z.any())).optional().describe("触发过滤器(定义见 flow_triggers)"),
957
+ frequency_type: z.enum(["atTime", "inLast", "none"]).optional().describe("频率控制类型"),
958
+ frequency_value: z.number().int().optional().describe("频率数值"),
959
+ frequency_unit: z.enum(["minute", "hour", "day"]).optional().describe("频率单位"),
960
+ },
961
+ async (a) => {
962
+ const args = {
963
+ flowName: a.flow_name,
964
+ triggerKey: a.trigger_key,
965
+ channel: a.channel,
966
+ };
967
+ const map = {
968
+ delayMinutes: a.delay_minutes,
969
+ delayUnit: a.delay_unit,
970
+ sendName: a.send_name,
971
+ sendEmail: a.send_email,
972
+ emailSubject: a.email_subject,
973
+ emailDesign: a.email_design,
974
+ templateId: a.template_id,
975
+ emailContent: a.email_content,
976
+ smsContent: a.sms_content,
977
+ steps: a.steps,
978
+ exitConditions: a.exit_conditions,
979
+ triggerFilters: a.trigger_filters,
980
+ frequencyType: a.frequency_type,
981
+ frequencyValue: a.frequency_value,
982
+ frequencyUnit: a.frequency_unit,
983
+ };
984
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
985
+ const data = await callWriteTool("create_flow", args);
986
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
987
+ }
988
+ );
989
+
990
+ server.tool(
991
+ "flow_update_content",
992
+ "修改自动化流程草稿(名称/邮件主题/邮件正文)。⚠️仅 status=draft 的流程可改,已启用流程会被拒绝。",
993
+ {
994
+ flow_id: z.string().min(1).describe("流程id(flow_list 返回)"),
995
+ flow_name: z.string().optional().describe("新名称"),
996
+ email_subject: z.string().optional().describe("新邮件主题"),
997
+ email_content: z.string().optional().describe("新邮件正文 HTML"),
998
+ },
999
+ async (a) => {
1000
+ const args = { flowId: a.flow_id };
1001
+ const map = { flowName: a.flow_name, emailSubject: a.email_subject, emailContent: a.email_content };
1002
+ for (const [k, v] of Object.entries(map)) if (v !== undefined) args[k] = v;
1003
+ const data = await callWriteTool("update_flow_content", args);
1004
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
1005
+ }
1006
+ );
1007
+
1008
+ server.tool(
1009
+ "user_group_create",
1010
+ `创建用户分组。⚠️必传 query_content(条件树 JSON 字符串);不传会创建"全部客户"分组,与条件诉求不符。
1011
+ 条件写法先用 group_catalog 查数据域与字段,再按校验规则构造(操作符仅支持 gte/gt/lt/lte/term_query/terms_query/fuzzy_query/not_fuzzy_query/exists_field/exists_field_not);创建后人数由系统后台打包计算,不会立即有值。`,
1012
+ {
1013
+ name: z.string().min(1).describe("分组名称"),
1014
+ query_content: z.string().min(2).describe("条件树 JSON 字符串(见 group_catalog 规则)"),
1015
+ },
1016
+ async ({ name, query_content }) => {
1017
+ const data = await callWriteTool("create_user_group", { name, queryContent: query_content });
1018
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
1019
+ }
1020
+ );
1021
+
408
1022
  const transport = new StdioServerTransport();
409
1023
  await server.connect(transport);
410
1024
  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.3.0",
3
+ "version": "0.5.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": {