@umbraco-cms/mcp-editor 17.6.0-beta.7 → 17.6.0-beta.9

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,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
  const isWorkersRuntime = typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers";
11
12
  if (isWorkersRuntime || typeof process === "undefined" || !process.env) return [];
@@ -30,13 +31,14 @@ async function buildServers() {
30
31
  const binEntry = typeof cmsDevPkg.bin === "string" ? cmsDevPkg.bin : cmsDevPkg.bin ? Object.values(cmsDevPkg.bin)[0] : void 0;
31
32
  if (!binEntry) throw new Error("@umbraco-cms/mcp-dev has no bin entry");
32
33
  const binAbs = path.resolve(path.dirname(pkgPath), binEntry);
34
+ const baseUrl = process.env.UMBRACO_BASE_URL || "http://localhost:44391";
33
35
  return [{
34
36
  name: "cms",
35
37
  command: process.execPath,
36
38
  args: [binAbs],
37
39
  env: {
38
- NODE_TLS_REJECT_UNAUTHORIZED: "0",
39
- UMBRACO_BASE_URL: process.env.UMBRACO_BASE_URL || "http://localhost:44391",
40
+ ...chainedTlsEnv(baseUrl),
41
+ UMBRACO_BASE_URL: baseUrl,
40
42
  UMBRACO_CLIENT_ID: process.env.UMBRACO_CLIENT_ID || "",
41
43
  UMBRACO_CLIENT_SECRET: process.env.UMBRACO_CLIENT_SECRET || "",
42
44
  // Clear tool filters so our editor tool names (search-content etc.) don't
@@ -141,78 +143,21 @@ async function chainCms(toolName, args) {
141
143
  }
142
144
  return { ok: true, data: extractChainedResult(result) };
143
145
  }
144
- function buildChainedCursor(skip, take) {
145
- return encodeCursor({ s: skip, t: take });
146
- }
147
- function stripHtml(html) {
148
- return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
149
- }
150
- function countWords(text) {
151
- const stripped = stripHtml(text);
152
- if (!stripped) return 0;
153
- return stripped.split(/\s+/).filter(Boolean).length;
154
- }
155
- function extractTextFromBlockValues(innerValues) {
156
- const parts = [];
157
- for (const v of innerValues || []) {
158
- const text = extractTextFromValue(v.value, v.editorAlias);
159
- if (text) parts.push(text);
160
- }
161
- return parts.join(" ");
162
- }
163
- function extractTextFromValue(value, editorAlias) {
164
- if (typeof value === "string") {
165
- return stripHtml(value);
166
- }
167
- if (value && typeof value === "object" && typeof value.markup === "string") {
168
- const markupText = stripHtml(value.markup);
169
- const blockText = extractTextFromContentData(value.blocks?.contentData);
170
- return [markupText, blockText].filter(Boolean).join(" ");
171
- }
172
- if (value && typeof value === "object" && Array.isArray(value.contentData)) {
173
- return extractTextFromContentData(value.contentData);
174
- }
175
- return "";
176
- }
177
- function extractTextFromContentData(contentData) {
178
- const parts = [];
179
- for (const block of contentData || []) {
180
- const blockText = extractTextFromBlockValues(block.values || []);
181
- if (blockText) parts.push(blockText);
182
- }
183
- return parts.join(" ");
184
- }
185
- function extractTextContent(values) {
186
- const parts = [];
187
- for (const v of values || []) {
188
- const text = extractTextFromValue(v.value, v.editorAlias);
189
- if (text) parts.push(text);
190
- }
191
- return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
192
- }
193
- function extractHeadings(html) {
194
- const headings = [];
195
- const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
196
- let match;
197
- while ((match = regex.exec(html)) !== null) {
198
- headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
199
- }
200
- return headings;
146
+ var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
147
+ var URL_BATCH_CHUNK_SIZE = 40;
148
+ function describeChainError(errorResult) {
149
+ const problem = extractInnerProblemDetails(errorResult);
150
+ const title = typeof problem.title === "string" ? problem.title : void 0;
151
+ const detail = typeof problem.detail === "string" ? problem.detail : void 0;
152
+ return [title, detail].filter(Boolean).join(": ") || "unknown error";
201
153
  }
202
- function extractImages(html) {
203
- const images = [];
204
- const regex = /<img[^>]*>/gi;
205
- let match;
206
- while ((match = regex.exec(html)) !== null) {
207
- const srcMatch = match[0].match(/src="([^"]*)"/i);
208
- const altMatch = match[0].match(/alt="([^"]*)"/i);
209
- const src = srcMatch?.[1] ?? "";
210
- const alt = altMatch?.[1] ?? "";
211
- images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
154
+ function chunkIds(ids, size) {
155
+ const chunks = [];
156
+ for (let i = 0; i < ids.length; i += size) {
157
+ chunks.push(ids.slice(i, i + size));
212
158
  }
213
- return images;
159
+ return chunks;
214
160
  }
215
- var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
216
161
  var cachedBaseUrl = null;
217
162
  var cachedMtimeMs = null;
218
163
  function readBaseUrlFromEnvFile(envPath) {
@@ -318,26 +263,131 @@ function flattenPublishedUrls(urls) {
318
263
  async function fetchPublishedUrls(id) {
319
264
  try {
320
265
  const result = await chainCms("get-document-urls", { id: [id] });
321
- if (!result.ok) return [];
266
+ if (!result.ok) {
267
+ console.warn(
268
+ `fetchPublishedUrls: get-document-urls failed for id ${id} \u2014 returning no published URLs: ${describeChainError(result.errorResult)}`
269
+ );
270
+ return [];
271
+ }
322
272
  return flattenPublishedUrls(result.data.items);
323
- } catch {
273
+ } catch (error) {
274
+ const message = error instanceof Error ? error.message : String(error);
275
+ console.warn(
276
+ `fetchPublishedUrls: unexpected error fetching published URLs for id ${id} \u2014 returning no published URLs: ${message}`
277
+ );
324
278
  return [];
325
279
  }
326
280
  }
327
281
  async function fetchPublishedUrlsBatch(ids) {
328
282
  const out = /* @__PURE__ */ new Map();
329
283
  if (ids.length === 0) return out;
330
- try {
331
- const result = await chainCms("get-document-urls", { id: ids });
332
- if (!result.ok) return out;
333
- for (const entry of result.data.items ?? []) {
334
- if (!entry?.id) continue;
335
- out.set(entry.id, flattenPublishedUrls([entry]));
284
+ for (const idChunk of chunkIds(ids, URL_BATCH_CHUNK_SIZE)) {
285
+ try {
286
+ const result = await chainCms("get-document-urls", { id: idChunk });
287
+ if (!result.ok) {
288
+ console.warn(
289
+ `fetchPublishedUrlsBatch: get-document-urls failed for a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${describeChainError(result.errorResult)}`
290
+ );
291
+ continue;
292
+ }
293
+ for (const entry of result.data.items ?? []) {
294
+ if (!entry?.id) continue;
295
+ out.set(entry.id, flattenPublishedUrls([entry]));
296
+ }
297
+ } catch (error) {
298
+ const message = error instanceof Error ? error.message : String(error);
299
+ console.warn(
300
+ `fetchPublishedUrlsBatch: unexpected error processing a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${message}`
301
+ );
336
302
  }
337
- } catch {
338
303
  }
339
304
  return out;
340
305
  }
306
+ async function fetchPrimaryPublishedUrl(id) {
307
+ const urls = await fetchPublishedUrls(id);
308
+ return urls[0] ?? "";
309
+ }
310
+ async function fetchPrimaryPublishedUrlsBatch(ids) {
311
+ const batch = await fetchPublishedUrlsBatch(ids);
312
+ const out = /* @__PURE__ */ new Map();
313
+ for (const id of ids) {
314
+ out.set(id, batch.get(id)?.[0] ?? "");
315
+ }
316
+ return out;
317
+ }
318
+
319
+ // src/umbraco-api/tools/helpers/tree-walker.ts
320
+ function buildChainedCursor(skip, take) {
321
+ return encodeCursor({ s: skip, t: take });
322
+ }
323
+ function stripHtml(html) {
324
+ return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
325
+ }
326
+ function countWords(text) {
327
+ const stripped = stripHtml(text);
328
+ if (!stripped) return 0;
329
+ return stripped.split(/\s+/).filter(Boolean).length;
330
+ }
331
+ function extractTextFromBlockValues(innerValues) {
332
+ const parts = [];
333
+ for (const v of innerValues || []) {
334
+ const text = extractTextFromValue(v.value, v.editorAlias);
335
+ if (text) parts.push(text);
336
+ }
337
+ return parts.join(" ");
338
+ }
339
+ function extractTextFromValue(value, editorAlias) {
340
+ if (typeof value === "string") {
341
+ return stripHtml(value);
342
+ }
343
+ if (value && typeof value === "object" && typeof value.markup === "string") {
344
+ const markupText = stripHtml(value.markup);
345
+ const blockText = extractTextFromContentData(value.blocks?.contentData);
346
+ return [markupText, blockText].filter(Boolean).join(" ");
347
+ }
348
+ if (value && typeof value === "object" && Array.isArray(value.contentData)) {
349
+ return extractTextFromContentData(value.contentData);
350
+ }
351
+ return "";
352
+ }
353
+ function extractTextFromContentData(contentData) {
354
+ const parts = [];
355
+ for (const block of contentData || []) {
356
+ const blockText = extractTextFromBlockValues(block.values || []);
357
+ if (blockText) parts.push(blockText);
358
+ }
359
+ return parts.join(" ");
360
+ }
361
+ function extractTextContent(values) {
362
+ const parts = [];
363
+ for (const v of values || []) {
364
+ const text = extractTextFromValue(v.value, v.editorAlias);
365
+ if (text) parts.push(text);
366
+ }
367
+ return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
368
+ }
369
+ function extractHeadings(html) {
370
+ const headings = [];
371
+ const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
372
+ let match;
373
+ while ((match = regex.exec(html)) !== null) {
374
+ headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
375
+ }
376
+ return headings;
377
+ }
378
+ function extractImages(html) {
379
+ const images = [];
380
+ const regex = /<img[^>]*>/gi;
381
+ let match;
382
+ while ((match = regex.exec(html)) !== null) {
383
+ const srcMatch = match[0].match(/src="([^"]*)"/i);
384
+ const altMatch = match[0].match(/alt="([^"]*)"/i);
385
+ const src = srcMatch?.[1] ?? "";
386
+ const alt = altMatch?.[1] ?? "";
387
+ images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
388
+ }
389
+ return images;
390
+ }
341
391
 
342
392
  // src/umbraco-api/tools/content/get/search-content.ts
343
393
  var inputSchema = {
@@ -356,7 +406,7 @@ var outputSchema = z.object({
356
406
  });
357
407
  var tool = {
358
408
  name: "search-content",
359
- description: "Search for content pages by name or text. Returns a list of matching pages with their names and IDs. Use get-page with an ID from the results to retrieve full page content.",
409
+ description: "Search for content pages by name only \u2014 it does not match body text or other field values (tracked in #234). Returns a list of matching pages with their names and IDs. For body text, use list-children + get-page instead. Use get-page with an ID from the results to retrieve full page content.",
360
410
  inputSchema,
361
411
  outputSchema,
362
412
  slices: ["search"],
@@ -432,8 +482,10 @@ var tool2 = {
432
482
  })),
433
483
  variants: doc.variants ?? [],
434
484
  previewUrl: buildPreviewUrl(doc.id),
435
- // GetDocumentByIdOutput doesn't include `urls` — runtime field, not in the upstream Zod schema.
436
- publishedUrls: flattenPublishedUrls(doc.urls)
485
+ // The get-document-by-id response doesn't carry `urls` — published
486
+ // URLs come only from the separate get-document-urls endpoint via
487
+ // fetchPublishedUrls.
488
+ publishedUrls: await fetchPublishedUrls(id)
437
489
  });
438
490
  }
439
491
  };
@@ -599,10 +651,15 @@ var tool4 = {
599
651
  var list_document_types_default = withStandardDecorators(tool4);
600
652
 
601
653
  // src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
602
- async function resolveDocumentTypeProperties(documentTypeId) {
603
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
604
- if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
605
- const data = docTypeResult.data;
654
+ async function resolveDocumentTypeProperties(documentTypeId, documentType) {
655
+ let data;
656
+ if (documentType) {
657
+ data = documentType;
658
+ } else {
659
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
660
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
661
+ data = docTypeResult.data;
662
+ }
606
663
  const collected = /* @__PURE__ */ new Map();
607
664
  function addProperties(props) {
608
665
  for (const p of props) {
@@ -1341,11 +1398,11 @@ ${aliases.join("\n")}`
1341
1398
  }
1342
1399
  };
1343
1400
  var get_property_value_template_default = withStandardDecorators(tool10);
1344
- async function resolveEditorAliases(documentTypeId, values) {
1401
+ async function resolveEditorAliases(documentTypeId, values, { defaultCulture = null, documentType, siteCultures } = {}) {
1345
1402
  if (!values || values.length === 0) {
1346
1403
  return { ok: true, values: [] };
1347
1404
  }
1348
- const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
1405
+ const docTypeResult = await resolveDocumentTypeProperties(documentTypeId, documentType);
1349
1406
  if (!docTypeResult.ok) return docTypeResult;
1350
1407
  const dataTypeIds = Array.from(
1351
1408
  new Set(
@@ -1364,22 +1421,32 @@ async function resolveEditorAliases(documentTypeId, values) {
1364
1421
  docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
1365
1422
  );
1366
1423
  const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1424
+ const cultureVariantAliases = /* @__PURE__ */ new Set();
1367
1425
  for (const prop of docTypeResult.properties) {
1368
1426
  const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
1369
1427
  if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1428
+ if (prop.alias && prop.variesByCulture) cultureVariantAliases.add(prop.alias);
1370
1429
  }
1371
1430
  const notAProperty = /* @__PURE__ */ new Set();
1372
1431
  const missingEditorAlias = /* @__PURE__ */ new Set();
1432
+ const unknownCultures = /* @__PURE__ */ new Set();
1373
1433
  const resolved = values.map((v) => {
1374
1434
  const editorAlias = editorAliasByPropertyAlias.get(v.alias);
1375
1435
  if (!editorAlias) {
1376
1436
  if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
1377
1437
  else notAProperty.add(v.alias);
1378
1438
  }
1439
+ let culture = v.culture ?? (cultureVariantAliases.has(v.alias) ? defaultCulture : null);
1440
+ if (v.culture && siteCultures) {
1441
+ const requested = v.culture.toLowerCase();
1442
+ const match = siteCultures.find((c) => c.toLowerCase() === requested);
1443
+ if (match) culture = match;
1444
+ else unknownCultures.add(v.culture);
1445
+ }
1379
1446
  return {
1380
1447
  alias: v.alias,
1381
1448
  value: v.value,
1382
- culture: v.culture ?? null,
1449
+ culture,
1383
1450
  segment: v.segment ?? null,
1384
1451
  editorAlias: editorAlias ?? ""
1385
1452
  };
@@ -1410,14 +1477,74 @@ async function resolveEditorAliases(documentTypeId, values) {
1410
1477
  )
1411
1478
  };
1412
1479
  }
1480
+ if (unknownCultures.size > 0 && siteCultures) {
1481
+ return {
1482
+ ok: false,
1483
+ errorResult: createToolResultError(
1484
+ `The following value culture(s) are not languages on this site: ${Array.from(unknownCultures).join(", ")}. Available cultures: ${siteCultures.join(", ")}.`
1485
+ )
1486
+ };
1487
+ }
1413
1488
  return { ok: true, values: resolved };
1414
1489
  }
1490
+ var LANGUAGE_PAGE_SIZE = 100;
1491
+ async function resolvePageCulture(documentTypeId, culture, { forPublish = false } = {}) {
1492
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1493
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
1494
+ const documentType = docTypeResult.data;
1495
+ if (!documentType.variesByCulture) {
1496
+ return { ok: true, culture: null, documentType };
1497
+ }
1498
+ const langResult = await chainCms("get-language", { cursor: encodeCursor({ s: 0, t: LANGUAGE_PAGE_SIZE }) });
1499
+ if (!langResult.ok) return { ok: false, errorResult: langResult.errorResult };
1500
+ const languages = langResult.data.items ?? [];
1501
+ const complete = (langResult.data.total ?? languages.length) <= languages.length;
1502
+ const siteCultures = languages.map((l) => l.isoCode);
1503
+ let pageCulture;
1504
+ if (culture) {
1505
+ const match = siteCultures.find((c) => c.toLowerCase() === culture.toLowerCase());
1506
+ if (!match && complete) {
1507
+ return {
1508
+ ok: false,
1509
+ errorResult: createToolResultError(
1510
+ `Culture "${culture}" is not a language on this site. Available cultures: ${siteCultures.join(", ")}.`
1511
+ )
1512
+ };
1513
+ }
1514
+ pageCulture = match ?? culture;
1515
+ } else {
1516
+ const defaultLanguage = languages.find((l) => l.isDefault);
1517
+ if (!defaultLanguage?.isoCode) {
1518
+ return {
1519
+ ok: false,
1520
+ errorResult: createToolResultError(
1521
+ "This document type varies by culture, but no default language could be determined. Call list-languages and pass `culture` explicitly."
1522
+ )
1523
+ };
1524
+ }
1525
+ pageCulture = defaultLanguage.isoCode;
1526
+ }
1527
+ if (forPublish) {
1528
+ const missingMandatory = languages.filter((l) => l.isMandatory && l.isoCode !== pageCulture).map((l) => l.isoCode);
1529
+ if (missingMandatory.length > 0) {
1530
+ const one = missingMandatory.length === 1;
1531
+ return {
1532
+ ok: false,
1533
+ errorResult: createToolResultError(
1534
+ `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.`
1535
+ )
1536
+ };
1537
+ }
1538
+ }
1539
+ return { ok: true, culture: pageCulture, documentType, siteCultures: complete ? siteCultures : void 0 };
1540
+ }
1415
1541
 
1416
1542
  // src/umbraco-api/tools/content/post/create-page.ts
1417
1543
  var inputSchema11 = {
1418
1544
  name: z.string().describe("The name of the page to create"),
1419
1545
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1420
1546
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1547
+ 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."),
1421
1548
  values: z.array(z.object({
1422
1549
  alias: z.string().describe("The property alias"),
1423
1550
  value: z.any().describe("The property value"),
@@ -1429,23 +1556,28 @@ var outputSchema11 = z.object({
1429
1556
  message: z.string(),
1430
1557
  id: z.string(),
1431
1558
  name: z.string(),
1559
+ 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."),
1432
1560
  previewUrl: previewUrlSchema,
1433
1561
  validation: validationResultSchema
1434
1562
  });
1435
1563
  var tool11 = {
1436
1564
  name: "create-page",
1437
- 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.).",
1565
+ 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.",
1438
1566
  inputSchema: inputSchema11,
1439
1567
  outputSchema: outputSchema11,
1440
1568
  slices: ["create"],
1441
1569
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1442
- handler: async ({ name, documentTypeId, parentId, values }) => {
1443
- const resolved = await resolveEditorAliases(documentTypeId, values);
1570
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1571
+ const cultureResult = await resolvePageCulture(documentTypeId, culture);
1572
+ if (!cultureResult.ok) return cultureResult.errorResult;
1573
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1574
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1444
1575
  if (!resolved.ok) return resolved.errorResult;
1445
1576
  const createResult = await chainCms("create-document", {
1446
1577
  documentTypeId,
1447
1578
  name,
1448
1579
  values: resolved.values,
1580
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1449
1581
  ...parentId ? { parentId } : {}
1450
1582
  });
1451
1583
  if (!createResult.ok) return createResult.errorResult;
@@ -1457,6 +1589,7 @@ var tool11 = {
1457
1589
  message,
1458
1590
  id: createdId,
1459
1591
  name,
1592
+ culture: pageCulture,
1460
1593
  previewUrl: createdId ? await fetchPreviewUrl(createdId) : null,
1461
1594
  validation
1462
1595
  });
@@ -1467,6 +1600,7 @@ var inputSchema12 = {
1467
1600
  name: z.string().describe("The name of the page to create"),
1468
1601
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1469
1602
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1603
+ 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."),
1470
1604
  values: z.array(z.object({
1471
1605
  alias: z.string().describe("The property alias"),
1472
1606
  value: z.any().describe("The property value"),
@@ -1478,23 +1612,28 @@ var outputSchema12 = z.object({
1478
1612
  message: z.string(),
1479
1613
  id: z.string(),
1480
1614
  name: z.string(),
1615
+ 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."),
1481
1616
  publishedUrls: publishedUrlsSchema
1482
1617
  });
1483
1618
  var tool12 = {
1484
1619
  name: "create-and-publish-page",
1485
- description: "Create a new content page and publish it \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. This is a single atomic operation when the connected Umbraco instance supports it (17.6+); otherwise a two-call create-then-publish sequence is used. 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. Required-property validation runs at publish time, not create time: on the atomic path a validation failure leaves no page behind, but on the fallback path the draft can already have been created before publish fails, leaving an unpublished draft. Either way, check the response `message` before retrying \u2014 don't retry blindly, or you may pile up duplicate drafts. Use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing.",
1620
+ description: "Create a new content page and publish it \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. This is a single atomic operation when the connected Umbraco instance supports it (17.6+); otherwise a two-call create-then-publish sequence is used. 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. Required-property validation runs at publish time, not create time: on the atomic path a validation failure leaves no page behind, but on the fallback path the draft can already have been created before publish fails, leaving an unpublished draft. Either way, check the response `message` before retrying \u2014 don't retry blindly, or you may pile up duplicate drafts. 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.",
1486
1621
  inputSchema: inputSchema12,
1487
1622
  outputSchema: outputSchema12,
1488
1623
  slices: ["create", "publish"],
1489
1624
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1490
- handler: async ({ name, documentTypeId, parentId, values }) => {
1491
- const resolved = await resolveEditorAliases(documentTypeId, values);
1625
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1626
+ const cultureResult = await resolvePageCulture(documentTypeId, culture, { forPublish: true });
1627
+ if (!cultureResult.ok) return cultureResult.errorResult;
1628
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1629
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1492
1630
  if (!resolved.ok) return resolved.errorResult;
1493
1631
  if (await isCmsToolAvailable("create-and-publish-document")) {
1494
1632
  const createResult = await chainCms("create-and-publish-document", {
1495
1633
  documentTypeId,
1496
1634
  name,
1497
1635
  values: resolved.values,
1636
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1498
1637
  ...parentId ? { parentId } : {}
1499
1638
  });
1500
1639
  if (!createResult.ok) return createResult.errorResult;
@@ -1503,6 +1642,7 @@ var tool12 = {
1503
1642
  message: `Created and published "${name}"`,
1504
1643
  id: createdId2,
1505
1644
  name,
1645
+ culture: pageCulture,
1506
1646
  publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
1507
1647
  });
1508
1648
  }
@@ -1510,19 +1650,21 @@ var tool12 = {
1510
1650
  documentTypeId,
1511
1651
  name,
1512
1652
  values: resolved.values,
1653
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1513
1654
  ...parentId ? { parentId } : {}
1514
1655
  });
1515
1656
  if (!createDocumentResult.ok) return createDocumentResult.errorResult;
1516
1657
  const createdId = createDocumentResult.data.id;
1517
1658
  const publishResult = await chainCms("publish-document", {
1518
1659
  id: createdId,
1519
- data: { publishSchedules: [{ culture: null }] }
1660
+ data: { publishSchedules: [{ culture: pageCulture }] }
1520
1661
  });
1521
1662
  if (!publishResult.ok) {
1522
1663
  return createToolResult({
1523
1664
  message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
1524
1665
  id: createdId,
1525
1666
  name,
1667
+ culture: pageCulture,
1526
1668
  publishedUrls: []
1527
1669
  });
1528
1670
  }
@@ -1530,6 +1672,7 @@ var tool12 = {
1530
1672
  message: `Created and published "${name}"`,
1531
1673
  id: createdId,
1532
1674
  name,
1675
+ culture: pageCulture,
1533
1676
  publishedUrls: createdId ? await fetchPublishedUrls(createdId) : []
1534
1677
  });
1535
1678
  }
@@ -4730,11 +4873,11 @@ var tool64 = {
4730
4873
  const headings = extractHeadings(allHtml);
4731
4874
  const images = extractImages(allHtml);
4732
4875
  const bodyWordCount = countWords(extractTextContent(values));
4733
- const extra = doc;
4876
+ const url = await fetchPrimaryPublishedUrl(id);
4734
4877
  return createToolResult({
4735
4878
  id: doc.id,
4736
4879
  name: variant?.name ?? "Unknown",
4737
- url: extra.urls?.[0]?.url ?? "",
4880
+ url,
4738
4881
  hasTitle: title.length > 0,
4739
4882
  hasMetaDescription: metaDescription.length > 0,
4740
4883
  titleLength: title.length,
@@ -4793,12 +4936,12 @@ var tool65 = {
4793
4936
  const fullBodyText = extractTextContent(values);
4794
4937
  const bodyContent = fullBodyText.slice(0, BODY_CONTENT_MAX);
4795
4938
  const wordCount = fullBodyText ? fullBodyText.split(/\s+/).filter(Boolean).length : 0;
4796
- const extra = doc;
4797
4939
  const dt = doc.documentType;
4940
+ const url = await fetchPrimaryPublishedUrl(id);
4798
4941
  return createToolResult({
4799
4942
  id: doc.id,
4800
4943
  name: variant?.name ?? "Unknown",
4801
- url: extra.urls?.[0]?.url ?? "",
4944
+ url,
4802
4945
  hasMetaDescription: metaDescription.length > 0,
4803
4946
  bodyWordCount: wordCount,
4804
4947
  metaDescription,
@@ -4849,6 +4992,9 @@ async function fetchTreeLevel(parentId, depth) {
4849
4992
  }
4850
4993
  async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef, maxDepthRef) {
4851
4994
  const items = await fetchTreeLevel(parentId);
4995
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(
4996
+ items.map((item) => item.id).filter((id) => typeof id === "string")
4997
+ );
4852
4998
  const nodes = [];
4853
4999
  for (const item of items) {
4854
5000
  totalRef.count++;
@@ -4864,7 +5010,7 @@ async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef
4864
5010
  nodes.push({
4865
5011
  id: item.id ?? "",
4866
5012
  name: item.name ?? item.variants?.[0]?.name ?? "Unknown",
4867
- url: item.url ?? item.urls?.[0]?.url ?? "",
5013
+ url: urlsById.get(item.id) ?? "",
4868
5014
  documentType: item.documentType?.name ?? item.contentTypeName ?? "",
4869
5015
  depth,
4870
5016
  childCount: children.length,
@@ -4932,6 +5078,9 @@ var tool67 = {
4932
5078
  if (!result.ok) return;
4933
5079
  const data = result.data;
4934
5080
  const items = data?.items ?? [];
5081
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(
5082
+ items.map((item) => item.id).filter((id) => typeof id === "string")
5083
+ );
4935
5084
  for (const item of items) {
4936
5085
  if (scannedRef.count >= 500) break;
4937
5086
  scannedRef.count++;
@@ -4940,7 +5089,7 @@ var tool67 = {
4940
5089
  allPages.push({
4941
5090
  id: item.id ?? "",
4942
5091
  name,
4943
- url: item.url ?? item.urls?.[0]?.url ?? "",
5092
+ url: urlsById.get(item.id) ?? "",
4944
5093
  documentType: item.documentType?.name ?? item.contentTypeName ?? "",
4945
5094
  depth,
4946
5095
  rawDepth: depth,
@@ -6582,6 +6731,26 @@ var outputSchema93 = z.object({
6582
6731
  ).describe("Pages that reference this item"),
6583
6732
  referenceCount: z.number().describe("Total number of pages referencing this item")
6584
6733
  });
6734
+ async function buildReferencedBy(refItems) {
6735
+ const docRefIds = refItems.filter((ref) => ref.$type === "DocumentReferenceResponseModel").map((ref) => ref.id);
6736
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(docRefIds);
6737
+ return refItems.map((ref) => {
6738
+ if (ref.$type === "DocumentReferenceResponseModel") {
6739
+ return {
6740
+ id: ref.id,
6741
+ name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6742
+ url: urlsById.get(ref.id) ?? "",
6743
+ documentType: ref.documentType?.alias ?? ""
6744
+ };
6745
+ }
6746
+ return {
6747
+ id: ref.id,
6748
+ name: ref.name ?? "(unnamed)",
6749
+ url: "",
6750
+ documentType: ""
6751
+ };
6752
+ });
6753
+ }
6585
6754
  var tool93 = {
6586
6755
  name: "report-content-references",
6587
6756
  description: "Find which pages reference a given content page or media item. Useful before deleting or restructuring content to understand the impact.",
@@ -6596,32 +6765,11 @@ var tool93 = {
6596
6765
  chainCms("get-document-by-id-referenced-by", { id })
6597
6766
  ]);
6598
6767
  let name = "Unknown";
6599
- let url = "";
6600
6768
  if (docResult.ok) {
6601
- const doc = docResult.data;
6602
- name = doc.variants?.[0]?.name ?? "Unknown";
6603
- url = doc.urls?.[0]?.url ?? "";
6604
- }
6605
- const referencedBy = [];
6606
- if (refResult.ok) {
6607
- for (const ref of refResult.data.items ?? []) {
6608
- if (ref.$type === "DocumentReferenceResponseModel") {
6609
- referencedBy.push({
6610
- id: ref.id,
6611
- name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6612
- url: ref.urls?.[0]?.url ?? ref.url ?? "",
6613
- documentType: ref.documentType?.alias ?? ""
6614
- });
6615
- } else {
6616
- referencedBy.push({
6617
- id: ref.id,
6618
- name: ref.name ?? "(unnamed)",
6619
- url: "",
6620
- documentType: ""
6621
- });
6622
- }
6623
- }
6769
+ name = docResult.data.variants?.[0]?.name ?? "Unknown";
6624
6770
  }
6771
+ const url = await fetchPrimaryPublishedUrl(id);
6772
+ const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
6625
6773
  return createToolResult({
6626
6774
  id,
6627
6775
  name,
@@ -6645,26 +6793,7 @@ var tool93 = {
6645
6793
  const entry = urlResult.data.items?.find((u) => u.id === id);
6646
6794
  url = entry?.urlInfos?.[0]?.url ?? "";
6647
6795
  }
6648
- const referencedBy = [];
6649
- if (refResult.ok) {
6650
- for (const ref of refResult.data.items ?? []) {
6651
- if (ref.$type === "DocumentReferenceResponseModel") {
6652
- referencedBy.push({
6653
- id: ref.id,
6654
- name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6655
- url: ref.urls?.[0]?.url ?? ref.url ?? "",
6656
- documentType: ref.documentType?.alias ?? ""
6657
- });
6658
- } else {
6659
- referencedBy.push({
6660
- id: ref.id,
6661
- name: ref.name ?? "(unnamed)",
6662
- url: "",
6663
- documentType: ""
6664
- });
6665
- }
6666
- }
6667
- }
6796
+ const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
6668
6797
  return createToolResult({
6669
6798
  id,
6670
6799
  name,
@@ -6837,18 +6966,18 @@ async function resolveOutboundIds(candidateIds, excludeId) {
6837
6966
  const internalPages = [];
6838
6967
  const media = [];
6839
6968
  const filtered = excludeId ? candidateIds.filter((cid) => cid !== excludeId.toLowerCase()) : candidateIds;
6969
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(filtered);
6840
6970
  await Promise.all(
6841
6971
  filtered.map(async (refId) => {
6842
6972
  try {
6843
6973
  const docResult = await chainCms("get-document-by-id", { id: refId });
6844
6974
  if (docResult.ok) {
6845
6975
  const refDoc = docResult.data;
6846
- const docExtra = refDoc;
6847
6976
  const docType = refDoc.documentType;
6848
6977
  internalPages.push({
6849
6978
  id: refId,
6850
6979
  name: refDoc.variants?.[0]?.name ?? "Unknown",
6851
- url: docExtra.urls?.[0]?.url ?? "",
6980
+ url: urlsById.get(refId) ?? "",
6852
6981
  documentType: docType?.alias ?? ""
6853
6982
  });
6854
6983
  return;
@@ -6922,7 +7051,7 @@ var tool94 = {
6922
7051
  const doc = result.data;
6923
7052
  const variant = doc.variants?.[0];
6924
7053
  const name = variant?.name ?? "Unknown";
6925
- const url = doc.urls?.[0]?.url ?? "";
7054
+ const url = await fetchPrimaryPublishedUrl(id);
6926
7055
  const values = doc.values ?? [];
6927
7056
  const links = extractLinksFromValues(values);
6928
7057
  const { internalPages, media } = await resolveOutboundIds(links.allIds, id);