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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
  import 'dotenv/config';
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
5
- import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas } from '@umbraco-cms/mcp-server-sdk';
5
+ import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, resetServerConfig, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas, isLoopbackUrl } from '@umbraco-cms/mcp-server-sdk';
6
6
  import { z } from 'zod';
7
7
  import { statSync, readFileSync } from 'fs';
8
8
  import { resolve } from 'path';
9
9
 
10
10
  // package.json
11
11
  var package_default = {
12
- version: "17.6.0-beta.8"};
12
+ version: "17.6.0-beta.9"};
13
13
 
14
14
  // src/auth/chained-deps.generated.ts
15
15
  var CHAINED_DEPS = {
@@ -33,7 +33,7 @@ var CHAINED_DEPS = {
33
33
  "create-media-folder": ["create-media-folder", "get-media-by-id"],
34
34
  "create-member": ["create-member", "get-member", "update-member"],
35
35
  "create-member-group": ["create-member-group"],
36
- "create-page": ["create-document", "get-data-types-by-id-array", "get-document-type-by-id"],
36
+ "create-page": ["create-document", "get-data-types-by-id-array", "get-document-type-by-id", "get-language"],
37
37
  "create-variant": ["get-document-by-id", "update-document"],
38
38
  "delete-block": ["get-document-by-id", "update-document-properties"],
39
39
  "delete-language": ["delete-language", "get-language-by-iso-code"],
@@ -117,8 +117,9 @@ var CHAINED_DEPS = {
117
117
  "update-member": ["get-member", "update-member"],
118
118
  "upload-media": ["create-media", "get-media-by-id"]
119
119
  };
120
-
121
- // src/config/mcp-servers.ts
120
+ function chainedTlsEnv(baseUrl) {
121
+ return isLoopbackUrl(baseUrl) ? { NODE_TLS_REJECT_UNAUTHORIZED: "0" } : {};
122
+ }
122
123
  async function buildServers() {
123
124
  const isWorkersRuntime = typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers";
124
125
  if (isWorkersRuntime || typeof process === "undefined" || !process.env) return [];
@@ -143,13 +144,14 @@ async function buildServers() {
143
144
  const binEntry = typeof cmsDevPkg.bin === "string" ? cmsDevPkg.bin : cmsDevPkg.bin ? Object.values(cmsDevPkg.bin)[0] : void 0;
144
145
  if (!binEntry) throw new Error("@umbraco-cms/mcp-dev has no bin entry");
145
146
  const binAbs = path.resolve(path.dirname(pkgPath), binEntry);
147
+ const baseUrl = process.env.UMBRACO_BASE_URL || "http://localhost:44391";
146
148
  return [{
147
149
  name: "cms",
148
150
  command: process.execPath,
149
151
  args: [binAbs],
150
152
  env: {
151
- NODE_TLS_REJECT_UNAUTHORIZED: "0",
152
- UMBRACO_BASE_URL: process.env.UMBRACO_BASE_URL || "http://localhost:44391",
153
+ ...chainedTlsEnv(baseUrl),
154
+ UMBRACO_BASE_URL: baseUrl,
153
155
  UMBRACO_CLIENT_ID: process.env.UMBRACO_CLIENT_ID || "",
154
156
  UMBRACO_CLIENT_SECRET: process.env.UMBRACO_CLIENT_SECRET || "",
155
157
  // Clear tool filters so our editor tool names (search-content etc.) don't
@@ -762,10 +764,15 @@ var tool4 = {
762
764
  var list_document_types_default = withStandardDecorators(tool4);
763
765
 
764
766
  // src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
765
- async function resolveDocumentTypeProperties(documentTypeId) {
766
- const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
767
- if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
768
- const data = docTypeResult.data;
767
+ async function resolveDocumentTypeProperties(documentTypeId, documentType) {
768
+ let data;
769
+ if (documentType) {
770
+ data = documentType;
771
+ } else {
772
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
773
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
774
+ data = docTypeResult.data;
775
+ }
769
776
  const collected = /* @__PURE__ */ new Map();
770
777
  function addProperties(props) {
771
778
  for (const p of props) {
@@ -1504,11 +1511,11 @@ ${aliases.join("\n")}`
1504
1511
  }
1505
1512
  };
1506
1513
  var get_property_value_template_default = withStandardDecorators(tool10);
1507
- async function resolveEditorAliases(documentTypeId, values) {
1514
+ async function resolveEditorAliases(documentTypeId, values, { defaultCulture = null, documentType, siteCultures } = {}) {
1508
1515
  if (!values || values.length === 0) {
1509
1516
  return { ok: true, values: [] };
1510
1517
  }
1511
- const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
1518
+ const docTypeResult = await resolveDocumentTypeProperties(documentTypeId, documentType);
1512
1519
  if (!docTypeResult.ok) return docTypeResult;
1513
1520
  const dataTypeIds = Array.from(
1514
1521
  new Set(
@@ -1527,22 +1534,32 @@ async function resolveEditorAliases(documentTypeId, values) {
1527
1534
  docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
1528
1535
  );
1529
1536
  const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
1537
+ const cultureVariantAliases = /* @__PURE__ */ new Set();
1530
1538
  for (const prop of docTypeResult.properties) {
1531
1539
  const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
1532
1540
  if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
1541
+ if (prop.alias && prop.variesByCulture) cultureVariantAliases.add(prop.alias);
1533
1542
  }
1534
1543
  const notAProperty = /* @__PURE__ */ new Set();
1535
1544
  const missingEditorAlias = /* @__PURE__ */ new Set();
1545
+ const unknownCultures = /* @__PURE__ */ new Set();
1536
1546
  const resolved = values.map((v) => {
1537
1547
  const editorAlias = editorAliasByPropertyAlias.get(v.alias);
1538
1548
  if (!editorAlias) {
1539
1549
  if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
1540
1550
  else notAProperty.add(v.alias);
1541
1551
  }
1552
+ let culture = v.culture ?? (cultureVariantAliases.has(v.alias) ? defaultCulture : null);
1553
+ if (v.culture && siteCultures) {
1554
+ const requested = v.culture.toLowerCase();
1555
+ const match = siteCultures.find((c) => c.toLowerCase() === requested);
1556
+ if (match) culture = match;
1557
+ else unknownCultures.add(v.culture);
1558
+ }
1542
1559
  return {
1543
1560
  alias: v.alias,
1544
1561
  value: v.value,
1545
- culture: v.culture ?? null,
1562
+ culture,
1546
1563
  segment: v.segment ?? null,
1547
1564
  editorAlias: editorAlias ?? ""
1548
1565
  };
@@ -1573,14 +1590,74 @@ async function resolveEditorAliases(documentTypeId, values) {
1573
1590
  )
1574
1591
  };
1575
1592
  }
1593
+ if (unknownCultures.size > 0 && siteCultures) {
1594
+ return {
1595
+ ok: false,
1596
+ errorResult: createToolResultError(
1597
+ `The following value culture(s) are not languages on this site: ${Array.from(unknownCultures).join(", ")}. Available cultures: ${siteCultures.join(", ")}.`
1598
+ )
1599
+ };
1600
+ }
1576
1601
  return { ok: true, values: resolved };
1577
1602
  }
1603
+ var LANGUAGE_PAGE_SIZE = 100;
1604
+ async function resolvePageCulture(documentTypeId, culture, { forPublish = false } = {}) {
1605
+ const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
1606
+ if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
1607
+ const documentType = docTypeResult.data;
1608
+ if (!documentType.variesByCulture) {
1609
+ return { ok: true, culture: null, documentType };
1610
+ }
1611
+ const langResult = await chainCms("get-language", { cursor: encodeCursor({ s: 0, t: LANGUAGE_PAGE_SIZE }) });
1612
+ if (!langResult.ok) return { ok: false, errorResult: langResult.errorResult };
1613
+ const languages = langResult.data.items ?? [];
1614
+ const complete = (langResult.data.total ?? languages.length) <= languages.length;
1615
+ const siteCultures = languages.map((l) => l.isoCode);
1616
+ let pageCulture;
1617
+ if (culture) {
1618
+ const match = siteCultures.find((c) => c.toLowerCase() === culture.toLowerCase());
1619
+ if (!match && complete) {
1620
+ return {
1621
+ ok: false,
1622
+ errorResult: createToolResultError(
1623
+ `Culture "${culture}" is not a language on this site. Available cultures: ${siteCultures.join(", ")}.`
1624
+ )
1625
+ };
1626
+ }
1627
+ pageCulture = match ?? culture;
1628
+ } else {
1629
+ const defaultLanguage = languages.find((l) => l.isDefault);
1630
+ if (!defaultLanguage?.isoCode) {
1631
+ return {
1632
+ ok: false,
1633
+ errorResult: createToolResultError(
1634
+ "This document type varies by culture, but no default language could be determined. Call list-languages and pass `culture` explicitly."
1635
+ )
1636
+ };
1637
+ }
1638
+ pageCulture = defaultLanguage.isoCode;
1639
+ }
1640
+ if (forPublish) {
1641
+ const missingMandatory = languages.filter((l) => l.isMandatory && l.isoCode !== pageCulture).map((l) => l.isoCode);
1642
+ if (missingMandatory.length > 0) {
1643
+ const one = missingMandatory.length === 1;
1644
+ return {
1645
+ ok: false,
1646
+ errorResult: createToolResultError(
1647
+ `Cannot create and publish this page in ${pageCulture} alone: ${missingMandatory.join(", ")} ${one ? "is a mandatory language" : "are mandatory languages"} on this site, and a page can only be published once it exists in every mandatory language. Nothing was created. ${one ? `Either pass culture "${missingMandatory[0]}", or use` : "Use"} create-page, add the other language(s) with create-variant, then publish.`
1648
+ )
1649
+ };
1650
+ }
1651
+ }
1652
+ return { ok: true, culture: pageCulture, documentType, siteCultures: complete ? siteCultures : void 0 };
1653
+ }
1578
1654
 
1579
1655
  // src/umbraco-api/tools/content/post/create-page.ts
1580
1656
  var inputSchema11 = {
1581
1657
  name: z.string().describe("The name of the page to create"),
1582
1658
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1583
1659
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1660
+ culture: z.string().optional().describe("Culture (ISO code, e.g. en-US) to create the page in. Only used when the document type varies by culture; defaults to the site's default language. Call list-languages for the available cultures. Add further languages afterwards with create-variant or copy-variant."),
1584
1661
  values: z.array(z.object({
1585
1662
  alias: z.string().describe("The property alias"),
1586
1663
  value: z.any().describe("The property value"),
@@ -1592,23 +1669,28 @@ var outputSchema11 = z.object({
1592
1669
  message: z.string(),
1593
1670
  id: z.string(),
1594
1671
  name: z.string(),
1672
+ culture: z.string().nullable().describe("The culture the page was created in \u2014 the requested `culture`, or the site's default language when none was given. Null when the document type does not vary by culture."),
1595
1673
  previewUrl: previewUrlSchema,
1596
1674
  validation: validationResultSchema
1597
1675
  });
1598
1676
  var tool11 = {
1599
1677
  name: "create-page",
1600
- description: "Create a new content page as a draft \u2014 the page will NOT be published automatically. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values (strings, numbers, booleans). For everything else, follow up with the dedicated tools after creation \u2014 they're shorter, safer, and avoid the JSON-payload errors that come from cramming a full page into one call: edit-page for property updates, add-blocklist-block / add-blockgrid-block / add-rte-block for block content, edit-block for block-property edits, and get-property-value-template for the value shape of structured non-block editors (media pickers, image cropper, etc.).",
1678
+ description: "Create a new content page as a draft \u2014 the page will NOT be published automatically. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values (strings, numbers, booleans). For everything else, follow up with the dedicated tools after creation \u2014 they're shorter, safer, and avoid the JSON-payload errors that come from cramming a full page into one call: edit-page for property updates, add-blocklist-block / add-blockgrid-block / add-rte-block for block content, edit-block for block-property edits, and get-property-value-template for the value shape of structured non-block editors (media pickers, image cropper, etc.). On a multilingual site, a document type that varies by culture is created in `culture` (default: the site's default language); values without a culture on culture-variant properties are stored in that culture too.",
1601
1679
  inputSchema: inputSchema11,
1602
1680
  outputSchema: outputSchema11,
1603
1681
  slices: ["create"],
1604
1682
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1605
- handler: async ({ name, documentTypeId, parentId, values }) => {
1606
- const resolved = await resolveEditorAliases(documentTypeId, values);
1683
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1684
+ const cultureResult = await resolvePageCulture(documentTypeId, culture);
1685
+ if (!cultureResult.ok) return cultureResult.errorResult;
1686
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1687
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1607
1688
  if (!resolved.ok) return resolved.errorResult;
1608
1689
  const createResult = await chainCms("create-document", {
1609
1690
  documentTypeId,
1610
1691
  name,
1611
1692
  values: resolved.values,
1693
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1612
1694
  ...parentId ? { parentId } : {}
1613
1695
  });
1614
1696
  if (!createResult.ok) return createResult.errorResult;
@@ -1620,6 +1702,7 @@ var tool11 = {
1620
1702
  message,
1621
1703
  id: createdId,
1622
1704
  name,
1705
+ culture: pageCulture,
1623
1706
  previewUrl: createdId ? await fetchPreviewUrl(createdId) : null,
1624
1707
  validation
1625
1708
  });
@@ -1630,6 +1713,7 @@ var inputSchema12 = {
1630
1713
  name: z.string().describe("The name of the page to create"),
1631
1714
  documentTypeId: z.string().uuid().describe("The ID of the document type to use. Call list-document-types first to find available types."),
1632
1715
  parentId: z.string().uuid().optional().describe("The ID of the parent page. If omitted, the page is created at the root"),
1716
+ culture: z.string().optional().describe("Culture (ISO code, e.g. en-US) to create the page in. Only used when the document type varies by culture; defaults to the site's default language. Call list-languages for the available cultures. Add further languages afterwards with create-variant or copy-variant."),
1633
1717
  values: z.array(z.object({
1634
1718
  alias: z.string().describe("The property alias"),
1635
1719
  value: z.any().describe("The property value"),
@@ -1641,23 +1725,28 @@ var outputSchema12 = z.object({
1641
1725
  message: z.string(),
1642
1726
  id: z.string(),
1643
1727
  name: z.string(),
1728
+ culture: z.string().nullable().describe("The culture the page was created in \u2014 the requested `culture`, or the site's default language when none was given. Null when the document type does not vary by culture."),
1644
1729
  publishedUrls: publishedUrlsSchema
1645
1730
  });
1646
1731
  var tool12 = {
1647
1732
  name: "create-and-publish-page",
1648
- description: "Create a new content page and publish it \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. This is a single atomic operation when the connected Umbraco instance supports it (17.6+); otherwise a two-call create-then-publish sequence is used. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values. Required-property validation runs at publish time, not create time: on the atomic path a validation failure leaves no page behind, but on the fallback path the draft can already have been created before publish fails, leaving an unpublished draft. Either way, check the response `message` before retrying \u2014 don't retry blindly, or you may pile up duplicate drafts. Use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing.",
1733
+ description: "Create a new content page and publish it \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. This is a single atomic operation when the connected Umbraco instance supports it (17.6+); otherwise a two-call create-then-publish sequence is used. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values. Required-property validation runs at publish time, not create time: on the atomic path a validation failure leaves no page behind, but on the fallback path the draft can already have been created before publish fails, leaving an unpublished draft. Either way, check the response `message` before retrying \u2014 don't retry blindly, or you may pile up duplicate drafts. Use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing. On a multilingual site, a document type that varies by culture is created in `culture` (default: the site's default language); values without a culture on culture-variant properties are stored in that culture too. If the site has a mandatory language other than that culture, the page can't be published from a single call \u2014 the tool says so and creates nothing; use create-page, create-variant, then publish instead.",
1649
1734
  inputSchema: inputSchema12,
1650
1735
  outputSchema: outputSchema12,
1651
1736
  slices: ["create", "publish"],
1652
1737
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
1653
- handler: async ({ name, documentTypeId, parentId, values }) => {
1654
- const resolved = await resolveEditorAliases(documentTypeId, values);
1738
+ handler: async ({ name, documentTypeId, parentId, culture, values }) => {
1739
+ const cultureResult = await resolvePageCulture(documentTypeId, culture, { forPublish: true });
1740
+ if (!cultureResult.ok) return cultureResult.errorResult;
1741
+ const { culture: pageCulture, documentType, siteCultures } = cultureResult;
1742
+ const resolved = await resolveEditorAliases(documentTypeId, values, { defaultCulture: pageCulture, documentType, siteCultures });
1655
1743
  if (!resolved.ok) return resolved.errorResult;
1656
1744
  if (await isCmsToolAvailable("create-and-publish-document")) {
1657
1745
  const createResult = await chainCms("create-and-publish-document", {
1658
1746
  documentTypeId,
1659
1747
  name,
1660
1748
  values: resolved.values,
1749
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1661
1750
  ...parentId ? { parentId } : {}
1662
1751
  });
1663
1752
  if (!createResult.ok) return createResult.errorResult;
@@ -1666,6 +1755,7 @@ var tool12 = {
1666
1755
  message: `Created and published "${name}"`,
1667
1756
  id: createdId2,
1668
1757
  name,
1758
+ culture: pageCulture,
1669
1759
  publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
1670
1760
  });
1671
1761
  }
@@ -1673,19 +1763,21 @@ var tool12 = {
1673
1763
  documentTypeId,
1674
1764
  name,
1675
1765
  values: resolved.values,
1766
+ ...pageCulture ? { cultures: [pageCulture] } : {},
1676
1767
  ...parentId ? { parentId } : {}
1677
1768
  });
1678
1769
  if (!createDocumentResult.ok) return createDocumentResult.errorResult;
1679
1770
  const createdId = createDocumentResult.data.id;
1680
1771
  const publishResult = await chainCms("publish-document", {
1681
1772
  id: createdId,
1682
- data: { publishSchedules: [{ culture: null }] }
1773
+ data: { publishSchedules: [{ culture: pageCulture }] }
1683
1774
  });
1684
1775
  if (!publishResult.ok) {
1685
1776
  return createToolResult({
1686
1777
  message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
1687
1778
  id: createdId,
1688
1779
  name,
1780
+ culture: pageCulture,
1689
1781
  publishedUrls: []
1690
1782
  });
1691
1783
  }
@@ -1693,6 +1785,7 @@ var tool12 = {
1693
1785
  message: `Created and published "${name}"`,
1694
1786
  id: createdId,
1695
1787
  name,
1788
+ culture: pageCulture,
1696
1789
  publishedUrls: createdId ? await fetchPublishedUrls(createdId) : []
1697
1790
  });
1698
1791
  }
@@ -7792,6 +7885,16 @@ async function loadServerConfig(isStdioMode) {
7792
7885
  }
7793
7886
  function clearConfigCache() {
7794
7887
  cachedConfig = null;
7888
+ resetServerConfig();
7889
+ }
7890
+
7891
+ // src/config/apply-filter-config.ts
7892
+ function applyFilterConfig(umbracoConfig, manager) {
7893
+ manager.setFilterConfig({
7894
+ readOnly: umbracoConfig.readonly,
7895
+ slices: umbracoConfig.includeSlices,
7896
+ excludeSlices: umbracoConfig.excludeSlices
7897
+ });
7795
7898
  }
7796
7899
 
7797
7900
  // src/server-instructions.ts
@@ -7924,6 +8027,7 @@ async function main() {
7924
8027
  if (chainingEnabled) {
7925
8028
  console.error("MCP chaining enabled \u2014 pre-connecting to chained servers...");
7926
8029
  try {
8030
+ applyFilterConfig(serverConfig.umbraco, mcpClientManager);
7927
8031
  for (const srv of mcpServers) {
7928
8032
  await mcpClientManager.connect(srv.name);
7929
8033
  console.error(`Connected to chained server: ${srv.name}`);