@cloudhal/mcp-server 0.4.0 → 0.6.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.
@@ -4,7 +4,8 @@
4
4
  * it uses and the current translation; `save_translation` writes a draft in the target locale,
5
5
  * linked to the source revision, with its provenance and the deterministic checks
6
6
  * (`checkTranslation`). Agents never review: only a person does, in Studio. A translation a person
7
- * wrote or reviewed is never overwritten here.
7
+ * wrote or reviewed is never overwritten here. Typed fields follow RFC-0041 §5
8
+ * (`translation-fields.ts`): only localized text is translated, shared values stay on the original.
8
9
  */
9
10
  import { forSite, holds } from "@cloudhal/agent-runtime";
10
11
 
@@ -34,6 +35,12 @@ import {
34
35
  ToolError,
35
36
  } from "./common.js";
36
37
  import { ENTRY, mcpWriter, PAGE, SNAPSHOT, sectionInput } from "./content-shared.js";
38
+ import {
39
+ refuseSharedFields,
40
+ TRANSLATED_FIELDS,
41
+ translatedFields,
42
+ translationSourceFields,
43
+ } from "./translation-fields.js";
37
44
 
38
45
 
39
46
 
@@ -100,7 +107,7 @@ const getSourceTool = {
100
107
  name: "get_translation_source",
101
108
  title: "Get translation source",
102
109
  description:
103
- "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), the glossary terms it uses (doNotTranslate terms stay as written, given translations are used), and the current translation in that locale if there is one (with `stale` when the source changed since, and for a linked page whose source changed its layout, `layout`: the translation's sections on the new layout, with the `untranslated` ones to translate). Then call save_translation.",
110
+ "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), for an entry with typed fields the localized text and rich-text values to translate (`fields`) and the shared fields a translation reads from the original (`sharedFields`, never translated), the glossary terms it uses (doNotTranslate terms stay as written, given translations are used), and the current translation in that locale if there is one (with `stale` when the source changed since, and for a linked page whose source changed its layout, `layout`: the translation's sections on the new layout, with the `untranslated` ones to translate). Then call save_translation.",
104
111
  inputSchema: obj(
105
112
  {
106
113
  siteId: id,
@@ -118,6 +125,17 @@ const getSourceTool = {
118
125
  {
119
126
  source: { type: "object" },
120
127
  glossary: { type: "array", items: { type: "object" } },
128
+ fields: {
129
+ type: "object",
130
+ description:
131
+ "Entries: the localized text and rich-text field values to translate, by key; send them translated as save_translation's `fields`",
132
+ },
133
+ sharedFields: {
134
+ type: "array",
135
+ items: { type: "string" },
136
+ description:
137
+ "Entries: keys of the fields that are not localized: every language version reads them from the original, so they are not translated",
138
+ },
121
139
  existing: { type: "object" },
122
140
  stale: { type: "boolean" },
123
141
  layout: {
@@ -140,7 +158,10 @@ const getSourceTool = {
140
158
  const group = await ctx.store.translationGroup(site, source.translation?.group ?? source.id);
141
159
  const member = group.members.find((m) => m.locale === locale && m.siteId === target.id);
142
160
  const existing = member ? await nodeOf(ctx, target.id, member.id) : undefined;
143
- const text = JSON.stringify("sections" in source ? source.sections : source.body.value);
161
+ const typed = translationSourceFields(site, source);
162
+ const text = JSON.stringify(
163
+ "sections" in source ? source.sections : [source.body.value, typed.fields ?? {}],
164
+ );
144
165
  // RFC-0033 §4a: a linked page translation follows the source's layout; nothing is written.
145
166
  const layout =
146
167
  existing &&
@@ -150,7 +171,7 @@ const getSourceTool = {
150
171
  ? linkedLayout(source, existing)
151
172
  : undefined;
152
173
  return {
153
- source,
174
+ ...typed,
154
175
  glossary: glossaryFor(
155
176
  await ctx.store.glossary.get(site.id),
156
177
  `${source.title} ${text}`,
@@ -166,7 +187,7 @@ const saveTranslationTool = {
166
187
  name: "save_translation",
167
188
  title: "Save translation",
168
189
  description:
169
- "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. Pages: send title, path and sections (same ids, kinds and order as the source; translated text). Entries: title, slug, body and summary. The checks (structure, links, numbers, glossary, length) run and are returned; a failed check keeps it from being published until fixed. A person reviews it in Studio before it goes live where the site asks for review. Refused for a translation a person wrote or reviewed. Snapshots afterwards.",
190
+ "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. Pages: send title, path and sections (same ids, kinds and order as the source; translated text). Entries: title, slug, body, summary and the translated `fields` (only the localized text and rich-text ones get_translation_source returns; shared fields are refused with field_not_localized). The checks (structure, links, numbers, glossary, length) run and are returned; a failed check keeps it from being published until fixed. A person reviews it in Studio before it goes live where the site asks for review. Refused for a translation a person wrote or reviewed. Snapshots afterwards.",
170
191
  inputSchema: obj(
171
192
  {
172
193
  siteId: id,
@@ -178,6 +199,7 @@ const saveTranslationTool = {
178
199
  sections: sectionInput,
179
200
  body: str("Entries: the translated markdown body"),
180
201
  summary: str("Entries: the translated summary"),
202
+ fields: TRANSLATED_FIELDS,
181
203
  coverAlt: str(
182
204
  "Entries: the cover image's alt text in `locale`. Without it a new translation leaves the cover alt empty, so the image's own alt text in `locale` (update_asset) is shown",
183
205
  { maxLength: 500 },
@@ -207,6 +229,13 @@ const saveTranslationTool = {
207
229
  openWorldHint: false,
208
230
  },
209
231
  scopes: ["content:write"],
232
+ // RFC-0041 §5: a shared (non-localized) field value is refused before anything is written.
233
+ precheck: async (a, ctx) => {
234
+ if (a.fields === undefined) return;
235
+ const site = await ctx.store.getSite(a.siteId );
236
+ const source = await ctx.store.getContentEntry(a.nodeId );
237
+ if (site && source?.siteId === site.id) refuseSharedFields(site, source, a.fields);
238
+ },
210
239
  handler: async (a, ctx) => {
211
240
  const site = await requireSite(ctx, a.siteId );
212
241
  const target = await targetOf(ctx, site, a.targetSiteId);
@@ -247,7 +276,25 @@ const saveTranslationTool = {
247
276
  },
248
277
  };
249
278
  try {
250
- const made = translatedNode({ a, site: target.id, locale, source, existing, translation });
279
+ const fields =
280
+ "sections" in source
281
+ ? undefined
282
+ : translatedFields({
283
+ site,
284
+ source,
285
+ existing: existing ,
286
+ given: a.fields ,
287
+ cross,
288
+ });
289
+ const made = translatedNode({
290
+ a,
291
+ site: target.id,
292
+ locale,
293
+ source,
294
+ existing,
295
+ translation,
296
+ fields,
297
+ });
251
298
  // RFC-0034 §6: on an edition, the images come along and the terms are the edition's.
252
299
  const draft = cross
253
300
  ? await forEdition(ctx.store, made, {
@@ -318,6 +365,8 @@ function translatedNode(input
318
365
 
319
366
 
320
367
 
368
+
369
+
321
370
  ) {
322
371
  const { a, site, locale, source, existing, translation } = input;
323
372
  const common = {
@@ -347,6 +396,7 @@ function translatedNode(input
347
396
  body: { format: "markdown", value: (a.body ) ?? base.body.value },
348
397
  ...(a.summary !== undefined ? { summary: a.summary } : {}),
349
398
  ...(cover ? { coverImage: cover } : {}),
399
+ ...(input.fields ? { fields: input.fields } : {}),
350
400
  } ;
351
401
  }
352
402
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/mcp-server",
3
- "version": "0.4.0",
3
+ "version": "0.6.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.4.0",
60
- "@cloudhal/agent-runtime": "0.4.0",
61
- "@cloudhal/astro-renderer": "0.4.0",
62
- "@cloudhal/comments": "0.4.0",
63
- "@cloudhal/core-contracts": "0.4.0",
64
- "@cloudhal/core-ts": "0.4.0",
65
- "@cloudhal/storage": "0.4.0",
59
+ "@cloudhal/analytics": "0.6.0",
60
+ "@cloudhal/agent-runtime": "0.6.0",
61
+ "@cloudhal/astro-renderer": "0.6.0",
62
+ "@cloudhal/comments": "0.6.0",
63
+ "@cloudhal/core-contracts": "0.6.0",
64
+ "@cloudhal/core-ts": "0.6.0",
65
+ "@cloudhal/storage": "0.6.0",
66
66
  "@modelcontextprotocol/server": "2.3.1",
67
- "@cloudhal/schedules": "0.4.0"
67
+ "@cloudhal/schedules": "0.6.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@cloudflare/workers-types": "^5.20261007.1",