webcake-storefront-mcp 1.30.0 → 1.31.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
@@ -29,7 +29,7 @@ export class WebcakeCmsApi {
29
29
  getBundleParams() {
30
30
  return { token: this._adminToken, x_cms_api_key: this._cmsApiKey };
31
31
  }
32
- async request(method, path, { body, query, timeout } = {}) {
32
+ async request(method, path, { body, query, timeout, headers: extraHeaders } = {}) {
33
33
  const url = new URL(`${this.baseUrl}${path}`);
34
34
  if (query) {
35
35
  for (const [k, v] of Object.entries(query)) {
@@ -41,6 +41,7 @@ export class WebcakeCmsApi {
41
41
  "Content-Type": "application/json",
42
42
  Authorization: `Bearer ${this.token}`,
43
43
  ...(this.sessionId && { "x-session-id": this.sessionId }),
44
+ ...(extraHeaders || {}),
44
45
  };
45
46
  const controller = new AbortController();
46
47
  const timer = setTimeout(() => controller.abort(), timeout || DEFAULT_TIMEOUT);
@@ -340,8 +341,37 @@ export class WebcakeCmsApi {
340
341
  getCollection(id) {
341
342
  return this.request("GET", `/api/v1/dashboard/site/${this.siteId}/db_collections/${id}`);
342
343
  }
343
- queryCollectionRecords(tableName, query) {
344
- return this.request("GET", `/api/v1/dashboard/site/${this.siteId}/db_collections/collections/${tableName}/records`, { query });
344
+ /** Header carrying the CMS api key — collection-data endpoints (records) need it on top of
345
+ * the dashboard JWT (without it they 401). Fetches the key once and caches it. */
346
+ async cmsApiHeader() {
347
+ await this.fetchCmsTokens();
348
+ return this._cmsApiKey ? { "x-cms-api-key": this._cmsApiKey } : {};
349
+ }
350
+ /** Query a collection's records. Needs the CMS api-key header (else 401). The records
351
+ * endpoint accepts page/limit plus `where` (a filter object/JSON) and `order_by`. */
352
+ async queryCollectionRecords(tableName, query) {
353
+ const headers = await this.cmsApiHeader();
354
+ return this.request("GET", `/api/v1/dashboard/site/${this.siteId}/db_collections/collections/${tableName}/records`, { query, headers });
355
+ }
356
+ /** Insert a record into a collection. Body = the record fields. CMS-api-key authed. */
357
+ async insertCollectionRecord(tableName, record) {
358
+ const headers = await this.cmsApiHeader();
359
+ return this.request("POST", `/api/v1/dashboard/site/${this.siteId}/db_collections/collections/${tableName}/records`, { body: record, headers });
360
+ }
361
+ /** Update a record by id. Body = the changed fields. CMS-api-key authed. */
362
+ async updateCollectionRecord(tableName, recordId, record) {
363
+ const headers = await this.cmsApiHeader();
364
+ return this.request("PATCH", `/api/v1/dashboard/site/${this.siteId}/db_collections/collections/${tableName}/records/${recordId}`, { body: record, headers });
365
+ }
366
+ /** Delete a record by id. CMS-api-key authed. */
367
+ async deleteCollectionRecord(tableName, recordId) {
368
+ const headers = await this.cmsApiHeader();
369
+ return this.request("DELETE", `/api/v1/dashboard/site/${this.siteId}/db_collections/collections/${tableName}/records/${recordId}`, { headers });
370
+ }
371
+ /** Create a collection (table). Body: { name, schema:[{name,type,...}], ... }. */
372
+ async createCollection(params) {
373
+ const headers = await this.cmsApiHeader();
374
+ return this.request("POST", `/api/v1/dashboard/site/${this.siteId}/db_collections`, { body: params, headers, timeout: 60000 });
345
375
  }
346
376
  // ── Blog Articles ──
347
377
  listArticles(query) {
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "v": "1.31.0",
4
+ "d": "26/06/2026",
5
+ "type": "Added",
6
+ "en": "New create_collection tool creates a custom data table by accepting a name and a schema array of field definitions (with types such as string,…",
7
+ "vi": "Tool mới create_collection tạo bảng dữ liệu tùy chỉnh bằng cách nhận tham số name và mảng schema chứa định nghĩa các trường (với các kiểu dữ liệu…"
8
+ },
2
9
  {
3
10
  "v": "1.30.0",
4
11
  "d": "26/06/2026",
@@ -33,12 +40,5 @@
33
40
  "type": "Fixed",
34
41
  "en": "list_products now correctly unwraps the { products, total_product } API response shape, returning a product array and accurate total instead of…",
35
42
  "vi": "list_products nay giải nén đúng kiểu phản hồi { products, total_product } từ API, trả về mảng sản phẩm và tổng chính xác thay vì trả thẳng đối tượng…"
36
- },
37
- {
38
- "v": "1.26.0",
39
- "d": "26/06/2026",
40
- "type": "Fixed",
41
- "en": "create_product now accepts a short_description parameter and sends it to the backend as [{description}] — the array shape the real product schema…",
42
- "vi": "create_product nay nhận thêm tham số short_description và gửi lên backend dưới dạng [{description}] — đúng kiểu mảng mà schema sản phẩm thực tế yêu…"
43
43
  }
44
44
  ]
@@ -25,9 +25,40 @@ export function registerCollectionTools(server, api, handle) {
25
25
  server.tool("get_collection", "Get a specific collection's details including full schema (field names, types, constraints, references) and records", {
26
26
  id: z.string().describe("Collection ID"),
27
27
  }, ({ id }) => handle(() => api.getCollection(id)));
28
- server.tool("query_collection_records", "Query records from a collection by table name. Use to inspect existing data", {
29
- table_name: z.string().describe("Collection table name (e.g. 'subscribers', 'custom_orders')"),
28
+ server.tool("query_collection_records", "Query records from a collection (custom data table) by table name. Supports paging + an optional `where` filter and `order_by` sort. (Uses the CMS api-key auth the records endpoint requires.)", {
29
+ table_name: z.string().describe("Collection table name (e.g. 'subscribers', 'custom_orders') — from get_collection.table_name"),
30
30
  page: z.number().optional().describe("Page number"),
31
31
  limit: z.number().optional().describe("Items per page"),
32
- }, ({ table_name, page, limit }) => handle(() => api.queryCollectionRecords(table_name, { page, limit })));
32
+ where: z.record(z.any()).optional().describe("Filter object, e.g. { status: 'active' } matches records by field value."),
33
+ order_by: z.string().optional().describe("Field to sort by (e.g. 'inserted_at')."),
34
+ }, ({ table_name, page, limit, where, order_by }) => handle(() => {
35
+ const query = { page: page ?? 1, limit: limit ?? 50 };
36
+ if (where && Object.keys(where).length)
37
+ query.where = JSON.stringify(where);
38
+ if (order_by)
39
+ query.order_by = order_by;
40
+ return api.queryCollectionRecords(table_name, query);
41
+ }));
42
+ // ── Write tools (custom data CRUD). Endpoints follow the same /db_collections/collections/
43
+ // {table}/records[/{id}] REST pattern as the verified read endpoint, with the CMS api-key
44
+ // header. They mutate live data — run a small test first to confirm your field shape. ──
45
+ server.tool("create_collection", "Create a new collection (custom data TABLE) so you can store/query arbitrary data. Pass a name + the field schema. The backend adds id/inserted_at/updated_at automatically.", {
46
+ name: z.string().describe("Collection / table name (e.g. 'subscribers')."),
47
+ schema: z
48
+ .array(z.object({ name: z.string(), type: z.string().describe("Field type: string | text | integer | float | boolean | naive_datetime | binary_id | map | array"), required: z.boolean().optional() }))
49
+ .describe("Field definitions, e.g. [{name:'email',type:'string',required:true},{name:'joined_at',type:'naive_datetime'}]."),
50
+ }, ({ name, schema }) => handle(() => api.createCollection({ name, schema })));
51
+ server.tool("insert_collection_record", "Insert a record into a collection (custom data table). `record` is a field→value object matching the table schema.", {
52
+ table_name: z.string().describe("Collection table name."),
53
+ record: z.record(z.any()).describe("Record fields, e.g. { email:'a@b.com', joined_at:'2026-06-26T10:00:00' }."),
54
+ }, ({ table_name, record }) => handle(() => api.insertCollectionRecord(table_name, record)));
55
+ server.tool("update_collection_record", "Update a record in a collection by id. `record` carries only the changed fields.", {
56
+ table_name: z.string().describe("Collection table name."),
57
+ record_id: z.string().describe("Record id to update."),
58
+ record: z.record(z.any()).describe("Changed fields."),
59
+ }, ({ table_name, record_id, record }) => handle(() => api.updateCollectionRecord(table_name, record_id, record)));
60
+ server.tool("delete_collection_record", "Delete a record from a collection by id.", {
61
+ table_name: z.string().describe("Collection table name."),
62
+ record_id: z.string().describe("Record id to delete."),
63
+ }, ({ table_name, record_id }) => handle(() => api.deleteCollectionRecord(table_name, record_id)));
33
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcake-storefront-mcp",
3
- "version": "1.30.0",
3
+ "version": "1.31.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",