@prenta/mcp-server 2.3.10 → 2.4.1

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/tools.js CHANGED
@@ -1,19 +1,20 @@
1
1
  /**
2
2
  * MCP tool definitions for Prenta CMS.
3
3
  *
4
- * Each tool is a thin wrapper around an PrentaClient call. We expose a small
5
- * but powerful set focused on the workflows AI agents actually need:
6
- * - discover collections and fields
7
- * - list / get / create / update / delete documents
8
- * - read / update globals (site settings)
9
- * - generate pages and blocks via the AI page builder
10
- * - create complete pages from a prompt in one shot
4
+ * Each tool is a thin wrapper around a PrentaClient call, grouped by area:
5
+ * - discovery: collections, the content model, section types
6
+ * - documents: list / get / create / update / delete, translations, workflow
7
+ * - page and post content: `data.sections`, built one section at a time
8
+ * with the section tools (there is no layout-tree or one-shot page
9
+ * generator), plus post templates
10
+ * - media, forms, navigation, globals (site settings), SEO and redirects
11
11
  *
12
12
  * We deliberately do not expose admin-only endpoints (user management,
13
13
  * api-key CRUD, audit log) — the agent already has limited scope via its key.
14
14
  */
15
15
  import { z } from 'zod';
16
16
  import { PrentaClientError } from './client.js';
17
+ import { FORM_SECTION_TYPE, buildContentModel, checkFormSlug } from './content-model.js';
17
18
  import { fetchUploadSourceUrl, mimeFromFilename, readUploadFilePath } from './upload-source.js';
18
19
  import { NAVIGATION_COLLECTION, addNavItem, buildDocPath, coerceNavItems, genNavItemId, removeNavItem, reorderNavLevel, validateNavTree, } from './navigation.js';
19
20
  export function annotationsForTool(name) {
@@ -25,6 +26,7 @@ export function annotationsForTool(name) {
25
26
  (name.startsWith('list_') ||
26
27
  name.startsWith('get_') ||
27
28
  name.startsWith('search_') ||
29
+ name.startsWith('describe_') ||
28
30
  name.startsWith('count_'));
29
31
  return {
30
32
  readOnlyHint: readOnly,
@@ -197,6 +199,35 @@ async function unavailableOnNotConfigured(run) {
197
199
  }
198
200
  export function buildTools(client) {
199
201
  const tools = [];
202
+ /** Append a `formSlug` warning to a validate result (`{ data: { valid, errors, warnings } }`). */
203
+ async function withFormWarning(res, formSlug) {
204
+ const data = res?.data;
205
+ if (!data || typeof data !== 'object')
206
+ return res;
207
+ const message = await checkFormSlug(client, formSlug);
208
+ if (!message)
209
+ return res;
210
+ const warnings = Array.isArray(data.warnings) ? data.warnings : [];
211
+ data.warnings = [...warnings, { sectionType: FORM_SECTION_TYPE, field: 'formSlug', message }];
212
+ return res;
213
+ }
214
+ /** Same check for section write results (`{ data: { section, validation } }`). */
215
+ async function withSectionFormWarning(res) {
216
+ const data = res?.data;
217
+ const section = data?.section;
218
+ if (!data || !section || section.sectionType !== FORM_SECTION_TYPE)
219
+ return res;
220
+ const message = await checkFormSlug(client, section.content?.formSlug);
221
+ if (!message)
222
+ return res;
223
+ const validation = data.validation && typeof data.validation === 'object' ? data.validation : {};
224
+ const warnings = Array.isArray(validation.warnings) ? validation.warnings : [];
225
+ data.validation = {
226
+ ...validation,
227
+ warnings: [...warnings, { sectionType: FORM_SECTION_TYPE, field: 'formSlug', message }],
228
+ };
229
+ return res;
230
+ }
200
231
  function tool(name, description, schema, handler) {
201
232
  tools.push({
202
233
  name,
@@ -245,7 +276,7 @@ export function buildTools(client) {
245
276
  id: z.string().describe('Source document ID. Not the translation draft ID.'),
246
277
  locale: z.string().min(1).max(35).describe('Target locale code.'),
247
278
  }), (args) => client.localizeTranslation(args.collection, args.id, args.locale));
248
- tool('create_document', 'Create a new document in a collection. Defaults to DRAFT status.', z.object({
279
+ tool('create_document', 'Create a new document in a collection. Defaults to DRAFT status. Check the collection `authoring` first (`describe_content_model` or `list_collections`): for `sections` and `post` collections create the document with title + slug here, then add content with `add_page_section`. Never use this tool on a `managed` collection such as `forms` (use `create_form`).', z.object({
249
280
  collection: z.string(),
250
281
  title: z.string().optional(),
251
282
  slug: z.string().optional(),
@@ -253,8 +284,11 @@ export function buildTools(client) {
253
284
  data: z
254
285
  .record(z.string(), z.any())
255
286
  .optional()
256
- .describe('Arbitrary field data — depends on the collection schema'),
257
- layout: z.any().optional().describe('Page-builder layout tree (for page collections)'),
287
+ .describe('Field data for the collection schema. Leave `sections` out and use add_page_section. If you do send `data.sections`, each entry must be `{ sectionType, content, settings? }` with a registered type; malformed or unknown entries return 400 with an `issues` list.'),
288
+ layout: z
289
+ .any()
290
+ .optional()
291
+ .describe('Legacy. Do not use. Page content lives in data.sections (see add_page_section).'),
258
292
  pageSettings: z.record(z.string(), z.any()).optional().describe('SEO and meta settings'),
259
293
  }), (args) => {
260
294
  const { collection, data, ...rest } = args;
@@ -266,8 +300,14 @@ export function buildTools(client) {
266
300
  title: z.string().optional(),
267
301
  slug: z.string().optional(),
268
302
  status: z.enum(['DRAFT', 'PUBLISHED', 'SCHEDULED']).optional(),
269
- data: z.record(z.string(), z.any()).optional(),
270
- layout: z.any().optional(),
303
+ data: z
304
+ .record(z.string(), z.any())
305
+ .optional()
306
+ .describe('Fields to change. Edit page and post content with the section tools, not by rewriting `data.sections`. A `data.sections` you do send must use `{ sectionType, content, settings? }` entries; malformed or unknown entries return 400 with an `issues` list.'),
307
+ layout: z
308
+ .any()
309
+ .optional()
310
+ .describe('Legacy. Do not use. Page content lives in data.sections (see add_page_section).'),
271
311
  pageSettings: z.record(z.string(), z.any()).optional(),
272
312
  }), (args) => {
273
313
  const { collection, id, data, ...rest } = args;
@@ -1248,7 +1288,7 @@ export function buildTools(client) {
1248
1288
  search: z.string().optional().describe('Free-text search against form name.'),
1249
1289
  }), (args) => client.listForms(args));
1250
1290
  tool('get_form', 'Fetch a single form definition by ID — metadata plus the current field schema. Pair with `list_forms` to discover IDs.', z.object({ id: z.string().describe('Form ID.') }), (args) => client.getForm(args.id));
1251
- tool('create_form', 'Create a form. Only `name` is required; the slug is derived from the name when omitted. Pass `fields` to seed the field schema in one shot, or omit it and add the schema later with `save_form_schema`. New forms default to `draft` status — set `status: "active"` to make the form accept submissions. Returns the created form.', z.object({
1291
+ tool('create_form', 'Create a form. Only `name` is required; the slug is derived from the name when omitted. Pass `fields` to seed the field schema in one shot, or omit it and add the schema later with `save_form_schema`. New forms default to `draft` status — set `status: "active"` to make the form accept submissions. A draft form does not render on the public site. To put it on a page or post, call `add_page_section` with `sectionType: "form"` and `content: { formSlug }`. Returns the created form.', z.object({
1252
1292
  name: z.string().min(1).describe('Human-facing form name (also seeds the slug).'),
1253
1293
  slug: z.string().optional().describe('URL slug override. Auto-derived from name if omitted.'),
1254
1294
  description: z.string().optional(),
@@ -1490,7 +1530,7 @@ export function buildTools(client) {
1490
1530
  prompt: enriched,
1491
1531
  });
1492
1532
  });
1493
- tool('list_collections', 'Discover available collections, their labels, type (`page`|`post`), and field summary. Primary source is the dedicated `/collections` discovery endpoint (sourced directly from the runtime CMS config so it stays accurate when the OpenAPI spec is incomplete). Falls back to the OpenAPI spec on older CMS servers that don\'t yet expose `/collections`. Returns `{ data: CollectionSummary[], source: "collections" | "openapi" }` — `data` is ALWAYS an array (the OpenAPI fallback is normalised to the same shape) so callers get a consistent contract regardless of which path responded.', z.object({}), async () => {
1533
+ tool('list_collections', 'Discover available collections, their labels, declared `type` (`page`|`post`, or null when unset), field summary, and how each is authored: `authoring` (`sections` = page canvas built with add_page_section; `post` = post canvas, sections plus the post type template; `fields` = plain field editor; `managed` = a plugin owns it, such as `forms`, so use its `tools`), `editorRoute` (admin route, `:id` placeholder) and `tools`. For the allowed section types per collection call `describe_content_model`. Primary source is the dedicated `/collections` discovery endpoint (sourced directly from the runtime CMS config so it stays accurate when the OpenAPI spec is incomplete). Falls back to the OpenAPI spec on older CMS servers that don\'t yet expose `/collections`. Returns `{ data: CollectionSummary[], source: "collections" | "openapi" }` — `data` is ALWAYS an array (the OpenAPI fallback is normalised to the same shape) so callers get a consistent contract regardless of which path responded.', z.object({}), async () => {
1494
1534
  // Phase 7 PR F (audit stylistic note #2): the previous
1495
1535
  // implementation relied solely on /openapi.json and silently
1496
1536
  // returned an empty map whenever the OpenAPI generator drifted.
@@ -1541,7 +1581,8 @@ export function buildTools(client) {
1541
1581
  // about labels should target a CMS server with the new
1542
1582
  // /collections endpoint.
1543
1583
  labels: { singular: slug, plural: slug },
1544
- type: 'page',
1584
+ // OpenAPI does not say whether a collection is a page or post type.
1585
+ type: null,
1545
1586
  urlPrefix: slug,
1546
1587
  hidden: false,
1547
1588
  fieldCount: fields.length,
@@ -1552,6 +1593,7 @@ export function buildTools(client) {
1552
1593
  return { data, source: 'openapi' };
1553
1594
  }
1554
1595
  });
1596
+ tool('describe_content_model', 'Start here before writing content. Returns `{ collections, sectionTypes, notes }`. Each collection has `authoring` (`sections`, `post`, `fields` or `managed`), the admin `editorRoute`, the `tools` to use, a one-line `hint`, and `sectionTypes`: the section type ids `add_page_section` accepts there (null when the collection stores no sections). `sectionTypes.page` / `.post` give the name and description of each type. A `managed` collection (such as `forms`) is owned by a plugin: use its tools, never `create_document`. Same data as the `prenta://content-model` resource.', z.object({}), async () => ({ data: await buildContentModel(client) }));
1555
1597
  tool('resolve_url', 'Resolve a public URL path (e.g. "/about") to its CMS document.', z.object({ path: z.string() }), (args) => client.resolveUrl(args.path));
1556
1598
  // ── Relationship resolver (WS-C C2) ───────────────────────────────────
1557
1599
  //
@@ -1934,7 +1976,7 @@ export function buildTools(client) {
1934
1976
  // Sections live in a page document's `data.sections` array; the page is a
1935
1977
  // document in a collection that declares a `sections` JSON field (default
1936
1978
  // slug "pages"). All mutations are server-side validated + audited.
1937
- tool('list_section_types', 'Discover the registered section types and their schemas. Returns each type\'s `id` (e.g. "hero", "text", "feature", "stats", "cta", "article-body", "quote", "author-bio", "related-posts", "gallery", "embed", "widget-embed"), `name`, `description`, `category`, `scope` (which surfaces it works on: "page" and/or "post"), `addable` (`false` means schema-only — do not add a new instance; existing rows still edit), `hideable` (`false` means do not hide — Hide/Show is omitted and a hide write returns 400; leftover `visible: false` is still treated as on the page), `templates` (page-family keys that allow inserting this type, omitted when none), the inspector `fields` schema (which content keys exist + which are required), and `defaultContent` / `defaultSettings`. Call this FIRST before building a page or a post template so you only use types that have a working renderer (no dead sections). Match a design band to the type whose description shows that layout. Skip the band when none fits. Pass `scope` to narrow to one surface. Pass `template` or `collection`+`documentId` to list only types insertable on that page family — do not add a type the filtered list omitted, and do not work around a 400 by writing it into `update_document`.', z.object({
1979
+ tool('list_section_types', 'Discover the registered section types and their schemas. Returns each type\'s `id` (built-ins: "hero", "text", "feature" (one image beside text, not a grid), "stats", "badges" (logo strip), "faq", "cta", "form" (embeds a form by `formSlug`), "article-body", "quote", "author-bio", "related-posts", "gallery", "embed", "widget-embed", "divider"; sites can add their own), `name`, `description`, `category`, `scope` (which surfaces it works on: "page" and/or "post"), `addable` (`false` means schema-only — do not add a new instance; existing rows still edit), `hideable` (`false` means do not hide — Hide/Show is omitted and a hide write returns 400; leftover `visible: false` is still treated as on the page), `templates` (page-family keys that allow inserting this type, omitted when none), the inspector `fields` schema (which content keys exist + which are required), and `defaultContent` / `defaultSettings`. Call this FIRST before building a page or a post template so you only use registered types. Custom types are registered on the CMS, but their renderer lives in the public site, so a custom type the site has not built renders nothing. Match a design band to the type whose description shows that layout. Skip the band when none fits. Pass `scope` to narrow to one surface. Pass `template` or `collection`+`documentId` to list only types insertable on that page family — do not add a type the filtered list omitted, and do not work around a 400 by writing it into `update_document`.', z.object({
1938
1980
  scope: z
1939
1981
  .enum(['page', 'post'])
1940
1982
  .optional()
@@ -1946,7 +1988,7 @@ export function buildTools(client) {
1946
1988
  collection: z
1947
1989
  .string()
1948
1990
  .optional()
1949
- .describe('Page collection slug. Required with documentId so the server reads data.template.'),
1991
+ .describe('Page or post collection slug. Required with documentId so the server reads data.template.'),
1950
1992
  documentId: z
1951
1993
  .string()
1952
1994
  .optional()
@@ -1972,7 +2014,7 @@ export function buildTools(client) {
1972
2014
  }
1973
2015
  return { data: match };
1974
2016
  });
1975
- tool('validate_section_content', 'Validate section content against its type schema WITHOUT persisting. Deterministic (no LLM). Returns `{ valid, errors, warnings }` where each issue is `{ sectionType, field?, message }`. Use to check AI-authored content before adding it, or to explain why a publish is blocked. An unknown `sectionType` is a hard error.', z.object({
2017
+ tool('validate_section_content', 'Validate section content against its type schema WITHOUT persisting. Deterministic (no LLM). Returns `{ valid, errors, warnings }` where each issue is `{ sectionType, field?, message }`. Use to check AI-authored content before adding it, or to explain why a publish is blocked. An unknown `sectionType` is a hard error. For a `form` section it also warns when `formSlug` does not name an active form.', z.object({
1976
2018
  sectionType: z.string().describe('Section type id to validate against.'),
1977
2019
  content: z
1978
2020
  .record(z.string(), z.any())
@@ -1981,24 +2023,32 @@ export function buildTools(client) {
1981
2023
  .record(z.string(), z.any())
1982
2024
  .optional()
1983
2025
  .describe('Optional section settings object.'),
1984
- }), (args) => client.validateSection({
1985
- sectionType: args.sectionType,
1986
- content: args.content,
1987
- ...(args.settings !== undefined ? { settings: args.settings } : {}),
1988
- }));
1989
- tool('list_page_sections', 'List the ordered sections on a page document (`data.sections`). Each section is `{ id, sectionType, name, visible, content, settings }`. Use to inspect the current page before editing, or to discover section ids for `update_page_section` / `remove_page_section` / `reorder_page_sections`.', z.object({
1990
- id: z.string().describe('Page document ID.'),
2026
+ }), async (args) => {
2027
+ const res = await client.validateSection({
2028
+ sectionType: args.sectionType,
2029
+ content: args.content,
2030
+ ...(args.settings !== undefined ? { settings: args.settings } : {}),
2031
+ });
2032
+ if (args.sectionType !== FORM_SECTION_TYPE)
2033
+ return res;
2034
+ return withFormWarning(res, args.content?.formSlug);
2035
+ });
2036
+ tool('list_page_sections', 'List the ordered sections on a page or post document (`data.sections`). Each section is `{ id, sectionType, name, visible, content, settings }`. Use to inspect the current page before editing, or to discover section ids for `update_page_section` / `remove_page_section` / `reorder_page_sections`.', z.object({
2037
+ id: z.string().describe('Page or post document ID.'),
1991
2038
  collection: z
1992
2039
  .string()
1993
2040
  .optional()
1994
- .describe('Collection slug of the page. Defaults to "pages".'),
2041
+ .describe('Collection slug: a page collection, or the post type (e.g. "blog") for a post. Defaults to "pages".'),
1995
2042
  }), (args) => client.listPageSections(args.collection ?? 'pages', args.id));
1996
- tool('add_page_section', "Add a section to a page — one call per visual band of the design, in top-to-bottom order (the visual stack). The server seeds the type's registry defaults, shallow-merges your `content` / `settings`, generates an id, inserts at `position` (0-based; omit to append), and persists through the audited update path. Returns `{ section, sections, validation }` — inspect `validation` for any content issues (the section is still added so you can fix it with `update_page_section`). Only registered, addable `sectionType`s allowed on the page's `data.template` (see `list_section_types` with `template` or `documentId`) are accepted. Types with `addable: false` or a foreign family are rejected with 400 — do not work around that by writing them into `update_document`.", z.object({
1997
- id: z.string().describe('Page document ID.'),
2043
+ tool('add_page_section', 'Add a section to a page or a post (pass the post type as `collection`) — one call per visual band of the design, in top-to-bottom order (the visual stack). The server seeds the type\'s registry defaults, shallow-merges your `content` / `settings`, generates an id, inserts at `position` (0-based; omit to append), and persists through the audited update path. Returns `{ section, sections, validation }` — inspect `validation` for any content issues (the section is still added so you can fix it with `update_page_section`). Only registered, addable `sectionType`s allowed on the page\'s `data.template` (see `list_section_types` with `template` or `documentId`) are accepted. Types with `addable: false` or a foreign family are rejected with 400 — do not work around that by writing them into `update_document`. For a `form` section pass `content: { formSlug }` naming an active form (create it with `create_form`, `status: "active"`); `validation.warnings` flags a missing or inactive form, which renders nothing on the public site.', z.object({
2044
+ id: z.string().describe('Page or post document ID.'),
1998
2045
  sectionType: z
1999
2046
  .string()
2000
2047
  .describe('Registered, addable section type id (see list_section_types). Types with addable: false are rejected.'),
2001
- collection: z.string().optional().describe('Page collection slug. Defaults to "pages".'),
2048
+ collection: z
2049
+ .string()
2050
+ .optional()
2051
+ .describe('Collection slug: a page collection, or the post type (e.g. "blog") for a post. Defaults to "pages".'),
2002
2052
  name: z
2003
2053
  .string()
2004
2054
  .optional()
@@ -2019,38 +2069,52 @@ export function buildTools(client) {
2019
2069
  .min(0)
2020
2070
  .optional()
2021
2071
  .describe('0-based insert index. Omit to append at the end.'),
2022
- }), (args) => {
2072
+ }), async (args) => {
2023
2073
  const { id, collection, ...body } = args;
2024
- return client.addPageSection(collection ?? 'pages', id, body);
2074
+ const res = await client.addPageSection(collection ?? 'pages', id, body);
2075
+ return withSectionFormWarning(res);
2025
2076
  });
2026
2077
  tool('update_page_section', 'Update a section in place. Only supplied fields change; `content` and `settings` are shallow-merged (so you can patch a single key). Use `visible` to show/hide (`visible: false` is rejected when the type has `hideable: false` — do not work around that via `update_document`), `name` / `internalLabel` to relabel. Returns `{ section, sections, validation }`. Pair with `list_page_sections` to discover the `sectionId`.', z.object({
2027
- id: z.string().describe('Page document ID.'),
2078
+ id: z.string().describe('Page or post document ID.'),
2028
2079
  sectionId: z.string().describe('Section id within the page (from list_page_sections).'),
2029
- collection: z.string().optional().describe('Page collection slug. Defaults to "pages".'),
2080
+ collection: z
2081
+ .string()
2082
+ .optional()
2083
+ .describe('Collection slug: a page collection, or the post type (e.g. "blog") for a post. Defaults to "pages".'),
2030
2084
  content: z.record(z.string(), z.any()).optional().describe('Content fields to merge in.'),
2031
2085
  settings: z.record(z.string(), z.any()).optional().describe('Settings fields to merge in.'),
2032
2086
  name: z.string().optional(),
2033
2087
  internalLabel: z.string().optional(),
2034
2088
  visible: z.boolean().optional().describe('Show (true) or hide (false) the section.'),
2035
- }), (args) => {
2089
+ }), async (args) => {
2036
2090
  const { id, sectionId, collection, ...body } = args;
2037
- return client.updatePageSection(collection ?? 'pages', id, sectionId, body);
2091
+ const res = await client.updatePageSection(collection ?? 'pages', id, sectionId, body);
2092
+ return withSectionFormWarning(res);
2038
2093
  });
2039
2094
  tool('reorder_page_sections', "Reorder a page's sections to an explicit id order. Pass the full list of section ids in the desired top-to-bottom order; any ids you omit are appended at the end (defensive — sections are never dropped). Returns the new ordered section array.", z.object({
2040
- id: z.string().describe('Page document ID.'),
2095
+ id: z.string().describe('Page or post document ID.'),
2041
2096
  orderedIds: z.array(z.string()).describe('Section ids in the desired order (top to bottom).'),
2042
- collection: z.string().optional().describe('Page collection slug. Defaults to "pages".'),
2097
+ collection: z
2098
+ .string()
2099
+ .optional()
2100
+ .describe('Collection slug: a page collection, or the post type (e.g. "blog") for a post. Defaults to "pages".'),
2043
2101
  }), (args) => client.reorderPageSections(args.collection ?? 'pages', args.id, args.orderedIds));
2044
- tool('remove_page_section', 'Remove a section from a page. Destructive (the section content is dropped from the draft) — confirm with the user for published pages; prefer `update_page_section` with `visible: false` when the content should survive. Returns the remaining sections.', z.object({
2045
- id: z.string().describe('Page document ID.'),
2102
+ tool('remove_page_section', 'Remove a section from a page or post. Destructive (the section content is dropped from the draft) — confirm with the user for published pages; prefer `update_page_section` with `visible: false` when the content should survive. Returns the remaining sections.', z.object({
2103
+ id: z.string().describe('Page or post document ID.'),
2046
2104
  sectionId: z.string().describe('Section id to remove (from list_page_sections).'),
2047
- collection: z.string().optional().describe('Page collection slug. Defaults to "pages".'),
2105
+ collection: z
2106
+ .string()
2107
+ .optional()
2108
+ .describe('Collection slug: a page collection, or the post type (e.g. "blog") for a post. Defaults to "pages".'),
2048
2109
  }), (args) => client.removePageSection(args.collection ?? 'pages', args.id, args.sectionId));
2049
2110
  tool('toggle_page_section_visibility', 'Show or hide a section without deleting it. Hidden sections stay in the draft but are excluded from the published page and from publish-time validation. Types with `hideable: false` reject `visible: false` (400) — do not work around that via `update_document`. Pass `visible` explicitly. Returns `{ section, sections, validation }`.', z.object({
2050
- id: z.string().describe('Page document ID.'),
2111
+ id: z.string().describe('Page or post document ID.'),
2051
2112
  sectionId: z.string().describe('Section id to toggle.'),
2052
2113
  visible: z.boolean().describe('true to show, false to hide.'),
2053
- collection: z.string().optional().describe('Page collection slug. Defaults to "pages".'),
2114
+ collection: z
2115
+ .string()
2116
+ .optional()
2117
+ .describe('Collection slug: a page collection, or the post type (e.g. "blog") for a post. Defaults to "pages".'),
2054
2118
  }), (args) => client.updatePageSection(args.collection ?? 'pages', args.id, args.sectionId, {
2055
2119
  visible: args.visible,
2056
2120
  }));