webcake-storefront-mcp 1.10.0 → 1.11.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/dist/api.js CHANGED
@@ -76,6 +76,12 @@ export class WebcakeCmsApi {
76
76
  createSite(params) {
77
77
  return this.request("POST", `/api/v1/dashboard/site/create`, { body: params, timeout: 60000 });
78
78
  }
79
+ /** Duplicate an existing site (its settings AND all pages/page-sources) into a NEW site
80
+ * owned by the current account. Used to spin up a site FROM a marketplace template
81
+ * (pass the template's source site id). Body: { site_id (source), name, slug? }. */
82
+ duplicateSite(params) {
83
+ return this.request("POST", `/api/v1/dashboard/site/duplicate`, { body: params, timeout: 90000 });
84
+ }
79
85
  getSiteInfo() {
80
86
  return this.request("GET", `/api/v1/site/${this.siteId}/`);
81
87
  }
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "v": "1.11.0",
4
+ "d": "24/06/2026",
5
+ "type": "Added",
6
+ "en": "New create_site_from_template tool clones a marketplace template (all its pages, page-sources, and settings) into a new account-owned site, switches…",
7
+ "vi": "Tool mới create_site_from_template nhân bản một template marketplace (toàn bộ trang, page-source và cài đặt) thành một site mới thuộc tài khoản hiện…"
8
+ },
2
9
  {
3
10
  "v": "1.10.0",
4
11
  "d": "24/06/2026",
@@ -33,12 +40,5 @@
33
40
  "type": "Added",
34
41
  "en": "get_element now returns an attributes field with a curated per-element reference covering the meaningful specials, config, events, and bindings keys…",
35
42
  "vi": "get_element nay trả về trường attributes chứa tài liệu tham chiếu theo từng loại element, bao gồm các key có ý nghĩa của specials, config, events và…"
36
- },
37
- {
38
- "v": "1.5.1",
39
- "d": "23/06/2026",
40
- "type": "Fixed",
41
- "en": "build_page now passes the finalized page source to create_page in the initial create call (required by the backend), then sets slug and is_homepage…",
42
- "vi": "build_page nay truyền source trang đã hoàn thiện vào lời gọi create_page ban đầu (bắt buộc bởi backend), sau đó đặt slug và is_homepage qua một lời…"
43
43
  }
44
44
  ]
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ import { setConfig } from "../db.js";
3
+ import { resolvePreviewUrl } from "../config.js";
2
4
  const TEMPLATE_THEMES_URL = "https://api.storecake.io/api/v1/templates/list_themes";
3
5
  const THEME_CATALOG_TTL_MS = 60 * 60 * 1000;
4
6
  const FETCH_TIMEOUT_MS = 15000;
@@ -50,6 +52,7 @@ async function getThemeCatalog(force = false) {
50
52
  preview_url: t.preview_url || "",
51
53
  thumbnail: t.thumbnail || "",
52
54
  categories: (t.categories || []).map((c) => c.name).filter(Boolean),
55
+ site_id: (t.site && t.site.id) || undefined,
53
56
  });
54
57
  }
55
58
  if (themes.length < limit)
@@ -143,6 +146,7 @@ export function registerSiteStyleTools(server, api, handle) {
143
146
  const desc = parseThemeDescription(te && te.description);
144
147
  return {
145
148
  theme_id: themeId,
149
+ template_site_id: info.site_id || null, // pass to create_site_from_template
146
150
  score: typeof score === "number" ? Number(score.toFixed(4)) : null,
147
151
  name: info.name || null,
148
152
  preview_url: info.preview_url || null,
@@ -152,6 +156,76 @@ export function registerSiteStyleTools(server, api, handle) {
152
156
  description_en: desc.description_en,
153
157
  };
154
158
  });
155
- return { query: q, count: matches.length, matches };
159
+ return {
160
+ query: q,
161
+ count: matches.length,
162
+ matches,
163
+ hint: "Pick one and call create_site_from_template with its theme_id (or template_site_id) to clone it into a new editable site.",
164
+ };
165
+ }));
166
+ server.tool("create_site_from_template", `Create a NEW site by CLONING a marketplace template (all its pages + settings), so the
167
+ customer starts from a finished design and then edits it. Resolve a template with
168
+ semantic_search_themes / list_template_themes first, then pass its theme_id (or
169
+ template_site_id). After cloning, switch to the new site and edit layout/content with
170
+ update_page_element(s), colours/typography with the site-style tools, and republish.`, {
171
+ name: z.string().describe("Name for the new site"),
172
+ theme_id: z.string().optional().describe("Marketplace theme id (from semantic_search_themes / list_template_themes)"),
173
+ template_site_id: z.string().optional().describe("The template's source site id (alternative to theme_id; semantic_search_themes returns it as template_site_id)"),
174
+ slug: z.string().optional().describe("URL-safe slug for the new site (auto-generated if omitted)"),
175
+ switch_to: z.boolean().default(true).describe("Switch the session to the new site after cloning (saved for next session)"),
176
+ }, ({ name, theme_id, template_site_id, slug, switch_to }) => handle(async () => {
177
+ // Resolve the template's source site id.
178
+ let sourceSiteId = template_site_id;
179
+ if (!sourceSiteId && theme_id) {
180
+ const catalog = await getThemeCatalog().catch(() => new Map());
181
+ sourceSiteId = catalog.get(theme_id)?.site_id;
182
+ }
183
+ if (!sourceSiteId) {
184
+ throw new Error("Could not resolve the template's source site. Pass template_site_id, or a theme_id that exists in the marketplace (list_template_themes / semantic_search_themes).");
185
+ }
186
+ // The duplicate endpoint returns success-only (no id), so snapshot the site list
187
+ // first, clone, then resolve the new site by diff.
188
+ const listIds = async () => {
189
+ const r = await api.listMySites({ page: 1, limit: 100 }).catch(() => null);
190
+ const arr = r?.data?.sites || r?.data || [];
191
+ return Array.isArray(arr) ? arr : [];
192
+ };
193
+ const before = await listIds();
194
+ const beforeIds = new Set(before.map((s) => s.id));
195
+ try {
196
+ await api.duplicateSite({ site_id: sourceSiteId, name, ...(slug ? { slug } : {}) });
197
+ }
198
+ catch (e) {
199
+ const msg = e instanceof Error ? e.message : String(e);
200
+ if (msg.includes("403"))
201
+ throw new Error("Cannot create site: account site quota reached (free plan allows up to 4 sites).");
202
+ throw new Error(`Cloning the template failed: ${msg}`);
203
+ }
204
+ const after = await listIds();
205
+ const fresh = after.filter((s) => !beforeIds.has(s.id));
206
+ const newSite = fresh.find((s) => s.name === name) || fresh[0];
207
+ const newId = newSite?.id;
208
+ if (!newId)
209
+ throw new Error("Template was cloned but the new site could not be located in your site list — check list_my_sites.");
210
+ let switched = false;
211
+ let previewUrl = null;
212
+ const previousSiteId = api.siteId;
213
+ if (switch_to) {
214
+ api.switchSite(newId);
215
+ setConfig("site_id", newId);
216
+ setConfig("site_name", newSite?.name || name);
217
+ switched = true;
218
+ previewUrl = await resolvePreviewUrl(api).catch(() => null);
219
+ }
220
+ return {
221
+ success: true,
222
+ site_id: newId,
223
+ name: newSite?.name || name,
224
+ from_template: { theme_id: theme_id || null, source_site_id: sourceSiteId },
225
+ switched,
226
+ ...(switched ? { current_site_id: api.siteId, previous_site_id: previousSiteId } : {}),
227
+ preview_url: previewUrl,
228
+ next_step: "Site cloned with all template pages. Edit content with search_page_elements + update_page_element(s), change colours/fonts via list_themes/site-style, then publish_site.",
229
+ };
156
230
  }));
157
231
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcake-storefront-mcp",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "MCP server for the WebCake/StoreCake storefront builder — page CRUD, page authoring, products, orders, and more",
5
5
  "mcpName": "io.github.vuluu2k/webcake-storefront-mcp",
6
6
  "license": "MIT",