@cloudhal/mcp-server 0.3.12 → 0.4.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Model Context Protocol surface of Cloudhal (spec 2026-07-28, `@modelcontextprotocol/server` 2.3). ADR-0004 and ADR-0011.
4
4
 
5
- **Tools (deterministic order):** `list_sites, get_site, list_pages, get_page, create_page, update_page, delete_page, list_entries, get_entry, create_entry, update_entry, add_correction, delete_entry`, then the taxonomy tools (RFC-0002 §6.2) `list_taxonomies, list_terms, resolve_terms, propose_term, update_term, rename_term, merge_terms, retire_term, set_term_parent, set_term_visibility, review_term, taxonomy_report, create_taxonomy, update_taxonomy, list_redirects, create_redirect, delete_redirect`, then `create_snapshot, list_snapshots, diff_snapshots, preview_page, publish, rollback`, the read-only analytics tools (RFC-0006 §9.3, scope `analytics:read`, every mode) `get_analytics, top_content, content_stats, broken_links`, then `get_mode, request_elevation`. Every tool has JSON Schema input/output (built from the contract schemas), honest annotations and `structuredContent`. Updates need the current `rev` (optimistic locking). Every mutation snapshots automatically (exactly one snapshot per call; governance snapshots carry `cloudhal.opId`).
5
+ **Tools:** every tool, with its scopes and whether a person approves it, is in the [tool reference](#tool-reference) below, generated from the definitions in `src/tools.ts` (`node scripts/mcp-tools-doc.ts`; CI fails when it is stale). The server lists them in a fixed order. Every tool has JSON Schema input/output (built from the contract schemas), honest annotations and `structuredContent`. Updates need the current `rev` (optimistic locking). Every mutation snapshots automatically (exactly one snapshot per call; governance snapshots carry `cloudhal.opId`).
6
6
 
7
7
  **Taxonomy (RFC-0002):** `create_entry` / `update_entry` take `terms: { [taxonomy]: { set?, add?, remove?, primary? } }` with values by id, slug, old slug, name, synonym or singular/plural, resolved by the store; an unknown or ambiguous value is an error with suggestions (`unknown_term`, `ambiguous_term`), never an implicit create. `tags` is a deprecated alias for `terms.tag.add`. `list_entries` takes the RFC §5 `filter`. Agents add terms only through `propose_term` (`allowNewTerms`: none → denied, propose → proposed, free → active; an existing match is returned). Structural tools (`site:write`) always wait for a person; their prompts list the articles touched and every redirect. Agents never redirect off-site, never reclaim slugs and never approve their own proposals (checked before anyone is asked). Store invariant errors map to stable codes (`required_term`, `too_many_terms`, …) with the next step in the text. Assignment deltas and governance results (`opId`, counts, redirects) go into the audit row's `input.effect`.
8
8
 
@@ -17,3 +17,117 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
17
17
  ```
18
18
 
19
19
  `tools.ts` is SDK-independent (`defineTools()`, `runTool()` = policy → audit → handler) and is what the tests exercise first; `test/e2e.test.ts` runs a real client ↔ server pair over the in-memory transport and proves the Sprint 5 exit criterion.
20
+
21
+ ## Tool reference
22
+
23
+ <!-- tools:start (generated by scripts/mcp-tools-doc.ts; do not edit) -->
24
+ **105 tools**, in the order the server lists them.
25
+
26
+ | Tool | Scopes | Kind | Approval | What it does |
27
+ |---|---|---|---|---|
28
+ | `list_sites` | `site:read` | read | — | Sites this principal can operate. |
29
+ | `get_site` | `site:read` | read | — | A site with its page order, locales, theme, published snapshot and per-collection settings (`collections.<key>.permalink`, e.g. /blog/{slug}; a collection without one lives at /&lt;c… |
30
+ | `list_pages` | `content:read` | read | — | Pages of a site in navigation order (all statuses). |
31
+ | `get_page` | `content:read` | read | — | One page with its sections and current revision (send `rev` back when updating). |
32
+ | `create_page` | `content:write` | write | by the key's mode | Create a draft page and append it to the site's navigation. |
33
+ | `update_page` | `content:write` | write | by the key's mode | Replace a page's title, path, sections or seo, or set its own motion level and chrome (RFC-0025: header default\|transparent\|hidden, footer default\|minimal\|hidden; null goes back t… |
34
+ | `get_catalog` | `content:read` | read | — | The components a page surface may use on this site (RFC-0020): Cloudhal's layout, content and interactive primitives plus the theme's block types, with their props, child rules, b… |
35
+ | `patch_draft` | `content:write` | write | by the key's mode | Build or change a page step by step with RFC 6902 JSON Patch operations on /title, /sections and /seo, e.g. {"op":"add","path":"/sections/-","value":{…a surface…}}. |
36
+ | `import_surface` | `content:write` | write | by the key's mode | Add (or replace) a page surface from another generative-UI format: `a2ui` takes A2UI v0.9 messages (createSurface, updateComponents, updateDataModel; basic catalog), `json-render`… |
37
+ | `export_surface` | `content:read` | read | — | A page's surface section in another generative-UI format: `a2ui` (A2UI v0.9 messages for the basic catalog, images as absolute URLs when the site has a primary domain) or `json-re`… |
38
+ | `delete_page` | `content:write` | write (destructive) | by the key's mode | Delete a page and remove it from navigation. |
39
+ | `list_entries` | `content:read` | read | — | Content entries, newest first. |
40
+ | `get_entry` | `content:read` | read | — | One content entry with its body and current revision. |
41
+ | `create_entry` | `content:write` | write | by the key's mode | Create a draft content entry (markdown body) in an existing collection (list_collections; a new one needs create_collection first), optionally filed under existing terms (`terms`;… |
42
+ | `update_entry` | `content:write` | write | by the key's mode | Update title, summary, body, slug, status (draft → review → published) or terms (`terms`: add, remove or set categories and tags by id, slug or name) of an entry. |
43
+ | `add_correction` | `content:write` | write | by the key's mode | Append a correction, clarification or update notice to an article (RFC-0019 §2) when a published story changed in substance. |
44
+ | `delete_entry` | `content:write` | write (destructive) | by the key's mode | Delete a content entry. |
45
+ | `list_translations` | `content:read` | read | — | Every language version of a page or entry (its translation group): locale, status, method (original, human, machine, machine-reviewed), whether it is stale (its source changed sin… |
46
+ | `list_stale_translations` | `content:read` | read | — | Translations whose source changed since they were made (or whose source is gone), optionally in one locale: the work queue for keeping languages in step. |
47
+ | `get_translation_source` | `content:read` | read | — | 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), th… |
48
+ | `save_translation` | `content:write` | write | by the key's mode | 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. |
49
+ | `search_site` | `content:read` | read | — | Find nodes by words instead of listing everything. |
50
+ | `get_theme_settings` | `content:read` | read | — | The theme's design settings (RFC-0017): their schema (colors as #rrggbb, enums, numbers; per-locale titles), the contrast rules colors must meet, and the site's current values. |
51
+ | `set_theme_settings` | `site:write` | write | always a person | Change the site's design settings (colors, type, spacing: get_theme_settings lists them). |
52
+ | `list_block_types` | `content:read` | read | — | The typed blocks this site can use (RFC-0015): callouts, buttons, video embeds, FAQs and the theme's own. |
53
+ | `get_body` | `content:read` | read | — | Read a markdown body (an article's, or a page's rich-text section) as blocks: each with its id, hash, type, markdown and who last changed it. |
54
+ | `edit_body` | `content:write` | write | depends on the call | Change a markdown body by block instead of rewriting it: replace a block, replace text inside one, insert, move or delete blocks, insert a typed block (insertBlock: a callout, a b… |
55
+ | `diff_node` | `content:read` | read | — | Compare one page or article between two versions: the fields that changed, and its body (or each rich-text section) block by block, with the words that changed inside edited block… |
56
+ | `get_design` | `site:read` | read | — | Read this first when you build or redesign pages (RFC-0021). |
57
+ | `get_design_tokens` | `site:read` | read | — | The site's design tokens as a W3C Design Tokens (DTCG 2025.10) file, for Figma (Tokens Studio), Style Dictionary or a designer: the color roles for light and dark, corner radii, s… |
58
+ | `set_design` | `site:write` | write | always a person | Replace the site's design rules (DESIGN.md, Markdown, at most 24,000 characters; null removes them). |
59
+ | `get_chrome` | `site:read` | read | — | The site's header, footer and brand (RFC-0025): what is set, what pages show (the defaults filled in), the form schemas with every allowed value, and the menu keys the header and… |
60
+ | `set_chrome` | `site:write` | write | always a person | Change the site's header and footer (get_chrome lists the fields and allowed values). |
61
+ | `set_brand` | `site:write` | write | always a person | Change the site's brand (get_chrome lists the fields): logo and logoDark as an image asset of the site (asset:&lt;id>, from list_assets or upload_asset; the site's name shows without… |
62
+ | `render_page` | `preview:create` | read | — | Look at a page's draft as people will see it: renders it in a real browser at desktop (1440), tablet (768) and phone (390) widths and returns screenshots plus automatic checks (si… |
63
+ | `list_taxonomies` | `site:read` | read | — | The site's taxonomies (e.g. category, tag) and their rules: `required` (review/published articles need a primary term), `maxPerEntry`, `allowNewTerms` (none: only people add terms… |
64
+ | `list_terms` | `content:read` | read | — | Terms of one taxonomy with names per locale, synonyms (altNames), old slugs (slugHistory), parent, status, visibility and usage (articles in total and published, last used). |
65
+ | `resolve_terms` | `content:read` | read | — | Which existing terms of a taxonomy the given ids, slugs, names or synonyms mean (the same rules as assigning `terms`: id → slug → old slug → name → synonym → singular/plural). |
66
+ | `propose_term` | `content:draft:own` | write | by the key's mode | Suggest a new term when no existing one fits (check list_terms / resolve_terms first). |
67
+ | `update_term` | `content:write` | write | by the key's mode | Change a term's text only: names, synonyms, archive intro (description) and SEO per locale, and its image. |
68
+ | `rename_term` | `site:write` | write | always a person | Change a term's slug (its archive URL). |
69
+ | `merge_terms` | `site:write` | write | always a person | Merge duplicate terms into one target term of the same taxonomy: every article is re-filed under the target (primary terms follow), the sources retire and their names and slugs be… |
70
+ | `retire_term` | `site:write` | write (destructive) | always a person | Retire a term: it is removed from every article, its sub-terms move up, and its archive redirects (301) to `redirectToId` (or, for categories, to its parent) — without a redirect… |
71
+ | `set_term_parent` | `site:write` | write | always a person | Move a term under another term of the same hierarchical taxonomy (null: to the top level). |
72
+ | `set_term_visibility` | `site:write` | write | always a person | Make a term public (archive, feed and sitemap entry; shown on articles) or internal (no public URL; themes and filters may still use it). |
73
+ | `review_term` | `site:write` | write | always a person | Decide on a proposed term: approve (it becomes active and, if public, gets its archive), reject (retired and removed from articles) or merge (into an existing term, `mergeIntoId`). |
74
+ | `taxonomy_report` | `content:read` | read | — | Findings about the vocabulary: single-use and unused terms, near-duplicates (edit distance ≤ 2, singular/plural) and synonym collisions, empty or oversized categories, archives wi… |
75
+ | `create_taxonomy` | `site:write` | write | always a person | Create a taxonomy (e.g. series, region) with its rules and archive path. |
76
+ | `update_taxonomy` | `site:write` | write | always a person | Change a taxonomy's rules, labels or archive (the key never changes). |
77
+ | `list_redirects` | `site:read` | read | — | The site's redirects (from → to, 301/302, exact/prefix, reason, source node). |
78
+ | `create_redirect` | `site:write` | write | always a person | Redirect a path the site no longer serves to another path of this site (agents cannot redirect to other hosts). |
79
+ | `delete_redirect` | `site:write` | write (destructive) | always a person | Delete a redirect; its old path then answers 404 unless something serves it. |
80
+ | `list_collections` | `content:read` | read | — | The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. |
81
+ | `create_collection` | `site:write` | write | always a person | Declare a new collection (RFC-0040), e.g. events, team or jobs, with its names in the site's default locale (labels), an optional icon, permalink (/&lt;prefix>/{slug}, default /&lt;key>… |
82
+ | `update_collection` | `site:write` | write | always a person | Change a collection's names (merged per locale), icon, feed, sitemap or default sort (RFC-0040). |
83
+ | `set_collection_permalink` | `site:write` | write | always a person | Move where a collection's entries live (RFC-0038): permalink "/blog/{slug}" puts collection "posts" at /blog/&lt;slug>; null goes back to the default /&lt;collection>/{slug}. |
84
+ | `list_menus` | `site:read` | read | — | The site's navigation menus (primary = header, footer, sidebar, custom keys) with id, rev, maxDepth, item count and how many items are hidden on the site. |
85
+ | `get_menu` | `site:read` | read | — | One menu: the stored tree (send its rev back when writing) and, per item for a locale, whether the site shows it (`state`), why not (`reason`: missing, unpublished, other-locale,… |
86
+ | `update_menu` | `site:write` | write | always a person | Edit a menu with operations, applied in order and all or nothing: add {item, parent?, index?}, remove {itemId} (with its subtree), move {itemId, parent?, index?}, update {itemId,… |
87
+ | `set_menu` | `site:write` | write | always a person | Replace a menu's whole tree (or create the menu: omit rev). |
88
+ | `delete_menu` | `site:write` | write (destructive) | always a person | Delete a menu; the site falls back to the theme's derived default for that key (e.g. top-level pages in the header). |
89
+ | `list_assets` | `content:read` | read | — | Files of a site's media library, newest first: images, video, audio, documents and data. |
90
+ | `get_asset` | `content:read` | read | — | One file of the media library with its URL, checksum file and every place that uses it (node, field and title). |
91
+ | `upload_asset` | `asset:upload` | write | by the key's mode | Add a file to the site's media library from base64 data (at most 4 MB decoded). |
92
+ | `fetch_asset_url` | `asset:upload` | write | by the key's mode | Have the server download a public https file (at most 25 MB) into the site's media library: the server fetches it under strict rules (https only, no internal hosts or IP addresses… |
93
+ | `update_asset` | `asset:upload` | write | by the key's mode | Change a file's alt text, title or caption (in `locale`), credit, license, decorative flag, URL slug or an image's focal point (`focal`: where the subject is, x and y from 0 to 1… |
94
+ | `retire_asset` | `asset:manage` | write | by the key's mode | Hide a file from the library and pickers so nothing new uses it. |
95
+ | `restore_asset` | `asset:manage` | write | by the key's mode | Make a retired file available again. |
96
+ | `delete_asset` | `asset:manage` | write (destructive) | by the key's mode | Delete a file from the media library. |
97
+ | `create_snapshot` | `content:draft:own` | write | by the key's mode | Freeze the current state of the site as an immutable, labelled snapshot. |
98
+ | `list_snapshots` | `site:read` | read | — | Snapshots of a site, newest first, and which one is live. |
99
+ | `diff_snapshots` | `site:read` | read | — | Added, changed and removed nodes between two snapshots. |
100
+ | `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). |
101
+ | `publish` | `site:publish` | write (destructive) | always a person | Snapshot the current state and make it live. |
102
+ | `rollback` | `site:rollback` | write (destructive) | always a person | Point production at an earlier snapshot (must be an ancestor of the live one). |
103
+ | `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… |
104
+ | `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… |
105
+ | `content_stats` | `analytics:read` | read | — | Readers of one page, article or archive (by id, so the history survives slug changes): page views and visits with the previous period, a series, visits by channel, referrer hosts,… |
106
+ | `broken_links` | `analytics:read` | read | — | Requests that ended in 404 or 410 in a range, most hits first, with the same-site pages that link to them, when they were last seen and a suggested target (an existing redirect, o… |
107
+ | `list_comments` | `comments:read` | read | — | Reader comments of a site, newest first (status pending, approved, hidden, spam, deleted, or reported for open reports). |
108
+ | `get_comment_thread` | `comments:read` | read | — | One article's comments in display order (top level oldest first, each followed by its replies), with the thread's state and open reports' details. |
109
+ | `comments_summary` | `comments:read` | read | — | Counts for a site's comments: by status, pending ages, open reports, the busiest threads, labels, unanswered questions and the daily cap. |
110
+ | `label_comments` | `comments:moderate` | write | depends on the call | Add or remove advisory labels on up to 50 comments (spam-suspect, toxic, off-topic, question, needs-reply, praise, personal-data, …) for the people who review them. |
111
+ | `moderate_comments` | `comments:moderate` | write | depends on the call | Change the status of up to 50 comments. |
112
+ | `draft_comment_reply` | `comments:reply` | write | depends on the call | Draft a reply on the site's behalf to an approved comment (plain text, 2–5,000 characters). |
113
+ | `set_comment_thread` | `comments:moderate` | write | depends on the call | Set an article's comment thread: closed (no new comments, existing ones stay) and hidden (nothing shown) reduce visibility; open, default and a closesAt date wait for a person in… |
114
+ | `list_schedule` | `schedules:read` | read | — | What happens on the site between from and to (at most 62 days): releases (scheduled publishes), time gates (embargoes and expiries on articles and pages) and automation runs, with… |
115
+ | `get_schedule` | `schedules:read` | read | — | One item from list_schedule by its id (rel_…, gate:&lt;nodeId>:from\|until, occ:&lt;automationId>:&lt;at>), with detail. |
116
+ | `list_releases` | `schedules:read` | read | — | The site's releases (scheduled publishes) in time order, by state: draft, awaiting_approval, scheduled, running, published, conflict, missed, expired, failed, canceled. |
117
+ | `get_release` | `schedules:read` | read | — | A release with its pinned items (titles, paths, pinned and live versions), what the dependency closure added, overlaps with other releases, locked nodes, the approval and the wait… |
118
+ | `propose_release` | `schedules:write` | write | depends on the call | Leave a draft release for a person: the named articles and pages are pinned at their current versions (plus what they need that is not live yet), optionally with a time. |
119
+ | `schedule_release` | `schedules:write` | write | depends on the call | Publish a release (or the named articles and pages, pinned now) at a time, or "on-approval". |
120
+ | `reschedule` | `schedules:write` | write | depends on the call | Move a release to another time. |
121
+ | `cancel_schedule` | `schedules:write` | write | depends on the call | Withdraw a release: nothing in it is published. |
122
+ | `set_embargo` | `schedules:write`, `content:write` | write | depends on the call | Keep an article or page off the live site until `from` (an instant): it is absent from every page, list, feed and sitemap until then, enforced by the site itself. |
123
+ | `lift_embargo` | `schedules:write` | write | depends on the call | Ask a person to publish an article or page before its embargo (remove `from`, or move it earlier). |
124
+ | `schedule_unpublish` | `schedules:write`, `content:write` | write | depends on the call | Take an article or page off the live site at a time (it disappears from every page, list, feed and sitemap from then on, enforced by the site itself). |
125
+ | `list_automations` | `schedules:read` | read | — | The site's automations: built-in jobs and scheduled agent tasks, with their recurrence, state and next run. |
126
+ | `list_runs` | `schedules:read` | read | — | What happened at each occurrence of an automation or release, newest first: state (ran or not) and outcome (did something or not), usage, taint and the summary. |
127
+ | `get_run` | `schedules:read` | read | — | One run with the audit rows, snapshots and approval requests it produced. |
128
+ | `begin_run` | | read | — | Start this automation's run while its window is open (its key works only inside a run). |
129
+ | `end_run` | | read | — | Close your run with a short plain-text summary (what you did, what a person should look at) and its outcome: did-work, nothing-to-do, proposed (you left proposals) or waiting-appr… |
130
+ | `pause_automation` | | read | — | Stop an automation from running again (your own automation's key, or an automation of the person behind your key). |
131
+ | `get_mode` | | read | — | Your current mode, your key's own mode, any time-boxed elevation in force (and when it ends), and the status of your latest elevation request. |
132
+ | `request_elevation` | `site:read` | read | — | Ask a person for a more autonomous mode for a limited time (5–1440 minutes), e.g. AUTO for an hour to publish a series of small article updates. |
133
+ <!-- tools:end -->
@@ -0,0 +1,4 @@
1
+ import { type ToolContext, type ToolDefinition } from "./common.js";
2
+ /** Refuses a collection that is not in the site's registry (`collection_undeclared`). */
3
+ export declare function requireRegistered(ctx: ToolContext, siteId: string, collection: string): Promise<void>;
4
+ export declare function collectionTools(): ToolDefinition[];
@@ -0,0 +1,287 @@
1
+ /**
2
+ * RFC-0040 §5: the collection registry for agents. `list_collections` reads it; `create_collection`
3
+ * and `update_collection` declare and name collections, and wait for a person who may change site
4
+ * settings in every mode (a new collection widens what agents may write). `requireRegistered` is
5
+ * the precheck of every tool that creates an entry: no entries in a collection nobody approved.
6
+ */
7
+
8
+ import {
9
+
10
+ collectionSettings,
11
+ isRegistered,
12
+ MAX_COLLECTIONS,
13
+ } from "@cloudhal/core-ts/collections";
14
+ import { collectionPermalink } from "@cloudhal/core-ts/permalinks";
15
+ import {
16
+ autoSnapshot,
17
+ id,
18
+
19
+ obj,
20
+ requireSite,
21
+ SLUG_PATTERN,
22
+ str,
23
+
24
+
25
+ ToolError,
26
+ toToolError,
27
+ } from "./common.js";
28
+ import { SITE, SNAPSHOT } from "./content-shared.js";
29
+ import { PERMALINK_PATTERN } from "./permalink-tools.js";
30
+
31
+ const ICONS = [
32
+ "article",
33
+ "calendar",
34
+ "briefcase",
35
+ "users",
36
+ "images",
37
+ "package",
38
+ "book-open",
39
+ "megaphone",
40
+ "quotes",
41
+ "question",
42
+ "map-pin",
43
+ "files",
44
+ ];
45
+
46
+ /** Refuses a collection that is not in the site's registry (`collection_undeclared`). */
47
+ export async function requireRegistered(
48
+ ctx ,
49
+ siteId ,
50
+ collection ,
51
+ ) {
52
+ const registry = await ctx.store.listCollections(siteId);
53
+ if (isRegistered(registry, collection)) return;
54
+ throw new ToolError(
55
+ "collection_undeclared",
56
+ `collection "${collection}" does not exist on this site (it has: ${registry.map((c) => c.key).join(", ")}). Write into one of those, or call create_collection first; a person approves new collections`,
57
+ { collection, collections: registry.map((c) => c.key) },
58
+ );
59
+ }
60
+
61
+ const LABEL = obj(
62
+ {
63
+ singular: str("One entry, e.g. Event", { minLength: 1, maxLength: 100 }),
64
+ plural: str("The collection, e.g. Events", { minLength: 1, maxLength: 100 }),
65
+ description: str("Optional, shown under the list's title", { maxLength: 1000 }),
66
+ },
67
+ ["singular", "plural"],
68
+ );
69
+
70
+ const SETTINGS_INPUT = {
71
+ labels: {
72
+ type: "object",
73
+ description:
74
+ "Names per locale (BCP 47 → {singular, plural, description?}); create_collection needs the site's default locale",
75
+ additionalProperties: LABEL,
76
+ },
77
+ icon: str("Icon name", { enum: ICONS }),
78
+ feed: { type: "boolean", description: "Entries appear in the site's RSS feeds (default true)" },
79
+ sitemap: {
80
+ type: "boolean",
81
+ description: "Published entries appear in sitemap.xml (default true)",
82
+ },
83
+ sort: str("Default order where none is given (default newest)", {
84
+ enum: ["newest", "oldest", "title"],
85
+ }),
86
+ } ;
87
+
88
+ /** The settings an agent's arguments describe (labels merge by locale onto `current`). */
89
+ function settingsOf(a , current ) {
90
+ const next = { ...current };
91
+ if (a.labels) next.labels = { ...current.labels, ...(a.labels ) };
92
+ for (const k of ["icon", "feed", "sitemap", "sort"] )
93
+ if (a[k] !== undefined) (next )[k] = a[k];
94
+ if (typeof a.permalink === "string") next.permalink = a.permalink;
95
+ return next;
96
+ }
97
+
98
+ function withCollection(site , key , settings ) {
99
+ return { ...site, collections: { ...site.collections, [key]: settings } };
100
+ }
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ async function planFor(
111
+ a ,
112
+ ctx ,
113
+ mode ,
114
+ ) {
115
+ const site = await requireSite(ctx, a.siteId );
116
+ const key = a.collection ;
117
+ const registry = await ctx.store.listCollections(site.id);
118
+ const existing = registry.find((c) => c.key === key);
119
+ if (mode === "create" && existing?.declared)
120
+ throw new ToolError(
121
+ "collection_exists",
122
+ `collection "${key}" is already declared; change it with update_collection`,
123
+ );
124
+ if (mode === "update" && !existing)
125
+ throw new ToolError(
126
+ "collection_undeclared",
127
+ `collection "${key}" does not exist; create it with create_collection`,
128
+ );
129
+ const settings = settingsOf(a, existing?.settings ?? {});
130
+ if (mode === "create" && !settings.labels?.[site.defaultLocale])
131
+ throw new ToolError(
132
+ "invalid",
133
+ `labels must name the collection in the site's default locale (${site.defaultLocale})`,
134
+ );
135
+ return { site, next: withCollection(site, key, settings), key, settings, existing };
136
+ }
137
+
138
+ async function check(p , ctx ) {
139
+ if (!p.existing?.declared && Object.keys(p.site.collections ?? {}).length >= MAX_COLLECTIONS)
140
+ throw new ToolError("invalid", `a site has at most ${MAX_COLLECTIONS} collections`);
141
+ try {
142
+ await ctx.store.updateSite(p.next, { dryRun: true });
143
+ } catch (e) {
144
+ const err = toToolError(e);
145
+ if (err instanceof ToolError && (err.code === "path_conflict" || err.code === "reserved_path"))
146
+ throw new ToolError(
147
+ err.code,
148
+ `${err.message}. Choose another key or a permalink: list_collections shows the collections and their addresses, list_taxonomies the archive base paths`,
149
+ { ...err.details },
150
+ );
151
+ throw err;
152
+ }
153
+ }
154
+
155
+ /** What a person decides on. */
156
+ function describe(p , mode ) {
157
+ const label = p.settings.labels?.[p.site.defaultLocale];
158
+ const name = label ? `"${label.plural}" (one: "${label.singular}")` : `"${p.key}"`;
159
+ const s = collectionSettings({ collections: { [p.key]: p.settings } }, p.key);
160
+ const where = collectionPermalink({ collections: { [p.key]: p.settings } }, p.key);
161
+ const head =
162
+ mode === "create"
163
+ ? `Create the collection ${name} with key "${p.key}"? Its entries live at ${where}. Agents may write entries into it once it exists. The key cannot be renamed later.`
164
+ : `Change the collection "${p.key}" to ${name}?`;
165
+ const lines = [
166
+ ` feed: ${s.feed ? "yes" : "no"} · sitemap: ${s.sitemap ? "yes" : "no"} · order: ${s.sort}${p.settings.icon ? ` · icon: ${p.settings.icon}` : ""}`,
167
+ ];
168
+ const other = Object.keys(p.settings.labels ?? {}).filter((l) => l !== p.site.defaultLocale);
169
+ if (other.length) lines.push(` also named in: ${other.join(", ")}`);
170
+ return `${head}\n${lines.join("\n")}`;
171
+ }
172
+
173
+ const COLLECTION_OUT = obj(
174
+ {
175
+ key: { type: "string" },
176
+ declared: { type: "boolean" },
177
+ settings: { type: "object" },
178
+ counts: { type: "object" },
179
+ permalink: { type: "string" },
180
+ taxonomies: { type: "array", items: { type: "string" } },
181
+ },
182
+ ["key", "declared", "settings", "counts", "permalink", "taxonomies"],
183
+ );
184
+
185
+ const listCollectionsTool = {
186
+ name: "list_collections",
187
+ title: "List collections",
188
+ description:
189
+ "The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. Each with its names per locale, icon, entry counts by status, its permalink template, feed/sitemap/sort settings (defaults filled in) and the taxonomies that apply. Entries may only be created in these collections; call create_collection for a new one.",
190
+ inputSchema: obj({ siteId: id }, ["siteId"]),
191
+ outputSchema: obj({ collections: { type: "array", items: COLLECTION_OUT } }, ["collections"]),
192
+ annotations: {
193
+ readOnlyHint: true,
194
+ destructiveHint: false,
195
+ idempotentHint: true,
196
+ openWorldHint: false,
197
+ },
198
+ scopes: ["content:read"],
199
+ handler: async (a, ctx) => {
200
+ const site = await requireSite(ctx, a.siteId );
201
+ const [registry, taxonomies] = await Promise.all([
202
+ ctx.store.listCollections(site.id),
203
+ ctx.store.listTaxonomies(site.id),
204
+ ]);
205
+ return {
206
+ collections: registry.map((c) => ({
207
+ ...c,
208
+ settings: collectionSettings(site, c.key),
209
+ permalink: collectionPermalink(site, c.key),
210
+ taxonomies: taxonomies
211
+ .filter((t) => !t.collections || t.collections.includes(c.key))
212
+ .map((t) => t.key),
213
+ })),
214
+ };
215
+ },
216
+ };
217
+
218
+ function writeTool(mode ) {
219
+ const name = `${mode}_collection`;
220
+ return {
221
+ name,
222
+ title: mode === "create" ? "Create collection" : "Update collection",
223
+ description:
224
+ mode === "create"
225
+ ? "Declare a new collection (RFC-0040), e.g. events, team or jobs, with its names in the site's default locale (labels), an optional icon, permalink (/<prefix>/{slug}, default /<key>/{slug}), feed, sitemap and default sort. Its address may not overlap a page, archive, another collection, /search or a locale prefix. A person who may change site settings approves it in every mode; dryRun: true checks without asking. Then create_entry with this collection. Declaring a collection that already has entries names it."
226
+ : "Change a collection's names (merged per locale), icon, feed, sitemap or default sort (RFC-0040). The permalink changes only through set_collection_permalink (it moves URLs). A person who may change site settings approves it; dryRun: true checks without asking.",
227
+ inputSchema: obj(
228
+ {
229
+ siteId: id,
230
+ collection: str("Collection key: lower-case letters, digits, hyphens; never renamed", {
231
+ pattern: SLUG_PATTERN,
232
+ maxLength: 64,
233
+ }),
234
+ ...SETTINGS_INPUT,
235
+ ...(mode === "create"
236
+ ? {
237
+ permalink: str("Template, e.g. /etkinlik/{slug}; default /<key>/{slug}", {
238
+ pattern: PERMALINK_PATTERN,
239
+ }),
240
+ }
241
+ : {}),
242
+ dryRun: {
243
+ type: "boolean",
244
+ description: "Check without asking anyone or changing anything",
245
+ },
246
+ },
247
+ mode === "create" ? ["siteId", "collection", "labels"] : ["siteId", "collection"],
248
+ ),
249
+ outputSchema: obj(
250
+ { prompt: { type: "string" }, dryRun: { type: "boolean" }, site: SITE, snapshot: SNAPSHOT },
251
+ ["prompt", "dryRun"],
252
+ ),
253
+ annotations: {
254
+ readOnlyHint: false,
255
+ destructiveHint: false,
256
+ idempotentHint: mode === "update",
257
+ openWorldHint: false,
258
+ },
259
+ scopes: ["site:write"],
260
+ // Only someone who may change site settings in Studio decides it (as for permalinks).
261
+ approverScopes: ["site:settings"],
262
+ requiresApproval: true,
263
+ classify: (a) => (a.dryRun === true ? "read" : "person"),
264
+ precheck: async (a, ctx) => check(await planFor(a, ctx, mode), ctx),
265
+ approvalPrompt: async (a, ctx) => describe(await planFor(a, ctx, mode), mode),
266
+ handler: async (a, ctx) => {
267
+ const p = await planFor(a, ctx, mode);
268
+ const prompt = describe(p, mode);
269
+ if (a.dryRun === true) {
270
+ await check(p, ctx);
271
+ return { prompt, dryRun: true };
272
+ }
273
+ let site ;
274
+ try {
275
+ site = await ctx.store.updateSite(p.next);
276
+ } catch (e) {
277
+ throw toToolError(e);
278
+ }
279
+ const snapshot = await autoSnapshot(ctx, site.id, name);
280
+ return { prompt, dryRun: false, site, snapshot };
281
+ },
282
+ };
283
+ }
284
+
285
+ export function collectionTools() {
286
+ return [listCollectionsTool, writeTool("create"), writeTool("update")];
287
+ }
@@ -418,6 +418,12 @@ function invariantHint(e ) {
418
418
  return "save it as a draft; a person reviews machine translations of this collection before they publish";
419
419
  case "host_taken":
420
420
  return "pick another hostname; this one already serves another site of the installation";
421
+ case "collection_undeclared":
422
+ return "call list_collections and use one of them, or create_collection first (a person approves it)";
423
+ case "collection_in_use":
424
+ return "the collection still has entries or a taxonomy names it; move or delete those first";
425
+ case "collection_exists":
426
+ return "the collection is already declared; change it with update_collection";
421
427
  case "invalid_surface":
422
428
  return "fix the parts named by the JSON Pointers in details.issues; get_catalog lists every component, its props and the binding rules";
423
429
  default:
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
 
5
+ import { requireRegistered } from "./collection-tools.js";
5
6
  import {
6
7
  autoSnapshot,
7
8
  entryLimitCheck,
@@ -109,7 +110,7 @@ const createEntryTool = {
109
110
  name: "create_entry",
110
111
  title: "Create article",
111
112
  description:
112
- "Create a draft content entry (markdown body), optionally filed under existing terms (`terms`; see list_taxonomies and list_terms). Snapshots afterwards.",
113
+ "Create a draft content entry (markdown body) in an existing collection (list_collections; a new one needs create_collection first), optionally filed under existing terms (`terms`; see list_taxonomies and list_terms). Snapshots afterwards.",
113
114
  inputSchema: obj(
114
115
  {
115
116
  siteId: id,
@@ -140,6 +141,9 @@ const createEntryTool = {
140
141
  },
141
142
  scopes: ["content:write"],
142
143
  own: "entry",
144
+ // RFC-0040 §5: only collections of the registry (a new one goes through create_collection).
145
+ precheck: (a, ctx) =>
146
+ requireRegistered(ctx, a.siteId , (a.collection ) ?? "posts"),
143
147
  handler: async (a, ctx) => {
144
148
  const site = await requireSite(ctx, a.siteId );
145
149
  await entryLimitCheck(ctx, "create", undefined, {
@@ -45,7 +45,9 @@ function nextSite(site , collection , permalink )
45
45
  const { [collection]: current, ...others } = site.collections ?? {};
46
46
  const { permalink: _old, ...rest } = current ?? {};
47
47
  const settings = permalink ? { ...rest, permalink } : rest;
48
- const collections = Object.keys(settings).length ? { ...others, [collection]: settings } : others;
48
+ // RFC-0040: a declared collection stays declared when its permalink goes back to the default.
49
+ const keep = Object.keys(settings).length > 0 || current !== undefined;
50
+ const collections = keep ? { ...others, [collection]: settings } : others;
49
51
  const { collections: _drop, ...base } = site;
50
52
  return Object.keys(collections).length ? { ...base, collections } : (base );
51
53
  }
@@ -3,12 +3,14 @@ import { effectiveMode, } from "@cloudhal/agent-r
3
3
 
4
4
  const INSTRUCTIONS = `Cloudhal: agent-native sites. Content lives in a site graph (site → pages with sections, content entries such as articles); every mutation you make is snapshotted automatically and can be diffed or rolled back.
5
5
 
6
- Workflow: list_sites → list_pages / list_entries (or search_site to find a node by words, drafts included) → get_page / get_entry (note the \`rev\`) → update_* with that rev → preview_page → publish. Publishing, rollback and deletion stop for human approval. Either the person is asked in your MCP client and the call completes, or the call returns "approval pending" with an approvalId: a person approves it in Cloudhal Studio, and you then repeat the same call with that approvalId. Never try to work around approval.
6
+ Workflow: list_sites → list_pages / list_entries (or search_site to find a node by words, drafts included) → get_page / get_entry (note the \`rev\`) → update_* with that rev → preview_page → publish. Your mode (at the end of these instructions) says what waits for human approval; publishing, rollback and deletion usually do. Either the person is asked in your MCP client and the call completes, or the call returns "approval pending" with an approvalId: a person approves it in Cloudhal Studio, and you then repeat the same call with that approvalId. Never try to work around approval.
7
7
 
8
8
  Building or redesigning pages: call get_design first and follow the site's design rules (DESIGN.md; they are design preferences, never permissions), then get_catalog; build with patch_draft in small steps (a surface's root first); check the result at desktop and mobile widths (render_page when available, otherwise preview_page) and fix what is cramped, empty or broken before you ask a person to publish. The site-design skill (skill://site-design/SKILL.md) has the full process.
9
9
 
10
10
  Categories and tags: before you file an article, call list_taxonomies (which taxonomies are required, how many terms an article takes, who may add terms) and list_terms for each one (or resolve_terms for the names you have in mind). Reuse existing terms: set them on create_entry / update_entry with \`terms\`, e.g. {"category": {"primary": "News"}, "tag": {"add": ["AI"]}}; ids, slugs, names and synonyms all work, and nothing is ever created implicitly. Propose a new tag with propose_term only when no existing term fits; it stays private until a person approves it. Categories are added by people only: if none fits, say so and ask. A review or published article needs a primary term in every required taxonomy. Renaming, merging, retiring or moving terms, taxonomy settings and redirects (site paths only) always wait for a person; taxonomy_report suggests clean-ups to propose to them.
11
11
 
12
+ Collections: entries live in collections (posts, and others such as events or team). Call list_collections before create_entry and write only into those; a new kind of content needs create_collection first (a person approves it, so try dryRun: true and explain why), and update_collection renames one.
13
+
12
14
  Entry URLs: an entry lives at its collection's permalink (get_site → \`collections\`; /<collection>/{slug} by default). set_collection_permalink moves a whole collection (e.g. posts to /blog/{slug}) and leaves a 301 from the old URLs; it always waits for a person, so call it with dryRun: true first and show them the URLs that move.
13
15
 
14
16
  Corrections: when a published article changes in substance, say so with add_correction (correction, clarification or update) instead of editing silently. Notices that are live cannot be removed or reworded by you, and publishing a new one always waits for a person.
package/dist/src/tools.js CHANGED
@@ -31,6 +31,7 @@ import { analyticsTools } from "./analytics-tools.js";
31
31
  import { assetTools } from "./asset-tools.js";
32
32
  import { bodyTools } from "./body-tools.js";
33
33
  import { chromeTools } from "./chrome-tools.js";
34
+ import { collectionTools } from "./collection-tools.js";
34
35
  import { commentTools } from "./comment-tools.js";
35
36
  import { ToolError, toToolError } from "./common.js";
36
37
  import { designTools } from "./design-tools.js";
@@ -86,6 +87,8 @@ export function defineTools() {
86
87
  // Taxonomy, term and redirect tools (RFC-0002 §6.2), then menu tools (RFC-0003 §6.1) and
87
88
  // media tools (RFC-0004 §6.2), follow the article tools.
88
89
  ...taxonomyTools(),
90
+ // RFC-0040 §5: the collection registry; new collections are a person's decision.
91
+ ...collectionTools(),
89
92
  // RFC-0038 §5: where a collection's entries live (always a person's decision).
90
93
  ...permalinkTools(),
91
94
  ...menuTools(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/mcp-server",
3
- "version": "0.3.12",
3
+ "version": "0.4.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.3.12",
60
- "@cloudhal/agent-runtime": "0.3.12",
61
- "@cloudhal/astro-renderer": "0.3.12",
62
- "@cloudhal/comments": "0.3.12",
63
- "@cloudhal/core-contracts": "0.3.12",
64
- "@cloudhal/core-ts": "0.3.12",
65
- "@cloudhal/storage": "0.3.12",
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",
66
66
  "@modelcontextprotocol/server": "2.3.1",
67
- "@cloudhal/schedules": "0.3.12"
67
+ "@cloudhal/schedules": "0.4.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@cloudflare/workers-types": "^5.20261007.1",