@mapled/mcp 0.17.0 → 0.18.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 +3 -3
- package/dist/tools.js +75 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ For the first integration, propose one plan and let the owner approve it on a tr
|
|
|
46
46
|
2. `propose_setup_plan` — the collections and singles (with fields and the records to import), the files you will change, the packages you will install. Nothing changes yet. Relation fields name their target — a collection of the plan by its display name, or an existing one by key; give a record a `"$ref": "jane"` and other records of the plan link to it as `"author": "jane"` (a list of refs for `many`), while links to existing collections use record ids from `list_records`. Group fields carry their sub-fields; their values are objects keyed by the sub-field keys. Mark a field — or a sub-field of a group — `sensitive: true` when editors keep it but the site must never get it. A link that does not resolve is answered right away with its path, so fix the plan before the owner sees it.
|
|
47
47
|
3. Ask the user to open the returned `reviewUrl` and approve. Poll `get_setup_run` until its status is `approved` (or `rejected` — then propose a better plan).
|
|
48
48
|
4. `apply_setup_plan` — Mapled creates everything in one go and tells you the keys it assigned.
|
|
49
|
-
5. Wire the site: `get_connection`, then `configure_revalidation` for a site with a server — or `set_site_url` for one rendered in the browser (a React single-page app, plain HTML: no webhook, no preview route) — and deploy.
|
|
49
|
+
5. Wire the site: `get_connection`, then `configure_revalidation` for a site with a server — or `set_site_url` for one rendered in the browser (a React single-page app, plain HTML: no webhook, no preview route) — and deploy. The webhook's signing secret never passes through the agent: the owner takes it from Mapled → Integrations → Your site, where Rotate secret shows a new one once, into the site's env as `MAPLED_WEBHOOK_SECRET`.
|
|
50
50
|
6. Leave a guide: `get_mapled_md` renders `MAPLED.md` from the project — what the site reads and where, the content model, the working rules, the commands that verify the integration. Write it to the repository root and commit it; the next agent (or person) starts from it. When the file exists, replace everything above its `<!-- mapled:notes -->` line and keep the notes below.
|
|
51
51
|
7. Close with `report_setup` (files changed, `buildPassed`, `secretsCommitted: false`, `mapledMdWritten: true`). Mapled runs its own checks — the site reads content, the webhook delivered, the preview route responds, fields have help texts, MAPLED.md was written — and the run is completed only when they pass. Fix what failed and call `verify_setup`. The result lands in the file's «Last setup run» section, so call `get_mapled_md` once more when the run is settled and commit the refreshed file.
|
|
52
52
|
|
|
@@ -69,8 +69,8 @@ A rename or a conversion Mapled wouldn't take is refused at once with the reason
|
|
|
69
69
|
| `create_form` / `list_forms` | Set up public forms with spam protection |
|
|
70
70
|
| `get_connection` | The delivery key and the API URL, plus — for the `framework` the agent names (`nextjs`, `react-spa`, `plain-html`, …) or the project's own — the package the site reads through (`@mapled/next`, `@mapled/react`, `@mapled/vanilla` — a script tag and `data-mapled-*` attributes for plain HTML — or `@mapled/client`), the env var of the key, whether the site renders on a server or in the browser, and the wire-up steps. Image values → `assetUrl(id, { width })` of the same package |
|
|
71
71
|
| `set_site_url` | Where the site is deployed — for a site rendered in the browser (a React single-page app, plain HTML), which has no webhook to learn it from: Preview opens the site there, verification checks that it answers |
|
|
72
|
-
| `push_site_manifest` / `list_bindings` | Tell Mapled where each field is rendered; read every binding's health (type mismatch, outdated, missing on site). Keep the repository's copy in `mapled/manifest.json` — `npx @mapled/cli scan --write` derives it from the code and `bindings push` / `bindings pull` exchange it with Mapled. A push records the integration hash — the schema and these bindings — and `list_bindings` says whether it still matches (`integration.inSync`, with `schemaChanged` / `bindingsChanged` naming what moved). `capabilities` says whether open tabs follow Publish: `{ realtime: true, releaseRoute: "/api/mapled/release" }` for a Next.js site with `<MapledLive />` and `createReleaseHandler
|
|
73
|
-
| `configure_revalidation` | Point the publish webhook at the site (one with a server that caches what it reads)
|
|
72
|
+
| `push_site_manifest` / `list_bindings` | Tell Mapled where each field is rendered; read every binding's health (type mismatch, outdated, missing on site). Keep the repository's copy in `mapled/manifest.json` — `npx @mapled/cli scan --write` derives it from the code and `bindings push` / `bindings pull` exchange it with Mapled. A push records the integration hash — the schema and these bindings — and `list_bindings` says whether it still matches (`integration.inSync`, with `schemaChanged` / `bindingsChanged` naming what moved). `capabilities` says whether open tabs follow Publish: `{ realtime: true, releaseRoute: "/api/mapled/release" }` for a Next.js site with `<MapledLive />` and `createReleaseHandler` (on the Pages Router, `createPagesReleaseHandler`), `{ realtime: true }` for a site rendered in the browser whose tabs ask Mapled directly (`live` on `MapledProvider`, `data-mapled-live` on the script tag), `{ realtime: false }` without live updates — only these two keys; MAPLED.md's Live updates line comes from it, so send it with every push |
|
|
73
|
+
| `configure_revalidation` | Point the publish webhook at the site (one with a server that caches what it reads). No answer carries the signing secret: it names the variable, `MAPLED_WEBHOOK_SECRET`, and the person takes the value from Mapled → Integrations → Your site, where Rotate secret shows a new one once, into the site's env. The description also tells the agent how to add live updates for tabs that are already open (`createReleaseHandler` and `<MapledLive />`, `@mapled/next` 0.8.0+; on the Pages Router `createPagesReleaseHandler` as an API route's default export and `<MapledLive />` from `@mapled/next/live/pages`, 0.9.0+), declared then in the manifest's `capabilities` |
|
|
74
74
|
| `check_integration` | The site's integration as Mapled sees it — delivery reads, the webhook and its last delivery, the bindings summary, the integration hash (is the last push still in step with the schema and the bindings?), current package versions; `npx @mapled/cli doctor` shows the same from inside the repository |
|
|
75
75
|
| `delete_collection` / `remove_field` / `clear_records` / `rename_field` / `convert_field` / `get_confirmation` | Destructive and breaking changes — each files a request a person confirms on a trusted Mapled screen (see above); `get_confirmation` reads its status |
|
|
76
76
|
| `get_mapled_md` | `MAPLED.md` rendered from the project — the guide for the next agent: project, how the site reads it, content model, bindings by page, last setup run, working rules, verification commands. Never a secret. `npx @mapled/cli md pull` writes the same file; `mapled doctor` says when it is out of date |
|
package/dist/tools.js
CHANGED
|
@@ -45,6 +45,78 @@ const COMPUTED_HELP = "For type computed only: { expression } — a formula over
|
|
|
45
45
|
"Numbers: + - * / %, round(x, digits), floor, ceil, abs, min, max, sum, avg, count, fixed(x, digits) → text. Text: & joins (empty counts as \"\"), concat, upper, lower, trim, length, left(s, n), right(s, n), replace(s, from, to), contains(s, part), slug(s), text(x), number(s). " +
|
|
46
46
|
"Logic: = != < <= > >=, and, or, not, if(cond, a, b), coalesce(a, b), empty(x). Dates: year, month, day, date(datetime), daysBetween(a, b), addDays(d, n), created() — when the record was added (a datetime). Literals: 12, 2.5, \"text\", true, false, null. " +
|
|
47
47
|
"Sensitive fields and relations, groups, JSON and location can't be read; there is no now(). The result type (number, text, boolean, date, datetime) follows from the formula.";
|
|
48
|
+
/** The variable the site's revalidate route verifies publishes with. */
|
|
49
|
+
const WEBHOOK_SECRET_ENV = "MAPLED_WEBHOOK_SECRET";
|
|
50
|
+
/** The header a publish webhook carries its signature in. */
|
|
51
|
+
const SIGNATURE_HEADER = "x-mapled-signature";
|
|
52
|
+
/** A text as the route words it, or nothing: an overlong text, a run of 24
|
|
53
|
+
letters and digits (a signing secret is 48 hex digits) or a Mapled
|
|
54
|
+
credential prefix never passes, so a secret sent whole or with its prefix
|
|
55
|
+
can't reach the model. A text filter can't promise more — the route's
|
|
56
|
+
refusals have to pass as worded. */
|
|
57
|
+
const routeText = (value) => typeof value === "string" &&
|
|
58
|
+
value.length <= 1000 &&
|
|
59
|
+
!/[A-Za-z0-9]{24}/.test(value) &&
|
|
60
|
+
!/(?:whsec|mk_live|msk_live|mcp_live|mpv)_/i.test(value)
|
|
61
|
+
? value
|
|
62
|
+
: undefined;
|
|
63
|
+
/** The address the route saved: the agent's own, as the URL parser writes it. */
|
|
64
|
+
const savedUrl = (sent, answered) => {
|
|
65
|
+
try {
|
|
66
|
+
return typeof answered === "string" && answered === new URL(sent).href ? answered : undefined;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/** configure_revalidation: the signing secret never passes through the
|
|
73
|
+
agent (§36.12) — the answer names the variable and hands the person
|
|
74
|
+
the step, over stdio and the hosted endpoint alike. Only the route's
|
|
75
|
+
own shapes pass: the agent's address as saved, the signature header's
|
|
76
|
+
name, a status of its two words, and texts — a refusal's too — that
|
|
77
|
+
carry no secret whole or with its prefix. */
|
|
78
|
+
function configureRevalidation(api) {
|
|
79
|
+
return {
|
|
80
|
+
name: "configure_revalidation",
|
|
81
|
+
description: "Point Mapled's publish webhook at the site so published changes appear instantly. Only for a site with " +
|
|
82
|
+
"a server that caches what it reads (Next.js and the like); a site rendered in the browser (react-spa, " +
|
|
83
|
+
"plain-html) shows a publish on the next load and needs none — call set_site_url for it instead. " +
|
|
84
|
+
"Pass the site's public revalidate URL (with @mapled/next: mount createRevalidateHandler " +
|
|
85
|
+
"from \"@mapled/next/server\" at /api/mapled/revalidate and pass that URL here). " +
|
|
86
|
+
"The webhook's signing secret never passes through you: the answer says how the person sets " +
|
|
87
|
+
`${WEBHOOK_SECRET_ENV} in the site's env — they copy it from Mapled → Integrations → Your site. ` +
|
|
88
|
+
"Don't ask them to paste it into the conversation. " +
|
|
89
|
+
"Local and private URLs are rejected; use the deployed site's URL. " +
|
|
90
|
+
"Optional, when the owner wants pages that are already open to follow a publish without a reload " +
|
|
91
|
+
"(@mapled/next 0.8.0+): also mount createReleaseHandler({ key: process.env.MAPLED_KEY! }) from " +
|
|
92
|
+
"\"@mapled/next/server\" as GET at /api/mapled/release and render <MapledLive /> from " +
|
|
93
|
+
"\"@mapled/next/live\" once in the root layout. On the Pages Router (@mapled/next 0.9.0+) export " +
|
|
94
|
+
"createPagesReleaseHandler({ key: process.env.MAPLED_KEY! }) from \"@mapled/next/server\" as the default " +
|
|
95
|
+
"of pages/api/mapled/release.ts and render <MapledLive /> from \"@mapled/next/live/pages\" in pages/_app; " +
|
|
96
|
+
"there only pages that read in getServerSideProps follow a publish (the @mapled/next README, Live updates → " +
|
|
97
|
+
"Pages Router). Tabs poll the site's own route, never Mapled; then declare it in push_site_manifest's " +
|
|
98
|
+
"capabilities.",
|
|
99
|
+
schema: {
|
|
100
|
+
url: z.string().min(8).max(2048),
|
|
101
|
+
},
|
|
102
|
+
handler: async (args) => {
|
|
103
|
+
let hook;
|
|
104
|
+
try {
|
|
105
|
+
hook = ((await api.request("PATCH", "/v1/agent/webhook", { url: args.url })) ?? {});
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
throw new Error(routeText(err instanceof Error ? err.message : undefined) ?? "Mapled couldn't save the webhook. Try again.");
|
|
109
|
+
}
|
|
110
|
+
const status = hook.signingSecret?.status;
|
|
111
|
+
return {
|
|
112
|
+
url: savedUrl(args.url, hook.url),
|
|
113
|
+
signatureHeader: hook.signatureHeader === SIGNATURE_HEADER ? SIGNATURE_HEADER : undefined,
|
|
114
|
+
signingSecret: { env: WEBHOOK_SECRET_ENV, status: status === "created" || status === "existing" ? status : undefined },
|
|
115
|
+
next: routeText(hook.next),
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
48
120
|
export function createTools(api) {
|
|
49
121
|
return [
|
|
50
122
|
{
|
|
@@ -297,7 +369,8 @@ export function createTools(api) {
|
|
|
297
369
|
"expects no webhook and no preview route. A plain HTML page that shows one record keeps the slug in its " +
|
|
298
370
|
"query — name it \"/post.html?slug=[slug]\", with a route_param binding on the slug field. " +
|
|
299
371
|
"`capabilities` says whether pages that are already open follow a publish (live updates): a Next.js site " +
|
|
300
|
-
"that renders <MapledLive /> (or calls watchRelease) and serves createReleaseHandler as GET at a route " +
|
|
372
|
+
"that renders <MapledLive /> (or calls watchRelease) and serves createReleaseHandler as GET at a route — " +
|
|
373
|
+
"on the Pages Router createPagesReleaseHandler as an API route's default export — " +
|
|
301
374
|
"sends { realtime: true, releaseRoute: \"/api/mapled/release\" } — the path its tabs ask; a site " +
|
|
302
375
|
"rendered in the browser whose tabs ask Mapled directly (live on MapledProvider, data-mapled-live on the " +
|
|
303
376
|
"script tag) sends { realtime: true }; a site without live updates sends { realtime: false }. Only these two keys " +
|
|
@@ -546,25 +619,7 @@ export function createTools(api) {
|
|
|
546
619
|
},
|
|
547
620
|
handler: async (args) => api.request("PATCH", "/v1/agent/site", { url: args.url }),
|
|
548
621
|
},
|
|
549
|
-
|
|
550
|
-
name: "configure_revalidation",
|
|
551
|
-
description: "Point Mapled's publish webhook at the site so published changes appear instantly. Only for a site with " +
|
|
552
|
-
"a server that caches what it reads (Next.js and the like); a site rendered in the browser (react-spa, " +
|
|
553
|
-
"plain-html) shows a publish on the next load and needs none — call set_site_url for it instead. " +
|
|
554
|
-
"Pass the site's public revalidate URL (with @mapled/next: mount createRevalidateHandler " +
|
|
555
|
-
"from \"@mapled/next/server\" at /api/mapled/revalidate and pass that URL here). " +
|
|
556
|
-
"Returns the signing secret — store it in the site's env as MAPLED_WEBHOOK_SECRET. " +
|
|
557
|
-
"Local and private URLs are rejected; use the deployed site's URL. " +
|
|
558
|
-
"Optional, when the owner wants pages that are already open to follow a publish without a reload " +
|
|
559
|
-
"(@mapled/next 0.8.0+): also mount createReleaseHandler({ key: process.env.MAPLED_KEY! }) from " +
|
|
560
|
-
"\"@mapled/next/server\" as GET at /api/mapled/release and render <MapledLive /> from " +
|
|
561
|
-
"\"@mapled/next/live\" once in the root layout — tabs poll the site's own route, never Mapled; then " +
|
|
562
|
-
"declare it in push_site_manifest's capabilities.",
|
|
563
|
-
schema: {
|
|
564
|
-
url: z.string().min(8).max(2048),
|
|
565
|
-
},
|
|
566
|
-
handler: async (args) => api.request("PATCH", "/v1/agent/webhook", { url: args.url }),
|
|
567
|
-
},
|
|
622
|
+
configureRevalidation(api),
|
|
568
623
|
{
|
|
569
624
|
name: "get_mapled_md",
|
|
570
625
|
description: "Get MAPLED.md — the guide Mapled writes for the next agent and for people: the project and how the site " +
|