webcake-landing-mcp 1.0.45 → 1.0.47
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/README.md
CHANGED
|
@@ -89,7 +89,7 @@ persists it (source-only — the page opens in the editor where re-saving render
|
|
|
89
89
|
| **npx (local)** — runs on your machine | Personal daily use, full control | browser `login`, a JWT, or none (reference tools) |
|
|
90
90
|
| **Hosted URL** — use our live server, nothing to install | No Node.js, teams, the claude.ai dialog | your personal `?jwt=` link / `x-webcake-jwt` header |
|
|
91
91
|
|
|
92
|
-
The **reference + generation tools** (`get_generation_guide`, `list_elements`, `validate_page`, …) and the **ingest tools** (`ingest_html`, `ingest_url` — turn an existing HTML or URL into a layout anchor so the AI can recreate or adapt it) work with **zero config**; only the **persistence tools** (`create_page`, `update_page`, `add_section`, `list_pages`, `find_pages`, `get_page`, `list_organizations`) need a token. Credentials resolve in order: **per-request header → env var → saved `auth.json`** (`login`).
|
|
92
|
+
The **reference + generation tools** (`get_generation_guide`, `list_elements`, `validate_page`, …) and the **ingest tools** (`ingest_html`, `ingest_url` — turn an existing HTML or URL into a layout anchor so the AI can recreate or adapt it) work with **zero config**; only the **persistence tools** (`create_page`, `update_page`, `add_section`, `patch_page`, `list_pages`, `find_pages`, `get_page`, `list_organizations`) need a token. Credentials resolve in order: **per-request header → env var → saved `auth.json`** (`login`).
|
|
93
93
|
|
|
94
94
|
> 🛠️ Prefer a shell-script installer (`install.sh`/`install.ps1`), a cloned local build, or hand-written per-IDE config? See **[docs/manual-install.md](docs/manual-install.md)**.
|
|
95
95
|
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.0.47",
|
|
4
|
+
"d": "10/06/2026",
|
|
5
|
+
"type": "Added",
|
|
6
|
+
"en": "New patch_page tool edits an existing page by element id without re-sending the whole source: the agent sends per-element ops (update, replace,…",
|
|
7
|
+
"vi": "Công cụ patch_page mới cho phép chỉnh sửa trang hiện có theo element id mà không cần gửi lại toàn bộ source: agent gửi các op theo element (update,…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "1.0.46",
|
|
11
|
+
"d": "09/06/2026",
|
|
12
|
+
"type": "Changed",
|
|
13
|
+
"en": "validate_page now emits an advisory warning when no section, button, or text on the page carries a non-neutral color (white, black, or grey),…",
|
|
14
|
+
"vi": "validate_page nay phát cảnh báo tư vấn khi không có section, button hay text nào trên trang mang màu thực sự (không phải trắng, đen hoặc xám), giúp…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.0.45",
|
|
4
18
|
"d": "09/06/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Fixed",
|
|
27
41
|
"en": "validate_page now raises an error when a countdown element's specials.language is set to a value outside the eight supported word-values (vietnam,…",
|
|
28
42
|
"vi": "validate_page nay phát lỗi khi element countdown có specials.language là giá trị nằm ngoài tám word-value được hỗ trợ (vietnam, english, filipino,…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.0.41",
|
|
32
|
-
"d": "09/06/2026",
|
|
33
|
-
"type": "Changed",
|
|
34
|
-
"en": "get_generation_guide and server instructions now require the agent to write all page copy in the same language the user is chatting in, with full,…",
|
|
35
|
-
"vi": "get_generation_guide và hướng dẫn server nay yêu cầu agent viết toàn bộ nội dung trang bằng cùng ngôn ngữ người dùng đang nhắn tin, với đầy đủ dấu…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.0.40",
|
|
39
|
-
"d": "09/06/2026",
|
|
40
|
-
"type": "Added",
|
|
41
|
-
"en": "New ingest_html tool parses an HTML string into a compact reference AST (~2–5KB) that classifies sections by role (header, hero, features, form,…",
|
|
42
|
-
"vi": "Công cụ ingest_html mới phân tích cú pháp một chuỗi HTML thành AST tham chiếu thu gọn (~2–5KB) phân loại các section theo vai trò (header, hero,…"
|
|
43
43
|
}
|
|
44
44
|
]
|
|
@@ -84,7 +84,7 @@ PREMIUM CRAFT (what separates a polished page from an amateur one — apply to E
|
|
|
84
84
|
- CTA WEIGHT: the primary button is the heaviest thing on its band — accent background, bold label, generous padding (height ~46–52), the same radius used everywhere else.
|
|
85
85
|
|
|
86
86
|
SECTION BUILD HINTS (apply to whichever sections the chosen archetype uses)
|
|
87
|
-
- Each section is one visual band: height that comfortably holds its content (taller on mobile since things stack), background that contrasts its text.
|
|
87
|
+
- Each section is one visual band: height that comfortably holds its content (taller on mobile since things stack), and a background that contrasts its text. SET responsive.<bp>.styles.background ON EVERY SECTION (both breakpoints) — the section factory default has NO background, so a section you leave unset renders transparent/white and the whole page looks colorless. Pull each band's background from the locked PALETTE and alternate them (light / tinted / dark) so consecutive bands read as distinct, never a flat white wall.
|
|
88
88
|
- HEADER — logo/brand at the page's LEFT margin (left=80 desktop / 20 mobile), nav/CTA flush to the RIGHT margin (its left = canvas − margin − width, so its right edge lands on 880 desktop / 400 mobile). Use the SAME margin as every section below — do NOT center the logo or invent a new left; a header on a different axis than the bands under it is the #1 header defect. Put every header child on ONE shared vertical centerline: match top + height/2 across the logo, brand text, and CTA button so nothing sits higher/lower than the rest.
|
|
89
89
|
- HERO — always a clear H1, a short supporting line, and the primary CTA visible without scrolling.
|
|
90
90
|
- FEATURES / BENEFITS — a row of equal cards (icon + title + text) or a 2-column list. Center the row with the ROW math; on mobile shrink to one canvas width or stack.
|
|
@@ -126,12 +126,17 @@ WORKFLOW (recommended)
|
|
|
126
126
|
0. INTAKE (never skip — even for a quick/test page): ask the essentials above, WAIT for the answers, restate a short outline (sections + CTA + colors), and get the user's "yes" BEFORE any new_page_skeleton / create_page. Do not generate on the same turn as the request.
|
|
127
127
|
0b. LOCK THE DESIGN SYSTEM (after the customer confirms): commit the exact palette, type scale, spacing scale, and component specs (see DESIGN SYSTEM) — these are your tokens for every element below. Set settings.fontGeneral to the chosen font.
|
|
128
128
|
1. Call get_generation_guide (this) once, then new_page_skeleton for the top-level shape.
|
|
129
|
-
2.
|
|
130
|
-
3.
|
|
131
|
-
|
|
129
|
+
2. For each element type you'll use, call get_element to learn its specials & see an example.
|
|
130
|
+
3. Optionally call new_element to get a correct skeleton, then fill specials + coordinates.
|
|
131
|
+
3b. For every image the page needs (hero, product, about, feature, gallery), call search_images and put a returned URL into specials.src / gallery item.link. Use placehold.co ONLY when search_images returns ok:false.
|
|
132
|
+
4. Assemble { page, popup, settings, options, cartConfigs }.
|
|
133
|
+
5. Call validate_page and fix every error.
|
|
134
|
+
6. To save: call list_organizations, show the orgs to the user and ask which to use (default to is_default). Then create_page (dry_run first, then dry_run:false with the chosen organization_id).
|
|
132
135
|
|
|
133
136
|
EDITING an existing page
|
|
134
|
-
- list_pages → let the user pick (or take a page_id from a URL).
|
|
137
|
+
- find_pages / list_pages → let the user pick (or take a page_id from a URL).
|
|
135
138
|
- get_page(page_id) → you get the live { page, popup, settings, ... }. Edit it surgically: change only the elements the user asked for (text/styles/specials/events); keep every other element, its id, and coordinates intact. Never regenerate the whole tree for a small change.
|
|
136
|
-
-
|
|
137
|
-
-
|
|
139
|
+
- SMALL edit → PREFER patch_page(page_id, patches): send ONLY the changed elements by id, not the whole source. Ops — {op:'update',id,specials?,styles?:{desktop?,mobile?},config?:{desktop?,mobile?},events?,properties?} (shallow-merge; op defaults to 'update'), {op:'replace',id,element}, {op:'remove',id}, {op:'add',parent_id,element}. The MCP fetches the live source, applies the ops, validates the whole tree, and saves. Reserve update_page(page_id, full source) for when you're rewriting most of the page.
|
|
140
|
+
- To add an element: give it a unique id + top/left/width/height, then patch_page({op:'add', parent_id:<section id>, element:<node>}).
|
|
141
|
+
- FIX-AFTER-ERROR: when create_page/update_page/add_section reports validation errors, fix ONLY the offending element ids with patch_page — do not rebuild and re-send the whole source. (If a create failed before any save, create_page a small valid skeleton first to get a page_id, then patch_page/add_section.)
|
|
142
|
+
- patch_page/update_page default to dry_run=true (preview); pass dry_run:false to save.`;
|
|
@@ -9,11 +9,12 @@ RULES (follow for every request):
|
|
|
9
9
|
- INTAKE FIRST — do this EVERY time, even for a "quick"/"test" page. Do NOT jump straight to new_page_skeleton/create_page on the same turn as the request: ask the essentials, restate an outline, get a "yes", THEN build. Ask ONE short batch (3–6, with sensible defaults so the user answers fast) enough to understand the page's PURPOSE, name, look and layout: page purpose/goal, brand/page name, what they sell + price (sales/ads pages), primary color + logo/branding, sections & layout in order, primary CTA + destination, desktop+mobile or mobile-only, which organization. CONSULT, don't interrogate: SUGGEST so the user reacts to something concrete — propose a section flow (pick the archetype matching the page type) + a look (hero treatment + color/tone), and when the user is vague offer 2–3 directions to choose from; proactively suggest sections that fit their goal (social-proof, FAQ, countdown), but ask, don't silently add. Then restate the proposed design (section flow + CTA + color/tone) and WAIT for the user's confirmation, iterating until it matches their intent, before generating. Never assume or silently placeholder the page name, product, price, or colors — ask; only placeholder a core fact when the user explicitly declines to give it.
|
|
10
10
|
- ASK for any real data the page will display — never invent it, and don't silently placeholder it. This includes: phone/hotline/Zalo, price (+ original price), address, shop/brand name, links/URLs, email, opening hours, and exact stats/social-proof numbers. If a value the page needs is missing, ASK the user for it (in intake, or pause and ask before generating). Use a clearly-labelled placeholder ONLY when the user explicitly says to skip it — then tell them exactly what to fill in.
|
|
11
11
|
- LANGUAGE: write ALL page copy in the SAME language the user is chatting in, with FULL, CORRECT diacritics/accents. For Vietnamese, every word MUST carry its proper dấu (e.g. "Trân Trọng Kính Mời", "Ngày 15 Tháng 08 Năm 2025") — NEVER emit accent-stripped "không dấu" text. Never romanize or drop accent marks from any language.
|
|
12
|
-
-
|
|
12
|
+
- ALWAYS call validate_page and fix every error before create_page / update_page.
|
|
13
13
|
- BUILD THE SOURCE IN ONE PASS — gather everything you need BEFORE assembling the source, then build the FULL tree once. BATCH the reads: when a section needs several element types (section + text-block + image-block + button + form + input), call get_element({types:[…]}) ONCE instead of one call per type — same for images, call search_images({queries:[…]}) ONCE with one query per image slot (it dedups + parallelizes and returns one best photo per query). Do NOT interleave get_element calls between create_page previews and rebuild. create_page/update_page take the entire source as input, so each call re-ships the whole page — re-previewing repeatedly wastes the request.
|
|
14
|
-
- create_page and update_page DEFAULT to dry_run=true (a safety net for ambiguous requests). When the user's intent is clear
|
|
14
|
+
- create_page and update_page DEFAULT to dry_run=true (a safety net for ambiguous requests). When the user's intent is clear AND validate_page already passed (no errors), SKIP the dry-run and call with dry_run=false directly — saves one round-trip. Use dry_run=true only when (a) the request is ambiguous about target/content, (b) the user explicitly asks to "preview" or "xem trước", (c) this is an update_page that overwrites significant existing content, or (d) you genuinely need to inspect the redacted payload. Never loop dry-runs to "check" the source — validate_page is the validator. Do not run dry-run then dry-run again before the real write.
|
|
15
15
|
- LARGE PAGES (4+ sections) — build INCREMENTALLY to avoid the giant single create_page payload that can drop the connection: create_page with a SMALL skeleton (empty/near-empty page) to get a page_id, then call add_section once per section (each call ships ONLY that section; the backend appends it server-side and rejects duplicate ids — no whole-source get+put). Small pages can still go in one create_page pass.
|
|
16
|
-
- EDIT existing pages surgically: find_pages (locate the page by name/domain/id when you don't already have a page_id) → get_page → change ONLY what was asked → keep every other element, its id, and coordinates
|
|
16
|
+
- EDIT existing pages surgically: find_pages (locate the page by name/domain/id when you don't already have a page_id) → get_page → change ONLY what was asked → keep every other element, its id, and coordinates. For a SMALL edit, PREFER patch_page over update_page: send only the changed elements by id (ops: update/replace/remove/add) instead of re-shipping the whole tree — the MCP fetches the live source, merges, validates and saves server-side. Use update_page only when you're rewriting most of the page. Never regenerate the whole tree for a small change.
|
|
17
|
+
- FIX-AFTER-ERROR (don't rebuild): when create_page / update_page / add_section returns validation errors, the page already saved by then has a page_id — correct ONLY the offending element ids with patch_page (send just those ops), do NOT re-emit the whole source. That avoids re-shipping the large payload that drops the connection. (For a create that failed before any save: create_page a SMALL valid skeleton first to get a page_id, then patch_page / add_section to fill it in.)
|
|
17
18
|
- Organizations: call list_organizations and ask which to use; default to the is_default org. Endpoints are owner-scoped (only the account's own pages).
|
|
18
19
|
- REFERENCE INPUT — if the user provides a layout reference, USE it as the layout anchor (don't ignore it, don't re-invent from scratch). Three input modes: (1) IMAGE/screenshot attached in chat → analyze it natively (no tool call): identify section flow (hero/features/form/cta/footer), heading hierarchy, dominant colors, font feel, then map sections to Webcake elements. (2) HTML string → call ingest_html(html) to get a compact AST. (3) URL → call ingest_url(url) for the same AST. The AST classifies sections by role and lists headings/subheadings/ctas/images/form_fields plus brand hints (colors/fonts) — use it for LAYOUT + HIERARCHY, then generate FRESH content tailored to the user's brand (don't 1:1 copy text). intent='clone' only when the user explicitly asks to mirror the original; default intent='adapt'. The reference workflow PRESERVES craft rules above (centering, page margin, premium spacing, real images) — apply them on top of the reference layout, don't bypass them.
|
|
19
20
|
|
|
@@ -28,4 +29,4 @@ MODEL (essentials):
|
|
|
28
29
|
- Visible content lives in specials (text, src, field_name…), never in styles. Colors as rgba(). Animation in config.animation={name,delay,duration,repeat}. Form inputs need a unique specials.field_name (use canonical keys: full_name, phone_number, email, address, quantity).
|
|
29
30
|
- IMAGES: include them (hero/product, feature icons, about photo). PREFER REAL PHOTOS — call search_images with a short English subject (e.g. 'fresh coffee cup') and put a returned URL (src.large for a hero/banner, src.medium for a card/thumb) into the image-block specials.src; it works out of the box (a shared proxy supplies images). Only if search_images returns ok:false, FALL BACK to a PLACEHOLDER sized to the box: https://placehold.co/<width>x<height>. (gallery.media = array of OBJECTS {type:'image',link:'<url>',linkVideo:'',typeVideo:'youtube',imageCompression:true} — NOT plain strings, the gallery reads item.link; video.specials.img = poster). NEVER leave src empty (renders blank). Ensure text contrasts with its section background.
|
|
30
31
|
|
|
31
|
-
Start by calling get_generation_guide. Tools: get_generation_guide, list_elements, get_element, new_element, new_page_skeleton, get_page_schema, validate_page, search_images, ingest_html, ingest_url, list_organizations, create_page, list_pages, find_pages, get_page, update_page, add_section.`;
|
|
32
|
+
Start by calling get_generation_guide. Tools: get_generation_guide, list_elements, get_element, new_element, new_page_skeleton, get_page_schema, validate_page, search_images, ingest_html, ingest_url, list_organizations, create_page, list_pages, find_pages, get_page, update_page, add_section, patch_page.`;
|
|
@@ -57,6 +57,45 @@ function num(v) {
|
|
|
57
57
|
}
|
|
58
58
|
return undefined;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* True when a CSS color string carries real hue — i.e. NOT white/black/grey/
|
|
62
|
+
* transparent. Used to flag a page that ships with no color at all (every band
|
|
63
|
+
* white/neutral, no accent), which renders flat/"colorless". A gradient or image
|
|
64
|
+
* background counts as color. Neutrals (white/black/grey) have ~0 channel spread.
|
|
65
|
+
*/
|
|
66
|
+
function isVividColor(v) {
|
|
67
|
+
if (typeof v !== "string")
|
|
68
|
+
return false;
|
|
69
|
+
const s = v.trim().toLowerCase();
|
|
70
|
+
if (!s || s === "transparent" || s === "none" || s === "inherit")
|
|
71
|
+
return false;
|
|
72
|
+
if (s.includes("gradient") || s.startsWith("url("))
|
|
73
|
+
return true;
|
|
74
|
+
let r, g, b, a = 1;
|
|
75
|
+
const rgba = s.match(/rgba?\(([^)]+)\)/);
|
|
76
|
+
if (rgba) {
|
|
77
|
+
const parts = rgba[1].split(",").map((x) => parseFloat(x.trim()));
|
|
78
|
+
[r, g, b] = parts;
|
|
79
|
+
if (parts.length >= 4 && Number.isFinite(parts[3]))
|
|
80
|
+
a = parts[3];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const hex = s.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/);
|
|
84
|
+
if (!hex)
|
|
85
|
+
return false;
|
|
86
|
+
let h = hex[1];
|
|
87
|
+
if (h.length === 3)
|
|
88
|
+
h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
|
89
|
+
r = parseInt(h.slice(0, 2), 16);
|
|
90
|
+
g = parseInt(h.slice(2, 4), 16);
|
|
91
|
+
b = parseInt(h.slice(4, 6), 16);
|
|
92
|
+
}
|
|
93
|
+
if (![r, g, b].every((n) => Number.isFinite(n)))
|
|
94
|
+
return false;
|
|
95
|
+
if (a <= 0.05)
|
|
96
|
+
return false; // fully transparent
|
|
97
|
+
return Math.max(r, g, b) - Math.min(r, g, b) >= 16; // channel spread ⇒ has hue
|
|
98
|
+
}
|
|
60
99
|
/** Accept an object or a JSON string. Returns the parsed page or throws. */
|
|
61
100
|
export function coercePage(input) {
|
|
62
101
|
if (typeof input === "string")
|
|
@@ -90,6 +129,9 @@ export function validatePage(input) {
|
|
|
90
129
|
// form nodes — used to check field_name uniqueness within each form's scope
|
|
91
130
|
const forms = [];
|
|
92
131
|
let elementCount = 0;
|
|
132
|
+
// Whether ANY element (section, button, text…) carries real color on either
|
|
133
|
+
// breakpoint. A page where this stays false renders flat/colorless (warned once).
|
|
134
|
+
let anyVividColor = false;
|
|
93
135
|
const topList = Array.isArray(page?.page)
|
|
94
136
|
? page.page
|
|
95
137
|
: page?.page
|
|
@@ -117,6 +159,20 @@ export function validatePage(input) {
|
|
|
117
159
|
if (!node.responsive?.desktop || !node.responsive?.mobile) {
|
|
118
160
|
errors.push(`${path} (${type}): must have responsive.desktop AND responsive.mobile.`);
|
|
119
161
|
}
|
|
162
|
+
// does this element put any real color on the page? (background / text / border)
|
|
163
|
+
if (!anyVividColor) {
|
|
164
|
+
for (const bp of ["desktop", "mobile"]) {
|
|
165
|
+
const st = node.responsive?.[bp]?.styles;
|
|
166
|
+
if (st &&
|
|
167
|
+
(isVividColor(st.background) ||
|
|
168
|
+
isVividColor(st.backgroundColor) ||
|
|
169
|
+
isVividColor(st.color) ||
|
|
170
|
+
isVividColor(st.borderColor))) {
|
|
171
|
+
anyVividColor = true;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
120
176
|
// children only on containers
|
|
121
177
|
if (Array.isArray(node.children) && node.children.length > 0 && type && !CONTAINER_TYPES.has(type)) {
|
|
122
178
|
errors.push(`${path} (${type}): has children but "${type}" is not a container type.`);
|
|
@@ -383,6 +439,12 @@ export function validatePage(input) {
|
|
|
383
439
|
warnings.push(`Sections start on different left margins (${list}). Put every band's left-anchored content (the header logo included) on ONE shared left axis — e.g. left=${minEdge} desktop — so the page reads aligned, not ragged. This is the #1 header-misalignment defect.`);
|
|
384
440
|
}
|
|
385
441
|
}
|
|
442
|
+
// 3c) Colorless page — nothing on the page carries real color (every band/button/
|
|
443
|
+
// heading is white/black/grey). Sections have NO default background, so a page
|
|
444
|
+
// that never sets one renders as a flat white wall. Advisory only.
|
|
445
|
+
if (topList.length >= 2 && elementCount >= 3 && !anyVividColor) {
|
|
446
|
+
warnings.push(`Page has no color — no section background, button, or text uses a non-neutral color, so it renders as a flat white/grey wall. Set responsive.<bp>.styles.background on each section (alternate light/tinted/dark from the palette) and give the primary CTA an accent background. If a stark black-and-white look is intentional, ignore this.`);
|
|
447
|
+
}
|
|
386
448
|
popups.forEach((p, i) => {
|
|
387
449
|
const ds = p?.responsive?.desktop?.styles ?? {};
|
|
388
450
|
const ms = p?.responsive?.mobile?.styles ?? {};
|
|
@@ -366,4 +366,235 @@ export function registerPersistenceTools(server, domain) {
|
|
|
366
366
|
warnings: mergedResult.warnings,
|
|
367
367
|
});
|
|
368
368
|
});
|
|
369
|
+
// 14) Patch page (surgical element edit / fix-after-error) -------------------
|
|
370
|
+
// Why this exists: update_page takes the ENTIRE source as one tool argument, so
|
|
371
|
+
// fixing one bad element — or making a small edit — forces the model to re-emit
|
|
372
|
+
// the whole (often huge) page JSON, the same large payload that can drop the
|
|
373
|
+
// client↔Claude connection. patch_page lets the model send ONLY the diff: a list
|
|
374
|
+
// of per-element ops keyed by element id. The MCP fetches the live source, applies
|
|
375
|
+
// the ops, validates the WHOLE merged tree, and PUTs — the big merge lives on the
|
|
376
|
+
// robust MCP↔backend link, never in a tool argument the model has to stream.
|
|
377
|
+
//
|
|
378
|
+
// This is the fix-after-error path: when create_page/add_section/update_page
|
|
379
|
+
// returns validation errors, the model corrects ONLY the offending element ids via
|
|
380
|
+
// patch_page instead of rebuilding the source. It is also the everyday surgical-edit
|
|
381
|
+
// path (change one element's text/color/position without resending the tree).
|
|
382
|
+
//
|
|
383
|
+
// Ops (each keyed by element id, found anywhere in page or popup):
|
|
384
|
+
// { op:"update", id, specials?, styles?:{desktop?,mobile?}, config?:{desktop?,mobile?}, events?, properties? }
|
|
385
|
+
// — shallow-merge the given fields into the existing element (op defaults to "update").
|
|
386
|
+
// { op:"replace", id, element } — swap the whole node in place (compact authoring ok; keeps the id).
|
|
387
|
+
// { op:"remove", id } — delete the element and its subtree.
|
|
388
|
+
// { op:"add", parent_id, element } — append a new child element to the parent container.
|
|
389
|
+
// Unlike create_page's env-less preview, patch_page MUST read the live page, so it
|
|
390
|
+
// needs creds even on dry_run; dry_run only gates the final write.
|
|
391
|
+
const asArray = (input) => {
|
|
392
|
+
let v = input;
|
|
393
|
+
if (typeof v === "string") {
|
|
394
|
+
try {
|
|
395
|
+
v = JSON.parse(v);
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
/* not JSON — wrap as single */
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return Array.isArray(v) ? v : [v];
|
|
402
|
+
};
|
|
403
|
+
// Find a node by id within the real array refs (so remove/add mutate the live tree),
|
|
404
|
+
// recursing into children; returns the node, its parent array, and index.
|
|
405
|
+
const findById = (arr, id) => {
|
|
406
|
+
for (let i = 0; i < arr.length; i++) {
|
|
407
|
+
const n = arr[i];
|
|
408
|
+
if (!n || typeof n !== "object")
|
|
409
|
+
continue;
|
|
410
|
+
if (n.id === id)
|
|
411
|
+
return { node: n, parentArr: arr, index: i };
|
|
412
|
+
if (Array.isArray(n.children)) {
|
|
413
|
+
const found = findById(n.children, id);
|
|
414
|
+
if (found)
|
|
415
|
+
return found;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
};
|
|
420
|
+
const mergeStyleMap = (node, kind, byBp) => {
|
|
421
|
+
const touched = [];
|
|
422
|
+
for (const bp of ["desktop", "mobile"]) {
|
|
423
|
+
const patch = byBp?.[bp];
|
|
424
|
+
if (!patch || typeof patch !== "object")
|
|
425
|
+
continue;
|
|
426
|
+
node.responsive = node.responsive ?? {};
|
|
427
|
+
node.responsive[bp] = node.responsive[bp] ?? { config: {}, styles: {} };
|
|
428
|
+
node.responsive[bp][kind] = { ...(node.responsive[bp][kind] ?? {}), ...patch };
|
|
429
|
+
touched.push(`${bp}.${kind}`);
|
|
430
|
+
}
|
|
431
|
+
return touched;
|
|
432
|
+
};
|
|
433
|
+
server.tool("patch_page", "Edits an EXISTING page by element id WITHOUT re-sending the whole source — the surgical-edit and fix-after-error path. Send only a list of per-element ops; the MCP fetches the live source, applies them, validates the WHOLE merged tree (blocks on errors), and saves. Ops: {op:'update',id,specials?,styles?:{desktop?,mobile?},config?:{desktop?,mobile?},events?,properties?} (shallow-merges; op defaults to 'update'), {op:'replace',id,element}, {op:'remove',id}, {op:'add',parent_id,element}. Use this to fix the elements a failed create_page/update_page/add_section reported, or to change one element's text/color/position — instead of rebuilding the page. DEFAULTS to dry_run=true (reads + merges + validates + previews, no write); dry_run=false to save. Needs WEBCAKE_API_BASE + WEBCAKE_JWT (it reads the live page, so creds are required even on dry_run).", {
|
|
434
|
+
page_id: z.string().describe("The page id to edit (from create_page, list_pages, or find_pages; must be owned by the account)."),
|
|
435
|
+
patches: z
|
|
436
|
+
.any()
|
|
437
|
+
.describe("One op object or an array of them (object/array or JSON string). Each targets an element by id: {op:'update',id,specials?,styles?:{desktop?,mobile?},config?:{desktop?,mobile?},events?,properties?} merges fields into the element (op may be omitted); {op:'replace',id,element} swaps the node; {op:'remove',id} deletes it; {op:'add',parent_id,element} appends a child to a container."),
|
|
438
|
+
dry_run: z
|
|
439
|
+
.boolean()
|
|
440
|
+
.optional()
|
|
441
|
+
.describe("Default TRUE — read, merge, validate and preview the resulting save WITHOUT writing. Set false to actually save."),
|
|
442
|
+
}, { title: "Patch Webcake Page (by element id)", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async ({ page_id, patches, dry_run }, extra) => {
|
|
443
|
+
const isDry = dry_run !== false; // default true (safe)
|
|
444
|
+
const ops = asArray(patches).filter((p) => p != null && typeof p === "object");
|
|
445
|
+
if (ops.length === 0) {
|
|
446
|
+
return text({ patched: false, reason: "no_patches", hint: "Pass an op object or a non-empty array of { op, id, … } ops." });
|
|
447
|
+
}
|
|
448
|
+
// patch_page always reads the live tree (even on dry_run) — needs creds.
|
|
449
|
+
const { config, missing } = cfgFor(extra);
|
|
450
|
+
if (!config) {
|
|
451
|
+
return text({
|
|
452
|
+
patched: false,
|
|
453
|
+
reason: "missing_env",
|
|
454
|
+
missing_env: missing,
|
|
455
|
+
hint: "Configure WEBCAKE_API_BASE and WEBCAKE_JWT (env), or send the x-webcake-jwt header (remote), then retry.",
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
const current = await getPageSource(config, page_id);
|
|
459
|
+
if (!current.ok || current.source == null) {
|
|
460
|
+
return text({
|
|
461
|
+
patched: false,
|
|
462
|
+
reason: "fetch_failed",
|
|
463
|
+
status: current.status,
|
|
464
|
+
error: current.error ?? "Page source not found.",
|
|
465
|
+
hint: "Check the page_id (find_pages/list_pages) and that the account owns it.",
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
let base = current.source;
|
|
469
|
+
if (typeof base === "string") {
|
|
470
|
+
try {
|
|
471
|
+
base = JSON.parse(base);
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
return text({ patched: false, reason: "bad_source", hint: "The stored page source could not be parsed." });
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const treeRoots = [base.page, base.popup].filter((a) => Array.isArray(a));
|
|
478
|
+
const locate = (id) => {
|
|
479
|
+
for (const r of treeRoots) {
|
|
480
|
+
const hit = findById(r, id);
|
|
481
|
+
if (hit)
|
|
482
|
+
return hit;
|
|
483
|
+
}
|
|
484
|
+
return null;
|
|
485
|
+
};
|
|
486
|
+
// Apply every op against the live tree. A missing target aborts the whole
|
|
487
|
+
// patch (we never write a partial edit).
|
|
488
|
+
const applied = [];
|
|
489
|
+
const notFound = [];
|
|
490
|
+
const badOps = [];
|
|
491
|
+
for (const p of ops) {
|
|
492
|
+
const op = p.op ?? "update";
|
|
493
|
+
if (op === "add") {
|
|
494
|
+
const pid = p.parent_id ?? p.id;
|
|
495
|
+
if (typeof pid !== "string" || p.element == null) {
|
|
496
|
+
badOps.push(`add needs parent_id + element`);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const hit = locate(pid);
|
|
500
|
+
if (!hit) {
|
|
501
|
+
notFound.push({ op, id: pid });
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
hit.node.children = Array.isArray(hit.node.children) ? hit.node.children : [];
|
|
505
|
+
hit.node.children.push(p.element);
|
|
506
|
+
applied.push({ op, parent_id: pid, added_id: p.element?.id });
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (typeof p.id !== "string") {
|
|
510
|
+
badOps.push(`${op} needs a string id`);
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
const hit = locate(p.id);
|
|
514
|
+
if (!hit) {
|
|
515
|
+
notFound.push({ op, id: p.id });
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (op === "remove") {
|
|
519
|
+
hit.parentArr.splice(hit.index, 1);
|
|
520
|
+
applied.push({ op, id: p.id });
|
|
521
|
+
}
|
|
522
|
+
else if (op === "replace") {
|
|
523
|
+
if (p.element == null) {
|
|
524
|
+
badOps.push(`replace ${p.id} needs element`);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
const repl = p.element;
|
|
528
|
+
if (repl && typeof repl === "object" && repl.id == null)
|
|
529
|
+
repl.id = p.id;
|
|
530
|
+
hit.parentArr[hit.index] = repl;
|
|
531
|
+
applied.push({ op, id: p.id });
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
// update (default)
|
|
535
|
+
const changed = [];
|
|
536
|
+
if (p.specials && typeof p.specials === "object") {
|
|
537
|
+
hit.node.specials = { ...(hit.node.specials ?? {}), ...p.specials };
|
|
538
|
+
changed.push("specials");
|
|
539
|
+
}
|
|
540
|
+
changed.push(...mergeStyleMap(hit.node, "styles", p.styles));
|
|
541
|
+
changed.push(...mergeStyleMap(hit.node, "config", p.config));
|
|
542
|
+
if (Array.isArray(p.events)) {
|
|
543
|
+
hit.node.events = p.events;
|
|
544
|
+
changed.push("events");
|
|
545
|
+
}
|
|
546
|
+
if (p.properties && typeof p.properties === "object") {
|
|
547
|
+
hit.node.properties = { ...(hit.node.properties ?? {}), ...p.properties };
|
|
548
|
+
changed.push("properties");
|
|
549
|
+
}
|
|
550
|
+
applied.push({ op: "update", id: p.id, changed });
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (badOps.length > 0) {
|
|
554
|
+
return text({ patched: false, reason: "bad_ops", bad_ops: badOps, hint: "Each op needs id (or parent_id for add) and an element where required." });
|
|
555
|
+
}
|
|
556
|
+
if (notFound.length > 0) {
|
|
557
|
+
return text({
|
|
558
|
+
patched: false,
|
|
559
|
+
reason: "target_not_found",
|
|
560
|
+
not_found: notFound,
|
|
561
|
+
hint: "No element with that id exists on the live page. Run get_page to see the current ids; ids are case-sensitive.",
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
// Validate the WHOLE merged tree (hydrate sparse replaced/added nodes first).
|
|
565
|
+
const expanded = domain.expand(base);
|
|
566
|
+
const result = domain.validate(expanded);
|
|
567
|
+
if (!result.valid) {
|
|
568
|
+
return text({
|
|
569
|
+
patched: false,
|
|
570
|
+
reason: "validation_failed",
|
|
571
|
+
errors: result.errors,
|
|
572
|
+
warnings: result.warnings,
|
|
573
|
+
patches_applied: applied,
|
|
574
|
+
hint: "The edit produced an invalid tree — fix the listed errors in your ops, then retry.",
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
const parsed = domain.coerce(expanded);
|
|
578
|
+
if (isDry) {
|
|
579
|
+
return text({
|
|
580
|
+
dry_run: true,
|
|
581
|
+
page_id,
|
|
582
|
+
patches_applied: applied,
|
|
583
|
+
validation: { valid: true, warnings: result.warnings, stats: result.stats },
|
|
584
|
+
request: buildUpdateRequestRedacted(config, page_id, parsed),
|
|
585
|
+
hint: "Re-run with dry_run=false to actually save the edit.",
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
const outcome = await updatePageSource(config, page_id, parsed);
|
|
589
|
+
return text({
|
|
590
|
+
patched: outcome.ok,
|
|
591
|
+
patches_applied: applied,
|
|
592
|
+
page_id: outcome.page_id,
|
|
593
|
+
editor_url: outcome.editor_url,
|
|
594
|
+
preview_url: outcome.preview_url,
|
|
595
|
+
status: outcome.status,
|
|
596
|
+
error: outcome.error,
|
|
597
|
+
warnings: result.warnings,
|
|
598
|
+
});
|
|
599
|
+
});
|
|
369
600
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webcake-landing-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"description": "MCP server exposing Webcake landing-page element schemas + AI usage hints, and persisting LLM-generated page sources to a Webcake backend.",
|
|
5
5
|
"mcpName": "io.github.vuluu2k/webcake-landing-mcp",
|
|
6
6
|
"type": "module",
|