inlaycms 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +469 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { InlayError } from '../../core/errors.js';
|
|
2
|
+
import { t } from '../../core/messages/index.js';
|
|
3
|
+
/** A successful result: `value` as a single JSON text block. */
|
|
4
|
+
export function ok(value) {
|
|
5
|
+
return { content: [{ type: 'text', text: JSON.stringify(value) }] };
|
|
6
|
+
}
|
|
7
|
+
/** An issue as tools report it: its field's labels, its dotted path and its message. */
|
|
8
|
+
export function issueJson(issue, prefix = []) {
|
|
9
|
+
const labels = [...prefix, ...issue.labels];
|
|
10
|
+
return {
|
|
11
|
+
field: labels.length > 0 ? labels.join(' → ') : t('label.content'),
|
|
12
|
+
path: issue.path.join('.'),
|
|
13
|
+
message: issue.message,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const issueLine = (issue) => issue.path === '' ? t('mcp.issueGeneral', { message: issue.message }) : t('mcp.issue', issue);
|
|
17
|
+
const USAGE_STATE = { draft: 'mcp.usage.draft', published: 'mcp.usage.published', 'draft-and-published': 'mcp.usage.both' };
|
|
18
|
+
const usageLine = (u) => t('mcp.usage', { state: t(USAGE_STATE[u.in]), title: u.title, locale: u.locale, id: u.documentId });
|
|
19
|
+
/**
|
|
20
|
+
* A failed result (`isError`): the catalog message, one line per issue and per usage, then the JSON
|
|
21
|
+
* `{ error: { code, message, issues, usages } }`. Anything but an `InlayError` gives a generic message and is logged.
|
|
22
|
+
*/
|
|
23
|
+
export function toolError(e, log) {
|
|
24
|
+
if (!(e instanceof InlayError)) {
|
|
25
|
+
log(e);
|
|
26
|
+
const message = t('mcp.unexpected');
|
|
27
|
+
return { isError: true, content: [{ type: 'text', text: `${message}\n${JSON.stringify({ error: { code: 'unexpected', message } })}` }] };
|
|
28
|
+
}
|
|
29
|
+
const { details } = e;
|
|
30
|
+
const issues = [
|
|
31
|
+
...(details.issues ?? []).map((issue) => issueJson(issue)),
|
|
32
|
+
...(details.documents ?? []).flatMap((doc) => doc.issues.map((issue) => issueJson(issue, [doc.title]))),
|
|
33
|
+
];
|
|
34
|
+
const usages = (details.usages ?? []).map((u) => ({
|
|
35
|
+
id: u.documentId,
|
|
36
|
+
groupId: u.groupId,
|
|
37
|
+
type: u.type,
|
|
38
|
+
locale: u.locale,
|
|
39
|
+
title: u.title,
|
|
40
|
+
in: u.in,
|
|
41
|
+
}));
|
|
42
|
+
const lines = [
|
|
43
|
+
e.message,
|
|
44
|
+
...issues.map(issueLine),
|
|
45
|
+
...(details.lines ?? []).map((l) => t('mcp.issueGeneral', { message: t('import.line', l) })),
|
|
46
|
+
...(details.usages ?? []).map(usageLine),
|
|
47
|
+
JSON.stringify({ error: { code: e.code, message: e.message, issues, usages } }),
|
|
48
|
+
];
|
|
49
|
+
return { isError: true, content: [{ type: 'text', text: lines.join('\n') }] };
|
|
50
|
+
}
|
|
51
|
+
/** Wraps a tool handler so anything it throws becomes a `toolError` result. */
|
|
52
|
+
export function tool(fn, log) {
|
|
53
|
+
return async (args, ctx) => {
|
|
54
|
+
try {
|
|
55
|
+
return await fn(args, ctx);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return toolError(e, log);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import type { AuthService } from '../../core/auth/service.js';
|
|
3
|
+
import type { Actor } from '../../core/types.js';
|
|
4
|
+
/** Who is calling `/mcp`, in the shape MCP's `AuthInfo` takes. */
|
|
5
|
+
export interface AuthInfo {
|
|
6
|
+
token: string;
|
|
7
|
+
/** The OAuth client the token was issued to, or `'api-key'`. */
|
|
8
|
+
clientId: string;
|
|
9
|
+
scopes: string[];
|
|
10
|
+
/** Seconds since the epoch; absent for API keys. */
|
|
11
|
+
expiresAt?: number;
|
|
12
|
+
extra: {
|
|
13
|
+
actor: Actor;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type McpHandle = (request: FastifyRequest, reply: FastifyReply, authInfo: AuthInfo) => Promise<FastifyReply>;
|
|
17
|
+
export interface McpRouteOptions {
|
|
18
|
+
service: AuthService;
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
handle: McpHandle;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The caller of an `/mcp` request: an OAuth access token (`Authorization: Bearer`) first, then an `x-api-key`.
|
|
24
|
+
* Both are checked against the user's current row, so access that ended stops working at once.
|
|
25
|
+
*/
|
|
26
|
+
export declare function authenticateMcp(request: FastifyRequest, service: AuthService): Promise<{
|
|
27
|
+
actor: Actor;
|
|
28
|
+
authInfo: AuthInfo;
|
|
29
|
+
} | null>;
|
|
30
|
+
/**
|
|
31
|
+
* `/mcp` (POST, GET and DELETE) behind the authentication gate: a foreign `Origin` gets a 403, a request without
|
|
32
|
+
* valid credentials a 401 whose `WWW-Authenticate` points MCP clients at the protected-resource metadata.
|
|
33
|
+
*/
|
|
34
|
+
export declare function registerMcpRoute(app: FastifyInstance, opts: McpRouteOptions): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MCP_PATH } from '../../core/auth/auth.js';
|
|
2
|
+
import { t } from '../../core/messages/index.js';
|
|
3
|
+
/** The JSON-RPC error code MCP servers use for a request that isn't authenticated. */
|
|
4
|
+
const UNAUTHORIZED = -32001;
|
|
5
|
+
const BEARER = /^Bearer\s+(\S+)\s*$/i;
|
|
6
|
+
const header = (request, name) => {
|
|
7
|
+
const value = request.headers[name];
|
|
8
|
+
return Array.isArray(value) ? value[0] : value;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The caller of an `/mcp` request: an OAuth access token (`Authorization: Bearer`) first, then an `x-api-key`.
|
|
12
|
+
* Both are checked against the user's current row, so access that ended stops working at once.
|
|
13
|
+
*/
|
|
14
|
+
export async function authenticateMcp(request, service) {
|
|
15
|
+
const token = BEARER.exec(header(request, 'authorization') ?? '')?.[1];
|
|
16
|
+
if (token !== undefined) {
|
|
17
|
+
const bearer = await service.bearerActor(token);
|
|
18
|
+
if (bearer) {
|
|
19
|
+
const { actor, clientId, scopes, expiresAt } = bearer;
|
|
20
|
+
return { actor, authInfo: { token, clientId, scopes, expiresAt, extra: { actor } } };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const key = header(request, 'x-api-key');
|
|
24
|
+
if (key !== undefined && key !== '') {
|
|
25
|
+
const found = await service.apiKeyActor(key);
|
|
26
|
+
if (found)
|
|
27
|
+
return { actor: found.actor, authInfo: { token: key, clientId: 'api-key', scopes: [], extra: { actor: found.actor } } };
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const rpcError = (messageId) => ({ jsonrpc: '2.0', error: { code: UNAUTHORIZED, message: t(messageId) }, id: null });
|
|
32
|
+
/**
|
|
33
|
+
* `/mcp` (POST, GET and DELETE) behind the authentication gate: a foreign `Origin` gets a 403, a request without
|
|
34
|
+
* valid credentials a 401 whose `WWW-Authenticate` points MCP clients at the protected-resource metadata.
|
|
35
|
+
*/
|
|
36
|
+
export function registerMcpRoute(app, opts) {
|
|
37
|
+
const { service, baseUrl, handle } = opts;
|
|
38
|
+
const challenge = `Bearer resource_metadata="${baseUrl}/.well-known/oauth-protected-resource${MCP_PATH}"`;
|
|
39
|
+
app.route({
|
|
40
|
+
method: ['POST', 'GET', 'DELETE'],
|
|
41
|
+
url: MCP_PATH,
|
|
42
|
+
handler: async (request, reply) => {
|
|
43
|
+
const origin = request.headers.origin;
|
|
44
|
+
if (origin !== undefined && origin !== baseUrl)
|
|
45
|
+
return reply.code(403).send(rpcError('mcp.badOrigin'));
|
|
46
|
+
const authed = await authenticateMcp(request, service);
|
|
47
|
+
if (!authed)
|
|
48
|
+
return reply.code(401).header('www-authenticate', challenge).send(rpcError('mcp.unauthorized'));
|
|
49
|
+
return handle(request, reply, authed.authInfo);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { McpServer, type McpHttpHandler } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { Core } from '../../core/core.js';
|
|
3
|
+
import type { Actor, Ctx } from '../../core/types.js';
|
|
4
|
+
import { type NonceStore } from './request-state.js';
|
|
5
|
+
import type { ErrorLog } from './results.js';
|
|
6
|
+
/** Downloads a file for `upload_media_from_url`, refusing anything over `maxBytes`. */
|
|
7
|
+
export type FetchFile = (url: string, opts: {
|
|
8
|
+
maxBytes: number;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
filename: string;
|
|
12
|
+
}>;
|
|
13
|
+
export interface McpDeps {
|
|
14
|
+
core: Core;
|
|
15
|
+
/** The site's origin, such as `https://example.com`. */
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
/** Signs preview links and request state. */
|
|
18
|
+
secret: string;
|
|
19
|
+
now: () => Date;
|
|
20
|
+
fetchFile: FetchFile;
|
|
21
|
+
uploads: {
|
|
22
|
+
maxBytes: number;
|
|
23
|
+
};
|
|
24
|
+
/** Where unexpected tool failures are reported. */
|
|
25
|
+
log: ErrorLog;
|
|
26
|
+
/** The request-state nonces already acted on, so a publish confirmation can't be replayed. */
|
|
27
|
+
confirmations: NonceStore;
|
|
28
|
+
/** The stored release this site runs; `null` or absent when it isn't one (such as under `inlaycms dev`). */
|
|
29
|
+
release?: {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
} | null;
|
|
33
|
+
}
|
|
34
|
+
/** What `createInlayMcpHandler` needs; it makes its own nonce store when none is given. */
|
|
35
|
+
export type McpHandlerOptions = Omit<McpDeps, 'confirmations'> & Partial<Pick<McpDeps, 'confirmations'>>;
|
|
36
|
+
/** What each tool module exports: registers its tools on `server`, acting as `ctx.actor`. */
|
|
37
|
+
export type RegisterTools = (server: McpServer, deps: McpDeps, ctx: Ctx) => void;
|
|
38
|
+
/** The MCP server for one request, with every tool acting as `actor`. */
|
|
39
|
+
export declare function buildServer(deps: McpDeps, actor: Actor): McpServer;
|
|
40
|
+
/**
|
|
41
|
+
* The stateless `/mcp` handler: a fresh server per request, serving 2026-era clients and, without sessions,
|
|
42
|
+
* 2025-era ones. Authentication happens before it; `authInfo.extra.actor` says who is calling.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createInlayMcpHandler(opts: McpHandlerOptions): McpHttpHandler;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createMcpHandler, McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { InlayError } from '../../core/errors.js';
|
|
3
|
+
import { t } from '../../core/messages/index.js';
|
|
4
|
+
import { inlayVersion } from '../../core/version.js';
|
|
5
|
+
import { createNonceStore, requestStateCodec } from './request-state.js';
|
|
6
|
+
import * as history from './tools/history.js';
|
|
7
|
+
import * as media from './tools/media.js';
|
|
8
|
+
import * as publish from './tools/publish.js';
|
|
9
|
+
import * as read from './tools/read.js';
|
|
10
|
+
import * as redirects from './tools/redirects.js';
|
|
11
|
+
import * as write from './tools/write.js';
|
|
12
|
+
const TOOLS = [read.register, write.register, history.register, publish.register, media.register, redirects.register];
|
|
13
|
+
function instructions(deps) {
|
|
14
|
+
const { guide } = deps.core.registry.site;
|
|
15
|
+
const parts = [t('mcp.instructions')];
|
|
16
|
+
if (guide !== undefined && guide.trim() !== '')
|
|
17
|
+
parts.push(`${t('mcp.siteGuide')}\n${guide}`);
|
|
18
|
+
return parts.join('\n\n');
|
|
19
|
+
}
|
|
20
|
+
/** The MCP server for one request, with every tool acting as `actor`. */
|
|
21
|
+
export function buildServer(deps, actor) {
|
|
22
|
+
const { verify } = requestStateCodec(deps.secret);
|
|
23
|
+
const server = new McpServer({ name: 'inlay', version: inlayVersion() }, { instructions: instructions(deps), requestState: { verify } });
|
|
24
|
+
const ctx = { actor, source: 'mcp' };
|
|
25
|
+
for (const register of TOOLS)
|
|
26
|
+
register(server, deps, ctx);
|
|
27
|
+
return server;
|
|
28
|
+
}
|
|
29
|
+
function isActor(value) {
|
|
30
|
+
if (typeof value !== 'object' || value === null)
|
|
31
|
+
return false;
|
|
32
|
+
const { id, name, role } = value;
|
|
33
|
+
return (id === null || typeof id === 'string') && typeof name === 'string' && (role === 'owner' || role === 'editor');
|
|
34
|
+
}
|
|
35
|
+
/** The actor `/mcp` authenticated, from `authInfo.extra.actor`. */
|
|
36
|
+
function actorOf(authInfo) {
|
|
37
|
+
const actor = authInfo?.extra?.actor;
|
|
38
|
+
if (!isActor(actor))
|
|
39
|
+
throw new InlayError('forbidden', 'error.forbidden');
|
|
40
|
+
return actor;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The stateless `/mcp` handler: a fresh server per request, serving 2026-era clients and, without sessions,
|
|
44
|
+
* 2025-era ones. Authentication happens before it; `authInfo.extra.actor` says who is calling.
|
|
45
|
+
*/
|
|
46
|
+
export function createInlayMcpHandler(opts) {
|
|
47
|
+
const deps = { ...opts, confirmations: opts.confirmations ?? createNonceStore() };
|
|
48
|
+
return createMcpHandler(({ authInfo }) => buildServer(deps, actorOf(authInfo)), { legacy: 'stateless' });
|
|
49
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { Ctx } from '../../../core/types.js';
|
|
3
|
+
import type { McpDeps } from '../server.js';
|
|
4
|
+
/** `list_revisions`, `diff_revisions` and `restore_revision`. */
|
|
5
|
+
export declare function register(server: McpServer, deps: McpDeps, ctx: Ctx): void;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { formatDiff } from '../../../core/content/diff.js';
|
|
3
|
+
import { InlayError } from '../../../core/errors.js';
|
|
4
|
+
import { t } from '../../../core/messages/index.js';
|
|
5
|
+
import { previewLink } from '../../site/preview.js';
|
|
6
|
+
import { documentOf, EDIT, livePath, READ_ONLY } from '../documents.js';
|
|
7
|
+
import { ok, tool } from '../results.js';
|
|
8
|
+
const listInput = z.object({
|
|
9
|
+
id: z.string().describe(t('mcp.param.id')),
|
|
10
|
+
limit: z.number().int().min(1).max(100).describe(t('mcp.param.revisionsLimit')).optional(),
|
|
11
|
+
});
|
|
12
|
+
const diffInput = z.object({
|
|
13
|
+
from: z.number().int().describe(t('mcp.param.diffFrom')).optional(),
|
|
14
|
+
to: z.number().int().describe(t('mcp.param.diffTo')),
|
|
15
|
+
});
|
|
16
|
+
const restoreInput = z.object({
|
|
17
|
+
id: z.string().describe(t('mcp.param.id')),
|
|
18
|
+
revisionId: z.number().int().describe(t('mcp.param.restoreRevisionId')),
|
|
19
|
+
message: z.string().describe(t('mcp.param.message')).optional(),
|
|
20
|
+
});
|
|
21
|
+
async function listRevisions(deps, args) {
|
|
22
|
+
const doc = await documentOf(deps, args.id);
|
|
23
|
+
const revisions = (await deps.core.listRevisions(doc.id)).sort((a, b) => b.id - a.id).slice(0, args.limit ?? 20);
|
|
24
|
+
return {
|
|
25
|
+
revisions: revisions.map((r) => ({
|
|
26
|
+
id: r.id,
|
|
27
|
+
createdAt: r.createdAt,
|
|
28
|
+
author: r.authorName,
|
|
29
|
+
source: r.source,
|
|
30
|
+
message: r.message,
|
|
31
|
+
isHead: r.id === doc.headRev,
|
|
32
|
+
isPublished: r.id === doc.publishedRev,
|
|
33
|
+
})),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function diffRevisions(deps, args) {
|
|
37
|
+
for (const revisionId of [args.from, args.to]) {
|
|
38
|
+
if (revisionId !== undefined && !(await deps.core.getRevision(revisionId))) {
|
|
39
|
+
throw new InlayError('not_found', 'mcp.revisionNotFound', { revisionId });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { changes: formatDiff(await deps.core.diffRevisions(args.from ?? null, args.to)) };
|
|
43
|
+
}
|
|
44
|
+
async function restoreRevision(deps, args, ctx) {
|
|
45
|
+
const doc = await documentOf(deps, args.id);
|
|
46
|
+
const revision = await deps.core.getRevision(args.revisionId);
|
|
47
|
+
if (!revision || revision.documentId !== doc.id) {
|
|
48
|
+
throw new InlayError('not_found', 'mcp.revisionNotFound', { revisionId: args.revisionId });
|
|
49
|
+
}
|
|
50
|
+
const result = await deps.core.restoreRevision(doc.id, args.revisionId, ctx, {
|
|
51
|
+
...(args.message !== undefined && { message: args.message }),
|
|
52
|
+
});
|
|
53
|
+
const { document } = result;
|
|
54
|
+
const path = await livePath(deps, document);
|
|
55
|
+
return {
|
|
56
|
+
id: document.id,
|
|
57
|
+
revisionId: document.headRev,
|
|
58
|
+
changed: result.changed,
|
|
59
|
+
changes: formatDiff(result.diff),
|
|
60
|
+
previewUrl: previewLink(deps, path ?? '/'),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** `list_revisions`, `diff_revisions` and `restore_revision`. */
|
|
64
|
+
export function register(server, deps, ctx) {
|
|
65
|
+
const run = (fn) => tool(async (args) => ok(await fn(args)), deps.log);
|
|
66
|
+
server.registerTool('list_revisions', {
|
|
67
|
+
title: t('mcp.tool.list_revisions.title'),
|
|
68
|
+
description: t('mcp.tool.list_revisions.description'),
|
|
69
|
+
inputSchema: listInput,
|
|
70
|
+
annotations: READ_ONLY,
|
|
71
|
+
}, run((args) => listRevisions(deps, args)));
|
|
72
|
+
server.registerTool('diff_revisions', {
|
|
73
|
+
title: t('mcp.tool.diff_revisions.title'),
|
|
74
|
+
description: t('mcp.tool.diff_revisions.description'),
|
|
75
|
+
inputSchema: diffInput,
|
|
76
|
+
annotations: READ_ONLY,
|
|
77
|
+
}, run((args) => diffRevisions(deps, args)));
|
|
78
|
+
server.registerTool('restore_revision', {
|
|
79
|
+
title: t('mcp.tool.restore_revision.title'),
|
|
80
|
+
description: t('mcp.tool.restore_revision.description'),
|
|
81
|
+
inputSchema: restoreInput,
|
|
82
|
+
annotations: EDIT,
|
|
83
|
+
}, run((args) => restoreRevision(deps, args, ctx)));
|
|
84
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { Ctx } from '../../../core/types.js';
|
|
3
|
+
import type { McpDeps } from '../server.js';
|
|
4
|
+
/** `list_media`, `set_media_alt`, `delete_media`, `upload_media_from_url` and `request_media_upload`. */
|
|
5
|
+
export declare function register(server: McpServer, deps: McpDeps, ctx: Ctx): void;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createUploadToken, UPLOAD_TTL_MS } from '../../../core/auth/upload-token.js';
|
|
3
|
+
import { InlayError } from '../../../core/errors.js';
|
|
4
|
+
import { t } from '../../../core/messages/index.js';
|
|
5
|
+
import { mediaUrl } from '../agent-refs.js';
|
|
6
|
+
import { DESTRUCTIVE, IDEMPOTENT_EDIT, READ_ONLY } from '../documents.js';
|
|
7
|
+
import { ok, tool } from '../results.js';
|
|
8
|
+
const FETCH = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
|
9
|
+
const LINK = { readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
10
|
+
const listMediaInput = z.object({
|
|
11
|
+
kind: z.enum(['image', 'file']).describe(t('mcp.param.mediaKind')).optional(),
|
|
12
|
+
search: z.string().describe(t('mcp.param.mediaSearch')).optional(),
|
|
13
|
+
limit: z.number().int().min(1).max(100).describe(t('mcp.param.mediaLimit')).optional(),
|
|
14
|
+
offset: z.number().int().min(0).describe(t('mcp.param.mediaOffset')).optional(),
|
|
15
|
+
});
|
|
16
|
+
const setMediaAltInput = z.object({
|
|
17
|
+
id: z.string().describe(t('mcp.param.mediaId')),
|
|
18
|
+
alt: z.string().nullable().describe(t('mcp.param.alt')),
|
|
19
|
+
});
|
|
20
|
+
const deleteMediaInput = z.object({ id: z.string().describe(t('mcp.param.mediaId')) });
|
|
21
|
+
const uploadFromUrlInput = z.object({
|
|
22
|
+
url: z.string().describe(t('mcp.param.url')),
|
|
23
|
+
filename: z.string().describe(t('mcp.param.filename')).optional(),
|
|
24
|
+
alt: z.string().describe(t('mcp.param.uploadAlt')).optional(),
|
|
25
|
+
});
|
|
26
|
+
/** A media file as tools show it, with its address. */
|
|
27
|
+
function mediaJson(deps, media) {
|
|
28
|
+
const { id, filename, mime, size, width, height, defaultAlt } = media;
|
|
29
|
+
return { id, filename, mime, size, width, height, defaultAlt, url: mediaUrl(deps.baseUrl, id) };
|
|
30
|
+
}
|
|
31
|
+
async function listMedia(deps, args) {
|
|
32
|
+
const media = await deps.core.listMedia({
|
|
33
|
+
...(args.kind !== undefined && { kind: args.kind }),
|
|
34
|
+
...(args.search !== undefined && { search: args.search }),
|
|
35
|
+
limit: args.limit ?? 30,
|
|
36
|
+
offset: args.offset ?? 0,
|
|
37
|
+
});
|
|
38
|
+
return { media: media.map((m) => mediaJson(deps, m)) };
|
|
39
|
+
}
|
|
40
|
+
async function deleteMedia(deps, args, ctx) {
|
|
41
|
+
const media = await deps.core.getMedia(args.id);
|
|
42
|
+
if (!media)
|
|
43
|
+
throw new InlayError('not_found', 'error.mediaNotFound');
|
|
44
|
+
await deps.core.deleteMedia(args.id, ctx);
|
|
45
|
+
return { deleted: { id: media.id, filename: media.filename } };
|
|
46
|
+
}
|
|
47
|
+
/** Adds the file at `args.url`. `alt` is set on a new file, or on a reused one without alt text; one with its own keeps it. */
|
|
48
|
+
async function uploadFromUrl(deps, args, ctx) {
|
|
49
|
+
const file = await deps.fetchFile(args.url, { maxBytes: deps.uploads.maxBytes });
|
|
50
|
+
const added = await deps.core.addMedia({ data: file.data, filename: args.filename ?? file.filename }, ctx);
|
|
51
|
+
const media = args.alt === undefined || (added.reused && added.media.defaultAlt !== null)
|
|
52
|
+
? added.media
|
|
53
|
+
: await deps.core.setMediaAlt(added.media.id, args.alt, ctx);
|
|
54
|
+
return { media: mediaJson(deps, media), reused: added.reused };
|
|
55
|
+
}
|
|
56
|
+
/** A link to `/admin/upload` that lets whoever opens it upload as this user for an hour. */
|
|
57
|
+
function requestUpload(deps, ctx) {
|
|
58
|
+
if (ctx.actor.id === null)
|
|
59
|
+
throw new InlayError('forbidden', 'error.forbidden');
|
|
60
|
+
// Upload links run on the real clock, like the rest of authentication; the page checks them the same way.
|
|
61
|
+
const now = new Date();
|
|
62
|
+
const token = createUploadToken(deps.secret, ctx.actor.id, now);
|
|
63
|
+
return {
|
|
64
|
+
uploadUrl: `${deps.baseUrl}/admin/upload?token=${encodeURIComponent(token)}`,
|
|
65
|
+
expiresAt: new Date(now.getTime() + UPLOAD_TTL_MS).toISOString(),
|
|
66
|
+
note: t('mcp.uploadNote'),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** `list_media`, `set_media_alt`, `delete_media`, `upload_media_from_url` and `request_media_upload`. */
|
|
70
|
+
export function register(server, deps, ctx) {
|
|
71
|
+
const run = (fn) => tool(async (args) => ok(await fn(args)), deps.log);
|
|
72
|
+
server.registerTool('list_media', {
|
|
73
|
+
title: t('mcp.tool.list_media.title'),
|
|
74
|
+
description: t('mcp.tool.list_media.description'),
|
|
75
|
+
inputSchema: listMediaInput,
|
|
76
|
+
annotations: READ_ONLY,
|
|
77
|
+
}, run((args) => listMedia(deps, args)));
|
|
78
|
+
server.registerTool('set_media_alt', {
|
|
79
|
+
title: t('mcp.tool.set_media_alt.title'),
|
|
80
|
+
description: t('mcp.tool.set_media_alt.description'),
|
|
81
|
+
inputSchema: setMediaAltInput,
|
|
82
|
+
annotations: IDEMPOTENT_EDIT,
|
|
83
|
+
}, run(async (args) => mediaJson(deps, await deps.core.setMediaAlt(args.id, args.alt, ctx))));
|
|
84
|
+
server.registerTool('delete_media', {
|
|
85
|
+
title: t('mcp.tool.delete_media.title'),
|
|
86
|
+
description: t('mcp.tool.delete_media.description'),
|
|
87
|
+
inputSchema: deleteMediaInput,
|
|
88
|
+
annotations: DESTRUCTIVE,
|
|
89
|
+
}, run((args) => deleteMedia(deps, args, ctx)));
|
|
90
|
+
server.registerTool('upload_media_from_url', {
|
|
91
|
+
title: t('mcp.tool.upload_media_from_url.title'),
|
|
92
|
+
description: t('mcp.tool.upload_media_from_url.description'),
|
|
93
|
+
inputSchema: uploadFromUrlInput,
|
|
94
|
+
annotations: FETCH,
|
|
95
|
+
}, run((args) => uploadFromUrl(deps, args, ctx)));
|
|
96
|
+
server.registerTool('request_media_upload', {
|
|
97
|
+
title: t('mcp.tool.request_media_upload.title'),
|
|
98
|
+
description: t('mcp.tool.request_media_upload.description'),
|
|
99
|
+
inputSchema: z.object({}),
|
|
100
|
+
annotations: LINK,
|
|
101
|
+
}, run(() => requestUpload(deps, ctx)));
|
|
102
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { Ctx } from '../../../core/types.js';
|
|
3
|
+
import type { McpDeps } from '../server.js';
|
|
4
|
+
/** `publish` and `unpublish`: both need the user's confirmation, through elicitation or the publish page. */
|
|
5
|
+
export declare function register(server: McpServer, deps: McpDeps, ctx: Ctx): void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { acceptedContent, CLIENT_CAPABILITIES_META_KEY, inputRequired, inputResponse, } from '@modelcontextprotocol/server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { t } from '../../../core/messages/index.js';
|
|
5
|
+
import { pageUrl } from '../agent-refs.js';
|
|
6
|
+
import { DESTRUCTIVE, IDEMPOTENT_EDIT, livePath } from '../documents.js';
|
|
7
|
+
import { requestStateCodec } from '../request-state.js';
|
|
8
|
+
import { ok, tool } from '../results.js';
|
|
9
|
+
const MAX_CHANGE_LINES = 3;
|
|
10
|
+
const publishInput = z.object({
|
|
11
|
+
ids: z.array(z.string()).min(1).max(50).describe(t('mcp.param.publishIds')),
|
|
12
|
+
message: z.string().describe(t('mcp.param.message')).optional(),
|
|
13
|
+
});
|
|
14
|
+
const unpublishInput = z.object({
|
|
15
|
+
ids: z.array(z.string()).min(1).max(50).describe(t('mcp.param.unpublishIds')),
|
|
16
|
+
});
|
|
17
|
+
const confirmSchema = z.object({ confirm: z.boolean().describe(t('mcp.confirm.field')) });
|
|
18
|
+
const COPY = {
|
|
19
|
+
publish: {
|
|
20
|
+
key: 'published',
|
|
21
|
+
confirm: 'mcp.confirm.publish',
|
|
22
|
+
declined: 'mcp.publishDeclined',
|
|
23
|
+
byLink: 'mcp.confirmByLink',
|
|
24
|
+
nothing: 'mcp.nothingToPublish',
|
|
25
|
+
},
|
|
26
|
+
unpublish: {
|
|
27
|
+
key: 'unpublished',
|
|
28
|
+
confirm: 'mcp.confirm.unpublish',
|
|
29
|
+
declined: 'mcp.unpublishDeclined',
|
|
30
|
+
byLink: 'mcp.confirmUnpublishByLink',
|
|
31
|
+
nothing: 'mcp.nothingToUnpublish',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
/** Whether the client said, on this very request, that it can show a form to the user. */
|
|
35
|
+
function canElicit(mcpCtx) {
|
|
36
|
+
// The published typings declare the envelope as `{}`; its client-capabilities key holds `ClientCapabilities`.
|
|
37
|
+
const envelope = mcpCtx.mcpReq.envelope;
|
|
38
|
+
const elicitation = envelope?.[CLIENT_CAPABILITIES_META_KEY]?.elicitation;
|
|
39
|
+
if (elicitation === undefined)
|
|
40
|
+
return false;
|
|
41
|
+
return elicitation.form !== undefined || elicitation.url === undefined;
|
|
42
|
+
}
|
|
43
|
+
/** The question the user is asked: a heading, then each document with its first few changes. */
|
|
44
|
+
async function confirmMessage(deps, action, ids) {
|
|
45
|
+
const lines = [t(COPY[action].confirm, { count: ids.length })];
|
|
46
|
+
for (const { document, isNew, lines: changes } of await deps.core.describeChanges(ids)) {
|
|
47
|
+
const item = { title: document.title, locale: document.locale };
|
|
48
|
+
lines.push(isNew && action === 'publish' ? t('mcp.confirm.itemNew', item) : t('mcp.confirm.item', item));
|
|
49
|
+
if (action === 'unpublish')
|
|
50
|
+
continue;
|
|
51
|
+
for (const line of changes.slice(0, MAX_CHANGE_LINES))
|
|
52
|
+
lines.push(t('mcp.confirm.change', { line }));
|
|
53
|
+
if (changes.length > MAX_CHANGE_LINES)
|
|
54
|
+
lines.push(t('mcp.confirm.moreChanges'));
|
|
55
|
+
}
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
/** The page where the user can confirm in their browser instead. */
|
|
59
|
+
function confirmUrl(deps, action, ids) {
|
|
60
|
+
return `${deps.baseUrl}/admin/publish?ids=${ids.map(encodeURIComponent).join(',')}&action=${action}`;
|
|
61
|
+
}
|
|
62
|
+
/** Each document `ids` names, with its live URL after publishing. */
|
|
63
|
+
async function describeDone(deps, action, ids) {
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const id of ids) {
|
|
66
|
+
const doc = await deps.core.getDocument(id);
|
|
67
|
+
if (!doc)
|
|
68
|
+
continue;
|
|
69
|
+
const item = { id, title: doc.title, locale: doc.locale };
|
|
70
|
+
if (action === 'unpublish') {
|
|
71
|
+
out.push(item);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
out.push({ ...item, url: pageUrl(deps.baseUrl, await livePath(deps, doc, 'published')) });
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The second call: the user answered. Publishes exactly what the signed state says they were shown, once: the
|
|
80
|
+
* state's nonce is used up before anything is published, and a state whose nonce was already used counts as declined.
|
|
81
|
+
*/
|
|
82
|
+
async function confirmed(deps, ctx, state, mcpCtx) {
|
|
83
|
+
const { action } = state;
|
|
84
|
+
const fresh = typeof state.nonce === 'string' && deps.confirmations.consume(state.nonce);
|
|
85
|
+
const answer = acceptedContent(mcpCtx.mcpReq.inputResponses, 'confirm', confirmSchema);
|
|
86
|
+
if (!fresh || answer?.confirm !== true)
|
|
87
|
+
return ok({ [COPY[action].key]: [], note: t(COPY[action].declined) });
|
|
88
|
+
const result = action === 'publish'
|
|
89
|
+
? await deps.core.publish(state.ids, ctx, {
|
|
90
|
+
expect: state.expect,
|
|
91
|
+
...(state.message !== undefined && { message: state.message }),
|
|
92
|
+
})
|
|
93
|
+
: await deps.core.unpublish(state.ids, ctx);
|
|
94
|
+
const done = result.items.map((item) => item.documentId);
|
|
95
|
+
return ok({ [COPY[action].key]: await describeDone(deps, action, done) });
|
|
96
|
+
}
|
|
97
|
+
/** The first call: check everything with a dry run, then ask the user, or hand back a link. */
|
|
98
|
+
async function ask(deps, ctx, action, args, mcpCtx) {
|
|
99
|
+
const expect = {};
|
|
100
|
+
if (action === 'publish') {
|
|
101
|
+
for (const id of new Set(args.ids)) {
|
|
102
|
+
const doc = await deps.core.getDocument(id);
|
|
103
|
+
if (doc)
|
|
104
|
+
expect[id] = doc.headRev;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const dry = action === 'publish'
|
|
108
|
+
? await deps.core.publish(args.ids, ctx, { dryRun: true, expect })
|
|
109
|
+
: await deps.core.unpublish(args.ids, ctx, { dryRun: true });
|
|
110
|
+
const ids = dry.items.map((item) => item.documentId);
|
|
111
|
+
if (ids.length === 0)
|
|
112
|
+
return ok({ [COPY[action].key]: [], note: t(COPY[action].nothing) });
|
|
113
|
+
if (!canElicit(mcpCtx)) {
|
|
114
|
+
return ok({ [COPY[action].key]: [], confirmUrl: confirmUrl(deps, action, ids), note: t(COPY[action].byLink) });
|
|
115
|
+
}
|
|
116
|
+
const state = {
|
|
117
|
+
action,
|
|
118
|
+
actorId: ctx.actor.id,
|
|
119
|
+
ids,
|
|
120
|
+
expect: Object.fromEntries(ids.flatMap((id) => (expect[id] === undefined ? [] : [[id, expect[id]]]))),
|
|
121
|
+
...(args.message !== undefined && { message: args.message }),
|
|
122
|
+
nonce: randomUUID(),
|
|
123
|
+
};
|
|
124
|
+
return inputRequired({
|
|
125
|
+
inputRequests: {
|
|
126
|
+
confirm: inputRequired.elicit({
|
|
127
|
+
message: await confirmMessage(deps, action, ids),
|
|
128
|
+
requestedSchema: confirmSchema,
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
requestState: await requestStateCodec(deps.secret).mint(state),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async function run(deps, ctx, action, args, mcpCtx) {
|
|
135
|
+
const answered = inputResponse(mcpCtx.mcpReq.inputResponses, 'confirm').kind !== 'missing';
|
|
136
|
+
// The state was verified (signature and expiry) before the handler ran; it must also be this tool's, for this user.
|
|
137
|
+
const state = mcpCtx.mcpReq.requestState();
|
|
138
|
+
if (answered && state?.action === action && state.actorId === ctx.actor.id) {
|
|
139
|
+
return confirmed(deps, ctx, state, mcpCtx);
|
|
140
|
+
}
|
|
141
|
+
return ask(deps, ctx, action, args, mcpCtx);
|
|
142
|
+
}
|
|
143
|
+
/** `publish` and `unpublish`: both need the user's confirmation, through elicitation or the publish page. */
|
|
144
|
+
export function register(server, deps, ctx) {
|
|
145
|
+
server.registerTool('publish', {
|
|
146
|
+
title: t('mcp.tool.publish.title'),
|
|
147
|
+
description: t('mcp.tool.publish.description'),
|
|
148
|
+
inputSchema: publishInput,
|
|
149
|
+
annotations: IDEMPOTENT_EDIT,
|
|
150
|
+
}, tool((args, mcpCtx) => run(deps, ctx, 'publish', args, mcpCtx), deps.log));
|
|
151
|
+
server.registerTool('unpublish', {
|
|
152
|
+
title: t('mcp.tool.unpublish.title'),
|
|
153
|
+
description: t('mcp.tool.unpublish.description'),
|
|
154
|
+
inputSchema: unpublishInput,
|
|
155
|
+
annotations: DESTRUCTIVE,
|
|
156
|
+
}, tool((args, mcpCtx) => run(deps, ctx, 'unpublish', args, mcpCtx), deps.log));
|
|
157
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { Ctx } from '../../../core/types.js';
|
|
3
|
+
import type { McpDeps } from '../server.js';
|
|
4
|
+
/** `describe_site`, `describe_type`, `get_document`, `search_entries` and `list_gaps`. */
|
|
5
|
+
export declare function register(server: McpServer, deps: McpDeps, _ctx: Ctx): void;
|