@cloudhal/mcp-server 0.11.0 → 0.12.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.
Files changed (38) hide show
  1. package/README.md +4 -1
  2. package/dist/src/asset-tools.d.ts +54 -2
  3. package/dist/src/asset-tools.js +20 -14
  4. package/dist/src/body-tools.d.ts +6 -0
  5. package/dist/src/body-tools.js +22 -5
  6. package/dist/src/changes.d.ts +8 -0
  7. package/dist/src/changes.js +14 -1
  8. package/dist/src/collection-listings.d.ts +2 -0
  9. package/dist/src/collection-listings.js +8 -2
  10. package/dist/src/common.d.ts +25 -1
  11. package/dist/src/common.js +26 -1
  12. package/dist/src/elevation-tools.js +13 -8
  13. package/dist/src/entry-list.d.ts +3 -2
  14. package/dist/src/entry-list.js +4 -3
  15. package/dist/src/field-hints.js +4 -0
  16. package/dist/src/http.d.ts +10 -1
  17. package/dist/src/http.js +25 -3
  18. package/dist/src/pending-changes.d.ts +4 -0
  19. package/dist/src/pending-changes.js +159 -0
  20. package/dist/src/publish-gate.d.ts +31 -0
  21. package/dist/src/publish-gate.js +115 -0
  22. package/dist/src/publish-tools.d.ts +4 -8
  23. package/dist/src/publish-tools.js +8 -34
  24. package/dist/src/render-tools.js +21 -1
  25. package/dist/src/section-queries.js +7 -1
  26. package/dist/src/server-call.js +1 -0
  27. package/dist/src/server-instructions.d.ts +3 -1
  28. package/dist/src/server-instructions.js +6 -2
  29. package/dist/src/server.d.ts +3 -1
  30. package/dist/src/server.js +7 -2
  31. package/dist/src/structured-data-tools.js +3 -1
  32. package/dist/src/tools.d.ts +1 -1
  33. package/dist/src/tools.js +12 -55
  34. package/dist/src/upload-hints.d.ts +13 -0
  35. package/dist/src/upload-hints.js +116 -0
  36. package/dist/src/upload-tools.d.ts +12 -0
  37. package/dist/src/upload-tools.js +328 -0
  38. package/package.json +10 -10
package/dist/src/tools.js CHANGED
@@ -14,14 +14,7 @@
14
14
 
15
15
 
16
16
 
17
- import {
18
-
19
- checkAutoPublish,
20
- describeAutoCheck,
21
- describeOwnOnly,
22
- effectiveMode,
23
- } from "@cloudhal/agent-runtime";
24
- import { expiringEntries, } from "@cloudhal/core-ts";
17
+ import { describeAutoCheck, effectiveMode } from "@cloudhal/agent-runtime";
25
18
  import {
26
19
  afterRunCall,
27
20
  checkRunBudget,
@@ -44,7 +37,8 @@ import { menuTools } from "./menu-tools.js";
44
37
  import { pageRemovalTools, siteAndPageTools } from "./page-tools.js";
45
38
  import { permalinkTools } from "./permalink-tools.js";
46
39
  import { previewDoc } from "./preview-doc.js";
47
- import { ownOnlyPublish, publishTools } from "./publish-tools.js";
40
+ import { autoPublishGate, ownOnlyGate } from "./publish-gate.js";
41
+ import { publishTools } from "./publish-tools.js";
48
42
  import { renderTools } from "./render-tools.js";
49
43
  import { scheduleTools } from "./schedule-tools.js";
50
44
  import { RUN_COUNTS, } from "./schedules.js";
@@ -53,6 +47,7 @@ import { searchTools } from "./search-tools.js";
53
47
  import { surfaceTools } from "./surface-tools.js";
54
48
  import { taxonomyTools } from "./taxonomy-tools.js";
55
49
  import { translationTools } from "./translation-tools.js";
50
+ import { uploadTools } from "./upload-tools.js";
56
51
 
57
52
  export {
58
53
 
@@ -68,7 +63,7 @@ export {
68
63
  toToolError,
69
64
  } from "./common.js";
70
65
  export { previewDoc } from "./preview-doc.js";
71
- export { ownOnlyPublish } from "./publish-tools.js";
66
+ export { ownOnlyPublish } from "./publish-gate.js";
72
67
  export { hoistDefs, relaxImageRefs } from "./schema-transforms.js";
73
68
 
74
69
  /**
@@ -102,6 +97,8 @@ export function defineTools(options = {}) {
102
97
  ...permalinkTools(),
103
98
  ...menuTools(),
104
99
  ...assetTools(),
100
+ // RFC-0048: agents' signed upload links.
101
+ ...uploadTools(),
105
102
  ...publishTools(),
106
103
  // RFC-0006 §9.3: read-only analytics (`analytics:read`).
107
104
  ...analyticsTools(),
@@ -141,19 +138,6 @@ export function toolPolicies(tools ) {
141
138
 
142
139
 
143
140
 
144
- /**
145
- * What the store knows about a pending publish for the `auto`-mode check: new images riding with
146
- * articles (RFC-0004 §6.3), corrections (RFC-0019 §2.4) and derived gates added or moved earlier
147
- * on live articles (RFC-0042 §3.5).
148
- */
149
- async function autoPublishFacts(store , siteId , pending ) {
150
- return {
151
- ridingAssets: await store.ridingAssets(siteId, pending),
152
- corrections: await store.correctingEntries(siteId, pending),
153
- expiries: await expiringEntries(store, siteId, pending),
154
- };
155
- }
156
-
157
141
  /**
158
142
  * Policy → audit → handler. Transports call this; it is the only path a tool runs through.
159
143
  * `confirmed` is set by the transport once the human said yes (MRTR response or confirm token);
@@ -185,20 +169,8 @@ export async function runTool(
185
169
  policy: deps.policy,
186
170
  ...(deps.audit ? { audit: deps.audit } : {}),
187
171
  };
188
- // Own-only publish (I10): an Author's (or their agent's) publish that carries someone else's
189
- // work, or structure, waits for someone whose role allows it (cause `role`).
190
- if (limit?.target === "changeset" && !deps.approved && siteId && decision.kind !== "deny") {
191
- const check = await ownOnlyPublish(ctx, siteId).catch(() => undefined);
192
- if (!check?.ownOnly) {
193
- const why = check ? describeOwnOnly(check) : "the site could not be read";
194
- decision = {
195
- kind: "approval-required",
196
- reason: `your role publishes only your own work, but ${why}`,
197
- cause: "role",
198
- limit,
199
- };
200
- }
201
- }
172
+ // Own-only publish (I10), shared with `pending_changes` (publish-gate.ts).
173
+ decision = await ownOnlyGate(ctx, siteId, decision, deps.approved);
202
174
  const audited = def.auditArgs ? def.auditArgs(args) : args;
203
175
  const base = {
204
176
  at: new Date().toISOString(),
@@ -256,24 +228,9 @@ export async function runTool(
256
228
  }
257
229
  }
258
230
  // `auto` mode: a publish that only adds or edits a few articles goes live without a person.
259
- let autoCheck ;
260
- let autoNote ;
261
- if (
262
- decision.kind === "approval-required" &&
263
- decision.autoApprove === "low-risk-publish" &&
264
- siteId
265
- ) {
266
- const pending = await ctx.store.pendingChanges(siteId);
267
- // New raster images used only by the articles in this publish ride along (RFC-0004 §6.3).
268
- autoCheck = checkAutoPublish(pending, await autoPublishFacts(ctx.store, siteId, pending));
269
- if (autoCheck.lowRisk)
270
- autoNote = `auto mode: published without approval (${describeAutoCheck(autoCheck)})`;
271
- else
272
- decision = {
273
- ...decision,
274
- reason: `auto mode waits for a person: ${describeAutoCheck(autoCheck)}`,
275
- };
276
- }
231
+ const gate = await autoPublishGate(ctx, siteId, decision);
232
+ decision = gate.decision;
233
+ const { autoCheck, autoNote } = gate;
277
234
  const checked = autoCheck ? { autoCheck } : {};
278
235
  // RFC-0008 §10.4: release tools file their own request bound to `rl1:` (or take `auto`'s
279
236
  // low-risk path), so their handler runs with the waiting decision instead of the generic gate.
@@ -0,0 +1,13 @@
1
+ import { ToolError } from "./common.js";
2
+ export declare const HASH_COMMANDS = "shasum -a 256 <file> on macOS, sha256sum <file> on Linux, Get-FileHash -Algorithm SHA256 <file> in PowerShell";
3
+ /** What a hint may name: the server's cap and the types agents may upload. */
4
+ export interface UploadHintInfo {
5
+ readonly cap: number;
6
+ readonly types: readonly string[];
7
+ }
8
+ /** The answer when this server cannot hand out links (stdio, no shared secret, turned off). */
9
+ export declare function unsupported(): ToolError;
10
+ /** Maps a refusal of `create_upload`'s store side; never returns. */
11
+ export declare function createRefusal(e: unknown, info: UploadHintInfo): never;
12
+ /** Maps a refusal of `complete_upload`; never returns. */
13
+ export declare function completeRefusal(e: unknown): never;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * RFC-0048 §5.3: how `create_upload` and `complete_upload` refuse. The store's invariant codes are
3
+ * answered with existing tool codes and a `details.reason`, each with the agent's next step (next
4
+ * to `field-hints.ts`, one responsibility per module). Anything else goes to `mapError`.
5
+ */
6
+ import { InvariantError, NotFoundError } from "@cloudhal/core-ts";
7
+ import { formatBytes } from "@cloudhal/core-ts/media";
8
+ import { mapError, ToolError, } from "./common.js";
9
+
10
+ export const HASH_COMMANDS =
11
+ "shasum -a 256 <file> on macOS, sha256sum <file> on Linux, Get-FileHash -Algorithm SHA256 <file> in PowerShell";
12
+
13
+ /** What a hint may name: the server's cap and the types agents may upload. */
14
+
15
+
16
+
17
+
18
+
19
+ const refuse = (
20
+ code ,
21
+ reason ,
22
+ message ,
23
+ details = {},
24
+ ) => new ToolError(code, message, { ...details, reason });
25
+
26
+ /** The answer when this server cannot hand out links (stdio, no shared secret, turned off). */
27
+ export function unsupported() {
28
+ return refuse(
29
+ "invalid",
30
+ "signed_upload_unsupported",
31
+ "this server has no upload links (stdio, no shared signing secret, or turned off by the operator): use upload_asset with base64 (at most 4 MB)",
32
+ );
33
+ }
34
+
35
+ /** Maps a refusal of `create_upload`'s store side; never returns. */
36
+ export function createRefusal(e , info ) {
37
+ if (e instanceof InvariantError) {
38
+ const d = e.details;
39
+ switch (e.code) {
40
+ case "too_large":
41
+ throw refuse(
42
+ "too_large",
43
+ "upload_cap",
44
+ `${e.message}. This server takes agent uploads up to ${formatBytes(info.cap)}; ask a person to upload it in Studio, or use fetch_asset_url for a public file`,
45
+ d,
46
+ );
47
+ case "unsupported_type":
48
+ throw refuse(
49
+ "invalid",
50
+ "unsupported_type",
51
+ `${e.message}. Agents may upload ${info.types.join(", ")}; SVG and HTML are refused`,
52
+ d,
53
+ );
54
+ case "invalid_asset":
55
+ throw refuse(
56
+ "invalid",
57
+ "checksum_required",
58
+ `${e.message}. Compute the file's SHA-256 (${HASH_COMMANDS}) and pass it as sha256`,
59
+ d,
60
+ );
61
+ case "too_many_uploads":
62
+ throw refuse(
63
+ "denied",
64
+ "too_many_uploads",
65
+ `${e.message}. Finish open uploads (PUT, then complete_upload) or let them expire: links that were never used expire 10 minutes after create_upload`,
66
+ d,
67
+ );
68
+ case "quota_exceeded":
69
+ throw refuse("denied", "quota_exceeded", e.message, d);
70
+ }
71
+ }
72
+ mapError(e);
73
+ }
74
+
75
+ /** Maps a refusal of `complete_upload`; never returns. */
76
+ export function completeRefusal(e ) {
77
+ if (e instanceof NotFoundError && e.kind === "upload")
78
+ throw refuse(
79
+ "not_found",
80
+ "upload_not_found",
81
+ "no such upload for this key; call create_upload",
82
+ );
83
+ if (e instanceof InvariantError) {
84
+ const d = e.details;
85
+ const attempts = typeof d.attempts === "number" ? d.attempts : 0;
86
+ if (e.code === "upload_pending" && attempts >= 3)
87
+ throw refuse(
88
+ "invalid",
89
+ "too_many_attempts",
90
+ "three PUTs of this upload were refused; call create_upload again",
91
+ d,
92
+ );
93
+ if (e.code === "upload_pending" && attempts > 0)
94
+ throw refuse(
95
+ "conflict",
96
+ "upload_failed",
97
+ `the last PUT was refused (wrong size, type or SHA-256); PUT the exact file again before ${String(d.expiresAt)} (${attempts} of 3 attempts used), or call create_upload again`,
98
+ d,
99
+ );
100
+ if (e.code === "upload_pending")
101
+ throw refuse(
102
+ "conflict",
103
+ "upload_pending",
104
+ `PUT the file to the url from create_upload first (the curl line), then call complete_upload again; start before ${String(d.expiresAt)}`,
105
+ d,
106
+ );
107
+ if (e.code === "upload_expired")
108
+ throw refuse(
109
+ "invalid",
110
+ "upload_expired",
111
+ `the upload expired before the bytes arrived (start the PUT by ${String(d.expiresAt)}) or before it was completed (by ${String(d.completeBy)}); call create_upload again`,
112
+ d,
113
+ );
114
+ }
115
+ mapError(e);
116
+ }
@@ -0,0 +1,12 @@
1
+ import { type JsonSchema, type ToolContext, type ToolDefinition } from "./common.js";
2
+ /** RFC-0048 §2.4: 10 minutes to start the PUT, 60 to complete. */
3
+ export declare const LINK_SECONDS = 600;
4
+ /** What `get_mode` reports (`uploads`) and `create_upload` obeys. */
5
+ export declare function uploadCapability(ctx: Pick<ToolContext, "media" | "uploads">): {
6
+ signedUrl: boolean;
7
+ maxBytes: number;
8
+ linkSeconds: number;
9
+ };
10
+ /** `get_mode`'s `uploads` property. */
11
+ export declare const UPLOADS_MODE_SCHEMA: JsonSchema;
12
+ export declare function uploadTools(): ToolDefinition[];
@@ -0,0 +1,328 @@
1
+ /**
2
+ * RFC-0048: agents' signed upload links. `create_upload` declares one file (size, type, SHA-256 and
3
+ * the asset's text) under `upload_asset`'s scope, mode, approval and limits, and returns a
4
+ * short-lived PUT link; the agent's shell sends the bytes; `complete_upload` creates the asset. The
5
+ * bytes never pass through the model. Only HTTP `/mcp` hands out links (`uploads.signedUrl`); the
6
+ * tools are always listed (ADR-0004) and say so where it is off.
7
+ */
8
+
9
+ import { InvariantError, NotFoundError } from "@cloudhal/core-ts";
10
+ import { formatBytes, MEDIA_LIMITS, MEDIA_TYPES } from "@cloudhal/core-ts/media";
11
+ import {
12
+ ASSET_OUT,
13
+ cleanName,
14
+ dailyLimit,
15
+ FETCH_TYPES,
16
+ MB,
17
+ report,
18
+ TEXT_FIELDS,
19
+ texts,
20
+ url,
21
+ WRITE,
22
+ } from "./asset-tools.js";
23
+ import {
24
+ autoSnapshot,
25
+ id,
26
+
27
+ quote,
28
+ requireSite,
29
+ SLUG_PATTERN,
30
+ str,
31
+
32
+
33
+ ToolError,
34
+ } from "./common.js";
35
+ import { completeRefusal, createRefusal, HASH_COMMANDS, unsupported } from "./upload-hints.js";
36
+
37
+ /** RFC-0048 §2.4: 10 minutes to start the PUT, 60 to complete. */
38
+ export const LINK_SECONDS = 600;
39
+ const COMPLETE_SECONDS = 3600;
40
+ /** RFC-0048 §3.3: open uploads per key and per site. */
41
+ const OPEN_PER_KEY = 10;
42
+ const OPEN_PER_SITE = 50;
43
+ const DEFAULT_CAP = 25 * MB;
44
+
45
+ /** What `get_mode` reports (`uploads`) and `create_upload` obeys. */
46
+ export function uploadCapability(ctx )
47
+
48
+
49
+
50
+ {
51
+ const cap = Math.min(ctx.media?.agentUploadBytes ?? DEFAULT_CAP, MEDIA_LIMITS.upload);
52
+ const signedUrl = ctx.uploads?.verifiable === true && ctx.media?.agentUploads !== false;
53
+ return { signedUrl, maxBytes: cap, linkSeconds: LINK_SECONDS };
54
+ }
55
+
56
+ /** `get_mode`'s `uploads` property. */
57
+ export const UPLOADS_MODE_SCHEMA = {
58
+ type: "object",
59
+ additionalProperties: false,
60
+ description:
61
+ "RFC-0048: whether this server hands out upload links (create_upload), the cap per file and how long a link lasts to start the PUT.",
62
+ properties: {
63
+ signedUrl: { type: "boolean" },
64
+ maxBytes: { type: "integer" },
65
+ linkSeconds: { type: "integer" },
66
+ },
67
+ required: ["signedUrl", "maxBytes", "linkSeconds"],
68
+ };
69
+
70
+ const nullable = (schema ) => ({
71
+ ...schema,
72
+ type: [schema.type , "null"],
73
+ });
74
+ const nullOrString = (description ) => ({
75
+ type: ["string", "null"],
76
+ description,
77
+ });
78
+
79
+ /** §5.1: the declared file, with every optional value also accepted as `null`. */
80
+ const CREATE_IN = {
81
+ type: "object",
82
+ additionalProperties: false,
83
+ properties: {
84
+ siteId: id,
85
+ filename: str("The file's name, e.g. ferries.webp (its extension must match the content)", {
86
+ minLength: 1,
87
+ maxLength: 255,
88
+ pattern: "^[^/\\\\\\u0000-\\u001f\\u007f]+$",
89
+ }),
90
+ bytes: {
91
+ type: "integer",
92
+ minimum: 1,
93
+ maximum: MEDIA_LIMITS.upload,
94
+ description: "The file's exact size in bytes (the server's cap may be lower: get_mode)",
95
+ },
96
+ mediaType: { type: "string", enum: [...FETCH_TYPES], description: "The file's type" },
97
+ sha256: str(`The file's SHA-256, 64 hex digits (${HASH_COMMANDS})`, {
98
+ pattern: "^[0-9a-fA-F]{64}$",
99
+ }),
100
+ alt: nullable(TEXT_FIELDS.alt ),
101
+ decorative: nullable(TEXT_FIELDS.decorative ),
102
+ title: nullable(TEXT_FIELDS.title ),
103
+ caption: nullable(TEXT_FIELDS.caption ),
104
+ credit: nullable(TEXT_FIELDS.credit ),
105
+ license: { anyOf: [TEXT_FIELDS.license , { type: "null" }] },
106
+ locale: nullable(TEXT_FIELDS.locale ),
107
+ slug: nullable(
108
+ str("File name in the URL, without extension", { pattern: SLUG_PATTERN, maxLength: 96 }),
109
+ ),
110
+ },
111
+ required: ["siteId", "filename", "bytes", "mediaType", "sha256"],
112
+ };
113
+
114
+ /** §5.1: every key always present, `null` where it does not apply (the strict profile). */
115
+ const CREATE_OUT = {
116
+ type: "object",
117
+ additionalProperties: false,
118
+ properties: {
119
+ status: { type: "string", enum: ["upload", "existing"] },
120
+ uploadId: nullOrString("Pass it to complete_upload after the PUT"),
121
+ url: nullOrString("PUT the file's bytes here (it is the credential: do not share it)"),
122
+ method: { type: ["string", "null"], enum: ["PUT", null] },
123
+ headers: {
124
+ type: ["object", "null"],
125
+ additionalProperties: false,
126
+ properties: { "content-type": { type: "string" } },
127
+ required: ["content-type"],
128
+ },
129
+ expiresAt: nullOrString("Start the PUT before this time (UTC)"),
130
+ completeBy: nullOrString("Call complete_upload before this time (UTC)"),
131
+ curl: nullOrString("The PUT as a curl command; replace the file name with its path"),
132
+ asset: {
133
+ type: ["object", "null"],
134
+ description: 'status "existing": the asset that already holds these bytes',
135
+ },
136
+ },
137
+ required: [
138
+ "status",
139
+ "uploadId",
140
+ "url",
141
+ "method",
142
+ "headers",
143
+ "expiresAt",
144
+ "completeBy",
145
+ "curl",
146
+ "asset",
147
+ ],
148
+ };
149
+
150
+ const present = (a ) =>
151
+ Object.fromEntries(Object.entries(a).filter(([, v]) => v !== null));
152
+
153
+ /** A single-quoted shell word. */
154
+ const shellWord = (text ) => `'${text.replaceAll("'", "'\\''")}'`;
155
+
156
+ function isImageType(mediaType ) {
157
+ return typeof mediaType === "string" && MEDIA_TYPES[mediaType]?.kind === "image";
158
+ }
159
+
160
+ /** `create_upload` after its precheck: the existing asset, or a new row and its signed link. */
161
+ async function openLink(raw , ctx ) {
162
+ const a = present(raw);
163
+ const cap = uploadCapability(ctx);
164
+ const links = ctx.uploads;
165
+ if (!cap.signedUrl || !links) throw unsupported();
166
+ const site = await requireSite(ctx, a.siteId );
167
+ const sha256 = (a.sha256 ).toLowerCase();
168
+ const hints = { cap: cap.maxBytes, types: FETCH_TYPES };
169
+ let existing ;
170
+ try {
171
+ existing = await ctx.store.assetForUploadedContent(site.id, sha256);
172
+ } catch (e) {
173
+ createRefusal(e, hints);
174
+ }
175
+ const none = {
176
+ uploadId: null,
177
+ url: null,
178
+ method: null,
179
+ headers: null,
180
+ expiresAt: null,
181
+ completeBy: null,
182
+ curl: null,
183
+ };
184
+ if (existing) return { status: "existing", ...none, asset: existing };
185
+ const filename = cleanName(a.filename );
186
+ try {
187
+ const upload = await ctx.store.uploads.open(
188
+ site.id,
189
+ ctx.principal.actor,
190
+ {
191
+ bytes: a.bytes ,
192
+ mediaType: a.mediaType ,
193
+ sha256,
194
+ filename,
195
+ fields: {
196
+ ...texts(site, a),
197
+ ...(a.license ? { license: a.license } : {}),
198
+ ...(a.slug ? { slug: a.slug } : {}),
199
+ },
200
+ },
201
+ {
202
+ ttlMs: LINK_SECONDS * 1000,
203
+ completeMs: COMPLETE_SECONDS * 1000,
204
+ maxOpenPerActor: OPEN_PER_KEY,
205
+ maxOpenPerSite: OPEN_PER_SITE,
206
+ maxBytes: cap.maxBytes,
207
+ now: ctx.now?.(),
208
+ },
209
+ );
210
+ const link = `${links.origin}${await links.link(upload)}`;
211
+ // The audit row's effect names the upload, never the link (RFC-0048 §3.2).
212
+ ctx.report?.({
213
+ upload: { id: upload.id, bytes: upload.bytes, sha256, mediaType: upload.mediaType },
214
+ });
215
+ return {
216
+ status: "upload",
217
+ uploadId: upload.id,
218
+ url: link,
219
+ method: "PUT",
220
+ headers: { "content-type": upload.mediaType },
221
+ expiresAt: upload.expiresAt,
222
+ completeBy: upload.completeBy,
223
+ curl: `curl --fail-with-body -X PUT -H ${shellWord(`content-type: ${upload.mediaType}`)} --upload-file ${shellWord(filename ?? "file")} ${shellWord(link)}`,
224
+ asset: null,
225
+ };
226
+ } catch (e) {
227
+ createRefusal(e, hints);
228
+ }
229
+ }
230
+
231
+ export function uploadTools() {
232
+ return [
233
+ {
234
+ name: "create_upload",
235
+ title: "Create an upload link",
236
+ description: `Get a short-lived link to PUT one file from your machine into the site's media library, without sending its bytes through this conversation (for files on disk when you have a shell; up to the cap in get_mode.uploads, ${DEFAULT_CAP / MB} MB by default). Declare the file's exact size, type and SHA-256 (${HASH_COMMANDS}); then run the returned curl command (or PUT the bytes with that Content-Type and Content-Length) within ${LINK_SECONDS / 60} minutes, and call complete_upload with the uploadId. Only that exact file can be sent with the link, once. Images need alt or decorative: true. Bytes already in the library answer status "existing" with the asset, and need no upload. Without a shell, or for small files, use upload_asset. Nothing is public until the site is published.`,
237
+ inputSchema: CREATE_IN,
238
+ outputSchema: CREATE_OUT,
239
+ annotations: WRITE,
240
+ scopes: ["asset:upload"],
241
+ approvalPrompt: async (a, ctx) => {
242
+ const site = await ctx.store.getSite(a.siteId );
243
+ const name = (a.alt ?? a.title ?? a.filename) ;
244
+ const type = MEDIA_TYPES[a.mediaType ]?.label ?? (a.mediaType );
245
+ const sha = String(a.sha256).toLowerCase().slice(0, 12);
246
+ return `Add media "${quote(name)}" (${quote(a.filename , 80)}, ${formatBytes(a.bytes )}, ${type}, sha256 ${sha}…) to "${quote(site?.name ?? (a.siteId ))}"? It becomes public only when the site is published.`;
247
+ },
248
+ precheck: async (a, ctx) => {
249
+ const cap = uploadCapability(ctx);
250
+ if (!cap.signedUrl) throw unsupported();
251
+ if (!FETCH_TYPES.includes(a.mediaType ))
252
+ createRefusal(
253
+ new InvariantError(
254
+ "unsupported_type",
255
+ `${String(a.mediaType)} is not accepted from agents`,
256
+ ),
257
+ { cap: cap.maxBytes, types: FETCH_TYPES },
258
+ );
259
+ if ((a.bytes ) > cap.maxBytes)
260
+ createRefusal(
261
+ new InvariantError(
262
+ "too_large",
263
+ `this file is ${formatBytes(a.bytes )}; upload links take at most ${formatBytes(cap.maxBytes)}`,
264
+ { bytes: a.bytes, limit: cap.maxBytes },
265
+ ),
266
+ { cap: cap.maxBytes, types: FETCH_TYPES },
267
+ );
268
+ if (
269
+ isImageType(a.mediaType) &&
270
+ !(typeof a.alt === "string" && a.alt.trim()) &&
271
+ a.decorative !== true
272
+ )
273
+ throw new ToolError(
274
+ "invalid",
275
+ "images need alt text (what the image shows, for screen readers) or decorative: true",
276
+ );
277
+ await dailyLimit(ctx, a.bytes );
278
+ },
279
+ handler: (a, ctx) => openLink(a, ctx),
280
+ },
281
+ {
282
+ name: "complete_upload",
283
+ title: "Complete an upload",
284
+ description:
285
+ "Turn an upload you sent to a create_upload link into an asset of the site's media library, with the alt text and fields given to create_upload; it answers as upload_asset does. Call it after the PUT succeeded. It needs no second approval (create_upload's covered the file), and calling it again returns the same asset.",
286
+ inputSchema: {
287
+ type: "object",
288
+ additionalProperties: false,
289
+ properties: { siteId: id, uploadId: id },
290
+ required: ["siteId", "uploadId"],
291
+ },
292
+ outputSchema: ASSET_OUT,
293
+ annotations: { ...WRITE, idempotentHint: true },
294
+ scopes: ["asset:upload"],
295
+ // Refused in `plan`, free in `manual`: the approval at create_upload bound this exact file
296
+ // (RFC-0048 §3.1, decision 8). The key's status, scopes and mode are checked again here.
297
+ classify: () => "advisory",
298
+ handler: async (a, ctx) => {
299
+ const site = await requireSite(ctx, a.siteId );
300
+ const upload = await ctx.store.uploads.get(a.uploadId );
301
+ if (!upload || upload.siteId !== site.id)
302
+ completeRefusal(new NotFoundError("upload", a.uploadId ));
303
+ let done ;
304
+ try {
305
+ done = await ctx.store.uploads.complete(upload.id, ctx.principal.actor, ctx.now?.());
306
+ } catch (e) {
307
+ completeRefusal(e);
308
+ }
309
+ report(ctx, done.asset, {
310
+ existing: done.existing,
311
+ uploadId: upload.id,
312
+ via: "signed-upload",
313
+ });
314
+ const usage =
315
+ (await ctx.store.assetUsage(site.id, [done.asset.id])).get(done.asset.id)?.total ?? 0;
316
+ return {
317
+ asset: done.asset,
318
+ existing: done.existing,
319
+ url: url(done.asset),
320
+ usage,
321
+ ...(done.existing
322
+ ? {}
323
+ : { snapshot: await autoSnapshot(ctx, site.id, "complete_upload") }),
324
+ };
325
+ },
326
+ },
327
+ ];
328
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/mcp-server",
3
- "version": "0.11.0",
3
+ "version": "0.12.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,20 +56,20 @@
56
56
  "README.md"
57
57
  ],
58
58
  "dependencies": {
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",
59
+ "@cloudhal/analytics": "0.12.0",
60
+ "@cloudhal/agent-runtime": "0.12.0",
61
+ "@cloudhal/astro-renderer": "0.12.0",
62
+ "@cloudhal/comments": "0.12.0",
63
+ "@cloudhal/core-contracts": "0.12.0",
64
+ "@cloudhal/core-ts": "0.12.0",
65
+ "@cloudhal/storage": "0.12.0",
66
66
  "@modelcontextprotocol/server": "2.4.0",
67
- "@cloudhal/schedules": "0.11.0"
67
+ "@cloudhal/schedules": "0.12.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@cloudflare/workers-types": "^5.20261007.1",
71
71
  "@modelcontextprotocol/client": "2.4.0",
72
- "@types/node": "^26.6.5",
72
+ "@types/node": "^26.6.11",
73
73
  "better-sqlite3": "13.2.0",
74
74
  "happy-dom": "^21.0.4",
75
75
  "typescript": "7.0.2",