@mambasms/mcp-server 0.3.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.
Files changed (3) hide show
  1. package/README.md +7 -1
  2. package/index.js +338 -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.4.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,342 @@ 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
+
408
744
  const transport = new StdioServerTransport();
409
745
  await server.connect(transport);
410
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.3.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": {