@cloudhal/mcp-server 0.5.0 → 0.6.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.
Files changed (39) hide show
  1. package/README.md +4 -3
  2. package/dist/src/collection-fields.d.ts +2 -0
  3. package/dist/src/collection-fields.js +1 -1
  4. package/dist/src/collection-listings.d.ts +48 -0
  5. package/dist/src/collection-listings.js +280 -0
  6. package/dist/src/collection-tools.js +34 -12
  7. package/dist/src/entry-fields.js +12 -57
  8. package/dist/src/entry-list.d.ts +17 -0
  9. package/dist/src/entry-list.js +101 -0
  10. package/dist/src/entry-tools.js +17 -10
  11. package/dist/src/field-hints.d.ts +2 -1
  12. package/dist/src/field-hints.js +18 -1
  13. package/dist/src/page-tools.js +7 -0
  14. package/dist/src/release-risk.d.ts +22 -0
  15. package/dist/src/release-risk.js +95 -0
  16. package/dist/src/render/cdp.d.ts +0 -1
  17. package/dist/src/render/cdp.js +3 -0
  18. package/dist/src/render/checks/content.d.ts +1 -1
  19. package/dist/src/render/checks/content.js +46 -9
  20. package/dist/src/render/checks/index.js +2 -0
  21. package/dist/src/render/checks/scripts.d.ts +11 -0
  22. package/dist/src/render/checks/scripts.js +45 -0
  23. package/dist/src/render/types.d.ts +1 -1
  24. package/dist/src/render/types.js +4 -0
  25. package/dist/src/render-tools.js +3 -1
  26. package/dist/src/render.d.ts +4 -3
  27. package/dist/src/render.js +4 -3
  28. package/dist/src/schedules.d.ts +2 -5
  29. package/dist/src/schedules.js +5 -38
  30. package/dist/src/section-queries.d.ts +10 -0
  31. package/dist/src/section-queries.js +52 -0
  32. package/dist/src/server-instructions.js +3 -1
  33. package/dist/src/structured-data-tools.d.ts +8 -0
  34. package/dist/src/structured-data-tools.js +111 -0
  35. package/dist/src/tools.js +15 -4
  36. package/dist/src/translation-fields.d.ts +32 -0
  37. package/dist/src/translation-fields.js +68 -0
  38. package/dist/src/translation-tools.js +56 -6
  39. package/package.json +9 -9
package/README.md CHANGED
@@ -21,7 +21,7 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
21
21
  ## Tool reference
22
22
 
23
23
  <!-- tools:start (generated by scripts/mcp-tools-doc.ts; do not edit) -->
24
- **109 tools**, in the order the server lists them.
24
+ **110 tools**, in the order the server lists them.
25
25
 
26
26
  | Tool | Scopes | Kind | Approval | What it does |
27
27
  |---|---|---|---|---|
@@ -44,7 +44,7 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
44
44
  | `delete_entry` | `content:write` | write (destructive) | by the key's mode | Delete a content entry. |
45
45
  | `list_translations` | `content:read` | read | — | Every language version of a page or entry (its translation group): locale, status, method (original, human, machine, machine-reviewed), whether it is stale (its source changed sin… |
46
46
  | `list_stale_translations` | `content:read` | read | — | Translations whose source changed since they were made (or whose source is gone), optionally in one locale: the work queue for keeping languages in step. |
47
- | `get_translation_source` | `content:read` | read | — | What you need to translate a page or entry into `locale`: the source (translate its title, text, summary and SEO; keep section ids, kinds, links, numbers, images and bindings), th… |
47
+ | `get_translation_source` | `content:read` | read | — | What you need to translate a page or entry into `locale`: the source (translate its title, text, summary and SEO; keep section ids, kinds, links, numbers, images and bindings), fo… |
48
48
  | `save_translation` | `content:write` | write | by the key's mode | Save your translation of a page or entry into `locale` as a draft linked to the source's current revision, with your model as its provenance. |
49
49
  | `search_site` | `content:read` | read | — | Find nodes by words instead of listing everything. |
50
50
  | `get_theme_settings` | `content:read` | read | — | The theme's design settings (RFC-0017): their schema (colors as #rrggbb, enums, numbers; per-locale titles), the contrast rules colors must meet, and the site's current values. |
@@ -79,7 +79,8 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
79
79
  | `delete_redirect` | `site:write` | write (destructive) | always a person | Delete a redirect; its old path then answers 404 unless something serves it. |
80
80
  | `list_collections` | `content:read` | read | — | The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. |
81
81
  | `create_collection` | `site:write` | write | always a person | Declare a new collection (RFC-0040), e.g. events, team or jobs, with its names in the site's default locale (labels), an optional icon, permalink (/&lt;prefix>/{slug}, default /&lt;key>… |
82
- | `update_collection` | `site:write` | write | always a person | Change a collection's names (merged per locale), icon, feed, sitemap, default sort (RFC-0040) or its typed custom fields (`fields`, the whole list; RFC-0041). |
82
+ | `update_collection` | `site:write` | write | always a person | Change a collection's names (merged per locale), icon, feed, sitemap, default sort (RFC-0040) or its typed custom fields (`fields`, the whole list; RFC-0041), list fields, date-dr… |
83
+ | `preview_structured_data` | `content:read` | read | — | The JSON-LD document an entry's page emits under its collection's structured-data preset (RFC-0042: Event, JobPosting, Product, Recipe), built exactly as the site builds it, with… |
83
84
  | `rename_field` | `site:write`, `content:write` | write | always a person | Rename a typed custom field's key (RFC-0041 §6): every entry's value moves from `from` to `to`; nothing is converted. |
84
85
  | `change_field_type` | `site:write`, `content:write` | write (destructive) | always a person | Change a typed custom field's type, or a select's multiple (RFC-0041 §6), converting every value by a closed table (text↔richText, text↔number, text↔select, text↔url, date↔datetim… |
85
86
  | `set_field_localized` | `site:write`, `content:write` | write | always a person | Make a typed custom field localized (each language version has its own value; translations fall back to the original's) or shared (only the original holds it; translations' own co… |
@@ -13,6 +13,8 @@ export declare const FIELD_DEFINITIONS_INPUT: JsonSchema;
13
13
  * its field (agents never write it), so editing labels meanwhile is not read as touching it.
14
14
  */
15
15
  export declare function withFields(current: CollectionSettings, next: CollectionSettings, fields: FieldDefinition[]): CollectionSettings;
16
+ /** JSON with sorted keys: stored definitions may list properties in another order. */
17
+ export declare function canonical(value: unknown): string;
16
18
  /** One line for the approval prompt: which fields are added, changed, removed or reordered. */
17
19
  export declare function describeFieldEdits(before: readonly FieldDefinition[], after: readonly FieldDefinition[], locale: string): string | undefined;
18
20
  /** What `list_collections` adds per collection that has definitions. */
@@ -62,7 +62,7 @@ export function withFields(
62
62
  }
63
63
 
64
64
  /** JSON with sorted keys: stored definitions may list properties in another order. */
65
- function canonical(value ) {
65
+ export function canonical(value ) {
66
66
  return JSON.stringify(value, (_k, v ) =>
67
67
  v && typeof v === "object" && !Array.isArray(v)
68
68
  ? Object.fromEntries(Object.entries(v).sort(([x], [y]) => x.localeCompare(y)))
@@ -0,0 +1,48 @@
1
+ /**
2
+ * RFC-0042 §7 for the collection tools: `update_collection` takes a collection's `listFields`,
3
+ * `expiry` and `structuredData` (null removes one), the store's dry run checks them in precheck
4
+ * (`unknown_field`, `invalid_expiry`, `structured_data_invalid`, `list_field_in_use`,
5
+ * `gates_unsupported`), and the approval prompt says in words what changes, e.g. "Events leave
6
+ * listings, feeds and search 1 hour after "Ends at" (endsAt); 2 published entries are already past
7
+ * it". `list_collections` shows each list field's operators and the preset's paths.
8
+ */
9
+ import type { CollectionSettings, FieldDefinition, Site, StructuredDataSource } from "@cloudhal/core-contracts";
10
+ import { type FieldQueryOp } from "@cloudhal/core-ts/fields";
11
+ import { type PresetType, type StructuredDataIssue } from "@cloudhal/core-ts/structured-data";
12
+ import { type JsonSchema, type ToolContext } from "./common.js";
13
+ /** `update_collection`'s stage 3 settings (RFC-0042), each removable with null. */
14
+ export declare const LISTINGS_INPUT: Record<string, JsonSchema>;
15
+ /** `next` with the agent's stage 3 settings applied: a value sets it, null removes it. */
16
+ export declare function withListings(next: CollectionSettings, a: Record<string, unknown>): CollectionSettings;
17
+ /** The warnings (not refusals) of the collection's preset: select options outside a vocabulary. */
18
+ export declare function presetWarnings(site: Site, key: string): StructuredDataIssue[];
19
+ /** Approval lines for the stage 3 settings that change between `before` and `next`. */
20
+ export declare function describeListings(ctx: ToolContext, next: Site, key: string, before: CollectionSettings | undefined): Promise<string[]>;
21
+ interface ListFieldView {
22
+ key: string;
23
+ type: FieldDefinition["type"];
24
+ ops: readonly FieldQueryOp[];
25
+ sortable: boolean;
26
+ }
27
+ interface PathView {
28
+ path: string;
29
+ required?: true;
30
+ /** "At least one of" this group is required. */
31
+ group?: string;
32
+ default?: StructuredDataSource;
33
+ fields: readonly string[];
34
+ entry: readonly string[];
35
+ site: readonly string[];
36
+ constant: boolean;
37
+ vocabulary?: string[];
38
+ }
39
+ /** What `list_collections` adds per collection for listings and structured data. */
40
+ export declare function listingsView(site: Site, key: string): {
41
+ listFields?: ListFieldView[];
42
+ structuredData?: {
43
+ type: PresetType;
44
+ paths: PathView[];
45
+ warnings: StructuredDataIssue[];
46
+ };
47
+ };
48
+ export {};
@@ -0,0 +1,280 @@
1
+ /**
2
+ * RFC-0042 §7 for the collection tools: `update_collection` takes a collection's `listFields`,
3
+ * `expiry` and `structuredData` (null removes one), the store's dry run checks them in precheck
4
+ * (`unknown_field`, `invalid_expiry`, `structured_data_invalid`, `list_field_in_use`,
5
+ * `gates_unsupported`), and the approval prompt says in words what changes, e.g. "Events leave
6
+ * listings, feeds and search 1 hour after "Ends at" (endsAt); 2 published entries are already past
7
+ * it". `list_collections` shows each list field's operators and the preset's paths.
8
+ */
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ import { SiteSchema } from "@cloudhal/core-contracts";
18
+ import {
19
+ canOrderBy,
20
+ derivedGate,
21
+ FIELD_QUERY_OPS,
22
+
23
+ fieldLabel,
24
+ originalsOf,
25
+ } from "@cloudhal/core-ts/fields";
26
+ import {
27
+ checkStructuredData,
28
+ KIND_SOURCES,
29
+ PRESET_TYPES,
30
+ PRESETS,
31
+
32
+
33
+ VOCABULARIES,
34
+ } from "@cloudhal/core-ts/structured-data";
35
+ import { canonical } from "./collection-fields.js";
36
+ import { quote, } from "./common.js";
37
+
38
+ const DEFS = SiteSchema.$defs ;
39
+ const SETTINGS_PROPS = (DEFS.CollectionSettings )
40
+ .properties;
41
+ const nullable = (ref , description , $defs ) => ({
42
+ anyOf: [{ $ref: `#/$defs/${ref}` }, { type: "null" }],
43
+ description,
44
+ $defs,
45
+ });
46
+
47
+ /** One line per preset type: its paths, required ones marked with `*`. */
48
+ function presetSummary() {
49
+ return PRESET_TYPES.map((type) => {
50
+ const paths = Object.entries(PRESETS[type].paths).map(
51
+ ([path, spec]) => `${path}${spec.required ? "*" : ""}`,
52
+ );
53
+ return `${type}: ${paths.join(", ")}`;
54
+ }).join(". ");
55
+ }
56
+
57
+ /** `update_collection`'s stage 3 settings (RFC-0042), each removable with null. */
58
+ export const LISTINGS_INPUT = {
59
+ listFields: {
60
+ anyOf: [SETTINGS_PROPS.listFields, { type: "null" }],
61
+ description:
62
+ "Up to 4 field keys that listings (contentList where/orderBy, list_entries) may filter and sort by, in column order; null removes them. A field contentList sections still use cannot be dropped (list_field_in_use)",
63
+ $defs: { FieldKey: DEFS.FieldKey },
64
+ },
65
+ expiry: nullable(
66
+ "CollectionExpiry",
67
+ 'A time gate every entry derives from a date or datetime field: {"field":"endsAt","action":"unlist"} (the page stays, the entry leaves listings, feeds, the sitemap and search) or "hide" (404 everywhere), afterMinutes of grace. Needs a site Worker that enforces derived gates (gates_unsupported otherwise). null removes it: expired entries come back at the next publish',
68
+ { CollectionExpiry: DEFS.CollectionExpiry, FieldKey: DEFS.FieldKey },
69
+ ),
70
+ structuredData: nullable(
71
+ "StructuredDataPreset",
72
+ `A JSON-LD preset the entry pages emit instead of BlogPosting: a type and its properties, each mapped to a source ({"kind":"field","field":"startsAt"}, {"kind":"entry","property":"title"}, {"kind":"site","property":"name"} or {"kind":"constant","value":"EUR"}). Unmapped paths with a default read it; required values (*) come from the entry, never a constant. Paths: ${presetSummary()}. Check an entry's output with preview_structured_data. null removes it`,
73
+ {
74
+ StructuredDataPreset: DEFS.StructuredDataPreset,
75
+ StructuredDataSource: DEFS.StructuredDataSource,
76
+ EntryValueProperty: DEFS.EntryValueProperty,
77
+ SiteValueProperty: DEFS.SiteValueProperty,
78
+ FieldKey: DEFS.FieldKey,
79
+ },
80
+ ),
81
+ };
82
+
83
+ const KEYS = ["listFields", "expiry", "structuredData"] ;
84
+
85
+ /** `next` with the agent's stage 3 settings applied: a value sets it, null removes it. */
86
+ export function withListings(
87
+ next ,
88
+ a ,
89
+ ) {
90
+ const out = { ...next };
91
+ for (const k of KEYS) {
92
+ if (a[k] === undefined) continue;
93
+ if (a[k] === null) delete out[k];
94
+ else out[k] = a[k];
95
+ }
96
+ return out ;
97
+ }
98
+
99
+ /** "30 minutes", "1 hour", "2 days". */
100
+ function duration(minutes ) {
101
+ const unit = (n , one ) => `${n} ${one}${n === 1 ? "" : "s"}`;
102
+ if (minutes % 1440 === 0) return unit(minutes / 1440, "day");
103
+ if (minutes % 60 === 0) return unit(minutes / 60, "hour");
104
+ return unit(minutes, "minute");
105
+ }
106
+
107
+ /** Published entries of the collection whose derived gate under `site` has already passed. */
108
+ async function pastCount(ctx , site , key ) {
109
+ const entries = await ctx.store.listContentEntries(site.id, {
110
+ collection: key,
111
+ status: ["published"],
112
+ });
113
+ const original = originalsOf(entries);
114
+ const now = (ctx.now?.() ?? new Date()).getTime();
115
+ return entries.filter((e) => {
116
+ const gate = derivedGate(site, e, original(e));
117
+ return gate !== undefined && gate.at <= now;
118
+ }).length;
119
+ }
120
+
121
+ function fieldName(defs , key , locale ) {
122
+ const def = defs?.find((d) => d.key === key);
123
+ return def ? `"${quote(fieldLabel(def, locale, locale), 40)}" (${key})` : key;
124
+ }
125
+
126
+ async function expiryLine(
127
+ ctx ,
128
+ site ,
129
+ key ,
130
+ rule ,
131
+ ) {
132
+ const settings = site.collections?.[key];
133
+ const plural = settings?.labels?.[site.defaultLocale]?.plural;
134
+ const who = plural ? quote(plural, 40) : `Entries of ${key}`;
135
+ const when = rule.afterMinutes ? `${duration(rule.afterMinutes)} after` : "at";
136
+ const field = fieldName(settings?.fields, rule.field, site.defaultLocale);
137
+ const what =
138
+ rule.action === "hide"
139
+ ? `disappear from the site (404 on every route)`
140
+ : "leave listings, feeds, the sitemap and search (their pages stay)";
141
+ const past = await pastCount(ctx, site, key);
142
+ const already =
143
+ past === 0
144
+ ? ""
145
+ : `; ${past} published ${past === 1 ? "entry is" : "entries are"} already past it`;
146
+ return ` expiry: ${who} ${what} ${when} ${field}${already}`;
147
+ }
148
+
149
+ function sourceText(source ) {
150
+ switch (source.kind) {
151
+ case "field":
152
+ return `field ${source.field}`;
153
+ case "entry":
154
+ return `entry ${source.property}`;
155
+ case "site":
156
+ return `site ${source.property}`;
157
+ case "constant":
158
+ return `"${quote(source.value, 30)}"`;
159
+ default:
160
+ return "?";
161
+ }
162
+ }
163
+
164
+ function presetLine(preset ) {
165
+ const maps = Object.entries(preset.properties)
166
+ .filter((e) => e[1] !== undefined)
167
+ .map(([path, source]) => `${path} ← ${sourceText(source)}`);
168
+ const shown = maps.slice(0, 8).join(", ");
169
+ const more = maps.length > 8 ? ` and ${maps.length - 8} more` : "";
170
+ return ` structured data: ${preset.type}, maps ${shown}${more}; entries without a required value keep BlogPosting`;
171
+ }
172
+
173
+ /** The warnings (not refusals) of the collection's preset: select options outside a vocabulary. */
174
+ export function presetWarnings(site , key ) {
175
+ const only = site.collections?.[key];
176
+ if (!only?.structuredData) return [];
177
+ return checkStructuredData({ ...site, collections: { [key]: only } }).filter((i) => i.warning);
178
+ }
179
+
180
+ /** Approval lines for the stage 3 settings that change between `before` and `next`. */
181
+ export async function describeListings(
182
+ ctx ,
183
+ next ,
184
+ key ,
185
+ before ,
186
+ ) {
187
+ const after = next.collections?.[key] ?? {};
188
+ const changed = (k ) => canonical(before?.[k]) !== canonical(after[k]);
189
+ const lines = [];
190
+ if (changed("listFields"))
191
+ lines.push(
192
+ after.listFields
193
+ ? ` list fields: ${after.listFields.map((f) => fieldName(after.fields, f, next.defaultLocale)).join(", ")}`
194
+ : " list fields: removed",
195
+ );
196
+ if (changed("expiry"))
197
+ lines.push(
198
+ after.expiry
199
+ ? await expiryLine(ctx, next, key, after.expiry)
200
+ : " expiry: removed; entries past it come back at the next publish",
201
+ );
202
+ if (changed("structuredData")) {
203
+ lines.push(
204
+ after.structuredData
205
+ ? presetLine(after.structuredData)
206
+ : " structured data: removed; entry pages go back to BlogPosting",
207
+ );
208
+ for (const w of presetWarnings(next, key).slice(0, 3))
209
+ lines.push(` structured data warning: ${w.message}`);
210
+ }
211
+ return lines;
212
+ }
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+ function pathsOf(type ) {
235
+ return Object.entries(PRESETS[type].paths).map(([path, spec]) => {
236
+ const sources = KIND_SOURCES[spec.kind];
237
+ return {
238
+ path,
239
+ ...(spec.required ? { required: true } : {}),
240
+ ...(spec.group ? { group: spec.group } : {}),
241
+ ...(spec.default ? { default: spec.default } : {}),
242
+ fields: [...sources.fields, ...(spec.alsoFields ?? [])],
243
+ entry: sources.entry,
244
+ site: sources.site,
245
+ constant: sources.constant && !spec.required,
246
+ ...(spec.vocabulary ? { vocabulary: VOCABULARIES[spec.vocabulary].map((v) => v.key) } : {}),
247
+ };
248
+ });
249
+ }
250
+
251
+ /** What `list_collections` adds per collection for listings and structured data. */
252
+ export function listingsView(
253
+ site ,
254
+ key ,
255
+ )
256
+
257
+
258
+ {
259
+ const settings = site.collections?.[key];
260
+ const defs = new Map((settings?.fields ?? []).map((d) => [d.key, d]));
261
+ const listFields = (settings?.listFields ?? []).flatMap((k) => {
262
+ const def = defs.get(k);
263
+ return def
264
+ ? [{ key: k, type: def.type, ops: FIELD_QUERY_OPS[def.type], sortable: canOrderBy(def.type) }]
265
+ : [];
266
+ });
267
+ const preset = settings?.structuredData;
268
+ return {
269
+ ...(listFields.length ? { listFields } : {}),
270
+ ...(preset && PRESETS[preset.type]
271
+ ? {
272
+ structuredData: {
273
+ type: preset.type,
274
+ paths: pathsOf(preset.type),
275
+ warnings: presetWarnings(site, key),
276
+ },
277
+ }
278
+ : {}),
279
+ };
280
+ }
@@ -18,6 +18,13 @@ import {
18
18
  fieldsView,
19
19
  withFields,
20
20
  } from "./collection-fields.js";
21
+ import {
22
+ describeListings,
23
+ LISTINGS_INPUT,
24
+ listingsView,
25
+ presetWarnings,
26
+ withListings,
27
+ } from "./collection-listings.js";
21
28
  import {
22
29
  autoSnapshot,
23
30
  id,
@@ -33,6 +40,7 @@ import {
33
40
  } from "./common.js";
34
41
  import { SITE, SNAPSHOT } from "./content-shared.js";
35
42
  import { PERMALINK_PATTERN } from "./permalink-tools.js";
43
+ import { previewStructuredDataTool } from "./structured-data-tools.js";
36
44
 
37
45
  const ICONS = [
38
46
  "article",
@@ -98,8 +106,10 @@ function settingsOf(a , current )
98
106
  for (const k of ["icon", "feed", "sitemap", "sort"] )
99
107
  if (a[k] !== undefined) (next )[k] = a[k];
100
108
  if (typeof a.permalink === "string") next.permalink = a.permalink;
101
- if (Array.isArray(a.fields)) return withFields(current, next, a.fields );
102
- return next;
109
+ const fielded = Array.isArray(a.fields)
110
+ ? withFields(current, next, a.fields )
111
+ : next;
112
+ return withListings(fielded, a);
103
113
  }
104
114
 
105
115
  function withCollection(site , key , settings ) {
@@ -160,7 +170,7 @@ async function check(p , ctx ) {
160
170
  }
161
171
 
162
172
  /** What a person decides on. */
163
- function describe(p , mode ) {
173
+ async function describe(p , mode , ctx ) {
164
174
  const label = p.settings.labels?.[p.site.defaultLocale];
165
175
  const name = label ? `"${label.plural}" (one: "${label.singular}")` : `"${p.key}"`;
166
176
  const s = collectionSettings({ collections: { [p.key]: p.settings } }, p.key);
@@ -180,6 +190,7 @@ function describe(p , mode ) {
180
190
  p.site.defaultLocale,
181
191
  );
182
192
  if (fields) lines.push(fields);
193
+ lines.push(...(await describeListings(ctx, p.next, p.key, p.existing?.settings)));
183
194
  return `${head}\n${lines.join("\n")}`;
184
195
  }
185
196
 
@@ -193,6 +204,8 @@ const COLLECTION_OUT = obj(
193
204
  taxonomies: { type: "array", items: { type: "string" } },
194
205
  fields: { type: "array", items: { type: "object" } },
195
206
  fieldsSchema: { type: "object" },
207
+ listFields: { type: "array", items: { type: "object" } },
208
+ structuredData: { type: "object" },
196
209
  },
197
210
  ["key", "declared", "settings", "counts", "permalink", "taxonomies"],
198
211
  );
@@ -201,7 +214,7 @@ const listCollectionsTool = {
201
214
  name: "list_collections",
202
215
  title: "List collections",
203
216
  description:
204
- "The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. Each with its names per locale, icon, entry counts by status, its permalink template, feed/sitemap/sort settings (defaults filled in) and the taxonomies that apply. A collection with typed custom fields (RFC-0041) also has `fields` (the definitions) and `fieldsSchema`, the JSON Schema of an entry's `fields` with labels and help in `locale` (default: the site's default locale): read it before create_entry or update_entry with fields. Entries may only be created in these collections; call create_collection for a new one.",
217
+ "The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. Each with its names per locale, icon, entry counts by status, its permalink template, feed/sitemap/sort settings (defaults filled in) and the taxonomies that apply. A collection with typed custom fields (RFC-0041) also has `fields` (the definitions) and `fieldsSchema`, the JSON Schema of an entry's `fields` with labels and help in `locale` (default: the site's default locale): read it before create_entry or update_entry with fields. RFC-0042: `listFields` names the fields list_entries and contentList sections may filter (`where`) and sort (`orderBy`) by, each with its operators (`ops`) and whether it sorts; settings.expiry is the collection's date-driven expiry; `structuredData` is the JSON-LD preset's type with every path it offers (required ones, defaults, the sources and vocabulary each takes) and its warnings. Entries may only be created in these collections; call create_collection for a new one.",
205
218
  inputSchema: obj(
206
219
  { siteId: id, locale: str("BCP 47 locale of field labels and help; default the site's") },
207
220
  ["siteId"],
@@ -225,6 +238,7 @@ const listCollectionsTool = {
225
238
  collections: registry.map((c) => ({
226
239
  ...c,
227
240
  ...fieldsView(site, c.key, locale),
241
+ ...listingsView(site, c.key),
228
242
  settings: collectionSettings(site, c.key),
229
243
  permalink: collectionPermalink(site, c.key),
230
244
  taxonomies: taxonomies
@@ -243,7 +257,7 @@ function writeTool(mode ) {
243
257
  description:
244
258
  mode === "create"
245
259
  ? "Declare a new collection (RFC-0040), e.g. events, team or jobs, with its names in the site's default locale (labels), an optional icon, permalink (/<prefix>/{slug}, default /<key>/{slug}), feed, sitemap and default sort. Its address may not overlap a page, archive, another collection, /search or a locale prefix. A person who may change site settings approves it in every mode; dryRun: true checks without asking. Then create_entry with this collection. Declaring a collection that already has entries names it."
246
- : "Change a collection's names (merged per locale), icon, feed, sitemap, default sort (RFC-0040) or its typed custom fields (`fields`, the whole list; RFC-0041). Field edits that keep every stored value are free here; renaming a key, changing a type, localization or multiple, and dropping a key or option still in use are refused (field_change_needs_operation) and go through rename_field, change_field_type, set_field_localized or remove_field. The permalink changes only through set_collection_permalink (it moves URLs). A person who may change site settings approves it; dryRun: true checks without asking.",
260
+ : "Change a collection's names (merged per locale), icon, feed, sitemap, default sort (RFC-0040) or its typed custom fields (`fields`, the whole list; RFC-0041), list fields, date-driven expiry and JSON-LD preset (`listFields`, `expiry`, `structuredData`; RFC-0042; null removes one). Field edits that keep every stored value are free here; renaming a key, changing a type, localization or multiple, and dropping a key or option still in use are refused (field_change_needs_operation) and go through rename_field, change_field_type, set_field_localized or remove_field. The permalink changes only through set_collection_permalink (it moves URLs). A person who may change site settings approves it; dryRun: true checks without asking.",
247
261
  inputSchema: obj(
248
262
  {
249
263
  siteId: id,
@@ -252,7 +266,7 @@ function writeTool(mode ) {
252
266
  maxLength: 64,
253
267
  }),
254
268
  ...SETTINGS_INPUT,
255
- ...(mode === "update" ? { fields: FIELD_DEFINITIONS_INPUT } : {}),
269
+ ...(mode === "update" ? { fields: FIELD_DEFINITIONS_INPUT, ...LISTINGS_INPUT } : {}),
256
270
  ...(mode === "create"
257
271
  ? {
258
272
  permalink: str("Template, e.g. /etkinlik/{slug}; default /<key>/{slug}", {
@@ -268,7 +282,13 @@ function writeTool(mode ) {
268
282
  mode === "create" ? ["siteId", "collection", "labels"] : ["siteId", "collection"],
269
283
  ),
270
284
  outputSchema: obj(
271
- { prompt: { type: "string" }, dryRun: { type: "boolean" }, site: SITE, snapshot: SNAPSHOT },
285
+ {
286
+ prompt: { type: "string" },
287
+ dryRun: { type: "boolean" },
288
+ site: SITE,
289
+ snapshot: SNAPSHOT,
290
+ warnings: { type: "array", items: { type: "object" } },
291
+ },
272
292
  ["prompt", "dryRun"],
273
293
  ),
274
294
  annotations: {
@@ -283,13 +303,15 @@ function writeTool(mode ) {
283
303
  requiresApproval: true,
284
304
  classify: (a) => (a.dryRun === true ? "read" : "person"),
285
305
  precheck: async (a, ctx) => check(await planFor(a, ctx, mode), ctx),
286
- approvalPrompt: async (a, ctx) => describe(await planFor(a, ctx, mode), mode),
306
+ approvalPrompt: async (a, ctx) => describe(await planFor(a, ctx, mode), mode, ctx),
287
307
  handler: async (a, ctx) => {
288
308
  const p = await planFor(a, ctx, mode);
289
- const prompt = describe(p, mode);
309
+ const prompt = await describe(p, mode, ctx);
310
+ const warnings = presetWarnings(p.next, p.key);
311
+ const warned = warnings.length ? { warnings } : {};
290
312
  if (a.dryRun === true) {
291
313
  await check(p, ctx);
292
- return { prompt, dryRun: true };
314
+ return { prompt, dryRun: true, ...warned };
293
315
  }
294
316
  let site ;
295
317
  try {
@@ -298,11 +320,11 @@ function writeTool(mode ) {
298
320
  throw toToolError(e);
299
321
  }
300
322
  const snapshot = await autoSnapshot(ctx, site.id, name);
301
- return { prompt, dryRun: false, site, snapshot };
323
+ return { prompt, dryRun: false, site, snapshot, ...warned };
302
324
  },
303
325
  };
304
326
  }
305
327
 
306
328
  export function collectionTools() {
307
- return [listCollectionsTool, writeTool("create"), writeTool("update")];
329
+ return [listCollectionsTool, writeTool("create"), writeTool("update"), previewStructuredDataTool];
308
330
  }
@@ -6,20 +6,18 @@
6
6
  * `fields` as a merge patch (`null` removes a key), and its approval prompt names each typed change
7
7
  * readably: labels, option labels, dates in their zone, values quoted and truncated.
8
8
  */
9
-
9
+
10
10
  import {
11
- ASSET_ID_PATTERN,
12
11
  checkFieldValues,
13
12
  checkRequiredToPublish,
14
13
  convertContext,
15
-
16
14
  fieldDefinitions,
17
15
  fieldLabel,
18
16
  normalizeThroughMarkers,
19
17
  optionLabel,
20
18
  refuseFieldIssues,
21
19
  } from "@cloudhal/core-ts/fields";
22
- import { markdownAssetIds } from "@cloudhal/core-ts/media";
20
+ import { fieldAssetIssues, fieldAssetRefs } from "@cloudhal/core-ts/media";
23
21
  import { quote, } from "./common.js";
24
22
 
25
23
 
@@ -61,56 +59,6 @@ async function originalOf(
61
59
  return original?.siteId === entry.siteId ? original : undefined;
62
60
  }
63
61
 
64
- const ASSET_ID = new RegExp(ASSET_ID_PATTERN);
65
-
66
- /** `fields.<key>` → asset ids an image or rich-text value refers to. */
67
- function assetRefs(defs , values ) {
68
- const out = new Set ();
69
- for (const def of defs) {
70
- const value = values?.[def.key];
71
- if (typeof value !== "string") continue;
72
- if (def.type === "image" && ASSET_ID.test(value)) out.add(`${def.key}\n${value}`);
73
- else if (def.type === "richText" && value.includes("asset:"))
74
- for (const id of markdownAssetIds(value)) out.add(`${def.key}\n${id}`);
75
- }
76
- return out;
77
- }
78
-
79
- function assetProblem(asset , def , siteId ) {
80
- if (!asset || asset.siteId !== siteId) return "is not a file of this site";
81
- if (def.type === "image" && asset.kind !== "image")
82
- return `is a ${asset.kind} file, not an image`;
83
- if (asset.status === "retired") return "was retired and cannot be newly used";
84
- return undefined;
85
- }
86
-
87
- /** New references (not held by the stored entry under the same key) name usable files of the site. */
88
- async function assetIssues(
89
- ctx ,
90
- check
91
-
92
-
93
-
94
-
95
- ,
96
- ) {
97
- const held = assetRefs(check.defs, check.stored);
98
- const byKey = new Map(check.defs.map((d) => [d.key, d]));
99
- const out = [];
100
- for (const ref of assetRefs(check.defs, check.values)) {
101
- if (held.has(ref)) continue;
102
- const [key = "", assetId = ""] = ref.split("\n");
103
- const problem = assetProblem(
104
- await ctx.store.getAsset(assetId),
105
- byKey.get(key) ,
106
- check.siteId,
107
- );
108
- if (problem)
109
- out.push({ path: `fields/${key}`, code: "invalid_value", message: `${assetId} ${problem}` });
110
- }
111
- return out;
112
- }
113
-
114
62
  /** What an entry write would store, for the check. */
115
63
 
116
64
 
@@ -150,9 +98,16 @@ export async function checkEntryFields(ctx , check )
150
98
  original: original ? { id: original.id, values: original.fields ?? {} } : undefined,
151
99
  blocks: ctx.store.blocks,
152
100
  });
153
- const invalid = new Set(issues.map((i) => i.path.split("/").slice(0, 2).join("/")));
154
- const assets = await assetIssues(ctx, { siteId: site.id, defs, values, stored: previous });
155
- issues.push(...assets.filter((i) => !invalid.has(i.path)));
101
+ // The store's asset check: new references name usable files of the site.
102
+ issues.push(
103
+ ...(await fieldAssetIssues({
104
+ defs,
105
+ refs: fieldAssetRefs(defs, values),
106
+ kept: stored ? fieldAssetRefs(fieldDefinitions(site, stored.collection), stored.fields) : [],
107
+ lookup: (ids) => ctx.store.getAssets(site.id, ids),
108
+ skip: new Set(issues.map((i) => i.path.split("/").slice(0, 2).join("/"))),
109
+ })),
110
+ );
156
111
  issues.push(...checkRequiredToPublish(site, { ...next, fields: values }, original));
157
112
  refuseFieldIssues(issues);
158
113
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * RFC-0042 §4 "API and MCP" for `list_entries`: `where` and `orderBy` over a collection's list
3
+ * fields, run by core-ts's shared evaluator (`queryContentEntries`), and `limit`/`cursor` paging.
4
+ * Without `orderBy` the list keeps its order (last updated first); without `limit` it is unpaged,
5
+ * as before. Problems are refused as `invalid_query` with their paths (`where/0/value`).
6
+ */
7
+ import type { ContentEntry } from "@cloudhal/core-contracts";
8
+ import { type EntryQuery } from "@cloudhal/core-ts";
9
+ import type { JsonSchema, ToolContext } from "./common.js";
10
+ export declare const ENTRY_QUERY_INPUT: Record<string, JsonSchema>;
11
+ export interface EntryListAnswer {
12
+ entries: ContentEntry[];
13
+ total?: number;
14
+ nextCursor?: string;
15
+ }
16
+ /** The entries of `base` matching the call's field query, ordered and paged. */
17
+ export declare function listEntries(ctx: ToolContext, siteId: string, base: EntryQuery, a: Record<string, unknown>): Promise<EntryListAnswer>;