@cloudhal/mcp-server 0.5.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.
- package/README.md +4 -3
- package/dist/src/collection-fields.d.ts +2 -0
- package/dist/src/collection-fields.js +1 -1
- package/dist/src/collection-listings.d.ts +48 -0
- package/dist/src/collection-listings.js +280 -0
- package/dist/src/collection-tools.js +34 -12
- package/dist/src/entry-fields.js +12 -57
- package/dist/src/entry-list.d.ts +17 -0
- package/dist/src/entry-list.js +98 -0
- package/dist/src/entry-tools.js +12 -6
- package/dist/src/field-hints.d.ts +2 -1
- package/dist/src/field-hints.js +18 -1
- package/dist/src/page-tools.js +7 -0
- package/dist/src/release-risk.d.ts +22 -0
- package/dist/src/release-risk.js +95 -0
- package/dist/src/schedules.d.ts +2 -5
- package/dist/src/schedules.js +5 -38
- package/dist/src/section-queries.d.ts +10 -0
- package/dist/src/section-queries.js +52 -0
- package/dist/src/server-instructions.js +3 -1
- package/dist/src/structured-data-tools.d.ts +8 -0
- package/dist/src/structured-data-tools.js +111 -0
- package/dist/src/tools.js +15 -4
- package/dist/src/translation-fields.d.ts +32 -0
- package/dist/src/translation-fields.js +68 -0
- package/dist/src/translation-tools.js +56 -6
- package/package.json +9 -9
package/dist/src/tools.js
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
describeOwnOnly,
|
|
22
22
|
effectiveMode,
|
|
23
23
|
} from "@cloudhal/agent-runtime";
|
|
24
|
+
import { expiringEntries, } from "@cloudhal/core-ts";
|
|
24
25
|
import {
|
|
25
26
|
afterRunCall,
|
|
26
27
|
checkRunBudget,
|
|
@@ -135,6 +136,19 @@ export function toolPolicies(tools ) {
|
|
|
135
136
|
|
|
136
137
|
|
|
137
138
|
|
|
139
|
+
/**
|
|
140
|
+
* What the store knows about a pending publish for the `auto`-mode check: new images riding with
|
|
141
|
+
* articles (RFC-0004 §6.3), corrections (RFC-0019 §2.4) and derived gates added or moved earlier
|
|
142
|
+
* on live articles (RFC-0042 §3.5).
|
|
143
|
+
*/
|
|
144
|
+
async function autoPublishFacts(store , siteId , pending ) {
|
|
145
|
+
return {
|
|
146
|
+
ridingAssets: await store.ridingAssets(siteId, pending),
|
|
147
|
+
corrections: await store.correctingEntries(siteId, pending),
|
|
148
|
+
expiries: await expiringEntries(store, siteId, pending),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
138
152
|
/**
|
|
139
153
|
* Policy → audit → handler. Transports call this; it is the only path a tool runs through.
|
|
140
154
|
* `confirmed` is set by the transport once the human said yes (MRTR response or confirm token);
|
|
@@ -246,10 +260,7 @@ export async function runTool(
|
|
|
246
260
|
) {
|
|
247
261
|
const pending = await ctx.store.pendingChanges(siteId);
|
|
248
262
|
// New raster images used only by the articles in this publish ride along (RFC-0004 §6.3).
|
|
249
|
-
autoCheck = checkAutoPublish(pending,
|
|
250
|
-
ridingAssets: await ctx.store.ridingAssets(siteId, pending),
|
|
251
|
-
corrections: await ctx.store.correctingEntries(siteId, pending),
|
|
252
|
-
});
|
|
263
|
+
autoCheck = checkAutoPublish(pending, await autoPublishFacts(ctx.store, siteId, pending));
|
|
253
264
|
if (autoCheck.lowRisk)
|
|
254
265
|
autoNote = `auto mode: published without approval (${describeAutoCheck(autoCheck)})`;
|
|
255
266
|
else
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041 §5: typed fields in machine translation. `get_translation_source` hands over only the
|
|
3
|
+
* localized `text` and `richText` values to translate and names the shared (non-localized) fields a
|
|
4
|
+
* translation reads from its original; `save_translation` takes translated values of localized
|
|
5
|
+
* fields and refuses shared ones in precheck (`field_not_localized`). Within a site, a new
|
|
6
|
+
* translation holds only the values sent (absent localized ones fall back to the original's) and
|
|
7
|
+
* never a copy of a shared value; a language edition copies the source's values (§5: the other
|
|
8
|
+
* site's definitions may differ).
|
|
9
|
+
*/
|
|
10
|
+
import type { ContentEntry, Site } from "@cloudhal/core-contracts";
|
|
11
|
+
import type { JsonSchema } from "./common.js";
|
|
12
|
+
type Values = Record<string, unknown>;
|
|
13
|
+
/** `save_translation`'s `fields`. */
|
|
14
|
+
export declare const TRANSLATED_FIELDS: JsonSchema;
|
|
15
|
+
/** What `get_translation_source` returns about an entry's typed fields (nothing for a page). */
|
|
16
|
+
export declare function translationSourceFields(site: Site, source: object): {
|
|
17
|
+
source: object;
|
|
18
|
+
fields?: Record<string, string>;
|
|
19
|
+
sharedFields?: string[];
|
|
20
|
+
};
|
|
21
|
+
/** The precheck: translated values of shared fields are refused, before anything is written. */
|
|
22
|
+
export declare function refuseSharedFields(site: Site, source: ContentEntry, values: unknown): void;
|
|
23
|
+
/** The `fields` of a translated entry: the sent values on what the translation may start from. */
|
|
24
|
+
export declare function translatedFields(input: {
|
|
25
|
+
site: Site;
|
|
26
|
+
source: ContentEntry;
|
|
27
|
+
existing: ContentEntry | undefined;
|
|
28
|
+
given: Values | undefined;
|
|
29
|
+
/** A language edition: the source's values come along. */
|
|
30
|
+
cross: boolean;
|
|
31
|
+
}): Values;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041 §5: typed fields in machine translation. `get_translation_source` hands over only the
|
|
3
|
+
* localized `text` and `richText` values to translate and names the shared (non-localized) fields a
|
|
4
|
+
* translation reads from its original; `save_translation` takes translated values of localized
|
|
5
|
+
* fields and refuses shared ones in precheck (`field_not_localized`). Within a site, a new
|
|
6
|
+
* translation holds only the values sent (absent localized ones fall back to the original's) and
|
|
7
|
+
* never a copy of a shared value; a language edition copies the source's values (§5: the other
|
|
8
|
+
* site's definitions may differ).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
fieldDefinitions,
|
|
13
|
+
refuseFieldIssues,
|
|
14
|
+
sharedFieldIssues,
|
|
15
|
+
sharedFieldKeys,
|
|
16
|
+
translatableFieldValues,
|
|
17
|
+
} from "@cloudhal/core-ts/fields";
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/** `save_translation`'s `fields`. */
|
|
23
|
+
export const TRANSLATED_FIELDS = {
|
|
24
|
+
type: "object",
|
|
25
|
+
description:
|
|
26
|
+
"Entries: your translation of each value in get_translation_source's `fields` (localized text and rich-text fields), by key. Shared fields (`sharedFields`) are read from the original and refused here",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** What `get_translation_source` returns about an entry's typed fields (nothing for a page). */
|
|
30
|
+
export function translationSourceFields(
|
|
31
|
+
site ,
|
|
32
|
+
source ,
|
|
33
|
+
) {
|
|
34
|
+
if (!("collection" in source)) return { source };
|
|
35
|
+
const entry = source ;
|
|
36
|
+
const defs = fieldDefinitions(site, entry.collection);
|
|
37
|
+
if (defs.length === 0) return { source };
|
|
38
|
+
const { fields, ...rest } = entry;
|
|
39
|
+
const shared = sharedFieldKeys(defs);
|
|
40
|
+
return {
|
|
41
|
+
source: rest,
|
|
42
|
+
fields: translatableFieldValues(defs, fields),
|
|
43
|
+
...(shared.length > 0 ? { sharedFields: shared } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The precheck: translated values of shared fields are refused, before anything is written. */
|
|
48
|
+
export function refuseSharedFields(site , source , values ) {
|
|
49
|
+
if (!values || typeof values !== "object") return;
|
|
50
|
+
const defs = fieldDefinitions(site, source.collection);
|
|
51
|
+
const original = source.translation?.group ?? source.id;
|
|
52
|
+
refuseFieldIssues(sharedFieldIssues(defs, values , original));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The `fields` of a translated entry: the sent values on what the translation may start from. */
|
|
56
|
+
export function translatedFields(input
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
) {
|
|
64
|
+
const { site, source, existing, given, cross } = input;
|
|
65
|
+
const defined = fieldDefinitions(site, source.collection).length > 0;
|
|
66
|
+
const base = existing?.fields ?? (cross || !defined ? (source.fields ?? {}) : {});
|
|
67
|
+
return { ...base, ...(given ?? {}) };
|
|
68
|
+
}
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
60
|
-
"@cloudhal/agent-runtime": "0.
|
|
61
|
-
"@cloudhal/astro-renderer": "0.
|
|
62
|
-
"@cloudhal/comments": "0.
|
|
63
|
-
"@cloudhal/core-contracts": "0.
|
|
64
|
-
"@cloudhal/core-ts": "0.
|
|
65
|
-
"@cloudhal/storage": "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.
|
|
67
|
+
"@cloudhal/schedules": "0.6.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@cloudflare/workers-types": "^5.20261007.1",
|