@cloudhal/mcp-server 0.7.2 → 0.8.0

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.
@@ -6,7 +6,10 @@
6
6
  */
7
7
  import type { CollectionSettings, FieldDefinition, Site } from "@cloudhal/core-contracts";
8
8
  import { type JsonSchema } from "./common.js";
9
- /** `update_collection`'s `fields`: the contract's definitions, minus the operation marker. */
9
+ /**
10
+ * `update_collection`'s `fields`: the enabled definitions, minus the operation marker, with every
11
+ * `$defs` entry they reach (`defsClosure`), so a contract change cannot leave a `$ref` dangling.
12
+ */
10
13
  export declare const FIELD_DEFINITIONS_INPUT: JsonSchema;
11
14
  /**
12
15
  * The settings with `fields` replaced by the agent's list. A running operation's marker stays on
@@ -6,19 +6,36 @@
6
6
  */
7
7
 
8
8
  import { SiteSchema } from "@cloudhal/core-contracts";
9
- import { fieldLabel, fieldsJsonSchema } from "@cloudhal/core-ts/fields";
9
+ import { fieldLabel, fieldsJsonSchema, isReferenceFieldType } from "@cloudhal/core-ts/fields";
10
10
  import { quote } from "./common.js";
11
+ import { defsClosure } from "./schema-transforms.js";
11
12
 
12
13
  const DEFS = SiteSchema.$defs ;
13
14
  const VARIANTS = (DEFS.FieldDefinition ).oneOf ;
14
15
 
16
+ /** A variant's `type` value (`{ enum: ["text"] }`). */
17
+ const typeOf = (variant ) =>
18
+ ((variant.properties ).type?.enum ?? [])[0] ?? "";
19
+
15
20
  /** A definition variant without `migration`: only field operations write the marker. */
16
21
  function withoutMarker(variant ) {
17
22
  const { migration: _m, ...properties } = variant.properties ;
18
23
  return { ...variant, properties };
19
24
  }
20
25
 
21
- /** `update_collection`'s `fields`: the contract's definitions, minus the operation marker. */
26
+ /**
27
+ * The definitions `update_collection` takes: the contract's variants of the enabled types (RFC-0045's
28
+ * `reference` and `repeater` join at rollout step 7), each without the operation marker.
29
+ */
30
+ const FIELD_DEFINITION = {
31
+ ...DEFS.FieldDefinition,
32
+ oneOf: VARIANTS.filter((v) => !isReferenceFieldType(typeOf(v))).map(withoutMarker),
33
+ };
34
+
35
+ /**
36
+ * `update_collection`'s `fields`: the enabled definitions, minus the operation marker, with every
37
+ * `$defs` entry they reach (`defsClosure`), so a contract change cannot leave a `$ref` dangling.
38
+ */
22
39
  export const FIELD_DEFINITIONS_INPUT = {
23
40
  type: "array",
24
41
  maxItems: 30,
@@ -26,16 +43,8 @@ export const FIELD_DEFINITIONS_INPUT = {
26
43
  "The collection's typed custom fields, the whole list in form order ([] removes them all). Free edits only: add fields, reorder, change labels and help, add select options or change their labels, toggle multiline, searchable or requiredToPublish, change maxLength/minimum/maximum. Renaming a key, changing a type, localized or multiple, and dropping a key or option still in use need rename_field, change_field_type, set_field_localized or remove_field.",
27
44
  items: { $ref: "#/$defs/FieldDefinition" },
28
45
  $defs: {
29
- FieldDefinition: {
30
- ...DEFS.FieldDefinition,
31
- oneOf: VARIANTS.map(withoutMarker),
32
- },
33
- FieldKey: DEFS.FieldKey,
34
- FieldLabel: DEFS.FieldLabel,
35
- FieldLabels: DEFS.FieldLabels,
36
- FieldOption: DEFS.FieldOption,
37
- Slug: DEFS.Slug,
38
- Locale: DEFS.Locale,
46
+ ...defsClosure(SiteSchema , FIELD_DEFINITION),
47
+ FieldDefinition: FIELD_DEFINITION,
39
48
  },
40
49
  };
41
50
 
@@ -111,7 +111,8 @@ export async function checkEntryFields(ctx , check )
111
111
  refs: fieldAssetRefs(defs, values),
112
112
  kept: stored ? fieldAssetRefs(fieldDefinitions(site, stored.collection), stored.fields) : [],
113
113
  lookup: (ids) => ctx.store.getAssets(site.id, ids),
114
- skip: new Set(issues.map((i) => i.path.split("/").slice(0, 2).join("/"))),
114
+ // RFC-0045 §2.5: issue paths as they are, as the store's check builds them.
115
+ skip: new Set(issues.map((i) => i.path)),
115
116
  })),
116
117
  );
117
118
  issues.push(...checkRequiredToPublish(site, { ...next, fields: values }, original));
@@ -4,6 +4,7 @@
4
4
  * `details.issues`, each at its slash path (`fields/startsAt/at`), so the hint only names the tool.
5
5
  */
6
6
 
7
+ import { FIELD_TYPES } from "@cloudhal/core-ts/fields";
7
8
 
8
9
  const OPERATIONS = "rename_field, change_field_type, set_field_localized or remove_field";
9
10
 
@@ -37,6 +38,26 @@ const HINTS = {
37
38
  "fix the mappings at the paths in details.issues: list_collections shows a preset's paths, which are required and the sources each takes (structuredData.paths); field sources need a field of a fitting type, and required values come from the entry, never a constant",
38
39
  invalid_expiry:
39
40
  "expiry.field must be a date or datetime field of the collection (list_collections → fields)",
41
+ // RFC-0045 (references and repeaters; refused until they are enabled)
42
+ fields_unsupported: `reference and repeater fields are not available on this server yet: give the field one of the types update_collection's fields input takes (${FIELD_TYPES.join(", ")}; text for now), and keep the rest of the change as it is`,
43
+ reference_target_unknown:
44
+ "a reference field's collections must be collections of this site (list_collections)",
45
+ too_many_references:
46
+ "an entry holds at most 100 references across its fields and repeater items; remove some",
47
+ unknown_entry:
48
+ "each reference names the groupId of an entry of this site in one of the field's collections (list_entries); remove or replace the ids at the paths in details.issues",
49
+ reference_target_moved:
50
+ "published entries show this entry through a field that does not allow the new collection: keep it where it is, or ask a person to unpublish or edit those entries first",
51
+ entry_referenced:
52
+ "published entries (details.referrers) show this entry, and it is the last one of its group here: ask a person to unpublish or edit them first; archiving it does not release them",
53
+ translation_group_in_use:
54
+ "other language versions use this entry as their original: unlink or move them first, then change its translation",
55
+ field_operation_running:
56
+ "a field operation is converting values into references to this collection: wait until it finishes, then try again",
57
+ field_operation_unsupported:
58
+ "field operations on reference and repeater fields are not available on this server yet; edit the entries instead",
59
+ field_key_in_use:
60
+ "entries of the collection already hold a value under that key: pick another key, or convert the existing field with change_field_type",
40
61
  list_field_in_use:
41
62
  "contentList sections on the pages in details.pages still filter or sort by that field: change their where/orderBy first (update_page), then try again",
42
63
  };
@@ -6,6 +6,14 @@ import type { JsonSchema } from "./common.js";
6
6
  * hoisted there (names are shared and identical across contracts).
7
7
  */
8
8
  export declare function hoistDefs(schema: JsonSchema): JsonSchema;
9
+ /**
10
+ * RFC-0045 §6: the `$defs` of `schema` that `from` reaches, transitively through `#/$defs/*`
11
+ * references: a `$defs` name (included itself) or a schema node of its own (not included). A tool
12
+ * that embeds part of a contract carries exactly these, so no `$ref` dangles when a contract
13
+ * change adds one (`hoistDefs` only hoists nested `$defs` and finds no missing ones). Throws on a
14
+ * reference `schema` does not define.
15
+ */
16
+ export declare function defsClosure(schema: JsonSchema, from: string | JsonSchema): Record<string, JsonSchema>;
9
17
  /**
10
18
  * Inputs may name an image by asset alone (`{ assetId, alt? }`, RFC-0004 §2.2): the store writes
11
19
  * `src`, `width` and `height`. So an input ImageRef needs `src` or `assetId`, and `alt` may be left
@@ -30,6 +30,44 @@ export function hoistDefs(schema ) {
30
30
  : root;
31
31
  }
32
32
 
33
+ const LOCAL_REF = "#/$defs/";
34
+
35
+ /** The `$defs` names `node` refers to directly (`#/$defs/<name>` only). */
36
+ function refsOf(node , out ) {
37
+ if (Array.isArray(node)) for (const n of node) refsOf(n, out);
38
+ else if (node && typeof node === "object")
39
+ for (const [k, v] of Object.entries(node )) {
40
+ if (k === "$ref" && typeof v === "string" && v.startsWith(LOCAL_REF))
41
+ out.add(v.slice(LOCAL_REF.length));
42
+ else refsOf(v, out);
43
+ }
44
+ return out;
45
+ }
46
+
47
+ /**
48
+ * RFC-0045 §6: the `$defs` of `schema` that `from` reaches, transitively through `#/$defs/*`
49
+ * references: a `$defs` name (included itself) or a schema node of its own (not included). A tool
50
+ * that embeds part of a contract carries exactly these, so no `$ref` dangles when a contract
51
+ * change adds one (`hoistDefs` only hoists nested `$defs` and finds no missing ones). Throws on a
52
+ * reference `schema` does not define.
53
+ */
54
+ export function defsClosure(
55
+ schema ,
56
+ from ,
57
+ ) {
58
+ const defs = (schema.$defs ?? {}) ;
59
+ const out = {};
60
+ const queue = typeof from === "string" ? [from] : [...refsOf(from, new Set())];
61
+ for (let name = queue.shift(); name !== undefined; name = queue.shift()) {
62
+ if (Object.hasOwn(out, name)) continue;
63
+ const def = defs[name];
64
+ if (!def) throw new Error(`$defs has no ${name}`);
65
+ out[name] = def;
66
+ for (const next of refsOf(def, new Set())) if (!Object.hasOwn(out, next)) queue.push(next);
67
+ }
68
+ return out;
69
+ }
70
+
33
71
  /**
34
72
  * Inputs may name an image by asset alone (`{ assetId, alt? }`, RFC-0004 §2.2): the store writes
35
73
  * `src`, `width` and `height`. So an input ImageRef needs `src` or `assetId`, and `alt` may be left
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/mcp-server",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Cloudhal MCP server: semantic site tools (pages, articles, snapshots, preview, publish) governed by the policy engine",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://cloudhal.dev",
@@ -56,15 +56,15 @@
56
56
  "README.md"
57
57
  ],
58
58
  "dependencies": {
59
- "@cloudhal/analytics": "0.7.2",
60
- "@cloudhal/agent-runtime": "0.7.2",
61
- "@cloudhal/astro-renderer": "0.7.2",
62
- "@cloudhal/comments": "0.7.2",
63
- "@cloudhal/core-contracts": "0.7.2",
64
- "@cloudhal/core-ts": "0.7.2",
65
- "@cloudhal/storage": "0.7.2",
59
+ "@cloudhal/analytics": "0.8.0",
60
+ "@cloudhal/agent-runtime": "0.8.0",
61
+ "@cloudhal/astro-renderer": "0.8.0",
62
+ "@cloudhal/comments": "0.8.0",
63
+ "@cloudhal/core-contracts": "0.8.0",
64
+ "@cloudhal/core-ts": "0.8.0",
65
+ "@cloudhal/storage": "0.8.0",
66
66
  "@modelcontextprotocol/server": "2.3.1",
67
- "@cloudhal/schedules": "0.7.2"
67
+ "@cloudhal/schedules": "0.8.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@cloudflare/workers-types": "^5.20261007.1",