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

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
@@ -9,7 +9,7 @@ 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.8"};
13
13
 
14
14
  // src/auth/chained-deps.generated.ts
15
15
  var CHAINED_DEPS = {
@@ -254,78 +254,21 @@ async function chainCms(toolName, args) {
254
254
  }
255
255
  return { ok: true, data: extractChainedResult(result) };
256
256
  }
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;
257
+ var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
258
+ var URL_BATCH_CHUNK_SIZE = 40;
259
+ function describeChainError(errorResult) {
260
+ const problem = extractInnerProblemDetails(errorResult);
261
+ const title = typeof problem.title === "string" ? problem.title : void 0;
262
+ const detail = typeof problem.detail === "string" ? problem.detail : void 0;
263
+ return [title, detail].filter(Boolean).join(": ") || "unknown error";
314
264
  }
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 });
265
+ function chunkIds(ids, size) {
266
+ const chunks = [];
267
+ for (let i = 0; i < ids.length; i += size) {
268
+ chunks.push(ids.slice(i, i + size));
325
269
  }
326
- return images;
270
+ return chunks;
327
271
  }
328
- var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
329
272
  var cachedBaseUrl = null;
330
273
  var cachedMtimeMs = null;
331
274
  function readBaseUrlFromEnvFile(envPath) {
@@ -431,26 +374,131 @@ function flattenPublishedUrls(urls) {
431
374
  async function fetchPublishedUrls(id) {
432
375
  try {
433
376
  const result = await chainCms("get-document-urls", { id: [id] });
434
- if (!result.ok) return [];
377
+ if (!result.ok) {
378
+ console.warn(
379
+ `fetchPublishedUrls: get-document-urls failed for id ${id} \u2014 returning no published URLs: ${describeChainError(result.errorResult)}`
380
+ );
381
+ return [];
382
+ }
435
383
  return flattenPublishedUrls(result.data.items);
436
- } catch {
384
+ } catch (error) {
385
+ const message = error instanceof Error ? error.message : String(error);
386
+ console.warn(
387
+ `fetchPublishedUrls: unexpected error fetching published URLs for id ${id} \u2014 returning no published URLs: ${message}`
388
+ );
437
389
  return [];
438
390
  }
439
391
  }
440
392
  async function fetchPublishedUrlsBatch(ids) {
441
393
  const out = /* @__PURE__ */ new Map();
442
394
  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]));
395
+ for (const idChunk of chunkIds(ids, URL_BATCH_CHUNK_SIZE)) {
396
+ try {
397
+ const result = await chainCms("get-document-urls", { id: idChunk });
398
+ if (!result.ok) {
399
+ console.warn(
400
+ `fetchPublishedUrlsBatch: get-document-urls failed for a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${describeChainError(result.errorResult)}`
401
+ );
402
+ continue;
403
+ }
404
+ for (const entry of result.data.items ?? []) {
405
+ if (!entry?.id) continue;
406
+ out.set(entry.id, flattenPublishedUrls([entry]));
407
+ }
408
+ } catch (error) {
409
+ const message = error instanceof Error ? error.message : String(error);
410
+ console.warn(
411
+ `fetchPublishedUrlsBatch: unexpected error processing a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${message}`
412
+ );
449
413
  }
450
- } catch {
451
414
  }
452
415
  return out;
453
416
  }
417
+ async function fetchPrimaryPublishedUrl(id) {
418
+ const urls = await fetchPublishedUrls(id);
419
+ return urls[0] ?? "";
420
+ }
421
+ async function fetchPrimaryPublishedUrlsBatch(ids) {
422
+ const batch = await fetchPublishedUrlsBatch(ids);
423
+ const out = /* @__PURE__ */ new Map();
424
+ for (const id of ids) {
425
+ out.set(id, batch.get(id)?.[0] ?? "");
426
+ }
427
+ return out;
428
+ }
429
+
430
+ // src/umbraco-api/tools/helpers/tree-walker.ts
431
+ function buildChainedCursor(skip, take) {
432
+ return encodeCursor({ s: skip, t: take });
433
+ }
434
+ function stripHtml(html) {
435
+ return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
436
+ }
437
+ function countWords(text) {
438
+ const stripped = stripHtml(text);
439
+ if (!stripped) return 0;
440
+ return stripped.split(/\s+/).filter(Boolean).length;
441
+ }
442
+ function extractTextFromBlockValues(innerValues) {
443
+ const parts = [];
444
+ for (const v of innerValues || []) {
445
+ const text = extractTextFromValue(v.value, v.editorAlias);
446
+ if (text) parts.push(text);
447
+ }
448
+ return parts.join(" ");
449
+ }
450
+ function extractTextFromValue(value, editorAlias) {
451
+ if (typeof value === "string") {
452
+ return stripHtml(value);
453
+ }
454
+ if (value && typeof value === "object" && typeof value.markup === "string") {
455
+ const markupText = stripHtml(value.markup);
456
+ const blockText = extractTextFromContentData(value.blocks?.contentData);
457
+ return [markupText, blockText].filter(Boolean).join(" ");
458
+ }
459
+ if (value && typeof value === "object" && Array.isArray(value.contentData)) {
460
+ return extractTextFromContentData(value.contentData);
461
+ }
462
+ return "";
463
+ }
464
+ function extractTextFromContentData(contentData) {
465
+ const parts = [];
466
+ for (const block of contentData || []) {
467
+ const blockText = extractTextFromBlockValues(block.values || []);
468
+ if (blockText) parts.push(blockText);
469
+ }
470
+ return parts.join(" ");
471
+ }
472
+ function extractTextContent(values) {
473
+ const parts = [];
474
+ for (const v of values || []) {
475
+ const text = extractTextFromValue(v.value, v.editorAlias);
476
+ if (text) parts.push(text);
477
+ }
478
+ return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
479
+ }
480
+ function extractHeadings(html) {
481
+ const headings = [];
482
+ const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
483
+ let match;
484
+ while ((match = regex.exec(html)) !== null) {
485
+ headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
486
+ }
487
+ return headings;
488
+ }
489
+ function extractImages(html) {
490
+ const images = [];
491
+ const regex = /<img[^>]*>/gi;
492
+ let match;
493
+ while ((match = regex.exec(html)) !== null) {
494
+ const srcMatch = match[0].match(/src="([^"]*)"/i);
495
+ const altMatch = match[0].match(/alt="([^"]*)"/i);
496
+ const src = srcMatch?.[1] ?? "";
497
+ const alt = altMatch?.[1] ?? "";
498
+ images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
499
+ }
500
+ return images;
501
+ }
454
502
 
455
503
  // src/umbraco-api/tools/content/get/search-content.ts
456
504
  var inputSchema = {
@@ -469,7 +517,7 @@ var outputSchema = z.object({
469
517
  });
470
518
  var tool = {
471
519
  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.",
520
+ 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
521
  inputSchema,
474
522
  outputSchema,
475
523
  slices: ["search"],
@@ -545,8 +593,10 @@ var tool2 = {
545
593
  })),
546
594
  variants: doc.variants ?? [],
547
595
  previewUrl: buildPreviewUrl(doc.id),
548
- // GetDocumentByIdOutput doesn't include `urls` — runtime field, not in the upstream Zod schema.
549
- publishedUrls: flattenPublishedUrls(doc.urls)
596
+ // The get-document-by-id response doesn't carry `urls` — published
597
+ // URLs come only from the separate get-document-urls endpoint via
598
+ // fetchPublishedUrls.
599
+ publishedUrls: await fetchPublishedUrls(id)
550
600
  });
551
601
  }
552
602
  };
@@ -4843,11 +4893,11 @@ var tool64 = {
4843
4893
  const headings = extractHeadings(allHtml);
4844
4894
  const images = extractImages(allHtml);
4845
4895
  const bodyWordCount = countWords(extractTextContent(values));
4846
- const extra = doc;
4896
+ const url = await fetchPrimaryPublishedUrl(id);
4847
4897
  return createToolResult({
4848
4898
  id: doc.id,
4849
4899
  name: variant?.name ?? "Unknown",
4850
- url: extra.urls?.[0]?.url ?? "",
4900
+ url,
4851
4901
  hasTitle: title.length > 0,
4852
4902
  hasMetaDescription: metaDescription.length > 0,
4853
4903
  titleLength: title.length,
@@ -4906,12 +4956,12 @@ var tool65 = {
4906
4956
  const fullBodyText = extractTextContent(values);
4907
4957
  const bodyContent = fullBodyText.slice(0, BODY_CONTENT_MAX);
4908
4958
  const wordCount = fullBodyText ? fullBodyText.split(/\s+/).filter(Boolean).length : 0;
4909
- const extra = doc;
4910
4959
  const dt = doc.documentType;
4960
+ const url = await fetchPrimaryPublishedUrl(id);
4911
4961
  return createToolResult({
4912
4962
  id: doc.id,
4913
4963
  name: variant?.name ?? "Unknown",
4914
- url: extra.urls?.[0]?.url ?? "",
4964
+ url,
4915
4965
  hasMetaDescription: metaDescription.length > 0,
4916
4966
  bodyWordCount: wordCount,
4917
4967
  metaDescription,
@@ -4962,6 +5012,9 @@ async function fetchTreeLevel(parentId, depth) {
4962
5012
  }
4963
5013
  async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef, maxDepthRef) {
4964
5014
  const items = await fetchTreeLevel(parentId);
5015
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(
5016
+ items.map((item) => item.id).filter((id) => typeof id === "string")
5017
+ );
4965
5018
  const nodes = [];
4966
5019
  for (const item of items) {
4967
5020
  totalRef.count++;
@@ -4977,7 +5030,7 @@ async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef
4977
5030
  nodes.push({
4978
5031
  id: item.id ?? "",
4979
5032
  name: item.name ?? item.variants?.[0]?.name ?? "Unknown",
4980
- url: item.url ?? item.urls?.[0]?.url ?? "",
5033
+ url: urlsById.get(item.id) ?? "",
4981
5034
  documentType: item.documentType?.name ?? item.contentTypeName ?? "",
4982
5035
  depth,
4983
5036
  childCount: children.length,
@@ -5045,6 +5098,9 @@ var tool67 = {
5045
5098
  if (!result.ok) return;
5046
5099
  const data = result.data;
5047
5100
  const items = data?.items ?? [];
5101
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(
5102
+ items.map((item) => item.id).filter((id) => typeof id === "string")
5103
+ );
5048
5104
  for (const item of items) {
5049
5105
  if (scannedRef.count >= 500) break;
5050
5106
  scannedRef.count++;
@@ -5053,7 +5109,7 @@ var tool67 = {
5053
5109
  allPages.push({
5054
5110
  id: item.id ?? "",
5055
5111
  name,
5056
- url: item.url ?? item.urls?.[0]?.url ?? "",
5112
+ url: urlsById.get(item.id) ?? "",
5057
5113
  documentType: item.documentType?.name ?? item.contentTypeName ?? "",
5058
5114
  depth,
5059
5115
  rawDepth: depth,
@@ -6695,6 +6751,26 @@ var outputSchema93 = z.object({
6695
6751
  ).describe("Pages that reference this item"),
6696
6752
  referenceCount: z.number().describe("Total number of pages referencing this item")
6697
6753
  });
6754
+ async function buildReferencedBy(refItems) {
6755
+ const docRefIds = refItems.filter((ref) => ref.$type === "DocumentReferenceResponseModel").map((ref) => ref.id);
6756
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(docRefIds);
6757
+ return refItems.map((ref) => {
6758
+ if (ref.$type === "DocumentReferenceResponseModel") {
6759
+ return {
6760
+ id: ref.id,
6761
+ name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
6762
+ url: urlsById.get(ref.id) ?? "",
6763
+ documentType: ref.documentType?.alias ?? ""
6764
+ };
6765
+ }
6766
+ return {
6767
+ id: ref.id,
6768
+ name: ref.name ?? "(unnamed)",
6769
+ url: "",
6770
+ documentType: ""
6771
+ };
6772
+ });
6773
+ }
6698
6774
  var tool93 = {
6699
6775
  name: "report-content-references",
6700
6776
  description: "Find which pages reference a given content page or media item. Useful before deleting or restructuring content to understand the impact.",
@@ -6709,32 +6785,11 @@ var tool93 = {
6709
6785
  chainCms("get-document-by-id-referenced-by", { id })
6710
6786
  ]);
6711
6787
  let name = "Unknown";
6712
- let url = "";
6713
6788
  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
- }
6789
+ name = docResult.data.variants?.[0]?.name ?? "Unknown";
6737
6790
  }
6791
+ const url = await fetchPrimaryPublishedUrl(id);
6792
+ const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
6738
6793
  return createToolResult({
6739
6794
  id,
6740
6795
  name,
@@ -6758,26 +6813,7 @@ var tool93 = {
6758
6813
  const entry = urlResult.data.items?.find((u) => u.id === id);
6759
6814
  url = entry?.urlInfos?.[0]?.url ?? "";
6760
6815
  }
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
- }
6816
+ const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
6781
6817
  return createToolResult({
6782
6818
  id,
6783
6819
  name,
@@ -6950,18 +6986,18 @@ async function resolveOutboundIds(candidateIds, excludeId) {
6950
6986
  const internalPages = [];
6951
6987
  const media = [];
6952
6988
  const filtered = excludeId ? candidateIds.filter((cid) => cid !== excludeId.toLowerCase()) : candidateIds;
6989
+ const urlsById = await fetchPrimaryPublishedUrlsBatch(filtered);
6953
6990
  await Promise.all(
6954
6991
  filtered.map(async (refId) => {
6955
6992
  try {
6956
6993
  const docResult = await chainCms("get-document-by-id", { id: refId });
6957
6994
  if (docResult.ok) {
6958
6995
  const refDoc = docResult.data;
6959
- const docExtra = refDoc;
6960
6996
  const docType = refDoc.documentType;
6961
6997
  internalPages.push({
6962
6998
  id: refId,
6963
6999
  name: refDoc.variants?.[0]?.name ?? "Unknown",
6964
- url: docExtra.urls?.[0]?.url ?? "",
7000
+ url: urlsById.get(refId) ?? "",
6965
7001
  documentType: docType?.alias ?? ""
6966
7002
  });
6967
7003
  return;
@@ -7035,7 +7071,7 @@ var tool94 = {
7035
7071
  const doc = result.data;
7036
7072
  const variant = doc.variants?.[0];
7037
7073
  const name = variant?.name ?? "Unknown";
7038
- const url = doc.urls?.[0]?.url ?? "";
7074
+ const url = await fetchPrimaryPublishedUrl(id);
7039
7075
  const values = doc.values ?? [];
7040
7076
  const links = extractLinksFromValues(values);
7041
7077
  const { internalPages, media } = await resolveOutboundIds(links.allIds, id);