sbuilder-mcp 0.111.5 → 0.112.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/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ All notable changes to this project are documented in this file.
6
6
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
7
7
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
+ ## [0.112.0] - 2026-11-20
10
+
11
+ ### Added
12
+ - `sb_store` adds `action: "tracking"`, which with no arguments lists every tracker (GA4, GTM, Meta/TikTok Pixel, ChatGPT Ads) with its ID, enabled state and problems, plus where visitors came from over the last 30 days.
13
+ - `sb_store` `action: "tracking"` accepts a pasted `text` snippet, recognises the provider, cleans the ID, and updates the existing tracker or creates a new one, defaulting to `dry_run`.
14
+ - `sb_store` `action: "tracking"` accepts `provider` and `enabled` to switch a single tracker on or off, and one provider's failure does not block the others.
15
+
9
16
  ## [0.111.5] - 2026-11-20
10
17
 
11
18
  ### Changed
package/CHANGELOG.vi.md CHANGED
@@ -6,6 +6,13 @@ Mọi thay đổi đáng chú ý của dự án được ghi lại trong file n
6
6
  Định dạng dựa trên [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
7
7
  và dự án tuân theo [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
+ ## [0.112.0] - 2026-11-20
10
+
11
+ ### Added
12
+ - `sb_store` có thêm `action: "tracking"`, khi không truyền tham số sẽ liệt kê mọi tracker (GA4, GTM, Meta/TikTok Pixel, ChatGPT Ads) cùng ID, trạng thái bật/tắt và vấn đề, kèm khách đến từ đâu trong 30 ngày qua.
13
+ - `sb_store` `action: "tracking"` nhận đoạn mã dán vào qua `text`, nhận diện nhà cung cấp, làm sạch ID, rồi cập nhật tracker đã có hoặc tạo mới, mặc định chạy `dry_run`.
14
+ - `sb_store` `action: "tracking"` nhận `provider` và `enabled` để bật/tắt một tracker, và lỗi của một nhà cung cấp không chặn các nhà cung cấp khác.
15
+
9
16
  ## [0.111.5] - 2026-11-20
10
17
 
11
18
  ### Changed
@@ -48,6 +48,7 @@ import { attachGlobal, buildChrome, detachGlobal, markSiteTemplate, promoteGloba
48
48
  import { bindMenu } from './menu.js';
49
49
  import { attachOverlay, ensureCartDrawer, relocalizeCartDrawer } from './overlay.js';
50
50
  import { installApp } from './app.js';
51
+ import { trackingFlow } from './tracking.js';
51
52
  import { BUILTIN_APP_KEYS } from '../catalog/appscaffolds.generated.js';
52
53
  import { ELEMENTS } from '../catalog/elements.generated.js';
53
54
  import { PAGE_TYPES } from '../catalog/storepages.generated.js';
@@ -570,7 +571,8 @@ export function registerStoreTools(server, ctx, session) {
570
571
  'leaves the page referencing it; action:"template_save" saves one as a section template ' +
571
572
  '(name; template_share sends one to the org\'s review). site_template offers the whole site as its org\'s ' +
572
573
  'template (org_id attaches first; site_template_remove withdraws). ' +
573
- 'Dry run returns the plan.',
574
+ 'action:"tracking": trackers + traffic sources; text installs a pasted snippet; provider+enabled ' +
575
+ 'switches one. Dry run returns the plan.',
574
576
  inputSchema: {
575
577
  action: z.enum([
576
578
  'checkout',
@@ -588,6 +590,7 @@ export function registerStoreTools(server, ctx, session) {
588
590
  'site_template',
589
591
  'site_template_remove',
590
592
  'template_share',
593
+ 'tracking',
591
594
  ]),
592
595
  site_id: z.string().optional(),
593
596
  language: z.enum(['vi', 'en']).optional().describe('Copy language, default vi'),
@@ -653,11 +656,20 @@ export function registerStoreTools(server, ctx, session) {
653
656
  .describe('action:"cart" — rewrite an EXISTING drawer\'s seed words that are in another language ' +
654
657
  'to the site locale\'s (edited text untouched), and turn a gallery line thumbnail into a ' +
655
658
  'single image; needs a page of the site open'),
659
+ text: z.string().optional(),
660
+ provider: z
661
+ .enum(['google_analytics', 'google_tag_manager', 'facebook_pixel', 'tiktok_pixel', 'openai_pixel'])
662
+ .optional(),
663
+ enabled: z.boolean().optional(),
656
664
  dry_run: z.boolean().optional(),
657
665
  },
658
666
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
659
- }, async ({ action, site_id: given, language, page_name, headline, template, name, footer, node_id, menu_id, kind, overlay_id, list_id, app_key, global_id, global_kind, template_id, description, categories, org_id, relocalize, settings, dry_run, }) => {
667
+ }, async ({ action, site_id: given, language, page_name, headline, template, name, footer, node_id, menu_id, kind, overlay_id, list_id, app_key, global_id, global_kind, template_id, description, categories, org_id, relocalize, settings, text: trackingText, provider, enabled, dry_run, }) => {
660
668
  const siteId = siteFor(ctx, given);
669
+ if (action === 'tracking') {
670
+ const dryRun = dry_run !== false;
671
+ return text(await trackingFlow(ctx, siteId, { text: trackingText, provider, enabled, dryRun }));
672
+ }
661
673
  if (action === 'global_attach' || action === 'global_detach') {
662
674
  // THE COMPOSED STAMP IS NEVER THE CALLER'S TO WRITE. A page references
663
675
  // a master with `specials.globalRef`; the server composes it in on read
@@ -0,0 +1,162 @@
1
+ /**
2
+ * `sb_store action:"tracking"` — A STORE'S MEASUREMENT, IN ONE CALL.
3
+ *
4
+ * Without it an agent had to find four routes (integrations list, detect,
5
+ * POST/PUT, channels) and know that a pasted snippet must be reduced to an id,
6
+ * that one row exists per provider, and that a stored row may carry a `problem`.
7
+ * web_builder answers all of that server-side; this only sequences it:
8
+ *
9
+ * - no `text`, no `provider` → STATUS: every tracker (connected or not, its id,
10
+ * on/off, and `problem` when a stored id installs no tag) plus where visitors
11
+ * came from over the last 30 days (GET /forms/submissions/channels). Read-only.
12
+ * - `text` → INSTALL whatever the text sets up: the server's detect names each
13
+ * provider and cleans its id; an existing row is UPDATED (its other config
14
+ * kept, switched on), a new one CREATED. Dry run by default: the plan.
15
+ * - `provider` + `enabled` → switch one tracker on or off.
16
+ *
17
+ * A failure on one provider does not stop the others; each reports its own
18
+ * result, and the server's own sentence (e.g. invalid_tracking_id naming the
19
+ * expected shape) is passed through untouched.
20
+ */
21
+ import { request } from '../transport/http.js';
22
+ import { siteToken } from './credentialpick.js';
23
+ /** web_builder's providers and the one config field each reads (integrations/providers.go). */
24
+ export const TRACKING_FIELDS = {
25
+ google_analytics: 'measurementId',
26
+ google_tag_manager: 'containerId',
27
+ facebook_pixel: 'pixelId',
28
+ tiktok_pixel: 'pixelId',
29
+ openai_pixel: 'pixelId',
30
+ };
31
+ export async function trackingFlow(ctx, siteId, args) {
32
+ const site = encodeURIComponent(siteId);
33
+ const base = `/api/sites/${site}/integrations`;
34
+ const send = async (method, path, body) => (await request({
35
+ base: ctx.base,
36
+ method,
37
+ path,
38
+ token: siteToken(ctx),
39
+ body,
40
+ fetchImpl: ctx.fetchImpl,
41
+ }));
42
+ const current = async () => (await send('GET', base)).integrations ?? [];
43
+ const idOf = (i) => i.config?.[TRACKING_FIELDS[i.provider] ?? ''] ?? '';
44
+ if (args.provider !== undefined || args.enabled !== undefined) {
45
+ if (!args.provider || args.enabled === undefined) {
46
+ throw new Error('sbuilder: action:"tracking" switches a tracker with BOTH provider and enabled.');
47
+ }
48
+ if (!(args.provider in TRACKING_FIELDS)) {
49
+ throw new Error(`sbuilder: provider must be one of ${Object.keys(TRACKING_FIELDS).join(', ')}.`);
50
+ }
51
+ const row = (await current()).find((i) => i.provider === args.provider);
52
+ if (!row?.id) {
53
+ throw new Error(`sbuilder: ${args.provider} is not connected — pass its snippet or id as text to install it.`);
54
+ }
55
+ const body = {
56
+ provider: row.provider,
57
+ enabled: args.enabled,
58
+ config: row.config,
59
+ };
60
+ if (args.dryRun) {
61
+ return {
62
+ dryRun: true,
63
+ plan: [
64
+ {
65
+ method: 'PUT',
66
+ path: `${base}/${encodeURIComponent(row.id)}`,
67
+ body,
68
+ },
69
+ ],
70
+ };
71
+ }
72
+ const saved = await send('PUT', `${base}/${encodeURIComponent(row.id)}`, body);
73
+ return {
74
+ provider: row.provider,
75
+ id: idOf(saved.integration),
76
+ enabled: saved.integration.enabled,
77
+ };
78
+ }
79
+ if (args.text !== undefined) {
80
+ if (!args.text.trim())
81
+ throw new Error('sbuilder: text is empty — paste the vendor snippet or the id.');
82
+ const found = (await send('POST', `${base}/detect`, {
83
+ text: args.text,
84
+ })).integrations ?? [];
85
+ if (!found.length) {
86
+ return {
87
+ recognised: [],
88
+ note: 'No tracker recognised. A bare TikTok or ChatGPT Ads id says nothing about whose it is: ' +
89
+ "paste the vendor's whole snippet, or POST /integrations with the provider named.",
90
+ };
91
+ }
92
+ const rows = await current();
93
+ const plan = found.map((d) => {
94
+ const existing = rows.find((r) => r.provider === d.provider);
95
+ const body = {
96
+ provider: d.provider,
97
+ enabled: true,
98
+ config: { ...existing?.config, ...d.config },
99
+ };
100
+ return existing?.id
101
+ ? {
102
+ provider: d.provider,
103
+ id: idOf(d),
104
+ replaces: idOf(existing),
105
+ method: 'PUT',
106
+ path: `${base}/${encodeURIComponent(existing.id)}`,
107
+ body,
108
+ }
109
+ : {
110
+ provider: d.provider,
111
+ id: idOf(d),
112
+ method: 'POST',
113
+ path: base,
114
+ body,
115
+ };
116
+ });
117
+ if (args.dryRun)
118
+ return { dry_run: true, plan };
119
+ const results = [];
120
+ for (const p of plan) {
121
+ try {
122
+ await send(p.method, p.path, p.body);
123
+ results.push({ provider: p.provider, id: p.id, ok: true });
124
+ }
125
+ catch (e) {
126
+ results.push({
127
+ provider: p.provider,
128
+ id: p.id,
129
+ ok: false,
130
+ error: e.message,
131
+ });
132
+ }
133
+ }
134
+ return {
135
+ results,
136
+ note: 'Tags are served at request time: live on the storefront now, no republish.',
137
+ };
138
+ }
139
+ const rows = await current();
140
+ let channels = null;
141
+ try {
142
+ channels =
143
+ (await send('GET', `/api/sites/${site}/forms/submissions/channels`)).channels ?? [];
144
+ }
145
+ catch (e) {
146
+ channels = { unavailable: e.message };
147
+ }
148
+ return {
149
+ trackers: Object.keys(TRACKING_FIELDS).map((provider) => {
150
+ const r = rows.find((x) => x.provider === provider);
151
+ if (!r)
152
+ return { provider, connected: false };
153
+ return {
154
+ provider,
155
+ id: idOf(r),
156
+ enabled: r.enabled,
157
+ ...(r.problem ? { problem: r.problem } : {}),
158
+ };
159
+ }),
160
+ channelsLast30Days: channels,
161
+ };
162
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbuilder-mcp",
3
- "version": "0.111.5",
3
+ "version": "0.112.0",
4
4
  "description": "MCP server that designs and operates a Store Builder site — pages, data, theme and publish — through the platform's own API and live-edit protocol.",
5
5
  "mcpName": "io.github.vuluu2k/sbuilder-mcp",
6
6
  "type": "module",