@umbraco-cms/mcp-editor 18.0.0-beta.8 → 18.0.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,15 +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, confirmAction, requestApproval, UmbracoManagementClient, encodeCursor, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas } from '@umbraco-cms/mcp-server-sdk';
5
+ import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas } 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
- import { randomUUID } from 'crypto';
10
9
 
11
10
  // package.json
12
11
  var package_default = {
13
- version: "18.0.0-beta.8"};
12
+ version: "18.0.0-beta.9"};
14
13
 
15
14
  // src/auth/chained-deps.generated.ts
16
15
  var CHAINED_DEPS = {
@@ -201,6 +200,12 @@ function extractInnerProblemDetails(result) {
201
200
  return parsed;
202
201
  }
203
202
  } catch {
203
+ return {
204
+ type: "Error",
205
+ title: "Chained tool error",
206
+ status: 500,
207
+ detail: `Chained CMS tool returned a non-JSON error: ${text}`
208
+ };
204
209
  }
205
210
  }
206
211
  }
@@ -211,8 +216,30 @@ function extractInnerProblemDetails(result) {
211
216
  detail: "Chained CMS tool returned an error with no structured details."
212
217
  };
213
218
  }
219
+ function truncateAvailableTools(message) {
220
+ const availableToolsIndex = message.indexOf(". Available tools");
221
+ if (availableToolsIndex === -1 || !message.includes("Tool not found:")) {
222
+ return message;
223
+ }
224
+ return message.slice(0, availableToolsIndex + 1);
225
+ }
214
226
  async function chainCms(toolName, args) {
215
- const result = await mcpClientManager.callTool("cms", toolName, args);
227
+ let result;
228
+ try {
229
+ result = await mcpClientManager.callTool("cms", toolName, args);
230
+ } catch (error) {
231
+ const message = truncateAvailableTools(error instanceof Error ? error.message : String(error));
232
+ console.warn(`Chained CMS tool "${toolName}" failed: ${message}`);
233
+ return {
234
+ ok: false,
235
+ errorResult: createToolResultError({
236
+ type: "Error",
237
+ title: "Chained tool call failed",
238
+ status: 500,
239
+ detail: `Chained CMS tool "${toolName}" failed: ${message}`
240
+ })
241
+ };
242
+ }
216
243
  if (result.isError) {
217
244
  const inner = extractInnerProblemDetails(result);
218
245
  return { ok: false, errorResult: createToolResultError(inner) };
@@ -557,6 +584,19 @@ var tool3 = {
557
584
  }
558
585
  };
559
586
  var list_children_default = withStandardDecorators(tool3);
587
+
588
+ // src/auth/auth-policies.ts
589
+ var sections = {
590
+ settings: "Umb.Section.Settings"};
591
+
592
+ // src/umbraco-api/tools/helpers/settings-access.ts
593
+ async function checkSettingsAccess() {
594
+ const result = await chainCms("get-user-current", {});
595
+ if (!result.ok) return result;
596
+ return { ok: true, hasAccess: result.data.allowedSections?.includes(sections.settings) ?? false };
597
+ }
598
+
599
+ // src/umbraco-api/tools/content/get/list-document-types.ts
560
600
  var inputSchema4 = {
561
601
  take: z.number().optional().default(50).describe("Number of results to return"),
562
602
  skip: z.number().optional().default(0).describe("Number of results to skip")
@@ -579,11 +619,14 @@ async function collectDocumentTypeIds() {
579
619
  let result;
580
620
  while (true) {
581
621
  result = parentId ? await chainCms("get-document-type-children", { parentId, cursor }) : await chainCms("get-document-type-root", { cursor });
582
- if (!result.ok) return;
622
+ if (!result.ok) return { ok: false, errorResult: result.errorResult };
583
623
  const items = result.data.items ?? [];
584
624
  for (const item of items) {
585
625
  if (item.isFolder) {
586
- if (item.hasChildren) await walk(item.id);
626
+ if (item.hasChildren) {
627
+ const childResult = await walk(item.id);
628
+ if (childResult && !childResult.ok) return childResult;
629
+ }
587
630
  } else {
588
631
  collected.push(item);
589
632
  }
@@ -592,26 +635,35 @@ async function collectDocumentTypeIds() {
592
635
  if (!nextCursor) break;
593
636
  cursor = nextCursor;
594
637
  }
638
+ return void 0;
595
639
  }
596
- await walk(void 0);
597
- return collected;
640
+ const failure = await walk(void 0);
641
+ if (failure && !failure.ok) return failure;
642
+ return { ok: true, nodes: collected };
598
643
  }
599
644
  async function resolveDocTypeDetails(nodes) {
600
645
  const results = await Promise.all(
601
646
  nodes.map(async (node) => {
602
647
  const detailResult = await chainCms("get-document-type-by-id", { id: node.id });
603
- if (!detailResult.ok) return null;
648
+ if (!detailResult.ok) return { ok: false, errorResult: detailResult.errorResult, node };
604
649
  const d = detailResult.data;
605
650
  return {
606
- id: node.id,
607
- alias: d.alias ?? "",
608
- name: d.name ?? node.name,
609
- description: d.description ?? void 0,
610
- icon: d.icon ?? node.icon
651
+ ok: true,
652
+ details: [{
653
+ id: node.id,
654
+ alias: d.alias ?? "",
655
+ name: d.name ?? node.name,
656
+ description: d.description ?? void 0,
657
+ icon: d.icon ?? node.icon
658
+ }],
659
+ node
611
660
  };
612
661
  })
613
662
  );
614
- return results.filter((r) => r !== null);
663
+ const failed = results.find((r) => !r.ok);
664
+ if (failed && !failed.ok) return { ok: false, errorResult: failed.errorResult };
665
+ const details = results.flatMap((r) => r.ok ? r.details : []);
666
+ return { ok: true, details };
615
667
  }
616
668
  var tool4 = {
617
669
  name: "list-document-types",
@@ -621,9 +673,22 @@ var tool4 = {
621
673
  slices: ["list"],
622
674
  annotations: { readOnlyHint: true },
623
675
  handler: async ({ take, skip }) => {
624
- const nodes = await collectDocumentTypeIds();
676
+ const accessCheck = await checkSettingsAccess();
677
+ if (!accessCheck.ok) return accessCheck.errorResult;
678
+ if (!accessCheck.hasAccess) {
679
+ return createToolResultError({
680
+ status: 403,
681
+ title: "Settings access required",
682
+ detail: "Listing document types requires the signed-in Umbraco user to have access to the Settings section. Grant Settings-section access to the user's group in the Umbraco backoffice (Users \u2192 [group] \u2192 Sections), then retry."
683
+ });
684
+ }
685
+ const treeResult = await collectDocumentTypeIds();
686
+ if (!treeResult.ok) return treeResult.errorResult;
687
+ const { nodes } = treeResult;
625
688
  const sliced = nodes.slice(skip, skip + take);
626
- const details = await resolveDocTypeDetails(sliced);
689
+ const detailsResult = await resolveDocTypeDetails(sliced);
690
+ if (!detailsResult.ok) return detailsResult.errorResult;
691
+ const { details } = detailsResult;
627
692
  return createToolResult({
628
693
  items: details.map((d) => ({
629
694
  id: d.id,
@@ -637,6 +702,73 @@ var tool4 = {
637
702
  }
638
703
  };
639
704
  var list_document_types_default = withStandardDecorators(tool4);
705
+
706
+ // src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
707
+ async function resolveDocumentTypeProperties(documentTypeId) {
708
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
709
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
710
+ const data = docTypeResult.data;
711
+ const collected = /* @__PURE__ */ new Map();
712
+ function addProperties(props) {
713
+ for (const p of props) {
714
+ if (p.alias && !collected.has(p.alias)) {
715
+ collected.set(p.alias, p);
716
+ }
717
+ }
718
+ }
719
+ function compositionIdsOf(d) {
720
+ return Array.from(
721
+ new Set(
722
+ (d.compositions ?? []).map((c) => c.documentType?.id).filter((id) => typeof id === "string")
723
+ )
724
+ );
725
+ }
726
+ function describeFailure(errorResult) {
727
+ const text = errorResult.content?.[0]?.type === "text" ? errorResult.content[0].text : void 0;
728
+ if (!text) return "unknown error";
729
+ try {
730
+ const parsed = JSON.parse(text);
731
+ const detail = parsed?.detail;
732
+ return typeof detail === "string" ? detail : text;
733
+ } catch {
734
+ return text;
735
+ }
736
+ }
737
+ addProperties(Array.isArray(data.properties) ? data.properties : []);
738
+ const visited = /* @__PURE__ */ new Set([documentTypeId]);
739
+ const failedCompositionIds = [];
740
+ const failedCompositionDetails = [];
741
+ let frontier = compositionIdsOf(data).filter((id) => !visited.has(id));
742
+ frontier.forEach((id) => visited.add(id));
743
+ while (frontier.length > 0) {
744
+ const results = await Promise.all(frontier.map((id) => chainCms("get-document-type-by-id", { id })));
745
+ const nextFrontier = [];
746
+ results.forEach((r, i) => {
747
+ if (!r.ok) {
748
+ failedCompositionIds.push(frontier[i]);
749
+ failedCompositionDetails.push(describeFailure(r.errorResult));
750
+ return;
751
+ }
752
+ if (Array.isArray(r.data.properties)) addProperties(r.data.properties);
753
+ for (const id of compositionIdsOf(r.data)) {
754
+ if (!visited.has(id)) {
755
+ visited.add(id);
756
+ nextFrontier.push(id);
757
+ }
758
+ }
759
+ });
760
+ frontier = nextFrontier;
761
+ }
762
+ return {
763
+ ok: true,
764
+ documentType: data,
765
+ properties: Array.from(collected.values()),
766
+ failedCompositionIds,
767
+ failedCompositionDetails
768
+ };
769
+ }
770
+
771
+ // src/umbraco-api/tools/content/get/get-document-type.ts
640
772
  var inputSchema5 = {
641
773
  id: z.string().uuid().describe("UUID of the document type to retrieve")
642
774
  };
@@ -664,30 +796,9 @@ var tool5 = {
664
796
  slices: ["read"],
665
797
  annotations: { readOnlyHint: true },
666
798
  handler: async ({ id }) => {
667
- const result = await chainCms("get-document-type-by-id", { id });
799
+ const result = await resolveDocumentTypeProperties(id);
668
800
  if (!result.ok) return result.errorResult;
669
- const data = result.data;
670
- const collected = /* @__PURE__ */ new Map();
671
- function addProperties(props) {
672
- for (const p of props) {
673
- if (p.alias && !collected.has(p.alias)) {
674
- collected.set(p.alias, p);
675
- }
676
- }
677
- }
678
- addProperties(Array.isArray(data.properties) ? data.properties : []);
679
- const compositionIds = (data.compositions ?? []).map((c) => c.document?.id ?? c.documentType?.id ?? c.id).filter((cid) => typeof cid === "string");
680
- if (compositionIds.length > 0) {
681
- const compositions = await Promise.all(
682
- compositionIds.map(async (cid) => {
683
- const r = await chainCms("get-document-type-by-id", { id: cid });
684
- return r.ok ? r.data : null;
685
- })
686
- );
687
- for (const comp of compositions) {
688
- if (comp && Array.isArray(comp.properties)) addProperties(comp.properties);
689
- }
690
- }
801
+ const { documentType: data, properties } = result;
691
802
  return createToolResult({
692
803
  id: data.id ?? id,
693
804
  alias: data.alias ?? "",
@@ -695,7 +806,7 @@ var tool5 = {
695
806
  description: data.description || void 0,
696
807
  variesByCulture: data.variesByCulture || void 0,
697
808
  variesBySegment: data.variesBySegment || void 0,
698
- properties: Array.from(collected.values()).map((p) => ({
809
+ properties: properties.map((p) => ({
699
810
  alias: p.alias ?? "",
700
811
  name: p.name ?? p.alias ?? "",
701
812
  description: p.description || void 0,
@@ -707,49 +818,193 @@ var tool5 = {
707
818
  }
708
819
  };
709
820
  var get_document_type_default = withStandardDecorators(tool5);
821
+ var validationErrorSchema = z.object({
822
+ propertyAlias: z.string().describe(
823
+ "The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
824
+ ),
825
+ culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
826
+ segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
827
+ message: z.string().describe("Human-readable validation error message.")
828
+ });
829
+ var validationResultSchema = z.object({
830
+ valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
831
+ errors: z.array(validationErrorSchema).describe(
832
+ "Property-level validation errors. Empty when `valid` is true. Each entry names the offending propertyAlias/culture/segment and a human message \u2014 surface these back to the editor so they know what to fix before publishing."
833
+ )
834
+ }).describe(
835
+ "Server-side validation outcome for the saved document. A 200 OK on save does NOT imply publishability \u2014 Umbraco only enforces required fields, regex, length, etc. via this validation endpoint. When `valid` is false the changes ARE persisted as a draft but the document cannot be published until the listed errors are resolved."
836
+ );
837
+ async function validateDocumentState(id, doc) {
838
+ let target = null;
839
+ if (!target) {
840
+ const docResult = await chainCms("get-document-by-id", { id });
841
+ if (!docResult.ok) {
842
+ return {
843
+ valid: false,
844
+ errors: [
845
+ {
846
+ propertyAlias: "__document__",
847
+ message: "Could not refetch document to run validation."
848
+ }
849
+ ]
850
+ };
851
+ }
852
+ target = docResult.data;
853
+ }
854
+ const values = (target.values ?? []).map((v) => ({
855
+ alias: v.alias,
856
+ value: v.value,
857
+ culture: v.culture ?? null,
858
+ segment: v.segment ?? null
859
+ }));
860
+ const variants = (target.variants ?? []).map((v) => ({
861
+ name: v.name,
862
+ culture: v.culture ?? null,
863
+ segment: v.segment ?? null
864
+ }));
865
+ const itemResult = await chainCms("get-item-document", { id: [id] });
866
+ const parent = itemResult.ok ? itemResult.data.items[0]?.parent ?? null : null;
867
+ const result = await chainCms("validate-document", {
868
+ id,
869
+ documentType: { id: target.documentType.id },
870
+ template: target.template ? { id: target.template.id } : null,
871
+ parent: parent ? { id: parent.id } : null,
872
+ values,
873
+ variants
874
+ });
875
+ if (result.ok) {
876
+ return { valid: true, errors: [] };
877
+ }
878
+ return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
879
+ }
880
+ function parseValidationErrors(errorResult, requestValues) {
881
+ const structured = extractStructured(errorResult);
882
+ if (!structured) {
883
+ return [
884
+ {
885
+ propertyAlias: "__document__",
886
+ message: stringifyErrorFallback(errorResult)
887
+ }
888
+ ];
889
+ }
890
+ const errors = structured.errors;
891
+ if (!errors || typeof errors !== "object") {
892
+ return [
893
+ {
894
+ propertyAlias: "__document__",
895
+ message: stringifyFromProblemDetails(structured)
896
+ }
897
+ ];
898
+ }
899
+ const out = [];
900
+ for (const [jsonPath, messages] of Object.entries(errors)) {
901
+ const messageList = Array.isArray(messages) ? messages : [String(messages)];
902
+ const resolved = resolveJsonPath(jsonPath, requestValues);
903
+ for (const message of messageList) {
904
+ out.push({
905
+ propertyAlias: resolved.propertyAlias,
906
+ culture: resolved.culture,
907
+ segment: resolved.segment,
908
+ message: String(message)
909
+ });
910
+ }
911
+ }
912
+ if (out.length === 0) {
913
+ out.push({
914
+ propertyAlias: "__document__",
915
+ message: stringifyFromProblemDetails(structured)
916
+ });
917
+ }
918
+ return out;
919
+ }
920
+ var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
921
+ function resolveJsonPath(jsonPath, requestValues) {
922
+ const match = jsonPath.match(VALUES_PATH);
923
+ if (match) {
924
+ const index = Number(match[1]);
925
+ const entry = requestValues[index];
926
+ if (entry) {
927
+ const trailing = match[2]?.replace(/^\./, "");
928
+ return {
929
+ propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
930
+ culture: entry.culture,
931
+ segment: entry.segment
932
+ };
933
+ }
934
+ }
935
+ return { propertyAlias: jsonPath, culture: null, segment: null };
936
+ }
937
+ function extractStructured(errorResult) {
938
+ if (!errorResult || typeof errorResult !== "object") return null;
939
+ const r = errorResult;
940
+ if (r.structuredContent && typeof r.structuredContent === "object") {
941
+ return r.structuredContent;
942
+ }
943
+ const text = r.content?.find((c) => c?.type === "text")?.text;
944
+ if (text) {
945
+ try {
946
+ const parsed = JSON.parse(text);
947
+ if (parsed && typeof parsed === "object") {
948
+ return parsed;
949
+ }
950
+ } catch {
951
+ }
952
+ }
953
+ return null;
954
+ }
955
+ function stringifyFromProblemDetails(pd) {
956
+ if (pd.detail && typeof pd.detail === "string") return pd.detail;
957
+ if (pd.title && typeof pd.title === "string") return pd.title;
958
+ return "Document failed validation but no detail was returned.";
959
+ }
960
+ function stringifyErrorFallback(errorResult) {
961
+ if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
962
+ const r = errorResult;
963
+ const text = r.content?.find((c) => c?.type === "text")?.text;
964
+ return text ? text : "Document failed validation.";
965
+ }
710
966
 
711
967
  // src/umbraco-api/tools/helpers/block-builder.ts
712
- async function resolveBlockEditorAliases(contentTypeKey) {
713
- const docTypeResult = await chainCms("get-document-type-by-id", { id: contentTypeKey });
968
+ async function toBlockProperties(elementTypeKey, values, culture, segment) {
969
+ if (values.length === 0) return { ok: true, properties: [] };
970
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: elementTypeKey });
714
971
  if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
715
- const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
716
- if (dataTypeIds.length === 0) {
717
- return { ok: true, editorAliasByAlias: /* @__PURE__ */ new Map() };
718
- }
719
- const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
720
- if (!dataTypesResult.ok) return { ok: false, errorResult: dataTypesResult.errorResult };
721
- const editorAliasByDataTypeId = new Map(
722
- dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
723
- );
724
- const editorAliasByAlias = /* @__PURE__ */ new Map();
725
- for (const prop of docTypeResult.data.properties) {
726
- const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
727
- if (editorAlias) editorAliasByAlias.set(prop.alias, editorAlias);
728
- }
729
- return { ok: true, editorAliasByAlias };
730
- }
731
- function buildBlockEntry(contentKey, contentTypeKey, values, editorAliasByAlias, culture, segment) {
972
+ const definitions = new Map(docTypeResult.data.properties.map((p) => [p.alias, p]));
732
973
  return {
733
- key: contentKey,
734
- contentTypeKey,
735
- values: values.map((v) => ({
736
- editorAlias: editorAliasByAlias.get(v.alias) ?? "",
737
- culture,
738
- segment,
739
- alias: v.alias,
740
- value: v.value
741
- }))
974
+ ok: true,
975
+ properties: values.map((v) => {
976
+ const def = definitions.get(v.alias);
977
+ return {
978
+ alias: v.alias,
979
+ value: v.value,
980
+ culture: def?.variesByCulture ? culture : null,
981
+ segment: def?.variesBySegment ? segment : null
982
+ };
983
+ })
742
984
  };
743
985
  }
744
- function insertAtPosition(list, item, position, matchAnchor) {
745
- if (position.mode === "append") return { ok: true, list: [...list, item] };
746
- if (position.mode === "prepend") return { ok: true, list: [item, ...list] };
747
- const anchorIndex = list.findIndex(matchAnchor);
748
- if (anchorIndex === -1) return { ok: false, reason: "anchor-not-found" };
749
- const insertIndex = position.mode === "before" ? anchorIndex : anchorIndex + 1;
750
- const next = [...list];
751
- next.splice(insertIndex, 0, item);
752
- return { ok: true, list: next };
986
+ async function toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, culture, segment) {
987
+ const content = await toBlockProperties(contentTypeKey, values, culture, segment);
988
+ if (!content.ok) return content;
989
+ if (!settingsTypeKey || !settingsValues) return { ok: true, properties: content.properties };
990
+ const settings = await toBlockProperties(settingsTypeKey, settingsValues, culture, segment);
991
+ if (!settings.ok) return settings;
992
+ return { ok: true, properties: content.properties, settings: { properties: settings.properties } };
993
+ }
994
+ function toPlacement(position) {
995
+ return position.mode === "before" || position.mode === "after" ? { position: position.mode, contentKey: position.anchorContentKey } : { position: position.mode };
996
+ }
997
+ async function buildBlockWriteResult(id, pageName, contentKey, baseMessage) {
998
+ const validation = await validateDocumentState(id);
999
+ const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
1000
+ return createToolResult({
1001
+ message,
1002
+ id,
1003
+ name: pageName,
1004
+ contentKey,
1005
+ previewUrl: await fetchPreviewUrl(id),
1006
+ validation
1007
+ });
753
1008
  }
754
1009
  function isBlockListOrGridValue(value) {
755
1010
  return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
@@ -757,18 +1012,6 @@ function isBlockListOrGridValue(value) {
757
1012
  function isRteWithBlocks(value) {
758
1013
  return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
759
1014
  }
760
- function exposeEntry(contentKey, culture, segment) {
761
- return { contentKey, culture, segment };
762
- }
763
- function removeBlockFromContainer(container, contentKey, layoutKey, newLayoutList, doomedSettingsKey) {
764
- return {
765
- ...container,
766
- layout: { ...container.layout ?? {}, [layoutKey]: [...newLayoutList] },
767
- contentData: (container.contentData ?? []).filter((entry) => entry.key !== contentKey),
768
- settingsData: doomedSettingsKey ? (container.settingsData ?? []).filter((entry) => entry.key !== doomedSettingsKey) : container.settingsData ?? [],
769
- expose: (container.expose ?? []).filter((entry) => entry.contentKey !== contentKey)
770
- };
771
- }
772
1015
 
773
1016
  // src/umbraco-api/tools/helpers/block-inspector.ts
774
1017
  function blockPropertiesSchema(editTool) {
@@ -831,12 +1074,82 @@ function collectBlockProperties(values, propertyAlias) {
831
1074
  };
832
1075
  });
833
1076
  }
1077
+ var MAX_ENRICHED_BLOCKS = 50;
1078
+ var MAX_BLOCK_WALK_DEPTH = 20;
1079
+ function enrichBlockNotFoundError(errorResult, values, options = {}) {
1080
+ const problem = extractInnerProblemDetails(errorResult);
1081
+ const availableBlocks = problem.availableBlocks;
1082
+ if (!Array.isArray(availableBlocks)) return errorResult;
1083
+ const { propertyAlias, note } = options;
1084
+ const filtered = propertyAlias ? values.filter((v) => v.alias === propertyAlias) : values;
1085
+ const typeByKey = /* @__PURE__ */ new Map();
1086
+ for (const v of filtered) {
1087
+ const container = isRteWithBlocks(v.value) ? v.value.blocks : v.value;
1088
+ if (isBlockListOrGridValue(container)) {
1089
+ collectBlockEntryTypes(container, typeByKey, 0);
1090
+ }
1091
+ }
1092
+ const truncated = availableBlocks.length > MAX_ENRICHED_BLOCKS;
1093
+ const limitedBlocks = truncated ? availableBlocks.slice(0, MAX_ENRICHED_BLOCKS) : availableBlocks;
1094
+ const enrichedBlocks = limitedBlocks.map(
1095
+ (b) => b && typeof b === "object" && typeof b.key === "string" ? { ...b, contentTypeKey: typeByKey.get(b.key) ?? null } : b
1096
+ );
1097
+ return createToolResultError({
1098
+ ...problem,
1099
+ availableBlocks: enrichedBlocks,
1100
+ ...truncated ? { availableBlocksNote: `Showing ${MAX_ENRICHED_BLOCKS} of ${availableBlocks.length} available blocks \u2014 use inspect-blocks for the full list.` } : {},
1101
+ ...note ? { note } : {}
1102
+ });
1103
+ }
1104
+ function collectBlockEntryTypes(container, into, depth) {
1105
+ if (depth > MAX_BLOCK_WALK_DEPTH) return;
1106
+ for (const list of [container.contentData, container.settingsData]) {
1107
+ if (!Array.isArray(list)) continue;
1108
+ for (const block of list) {
1109
+ if (!block || typeof block !== "object") continue;
1110
+ const key = block.key;
1111
+ const contentTypeKey = block.contentTypeKey;
1112
+ if (typeof key === "string" && typeof contentTypeKey === "string") into.set(key, contentTypeKey);
1113
+ const nestedValues = block.values;
1114
+ if (!Array.isArray(nestedValues)) continue;
1115
+ for (const nested of nestedValues) {
1116
+ const nestedRaw = nested?.value;
1117
+ const nestedContainer = isRteWithBlocks(nestedRaw) ? nestedRaw.blocks : nestedRaw;
1118
+ if (isBlockListOrGridValue(nestedContainer)) {
1119
+ collectBlockEntryTypes(nestedContainer, into, depth + 1);
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ }
834
1125
  function withSettingsKeys(blocks, container) {
835
1126
  return blocks.map((block) => {
836
1127
  const settingsKey = findSettingsKey(container, block.contentKey);
837
1128
  return settingsKey ? { ...block, settingsKey } : block;
838
1129
  });
839
1130
  }
1131
+ var blockPropertyAliasSchema = z.string().regex(
1132
+ /^[A-Za-z_][A-Za-z0-9_]*$/,
1133
+ "Property alias must be a valid identifier (letters, digits, underscore; not starting with a digit)"
1134
+ );
1135
+ function classifyBlockUpdateResults(results, requestedCount, requestedAliases = [], expectedEntryCount = 1) {
1136
+ const list = results ?? [];
1137
+ const processedCount = list.reduce((sum, r) => sum + (r.updatedCount ?? 0) + (r.addedCount ?? 0), 0);
1138
+ const updatedEntryCount = list.filter((r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) > 0).length;
1139
+ const errors = list.flatMap((r) => r.errors ?? []);
1140
+ const warnings = list.flatMap((r) => r.warnings ?? []);
1141
+ const failureText = [...errors, ...warnings].join("; ");
1142
+ const unresolvedEntries = list.filter(
1143
+ (r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) === 0 && !r.errors?.length && !r.warnings?.length
1144
+ );
1145
+ const missingEntryCount = Math.max(0, expectedEntryCount - list.length);
1146
+ const unresolvedBlockCount = unresolvedEntries.length + missingEntryCount;
1147
+ const detail = [...errors, ...warnings, ...unresolvedEntries.map((r) => r.message).filter(Boolean)].join("; ") || list.map((r) => r.message).filter(Boolean).join("; ") || "no detail returned";
1148
+ const outcome = processedCount === 0 ? "failed" : processedCount < requestedCount ? "partial" : "clean";
1149
+ const failedFields = requestedAliases.filter((alias) => failureText.includes(`'${alias}'`));
1150
+ const savedFields = unresolvedBlockCount > 0 ? [] : requestedAliases.filter((alias) => !failedFields.includes(alias));
1151
+ return { outcome, processedCount, updatedEntryCount, detail, warnings, savedFields, failedFields, unresolvedBlockCount };
1152
+ }
840
1153
 
841
1154
  // src/umbraco-api/tools/content/get/inspect-blocks.ts
842
1155
  var inputSchema6 = {
@@ -1183,166 +1496,92 @@ var tool10 = {
1183
1496
  ${aliases.join("\n")}`
1184
1497
  });
1185
1498
  }
1186
- const match = findResult.data.items[0];
1187
- if (!match) {
1188
- return createToolResultError({
1189
- detail: `No data type found with editorAlias "${editorAlias}".`
1190
- });
1191
- }
1192
- const schemaResult = await chainCms("get-data-type-schema", { id: match.id });
1193
- if (!schemaResult.ok) return schemaResult.errorResult;
1194
- return createToolResult({
1195
- message: `Value-shape template for ${editorAlias}:
1196
- ${JSON.stringify(schemaResult.data, null, 2)}`,
1197
- editorAlias
1198
- });
1199
- }
1200
- };
1201
- var get_property_value_template_default = withStandardDecorators(tool10);
1202
- var validationErrorSchema = z.object({
1203
- propertyAlias: z.string().describe(
1204
- "The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
1205
- ),
1206
- culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
1207
- segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
1208
- message: z.string().describe("Human-readable validation error message.")
1209
- });
1210
- var validationResultSchema = z.object({
1211
- valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
1212
- errors: z.array(validationErrorSchema).describe(
1213
- "Property-level validation errors. Empty when `valid` is true. Each entry names the offending propertyAlias/culture/segment and a human message \u2014 surface these back to the editor so they know what to fix before publishing."
1214
- )
1215
- }).describe(
1216
- "Server-side validation outcome for the saved document. A 200 OK on save does NOT imply publishability \u2014 Umbraco only enforces required fields, regex, length, etc. via this validation endpoint. When `valid` is false the changes ARE persisted as a draft but the document cannot be published until the listed errors are resolved."
1217
- );
1218
- async function validateDocumentState(id, doc) {
1219
- let target = null;
1220
- if (!target) {
1221
- const docResult = await chainCms("get-document-by-id", { id });
1222
- if (!docResult.ok) {
1223
- return {
1224
- valid: false,
1225
- errors: [
1226
- {
1227
- propertyAlias: "__document__",
1228
- message: "Could not refetch document to run validation."
1229
- }
1230
- ]
1231
- };
1232
- }
1233
- target = docResult.data;
1234
- }
1235
- const values = (target.values ?? []).map((v) => ({
1236
- alias: v.alias,
1237
- value: v.value,
1238
- culture: v.culture ?? null,
1239
- segment: v.segment ?? null
1240
- }));
1241
- const variants = (target.variants ?? []).map((v) => ({
1242
- name: v.name,
1243
- culture: v.culture ?? null,
1244
- segment: v.segment ?? null
1245
- }));
1246
- const itemResult = await chainCms("get-item-document", { id: [id] });
1247
- const parent = itemResult.ok ? itemResult.data.items[0]?.parent ?? null : null;
1248
- const result = await chainCms("validate-document", {
1249
- id,
1250
- documentType: { id: target.documentType.id },
1251
- template: target.template ? { id: target.template.id } : null,
1252
- parent: parent ? { id: parent.id } : null,
1253
- values,
1254
- variants
1255
- });
1256
- if (result.ok) {
1257
- return { valid: true, errors: [] };
1258
- }
1259
- return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
1260
- }
1261
- function parseValidationErrors(errorResult, requestValues) {
1262
- const structured = extractStructured(errorResult);
1263
- if (!structured) {
1264
- return [
1265
- {
1266
- propertyAlias: "__document__",
1267
- message: stringifyErrorFallback(errorResult)
1268
- }
1269
- ];
1270
- }
1271
- const errors = structured.errors;
1272
- if (!errors || typeof errors !== "object") {
1273
- return [
1274
- {
1275
- propertyAlias: "__document__",
1276
- message: stringifyFromProblemDetails(structured)
1277
- }
1278
- ];
1279
- }
1280
- const out = [];
1281
- for (const [jsonPath, messages] of Object.entries(errors)) {
1282
- const messageList = Array.isArray(messages) ? messages : [String(messages)];
1283
- const resolved = resolveJsonPath(jsonPath, requestValues);
1284
- for (const message of messageList) {
1285
- out.push({
1286
- propertyAlias: resolved.propertyAlias,
1287
- culture: resolved.culture,
1288
- segment: resolved.segment,
1289
- message: String(message)
1499
+ const match = findResult.data.items[0];
1500
+ if (!match) {
1501
+ return createToolResultError({
1502
+ detail: `No data type found with editorAlias "${editorAlias}".`
1290
1503
  });
1291
1504
  }
1292
- }
1293
- if (out.length === 0) {
1294
- out.push({
1295
- propertyAlias: "__document__",
1296
- message: stringifyFromProblemDetails(structured)
1505
+ const schemaResult = await chainCms("get-data-type-schema", { id: match.id });
1506
+ if (!schemaResult.ok) return schemaResult.errorResult;
1507
+ return createToolResult({
1508
+ message: `Value-shape template for ${editorAlias}:
1509
+ ${JSON.stringify(schemaResult.data, null, 2)}`,
1510
+ editorAlias
1297
1511
  });
1298
1512
  }
1299
- return out;
1300
- }
1301
- var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
1302
- function resolveJsonPath(jsonPath, requestValues) {
1303
- const match = jsonPath.match(VALUES_PATH);
1304
- if (match) {
1305
- const index = Number(match[1]);
1306
- const entry = requestValues[index];
1307
- if (entry) {
1308
- const trailing = match[2]?.replace(/^\./, "");
1309
- return {
1310
- propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
1311
- culture: entry.culture,
1312
- segment: entry.segment
1313
- };
1513
+ };
1514
+ var get_property_value_template_default = withStandardDecorators(tool10);
1515
+ async function resolveEditorAliases(documentTypeId, values) {
1516
+ if (!values || values.length === 0) {
1517
+ return { ok: true, values: [] };
1518
+ }
1519
+ const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
1520
+ if (!docTypeResult.ok) return docTypeResult;
1521
+ const dataTypeIds = Array.from(
1522
+ new Set(
1523
+ docTypeResult.properties.map((p) => p.dataType?.id).filter((id) => typeof id === "string")
1524
+ )
1525
+ );
1526
+ const editorAliasByDataTypeId = /* @__PURE__ */ new Map();
1527
+ if (dataTypeIds.length > 0) {
1528
+ const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
1529
+ if (!dataTypesResult.ok) return dataTypesResult;
1530
+ for (const dt of dataTypesResult.data.items) {
1531
+ if (dt.id && dt.editorAlias) editorAliasByDataTypeId.set(dt.id, dt.editorAlias);
1314
1532
  }
1315
1533
  }
1316
- return { propertyAlias: jsonPath, culture: null, segment: null };
1317
- }
1318
- function extractStructured(errorResult) {
1319
- if (!errorResult || typeof errorResult !== "object") return null;
1320
- const r = errorResult;
1321
- if (r.structuredContent && typeof r.structuredContent === "object") {
1322
- return r.structuredContent;
1323
- }
1324
- const text = r.content?.find((c) => c?.type === "text")?.text;
1325
- if (text) {
1326
- try {
1327
- const parsed = JSON.parse(text);
1328
- if (parsed && typeof parsed === "object") {
1329
- return parsed;
1534
+ const propertyAliases = new Set(
1535
+ docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
1536
+ );
1537
+ const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1538
+ for (const prop of docTypeResult.properties) {
1539
+ const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
1540
+ if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1541
+ }
1542
+ const notAProperty = /* @__PURE__ */ new Set();
1543
+ const missingEditorAlias = /* @__PURE__ */ new Set();
1544
+ const resolved = values.map((v) => {
1545
+ const editorAlias = editorAliasByPropertyAlias.get(v.alias);
1546
+ if (!editorAlias) {
1547
+ if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
1548
+ else notAProperty.add(v.alias);
1549
+ }
1550
+ return {
1551
+ alias: v.alias,
1552
+ value: v.value,
1553
+ culture: v.culture ?? null,
1554
+ segment: v.segment ?? null,
1555
+ editorAlias: editorAlias ?? ""
1556
+ };
1557
+ });
1558
+ if (notAProperty.size > 0 || missingEditorAlias.size > 0) {
1559
+ const messages = [];
1560
+ if (notAProperty.size > 0) {
1561
+ if (docTypeResult.failedCompositionIds.length > 0) {
1562
+ const failures = docTypeResult.failedCompositionIds.map((id, i) => `${id} (${docTypeResult.failedCompositionDetails[i]})`).join(", ");
1563
+ messages.push(
1564
+ `not found among the resolvable properties on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")} \u2014 but ${docTypeResult.failedCompositionIds.length} composition(s) could not be loaded: ${failures}, so one of these aliases may actually be valid and just unverifiable right now. Resolve the composition failure(s) above and retry`
1565
+ );
1566
+ } else {
1567
+ messages.push(
1568
+ `not a property on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")}`
1569
+ );
1330
1570
  }
1331
- } catch {
1332
1571
  }
1572
+ if (missingEditorAlias.size > 0) {
1573
+ messages.push(
1574
+ `a property on this document type, but its data type has no resolvable editor alias: ${Array.from(missingEditorAlias).join(", ")}`
1575
+ );
1576
+ }
1577
+ return {
1578
+ ok: false,
1579
+ errorResult: createToolResultError(
1580
+ `The following value alias(es) could not be resolved \u2014 ${messages.join("; ")}. Call get-document-type to see the valid property aliases for this document type.`
1581
+ )
1582
+ };
1333
1583
  }
1334
- return null;
1335
- }
1336
- function stringifyFromProblemDetails(pd) {
1337
- if (pd.detail && typeof pd.detail === "string") return pd.detail;
1338
- if (pd.title && typeof pd.title === "string") return pd.title;
1339
- return "Document failed validation but no detail was returned.";
1340
- }
1341
- function stringifyErrorFallback(errorResult) {
1342
- if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
1343
- const r = errorResult;
1344
- const text = r.content?.find((c) => c?.type === "text")?.text;
1345
- return text ? text : "Document failed validation.";
1584
+ return { ok: true, values: resolved };
1346
1585
  }
1347
1586
 
1348
1587
  // src/umbraco-api/tools/content/post/create-page.ts
@@ -1372,31 +1611,12 @@ var tool11 = {
1372
1611
  slices: ["create"],
1373
1612
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1374
1613
  handler: async ({ name, documentTypeId, parentId, values }) => {
1375
- const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1376
- if (values && values.length > 0) {
1377
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1378
- if (!docTypeResult.ok) return docTypeResult.errorResult;
1379
- const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
1380
- const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
1381
- if (!dataTypesResult.ok) return dataTypesResult.errorResult;
1382
- const editorAliasByDataTypeId = new Map(
1383
- dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
1384
- );
1385
- for (const prop of docTypeResult.data.properties) {
1386
- const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
1387
- if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1388
- }
1389
- }
1614
+ const resolved = await resolveEditorAliases(documentTypeId, values);
1615
+ if (!resolved.ok) return resolved.errorResult;
1390
1616
  const createResult = await chainCms("create-document", {
1391
1617
  documentTypeId,
1392
1618
  name,
1393
- values: (values ?? []).map((v) => ({
1394
- alias: v.alias,
1395
- value: v.value,
1396
- culture: v.culture ?? null,
1397
- segment: v.segment ?? null,
1398
- editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
1399
- })),
1619
+ values: resolved.values,
1400
1620
  ...parentId ? { parentId } : {}
1401
1621
  });
1402
1622
  if (!createResult.ok) return createResult.errorResult;
@@ -1439,31 +1659,12 @@ var tool12 = {
1439
1659
  slices: ["create", "publish"],
1440
1660
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1441
1661
  handler: async ({ name, documentTypeId, parentId, values }) => {
1442
- const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1443
- if (values && values.length > 0) {
1444
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1445
- if (!docTypeResult.ok) return docTypeResult.errorResult;
1446
- const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
1447
- const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
1448
- if (!dataTypesResult.ok) return dataTypesResult.errorResult;
1449
- const editorAliasByDataTypeId = new Map(
1450
- dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
1451
- );
1452
- for (const prop of docTypeResult.data.properties) {
1453
- const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
1454
- if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1455
- }
1456
- }
1662
+ const resolved = await resolveEditorAliases(documentTypeId, values);
1663
+ if (!resolved.ok) return resolved.errorResult;
1457
1664
  const createResult = await chainCms("create-and-publish-document", {
1458
1665
  documentTypeId,
1459
1666
  name,
1460
- values: (values ?? []).map((v) => ({
1461
- alias: v.alias,
1462
- value: v.value,
1463
- culture: v.culture ?? null,
1464
- segment: v.segment ?? null,
1465
- editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
1466
- })),
1667
+ values: resolved.values,
1467
1668
  ...parentId ? { parentId } : {}
1468
1669
  });
1469
1670
  if (!createResult.ok) return createResult.errorResult;
@@ -1572,64 +1773,25 @@ var tool14 = {
1572
1773
  const existingProp = (doc.values ?? []).find(
1573
1774
  (v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
1574
1775
  );
1575
- const propValue = existingProp?.value ?? {
1576
- layout: { "Umbraco.BlockList": [] },
1577
- contentData: [],
1578
- settingsData: [],
1579
- expose: []
1580
- };
1581
- if (existingProp && (!isBlockListOrGridValue(propValue) || existingProp.editorAlias !== "Umbraco.BlockList")) {
1776
+ if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockList")) {
1582
1777
  return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a BlockList. Use inspect-blocks to confirm the editor type, or add-rte-block / add-blockgrid-block as appropriate.` }], isError: true });
1583
1778
  }
1584
- const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
1585
- if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
1586
- let settingsEditorAliases = null;
1587
- if (settingsTypeKey) {
1588
- const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
1589
- if (!settingsResult.ok) return settingsResult.errorResult;
1590
- settingsEditorAliases = settingsResult.editorAliasByAlias;
1591
- }
1592
- const newContentKey = randomUUID();
1593
- const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
1594
1779
  const cultureValue = culture ?? null;
1595
1780
  const segmentValue = segment ?? null;
1596
- const newContentEntry = buildBlockEntry(newContentKey, contentTypeKey, values, contentEditorAliases.editorAliasByAlias, cultureValue, segmentValue);
1597
- const newSettingsEntry = settingsTypeKey && newSettingsKey && settingsValues ? buildBlockEntry(newSettingsKey, settingsTypeKey, settingsValues, settingsEditorAliases ?? /* @__PURE__ */ new Map(), cultureValue, segmentValue) : null;
1598
- const layoutKey = "Umbraco.BlockList";
1599
- const layoutEntry = newSettingsKey ? { contentKey: newContentKey, settingsKey: newSettingsKey } : { contentKey: newContentKey };
1600
- const existingLayout = Array.isArray(propValue.layout?.[layoutKey]) ? propValue.layout[layoutKey] : [];
1601
- const insertResult = insertAtPosition(existingLayout, layoutEntry, resolvedPosition, (entry) => entry.contentKey === resolvedPosition.anchorContentKey);
1602
- if (!insertResult.ok) {
1603
- return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
1604
- }
1605
- const newValue = {
1606
- ...propValue,
1607
- layout: { ...propValue.layout ?? {}, [layoutKey]: insertResult.list },
1608
- contentData: [...propValue.contentData ?? [], newContentEntry],
1609
- settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
1610
- expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
1611
- };
1612
- const updateResult = await chainCms("update-document-properties", {
1613
- id,
1614
- properties: [{
1615
- alias: propertyAlias,
1616
- value: newValue,
1617
- culture: cultureValue,
1618
- segment: segmentValue
1619
- }]
1620
- });
1621
- if (!updateResult.ok) return updateResult.errorResult;
1622
- const validation = await validateDocumentState(id);
1623
- const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
1624
- const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
1625
- return createToolResult({
1626
- message,
1627
- id,
1628
- name: pageName,
1629
- contentKey: newContentKey,
1630
- previewUrl: await fetchPreviewUrl(id),
1631
- validation
1781
+ const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
1782
+ if (!blockProperties.ok) return blockProperties.errorResult;
1783
+ const createResult = await chainCms("create-document-block", {
1784
+ documentId: id,
1785
+ propertyAlias,
1786
+ culture: cultureValue,
1787
+ segment: segmentValue,
1788
+ contentTypeKey,
1789
+ properties: blockProperties.properties,
1790
+ settings: blockProperties.settings,
1791
+ placement: toPlacement(resolvedPosition)
1632
1792
  });
1793
+ if (!createResult.ok) return createResult.errorResult;
1794
+ return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
1633
1795
  }
1634
1796
  };
1635
1797
  var add_blocklist_block_default = withStandardDecorators(tool14);
@@ -1692,100 +1854,30 @@ var tool15 = {
1692
1854
  const existingProp = (doc.values ?? []).find(
1693
1855
  (v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
1694
1856
  );
1695
- const propValue = existingProp?.value ?? {
1696
- layout: { "Umbraco.BlockGrid": [] },
1697
- contentData: [],
1698
- settingsData: [],
1699
- expose: []
1700
- };
1701
- if (existingProp && (!isBlockListOrGridValue(propValue) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
1857
+ if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
1702
1858
  return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a BlockGrid. Use inspect-blocks to confirm the editor type, or add-blocklist-block / add-rte-block as appropriate.` }], isError: true });
1703
1859
  }
1704
- const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
1705
- if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
1706
- let settingsEditorAliases = null;
1707
- if (settingsTypeKey) {
1708
- const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
1709
- if (!settingsResult.ok) return settingsResult.errorResult;
1710
- settingsEditorAliases = settingsResult.editorAliasByAlias;
1711
- }
1712
- const newContentKey = randomUUID();
1713
- const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
1714
1860
  const cultureValue = culture ?? null;
1715
1861
  const segmentValue = segment ?? null;
1716
- const newContentEntry = buildBlockEntry(newContentKey, contentTypeKey, values, contentEditorAliases.editorAliasByAlias, cultureValue, segmentValue);
1717
- const newSettingsEntry = settingsTypeKey && newSettingsKey && settingsValues ? buildBlockEntry(newSettingsKey, settingsTypeKey, settingsValues, settingsEditorAliases ?? /* @__PURE__ */ new Map(), cultureValue, segmentValue) : null;
1718
- const layoutKey = "Umbraco.BlockGrid";
1719
- const layoutEntry = {
1720
- contentKey: newContentKey,
1721
- ...newSettingsKey ? { settingsKey: newSettingsKey } : {},
1722
- columnSpan: columnSpan ?? 12,
1723
- rowSpan: rowSpan ?? 1,
1724
- // Top-level grid blocks include an areas array that mirrors the element
1725
- // type's area configuration. We don't know the configured areas without
1726
- // a doc-type lookup, so default to an empty array — Umbraco will fill in
1727
- // the configured areas on first edit in the backoffice.
1728
- ...areaKey ? {} : { areas: [] }
1729
- };
1730
- const topLayout = Array.isArray(propValue.layout?.[layoutKey]) ? propValue.layout[layoutKey] : [];
1731
- let nextTopLayout;
1732
- if (areaKey) {
1733
- const parentIndex = topLayout.findIndex((item) => item.contentKey === parentContentKey);
1734
- if (parentIndex === -1) {
1735
- return createToolResultError({ content: [{ type: "text", text: `Parent block '${parentContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
1736
- }
1737
- const parent = topLayout[parentIndex];
1738
- const areas = Array.isArray(parent.areas) ? parent.areas : [];
1739
- const areaIndex = areas.findIndex((area2) => area2.key === areaKey);
1740
- if (areaIndex === -1) {
1741
- return createToolResultError({ content: [{ type: "text", text: `Area '${areaKey}' was not found on parent block '${parentContentKey}'.` }], isError: true });
1742
- }
1743
- const area = areas[areaIndex];
1744
- const insertResult = insertAtPosition(area.items ?? [], layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
1745
- if (!insertResult.ok) {
1746
- return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in area '${areaKey}'.` }], isError: true });
1747
- }
1748
- const updatedArea = { ...area, items: insertResult.list };
1749
- const updatedAreas = areas.slice();
1750
- updatedAreas[areaIndex] = updatedArea;
1751
- const updatedParent = { ...parent, areas: updatedAreas };
1752
- nextTopLayout = topLayout.slice();
1753
- nextTopLayout[parentIndex] = updatedParent;
1754
- } else {
1755
- const insertResult = insertAtPosition(topLayout, layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
1756
- if (!insertResult.ok) {
1757
- return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
1862
+ const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
1863
+ if (!blockProperties.ok) return blockProperties.errorResult;
1864
+ const createResult = await chainCms("create-document-block", {
1865
+ documentId: id,
1866
+ propertyAlias,
1867
+ culture: cultureValue,
1868
+ segment: segmentValue,
1869
+ contentTypeKey,
1870
+ properties: blockProperties.properties,
1871
+ settings: blockProperties.settings,
1872
+ placement: toPlacement(resolvedPosition),
1873
+ grid: {
1874
+ columnSpan: columnSpan ?? 12,
1875
+ rowSpan: rowSpan ?? 1,
1876
+ ...areaKey && parentContentKey ? { areaKey, parentContentKey } : {}
1758
1877
  }
1759
- nextTopLayout = insertResult.list;
1760
- }
1761
- const newValue = {
1762
- ...propValue,
1763
- layout: { ...propValue.layout ?? {}, [layoutKey]: nextTopLayout },
1764
- contentData: [...propValue.contentData ?? [], newContentEntry],
1765
- settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
1766
- expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
1767
- };
1768
- const updateResult = await chainCms("update-document-properties", {
1769
- id,
1770
- properties: [{
1771
- alias: propertyAlias,
1772
- value: newValue,
1773
- culture: cultureValue,
1774
- segment: segmentValue
1775
- }]
1776
- });
1777
- if (!updateResult.ok) return updateResult.errorResult;
1778
- const validation = await validateDocumentState(id);
1779
- const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
1780
- const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
1781
- return createToolResult({
1782
- message,
1783
- id,
1784
- name: pageName,
1785
- contentKey: newContentKey,
1786
- previewUrl: await fetchPreviewUrl(id),
1787
- validation
1788
1878
  });
1879
+ if (!createResult.ok) return createResult.errorResult;
1880
+ return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
1789
1881
  }
1790
1882
  };
1791
1883
  var add_blockgrid_block_default = withStandardDecorators(tool15);
@@ -1816,26 +1908,6 @@ var outputSchema16 = z.object({
1816
1908
  previewUrl: previewUrlSchema,
1817
1909
  validation: validationResultSchema
1818
1910
  });
1819
- function buildBlockTag(contentKey) {
1820
- return `<umb-rte-block data-content-key="${contentKey}"></umb-rte-block>`;
1821
- }
1822
- function findAnchorTagRange(markup, anchorKey) {
1823
- const re = new RegExp(`<umb-rte-block[^>]*data-content-key="${anchorKey}"[^>]*>\\s*</umb-rte-block>`, "i");
1824
- const match = markup.match(re);
1825
- if (!match || match.index === void 0) return null;
1826
- return { start: match.index, end: match.index + match[0].length };
1827
- }
1828
- function insertMarkup(markup, newTag, mode, anchorKey) {
1829
- if (mode === "append") return { ok: true, markup: `${markup}${newTag}` };
1830
- if (mode === "prepend") return { ok: true, markup: `${newTag}${markup}` };
1831
- if (!anchorKey) return { ok: false, reason: "missing anchor" };
1832
- const range = findAnchorTagRange(markup, anchorKey);
1833
- if (!range) return { ok: false, reason: "anchor not found" };
1834
- if (mode === "before") {
1835
- return { ok: true, markup: `${markup.slice(0, range.start)}${newTag}${markup.slice(range.start)}` };
1836
- }
1837
- return { ok: true, markup: `${markup.slice(0, range.end)}${newTag}${markup.slice(range.end)}` };
1838
- }
1839
1911
  var tool16 = {
1840
1912
  name: "add-rte-block",
1841
1913
  description: "Add a new block inside a Rich Text property on a page. Inserts the umb-rte-block tag in the markup at the chosen position and adds the matching content/settings entries. Use inspect-blocks first to find the propertyAlias and a sample contentTypeKey. For non-string property values inside the block (media pickers, content pickers, image cropper, slider, color, date, etc.) call get-property-value-template with the editor alias first to see the expected JSON shape. For BlockList use add-blocklist-block; for BlockGrid use add-blockgrid-block. Changes are saved as a draft, NOT published.",
@@ -1861,71 +1933,25 @@ var tool16 = {
1861
1933
  const existingProp = (doc.values ?? []).find(
1862
1934
  (v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
1863
1935
  );
1864
- const propValue = existingProp?.value ?? {
1865
- markup: "",
1866
- blocks: { layout: {}, contentData: [], settingsData: [], expose: [] }
1867
- };
1868
- if (existingProp && !isRteWithBlocks(propValue)) {
1936
+ if (existingProp?.value && !isRteWithBlocks(existingProp.value)) {
1869
1937
  return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a rich text with blocks. Use inspect-blocks to confirm the editor type, or add-blocklist-block / add-blockgrid-block as appropriate.` }], isError: true });
1870
1938
  }
1871
- const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
1872
- if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
1873
- let settingsEditorAliases = null;
1874
- if (settingsTypeKey) {
1875
- const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
1876
- if (!settingsResult.ok) return settingsResult.errorResult;
1877
- settingsEditorAliases = settingsResult.editorAliasByAlias;
1878
- }
1879
- const newContentKey = randomUUID();
1880
- const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
1881
1939
  const cultureValue = culture ?? null;
1882
1940
  const segmentValue = segment ?? null;
1883
- const newContentEntry = buildBlockEntry(newContentKey, contentTypeKey, values, contentEditorAliases.editorAliasByAlias, cultureValue, segmentValue);
1884
- const newSettingsEntry = settingsTypeKey && newSettingsKey && settingsValues ? buildBlockEntry(newSettingsKey, settingsTypeKey, settingsValues, settingsEditorAliases ?? /* @__PURE__ */ new Map(), cultureValue, segmentValue) : null;
1885
- const blocks = propValue.blocks;
1886
- const layoutKey = "Umbraco.RichText";
1887
- const existingLayout = Array.isArray(blocks.layout?.[layoutKey]) ? blocks.layout[layoutKey] : [];
1888
- const layoutEntry = newSettingsKey ? { contentKey: newContentKey, settingsKey: newSettingsKey } : { contentKey: newContentKey };
1889
- const insertLayoutResult = insertAtPosition(existingLayout, layoutEntry, resolvedPosition, (entry) => entry.contentKey === resolvedPosition.anchorContentKey);
1890
- if (!insertLayoutResult.ok) {
1891
- return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
1892
- }
1893
- const markupResult = insertMarkup(propValue.markup ?? "", buildBlockTag(newContentKey), resolvedPosition.mode, resolvedPosition.anchorContentKey);
1894
- if (!markupResult.ok) {
1895
- return createToolResultError({ content: [{ type: "text", text: `Could not insert into markup \u2014 ${markupResult.reason}.` }], isError: true });
1896
- }
1897
- const newValue = {
1898
- ...propValue,
1899
- markup: markupResult.markup,
1900
- blocks: {
1901
- ...blocks,
1902
- layout: { ...blocks.layout ?? {}, [layoutKey]: insertLayoutResult.list },
1903
- contentData: [...blocks.contentData ?? [], newContentEntry],
1904
- settingsData: newSettingsEntry ? [...blocks.settingsData ?? [], newSettingsEntry] : blocks.settingsData ?? [],
1905
- expose: [...blocks.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
1906
- }
1907
- };
1908
- const updateResult = await chainCms("update-document-properties", {
1909
- id,
1910
- properties: [{
1911
- alias: propertyAlias,
1912
- value: newValue,
1913
- culture: cultureValue,
1914
- segment: segmentValue
1915
- }]
1916
- });
1917
- if (!updateResult.ok) return updateResult.errorResult;
1918
- const validation = await validateDocumentState(id);
1919
- const baseMessage = `Added a new block to "${pageName}" rich text (saved, not published)`;
1920
- const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
1921
- return createToolResult({
1922
- message,
1923
- id,
1924
- name: pageName,
1925
- contentKey: newContentKey,
1926
- previewUrl: await fetchPreviewUrl(id),
1927
- validation
1941
+ const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
1942
+ if (!blockProperties.ok) return blockProperties.errorResult;
1943
+ const createResult = await chainCms("create-document-block", {
1944
+ documentId: id,
1945
+ propertyAlias,
1946
+ culture: cultureValue,
1947
+ segment: segmentValue,
1948
+ contentTypeKey,
1949
+ properties: blockProperties.properties,
1950
+ settings: blockProperties.settings,
1951
+ placement: toPlacement(resolvedPosition)
1928
1952
  });
1953
+ if (!createResult.ok) return createResult.errorResult;
1954
+ return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" rich text (saved, not published)`);
1929
1955
  }
1930
1956
  };
1931
1957
  var add_rte_block_default = withStandardDecorators(tool16);
@@ -1985,7 +2011,7 @@ var inputSchema18 = {
1985
2011
  propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'mainContent'). Use inspect-blocks to find this."),
1986
2012
  contentKey: z.string().uuid().describe("The unique key of the block to edit. Use inspect-blocks to find this."),
1987
2013
  values: z.array(z.object({
1988
- alias: z.string().describe("The property alias within the block"),
2014
+ alias: blockPropertyAliasSchema.describe("The property alias within the block"),
1989
2015
  value: z.any().describe("The new value for the property")
1990
2016
  })).describe("Properties to update within the block"),
1991
2017
  blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
@@ -1999,7 +2025,8 @@ var outputSchema18 = z.object({
1999
2025
  contentKey: z.string(),
2000
2026
  updatedFields: z.array(z.string()),
2001
2027
  previewUrl: previewUrlSchema,
2002
- validation: validationResultSchema
2028
+ validation: validationResultSchema,
2029
+ warnings: z.array(z.string()).optional()
2003
2030
  });
2004
2031
  var tool18 = {
2005
2032
  name: "edit-block",
@@ -2014,6 +2041,20 @@ var tool18 = {
2014
2041
  const pageName = docResult.data.variants?.[0]?.name ?? "Unknown";
2015
2042
  const fieldNames = values.map((v) => v.alias);
2016
2043
  const resolvedBlockType = blockType ?? "content";
2044
+ let targetKey = contentKey;
2045
+ if (resolvedBlockType === "settings") {
2046
+ const rawValue = (docResult.data.values ?? []).find(
2047
+ (v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
2048
+ )?.value;
2049
+ const container = isRteWithBlocks(rawValue) ? rawValue.blocks : rawValue;
2050
+ const settingsKey = findSettingsKey(container, contentKey);
2051
+ if (!settingsKey) {
2052
+ return createToolResultError(
2053
+ `Block ${contentKey} in property "${propertyAlias}" has no settings entry, so its settings cannot be edited. Use inspect-blocks to check for a settingsKey, or omit blockType to edit the block's content.`
2054
+ );
2055
+ }
2056
+ targetKey = settingsKey;
2057
+ }
2017
2058
  const propsTuple = values.map((v) => ({ alias: v.alias, value: v.value }));
2018
2059
  const updateResult = await chainCms("update-block-property", {
2019
2060
  documentId: id,
@@ -2021,12 +2062,41 @@ var tool18 = {
2021
2062
  culture: culture ?? null,
2022
2063
  segment: segment ?? null,
2023
2064
  updates: [{
2024
- contentKey,
2065
+ contentKey: targetKey,
2025
2066
  blockType: resolvedBlockType,
2026
2067
  properties: propsTuple
2027
2068
  }]
2028
2069
  });
2029
- if (!updateResult.ok) return updateResult.errorResult;
2070
+ if (!updateResult.ok) {
2071
+ return enrichBlockNotFoundError(updateResult.errorResult, docResult.data.values ?? [], {
2072
+ propertyAlias,
2073
+ note: `A block's settingsKey (reported by inspect-blocks) is not a valid contentKey \u2014 pass the block's contentKey together with blockType: "settings" to edit its settings instead.`
2074
+ });
2075
+ }
2076
+ const results = updateResult.data.results;
2077
+ if (!results || results.length === 0) {
2078
+ return createToolResultError(
2079
+ "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
2080
+ );
2081
+ }
2082
+ const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
2083
+ if (classification.outcome === "failed") {
2084
+ return createToolResultError(
2085
+ `Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
2086
+ );
2087
+ }
2088
+ if (classification.outcome === "partial") {
2089
+ return createToolResultError({
2090
+ message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
2091
+ savedFields: classification.savedFields,
2092
+ failedFields: classification.failedFields,
2093
+ ...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {},
2094
+ ...classification.warnings.length ? { warnings: classification.warnings } : {},
2095
+ validation: await validateDocumentState(id),
2096
+ previewUrl: await fetchPreviewUrl(id)
2097
+ });
2098
+ }
2099
+ const warnings = classification.warnings;
2030
2100
  const validation = await validateDocumentState(id);
2031
2101
  const target = resolvedBlockType === "settings" ? "settings" : "content";
2032
2102
  const baseMessage = `Updated ${fieldNames.length} field(s) in block ${target} on "${pageName}" (saved, not published)`;
@@ -2038,7 +2108,8 @@ var tool18 = {
2038
2108
  contentKey,
2039
2109
  updatedFields: fieldNames,
2040
2110
  previewUrl: await fetchPreviewUrl(id),
2041
- validation
2111
+ validation,
2112
+ ...warnings.length ? { warnings } : {}
2042
2113
  });
2043
2114
  }
2044
2115
  };
@@ -2092,10 +2163,9 @@ var tool19 = {
2092
2163
  });
2093
2164
  }
2094
2165
  const cultureLabel = targetCulture ? ` (${targetCulture})` : "";
2095
- const confirmed = await confirmAction(
2166
+ const confirmed = await requestApproval(
2096
2167
  extra,
2097
- `Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`,
2098
- { title: "Confirm rename" }
2168
+ `Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`
2099
2169
  );
2100
2170
  if (!confirmed) {
2101
2171
  return createToolResult({
@@ -2382,68 +2452,26 @@ var outputSchema24 = z.object({
2382
2452
  previewUrl: previewUrlSchema,
2383
2453
  validation: validationResultSchema
2384
2454
  });
2385
- function findAndRemoveGridItem(items, contentKey) {
2386
- const idx = items.findIndex((item) => item.contentKey === contentKey);
2387
- if (idx !== -1) {
2388
- return { found: true, doomedSettingsKey: items[idx].settingsKey, nextItems: items.filter((_, i) => i !== idx) };
2389
- }
2390
- for (let i = 0; i < items.length; i++) {
2391
- const item = items[i];
2392
- if (!Array.isArray(item.areas)) continue;
2393
- for (let aIdx = 0; aIdx < item.areas.length; aIdx++) {
2394
- const inner = findAndRemoveGridItem(item.areas[aIdx].items ?? [], contentKey);
2395
- if (inner.found) {
2396
- const updatedAreas = item.areas.slice();
2397
- updatedAreas[aIdx] = { ...item.areas[aIdx], items: inner.nextItems };
2398
- const nextItems = items.slice();
2399
- nextItems[i] = { ...item, areas: updatedAreas };
2400
- return { found: true, doomedSettingsKey: inner.doomedSettingsKey, nextItems };
2401
- }
2402
- }
2403
- }
2404
- return { found: false };
2455
+ function gridContainsBlock(items, contentKey) {
2456
+ return items.some(
2457
+ (item) => item.contentKey === contentKey || (item.areas ?? []).some((area) => gridContainsBlock(area.items ?? [], contentKey))
2458
+ );
2405
2459
  }
2406
- function planRemoval(propValue, editorAlias, propertyAlias, contentKey, pageName) {
2460
+ function locateBlock(propValue, editorAlias, propertyAlias, contentKey, pageName) {
2407
2461
  const notFound = { ok: false, errorText: `Block '${contentKey}' was not found in property '${propertyAlias}'.` };
2408
2462
  const draftSuffix = "Will be saved as a draft, not published.";
2409
2463
  if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockList") {
2410
- const layoutKey = "Umbraco.BlockList";
2411
- const layoutList = propValue.layout?.[layoutKey] ?? [];
2412
- const doomed = layoutList.find((e) => e.contentKey === contentKey);
2413
- if (!doomed) return notFound;
2414
- return {
2415
- ok: true,
2416
- newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomed.settingsKey),
2417
- confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}`
2418
- };
2464
+ const layoutList = propValue.layout?.["Umbraco.BlockList"] ?? [];
2465
+ if (!layoutList.some((e) => e.contentKey === contentKey)) return notFound;
2466
+ return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}` };
2419
2467
  }
2420
2468
  if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockGrid") {
2421
- const layoutKey = "Umbraco.BlockGrid";
2422
- const removed = findAndRemoveGridItem(propValue.layout?.[layoutKey] ?? [], contentKey);
2423
- if (!removed.found) return notFound;
2424
- return {
2425
- ok: true,
2426
- newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, removed.nextItems, removed.doomedSettingsKey),
2427
- confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}`
2428
- };
2469
+ if (!gridContainsBlock(propValue.layout?.["Umbraco.BlockGrid"] ?? [], contentKey)) return notFound;
2470
+ return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}` };
2429
2471
  }
2430
2472
  if (isRteWithBlocks(propValue)) {
2431
- const layoutKey = "Umbraco.RichText";
2432
- const blocks = propValue.blocks;
2433
- const layoutList = blocks.layout?.[layoutKey] ?? [];
2434
- const inContent = (blocks.contentData ?? []).some((e) => e.key === contentKey);
2435
- if (!inContent) return notFound;
2436
- const doomedSettingsKey = layoutList.find((e) => e.contentKey === contentKey)?.settingsKey;
2437
- const tagRe = new RegExp(`<umb-rte-block[^>]*data-content-key="${contentKey}"[^>]*>\\s*</umb-rte-block>`, "gi");
2438
- return {
2439
- ok: true,
2440
- newValue: {
2441
- ...propValue,
2442
- markup: (propValue.markup ?? "").replace(tagRe, ""),
2443
- blocks: removeBlockFromContainer(blocks, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomedSettingsKey)
2444
- },
2445
- confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}`
2446
- };
2473
+ if (!(propValue.blocks.contentData ?? []).some((e) => e.key === contentKey)) return notFound;
2474
+ return { ok: true, confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}` };
2447
2475
  }
2448
2476
  return { ok: false, errorText: `Property '${propertyAlias}' on '${pageName}' is not a block-bearing property (BlockList, BlockGrid, or Rich Text with blocks). Use inspect-blocks to confirm.` };
2449
2477
  }
@@ -2468,29 +2496,22 @@ var tool24 = {
2468
2496
  isError: true
2469
2497
  });
2470
2498
  }
2471
- const plan = planRemoval(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
2472
- if (!plan.ok) {
2473
- return createToolResultError({ content: [{ type: "text", text: plan.errorText }], isError: true });
2499
+ const location = locateBlock(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
2500
+ if (!location.ok) {
2501
+ return createToolResultError({ content: [{ type: "text", text: location.errorText }], isError: true });
2474
2502
  }
2475
- if (!await requestApproval(extra, plan.confirmMessage)) {
2503
+ if (!await requestApproval(extra, location.confirmMessage)) {
2476
2504
  return createToolResultError({ content: [{ type: "text", text: "Cancelled by user." }], isError: true });
2477
2505
  }
2478
- const updateResult = await chainCms("update-document-properties", {
2479
- id,
2480
- properties: [{ alias: propertyAlias, value: plan.newValue, culture: culture ?? null, segment: segment ?? null }]
2481
- });
2482
- if (!updateResult.ok) return updateResult.errorResult;
2483
- const validation = await validateDocumentState(id);
2484
- const baseMessage = `Removed block from "${pageName}" (saved, not published)`;
2485
- const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
2486
- return createToolResult({
2487
- message,
2488
- id,
2489
- name: pageName,
2490
- contentKey,
2491
- previewUrl: await fetchPreviewUrl(id),
2492
- validation
2506
+ const deleteResult = await chainCms("delete-document-block", {
2507
+ documentId: id,
2508
+ propertyAlias,
2509
+ culture: culture ?? null,
2510
+ segment: segment ?? null,
2511
+ contentKey
2493
2512
  });
2513
+ if (!deleteResult.ok) return deleteResult.errorResult;
2514
+ return buildBlockWriteResult(id, pageName, contentKey, `Removed block from "${pageName}" (saved, not published)`);
2494
2515
  }
2495
2516
  };
2496
2517
  var delete_block_default = withStandardDecorators(tool24);
@@ -2753,7 +2774,7 @@ var tool27 = {
2753
2774
  });
2754
2775
  if (!updateAndPublishResult.ok) {
2755
2776
  const rolledBack = `No changes were saved to "${pageName}" \u2014 save-and-publish is a single atomic operation, so the field updates were rolled back along with the publish.`;
2756
- const problem = updateAndPublishResult.errorResult.structuredContent;
2777
+ const problem = extractInnerProblemDetails(updateAndPublishResult.errorResult);
2757
2778
  return createToolResultError({
2758
2779
  ...problem,
2759
2780
  status: typeof problem?.status === "number" ? problem.status : 500,
@@ -3615,12 +3636,7 @@ function validateBulkIds(ids) {
3615
3636
  function parseBulkError(err) {
3616
3637
  if (err === null || err === void 0) return "Unknown error";
3617
3638
  if (typeof err === "object") {
3618
- const asRecord = err;
3619
- const sc = asRecord.structuredContent;
3620
- if (sc !== null && sc !== void 0 && typeof sc === "object") {
3621
- return sc;
3622
- }
3623
- return err;
3639
+ return extractInnerProblemDetails(err);
3624
3640
  }
3625
3641
  if (typeof err === "string") {
3626
3642
  try {
@@ -4024,31 +4040,12 @@ var tool50 = {
4024
4040
  slices: ["create"],
4025
4041
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
4026
4042
  handler: async ({ name, elementTypeId, parentId, values }) => {
4027
- const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
4028
- if (values && values.length > 0) {
4029
- const typeResult = await chainCms("get-document-type-by-id", { id: elementTypeId });
4030
- if (!typeResult.ok) return typeResult.errorResult;
4031
- const dataTypeIds = Array.from(new Set(typeResult.data.properties.map((p) => p.dataType.id)));
4032
- const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
4033
- if (!dataTypesResult.ok) return dataTypesResult.errorResult;
4034
- const editorAliasByDataTypeId = new Map(
4035
- dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
4036
- );
4037
- for (const prop of typeResult.data.properties) {
4038
- const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
4039
- if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
4040
- }
4041
- }
4043
+ const resolved = await resolveEditorAliases(elementTypeId, values);
4044
+ if (!resolved.ok) return resolved.errorResult;
4042
4045
  const createResult = await chainCms("create-element", {
4043
4046
  documentTypeId: elementTypeId,
4044
4047
  name,
4045
- values: (values ?? []).map((v) => ({
4046
- alias: v.alias,
4047
- value: v.value,
4048
- culture: v.culture ?? null,
4049
- segment: v.segment ?? null,
4050
- editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
4051
- })),
4048
+ values: resolved.values,
4052
4049
  ...parentId ? { parentId } : {}
4053
4050
  });
4054
4051
  if (!createResult.ok) return createResult.errorResult;
@@ -4260,7 +4257,7 @@ var inputSchema56 = {
4260
4257
  propertyAlias: z.string().describe("The element property alias containing the blocks (e.g. 'mainContent'). Use inspect-element-blocks to find this."),
4261
4258
  contentKey: z.string().uuid().describe("The unique key of the block to edit \u2014 always the block's contentKey as reported by inspect-element-blocks, including when blockType is 'settings'."),
4262
4259
  values: z.array(z.object({
4263
- alias: z.string().describe("The property alias within the block"),
4260
+ alias: blockPropertyAliasSchema.describe("The property alias within the block"),
4264
4261
  value: z.any().describe("The new value for the property")
4265
4262
  })).min(1).describe("Properties to update within the block"),
4266
4263
  blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
@@ -4315,15 +4312,29 @@ var tool56 = {
4315
4312
  }]
4316
4313
  });
4317
4314
  if (!updateResult.ok) return updateResult.errorResult;
4318
- const failed = (updateResult.data.results ?? []).filter((r) => r.success === false);
4319
- if (failed.length > 0) {
4320
- const detail = failed.flatMap((r) => r.errors?.length ? r.errors : [r.message]).join("; ");
4315
+ const results = updateResult.data.results;
4316
+ if (!results || results.length === 0) {
4317
+ return createToolResultError(
4318
+ "update-element-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
4319
+ );
4320
+ }
4321
+ const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
4322
+ if (classification.outcome === "failed") {
4321
4323
  return createToolResultError(
4322
- `Block update failed: ${detail || updateResult.data.message || "no detail returned"}`
4324
+ `Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
4323
4325
  );
4324
4326
  }
4327
+ if (classification.outcome === "partial") {
4328
+ return createToolResultError({
4329
+ message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
4330
+ savedFields: classification.savedFields,
4331
+ failedFields: classification.failedFields,
4332
+ ...classification.savedFields.length > 0 ? { note: "savedFields were written to the element and must not be retried." } : {},
4333
+ ...classification.warnings.length ? { warnings: classification.warnings } : {}
4334
+ });
4335
+ }
4325
4336
  const target = resolvedBlockType === "settings" ? "settings" : "content";
4326
- const warnings = (updateResult.data.results ?? []).flatMap((r) => r.warnings ?? []);
4337
+ const warnings = classification.warnings;
4327
4338
  return createToolResult({
4328
4339
  message: `Updated ${fieldNames.length} field(s) in block ${target} on element "${elementName}" (saved, not published)`,
4329
4340
  id,
@@ -4408,6 +4419,15 @@ var tool58 = {
4408
4419
  slices: ["list"],
4409
4420
  annotations: { readOnlyHint: true },
4410
4421
  handler: async ({ parentId, take, skip }) => {
4422
+ const accessCheck = await checkSettingsAccess();
4423
+ if (!accessCheck.ok) return accessCheck.errorResult;
4424
+ if (!accessCheck.hasAccess) {
4425
+ return createToolResultError({
4426
+ status: 403,
4427
+ title: "Settings access required",
4428
+ detail: "Listing blueprints requires the signed-in Umbraco user to have access to the Settings section. Grant Settings-section access to the user's group in the Umbraco backoffice (Users \u2192 [group] \u2192 Sections), then retry."
4429
+ });
4430
+ }
4411
4431
  const cursor = buildChainedCursor(skip, take);
4412
4432
  const result = parentId ? await chainCms("get-document-blueprint-children", { parentId, cursor }) : await chainCms("get-document-blueprint-root", { cursor });
4413
4433
  if (!result.ok) return result.errorResult;
@@ -5941,7 +5961,7 @@ var inputSchema85 = {
5941
5961
  contentTypeKey: z.string().uuid().describe("The block element type key to target. Use inspect-blocks to find this."),
5942
5962
  propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'contentRows'). Use inspect-blocks to find this."),
5943
5963
  values: z.array(z.object({
5944
- alias: z.string().describe("The property alias within the block"),
5964
+ alias: blockPropertyAliasSchema.describe("The property alias within the block"),
5945
5965
  value: z.any().describe("The new value for the property")
5946
5966
  })).min(1).describe("Properties to update on every matching block"),
5947
5967
  culture: z.string().nullable().optional().describe("Culture code if the document property is variant"),
@@ -5957,7 +5977,8 @@ var outputSchema85 = z.object({
5957
5977
  previousVersionId: z.string().optional(),
5958
5978
  error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
5959
5979
  previewUrl: previewUrlSchema.optional(),
5960
- validation: validationResultSchema.optional()
5980
+ validation: validationResultSchema.optional(),
5981
+ warnings: z.array(z.string()).optional()
5961
5982
  })),
5962
5983
  successCount: z.number(),
5963
5984
  failureCount: z.number(),
@@ -6001,6 +6022,7 @@ var tool85 = {
6001
6022
  });
6002
6023
  const items = [];
6003
6024
  const pageBlocks = /* @__PURE__ */ new Map();
6025
+ const docValuesByItem = /* @__PURE__ */ new Map();
6004
6026
  for (const id of ids) {
6005
6027
  const docResult = await chainCms("get-document-by-id", { id });
6006
6028
  if (!docResult.ok) continue;
@@ -6014,6 +6036,7 @@ var tool85 = {
6014
6036
  const currentVersionId = versionData?.items?.[0]?.id ?? "";
6015
6037
  items.push({ id, name, currentVersionId });
6016
6038
  pageBlocks.set(id, findMatchingBlocks(doc, propertyAlias, contentTypeKey));
6039
+ docValuesByItem.set(id, doc.values ?? []);
6017
6040
  }
6018
6041
  if (items.length === 0) {
6019
6042
  return createToolResult({
@@ -6086,28 +6109,68 @@ Changes will be saved but not published.`;
6086
6109
  updates
6087
6110
  });
6088
6111
  if (!updateResult.ok) {
6112
+ const enriched = enrichBlockNotFoundError(
6113
+ updateResult.errorResult,
6114
+ docValuesByItem.get(item.id) ?? [],
6115
+ { propertyAlias }
6116
+ );
6089
6117
  results.push({
6090
6118
  id: item.id,
6091
6119
  name: item.name,
6092
6120
  success: false,
6093
6121
  blocksUpdated: 0,
6094
6122
  previousVersionId: item.currentVersionId || void 0,
6095
- error: parseBulkError(updateResult.errorResult)
6123
+ error: parseBulkError(enriched)
6096
6124
  });
6097
6125
  stopped = true;
6098
6126
  } else {
6099
- totalBlocksUpdated += blocks.length;
6100
- results.push({
6101
- id: item.id,
6102
- name: item.name,
6103
- success: true,
6104
- blocksUpdated: blocks.length,
6105
- previousVersionId: item.currentVersionId || void 0
6106
- });
6127
+ const blockResults = updateResult.data.results;
6128
+ if (!blockResults || blockResults.length === 0) {
6129
+ results.push({
6130
+ id: item.id,
6131
+ name: item.name,
6132
+ success: false,
6133
+ blocksUpdated: 0,
6134
+ previousVersionId: item.currentVersionId || void 0,
6135
+ error: "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
6136
+ });
6137
+ stopped = true;
6138
+ } else {
6139
+ const classification = classifyBlockUpdateResults(blockResults, blocks.length * values.length, fieldNames, blocks.length);
6140
+ if (classification.outcome === "clean") {
6141
+ totalBlocksUpdated += blocks.length;
6142
+ results.push({
6143
+ id: item.id,
6144
+ name: item.name,
6145
+ success: true,
6146
+ blocksUpdated: blocks.length,
6147
+ previousVersionId: item.currentVersionId || void 0,
6148
+ ...classification.warnings.length ? { warnings: classification.warnings } : {}
6149
+ });
6150
+ } else {
6151
+ totalBlocksUpdated += classification.updatedEntryCount;
6152
+ const totalProperties = blocks.length * values.length;
6153
+ results.push({
6154
+ id: item.id,
6155
+ name: item.name,
6156
+ success: false,
6157
+ blocksUpdated: classification.updatedEntryCount,
6158
+ previousVersionId: item.currentVersionId || void 0,
6159
+ error: classification.outcome === "failed" ? `Block update failed: ${classification.detail}` : {
6160
+ message: `Block update partially failed: ${classification.processedCount} of ${totalProperties} propert${totalProperties === 1 ? "y" : "ies"} saved, across ${classification.updatedEntryCount} of ${blockResults.length} block(s)` + (classification.unresolvedBlockCount > 0 ? ` (${classification.unresolvedBlockCount} matched block(s) could not be located \u2014 likely changed concurrently; rerun this tool to retarget them)` : "") + ` \u2014 ${classification.detail}`,
6161
+ savedFields: classification.savedFields,
6162
+ failedFields: classification.failedFields,
6163
+ ...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {}
6164
+ },
6165
+ ...classification.warnings.length ? { warnings: classification.warnings } : {}
6166
+ });
6167
+ stopped = true;
6168
+ }
6169
+ }
6107
6170
  }
6108
6171
  }
6109
6172
  for (const row of results) {
6110
- if (!row.success || row.blocksUpdated === 0) continue;
6173
+ if (row.blocksUpdated === 0) continue;
6111
6174
  row.validation = await validateDocumentState(row.id);
6112
6175
  row.previewUrl = await fetchPreviewUrl(row.id);
6113
6176
  }
@@ -6192,12 +6255,10 @@ var tool86 = {
6192
6255
  var search_members_default = withStandardDecorators(tool86);
6193
6256
 
6194
6257
  // src/umbraco-api/tools/member/sensitive-data-access.ts
6195
- var cachedAccess;
6196
- async function hasSensitiveDataAccess() {
6197
- if (cachedAccess !== void 0) return cachedAccess;
6258
+ async function checkSensitiveDataAccess() {
6198
6259
  const result = await chainCms("get-user-current", {});
6199
- cachedAccess = result.ok ? result.data.hasAccessToSensitiveData ?? false : false;
6200
- return cachedAccess;
6260
+ if (!result.ok) return result;
6261
+ return { ok: true, hasAccess: result.data.hasAccessToSensitiveData ?? false };
6201
6262
  }
6202
6263
 
6203
6264
  // src/umbraco-api/tools/member/get/get-member.ts
@@ -6235,7 +6296,8 @@ var tool87 = {
6235
6296
  const result = await chainCms("get-member", { id });
6236
6297
  if (!result.ok) return result.errorResult;
6237
6298
  const data = result.data;
6238
- const accessible = await hasSensitiveDataAccess();
6299
+ const accessCheck = await checkSensitiveDataAccess();
6300
+ const accessible = accessCheck.ok && accessCheck.hasAccess;
6239
6301
  return createToolResult({
6240
6302
  id: data.id ?? id,
6241
6303
  name: data.variants?.[0]?.name ?? "Unknown",
@@ -6394,12 +6456,16 @@ var tool90 = {
6394
6456
  slices: ["update"],
6395
6457
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
6396
6458
  handler: async ({ id, name, email, username, newPassword, isTwoFactorEnabled, isApproved, isLockedOut, groups, values }, extra) => {
6397
- if ((isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) && !await hasSensitiveDataAccess()) {
6398
- return createToolResultError({
6399
- status: 403,
6400
- title: "Sensitive Data access required",
6401
- detail: "Updating isApproved, isLockedOut, or isTwoFactorEnabled requires the API user to be in Umbraco's built-in Sensitive Data user group (group key 8C6AD70F-D307-4E4A-AF58-72C2E4E9439D). Add the API user to that group in the Umbraco backoffice (Settings \u2192 Users \u2192 API Users \u2192 groups), then retry. Other update-member fields (name, email, username, groups, values, newPassword) are not affected."
6402
- });
6459
+ if (isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) {
6460
+ const accessCheck = await checkSensitiveDataAccess();
6461
+ if (!accessCheck.ok) return accessCheck.errorResult;
6462
+ if (!accessCheck.hasAccess) {
6463
+ return createToolResultError({
6464
+ status: 403,
6465
+ title: "Sensitive Data access required",
6466
+ detail: "Updating isApproved, isLockedOut, or isTwoFactorEnabled requires the signed-in Umbraco user to be in the built-in Sensitive Data user group (group key 8C6AD70F-D307-4E4A-AF58-72C2E4E9439D). In the Umbraco backoffice, edit the user's User group under Users and add the Sensitive Data group, then retry. Other update-member fields (name, email, username, groups, values, newPassword) are not affected."
6467
+ });
6468
+ }
6403
6469
  }
6404
6470
  const memberResult = await chainCms("get-member", { id });
6405
6471
  if (!memberResult.ok) return memberResult.errorResult;
@@ -8231,17 +8297,16 @@ Talk like a helpful colleague, not a developer. Many editors are not very techni
8231
8297
  - If a tool fails, say what went wrong in plain language and suggest the next step the editor can take. Don't dump stack traces or raw error payloads on them.
8232
8298
  - It's fine to ask a clarifying question if you genuinely need one \u2014 but only if the answer would change what you do. Otherwise just get on with it.
8233
8299
 
8234
- # Confirmations come from the tools, not from you
8300
+ # Confirmations come from the host and the tools, not from you
8235
8301
 
8236
- Many tools (anything destructive, anything that publishes, unpublishes, deletes, moves, or applies in bulk) will pop up their own confirmation prompt via MCP elicitation before they do anything. That prompt is the source of truth for the editor's consent.
8302
+ Changes such as publishing, unpublishing, deleting, moving, or bulk edits are confirmed by a prompt the editor sees. That's either the tool's own confirmation (in hosts that support MCP elicitation) or the host's own approval step (e.g. ChatGPT's Allow / Deny). The editor is never asked twice. That prompt is their consent:
8237
8303
 
8238
- - Do NOT skip, bypass, or pre-answer those prompts on the user's behalf. The editor must see and confirm them.
8239
- - Do NOT promise an action is done before the tool has actually returned success. "Just confirm the prompt and I'll proceed" is fine; "Done!" before confirmation is not.
8240
- - Do NOT batch destructive actions into a single ask to dodge multiple confirmations \u2014 let each tool elicit as it normally would.
8241
- - When you describe what's about to happen, describe it accurately in editorial terms (e.g. "this will take the Home page off the live website") so the editor can make a real decision.
8242
- - If the editor cancels at the prompt, treat that as a clear "no" \u2014 acknowledge it warmly and stop. Don't retry or argue.
8304
+ - Before calling the tool, say accurately and in editorial terms what will happen (e.g. "this will take the Home page off the live website").
8305
+ - Never answer or bypass a prompt on the editor's behalf, and don't bundle actions to avoid prompts.
8306
+ - Only say something is done once the tool has returned success.
8307
+ - If the editor declines, accept it warmly and stop.
8243
8308
 
8244
- Being friendly never means being loose with destructive actions. The tone is warm; the safety rails stay on.
8309
+ Being friendly never means being loose with destructive actions.
8245
8310
 
8246
8311
  # Never show internal IDs or UUIDs to the editor
8247
8312