@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/dist/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
  import 'dotenv/config';
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
5
- import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas } from '@umbraco-cms/mcp-server-sdk';
5
+ import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas, isLoopbackUrl } from '@umbraco-cms/mcp-server-sdk';
6
6
  import { z } from 'zod';
7
7
  import { statSync, readFileSync } from 'fs';
8
8
  import { resolve } from 'path';
9
9
 
10
10
  // package.json
11
11
  var package_default = {
12
- version: "18.0.0-beta.10"};
12
+ version: "18.0.0-beta.11"};
13
13
 
14
14
  // src/auth/chained-deps.generated.ts
15
15
  var CHAINED_DEPS = {
@@ -20,21 +20,21 @@ var CHAINED_DEPS = {
20
20
  "audit-page-seo": ["get-document-by-id"],
21
21
  "bulk-move": ["get-document-by-id", "move-document"],
22
22
  "bulk-move-media": ["get-media-by-id", "move-media"],
23
- "bulk-publish": ["publish-document", "publish-document-with-descendants"],
23
+ "bulk-publish": ["get-document-publish-with-descendants-result", "publish-document", "publish-document-with-descendants"],
24
24
  "bulk-schedule-publish": ["publish-document"],
25
25
  "bulk-set-block-property": ["get-document-by-id", "get-document-version", "update-block-property"],
26
26
  "bulk-set-property": ["update-document-properties"],
27
27
  "bulk-unpublish": ["get-document-by-id", "unpublish-document"],
28
28
  "cancel-schedule": ["get-document-by-id", "publish-document"],
29
29
  "copy-variant": ["get-document-by-id", "update-document"],
30
- "create-and-publish-page": ["create-and-publish-document", "get-data-types-by-id-array", "get-document-type-by-id"],
30
+ "create-and-publish-page": ["create-and-publish-document", "get-data-types-by-id-array", "get-document-type-by-id", "get-language"],
31
31
  "create-blueprint": ["create-document-blueprint-from-document", "get-document-blueprint-root", "get-document-by-id"],
32
32
  "create-dictionary": ["create-dictionary"],
33
33
  "create-language": ["create-language"],
34
34
  "create-media-folder": ["create-media-folder", "get-media-by-id"],
35
35
  "create-member": ["create-member", "get-member", "update-member"],
36
36
  "create-member-group": ["create-member-group"],
37
- "create-page": ["create-document", "get-data-types-by-id-array", "get-document-type-by-id"],
37
+ "create-page": ["create-document", "get-data-types-by-id-array", "get-document-type-by-id", "get-language"],
38
38
  "create-variant": ["get-document-by-id", "update-document"],
39
39
  "delete-block": ["get-document-by-id", "update-document-properties"],
40
40
  "delete-language": ["delete-language", "get-language-by-iso-code"],
@@ -83,7 +83,7 @@ var CHAINED_DEPS = {
83
83
  "move-dictionary": ["get-dictionary", "move-dictionary-item"],
84
84
  "move-media": ["get-media-by-id", "move-media"],
85
85
  "permanent-delete-recycle-bin-item": ["get-document-by-id", "get-media-by-id"],
86
- "publish-page": ["get-document-by-id", "publish-document", "publish-document-with-descendants"],
86
+ "publish-page": ["get-document-by-id", "get-document-publish-with-descendants-result", "publish-document", "publish-document-with-descendants"],
87
87
  "remove-public-access": ["delete-document-public-access"],
88
88
  "report-content-references": ["get-document-by-id", "get-document-by-id-referenced-by", "get-media-by-id", "get-media-by-id-referenced-by", "get-media-urls"],
89
89
  "report-deep-pages": ["get-document-children", "get-document-root"],
@@ -101,7 +101,7 @@ var CHAINED_DEPS = {
101
101
  "restore-media": ["get-media-by-id", "restore-media-from-recycle-bin"],
102
102
  "restore-page": ["get-document-by-id"],
103
103
  "rollback-page": ["create-document-version-rollback", "get-document-by-id", "get-document-version", "get-user-by-id"],
104
- "save-and-publish": ["get-document-by-id", "publish-document", "publish-document-with-descendants", "update-and-publish-document", "update-document-properties"],
104
+ "save-and-publish": ["get-document-by-id", "get-document-publish-with-descendants-result", "publish-document", "publish-document-with-descendants", "update-and-publish-document", "update-document-properties"],
105
105
  "schedule-publish": ["get-document-by-id", "publish-document"],
106
106
  "search-content": ["search-document"],
107
107
  "search-dictionary": ["find-dictionary"],
@@ -118,8 +118,9 @@ var CHAINED_DEPS = {
118
118
  "update-member": ["get-member", "update-member"],
119
119
  "upload-media": ["create-media", "get-media-by-id"]
120
120
  };
121
-
122
- // src/config/mcp-servers.ts
121
+ function chainedTlsEnv(baseUrl) {
122
+ return isLoopbackUrl(baseUrl) ? { NODE_TLS_REJECT_UNAUTHORIZED: "0" } : {};
123
+ }
123
124
  async function buildServers() {
124
125
  if (typeof process === "undefined" || !process.env) return [];
125
126
  const useMockChain = process.env.USE_MOCK_MCP_CHAIN === "true";
@@ -143,13 +144,14 @@ async function buildServers() {
143
144
  const binEntry = typeof cmsDevPkg.bin === "string" ? cmsDevPkg.bin : cmsDevPkg.bin ? Object.values(cmsDevPkg.bin)[0] : void 0;
144
145
  if (!binEntry) throw new Error("@umbraco-cms/mcp-dev has no bin entry");
145
146
  const binAbs = path.resolve(path.dirname(pkgPath), binEntry);
147
+ const baseUrl = process.env.UMBRACO_BASE_URL || "http://localhost:44391";
146
148
  return [{
147
149
  name: "cms",
148
150
  command: process.execPath,
149
151
  args: [binAbs],
150
152
  env: {
151
- NODE_TLS_REJECT_UNAUTHORIZED: "0",
152
- UMBRACO_BASE_URL: process.env.UMBRACO_BASE_URL || "http://localhost:44391",
153
+ ...chainedTlsEnv(baseUrl),
154
+ UMBRACO_BASE_URL: baseUrl,
153
155
  UMBRACO_CLIENT_ID: process.env.UMBRACO_CLIENT_ID || "",
154
156
  UMBRACO_CLIENT_SECRET: process.env.UMBRACO_CLIENT_SECRET || "",
155
157
  // Clear tool filters so our editor tool names (search-content etc.) don't
@@ -754,10 +756,15 @@ var tool4 = {
754
756
  var list_document_types_default = withStandardDecorators(tool4);
755
757
 
756
758
  // src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
757
- async function resolveDocumentTypeProperties(documentTypeId) {
758
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
759
- if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
760
- const data = docTypeResult.data;
759
+ async function resolveDocumentTypeProperties(documentTypeId, documentType) {
760
+ let data;
761
+ if (documentType) {
762
+ data = documentType;
763
+ } else {
764
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
765
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
766
+ data = docTypeResult.data;
767
+ }
761
768
  const collected = /* @__PURE__ */ new Map();
762
769
  function addProperties(props) {
763
770
  for (const p of props) {
@@ -1562,11 +1569,11 @@ ${JSON.stringify(schemaResult.data, null, 2)}`,
1562
1569
  }
1563
1570
  };
1564
1571
  var get_property_value_template_default = withStandardDecorators(tool10);
1565
- async function resolveEditorAliases(documentTypeId, values) {
1572
+ async function resolveEditorAliases(documentTypeId, values, { defaultCulture = null, documentType, siteCultures } = {}) {
1566
1573
  if (!values || values.length === 0) {
1567
1574
  return { ok: true, values: [] };
1568
1575
  }
1569
- const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
1576
+ const docTypeResult = await resolveDocumentTypeProperties(documentTypeId, documentType);
1570
1577
  if (!docTypeResult.ok) return docTypeResult;
1571
1578
  const dataTypeIds = Array.from(
1572
1579
  new Set(
@@ -1585,22 +1592,32 @@ async function resolveEditorAliases(documentTypeId, values) {
1585
1592
  docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
1586
1593
  );
1587
1594
  const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1595
+ const cultureVariantAliases = /* @__PURE__ */ new Set();
1588
1596
  for (const prop of docTypeResult.properties) {
1589
1597
  const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
1590
1598
  if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1599
+ if (prop.alias && prop.variesByCulture) cultureVariantAliases.add(prop.alias);
1591
1600
  }
1592
1601
  const notAProperty = /* @__PURE__ */ new Set();
1593
1602
  const missingEditorAlias = /* @__PURE__ */ new Set();
1603
+ const unknownCultures = /* @__PURE__ */ new Set();
1594
1604
  const resolved = values.map((v) => {
1595
1605
  const editorAlias = editorAliasByPropertyAlias.get(v.alias);
1596
1606
  if (!editorAlias) {
1597
1607
  if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
1598
1608
  else notAProperty.add(v.alias);
1599
1609
  }
1610
+ let culture = v.culture ?? (cultureVariantAliases.has(v.alias) ? defaultCulture : null);
1611
+ if (v.culture && siteCultures) {
1612
+ const requested = v.culture.toLowerCase();
1613
+ const match = siteCultures.find((c) => c.toLowerCase() === requested);
1614
+ if (match) culture = match;
1615
+ else unknownCultures.add(v.culture);
1616
+ }
1600
1617
  return {
1601
1618
  alias: v.alias,
1602
1619
  value: v.value,
1603
- culture: v.culture ?? null,
1620
+ culture,
1604
1621
  segment: v.segment ?? null,
1605
1622
  editorAlias: editorAlias ?? ""
1606
1623
  };
@@ -1631,14 +1648,74 @@ async function resolveEditorAliases(documentTypeId, values) {
1631
1648
  )
1632
1649
  };
1633
1650
  }
1651
+ if (unknownCultures.size > 0 && siteCultures) {
1652
+ return {
1653
+ ok: false,
1654
+ errorResult: createToolResultError(
1655
+ `The following value culture(s) are not languages on this site: ${Array.from(unknownCultures).join(", ")}. Available cultures: ${siteCultures.join(", ")}.`
1656
+ )
1657
+ };
1658
+ }
1634
1659
  return { ok: true, values: resolved };
1635
1660
  }
1661
+ var LANGUAGE_PAGE_SIZE = 100;
1662
+ async function resolvePageCulture(documentTypeId, culture, { forPublish = false } = {}) {
1663
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1664
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
1665
+ const documentType = docTypeResult.data;
1666
+ if (!documentType.variesByCulture) {
1667
+ return { ok: true, culture: null, documentType };
1668
+ }
1669
+ const langResult = await chainCms("get-language", { cursor: encodeCursor({ s: 0, t: LANGUAGE_PAGE_SIZE }) });
1670
+ if (!langResult.ok) return { ok: false, errorResult: langResult.errorResult };
1671
+ const languages = langResult.data.items ?? [];
1672
+ const complete = (langResult.data.total ?? languages.length) <= languages.length;
1673
+ const siteCultures = languages.map((l) => l.isoCode);
1674
+ let pageCulture;
1675
+ if (culture) {
1676
+ const match = siteCultures.find((c) => c.toLowerCase() === culture.toLowerCase());
1677
+ if (!match && complete) {
1678
+ return {
1679
+ ok: false,
1680
+ errorResult: createToolResultError(
1681
+ `Culture "${culture}" is not a language on this site. Available cultures: ${siteCultures.join(", ")}.`
1682
+ )
1683
+ };
1684
+ }
1685
+ pageCulture = match ?? culture;
1686
+ } else {
1687
+ const defaultLanguage = languages.find((l) => l.isDefault);
1688
+ if (!defaultLanguage?.isoCode) {
1689
+ return {
1690
+ ok: false,
1691
+ errorResult: createToolResultError(
1692
+ "This document type varies by culture, but no default language could be determined. Call list-languages and pass `culture` explicitly."
1693
+ )
1694
+ };
1695
+ }
1696
+ pageCulture = defaultLanguage.isoCode;
1697
+ }
1698
+ if (forPublish) {
1699
+ const missingMandatory = languages.filter((l) => l.isMandatory && l.isoCode !== pageCulture).map((l) => l.isoCode);
1700
+ if (missingMandatory.length > 0) {
1701
+ const one = missingMandatory.length === 1;
1702
+ return {
1703
+ ok: false,
1704
+ errorResult: createToolResultError(
1705
+ `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.`
1706
+ )
1707
+ };
1708
+ }
1709
+ }
1710
+ return { ok: true, culture: pageCulture, documentType, siteCultures: complete ? siteCultures : void 0 };
1711
+ }
1636
1712
 
1637
1713
  // src/umbraco-api/tools/content/post/create-page.ts
1638
1714
  var inputSchema11 = {
1639
1715
  name: z.string().describe("The name of the page to create"),
1640
1716
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1641
1717
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1718
+ 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."),
1642
1719
  values: z.array(z.object({
1643
1720
  alias: z.string().describe("The property alias"),
1644
1721
  value: z.any().describe("The property value"),
@@ -1650,23 +1727,28 @@ var outputSchema11 = z.object({
1650
1727
  message: z.string(),
1651
1728
  id: z.string(),
1652
1729
  name: z.string(),
1730
+ 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."),
1653
1731
  previewUrl: previewUrlSchema,
1654
1732
  validation: validationResultSchema
1655
1733
  });
1656
1734
  var tool11 = {
1657
1735
  name: "create-page",
1658
- 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.).",
1736
+ 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.",
1659
1737
  inputSchema: inputSchema11,
1660
1738
  outputSchema: outputSchema11,
1661
1739
  slices: ["create"],
1662
1740
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1663
- handler: async ({ name, documentTypeId, parentId, values }) => {
1664
- const resolved = await resolveEditorAliases(documentTypeId, values);
1741
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1742
+ const cultureResult = await resolvePageCulture(documentTypeId, culture);
1743
+ if (!cultureResult.ok) return cultureResult.errorResult;
1744
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1745
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1665
1746
  if (!resolved.ok) return resolved.errorResult;
1666
1747
  const createResult = await chainCms("create-document", {
1667
1748
  documentTypeId,
1668
1749
  name,
1669
1750
  values: resolved.values,
1751
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1670
1752
  ...parentId ? { parentId } : {}
1671
1753
  });
1672
1754
  if (!createResult.ok) return createResult.errorResult;
@@ -1678,6 +1760,7 @@ var tool11 = {
1678
1760
  message,
1679
1761
  id: createdId,
1680
1762
  name,
1763
+ culture: pageCulture,
1681
1764
  previewUrl: createdId ? await fetchPreviewUrl(createdId) : null,
1682
1765
  validation
1683
1766
  });
@@ -1688,6 +1771,7 @@ var inputSchema12 = {
1688
1771
  name: z.string().describe("The name of the page to create"),
1689
1772
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1690
1773
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1774
+ 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."),
1691
1775
  values: z.array(z.object({
1692
1776
  alias: z.string().describe("The property alias"),
1693
1777
  value: z.any().describe("The property value"),
@@ -1699,22 +1783,27 @@ var outputSchema12 = z.object({
1699
1783
  message: z.string(),
1700
1784
  id: z.string(),
1701
1785
  name: z.string(),
1786
+ 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."),
1702
1787
  publishedUrls: publishedUrlsSchema
1703
1788
  });
1704
1789
  var tool12 = {
1705
1790
  name: "create-and-publish-page",
1706
- 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.",
1791
+ 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.",
1707
1792
  inputSchema: inputSchema12,
1708
1793
  outputSchema: outputSchema12,
1709
1794
  slices: ["create", "publish"],
1710
1795
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1711
- handler: async ({ name, documentTypeId, parentId, values }) => {
1712
- const resolved = await resolveEditorAliases(documentTypeId, values);
1796
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1797
+ const cultureResult = await resolvePageCulture(documentTypeId, culture, { forPublish: true });
1798
+ if (!cultureResult.ok) return cultureResult.errorResult;
1799
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1800
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1713
1801
  if (!resolved.ok) return resolved.errorResult;
1714
1802
  const createResult = await chainCms("create-and-publish-document", {
1715
1803
  documentTypeId,
1716
1804
  name,
1717
1805
  values: resolved.values,
1806
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1718
1807
  ...parentId ? { parentId } : {}
1719
1808
  });
1720
1809
  if (!createResult.ok) return createResult.errorResult;
@@ -1723,6 +1812,7 @@ var tool12 = {
1723
1812
  message: `Created and published "${name}"`,
1724
1813
  id: createdId,
1725
1814
  name,
1815
+ culture: pageCulture,
1726
1816
  publishedUrls: createdId ? await fetchPublishedUrls(createdId) : []
1727
1817
  });
1728
1818
  }
@@ -2595,6 +2685,48 @@ async function verifyDocumentPublished(id, expectedCultures) {
2595
2685
  return `publish call returned success but ${failures.length === 1 ? "this culture is" : "these cultures are"} still in draft: ${failures.join(", ")}`;
2596
2686
  }
2597
2687
 
2688
+ // src/umbraco-api/tools/helpers/publish-with-descendants.ts
2689
+ var FOLLOWUP_MAX_ATTEMPTS = 30;
2690
+ var FOLLOWUP_POLL_INTERVAL_MS = 2e3;
2691
+ function parsePublishWithDescendantsStatus(data) {
2692
+ if (data !== null && typeof data === "object" && data.status === "in-progress" && typeof data.taskId === "string") {
2693
+ return { complete: false, taskId: data.taskId };
2694
+ }
2695
+ if (data !== "") {
2696
+ console.warn(
2697
+ `publish-document-with-descendants returned an unrecognized success payload (neither "" nor an in-progress marker) \u2014 treating as complete: ${JSON.stringify(data)}`
2698
+ );
2699
+ }
2700
+ return { complete: true };
2701
+ }
2702
+ function isRequestTimeout(error) {
2703
+ const detail = extractInnerProblemDetails(error.errorResult).detail;
2704
+ return typeof detail === "string" && detail.includes("Request timed out");
2705
+ }
2706
+ async function publishWithDescendants(id, data, options) {
2707
+ const initial = await chainCms("publish-document-with-descendants", { id, data });
2708
+ if (!initial.ok) {
2709
+ if (isRequestTimeout(initial)) return { ok: true, complete: false };
2710
+ return initial;
2711
+ }
2712
+ const status = parsePublishWithDescendantsStatus(initial.data);
2713
+ if (status.complete) return { ok: true, complete: true };
2714
+ if (options?.followUp === false) return { ok: true, complete: false };
2715
+ for (let attempt = 0; attempt < FOLLOWUP_MAX_ATTEMPTS; attempt++) {
2716
+ await new Promise((resolve2) => setTimeout(resolve2, FOLLOWUP_POLL_INTERVAL_MS));
2717
+ const poll = await chainCms("get-document-publish-with-descendants-result", {
2718
+ id,
2719
+ taskId: status.taskId
2720
+ });
2721
+ if (!poll.ok) {
2722
+ if (isRequestTimeout(poll)) return { ok: true, complete: false };
2723
+ return poll;
2724
+ }
2725
+ if (poll.data.isComplete) return { ok: true, complete: true };
2726
+ }
2727
+ return { ok: true, complete: false };
2728
+ }
2729
+
2598
2730
  // src/umbraco-api/tools/publishing/post/publish-page.ts
2599
2731
  var inputSchema25 = {
2600
2732
  id: z.string().uuid().describe("The ID of the page to publish"),
@@ -2612,7 +2744,12 @@ var tool25 = {
2612
2744
  inputSchema: inputSchema25,
2613
2745
  outputSchema: outputSchema25,
2614
2746
  slices: ["publish"],
2615
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
2747
+ // includeDescendants delegates to publish-document-with-descendants, which
2748
+ // the chained CMS tool annotates idempotentHint: false — a retry fires a
2749
+ // second concurrent recursive publish job rather than converging to the
2750
+ // same end state. That makes this tool non-idempotent as a whole, since
2751
+ // includeDescendants is a valid input, not a separate tool.
2752
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
2616
2753
  handler: async ({ id, includeDescendants }, extra) => {
2617
2754
  const docResult = await chainCms("get-document-by-id", { id });
2618
2755
  if (!docResult.ok) return docResult.errorResult;
@@ -2624,29 +2761,42 @@ var tool25 = {
2624
2761
  }
2625
2762
  }
2626
2763
  const variantCultures = (doc.variants ?? []).length ? doc.variants.map((v) => v.culture ?? null) : [null];
2627
- const publishResult = includeDescendants ? await chainCms("publish-document-with-descendants", {
2628
- id,
2629
- data: {
2764
+ if (includeDescendants) {
2765
+ const result = await publishWithDescendants(id, {
2630
2766
  includeUnpublishedDescendants: false,
2631
2767
  cultures: variantCultures.filter((c) => c !== null)
2768
+ });
2769
+ if (!result.ok) return result.errorResult;
2770
+ if (!result.complete) {
2771
+ return createToolResult({
2772
+ message: `"${pageName}" and its descendants are a large tree \u2014 publishing is still running in the background. Check again shortly.`,
2773
+ id,
2774
+ name: pageName,
2775
+ publishedUrls: []
2776
+ });
2632
2777
  }
2633
- }) : await chainCms("publish-document", {
2778
+ return createToolResult({
2779
+ message: `Published "${pageName}" and all child pages`,
2780
+ id,
2781
+ name: pageName,
2782
+ publishedUrls: await fetchPublishedUrls(id)
2783
+ });
2784
+ }
2785
+ const publishResult = await chainCms("publish-document", {
2634
2786
  id,
2635
2787
  data: { publishSchedules: variantCultures.map((c) => ({ culture: c })) }
2636
2788
  });
2637
2789
  if (!publishResult.ok) return publishResult.errorResult;
2638
- if (!includeDescendants) {
2639
- const verifyError = await verifyDocumentPublished(id, variantCultures);
2640
- if (verifyError) {
2641
- return createToolResultError({
2642
- status: 500,
2643
- title: "Publish did not take effect",
2644
- detail: `"${pageName}": ${verifyError}`
2645
- });
2646
- }
2790
+ const verifyError = await verifyDocumentPublished(id, variantCultures);
2791
+ if (verifyError) {
2792
+ return createToolResultError({
2793
+ status: 500,
2794
+ title: "Publish did not take effect",
2795
+ detail: `"${pageName}": ${verifyError}`
2796
+ });
2647
2797
  }
2648
2798
  return createToolResult({
2649
- message: includeDescendants ? `Published "${pageName}" and all child pages` : `Published "${pageName}"`,
2799
+ message: `Published "${pageName}"`,
2650
2800
  id,
2651
2801
  name: pageName,
2652
2802
  publishedUrls: await fetchPublishedUrls(id)
@@ -2776,12 +2926,9 @@ var tool27 = {
2776
2926
  if (!updateResult.ok) return updateResult.errorResult;
2777
2927
  saved = true;
2778
2928
  }
2779
- const publishResult = await chainCms("publish-document-with-descendants", {
2780
- id,
2781
- data: {
2782
- includeUnpublishedDescendants: false,
2783
- cultures: variantCultures.filter((c) => c !== null)
2784
- }
2929
+ const publishResult = await publishWithDescendants(id, {
2930
+ includeUnpublishedDescendants: false,
2931
+ cultures: variantCultures.filter((c) => c !== null)
2785
2932
  });
2786
2933
  if (!publishResult.ok) {
2787
2934
  if (saved) {
@@ -2797,6 +2944,18 @@ var tool27 = {
2797
2944
  }
2798
2945
  return publishResult.errorResult;
2799
2946
  }
2947
+ if (!publishResult.complete) {
2948
+ const savedPrefix = saved ? `Saved ${fieldNames.length} field(s) on "${pageName}". ` : "";
2949
+ return createToolResult({
2950
+ message: `${savedPrefix}"${pageName}" and its descendants are a large tree \u2014 publishing is still running in the background. Check again shortly.`,
2951
+ id,
2952
+ name: pageName,
2953
+ saved,
2954
+ published: false,
2955
+ updatedFields: fieldNames,
2956
+ publishedUrls: []
2957
+ });
2958
+ }
2800
2959
  const savedPart2 = saved ? `Saved ${fieldNames.length} field(s) and ` : "";
2801
2960
  return createToolResult({
2802
2961
  message: `${savedPart2}published "${pageName}" and all descendants`,
@@ -5640,7 +5799,8 @@ var outputSchema80 = z.object({
5640
5799
  success: z.boolean(),
5641
5800
  previousVersionId: z.string().optional(),
5642
5801
  error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
5643
- publishedUrls: publishedUrlsSchema.optional()
5802
+ publishedUrls: publishedUrlsSchema.optional(),
5803
+ 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.")
5644
5804
  })),
5645
5805
  successCount: z.number(),
5646
5806
  failureCount: z.number(),
@@ -5652,7 +5812,12 @@ var tool80 = {
5652
5812
  inputSchema: inputSchema80,
5653
5813
  outputSchema: outputSchema80,
5654
5814
  slices: ["publish"],
5655
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
5815
+ // includeDescendants delegates to publish-document-with-descendants, which
5816
+ // the chained CMS tool annotates idempotentHint: false — a retry fires a
5817
+ // second concurrent recursive publish job rather than converging to the
5818
+ // same end state. That makes this tool non-idempotent as a whole, since
5819
+ // includeDescendants is a valid input, not a separate tool.
5820
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
5656
5821
  handler: async ({ ids, includeDescendants }, extra) => {
5657
5822
  const validationError = validateBulkIds(ids);
5658
5823
  if (validationError) return createToolResult(validationError);
@@ -5678,15 +5843,20 @@ ${nameList}`;
5678
5843
  skippedCount: 0
5679
5844
  });
5680
5845
  }
5846
+ const stillPublishing = /* @__PURE__ */ new Set();
5681
5847
  const results = await executeBulkSequentially(items, async (item) => {
5682
5848
  const cultures = item.cultures ?? [null];
5683
- const result = includeDescendants ? await chainCms("publish-document-with-descendants", {
5684
- id: item.id,
5685
- data: {
5686
- includeUnpublishedDescendants: false,
5687
- cultures: cultures.filter((c) => c !== null)
5688
- }
5689
- }) : await chainCms("publish-document", {
5849
+ if (includeDescendants) {
5850
+ const result2 = await publishWithDescendants(
5851
+ item.id,
5852
+ { includeUnpublishedDescendants: false, cultures: cultures.filter((c) => c !== null) },
5853
+ { followUp: false }
5854
+ );
5855
+ if (!result2.ok) return result2.errorResult;
5856
+ if (!result2.complete) stillPublishing.add(item.id);
5857
+ return null;
5858
+ }
5859
+ const result = await chainCms("publish-document", {
5690
5860
  id: item.id,
5691
5861
  data: { publishSchedules: cultures.map((c) => ({ culture: c })) }
5692
5862
  });
@@ -5697,9 +5867,18 @@ ${nameList}`;
5697
5867
  });
5698
5868
  for (const row of results) {
5699
5869
  if (!row.success) continue;
5870
+ if (stillPublishing.has(row.id)) {
5871
+ row.publishPending = true;
5872
+ continue;
5873
+ }
5700
5874
  row.publishedUrls = await fetchPublishedUrls(row.id);
5701
5875
  }
5702
- return createToolResult(buildBulkOutput("Published", results));
5876
+ const output = buildBulkOutput("Published", results);
5877
+ if (stillPublishing.size > 0) {
5878
+ const names = results.filter((r) => stillPublishing.has(r.id)).map((r) => r.name);
5879
+ output.message += ` (${names.join(", ")} ${names.length === 1 ? "is" : "are"} a large tree \u2014 descendants still publishing in the background; check again shortly)`;
5880
+ }
5881
+ return createToolResult(output);
5703
5882
  }
5704
5883
  };
5705
5884
  var bulk_publish_default = withStandardDecorators(tool80);