@cloudhal/mcp-server 0.10.0 → 0.11.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 +1 -1
- package/dist/src/asset-tools.js +32 -9
- package/dist/src/publish-tools.js +4 -2
- package/dist/src/render/cdp.js +6 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ The playground and the local stdio server (`cloudhal mcp`) take none of these: a
|
|
|
114
114
|
| `list_snapshots` | `site:read` | read | — | Snapshots of a site, newest first, and which one is live. |
|
|
115
115
|
| `diff_snapshots` | `site:read` | read | — | Added, changed and removed nodes between two snapshots. |
|
|
116
116
|
| `preview_page` | `preview:create` | read | — | Render a page (or an article by entryId) to HTML as the site would show it, plus a preview link (signed, to the deployed site, or the `cloudhal dev` URL). |
|
|
117
|
-
| `publish` | `site:publish` | write (destructive) |
|
|
117
|
+
| `publish` | `site:publish` | write (destructive) | a person, except a low-risk article publish in `auto` | Snapshot the current state and make it live. |
|
|
118
118
|
| `rollback` | `site:rollback` | write (destructive) | always a person | Point production at an earlier snapshot (must be an ancestor of the live one). |
|
|
119
119
|
| `get_analytics` | `analytics:read` | read | — | How the site is doing over a range: page views, visits (entrances from other sites or typed in), unique visitors when the site counts them, the estimated cache-hit ratio (on Cloud… |
|
|
120
120
|
| `top_content` | `analytics:read` | read | — | The most viewed pages, articles and archives in a range, with their current title and path (renamed articles show their new ones; deleted ones read as gone) and the change of page… |
|
package/dist/src/asset-tools.js
CHANGED
|
@@ -156,6 +156,34 @@ function cleanName(name ) {
|
|
|
156
156
|
return clean || undefined;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/** `upload_asset`'s file name: the original name, whose extension must match the content. */
|
|
160
|
+
const UPLOAD_FILENAME = str(
|
|
161
|
+
"Original file name, e.g. ferries.jpg (its extension must match the content)",
|
|
162
|
+
{ minLength: 1, maxLength: 255, pattern: "^[^/\\\\\\u0000-\\u001f\\u007f]+$" },
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
/** #250 B: the SHA-256 the agent expects of the decoded bytes, so a damaged copy is refused. */
|
|
166
|
+
const UPLOAD_SHA256 = str(
|
|
167
|
+
"The file's SHA-256 (64 hex digits). When given, the decoded bytes must match it, or nothing is stored",
|
|
168
|
+
{ pattern: "^[0-9a-fA-F]{64}$" },
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Refuses bytes whose SHA-256 is not the one the caller expected: base64 copied into a tool call
|
|
173
|
+
* can lose or change a character and still decode, and the media pipeline would accept the result.
|
|
174
|
+
*/
|
|
175
|
+
async function expectChecksum(bytes , expected ) {
|
|
176
|
+
if (!expected) return;
|
|
177
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes );
|
|
178
|
+
const actual = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
179
|
+
if (actual === expected.toLowerCase()) return;
|
|
180
|
+
throw new ToolError(
|
|
181
|
+
"invalid",
|
|
182
|
+
`the decoded data's SHA-256 is ${actual}, not the expected ${expected.toLowerCase()}: the base64 was changed or cut on the way. Nothing was stored; send the file's data again.`,
|
|
183
|
+
{ reason: "checksum_mismatch", expected: expected.toLowerCase(), actual },
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
159
187
|
function decodeBase64(data ) {
|
|
160
188
|
const clean = data.replace(/\s+/g, "");
|
|
161
189
|
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean) || clean.length % 4 === 1)
|
|
@@ -364,22 +392,16 @@ export function assetTools() {
|
|
|
364
392
|
{
|
|
365
393
|
name: "upload_asset",
|
|
366
394
|
title: "Upload media",
|
|
367
|
-
description: `Add a file to the site's media library from base64 data (at most ${MEDIA_LIMITS.uploadAsset / MB} MB decoded). The server checks the type from the bytes (JPEG, PNG, WebP, AVIF, GIF, MP4, WebM, MP3, M4A, Ogg, WAV, PDF, CSV, TSV, JSON, NDJSON, Parquet; no SVG), strips photo metadata such as GPS, and returns the asset. Images need alt text or decorative: true. Uploading the same bytes again returns the existing asset (existing: true). Use it in an article with coverImage: {assetId} or in markdown as . Nothing is public until the site is published.`,
|
|
395
|
+
description: `Add a file to the site's media library from base64 data (at most ${MEDIA_LIMITS.uploadAsset / MB} MB decoded). The server checks the type from the bytes (JPEG, PNG, WebP, AVIF, GIF, MP4, WebM, MP3, M4A, Ogg, WAV, PDF, CSV, TSV, JSON, NDJSON, Parquet; no SVG), strips photo metadata such as GPS, and returns the asset. Images need alt text or decorative: true. Uploading the same bytes again returns the existing asset (existing: true). Pass sha256 (of the file) to have the decoded bytes checked: a mismatch stores nothing. Use it in an article with coverImage: {assetId} or in markdown as . Nothing is public until the site is published.`,
|
|
368
396
|
inputSchema: obj(
|
|
369
397
|
{
|
|
370
398
|
siteId: id,
|
|
371
|
-
filename:
|
|
372
|
-
"Original file name, e.g. ferries.jpg (its extension must match the content)",
|
|
373
|
-
{
|
|
374
|
-
minLength: 1,
|
|
375
|
-
maxLength: 255,
|
|
376
|
-
pattern: "^[^/\\\\\\u0000-\\u001f\\u007f]+$",
|
|
377
|
-
},
|
|
378
|
-
),
|
|
399
|
+
filename: UPLOAD_FILENAME,
|
|
379
400
|
data: str("The file's bytes, base64", {
|
|
380
401
|
minLength: 4,
|
|
381
402
|
maxLength: Math.ceil((MEDIA_LIMITS.uploadAsset * 4) / 3) + 8,
|
|
382
403
|
}),
|
|
404
|
+
sha256: UPLOAD_SHA256,
|
|
383
405
|
mediaType: str(
|
|
384
406
|
"What you believe the type is, e.g. image/png (checked against the bytes)",
|
|
385
407
|
{
|
|
@@ -409,6 +431,7 @@ export function assetTools() {
|
|
|
409
431
|
},
|
|
410
432
|
precheck: async (a, ctx) => {
|
|
411
433
|
const bytes = decodeBase64(a.data );
|
|
434
|
+
await expectChecksum(bytes, a.sha256 );
|
|
412
435
|
if (bytes.byteLength > MEDIA_LIMITS.uploadAsset)
|
|
413
436
|
throw new ToolError(
|
|
414
437
|
"too_large",
|
|
@@ -82,7 +82,8 @@ const listSnapshotsTool = {
|
|
|
82
82
|
const diffSnapshotsTool = {
|
|
83
83
|
name: "diff_snapshots",
|
|
84
84
|
title: "Diff snapshots",
|
|
85
|
-
description:
|
|
85
|
+
description:
|
|
86
|
+
"Added, changed and removed nodes between two snapshots. The site node is listed only when its settings differ: the live pointer, rev and updatedAt that every publish rewrites are not a change (the same rule as publish's approval).",
|
|
86
87
|
inputSchema: obj({ siteId: id, fromSnapshotId: id, toSnapshotId: id }, [
|
|
87
88
|
"siteId",
|
|
88
89
|
"fromSnapshotId",
|
|
@@ -144,7 +145,8 @@ const previewPageTool = {
|
|
|
144
145
|
const publishTool = {
|
|
145
146
|
name: "publish",
|
|
146
147
|
title: "Publish site",
|
|
147
|
-
description:
|
|
148
|
+
description:
|
|
149
|
+
"Snapshot the current state and make it live. Waits for a person, except a low-risk article publish in `auto` mode (only articles added or edited, nothing removed, within the mode's limits; get_mode shows your mode).",
|
|
148
150
|
inputSchema: obj({ siteId: id, label: str("Label for the published snapshot") }, ["siteId"]),
|
|
149
151
|
outputSchema: obj({ site: SITE, snapshot: SNAPSHOT }, ["site", "snapshot"]),
|
|
150
152
|
annotations: {
|
package/dist/src/render/cdp.js
CHANGED
|
@@ -107,6 +107,12 @@ export async function cdpSession(
|
|
|
107
107
|
const s = (method , params = {}) =>
|
|
108
108
|
cdp.send(method, params, sessionId);
|
|
109
109
|
await s("Page.enable");
|
|
110
|
+
// #249: a tab that is not in front (a browser's own first page, another render in the same
|
|
111
|
+
// browser) is hidden, and Chrome throttles a hidden page's frames: IntersectionObserver
|
|
112
|
+
// runs late or not at all (a scroll story keeps its first step) and screenshots wait for
|
|
113
|
+
// frames. Each render tab is focused and in front, whatever else the browser has open.
|
|
114
|
+
await s("Emulation.setFocusEmulationEnabled", { enabled: true });
|
|
115
|
+
await s("Page.bringToFront");
|
|
110
116
|
await s("Emulation.setDeviceMetricsOverride", {
|
|
111
117
|
width: viewport.width,
|
|
112
118
|
height: viewport.height,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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,24 +56,24 @@
|
|
|
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.
|
|
66
|
-
"@modelcontextprotocol/server": "2.
|
|
67
|
-
"@cloudhal/schedules": "0.
|
|
59
|
+
"@cloudhal/analytics": "0.11.0",
|
|
60
|
+
"@cloudhal/agent-runtime": "0.11.0",
|
|
61
|
+
"@cloudhal/astro-renderer": "0.11.0",
|
|
62
|
+
"@cloudhal/comments": "0.11.0",
|
|
63
|
+
"@cloudhal/core-contracts": "0.11.0",
|
|
64
|
+
"@cloudhal/core-ts": "0.11.0",
|
|
65
|
+
"@cloudhal/storage": "0.11.0",
|
|
66
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
67
|
+
"@cloudhal/schedules": "0.11.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@cloudflare/workers-types": "^5.20261007.1",
|
|
71
71
|
"@modelcontextprotocol/client": "2.4.0",
|
|
72
72
|
"@types/node": "^26.6.5",
|
|
73
|
-
"better-sqlite3": "13.0
|
|
73
|
+
"better-sqlite3": "13.2.0",
|
|
74
74
|
"happy-dom": "^21.0.4",
|
|
75
75
|
"typescript": "7.0.2",
|
|
76
|
-
"vitest": "5.1.
|
|
76
|
+
"vitest": "5.1.2"
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|
|
79
79
|
"node": ">=24"
|