@umbraco-cms/mcp-editor 18.0.0-beta.10 → 18.0.0-beta.11

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
@@ -6,7 +6,7 @@ MCP server template for Umbraco add-ons using the @umbraco-cms/mcp-server-sdk.
6
6
 
7
7
  ### System Prerequisites
8
8
 
9
- - **Node.js 22+** is required. Check your version with `node --version`.
9
+ - **Node.js 22.23.4+, 24.22.1+ or 26.12.1+** is required. Check your version with `node --version`. Earlier releases are affected by [CVE-2026-111497](https://nodejs.org/en/blog/vulnerability/october-2026-security-releases) (Brotli decoder out-of-bounds write), which Node's built-in `fetch` reaches when it decompresses a Brotli response from Umbraco. Upgrading Node.js is the only fix.
10
10
 
11
11
  ### 1. Install Dependencies
12
12
 
@@ -1,11 +1,12 @@
1
1
  import { z } from 'zod';
2
- import { createMcpClientManager, withStandardDecorators, baseSliceNames, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor } from '@umbraco-cms/mcp-server-sdk';
2
+ import { createMcpClientManager, withStandardDecorators, baseSliceNames, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, isLoopbackUrl } from '@umbraco-cms/mcp-server-sdk';
3
3
  import { statSync, readFileSync } from 'fs';
4
4
  import { resolve } from 'path';
5
5
 
6
6
  // src/umbraco-api/tools/content/get/search-content.ts
7
-
8
- // src/config/mcp-servers.ts
7
+ function chainedTlsEnv(baseUrl) {
8
+ return isLoopbackUrl(baseUrl) ? { NODE_TLS_REJECT_UNAUTHORIZED: "0" } : {};
9
+ }
9
10
  async function buildServers() {
10
11
  if (typeof process === "undefined" || !process.env) return [];
11
12
  const useMockChain = process.env.USE_MOCK_MCP_CHAIN === "true";
@@ -29,13 +30,14 @@ async function buildServers() {
29
30
  const binEntry = typeof cmsDevPkg.bin === "string" ? cmsDevPkg.bin : cmsDevPkg.bin ? Object.values(cmsDevPkg.bin)[0] : void 0;
30
31
  if (!binEntry) throw new Error("@umbraco-cms/mcp-dev has no bin entry");
31
32
  const binAbs = path.resolve(path.dirname(pkgPath), binEntry);
33
+ const baseUrl = process.env.UMBRACO_BASE_URL || "http://localhost:44391";
32
34
  return [{
33
35
  name: "cms",
34
36
  command: process.execPath,
35
37
  args: [binAbs],
36
38
  env: {
37
- NODE_TLS_REJECT_UNAUTHORIZED: "0",
38
- UMBRACO_BASE_URL: process.env.UMBRACO_BASE_URL || "http://localhost:44391",
39
+ ...chainedTlsEnv(baseUrl),
40
+ UMBRACO_BASE_URL: baseUrl,
39
41
  UMBRACO_CLIENT_ID: process.env.UMBRACO_CLIENT_ID || "",
40
42
  UMBRACO_CLIENT_SECRET: process.env.UMBRACO_CLIENT_SECRET || "",
41
43
  // Clear tool filters so our editor tool names (search-content etc.) don't
@@ -640,10 +642,15 @@ var tool4 = {
640
642
  var list_document_types_default = withStandardDecorators(tool4);
641
643
 
642
644
  // src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
643
- async function resolveDocumentTypeProperties(documentTypeId) {
644
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
645
- if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
646
- const data = docTypeResult.data;
645
+ async function resolveDocumentTypeProperties(documentTypeId, documentType) {
646
+ let data;
647
+ if (documentType) {
648
+ data = documentType;
649
+ } else {
650
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
651
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
652
+ data = docTypeResult.data;
653
+ }
647
654
  const collected = /* @__PURE__ */ new Map();
648
655
  function addProperties(props) {
649
656
  for (const p of props) {
@@ -1448,11 +1455,11 @@ ${JSON.stringify(schemaResult.data, null, 2)}`,
1448
1455
  }
1449
1456
  };
1450
1457
  var get_property_value_template_default = withStandardDecorators(tool10);
1451
- async function resolveEditorAliases(documentTypeId, values) {
1458
+ async function resolveEditorAliases(documentTypeId, values, { defaultCulture = null, documentType, siteCultures } = {}) {
1452
1459
  if (!values || values.length === 0) {
1453
1460
  return { ok: true, values: [] };
1454
1461
  }
1455
- const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
1462
+ const docTypeResult = await resolveDocumentTypeProperties(documentTypeId, documentType);
1456
1463
  if (!docTypeResult.ok) return docTypeResult;
1457
1464
  const dataTypeIds = Array.from(
1458
1465
  new Set(
@@ -1471,22 +1478,32 @@ async function resolveEditorAliases(documentTypeId, values) {
1471
1478
  docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
1472
1479
  );
1473
1480
  const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1481
+ const cultureVariantAliases = /* @__PURE__ */ new Set();
1474
1482
  for (const prop of docTypeResult.properties) {
1475
1483
  const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
1476
1484
  if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1485
+ if (prop.alias && prop.variesByCulture) cultureVariantAliases.add(prop.alias);
1477
1486
  }
1478
1487
  const notAProperty = /* @__PURE__ */ new Set();
1479
1488
  const missingEditorAlias = /* @__PURE__ */ new Set();
1489
+ const unknownCultures = /* @__PURE__ */ new Set();
1480
1490
  const resolved = values.map((v) => {
1481
1491
  const editorAlias = editorAliasByPropertyAlias.get(v.alias);
1482
1492
  if (!editorAlias) {
1483
1493
  if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
1484
1494
  else notAProperty.add(v.alias);
1485
1495
  }
1496
+ let culture = v.culture ?? (cultureVariantAliases.has(v.alias) ? defaultCulture : null);
1497
+ if (v.culture && siteCultures) {
1498
+ const requested = v.culture.toLowerCase();
1499
+ const match = siteCultures.find((c) => c.toLowerCase() === requested);
1500
+ if (match) culture = match;
1501
+ else unknownCultures.add(v.culture);
1502
+ }
1486
1503
  return {
1487
1504
  alias: v.alias,
1488
1505
  value: v.value,
1489
- culture: v.culture ?? null,
1506
+ culture,
1490
1507
  segment: v.segment ?? null,
1491
1508
  editorAlias: editorAlias ?? ""
1492
1509
  };
@@ -1517,14 +1534,74 @@ async function resolveEditorAliases(documentTypeId, values) {
1517
1534
  )
1518
1535
  };
1519
1536
  }
1537
+ if (unknownCultures.size > 0 && siteCultures) {
1538
+ return {
1539
+ ok: false,
1540
+ errorResult: createToolResultError(
1541
+ `The following value culture(s) are not languages on this site: ${Array.from(unknownCultures).join(", ")}. Available cultures: ${siteCultures.join(", ")}.`
1542
+ )
1543
+ };
1544
+ }
1520
1545
  return { ok: true, values: resolved };
1521
1546
  }
1547
+ var LANGUAGE_PAGE_SIZE = 100;
1548
+ async function resolvePageCulture(documentTypeId, culture, { forPublish = false } = {}) {
1549
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1550
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
1551
+ const documentType = docTypeResult.data;
1552
+ if (!documentType.variesByCulture) {
1553
+ return { ok: true, culture: null, documentType };
1554
+ }
1555
+ const langResult = await chainCms("get-language", { cursor: encodeCursor({ s: 0, t: LANGUAGE_PAGE_SIZE }) });
1556
+ if (!langResult.ok) return { ok: false, errorResult: langResult.errorResult };
1557
+ const languages = langResult.data.items ?? [];
1558
+ const complete = (langResult.data.total ?? languages.length) <= languages.length;
1559
+ const siteCultures = languages.map((l) => l.isoCode);
1560
+ let pageCulture;
1561
+ if (culture) {
1562
+ const match = siteCultures.find((c) => c.toLowerCase() === culture.toLowerCase());
1563
+ if (!match && complete) {
1564
+ return {
1565
+ ok: false,
1566
+ errorResult: createToolResultError(
1567
+ `Culture "${culture}" is not a language on this site. Available cultures: ${siteCultures.join(", ")}.`
1568
+ )
1569
+ };
1570
+ }
1571
+ pageCulture = match ?? culture;
1572
+ } else {
1573
+ const defaultLanguage = languages.find((l) => l.isDefault);
1574
+ if (!defaultLanguage?.isoCode) {
1575
+ return {
1576
+ ok: false,
1577
+ errorResult: createToolResultError(
1578
+ "This document type varies by culture, but no default language could be determined. Call list-languages and pass `culture` explicitly."
1579
+ )
1580
+ };
1581
+ }
1582
+ pageCulture = defaultLanguage.isoCode;
1583
+ }
1584
+ if (forPublish) {
1585
+ const missingMandatory = languages.filter((l) => l.isMandatory && l.isoCode !== pageCulture).map((l) => l.isoCode);
1586
+ if (missingMandatory.length > 0) {
1587
+ const one = missingMandatory.length === 1;
1588
+ return {
1589
+ ok: false,
1590
+ errorResult: createToolResultError(
1591
+ `Cannot create and publish this page in ${pageCulture} alone: ${missingMandatory.join(", ")} ${one ? "is a mandatory language" : "are mandatory languages"} on this site, and a page can only be published once it exists in every mandatory language. Nothing was created. ${one ? `Either pass culture "${missingMandatory[0]}", or use` : "Use"} create-page, add the other language(s) with create-variant, then publish.`
1592
+ )
1593
+ };
1594
+ }
1595
+ }
1596
+ return { ok: true, culture: pageCulture, documentType, siteCultures: complete ? siteCultures : void 0 };
1597
+ }
1522
1598
 
1523
1599
  // src/umbraco-api/tools/content/post/create-page.ts
1524
1600
  var inputSchema11 = {
1525
1601
  name: z.string().describe("The name of the page to create"),
1526
1602
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1527
1603
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1604
+ culture: z.string().optional().describe("Culture (ISO code, e.g. en-US) to create the page in. Only used when the document type varies by culture; defaults to the site's default language. Call list-languages for the available cultures. Add further languages afterwards with create-variant or copy-variant."),
1528
1605
  values: z.array(z.object({
1529
1606
  alias: z.string().describe("The property alias"),
1530
1607
  value: z.any().describe("The property value"),
@@ -1536,23 +1613,28 @@ var outputSchema11 = z.object({
1536
1613
  message: z.string(),
1537
1614
  id: z.string(),
1538
1615
  name: z.string(),
1616
+ culture: z.string().nullable().describe("The culture the page was created in \u2014 the requested `culture`, or the site's default language when none was given. Null when the document type does not vary by culture."),
1539
1617
  previewUrl: previewUrlSchema,
1540
1618
  validation: validationResultSchema
1541
1619
  });
1542
1620
  var tool11 = {
1543
1621
  name: "create-page",
1544
- description: "Create a new content page as a draft \u2014 the page will NOT be published automatically. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values (strings, numbers, booleans). For everything else, follow up with the dedicated tools after creation \u2014 they're shorter, safer, and avoid the JSON-payload errors that come from cramming a full page into one call: edit-page for property updates, add-blocklist-block / add-blockgrid-block / add-rte-block for block content, edit-block for block-property edits, and get-property-value-template for the value shape of structured non-block editors (media pickers, image cropper, etc.).",
1622
+ description: "Create a new content page as a draft \u2014 the page will NOT be published automatically. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values (strings, numbers, booleans). For everything else, follow up with the dedicated tools after creation \u2014 they're shorter, safer, and avoid the JSON-payload errors that come from cramming a full page into one call: edit-page for property updates, add-blocklist-block / add-blockgrid-block / add-rte-block for block content, edit-block for block-property edits, and get-property-value-template for the value shape of structured non-block editors (media pickers, image cropper, etc.). On a multilingual site, a document type that varies by culture is created in `culture` (default: the site's default language); values without a culture on culture-variant properties are stored in that culture too.",
1545
1623
  inputSchema: inputSchema11,
1546
1624
  outputSchema: outputSchema11,
1547
1625
  slices: ["create"],
1548
1626
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1549
- handler: async ({ name, documentTypeId, parentId, values }) => {
1550
- const resolved = await resolveEditorAliases(documentTypeId, values);
1627
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1628
+ const cultureResult = await resolvePageCulture(documentTypeId, culture);
1629
+ if (!cultureResult.ok) return cultureResult.errorResult;
1630
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1631
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1551
1632
  if (!resolved.ok) return resolved.errorResult;
1552
1633
  const createResult = await chainCms("create-document", {
1553
1634
  documentTypeId,
1554
1635
  name,
1555
1636
  values: resolved.values,
1637
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1556
1638
  ...parentId ? { parentId } : {}
1557
1639
  });
1558
1640
  if (!createResult.ok) return createResult.errorResult;
@@ -1564,6 +1646,7 @@ var tool11 = {
1564
1646
  message,
1565
1647
  id: createdId,
1566
1648
  name,
1649
+ culture: pageCulture,
1567
1650
  previewUrl: createdId ? await fetchPreviewUrl(createdId) : null,
1568
1651
  validation
1569
1652
  });
@@ -1574,6 +1657,7 @@ var inputSchema12 = {
1574
1657
  name: z.string().describe("The name of the page to create"),
1575
1658
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1576
1659
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1660
+ culture: z.string().optional().describe("Culture (ISO code, e.g. en-US) to create the page in. Only used when the document type varies by culture; defaults to the site's default language. Call list-languages for the available cultures. Add further languages afterwards with create-variant or copy-variant."),
1577
1661
  values: z.array(z.object({
1578
1662
  alias: z.string().describe("The property alias"),
1579
1663
  value: z.any().describe("The property value"),
@@ -1585,22 +1669,27 @@ var outputSchema12 = z.object({
1585
1669
  message: z.string(),
1586
1670
  id: z.string(),
1587
1671
  name: z.string(),
1672
+ culture: z.string().nullable().describe("The culture the page was created in \u2014 the requested `culture`, or the site's default language when none was given. Null when the document type does not vary by culture."),
1588
1673
  publishedUrls: publishedUrlsSchema
1589
1674
  });
1590
1675
  var tool12 = {
1591
1676
  name: "create-and-publish-page",
1592
- description: "Create a new content page and publish it in one atomic operation \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values. If the document type requires properties this doesn't set, or if the values fail validation, the whole operation fails and no page is created \u2014 use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing.",
1677
+ description: "Create a new content page and publish it in one atomic operation \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values. If the document type requires properties this doesn't set, or if the values fail validation, the whole operation fails and no page is created \u2014 use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing. On a multilingual site, a document type that varies by culture is created in `culture` (default: the site's default language); values without a culture on culture-variant properties are stored in that culture too. If the site has a mandatory language other than that culture, the page can't be published from a single call \u2014 the tool says so and creates nothing; use create-page, create-variant, then publish instead.",
1593
1678
  inputSchema: inputSchema12,
1594
1679
  outputSchema: outputSchema12,
1595
1680
  slices: ["create", "publish"],
1596
1681
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1597
- handler: async ({ name, documentTypeId, parentId, values }) => {
1598
- const resolved = await resolveEditorAliases(documentTypeId, values);
1682
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1683
+ const cultureResult = await resolvePageCulture(documentTypeId, culture, { forPublish: true });
1684
+ if (!cultureResult.ok) return cultureResult.errorResult;
1685
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1686
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1599
1687
  if (!resolved.ok) return resolved.errorResult;
1600
1688
  const createResult = await chainCms("create-and-publish-document", {
1601
1689
  documentTypeId,
1602
1690
  name,
1603
1691
  values: resolved.values,
1692
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1604
1693
  ...parentId ? { parentId } : {}
1605
1694
  });
1606
1695
  if (!createResult.ok) return createResult.errorResult;
@@ -1609,6 +1698,7 @@ var tool12 = {
1609
1698
  message: `Created and published "${name}"`,
1610
1699
  id: createdId,
1611
1700
  name,
1701
+ culture: pageCulture,
1612
1702
  publishedUrls: createdId ? await fetchPublishedUrls(createdId) : []
1613
1703
  });
1614
1704
  }
@@ -2481,6 +2571,48 @@ async function verifyDocumentPublished(id, expectedCultures) {
2481
2571
  return `publish call returned success but ${failures.length === 1 ? "this culture is" : "these cultures are"} still in draft: ${failures.join(", ")}`;
2482
2572
  }
2483
2573
 
2574
+ // src/umbraco-api/tools/helpers/publish-with-descendants.ts
2575
+ var FOLLOWUP_MAX_ATTEMPTS = 30;
2576
+ var FOLLOWUP_POLL_INTERVAL_MS = 2e3;
2577
+ function parsePublishWithDescendantsStatus(data) {
2578
+ if (data !== null && typeof data === "object" && data.status === "in-progress" && typeof data.taskId === "string") {
2579
+ return { complete: false, taskId: data.taskId };
2580
+ }
2581
+ if (data !== "") {
2582
+ console.warn(
2583
+ `publish-document-with-descendants returned an unrecognized success payload (neither "" nor an in-progress marker) \u2014 treating as complete: ${JSON.stringify(data)}`
2584
+ );
2585
+ }
2586
+ return { complete: true };
2587
+ }
2588
+ function isRequestTimeout(error) {
2589
+ const detail = extractInnerProblemDetails(error.errorResult).detail;
2590
+ return typeof detail === "string" && detail.includes("Request timed out");
2591
+ }
2592
+ async function publishWithDescendants(id, data, options) {
2593
+ const initial = await chainCms("publish-document-with-descendants", { id, data });
2594
+ if (!initial.ok) {
2595
+ if (isRequestTimeout(initial)) return { ok: true, complete: false };
2596
+ return initial;
2597
+ }
2598
+ const status = parsePublishWithDescendantsStatus(initial.data);
2599
+ if (status.complete) return { ok: true, complete: true };
2600
+ if (options?.followUp === false) return { ok: true, complete: false };
2601
+ for (let attempt = 0; attempt < FOLLOWUP_MAX_ATTEMPTS; attempt++) {
2602
+ await new Promise((resolve2) => setTimeout(resolve2, FOLLOWUP_POLL_INTERVAL_MS));
2603
+ const poll = await chainCms("get-document-publish-with-descendants-result", {
2604
+ id,
2605
+ taskId: status.taskId
2606
+ });
2607
+ if (!poll.ok) {
2608
+ if (isRequestTimeout(poll)) return { ok: true, complete: false };
2609
+ return poll;
2610
+ }
2611
+ if (poll.data.isComplete) return { ok: true, complete: true };
2612
+ }
2613
+ return { ok: true, complete: false };
2614
+ }
2615
+
2484
2616
  // src/umbraco-api/tools/publishing/post/publish-page.ts
2485
2617
  var inputSchema25 = {
2486
2618
  id: z.string().uuid().describe("The ID of the page to publish"),
@@ -2498,7 +2630,12 @@ var tool25 = {
2498
2630
  inputSchema: inputSchema25,
2499
2631
  outputSchema: outputSchema25,
2500
2632
  slices: ["publish"],
2501
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
2633
+ // includeDescendants delegates to publish-document-with-descendants, which
2634
+ // the chained CMS tool annotates idempotentHint: false — a retry fires a
2635
+ // second concurrent recursive publish job rather than converging to the
2636
+ // same end state. That makes this tool non-idempotent as a whole, since
2637
+ // includeDescendants is a valid input, not a separate tool.
2638
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
2502
2639
  handler: async ({ id, includeDescendants }, extra) => {
2503
2640
  const docResult = await chainCms("get-document-by-id", { id });
2504
2641
  if (!docResult.ok) return docResult.errorResult;
@@ -2510,29 +2647,42 @@ var tool25 = {
2510
2647
  }
2511
2648
  }
2512
2649
  const variantCultures = (doc.variants ?? []).length ? doc.variants.map((v) => v.culture ?? null) : [null];
2513
- const publishResult = includeDescendants ? await chainCms("publish-document-with-descendants", {
2514
- id,
2515
- data: {
2650
+ if (includeDescendants) {
2651
+ const result = await publishWithDescendants(id, {
2516
2652
  includeUnpublishedDescendants: false,
2517
2653
  cultures: variantCultures.filter((c) => c !== null)
2654
+ });
2655
+ if (!result.ok) return result.errorResult;
2656
+ if (!result.complete) {
2657
+ return createToolResult({
2658
+ message: `"${pageName}" and its descendants are a large tree \u2014 publishing is still running in the background. Check again shortly.`,
2659
+ id,
2660
+ name: pageName,
2661
+ publishedUrls: []
2662
+ });
2518
2663
  }
2519
- }) : await chainCms("publish-document", {
2664
+ return createToolResult({
2665
+ message: `Published "${pageName}" and all child pages`,
2666
+ id,
2667
+ name: pageName,
2668
+ publishedUrls: await fetchPublishedUrls(id)
2669
+ });
2670
+ }
2671
+ const publishResult = await chainCms("publish-document", {
2520
2672
  id,
2521
2673
  data: { publishSchedules: variantCultures.map((c) => ({ culture: c })) }
2522
2674
  });
2523
2675
  if (!publishResult.ok) return publishResult.errorResult;
2524
- if (!includeDescendants) {
2525
- const verifyError = await verifyDocumentPublished(id, variantCultures);
2526
- if (verifyError) {
2527
- return createToolResultError({
2528
- status: 500,
2529
- title: "Publish did not take effect",
2530
- detail: `"${pageName}": ${verifyError}`
2531
- });
2532
- }
2676
+ const verifyError = await verifyDocumentPublished(id, variantCultures);
2677
+ if (verifyError) {
2678
+ return createToolResultError({
2679
+ status: 500,
2680
+ title: "Publish did not take effect",
2681
+ detail: `"${pageName}": ${verifyError}`
2682
+ });
2533
2683
  }
2534
2684
  return createToolResult({
2535
- message: includeDescendants ? `Published "${pageName}" and all child pages` : `Published "${pageName}"`,
2685
+ message: `Published "${pageName}"`,
2536
2686
  id,
2537
2687
  name: pageName,
2538
2688
  publishedUrls: await fetchPublishedUrls(id)
@@ -2662,12 +2812,9 @@ var tool27 = {
2662
2812
  if (!updateResult.ok) return updateResult.errorResult;
2663
2813
  saved = true;
2664
2814
  }
2665
- const publishResult = await chainCms("publish-document-with-descendants", {
2666
- id,
2667
- data: {
2668
- includeUnpublishedDescendants: false,
2669
- cultures: variantCultures.filter((c) => c !== null)
2670
- }
2815
+ const publishResult = await publishWithDescendants(id, {
2816
+ includeUnpublishedDescendants: false,
2817
+ cultures: variantCultures.filter((c) => c !== null)
2671
2818
  });
2672
2819
  if (!publishResult.ok) {
2673
2820
  if (saved) {
@@ -2683,6 +2830,18 @@ var tool27 = {
2683
2830
  }
2684
2831
  return publishResult.errorResult;
2685
2832
  }
2833
+ if (!publishResult.complete) {
2834
+ const savedPrefix = saved ? `Saved ${fieldNames.length} field(s) on "${pageName}". ` : "";
2835
+ return createToolResult({
2836
+ message: `${savedPrefix}"${pageName}" and its descendants are a large tree \u2014 publishing is still running in the background. Check again shortly.`,
2837
+ id,
2838
+ name: pageName,
2839
+ saved,
2840
+ published: false,
2841
+ updatedFields: fieldNames,
2842
+ publishedUrls: []
2843
+ });
2844
+ }
2686
2845
  const savedPart2 = saved ? `Saved ${fieldNames.length} field(s) and ` : "";
2687
2846
  return createToolResult({
2688
2847
  message: `${savedPart2}published "${pageName}" and all descendants`,
@@ -5526,7 +5685,8 @@ var outputSchema80 = z.object({
5526
5685
  success: z.boolean(),
5527
5686
  previousVersionId: z.string().optional(),
5528
5687
  error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
5529
- publishedUrls: publishedUrlsSchema.optional()
5688
+ publishedUrls: publishedUrlsSchema.optional(),
5689
+ publishPending: z.boolean().optional().describe("True when includeDescendants was requested and the CMS couldn't confirm the tree finished publishing in time \u2014 the operation is still running, not failed.")
5530
5690
  })),
5531
5691
  successCount: z.number(),
5532
5692
  failureCount: z.number(),
@@ -5538,7 +5698,12 @@ var tool80 = {
5538
5698
  inputSchema: inputSchema80,
5539
5699
  outputSchema: outputSchema80,
5540
5700
  slices: ["publish"],
5541
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
5701
+ // includeDescendants delegates to publish-document-with-descendants, which
5702
+ // the chained CMS tool annotates idempotentHint: false — a retry fires a
5703
+ // second concurrent recursive publish job rather than converging to the
5704
+ // same end state. That makes this tool non-idempotent as a whole, since
5705
+ // includeDescendants is a valid input, not a separate tool.
5706
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
5542
5707
  handler: async ({ ids, includeDescendants }, extra) => {
5543
5708
  const validationError = validateBulkIds(ids);
5544
5709
  if (validationError) return createToolResult(validationError);
@@ -5564,15 +5729,20 @@ ${nameList}`;
5564
5729
  skippedCount: 0
5565
5730
  });
5566
5731
  }
5732
+ const stillPublishing = /* @__PURE__ */ new Set();
5567
5733
  const results = await executeBulkSequentially(items, async (item) => {
5568
5734
  const cultures = item.cultures ?? [null];
5569
- const result = includeDescendants ? await chainCms("publish-document-with-descendants", {
5570
- id: item.id,
5571
- data: {
5572
- includeUnpublishedDescendants: false,
5573
- cultures: cultures.filter((c) => c !== null)
5574
- }
5575
- }) : await chainCms("publish-document", {
5735
+ if (includeDescendants) {
5736
+ const result2 = await publishWithDescendants(
5737
+ item.id,
5738
+ { includeUnpublishedDescendants: false, cultures: cultures.filter((c) => c !== null) },
5739
+ { followUp: false }
5740
+ );
5741
+ if (!result2.ok) return result2.errorResult;
5742
+ if (!result2.complete) stillPublishing.add(item.id);
5743
+ return null;
5744
+ }
5745
+ const result = await chainCms("publish-document", {
5576
5746
  id: item.id,
5577
5747
  data: { publishSchedules: cultures.map((c) => ({ culture: c })) }
5578
5748
  });
@@ -5583,9 +5753,18 @@ ${nameList}`;
5583
5753
  });
5584
5754
  for (const row of results) {
5585
5755
  if (!row.success) continue;
5756
+ if (stillPublishing.has(row.id)) {
5757
+ row.publishPending = true;
5758
+ continue;
5759
+ }
5586
5760
  row.publishedUrls = await fetchPublishedUrls(row.id);
5587
5761
  }
5588
- return createToolResult(buildBulkOutput("Published", results));
5762
+ const output = buildBulkOutput("Published", results);
5763
+ if (stillPublishing.size > 0) {
5764
+ const names = results.filter((r) => stillPublishing.has(r.id)).map((r) => r.name);
5765
+ output.message += ` (${names.join(", ")} ${names.length === 1 ? "is" : "are"} a large tree \u2014 descendants still publishing in the background; check again shortly)`;
5766
+ }
5767
+ return createToolResult(output);
5589
5768
  }
5590
5769
  };
5591
5770
  var bulk_publish_default = withStandardDecorators(tool80);