webcake-landing-mcp 1.15.0 → 1.16.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.
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "v": "1.16.0",
4
+ "d": "25/11/2026",
5
+ "type": "Added",
6
+ "en": "list_pages, find_pages, get_page, update_page, add_section, patch_page, and publish_page now accept an organization_id argument (an organization id,…",
7
+ "vi": "list_pages, find_pages, get_page, update_page, add_section, patch_page và publish_page nay nhận thêm tham số organization_id (một id tổ chức, hoặc…"
8
+ },
2
9
  {
3
10
  "v": "1.15.0",
4
11
  "d": "23/11/2026",
@@ -33,12 +40,5 @@
33
40
  "type": "Fixed",
34
41
  "en": "update_page/patch_page no longer block on a click event the Webcake editor itself saved with action:null (an event added via the editor's EventTrait…",
35
42
  "vi": "update_page/patch_page không còn bị chặn bởi một event click mà chính editor Webcake đã lưu với action:null (một event được thêm qua picker…"
36
- },
37
- {
38
- "v": "1.13.4",
39
- "d": "20/11/2026",
40
- "type": "Changed",
41
- "en": "All read-only tools (get_generation_guide, list_elements, get_element, get_page_schema, new_element, new_page_skeleton, validate_page,…",
42
- "vi": "Tất cả tool chỉ-đọc (get_generation_guide, list_elements, get_element, get_page_schema, new_element, new_page_skeleton, validate_page,…"
43
43
  }
44
44
  ]
@@ -15,7 +15,7 @@ RULES (follow for every request):
15
15
  - 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). Across MULTIPLE pages in one conversation: reusing skeletons you already fetched is correct, but call get_element for any type you have NOT already fetched in this conversation — NEVER author an unfamiliar type from memory; and if the earlier skeletons are no longer in your context (long conversation, compacted history), re-fetch before building. 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.
16
16
  - 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, warnings fixed), 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.
17
17
  - 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.
18
- - 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. CONCURRENCY — the user may be editing the SAME page in the Webcake editor while you work: update_page replaces the whole stored tree, so a source read a while ago (or a cached draft_id, which can be hours old) would silently revert their changes. The server now checks this for you: get_page returns source_version, and update_page re-reads the page and REJECTS the save with reason:"page_changed_externally" (naming the element ids it would have deleted) when the live tree moved. When you see that, do NOT pass force:true on your own — either redo the edit with patch_page({ page_id, patches }), which merges into the live tree and can never revert anyone, or call get_page again, re-apply the change to the fresh tree, and save. Only use force:true after the user has explicitly said to discard the newer edits.
18
+ - EDIT existing pages surgically: FIRST settle the ORGANIZATION — pages are scoped per organization and a page inside an org is 'Page not found' without it. Call list_organizations (ask the user which one when the account has 2+), then pass organization_id (an id, or 'personal') to EVERY page tool: list_pages, find_pages, get_page, update_page, add_section, patch_page (page_id mode), publish_page. With 2+ orgs and none chosen they return ok:false reason:'organization_required' + the list; one org is auto-selected; get_page remembers the page's own org for later calls on that page_id. Then: 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. CONCURRENCY — the user may be editing the SAME page in the Webcake editor while you work: update_page replaces the whole stored tree, so a source read a while ago (or a cached draft_id, which can be hours old) would silently revert their changes. The server now checks this for you: get_page returns source_version, and update_page re-reads the page and REJECTS the save with reason:"page_changed_externally" (naming the element ids it would have deleted) when the live tree moved. When you see that, do NOT pass force:true on your own — either redo the edit with patch_page({ page_id, patches }), which merges into the live tree and can never revert anyone, or call get_page again, re-apply the change to the fresh tree, and save. Only use force:true after the user has explicitly said to discard the newer edits.
19
19
  - FIX-AFTER-ERROR / RETRY-AFTER-TIMEOUT (don't rebuild — this is the #1 time-waster): every mutating tool (create_page, update_page, add_section, patch_page) writes the payload to a draft cache BEFORE the network call and returns a draft_id. On validation failure, timeout, or any network error, the draft is kept — retry or fix without re-sending the full JSON:
20
20
  · create_page failed validation OR timed out → its error returns a draft_id (full source cached). Call patch_page({ draft_id, patches:[…], dry_run:false }) to fix ONLY the listed elements, or retry create_page({ draft_id, dry_run:false }) as-is after a timeout.
21
21
  · add_section failed validation, timed out, or returned dry_run=true → response returns a draft_id (section batch cached). Call patch_page({ draft_id, patches:[…], dry_run:false }) to fix elements and append, or retry patch_page({ draft_id, dry_run:false }) (no patches) to commit as-is.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Organization scope for the page tools (list/find/get/update/add_section/patch/publish).
3
+ *
4
+ * The backend scopes pages by the `x-org-id` header, so a page that lives in an
5
+ * organization is "Page not found" when asked for without it. Every page tool
6
+ * therefore settles the org up front, with the same policy as create_page /
7
+ * upload_images:
8
+ * 1. explicit `organization_id` ('personal' = send no x-org-id)
9
+ * 2. the org remembered for this page (from get_page / a previous call)
10
+ * 3. WEBCAKE_ORG_ID / x-webcake-org-id (config.orgId)
11
+ * 4. exactly ONE organization → auto-selected
12
+ * 5. 2+ organizations and none chosen → ok:false reason:"organization_required"
13
+ * No HTTP function needs a new parameter: the resolved org is stamped onto the
14
+ * per-call config (`authHeaders` reads config.orgId).
15
+ */
16
+ import { createHash } from "node:crypto";
17
+ import { listOrganizations } from "./webcake-client.js";
18
+ const ORG_MEMO_TTL_MS = 5 * 60 * 1000;
19
+ const orgMemo = new Map();
20
+ const pageOrg = new Map(); // null = personal
21
+ const MAX_PAGE_ORG = 500;
22
+ const jwtKey = (config) => createHash("sha256").update(`${config.jwt}`).digest("hex").slice(0, 16);
23
+ const pageKey = (config, pageId) => `${config.base}|${jwtKey(config)}|${pageId}`;
24
+ /** list_organizations memoized per (api base, jwt). null = the lookup failed (not memoized for long). */
25
+ async function orgsOf(config) {
26
+ const key = `${config.base}|${jwtKey(config)}`;
27
+ const hit = orgMemo.get(key);
28
+ if (hit && Date.now() - hit.at < ORG_MEMO_TTL_MS)
29
+ return hit.orgs;
30
+ const res = await listOrganizations(config).catch(() => null);
31
+ const orgs = res?.ok && res.organizations ? res.organizations.map((o) => ({ id: o.id, name: o.name, is_default: o.is_default })) : null;
32
+ if (orgs)
33
+ orgMemo.set(key, { at: Date.now(), orgs });
34
+ return orgs;
35
+ }
36
+ /** Remember which org a page lives in (from get_page's organization_id) so later calls need no question. */
37
+ export function rememberPageOrg(config, pageId, organizationId) {
38
+ const org = organizationId == null || `${organizationId}` === "" ? null : `${organizationId}`;
39
+ if (pageOrg.size >= MAX_PAGE_ORG)
40
+ pageOrg.delete(pageOrg.keys().next().value);
41
+ pageOrg.set(pageKey(config, pageId), org);
42
+ }
43
+ /**
44
+ * Resolve the org for a page-tool call. `pageId` lets a page already seen reuse its org.
45
+ * A failed org lookup never blocks: the call proceeds with the config as it is.
46
+ */
47
+ export async function resolveOrgScope(config, organization_id, opts = {}) {
48
+ const withOrg = (org) => ({ ...config, orgId: org });
49
+ if (organization_id != null && `${organization_id}` !== "") {
50
+ if (`${organization_id}`.toLowerCase() === "personal")
51
+ return { ok: true, config: withOrg(undefined), via: "explicit_personal" };
52
+ return { ok: true, config: withOrg(`${organization_id}`), org_id: `${organization_id}`, via: "explicit" };
53
+ }
54
+ if (opts.pageId) {
55
+ const k = pageKey(config, opts.pageId);
56
+ if (pageOrg.has(k)) {
57
+ const org = pageOrg.get(k) ?? undefined;
58
+ return { ok: true, config: withOrg(org), ...(org ? { org_id: org } : {}), via: "page_cache" };
59
+ }
60
+ }
61
+ if (config.orgId != null && `${config.orgId}` !== "")
62
+ return { ok: true, config, org_id: `${config.orgId}`, via: "env" };
63
+ const orgs = await orgsOf(config);
64
+ if (!orgs || orgs.length === 0)
65
+ return { ok: true, config, via: "none" };
66
+ if (orgs.length === 1)
67
+ return { ok: true, config: withOrg(`${orgs[0].id}`), org_id: `${orgs[0].id}`, via: "auto", auto_selected: true };
68
+ return {
69
+ ok: false,
70
+ response: {
71
+ ok: false,
72
+ reason: "organization_required",
73
+ organizations: orgs.map((o) => ({ id: o.id, name: o.name, is_default: o.is_default })),
74
+ error: "This account has multiple organizations and pages are scoped per organization. Re-call with organization_id set to one of the listed ids (or 'personal' for pages outside any organization).",
75
+ hint: `Ask the user which organization the page belongs to (list_organizations), then re-call${opts.retryTool ? ` ${opts.retryTool}` : ""} with organization_id.`,
76
+ },
77
+ };
78
+ }
79
+ /** Does this account have 2+ organizations? (memoized) — for the "Page not found" hint. */
80
+ export async function hasMultipleOrgs(config) {
81
+ const orgs = await orgsOf(config);
82
+ return !!orgs && orgs.length > 1;
83
+ }
84
+ /** Extra hint for a not-found read when the org may simply be wrong. */
85
+ export async function notFoundOrgHint(config, status, error) {
86
+ const nf = status === 404 || /not found/i.test(error ?? "");
87
+ if (!nf || !(await hasMultipleOrgs(config)))
88
+ return {};
89
+ return {
90
+ organization_hint: "Page not found — this account has several organizations and pages are scoped per organization. Re-check organization_id (list_organizations; a page in an org is invisible without it, and 'personal' only sees pages outside any org).",
91
+ };
92
+ }
@@ -20,6 +20,7 @@ import { matchAccountDomain, normalizeDomain } from "../persistence/domain-match
20
20
  import { healBrokenResizeUrls } from "../persistence/rehost.js";
21
21
  import { putDraft, getDraft, updateDraft, deleteDraft } from "../persistence/draft-cache.js";
22
22
  import { sourceFingerprint, decideOverwrite, rememberPageVersion, forgetPageVersion, lastKnownPageVersion, sourceCacheKey, cachePageSource, cachedPageSource, cachedPageSourceVersion, dropCachedPageSource, } from "../persistence/page-version.js";
23
+ import { resolveOrgScope, rememberPageOrg, notFoundOrgHint } from "../persistence/org-scope.js";
23
24
  import { locate as locateNode, outline as pageOutline, selectIds, matchProblem, dropStaleMeasure, dropStaleAgainst, moveNode, duplicateNode, refsTo, subtreeIds, } from "../domains/landing/tree.js";
24
25
  /**
25
26
  * What a save learned beyond pass/fail, for the tools that pick their response
@@ -68,6 +69,21 @@ function addedAgainst(prior, after) {
68
69
  export function registerPersistenceTools(server, domain) {
69
70
  // Resolve config from THIS request's headers (remote per-user JWT) first, then env.
70
71
  const cfgFor = (extra) => readConfig(configFromHeaders(extra?.requestInfo?.headers));
72
+ // Organization scope for the page tools: explicit organization_id > org remembered for the page >
73
+ // WEBCAKE_ORG_ID / header > the account's only org > ask (organization_required). See org-scope.ts.
74
+ const orgArg = () => z
75
+ .string()
76
+ .optional()
77
+ .describe("Organization the page(s) belong to: an organization id, or 'personal' (= no organization). Settle it first (list_organizations; ask the user when the account has 2+). When omitted: the org remembered for this page_id (from get_page), else WEBCAKE_ORG_ID / x-webcake-org-id, else the account's only organization, else ok:false reason:'organization_required' with the list.");
78
+ const scopedCfg = async (extra, organization_id, pageId, retryTool) => {
79
+ const r = cfgFor(extra);
80
+ if (!r.config)
81
+ return { config: undefined, missing: r.missing, refusal: undefined };
82
+ const sc = await resolveOrgScope(r.config, organization_id, { pageId, retryTool });
83
+ if (!sc.ok)
84
+ return { config: undefined, missing: r.missing, refusal: sc.response };
85
+ return { config: sc.config, missing: r.missing, refusal: undefined };
86
+ };
71
87
  // ---- live source read (version-validated cache) ---------------------------
72
88
  // Every live read used to download the whole tree, and the concurrency guard
73
89
  // added one more. It cannot be served from a plain cache — a cached answer
@@ -592,8 +608,10 @@ export function registerPersistenceTools(server, domain) {
592
608
  });
593
609
  });
594
610
  // 10) List pages ------------------------------------------------------------
595
- server.tool("list_pages", "Lists the pages owned by the account (id, name, organization_id, updated_at), most-recent first. Needs WEBCAKE_API_BASE + WEBCAKE_JWT.", {}, { title: "List Webcake Pages", readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (_args, extra) => {
596
- const { config, missing } = cfgFor(extra);
611
+ server.tool("list_pages", "Lists the pages owned by the account (id, name, organization_id, updated_at), most-recent first. Pages are scoped per organization: pass organization_id (an id, or 'personal'); with 2+ organizations and none chosen it returns ok:false reason:'organization_required' with the list. Needs WEBCAKE_API_BASE + WEBCAKE_JWT.", { organization_id: orgArg() }, { title: "List Webcake Pages", readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async ({ organization_id }, extra) => {
612
+ const { config, missing, refusal } = await scopedCfg(extra, organization_id, undefined, "list_pages");
613
+ if (refusal)
614
+ return text(refusal);
597
615
  if (!config)
598
616
  return text({ ok: false, reason: "missing_env", missing_env: missing });
599
617
  return text(await listPages(config));
@@ -616,8 +634,11 @@ export function registerPersistenceTools(server, domain) {
616
634
  .describe("Case-insensitive substring of the page's domain (matches custom_domain OR default_domain)."),
617
635
  page_id: z.string().optional().describe("Exact page id — narrows to that single page (useful to confirm it exists/owned)."),
618
636
  limit: z.number().int().positive().max(100).optional().describe("Max results (default 50, capped at 100)."),
619
- }, { title: "Find Webcake Pages", readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async ({ name, domain, page_id, limit }, extra) => {
620
- const { config, missing } = cfgFor(extra);
637
+ organization_id: orgArg(),
638
+ }, { title: "Find Webcake Pages", readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async ({ name, domain, page_id, limit, organization_id }, extra) => {
639
+ const { config, missing, refusal } = await scopedCfg(extra, organization_id, page_id, "find_pages");
640
+ if (refusal)
641
+ return text(refusal);
621
642
  if (!config)
622
643
  return text({ ok: false, reason: "missing_env", missing_env: missing });
623
644
  const res = await searchPages(config, { name, domain, id: page_id, limit });
@@ -654,7 +675,8 @@ export function registerPersistenceTools(server, domain) {
654
675
  .boolean()
655
676
  .optional()
656
677
  .describe("Default TRUE — strip factory-default boilerplate from every element (sparse shape, far fewer tokens). false returns the raw stored tree."),
657
- }, { title: "Get Webcake Page Source", readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async ({ page_id, draft_id, outline, element_id, compact }, extra) => {
678
+ organization_id: orgArg(),
679
+ }, { title: "Get Webcake Page Source", readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async ({ page_id, draft_id, outline, element_id, compact, organization_id }, extra) => {
658
680
  // Outline / one element / a draft: a narrow read of the same tree.
659
681
  const narrow = (src, meta) => {
660
682
  if (typeof src === "string")
@@ -687,12 +709,17 @@ export function registerPersistenceTools(server, domain) {
687
709
  }
688
710
  if (!page_id)
689
711
  return text({ ok: false, reason: "no_target", hint: "Pass page_id (a live page) or draft_id (a cached draft)." });
690
- const { config, missing } = cfgFor(extra);
712
+ const { config, missing, refusal } = await scopedCfg(extra, organization_id, page_id, "get_page");
713
+ if (refusal)
714
+ return text(refusal);
691
715
  if (!config)
692
716
  return text({ ok: false, reason: "missing_env", missing_env: missing });
693
717
  const res = await readLiveSource(config, page_id);
694
718
  if (!res.ok || res.source == null)
695
- return text(res);
719
+ return text({ ...res, ...(await notFoundOrgHint(config, res.status, res.error)) });
720
+ // the page's own org: later update/add_section/patch/publish on it need no question
721
+ if ("organization_id" in res)
722
+ rememberPageOrg(config, page_id, res.organization_id);
696
723
  // Fingerprint what the page holds RIGHT NOW: this read is the baseline a
697
724
  // later update_page is checked against, so an edit made in the Webcake
698
725
  // editor after this point cannot be silently overwritten.
@@ -731,7 +758,8 @@ export function registerPersistenceTools(server, domain) {
731
758
  .optional()
732
759
  .describe("Default false. true saves even when the page changed outside this session, discarding those outside changes."),
733
760
  dry_run: z.boolean().optional().describe("Default TRUE — validate, cache the source as draft_id, and preview without sending. Set false to actually save."),
734
- }, { title: "Update Webcake Page (Overwrite)", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async ({ page_id, source, draft_id, base_version, force, dry_run }, extra) => {
761
+ organization_id: orgArg(),
762
+ }, { title: "Update Webcake Page (Overwrite)", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async ({ page_id, source, draft_id, base_version, force, dry_run, organization_id }, extra) => {
735
763
  const isDry = dry_run !== false;
736
764
  // --- Resolve source: from cache (draft_id) or from the argument ---
737
765
  let expanded;
@@ -777,7 +805,10 @@ export function registerPersistenceTools(server, domain) {
777
805
  }
778
806
  // The live page as it is now (version-validated cache): a text whose content changed against it
779
807
  // loses its stale measured height, and only errors this overwrite ADDS refuse it.
780
- const cfg0 = cfgFor(extra).config;
808
+ const sc0 = await scopedCfg(extra, organization_id, resolvedPageId, "update_page");
809
+ if (sc0.refusal)
810
+ return text({ updated: false, ...sc0.refusal });
811
+ const cfg0 = sc0.config;
781
812
  // no explicit base: the version of the tree get_page last handed the model
782
813
  if (!resolvedBaseVersion && cfg0 && !draft_id)
783
814
  resolvedBaseVersion = servedOf(cfg0, resolvedPageId);
@@ -816,7 +847,8 @@ export function registerPersistenceTools(server, domain) {
816
847
  });
817
848
  }
818
849
  const parsed = domain.coerce(expanded);
819
- const { config, missing } = cfgFor(extra);
850
+ const config = cfg0;
851
+ const missing = sc0.missing;
820
852
  if (isDry) {
821
853
  // Cache (or refresh) the validated source so the model can confirm with
822
854
  // dry_run=false without re-sending the full payload.
@@ -937,7 +969,8 @@ export function registerPersistenceTools(server, domain) {
937
969
  .boolean()
938
970
  .optional()
939
971
  .describe("Default TRUE — validate the section(s) and preview the request without writing. Set false to actually append."),
940
- }, { title: "Append Section(s) to Webcake Page", readOnlyHint: false, destructiveHint: false, openWorldHint: true }, async ({ page_id, sections, draft_id, dry_run }, extra) => {
972
+ organization_id: orgArg(),
973
+ }, { title: "Append Section(s) to Webcake Page", readOnlyHint: false, destructiveHint: false, openWorldHint: true }, async ({ page_id, sections, draft_id, dry_run, organization_id }, extra) => {
941
974
  const isDry = dry_run !== false; // default true (safe)
942
975
  // --- Resolve section payload: from cache (draft_id) or from the argument ---
943
976
  let expandedShell;
@@ -1013,7 +1046,9 @@ export function registerPersistenceTools(server, domain) {
1013
1046
  hint: "Do NOT rebuild the section batch — it is cached as draft_id. Each error names the offending element id — fix ONLY those elements with patch_page({ draft_id, patches:[…], dry_run:false }); it re-validates the merged shell and appends the sections. A wrong element type → { op:'update', id:'<element id>', type:'<allowed type>' }. A stray/extra key ('must NOT have additional properties') → { op:'replace', id, element:<clean node> } — op:'update' MERGES and cannot delete a key. The draft expires in ~2 h.",
1014
1047
  });
1015
1048
  }
1016
- const { config, missing } = cfgFor(extra);
1049
+ const { config, missing, refusal } = await scopedCfg(extra, organization_id, page_id, "add_section");
1050
+ if (refusal)
1051
+ return text({ added: false, ...refusal });
1017
1052
  if (!config) {
1018
1053
  return text({
1019
1054
  added: false,
@@ -1217,7 +1252,7 @@ export function registerPersistenceTools(server, domain) {
1217
1252
  };
1218
1253
  // patch_page body. `fresh`: the retry after the backend refused a write made against a cached
1219
1254
  // tree (page_changed) — re-read the live page and apply the same ops to it, once.
1220
- const runPatch = async ({ page_id, draft_id, patches, force, dry_run }, extra, fresh = false) => {
1255
+ const runPatch = async ({ page_id, draft_id, patches, force, dry_run, organization_id }, extra, fresh = false) => {
1221
1256
  const isDry = dry_run !== false; // default true (safe)
1222
1257
  const ops = asArray(patches).filter((p) => p != null && typeof p === "object");
1223
1258
  // Empty ops are only valid when a draft_id is supplied (commit-as-is / retry path).
@@ -1228,7 +1263,14 @@ export function registerPersistenceTools(server, domain) {
1228
1263
  if (!page_id && !draft_id) {
1229
1264
  return text({ patched: false, reason: "no_target", hint: "Pass page_id (a live page) or draft_id (the cached source from a failed/timed-out create_page, update_page, or add_section)." });
1230
1265
  }
1231
- const { config, missing } = cfgFor(extra);
1266
+ // A live page (page_id, or an update/section draft that targets one) is scoped by organization;
1267
+ // a create draft is not — createPage resolves its own org.
1268
+ const draftPre = draft_id ? await getDraft(draft_id) : null;
1269
+ const scopePid = page_id ?? (draftPre && draftPre.kind !== "page" ? draftPre.page_id : undefined);
1270
+ const scoped = scopePid ? await scopedCfg(extra, organization_id, scopePid, "patch_page") : { ...cfgFor(extra), refusal: undefined };
1271
+ if (scoped.refusal)
1272
+ return text({ patched: false, ...scoped.refusal });
1273
+ const { config, missing } = scoped;
1232
1274
  // Resolve the base source: a cached draft (create-before-save), else a live page.
1233
1275
  let base;
1234
1276
  let liveRead; // the live read a page_id patch merges into (its version guards the save)
@@ -1263,6 +1305,7 @@ export function registerPersistenceTools(server, domain) {
1263
1305
  status: current.status,
1264
1306
  error: current.error ?? "Page source not found.",
1265
1307
  hint: "Check the page_id (find_pages/list_pages) and that the account owns it.",
1308
+ ...(await notFoundOrgHint(config, current.status, current.error)),
1266
1309
  });
1267
1310
  }
1268
1311
  // This read is by definition current, so it becomes the baseline: a later
@@ -1683,7 +1726,7 @@ export function registerPersistenceTools(server, domain) {
1683
1726
  await deleteDraft(liveDraftId);
1684
1727
  invalidateSource(config, page_id);
1685
1728
  if (!fresh)
1686
- return runPatch({ page_id, draft_id, patches, force, dry_run }, extra, true);
1729
+ return runPatch({ page_id, draft_id, patches, force, dry_run, organization_id }, extra, true);
1687
1730
  return text({ patched: false, ...pageChangedPayload(page_id, outcome, "patch_page"), hint: "The page was saved by someone else between this patch's read and its write — nothing was written. Re-run the SAME patch_page call: it re-reads the live page and applies your ops to it." });
1688
1731
  }
1689
1732
  if (outcome.ok) {
@@ -1729,6 +1772,7 @@ export function registerPersistenceTools(server, domain) {
1729
1772
  .boolean()
1730
1773
  .optional()
1731
1774
  .describe("Default TRUE — load, merge, validate and preview the resulting save WITHOUT writing. Set false to actually save."),
1775
+ organization_id: orgArg(),
1732
1776
  }, { title: "Patch Webcake Page (by element id)", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async (args, extra) => runPatch(args, extra));
1733
1777
  // 15) Publish page (go live) -------------------------------------------------
1734
1778
  server.tool("publish_page", "Publishes an existing page: builds the rendered app on the Webcake build host (POST <buildBase>/render/build; https://build.webcake.io in production, overridable with WEBCAKE_BUILD_BASE / x-webcake-build-base) and then creates or updates the published record that public serving reads. With custom_domain (already pointed at Webcake) the page is served at that domain; when omitted, the page's currently attached domain is reused; with no domain, or custom_domain:'', only the preview link (<previewBase>/preview/<page_id>) is returned, and it renders for about 10 minutes after the publish. Without a build host, or if the build fails, it falls back to a source-only publish that saves a version but serves nothing, and returns a warning. dry_run defaults to true and makes no network calls; dry_run:false builds and publishes. Requires Webcake credentials.", {
@@ -1739,9 +1783,12 @@ export function registerPersistenceTools(server, domain) {
1739
1783
  .describe("Optional custom domain to serve the page at (e.g. 'shop.example.com' — must already point at Webcake). Use it EXACTLY as the account lists it: 'www.example.com' and 'example.com' are DIFFERENT domain records — a www/non-www mismatch is corrected to the stored form, and a domain the account never added is refused (nothing published). OMIT to reuse the page's CURRENTLY-ATTACHED domain (so republishing keeps it live at the same URL, like the editor's publish modal); if the page has none it publishes domain-less (preview-host URL). Pass an empty string '' to force a domain-less publish even when the page has a domain."),
1740
1784
  custom_path: z.string().optional().describe("Optional path under the custom domain (e.g. 'sale')."),
1741
1785
  dry_run: z.boolean().optional().describe("Default TRUE — preview the request without sending. Does NOT call the build host. Set false to actually publish (build + publish)."),
1742
- }, { title: "Publish Webcake Page", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async ({ page_id, custom_domain, custom_path, dry_run }, extra) => {
1786
+ organization_id: orgArg(),
1787
+ }, { title: "Publish Webcake Page", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async ({ page_id, custom_domain, custom_path, dry_run, organization_id }, extra) => {
1743
1788
  const isDry = dry_run !== false; // default true (safe)
1744
- const { config, missing } = cfgFor(extra);
1789
+ const { config, missing, refusal } = await scopedCfg(extra, organization_id, page_id, "publish_page");
1790
+ if (refusal)
1791
+ return text({ published: false, ...refusal });
1745
1792
  if (!config)
1746
1793
  return text({ published: false, reason: "missing_env", missing_env: missing });
1747
1794
  // Publish re-saves the page's CURRENT stored source (the publish endpoint
@@ -1749,7 +1796,7 @@ export function registerPersistenceTools(server, domain) {
1749
1796
  // the real payload.
1750
1797
  const res = await readLiveSource(config, page_id);
1751
1798
  if (!res.ok || res.source == null) {
1752
- return text({ published: false, reason: "page_not_found", status: res.status, error: res.error ?? "No source on this page." });
1799
+ return text({ published: false, reason: "page_not_found", status: res.status, error: res.error ?? "No source on this page.", ...(await notFoundOrgHint(config, res.status, res.error)) });
1753
1800
  }
1754
1801
  // An editor publish may have stored a 404 `sNaN` thumbnail/favicon — don't republish it (#5).
1755
1802
  const source = healBrokenResizeUrls(res.source);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcake-landing-mcp",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
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",