@mambasms/mcp-server 0.4.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 (2) hide show
  1. package/index.js +280 -2
  2. package/package.json +1 -1
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.4.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) —— 动态区块(购物车/浏览商品列表),发送时自动填充该联系人的数据。
@@ -741,6 +741,284 @@ server.tool(
741
741
  }
742
742
  );
743
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
+
744
1022
  const transport = new StdioServerTransport();
745
1023
  await server.connect(transport);
746
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.4.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": {