@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.
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, resetServerConfig, 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: "17.6.0-beta.7"};
12
+ version: "17.6.0-beta.9"};
13
13
 
14
14
  // src/auth/chained-deps.generated.ts
15
15
  var CHAINED_DEPS = {
@@ -33,7 +33,7 @@ var CHAINED_DEPS = {
33
33
  "create-media-folder": ["create-media-folder", "get-media-by-id"],
34
34
  "create-member": ["create-member", "get-member", "update-member"],
35
35
  "create-member-group": ["create-member-group"],
36
- "create-page": ["create-document", "get-data-types-by-id-array", "get-document-type-by-id"],
36
+ "create-page": ["create-document", "get-data-types-by-id-array", "get-document-type-by-id", "get-language"],
37
37
  "create-variant": ["get-document-by-id", "update-document"],
38
38
  "delete-block": ["get-document-by-id", "update-document-properties"],
39
39
  "delete-language": ["delete-language", "get-language-by-iso-code"],
@@ -117,8 +117,9 @@ var CHAINED_DEPS = {
117
117
  "update-member": ["get-member", "update-member"],
118
118
  "upload-media": ["create-media", "get-media-by-id"]
119
119
  };
120
-
121
- // src/config/mcp-servers.ts
120
+ function chainedTlsEnv(baseUrl) {
121
+ return isLoopbackUrl(baseUrl) ? { NODE_TLS_REJECT_UNAUTHORIZED: "0" } : {};
122
+ }
122
123
  async function buildServers() {
123
124
  const isWorkersRuntime = typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers";
124
125
  if (isWorkersRuntime || typeof process === "undefined" || !process.env) return [];
@@ -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
@@ -254,78 +256,21 @@ async function chainCms(toolName, args) {
254
256
  }
255
257
  return { ok: true, data: extractChainedResult(result) };
256
258
  }
257
- function buildChainedCursor(skip, take) {
258
- return encodeCursor({ s: skip, t: take });
259
- }
260
- function stripHtml(html) {
261
- return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
262
- }
263
- function countWords(text) {
264
- const stripped = stripHtml(text);
265
- if (!stripped) return 0;
266
- return stripped.split(/\s+/).filter(Boolean).length;
267
- }
268
- function extractTextFromBlockValues(innerValues) {
269
- const parts = [];
270
- for (const v of innerValues || []) {
271
- const text = extractTextFromValue(v.value, v.editorAlias);
272
- if (text) parts.push(text);
273
- }
274
- return parts.join(" ");
275
- }
276
- function extractTextFromValue(value, editorAlias) {
277
- if (typeof value === "string") {
278
- return stripHtml(value);
279
- }
280
- if (value && typeof value === "object" && typeof value.markup === "string") {
281
- const markupText = stripHtml(value.markup);
282
- const blockText = extractTextFromContentData(value.blocks?.contentData);
283
- return [markupText, blockText].filter(Boolean).join(" ");
284
- }
285
- if (value && typeof value === "object" && Array.isArray(value.contentData)) {
286
- return extractTextFromContentData(value.contentData);
287
- }
288
- return "";
289
- }
290
- function extractTextFromContentData(contentData) {
291
- const parts = [];
292
- for (const block of contentData || []) {
293
- const blockText = extractTextFromBlockValues(block.values || []);
294
- if (blockText) parts.push(blockText);
295
- }
296
- return parts.join(" ");
297
- }
298
- function extractTextContent(values) {
299
- const parts = [];
300
- for (const v of values || []) {
301
- const text = extractTextFromValue(v.value, v.editorAlias);
302
- if (text) parts.push(text);
303
- }
304
- return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
305
- }
306
- function extractHeadings(html) {
307
- const headings = [];
308
- const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
309
- let match;
310
- while ((match = regex.exec(html)) !== null) {
311
- headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
312
- }
313
- return headings;
259
+ var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
260
+ var URL_BATCH_CHUNK_SIZE = 40;
261
+ function describeChainError(errorResult) {
262
+ const problem = extractInnerProblemDetails(errorResult);
263
+ const title = typeof problem.title === "string" ? problem.title : void 0;
264
+ const detail = typeof problem.detail === "string" ? problem.detail : void 0;
265
+ return [title, detail].filter(Boolean).join(": ") || "unknown error";
314
266
  }
315
- function extractImages(html) {
316
- const images = [];
317
- const regex = /<img[^>]*>/gi;
318
- let match;
319
- while ((match = regex.exec(html)) !== null) {
320
- const srcMatch = match[0].match(/src="([^"]*)"/i);
321
- const altMatch = match[0].match(/alt="([^"]*)"/i);
322
- const src = srcMatch?.[1] ?? "";
323
- const alt = altMatch?.[1] ?? "";
324
- images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
267
+ function chunkIds(ids, size) {
268
+ const chunks = [];
269
+ for (let i = 0; i < ids.length; i += size) {
270
+ chunks.push(ids.slice(i, i + size));
325
271
  }
326
- return images;
272
+ return chunks;
327
273
  }
328
- var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
329
274
  var cachedBaseUrl = null;
330
275
  var cachedMtimeMs = null;
331
276
  function readBaseUrlFromEnvFile(envPath) {
@@ -431,27 +376,132 @@ function flattenPublishedUrls(urls) {
431
376
  async function fetchPublishedUrls(id) {
432
377
  try {
433
378
  const result = await chainCms("get-document-urls", { id: [id] });
434
- if (!result.ok) return [];
379
+ if (!result.ok) {
380
+ console.warn(
381
+ `fetchPublishedUrls: get-document-urls failed for id ${id} \u2014 returning no published URLs: ${describeChainError(result.errorResult)}`
382
+ );
383
+ return [];
384
+ }
435
385
  return flattenPublishedUrls(result.data.items);
436
- } catch {
386
+ } catch (error) {
387
+ const message = error instanceof Error ? error.message : String(error);
388
+ console.warn(
389
+ `fetchPublishedUrls: unexpected error fetching published URLs for id ${id} \u2014 returning no published URLs: ${message}`
390
+ );
437
391
  return [];
438
392
  }
439
393
  }
440
394
  async function fetchPublishedUrlsBatch(ids) {
441
395
  const out = /* @__PURE__ */ new Map();
442
396
  if (ids.length === 0) return out;
443
- try {
444
- const result = await chainCms("get-document-urls", { id: ids });
445
- if (!result.ok) return out;
446
- for (const entry of result.data.items ?? []) {
447
- if (!entry?.id) continue;
448
- out.set(entry.id, flattenPublishedUrls([entry]));
397
+ for (const idChunk of chunkIds(ids, URL_BATCH_CHUNK_SIZE)) {
398
+ try {
399
+ const result = await chainCms("get-document-urls", { id: idChunk });
400
+ if (!result.ok) {
401
+ console.warn(
402
+ `fetchPublishedUrlsBatch: get-document-urls failed for a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${describeChainError(result.errorResult)}`
403
+ );
404
+ continue;
405
+ }
406
+ for (const entry of result.data.items ?? []) {
407
+ if (!entry?.id) continue;
408
+ out.set(entry.id, flattenPublishedUrls([entry]));
409
+ }
410
+ } catch (error) {
411
+ const message = error instanceof Error ? error.message : String(error);
412
+ console.warn(
413
+ `fetchPublishedUrlsBatch: unexpected error processing a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${message}`
414
+ );
449
415
  }
450
- } catch {
416
+ }
417
+ return out;
418
+ }
419
+ async function fetchPrimaryPublishedUrl(id) {
420
+ const urls = await fetchPublishedUrls(id);
421
+ return urls[0] ?? "";
422
+ }
423
+ async function fetchPrimaryPublishedUrlsBatch(ids) {
424
+ const batch = await fetchPublishedUrlsBatch(ids);
425
+ const out = /* @__PURE__ */ new Map();
426
+ for (const id of ids) {
427
+ out.set(id, batch.get(id)?.[0] ?? "");
451
428
  }
452
429
  return out;
453
430
  }
454
431
 
432
+ // src/umbraco-api/tools/helpers/tree-walker.ts
433
+ function buildChainedCursor(skip, take) {
434
+ return encodeCursor({ s: skip, t: take });
435
+ }
436
+ function stripHtml(html) {
437
+ return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
438
+ }
439
+ function countWords(text) {
440
+ const stripped = stripHtml(text);
441
+ if (!stripped) return 0;
442
+ return stripped.split(/\s+/).filter(Boolean).length;
443
+ }
444
+ function extractTextFromBlockValues(innerValues) {
445
+ const parts = [];
446
+ for (const v of innerValues || []) {
447
+ const text = extractTextFromValue(v.value, v.editorAlias);
448
+ if (text) parts.push(text);
449
+ }
450
+ return parts.join(" ");
451
+ }
452
+ function extractTextFromValue(value, editorAlias) {
453
+ if (typeof value === "string") {
454
+ return stripHtml(value);
455
+ }
456
+ if (value && typeof value === "object" && typeof value.markup === "string") {
457
+ const markupText = stripHtml(value.markup);
458
+ const blockText = extractTextFromContentData(value.blocks?.contentData);
459
+ return [markupText, blockText].filter(Boolean).join(" ");
460
+ }
461
+ if (value && typeof value === "object" && Array.isArray(value.contentData)) {
462
+ return extractTextFromContentData(value.contentData);
463
+ }
464
+ return "";
465
+ }
466
+ function extractTextFromContentData(contentData) {
467
+ const parts = [];
468
+ for (const block of contentData || []) {
469
+ const blockText = extractTextFromBlockValues(block.values || []);
470
+ if (blockText) parts.push(blockText);
471
+ }
472
+ return parts.join(" ");
473
+ }
474
+ function extractTextContent(values) {
475
+ const parts = [];
476
+ for (const v of values || []) {
477
+ const text = extractTextFromValue(v.value, v.editorAlias);
478
+ if (text) parts.push(text);
479
+ }
480
+ return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
481
+ }
482
+ function extractHeadings(html) {
483
+ const headings = [];
484
+ const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
485
+ let match;
486
+ while ((match = regex.exec(html)) !== null) {
487
+ headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
488
+ }
489
+ return headings;
490
+ }
491
+ function extractImages(html) {
492
+ const images = [];
493
+ const regex = /<img[^>]*>/gi;
494
+ let match;
495
+ while ((match = regex.exec(html)) !== null) {
496
+ const srcMatch = match[0].match(/src="([^"]*)"/i);
497
+ const altMatch = match[0].match(/alt="([^"]*)"/i);
498
+ const src = srcMatch?.[1] ?? "";
499
+ const alt = altMatch?.[1] ?? "";
500
+ images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
501
+ }
502
+ return images;
503
+ }
504
+
455
505
  // src/umbraco-api/tools/content/get/search-content.ts
456
506
  var inputSchema = {
457
507
  query: z.string().describe("Search term to find content pages"),
@@ -469,7 +519,7 @@ var outputSchema = z.object({
469
519
  });
470
520
  var tool = {
471
521
  name: "search-content",
472
- 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.",
522
+ 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.",
473
523
  inputSchema,
474
524
  outputSchema,
475
525
  slices: ["search"],
@@ -545,8 +595,10 @@ var tool2 = {
545
595
  })),
546
596
  variants: doc.variants ?? [],
547
597
  previewUrl: buildPreviewUrl(doc.id),
548
- // GetDocumentByIdOutput doesn't include `urls` — runtime field, not in the upstream Zod schema.
549
- publishedUrls: flattenPublishedUrls(doc.urls)
598
+ // The get-document-by-id response doesn't carry `urls` — published
599
+ // URLs come only from the separate get-document-urls endpoint via
600
+ // fetchPublishedUrls.
601
+ publishedUrls: await fetchPublishedUrls(id)
550
602
  });
551
603
  }
552
604
  };
@@ -712,10 +764,15 @@ var tool4 = {
712
764
  var list_document_types_default = withStandardDecorators(tool4);
713
765
 
714
766
  // src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
715
- async function resolveDocumentTypeProperties(documentTypeId) {
716
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
717
- if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
718
- const data = docTypeResult.data;
767
+ async function resolveDocumentTypeProperties(documentTypeId, documentType) {
768
+ let data;
769
+ if (documentType) {
770
+ data = documentType;
771
+ } else {
772
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
773
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
774
+ data = docTypeResult.data;
775
+ }
719
776
  const collected = /* @__PURE__ */ new Map();
720
777
  function addProperties(props) {
721
778
  for (const p of props) {
@@ -1454,11 +1511,11 @@ ${aliases.join("\n")}`
1454
1511
  }
1455
1512
  };
1456
1513
  var get_property_value_template_default = withStandardDecorators(tool10);
1457
- async function resolveEditorAliases(documentTypeId, values) {
1514
+ async function resolveEditorAliases(documentTypeId, values, { defaultCulture = null, documentType, siteCultures } = {}) {
1458
1515
  if (!values || values.length === 0) {
1459
1516
  return { ok: true, values: [] };
1460
1517
  }
1461
- const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
1518
+ const docTypeResult = await resolveDocumentTypeProperties(documentTypeId, documentType);
1462
1519
  if (!docTypeResult.ok) return docTypeResult;
1463
1520
  const dataTypeIds = Array.from(
1464
1521
  new Set(
@@ -1477,22 +1534,32 @@ async function resolveEditorAliases(documentTypeId, values) {
1477
1534
  docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
1478
1535
  );
1479
1536
  const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1537
+ const cultureVariantAliases = /* @__PURE__ */ new Set();
1480
1538
  for (const prop of docTypeResult.properties) {
1481
1539
  const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
1482
1540
  if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1541
+ if (prop.alias && prop.variesByCulture) cultureVariantAliases.add(prop.alias);
1483
1542
  }
1484
1543
  const notAProperty = /* @__PURE__ */ new Set();
1485
1544
  const missingEditorAlias = /* @__PURE__ */ new Set();
1545
+ const unknownCultures = /* @__PURE__ */ new Set();
1486
1546
  const resolved = values.map((v) => {
1487
1547
  const editorAlias = editorAliasByPropertyAlias.get(v.alias);
1488
1548
  if (!editorAlias) {
1489
1549
  if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
1490
1550
  else notAProperty.add(v.alias);
1491
1551
  }
1552
+ let culture = v.culture ?? (cultureVariantAliases.has(v.alias) ? defaultCulture : null);
1553
+ if (v.culture && siteCultures) {
1554
+ const requested = v.culture.toLowerCase();
1555
+ const match = siteCultures.find((c) => c.toLowerCase() === requested);
1556
+ if (match) culture = match;
1557
+ else unknownCultures.add(v.culture);
1558
+ }
1492
1559
  return {
1493
1560
  alias: v.alias,
1494
1561
  value: v.value,
1495
- culture: v.culture ?? null,
1562
+ culture,
1496
1563
  segment: v.segment ?? null,
1497
1564
  editorAlias: editorAlias ?? ""
1498
1565
  };
@@ -1523,14 +1590,74 @@ async function resolveEditorAliases(documentTypeId, values) {
1523
1590
  )
1524
1591
  };
1525
1592
  }
1593
+ if (unknownCultures.size > 0 && siteCultures) {
1594
+ return {
1595
+ ok: false,
1596
+ errorResult: createToolResultError(
1597
+ `The following value culture(s) are not languages on this site: ${Array.from(unknownCultures).join(", ")}. Available cultures: ${siteCultures.join(", ")}.`
1598
+ )
1599
+ };
1600
+ }
1526
1601
  return { ok: true, values: resolved };
1527
1602
  }
1603
+ var LANGUAGE_PAGE_SIZE = 100;
1604
+ async function resolvePageCulture(documentTypeId, culture, { forPublish = false } = {}) {
1605
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1606
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
1607
+ const documentType = docTypeResult.data;
1608
+ if (!documentType.variesByCulture) {
1609
+ return { ok: true, culture: null, documentType };
1610
+ }
1611
+ const langResult = await chainCms("get-language", { cursor: encodeCursor({ s: 0, t: LANGUAGE_PAGE_SIZE }) });
1612
+ if (!langResult.ok) return { ok: false, errorResult: langResult.errorResult };
1613
+ const languages = langResult.data.items ?? [];
1614
+ const complete = (langResult.data.total ?? languages.length) <= languages.length;
1615
+ const siteCultures = languages.map((l) => l.isoCode);
1616
+ let pageCulture;
1617
+ if (culture) {
1618
+ const match = siteCultures.find((c) => c.toLowerCase() === culture.toLowerCase());
1619
+ if (!match && complete) {
1620
+ return {
1621
+ ok: false,
1622
+ errorResult: createToolResultError(
1623
+ `Culture "${culture}" is not a language on this site. Available cultures: ${siteCultures.join(", ")}.`
1624
+ )
1625
+ };
1626
+ }
1627
+ pageCulture = match ?? culture;
1628
+ } else {
1629
+ const defaultLanguage = languages.find((l) => l.isDefault);
1630
+ if (!defaultLanguage?.isoCode) {
1631
+ return {
1632
+ ok: false,
1633
+ errorResult: createToolResultError(
1634
+ "This document type varies by culture, but no default language could be determined. Call list-languages and pass `culture` explicitly."
1635
+ )
1636
+ };
1637
+ }
1638
+ pageCulture = defaultLanguage.isoCode;
1639
+ }
1640
+ if (forPublish) {
1641
+ const missingMandatory = languages.filter((l) => l.isMandatory && l.isoCode !== pageCulture).map((l) => l.isoCode);
1642
+ if (missingMandatory.length > 0) {
1643
+ const one = missingMandatory.length === 1;
1644
+ return {
1645
+ ok: false,
1646
+ errorResult: createToolResultError(
1647
+ `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.`
1648
+ )
1649
+ };
1650
+ }
1651
+ }
1652
+ return { ok: true, culture: pageCulture, documentType, siteCultures: complete ? siteCultures : void 0 };
1653
+ }
1528
1654
 
1529
1655
  // src/umbraco-api/tools/content/post/create-page.ts
1530
1656
  var inputSchema11 = {
1531
1657
  name: z.string().describe("The name of the page to create"),
1532
1658
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1533
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."),
1534
1661
  values: z.array(z.object({
1535
1662
  alias: z.string().describe("The property alias"),
1536
1663
  value: z.any().describe("The property value"),
@@ -1542,23 +1669,28 @@ var outputSchema11 = z.object({
1542
1669
  message: z.string(),
1543
1670
  id: z.string(),
1544
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."),
1545
1673
  previewUrl: previewUrlSchema,
1546
1674
  validation: validationResultSchema
1547
1675
  });
1548
1676
  var tool11 = {
1549
1677
  name: "create-page",
1550
- 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.).",
1678
+ 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.",
1551
1679
  inputSchema: inputSchema11,
1552
1680
  outputSchema: outputSchema11,
1553
1681
  slices: ["create"],
1554
1682
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1555
- handler: async ({ name, documentTypeId, parentId, values }) => {
1556
- const resolved = await resolveEditorAliases(documentTypeId, values);
1683
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1684
+ const cultureResult = await resolvePageCulture(documentTypeId, culture);
1685
+ if (!cultureResult.ok) return cultureResult.errorResult;
1686
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1687
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1557
1688
  if (!resolved.ok) return resolved.errorResult;
1558
1689
  const createResult = await chainCms("create-document", {
1559
1690
  documentTypeId,
1560
1691
  name,
1561
1692
  values: resolved.values,
1693
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1562
1694
  ...parentId ? { parentId } : {}
1563
1695
  });
1564
1696
  if (!createResult.ok) return createResult.errorResult;
@@ -1570,6 +1702,7 @@ var tool11 = {
1570
1702
  message,
1571
1703
  id: createdId,
1572
1704
  name,
1705
+ culture: pageCulture,
1573
1706
  previewUrl: createdId ? await fetchPreviewUrl(createdId) : null,
1574
1707
  validation
1575
1708
  });
@@ -1580,6 +1713,7 @@ var inputSchema12 = {
1580
1713
  name: z.string().describe("The name of the page to create"),
1581
1714
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1582
1715
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1716
+ 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."),
1583
1717
  values: z.array(z.object({
1584
1718
  alias: z.string().describe("The property alias"),
1585
1719
  value: z.any().describe("The property value"),
@@ -1591,23 +1725,28 @@ var outputSchema12 = z.object({
1591
1725
  message: z.string(),
1592
1726
  id: z.string(),
1593
1727
  name: z.string(),
1728
+ 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."),
1594
1729
  publishedUrls: publishedUrlsSchema
1595
1730
  });
1596
1731
  var tool12 = {
1597
1732
  name: "create-and-publish-page",
1598
- 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.",
1733
+ 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.",
1599
1734
  inputSchema: inputSchema12,
1600
1735
  outputSchema: outputSchema12,
1601
1736
  slices: ["create", "publish"],
1602
1737
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1603
- handler: async ({ name, documentTypeId, parentId, values }) => {
1604
- const resolved = await resolveEditorAliases(documentTypeId, values);
1738
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1739
+ const cultureResult = await resolvePageCulture(documentTypeId, culture, { forPublish: true });
1740
+ if (!cultureResult.ok) return cultureResult.errorResult;
1741
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1742
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1605
1743
  if (!resolved.ok) return resolved.errorResult;
1606
1744
  if (await isCmsToolAvailable("create-and-publish-document")) {
1607
1745
  const createResult = await chainCms("create-and-publish-document", {
1608
1746
  documentTypeId,
1609
1747
  name,
1610
1748
  values: resolved.values,
1749
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1611
1750
  ...parentId ? { parentId } : {}
1612
1751
  });
1613
1752
  if (!createResult.ok) return createResult.errorResult;
@@ -1616,6 +1755,7 @@ var tool12 = {
1616
1755
  message: `Created and published "${name}"`,
1617
1756
  id: createdId2,
1618
1757
  name,
1758
+ culture: pageCulture,
1619
1759
  publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
1620
1760
  });
1621
1761
  }
@@ -1623,19 +1763,21 @@ var tool12 = {
1623
1763
  documentTypeId,
1624
1764
  name,
1625
1765
  values: resolved.values,
1766
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1626
1767
  ...parentId ? { parentId } : {}
1627
1768
  });
1628
1769
  if (!createDocumentResult.ok) return createDocumentResult.errorResult;
1629
1770
  const createdId = createDocumentResult.data.id;
1630
1771
  const publishResult = await chainCms("publish-document", {
1631
1772
  id: createdId,
1632
- data: { publishSchedules: [{ culture: null }] }
1773
+ data: { publishSchedules: [{ culture: pageCulture }] }
1633
1774
  });
1634
1775
  if (!publishResult.ok) {
1635
1776
  return createToolResult({
1636
1777
  message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
1637
1778
  id: createdId,
1638
1779
  name,
1780
+ culture: pageCulture,
1639
1781
  publishedUrls: []
1640
1782
  });
1641
1783
  }
@@ -1643,6 +1785,7 @@ var tool12 = {
1643
1785
  message: `Created and published "${name}"`,
1644
1786
  id: createdId,
1645
1787
  name,
1788
+ culture: pageCulture,
1646
1789
  publishedUrls: createdId ? await fetchPublishedUrls(createdId) : []
1647
1790
  });
1648
1791
  }
@@ -4843,11 +4986,11 @@ var tool64 = {
4843
4986
  const headings = extractHeadings(allHtml);
4844
4987
  const images = extractImages(allHtml);
4845
4988
  const bodyWordCount = countWords(extractTextContent(values));
4846
- const extra = doc;
4989
+ const url = await fetchPrimaryPublishedUrl(id);
4847
4990
  return createToolResult({
4848
4991
  id: doc.id,
4849
4992
  name: variant?.name ?? "Unknown",
4850
- url: extra.urls?.[0]?.url ?? "",
4993
+ url,
4851
4994
  hasTitle: title.length > 0,
4852
4995
  hasMetaDescription: metaDescription.length > 0,
4853
4996
  titleLength: title.length,
@@ -4906,12 +5049,12 @@ var tool65 = {
4906
5049
  const fullBodyText = extractTextContent(values);
4907
5050
  const bodyContent = fullBodyText.slice(0, BODY_CONTENT_MAX);
4908
5051
  const wordCount = fullBodyText ? fullBodyText.split(/\s+/).filter(Boolean).length : 0;
4909
- const extra = doc;
4910
5052
  const dt = doc.documentType;
5053
+ const url = await fetchPrimaryPublishedUrl(id);
4911
5054
  return createToolResult({
4912
5055
  id: doc.id,
4913
5056
  name: variant?.name ?? "Unknown",
4914
- url: extra.urls?.[0]?.url ?? "",
5057
+ url,
4915
5058
  hasMetaDescription: metaDescription.length > 0,
4916
5059
  bodyWordCount: wordCount,
4917
5060
  metaDescription,
@@ -4962,6 +5105,9 @@ async function fetchTreeLevel(parentId, depth) {
4962
5105
  }
4963
5106
  async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef, maxDepthRef) {
4964
5107
  const items = await fetchTreeLevel(parentId);
5108
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(
5109
+ items.map((item) => item.id).filter((id) => typeof id === "string")
5110
+ );
4965
5111
  const nodes = [];
4966
5112
  for (const item of items) {
4967
5113
  totalRef.count++;
@@ -4977,7 +5123,7 @@ async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef
4977
5123
  nodes.push({
4978
5124
  id: item.id ?? "",
4979
5125
  name: item.name ?? item.variants?.[0]?.name ?? "Unknown",
4980
- url: item.url ?? item.urls?.[0]?.url ?? "",
5126
+ url: urlsById.get(item.id) ?? "",
4981
5127
  documentType: item.documentType?.name ?? item.contentTypeName ?? "",
4982
5128
  depth,
4983
5129
  childCount: children.length,
@@ -5045,6 +5191,9 @@ var tool67 = {
5045
5191
  if (!result.ok) return;
5046
5192
  const data = result.data;
5047
5193
  const items = data?.items ?? [];
5194
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(
5195
+ items.map((item) => item.id).filter((id) => typeof id === "string")
5196
+ );
5048
5197
  for (const item of items) {
5049
5198
  if (scannedRef.count >= 500) break;
5050
5199
  scannedRef.count++;
@@ -5053,7 +5202,7 @@ var tool67 = {
5053
5202
  allPages.push({
5054
5203
  id: item.id ?? "",
5055
5204
  name,
5056
- url: item.url ?? item.urls?.[0]?.url ?? "",
5205
+ url: urlsById.get(item.id) ?? "",
5057
5206
  documentType: item.documentType?.name ?? item.contentTypeName ?? "",
5058
5207
  depth,
5059
5208
  rawDepth: depth,
@@ -6695,6 +6844,26 @@ var outputSchema93 = z.object({
6695
6844
  ).describe("Pages that reference this item"),
6696
6845
  referenceCount: z.number().describe("Total number of pages referencing this item")
6697
6846
  });
6847
+ async function buildReferencedBy(refItems) {
6848
+ const docRefIds = refItems.filter((ref) => ref.$type === "DocumentReferenceResponseModel").map((ref) => ref.id);
6849
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(docRefIds);
6850
+ return refItems.map((ref) => {
6851
+ if (ref.$type === "DocumentReferenceResponseModel") {
6852
+ return {
6853
+ id: ref.id,
6854
+ name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6855
+ url: urlsById.get(ref.id) ?? "",
6856
+ documentType: ref.documentType?.alias ?? ""
6857
+ };
6858
+ }
6859
+ return {
6860
+ id: ref.id,
6861
+ name: ref.name ?? "(unnamed)",
6862
+ url: "",
6863
+ documentType: ""
6864
+ };
6865
+ });
6866
+ }
6698
6867
  var tool93 = {
6699
6868
  name: "report-content-references",
6700
6869
  description: "Find which pages reference a given content page or media item. Useful before deleting or restructuring content to understand the impact.",
@@ -6709,32 +6878,11 @@ var tool93 = {
6709
6878
  chainCms("get-document-by-id-referenced-by", { id })
6710
6879
  ]);
6711
6880
  let name = "Unknown";
6712
- let url = "";
6713
6881
  if (docResult.ok) {
6714
- const doc = docResult.data;
6715
- name = doc.variants?.[0]?.name ?? "Unknown";
6716
- url = doc.urls?.[0]?.url ?? "";
6717
- }
6718
- const referencedBy = [];
6719
- if (refResult.ok) {
6720
- for (const ref of refResult.data.items ?? []) {
6721
- if (ref.$type === "DocumentReferenceResponseModel") {
6722
- referencedBy.push({
6723
- id: ref.id,
6724
- name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6725
- url: ref.urls?.[0]?.url ?? ref.url ?? "",
6726
- documentType: ref.documentType?.alias ?? ""
6727
- });
6728
- } else {
6729
- referencedBy.push({
6730
- id: ref.id,
6731
- name: ref.name ?? "(unnamed)",
6732
- url: "",
6733
- documentType: ""
6734
- });
6735
- }
6736
- }
6882
+ name = docResult.data.variants?.[0]?.name ?? "Unknown";
6737
6883
  }
6884
+ const url = await fetchPrimaryPublishedUrl(id);
6885
+ const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
6738
6886
  return createToolResult({
6739
6887
  id,
6740
6888
  name,
@@ -6758,26 +6906,7 @@ var tool93 = {
6758
6906
  const entry = urlResult.data.items?.find((u) => u.id === id);
6759
6907
  url = entry?.urlInfos?.[0]?.url ?? "";
6760
6908
  }
6761
- const referencedBy = [];
6762
- if (refResult.ok) {
6763
- for (const ref of refResult.data.items ?? []) {
6764
- if (ref.$type === "DocumentReferenceResponseModel") {
6765
- referencedBy.push({
6766
- id: ref.id,
6767
- name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6768
- url: ref.urls?.[0]?.url ?? ref.url ?? "",
6769
- documentType: ref.documentType?.alias ?? ""
6770
- });
6771
- } else {
6772
- referencedBy.push({
6773
- id: ref.id,
6774
- name: ref.name ?? "(unnamed)",
6775
- url: "",
6776
- documentType: ""
6777
- });
6778
- }
6779
- }
6780
- }
6909
+ const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
6781
6910
  return createToolResult({
6782
6911
  id,
6783
6912
  name,
@@ -6950,18 +7079,18 @@ async function resolveOutboundIds(candidateIds, excludeId) {
6950
7079
  const internalPages = [];
6951
7080
  const media = [];
6952
7081
  const filtered = excludeId ? candidateIds.filter((cid) => cid !== excludeId.toLowerCase()) : candidateIds;
7082
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(filtered);
6953
7083
  await Promise.all(
6954
7084
  filtered.map(async (refId) => {
6955
7085
  try {
6956
7086
  const docResult = await chainCms("get-document-by-id", { id: refId });
6957
7087
  if (docResult.ok) {
6958
7088
  const refDoc = docResult.data;
6959
- const docExtra = refDoc;
6960
7089
  const docType = refDoc.documentType;
6961
7090
  internalPages.push({
6962
7091
  id: refId,
6963
7092
  name: refDoc.variants?.[0]?.name ?? "Unknown",
6964
- url: docExtra.urls?.[0]?.url ?? "",
7093
+ url: urlsById.get(refId) ?? "",
6965
7094
  documentType: docType?.alias ?? ""
6966
7095
  });
6967
7096
  return;
@@ -7035,7 +7164,7 @@ var tool94 = {
7035
7164
  const doc = result.data;
7036
7165
  const variant = doc.variants?.[0];
7037
7166
  const name = variant?.name ?? "Unknown";
7038
- const url = doc.urls?.[0]?.url ?? "";
7167
+ const url = await fetchPrimaryPublishedUrl(id);
7039
7168
  const values = doc.values ?? [];
7040
7169
  const links = extractLinksFromValues(values);
7041
7170
  const { internalPages, media } = await resolveOutboundIds(links.allIds, id);
@@ -7756,6 +7885,16 @@ async function loadServerConfig(isStdioMode) {
7756
7885
  }
7757
7886
  function clearConfigCache() {
7758
7887
  cachedConfig = null;
7888
+ resetServerConfig();
7889
+ }
7890
+
7891
+ // src/config/apply-filter-config.ts
7892
+ function applyFilterConfig(umbracoConfig, manager) {
7893
+ manager.setFilterConfig({
7894
+ readOnly: umbracoConfig.readonly,
7895
+ slices: umbracoConfig.includeSlices,
7896
+ excludeSlices: umbracoConfig.excludeSlices
7897
+ });
7759
7898
  }
7760
7899
 
7761
7900
  // src/server-instructions.ts
@@ -7888,6 +8027,7 @@ async function main() {
7888
8027
  if (chainingEnabled) {
7889
8028
  console.error("MCP chaining enabled \u2014 pre-connecting to chained servers...");
7890
8029
  try {
8030
+ applyFilterConfig(serverConfig.umbraco, mcpClientManager);
7891
8031
  for (const srv of mcpServers) {
7892
8032
  await mcpClientManager.connect(srv.name);
7893
8033
  console.error(`Connected to chained server: ${srv.name}`);