inlaycms 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +462 -2
  3. package/assets/admin/admin.css +2 -0
  4. package/assets/admin/admin.js +1 -0
  5. package/assets/admin/editor.js +125 -0
  6. package/dist/adapters/admin/activity.d.ts +17 -0
  7. package/dist/adapters/admin/activity.js +59 -0
  8. package/dist/adapters/admin/assets.d.ts +14 -0
  9. package/dist/adapters/admin/assets.js +64 -0
  10. package/dist/adapters/admin/attention.d.ts +15 -0
  11. package/dist/adapters/admin/attention.js +34 -0
  12. package/dist/adapters/admin/context.d.ts +40 -0
  13. package/dist/adapters/admin/context.js +142 -0
  14. package/dist/adapters/admin/form/walk.d.ts +61 -0
  15. package/dist/adapters/admin/form/walk.js +565 -0
  16. package/dist/adapters/admin/pages.d.ts +38 -0
  17. package/dist/adapters/admin/pages.js +66 -0
  18. package/dist/adapters/admin/publish.d.ts +12 -0
  19. package/dist/adapters/admin/publish.js +195 -0
  20. package/dist/adapters/admin/routes.d.ts +47 -0
  21. package/dist/adapters/admin/routes.js +255 -0
  22. package/dist/adapters/admin/screens/backups.d.ts +11 -0
  23. package/dist/adapters/admin/screens/backups.js +223 -0
  24. package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
  25. package/dist/adapters/admin/screens/dashboard.js +160 -0
  26. package/dist/adapters/admin/screens/editor.d.ts +67 -0
  27. package/dist/adapters/admin/screens/editor.js +416 -0
  28. package/dist/adapters/admin/screens/history.d.ts +4 -0
  29. package/dist/adapters/admin/screens/history.js +105 -0
  30. package/dist/adapters/admin/screens/lists.d.ts +4 -0
  31. package/dist/adapters/admin/screens/lists.js +297 -0
  32. package/dist/adapters/admin/screens/media.d.ts +20 -0
  33. package/dist/adapters/admin/screens/media.js +186 -0
  34. package/dist/adapters/admin/screens/pickers.d.ts +29 -0
  35. package/dist/adapters/admin/screens/pickers.js +134 -0
  36. package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
  37. package/dist/adapters/admin/screens/preview-pane.js +74 -0
  38. package/dist/adapters/admin/screens/redirects.d.ts +4 -0
  39. package/dist/adapters/admin/screens/redirects.js +137 -0
  40. package/dist/adapters/admin/screens/releases.d.ts +7 -0
  41. package/dist/adapters/admin/screens/releases.js +287 -0
  42. package/dist/adapters/admin/screens/search.d.ts +22 -0
  43. package/dist/adapters/admin/screens/search.js +113 -0
  44. package/dist/adapters/admin/screens/security.d.ts +4 -0
  45. package/dist/adapters/admin/screens/security.js +85 -0
  46. package/dist/adapters/admin/screens/users.d.ts +4 -0
  47. package/dist/adapters/admin/screens/users.js +330 -0
  48. package/dist/adapters/admin/theme.d.ts +1 -0
  49. package/dist/adapters/admin/theme.js +1 -0
  50. package/dist/adapters/admin/translations.d.ts +16 -0
  51. package/dist/adapters/admin/translations.js +23 -0
  52. package/dist/adapters/admin/upload.d.ts +8 -0
  53. package/dist/adapters/admin/upload.js +116 -0
  54. package/dist/adapters/admin/views/data-table.d.ts +82 -0
  55. package/dist/adapters/admin/views/data-table.js +117 -0
  56. package/dist/adapters/admin/views/icons.d.ts +48 -0
  57. package/dist/adapters/admin/views/icons.js +47 -0
  58. package/dist/adapters/admin/views/layout.d.ts +51 -0
  59. package/dist/adapters/admin/views/layout.js +145 -0
  60. package/dist/adapters/admin/views/sheet.d.ts +15 -0
  61. package/dist/adapters/admin/views/sheet.js +6 -0
  62. package/dist/adapters/admin/views/status.d.ts +32 -0
  63. package/dist/adapters/admin/views/status.js +74 -0
  64. package/dist/adapters/auth/handler.d.ts +10 -0
  65. package/dist/adapters/auth/handler.js +63 -0
  66. package/dist/adapters/auth/request.d.ts +8 -0
  67. package/dist/adapters/auth/request.js +14 -0
  68. package/dist/adapters/cli/bin.d.ts +2 -0
  69. package/dist/adapters/cli/bin.js +42 -0
  70. package/dist/adapters/cli/main.d.ts +7 -0
  71. package/dist/adapters/cli/main.js +982 -0
  72. package/dist/adapters/cli/remote.d.ts +52 -0
  73. package/dist/adapters/cli/remote.js +161 -0
  74. package/dist/adapters/mcp/agent-refs.d.ts +9 -0
  75. package/dist/adapters/mcp/agent-refs.js +25 -0
  76. package/dist/adapters/mcp/documents.d.ts +15 -0
  77. package/dist/adapters/mcp/documents.js +26 -0
  78. package/dist/adapters/mcp/fetch-url.d.ts +19 -0
  79. package/dist/adapters/mcp/fetch-url.js +244 -0
  80. package/dist/adapters/mcp/request-state.d.ts +15 -0
  81. package/dist/adapters/mcp/request-state.js +38 -0
  82. package/dist/adapters/mcp/results.d.ts +20 -0
  83. package/dist/adapters/mcp/results.js +61 -0
  84. package/dist/adapters/mcp/route.d.ts +34 -0
  85. package/dist/adapters/mcp/route.js +52 -0
  86. package/dist/adapters/mcp/server.d.ts +44 -0
  87. package/dist/adapters/mcp/server.js +49 -0
  88. package/dist/adapters/mcp/tools/history.d.ts +5 -0
  89. package/dist/adapters/mcp/tools/history.js +84 -0
  90. package/dist/adapters/mcp/tools/media.d.ts +5 -0
  91. package/dist/adapters/mcp/tools/media.js +102 -0
  92. package/dist/adapters/mcp/tools/publish.d.ts +5 -0
  93. package/dist/adapters/mcp/tools/publish.js +157 -0
  94. package/dist/adapters/mcp/tools/read.d.ts +5 -0
  95. package/dist/adapters/mcp/tools/read.js +279 -0
  96. package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
  97. package/dist/adapters/mcp/tools/redirects.js +74 -0
  98. package/dist/adapters/mcp/tools/write.d.ts +5 -0
  99. package/dist/adapters/mcp/tools/write.js +304 -0
  100. package/dist/adapters/site/backup-schedule.d.ts +8 -0
  101. package/dist/adapters/site/backup-schedule.js +31 -0
  102. package/dist/adapters/site/cache.d.ts +29 -0
  103. package/dist/adapters/site/cache.js +63 -0
  104. package/dist/adapters/site/context.d.ts +29 -0
  105. package/dist/adapters/site/context.js +278 -0
  106. package/dist/adapters/site/head.d.ts +23 -0
  107. package/dist/adapters/site/head.js +44 -0
  108. package/dist/adapters/site/limiter.d.ts +17 -0
  109. package/dist/adapters/site/limiter.js +39 -0
  110. package/dist/adapters/site/lock.d.ts +30 -0
  111. package/dist/adapters/site/lock.js +143 -0
  112. package/dist/adapters/site/media-routes.d.ts +4 -0
  113. package/dist/adapters/site/media-routes.js +55 -0
  114. package/dist/adapters/site/plugin.d.ts +122 -0
  115. package/dist/adapters/site/plugin.js +436 -0
  116. package/dist/adapters/site/preview.d.ts +36 -0
  117. package/dist/adapters/site/preview.js +82 -0
  118. package/dist/adapters/site/public.d.ts +6 -0
  119. package/dist/adapters/site/public.js +87 -0
  120. package/dist/adapters/site/render.d.ts +45 -0
  121. package/dist/adapters/site/render.js +191 -0
  122. package/dist/adapters/site/routes.d.ts +17 -0
  123. package/dist/adapters/site/routes.js +125 -0
  124. package/dist/adapters/site/sitemap.d.ts +10 -0
  125. package/dist/adapters/site/sitemap.js +10 -0
  126. package/dist/adapters/web.d.ts +22 -0
  127. package/dist/adapters/web.js +75 -0
  128. package/dist/config.d.ts +21 -0
  129. package/dist/config.js +58 -0
  130. package/dist/core/agent/format.d.ts +62 -0
  131. package/dist/core/agent/format.js +211 -0
  132. package/dist/core/agent/schema.d.ts +6 -0
  133. package/dist/core/agent/schema.js +86 -0
  134. package/dist/core/archive.d.ts +12 -0
  135. package/dist/core/archive.js +72 -0
  136. package/dist/core/auth/auth.d.ts +4911 -0
  137. package/dist/core/auth/auth.js +61 -0
  138. package/dist/core/auth/roles.d.ts +10 -0
  139. package/dist/core/auth/roles.js +38 -0
  140. package/dist/core/auth/service.d.ts +118 -0
  141. package/dist/core/auth/service.js +424 -0
  142. package/dist/core/auth/upload-token.d.ts +8 -0
  143. package/dist/core/auth/upload-token.js +27 -0
  144. package/dist/core/backup/backup.d.ts +28 -0
  145. package/dist/core/backup/backup.js +126 -0
  146. package/dist/core/backup/restore.d.ts +41 -0
  147. package/dist/core/backup/restore.js +264 -0
  148. package/dist/core/backup/schedule.d.ts +12 -0
  149. package/dist/core/backup/schedule.js +29 -0
  150. package/dist/core/boot.d.ts +63 -0
  151. package/dist/core/boot.js +141 -0
  152. package/dist/core/check.d.ts +32 -0
  153. package/dist/core/check.js +111 -0
  154. package/dist/core/content/activity.d.ts +8 -0
  155. package/dist/core/content/activity.js +101 -0
  156. package/dist/core/content/delete.d.ts +5 -0
  157. package/dist/core/content/delete.js +100 -0
  158. package/dist/core/content/diff.d.ts +6 -0
  159. package/dist/core/content/diff.js +129 -0
  160. package/dist/core/content/dry-run.d.ts +24 -0
  161. package/dist/core/content/dry-run.js +69 -0
  162. package/dist/core/content/gaps.d.ts +25 -0
  163. package/dist/core/content/gaps.js +50 -0
  164. package/dist/core/content/hidden.d.ts +33 -0
  165. package/dist/core/content/hidden.js +103 -0
  166. package/dist/core/content/history.d.ts +15 -0
  167. package/dist/core/content/history.js +62 -0
  168. package/dist/core/content/patch.d.ts +40 -0
  169. package/dist/core/content/patch.js +287 -0
  170. package/dist/core/content/path.d.ts +6 -0
  171. package/dist/core/content/path.js +38 -0
  172. package/dist/core/content/publish.d.ts +26 -0
  173. package/dist/core/content/publish.js +211 -0
  174. package/dist/core/content/read.d.ts +99 -0
  175. package/dist/core/content/read.js +141 -0
  176. package/dist/core/content/reader.d.ts +37 -0
  177. package/dist/core/content/reader.js +195 -0
  178. package/dist/core/content/refs.d.ts +44 -0
  179. package/dist/core/content/refs.js +161 -0
  180. package/dist/core/content/release-migrations.d.ts +12 -0
  181. package/dist/core/content/release-migrations.js +154 -0
  182. package/dist/core/content/save.d.ts +25 -0
  183. package/dist/core/content/save.js +87 -0
  184. package/dist/core/content/schema.d.ts +22 -0
  185. package/dist/core/content/schema.js +127 -0
  186. package/dist/core/content/search.d.ts +8 -0
  187. package/dist/core/content/search.js +89 -0
  188. package/dist/core/content/shipped-input.d.ts +39 -0
  189. package/dist/core/content/shipped-input.js +221 -0
  190. package/dist/core/content/shipped.d.ts +112 -0
  191. package/dist/core/content/shipped.js +437 -0
  192. package/dist/core/content/slug.d.ts +23 -0
  193. package/dist/core/content/slug.js +182 -0
  194. package/dist/core/content/stats.d.ts +11 -0
  195. package/dist/core/content/stats.js +30 -0
  196. package/dist/core/content/translate.d.ts +3 -0
  197. package/dist/core/content/translate.js +68 -0
  198. package/dist/core/content/usages.d.ts +13 -0
  199. package/dist/core/content/usages.js +70 -0
  200. package/dist/core/content/validate.d.ts +21 -0
  201. package/dist/core/content/validate.js +124 -0
  202. package/dist/core/content/write.d.ts +10 -0
  203. package/dist/core/content/write.js +93 -0
  204. package/dist/core/core.d.ts +227 -0
  205. package/dist/core/core.js +251 -0
  206. package/dist/core/db/connection.d.ts +6 -0
  207. package/dist/core/db/connection.js +12 -0
  208. package/dist/core/db/migrate.d.ts +9 -0
  209. package/dist/core/db/migrate.js +42 -0
  210. package/dist/core/db/migrations/0001_content.d.ts +2 -0
  211. package/dist/core/db/migrations/0001_content.js +69 -0
  212. package/dist/core/db/migrations/0002_media.d.ts +2 -0
  213. package/dist/core/db/migrations/0002_media.js +26 -0
  214. package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
  215. package/dist/core/db/migrations/0003_redirects.js +19 -0
  216. package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
  217. package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
  218. package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
  219. package/dist/core/db/migrations/0005_site_lock.js +10 -0
  220. package/dist/core/db/migrations/0006_releases.d.ts +3 -0
  221. package/dist/core/db/migrations/0006_releases.js +34 -0
  222. package/dist/core/db/schema.d.ts +155 -0
  223. package/dist/core/db/schema.js +1 -0
  224. package/dist/core/errors.d.ts +27 -0
  225. package/dist/core/errors.js +15 -0
  226. package/dist/core/export/export.d.ts +17 -0
  227. package/dist/core/export/export.js +185 -0
  228. package/dist/core/export/format.d.ts +241 -0
  229. package/dist/core/export/format.js +106 -0
  230. package/dist/core/export/import.d.ts +54 -0
  231. package/dist/core/export/import.js +180 -0
  232. package/dist/core/export/read.d.ts +16 -0
  233. package/dist/core/export/read.js +234 -0
  234. package/dist/core/export/replace.d.ts +17 -0
  235. package/dist/core/export/replace.js +36 -0
  236. package/dist/core/export/report.d.ts +55 -0
  237. package/dist/core/export/report.js +50 -0
  238. package/dist/core/export/schema.d.ts +8 -0
  239. package/dist/core/export/schema.js +47 -0
  240. package/dist/core/export/stage.d.ts +25 -0
  241. package/dist/core/export/stage.js +192 -0
  242. package/dist/core/fields/builtins.d.ts +70 -0
  243. package/dist/core/fields/builtins.js +335 -0
  244. package/dist/core/fields/define.d.ts +86 -0
  245. package/dist/core/fields/define.js +34 -0
  246. package/dist/core/fields/walk.d.ts +49 -0
  247. package/dist/core/fields/walk.js +270 -0
  248. package/dist/core/fields/widgets.d.ts +27 -0
  249. package/dist/core/fields/widgets.js +330 -0
  250. package/dist/core/fields/zod-internals.d.ts +29 -0
  251. package/dist/core/fields/zod-internals.js +28 -0
  252. package/dist/core/media/detect.d.ts +5 -0
  253. package/dist/core/media/detect.js +66 -0
  254. package/dist/core/media/labels.d.ts +6 -0
  255. package/dist/core/media/labels.js +17 -0
  256. package/dist/core/media/library.d.ts +45 -0
  257. package/dist/core/media/library.js +239 -0
  258. package/dist/core/media/store.d.ts +11 -0
  259. package/dist/core/media/store.js +49 -0
  260. package/dist/core/media/variants.d.ts +10 -0
  261. package/dist/core/media/variants.js +59 -0
  262. package/dist/core/messages/en.d.ts +1278 -0
  263. package/dist/core/messages/en.js +1287 -0
  264. package/dist/core/messages/index.d.ts +7 -0
  265. package/dist/core/messages/index.js +14 -0
  266. package/dist/core/preview.d.ts +16 -0
  267. package/dist/core/preview.js +42 -0
  268. package/dist/core/redirects/collapse.d.ts +68 -0
  269. package/dist/core/redirects/collapse.js +153 -0
  270. package/dist/core/redirects/csv.d.ts +15 -0
  271. package/dist/core/redirects/csv.js +68 -0
  272. package/dist/core/redirects/redirects.d.ts +58 -0
  273. package/dist/core/redirects/redirects.js +545 -0
  274. package/dist/core/registry/content.d.ts +26 -0
  275. package/dist/core/registry/content.js +9 -0
  276. package/dist/core/registry/define.d.ts +145 -0
  277. package/dist/core/registry/define.js +41 -0
  278. package/dist/core/registry/migration.d.ts +44 -0
  279. package/dist/core/registry/migration.js +4 -0
  280. package/dist/core/registry/registry.d.ts +18 -0
  281. package/dist/core/registry/registry.js +255 -0
  282. package/dist/core/registry/render.d.ts +98 -0
  283. package/dist/core/registry/render.js +1 -0
  284. package/dist/core/registry/route.d.ts +42 -0
  285. package/dist/core/registry/route.js +3 -0
  286. package/dist/core/release/bundle.d.ts +21 -0
  287. package/dist/core/release/bundle.js +252 -0
  288. package/dist/core/release/keys.d.ts +11 -0
  289. package/dist/core/release/keys.js +60 -0
  290. package/dist/core/release/manifest.d.ts +103 -0
  291. package/dist/core/release/manifest.js +138 -0
  292. package/dist/core/release/pack.d.ts +20 -0
  293. package/dist/core/release/pack.js +97 -0
  294. package/dist/core/release/pointer.d.ts +19 -0
  295. package/dist/core/release/pointer.js +53 -0
  296. package/dist/core/release/read.d.ts +59 -0
  297. package/dist/core/release/read.js +256 -0
  298. package/dist/core/report.d.ts +31 -0
  299. package/dist/core/report.js +37 -0
  300. package/dist/core/richtext/html.d.ts +15 -0
  301. package/dist/core/richtext/html.js +81 -0
  302. package/dist/core/richtext/markdown.d.ts +19 -0
  303. package/dist/core/richtext/markdown.js +951 -0
  304. package/dist/core/richtext/schema.d.ts +98 -0
  305. package/dist/core/richtext/schema.js +275 -0
  306. package/dist/core/site/live.d.ts +56 -0
  307. package/dist/core/site/live.js +145 -0
  308. package/dist/core/site/paths.d.ts +15 -0
  309. package/dist/core/site/paths.js +64 -0
  310. package/dist/core/site/resolve.d.ts +9 -0
  311. package/dist/core/site/resolve.js +202 -0
  312. package/dist/core/site/sitemap.d.ts +11 -0
  313. package/dist/core/site/sitemap.js +24 -0
  314. package/dist/core/site-lock/site-lock.d.ts +21 -0
  315. package/dist/core/site-lock/site-lock.js +65 -0
  316. package/dist/core/site-lock/token.d.ts +7 -0
  317. package/dist/core/site-lock/token.js +24 -0
  318. package/dist/core/theme.d.ts +22 -0
  319. package/dist/core/theme.js +133 -0
  320. package/dist/core/types.d.ts +253 -0
  321. package/dist/core/types.js +1 -0
  322. package/dist/core/version.d.ts +1 -0
  323. package/dist/core/version.js +5 -0
  324. package/dist/host/activate.d.ts +53 -0
  325. package/dist/host/activate.js +162 -0
  326. package/dist/host/app.d.ts +46 -0
  327. package/dist/host/app.js +129 -0
  328. package/dist/host/bin.d.ts +5 -0
  329. package/dist/host/bin.js +8 -0
  330. package/dist/host/config.d.ts +36 -0
  331. package/dist/host/config.js +152 -0
  332. package/dist/host/dev.d.ts +10 -0
  333. package/dist/host/dev.js +293 -0
  334. package/dist/host/diff.d.ts +78 -0
  335. package/dist/host/diff.js +346 -0
  336. package/dist/host/hooks.d.ts +41 -0
  337. package/dist/host/hooks.js +49 -0
  338. package/dist/host/ipc.d.ts +123 -0
  339. package/dist/host/ipc.js +61 -0
  340. package/dist/host/preview-proxy.d.ts +24 -0
  341. package/dist/host/preview-proxy.js +154 -0
  342. package/dist/host/preview-worker.d.ts +42 -0
  343. package/dist/host/preview-worker.js +242 -0
  344. package/dist/host/primary.d.ts +38 -0
  345. package/dist/host/primary.js +357 -0
  346. package/dist/host/push.d.ts +125 -0
  347. package/dist/host/push.js +420 -0
  348. package/dist/host/serve.d.ts +16 -0
  349. package/dist/host/serve.js +150 -0
  350. package/dist/host/store.d.ts +48 -0
  351. package/dist/host/store.js +109 -0
  352. package/dist/host/worker.d.ts +67 -0
  353. package/dist/host/worker.js +310 -0
  354. package/dist/index.d.ts +47 -0
  355. package/dist/index.js +32 -0
  356. package/dist/jsx/html.d.ts +16 -0
  357. package/dist/jsx/html.js +65 -0
  358. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  359. package/dist/jsx/jsx-dev-runtime.js +5 -0
  360. package/dist/jsx/jsx-runtime.d.ts +17 -0
  361. package/dist/jsx/jsx-runtime.js +41 -0
  362. package/dist/site.d.ts +17 -0
  363. package/dist/site.js +14 -0
  364. package/package.json +111 -3
@@ -0,0 +1,279 @@
1
+ import { z } from 'zod';
2
+ import { agentLinks, toAgent } from '../../../core/agent/format.js';
3
+ import { agentTypeSchema } from '../../../core/agent/schema.js';
4
+ import { docLabels } from '../../../core/content/schema.js';
5
+ import { InlayError } from '../../../core/errors.js';
6
+ import { t } from '../../../core/messages/index.js';
7
+ import { singletonPath, withLocale } from '../../../core/site/paths.js';
8
+ import { previewLink } from '../../site/preview.js';
9
+ import { loadAgentRefs, pageUrl } from '../agent-refs.js';
10
+ import { livePath, READ_ONLY } from '../documents.js';
11
+ import { issueJson, ok, tool } from '../results.js';
12
+ const describeTypeInput = z.object({ type: z.string().describe(t('mcp.param.type')) });
13
+ const listGapsInput = z.object({
14
+ type: z.string().describe(t('mcp.param.gapType')).optional(),
15
+ limit: z.number().int().min(1).max(100).describe(t('mcp.param.gapsLimit')).optional(),
16
+ offset: z.number().int().min(0).describe(t('mcp.param.gapsOffset')).optional(),
17
+ });
18
+ const getDocumentInput = z.object({
19
+ id: z.string().describe(t('mcp.param.id')).optional(),
20
+ type: z.string().describe(t('mcp.param.type')).optional(),
21
+ slug: z.string().describe(t('mcp.param.slug')).optional(),
22
+ locale: z.string().describe(t('mcp.param.documentLocale')).optional(),
23
+ state: z.enum(['draft', 'published']).describe(t('mcp.param.state')).optional(),
24
+ });
25
+ const searchEntriesInput = z.object({
26
+ collection: z.string().describe(t('mcp.param.collection')),
27
+ query: z.string().describe(t('mcp.param.query')).optional(),
28
+ locale: z.string().describe(t('mcp.param.locale')).optional(),
29
+ limit: z.number().int().min(1).max(50).describe(t('mcp.param.limit')).optional(),
30
+ });
31
+ /** `locale`, or the default locale when it's absent. An unknown locale is refused. */
32
+ function localeOf(registry, locale) {
33
+ if (locale === undefined)
34
+ return registry.defaultLocale;
35
+ if (!registry.locales.includes(locale)) {
36
+ throw new InlayError('invalid_operation', 'mcp.unknownLocale', { locale, locales: registry.locales.join(', ') });
37
+ }
38
+ return locale;
39
+ }
40
+ /**
41
+ * Refuses a type the site doesn't have: one with documents is hidden (spec §6.4), and says so without showing
42
+ * them; any other is the usual not-found.
43
+ */
44
+ async function requireType(deps, type) {
45
+ const { core } = deps;
46
+ if (core.registry.types.has(type))
47
+ return;
48
+ if ((await core.hiddenDocuments()).types.some((hidden) => hidden.type === type)) {
49
+ throw new InlayError('not_found', 'mcp.hiddenType', { type });
50
+ }
51
+ throw new InlayError('not_found', 'error.typeNotFound', { name: type });
52
+ }
53
+ async function describeSite(deps) {
54
+ const { core, baseUrl } = deps;
55
+ const { registry } = core;
56
+ const { locales, defaultLocale, site } = registry;
57
+ const documents = async (type) => {
58
+ const out = {};
59
+ for (const locale of locales) {
60
+ const doc = await core.findSingleton(type, locale);
61
+ if (doc)
62
+ out[locale] = { id: doc.id, groupId: doc.groupId, title: doc.title, published: doc.publishedRev !== null };
63
+ }
64
+ return out;
65
+ };
66
+ const singletons = [];
67
+ for (const def of site.singletons) {
68
+ const urls = {};
69
+ for (const locale of locales) {
70
+ const path = singletonPath(def, locale, defaultLocale);
71
+ if (path !== null)
72
+ urls[locale] = pageUrl(baseUrl, withLocale(registry, locale, path));
73
+ }
74
+ singletons.push({ type: def.name, label: def.label, help: def.help ?? null, urls, documents: await documents(def.name) });
75
+ }
76
+ const globals = [];
77
+ for (const def of site.globals) {
78
+ globals.push({ type: def.name, label: def.label, help: def.help ?? null, documents: await documents(def.name) });
79
+ }
80
+ const collections = [];
81
+ for (const def of site.collections) {
82
+ const entryCount = {};
83
+ for (const locale of locales)
84
+ entryCount[locale] = (await core.listEntries(def.name, { locale })).length;
85
+ collections.push({
86
+ type: def.name,
87
+ label: def.label,
88
+ help: def.help ?? null,
89
+ route: def.route,
90
+ routed: def.route !== null || def.customPaths,
91
+ customPaths: def.customPaths,
92
+ entryCount,
93
+ });
94
+ }
95
+ return {
96
+ guide: site.guide ?? null,
97
+ release: deps.release ? { name: deps.release.name } : null,
98
+ locales,
99
+ defaultLocale,
100
+ singletons,
101
+ globals,
102
+ collections,
103
+ gaps: await core.gapSummary(),
104
+ };
105
+ }
106
+ async function describeType(deps, type) {
107
+ const { registry } = deps.core;
108
+ await requireType(deps, type);
109
+ const def = registry.getType(type);
110
+ return {
111
+ type: def.name,
112
+ kind: def.kind,
113
+ label: def.label,
114
+ help: def.help ?? null,
115
+ ...(def.kind === 'collection' && { titleField: def.titleField }),
116
+ slots: Object.entries(def.template.slots).map(([key, slot]) => ({
117
+ key,
118
+ label: slot.label ?? slot.block.label,
119
+ help: slot.block.help ?? null,
120
+ optional: slot.optional === true,
121
+ })),
122
+ schema: agentTypeSchema(registry, def.name),
123
+ };
124
+ }
125
+ async function listGaps(deps, args) {
126
+ if (args.type !== undefined)
127
+ await requireType(deps, args.type);
128
+ const gaps = await deps.core.listGaps(args.type === undefined ? {} : { type: args.type });
129
+ const offset = args.offset ?? 0;
130
+ return {
131
+ total: gaps.length,
132
+ gaps: gaps.slice(offset, offset + (args.limit ?? 50)).map(({ document: doc, issues }) => ({
133
+ id: doc.id,
134
+ groupId: doc.groupId,
135
+ type: doc.type,
136
+ locale: doc.locale,
137
+ title: doc.title,
138
+ fields: issues.map((issue) => issueJson(issue)),
139
+ })),
140
+ };
141
+ }
142
+ /** The document `getDocumentInput` points at, in the requested state. */
143
+ async function findDocument(deps, args) {
144
+ const { core } = deps;
145
+ const { registry } = core;
146
+ const state = args.state === 'published' ? 'published' : 'head';
147
+ let id = args.id;
148
+ if (id !== undefined && args.locale !== undefined) {
149
+ const locale = localeOf(registry, args.locale);
150
+ const given = await core.getDocument(id);
151
+ if (given && given.deletedAt === null && given.locale !== locale) {
152
+ const translation = await core.findTranslation(given.groupId, locale);
153
+ if (!translation || translation.deletedAt !== null)
154
+ throw new InlayError('not_found', 'mcp.notTranslated', { locale });
155
+ id = translation.id;
156
+ }
157
+ }
158
+ if (id === undefined) {
159
+ if (args.type === undefined)
160
+ throw new InlayError('invalid_operation', 'mcp.findWhat');
161
+ const def = registry.getType(args.type);
162
+ const locale = localeOf(registry, args.locale);
163
+ let found;
164
+ if (def.kind === 'collection') {
165
+ if (docLabels(registry, def.name, ['slug']) === null)
166
+ throw new InlayError('invalid_operation', 'mcp.noSlugs', { type: def.name });
167
+ if (args.slug === undefined)
168
+ throw new InlayError('invalid_operation', 'mcp.slugRequired', { type: def.name });
169
+ found = await core.findEntry(def.name, args.slug, locale);
170
+ if (!found) {
171
+ const original = locale === registry.defaultLocale ? null : await core.findEntry(def.name, args.slug);
172
+ throw original
173
+ ? new InlayError('not_found', 'mcp.notTranslated', { locale })
174
+ : new InlayError('not_found', 'mcp.entryNotFound', { type: def.name, slug: args.slug });
175
+ }
176
+ }
177
+ else {
178
+ found = await core.findSingleton(def.name, locale);
179
+ if (!found) {
180
+ throw locale === registry.defaultLocale
181
+ ? new InlayError('not_found', 'error.notFound', { name: def.label })
182
+ : new InlayError('not_found', 'mcp.notTranslated', { locale });
183
+ }
184
+ }
185
+ id = found.id;
186
+ }
187
+ const doc = await core.getDocument(id, { state });
188
+ if (doc && doc.deletedAt === null)
189
+ return doc;
190
+ if (state === 'published') {
191
+ const head = await core.getDocument(id);
192
+ if (head && head.deletedAt === null)
193
+ throw new InlayError('not_found', 'mcp.notPublished', { title: head.title });
194
+ }
195
+ throw new InlayError('not_found', 'mcp.documentNotFound', { id });
196
+ }
197
+ async function getDocument(deps, args) {
198
+ const { core, baseUrl } = deps;
199
+ const { registry } = core;
200
+ const doc = await findDocument(deps, args);
201
+ const refs = await loadAgentRefs(deps, doc.type, doc.locale, doc.data);
202
+ const path = await livePath(deps, doc);
203
+ return {
204
+ id: doc.id,
205
+ groupId: doc.groupId,
206
+ type: doc.type,
207
+ kind: doc.kind,
208
+ locale: doc.locale,
209
+ title: doc.title,
210
+ revisionId: doc.revision.id,
211
+ publishedRevisionId: doc.publishedRev,
212
+ hasUnpublishedChanges: doc.publishedRev !== doc.headRev,
213
+ url: pageUrl(baseUrl, await livePath(deps, doc, 'published')),
214
+ previewUrl: previewLink(deps, path ?? '/'),
215
+ content: toAgent(registry, doc.type, doc.data, refs),
216
+ links: agentLinks(registry, doc.type, doc.data, refs),
217
+ };
218
+ }
219
+ async function searchEntries(deps, args) {
220
+ const { core } = deps;
221
+ const { registry } = core;
222
+ const def = registry.getType(args.collection);
223
+ if (def.kind !== 'collection') {
224
+ const collections = registry.site.collections.map((c) => c.name).join(', ');
225
+ throw new InlayError('invalid_operation', 'mcp.notCollection', { type: def.name, collections });
226
+ }
227
+ const locale = localeOf(registry, args.locale);
228
+ const hits = await core.searchEntries(def.name, args.query ?? '', {
229
+ locale,
230
+ ...(args.limit !== undefined && { limit: args.limit }),
231
+ });
232
+ const live = await core.liveDocuments(hits.map((hit) => hit.groupId), locale, { state: 'preview' });
233
+ return {
234
+ entries: hits.map((hit) => ({
235
+ id: hit.id,
236
+ groupId: hit.groupId,
237
+ title: hit.title,
238
+ locale: hit.locale,
239
+ slug: live.get(hit.groupId)?.slug ?? null,
240
+ published: hit.publishedRev !== null,
241
+ hasUnpublishedChanges: hit.publishedRev !== hit.headRev,
242
+ snippet: hit.snippet,
243
+ })),
244
+ };
245
+ }
246
+ /** `describe_site`, `describe_type`, `get_document`, `search_entries` and `list_gaps`. */
247
+ export function register(server, deps, _ctx) {
248
+ const run = (fn) => tool(async (args) => ok(await fn(args)), deps.log);
249
+ server.registerTool('describe_site', {
250
+ title: t('mcp.tool.describe_site.title'),
251
+ description: t('mcp.tool.describe_site.description'),
252
+ inputSchema: z.object({}),
253
+ annotations: READ_ONLY,
254
+ }, run(() => describeSite(deps)));
255
+ server.registerTool('describe_type', {
256
+ title: t('mcp.tool.describe_type.title'),
257
+ description: t('mcp.tool.describe_type.description'),
258
+ inputSchema: describeTypeInput,
259
+ annotations: READ_ONLY,
260
+ }, run((args) => describeType(deps, args.type)));
261
+ server.registerTool('get_document', {
262
+ title: t('mcp.tool.get_document.title'),
263
+ description: t('mcp.tool.get_document.description'),
264
+ inputSchema: getDocumentInput,
265
+ annotations: READ_ONLY,
266
+ }, run((args) => getDocument(deps, args)));
267
+ server.registerTool('search_entries', {
268
+ title: t('mcp.tool.search_entries.title'),
269
+ description: t('mcp.tool.search_entries.description'),
270
+ inputSchema: searchEntriesInput,
271
+ annotations: READ_ONLY,
272
+ }, run((args) => searchEntries(deps, args)));
273
+ server.registerTool('list_gaps', {
274
+ title: t('mcp.tool.list_gaps.title'),
275
+ description: t('mcp.tool.list_gaps.description'),
276
+ inputSchema: listGapsInput,
277
+ annotations: READ_ONLY,
278
+ }, run((args) => listGaps(deps, args)));
279
+ }
@@ -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_redirects`, `create_redirect` and `delete_redirect`. */
5
+ export declare function register(server: McpServer, deps: McpDeps, ctx: Ctx): void;
@@ -0,0 +1,74 @@
1
+ import { z } from 'zod';
2
+ import { contentIssue } from '../../../core/content/validate.js';
3
+ import { InlayError } from '../../../core/errors.js';
4
+ import { t } from '../../../core/messages/index.js';
5
+ import { DESTRUCTIVE, EDIT, READ_ONLY } from '../documents.js';
6
+ import { ok, tool } from '../results.js';
7
+ const createInput = z.object({
8
+ from: z.string().describe(t('mcp.param.redirectFrom')),
9
+ to: z.union([z.string(), z.object({ document: z.string() })]).describe(t('mcp.param.redirectTo')),
10
+ status: z.union([z.literal(301), z.literal(302)]).describe(t('mcp.param.redirectStatus')).optional(),
11
+ note: z.string().describe(t('mcp.param.redirectNote')).optional(),
12
+ });
13
+ const deleteInput = z.object({ id: z.number().int().describe(t('mcp.param.redirectId')) });
14
+ /** Redirects as tools show them; document targets carry the document's title (`null` if it has none). */
15
+ async function redirectsJson(deps, redirects) {
16
+ const groupIds = redirects.flatMap((r) => ('document' in r.to ? [r.to.document] : []));
17
+ const live = groupIds.length === 0
18
+ ? new Map()
19
+ : await deps.core.liveDocuments(groupIds, deps.core.registry.defaultLocale, { state: 'preview' });
20
+ return redirects.map(({ id, from, to, status, source, note }) => ({
21
+ id,
22
+ from,
23
+ to: 'document' in to ? { document: to.document, title: live.get(to.document)?.title ?? null } : to.path,
24
+ status,
25
+ source,
26
+ note,
27
+ }));
28
+ }
29
+ /** Refuses a document id where the target's `groupId` belongs, naming the right one. */
30
+ async function checkGroupId(deps, id) {
31
+ const doc = await deps.core.getDocument(id);
32
+ if (!doc || doc.groupId === id)
33
+ return;
34
+ const issue = contentIssue(['to'], [t('label.redirect.to')], 'invalid', 'mcp.useGroupId', { id, groupId: doc.groupId });
35
+ throw new InlayError('validation', 'error.redirectInvalid', {}, { issues: [issue] });
36
+ }
37
+ /** `list_redirects`, `create_redirect` and `delete_redirect`. */
38
+ export function register(server, deps, ctx) {
39
+ const run = (fn) => tool(async (args) => ok(await fn(args)), deps.log);
40
+ server.registerTool('list_redirects', {
41
+ title: t('mcp.tool.list_redirects.title'),
42
+ description: t('mcp.tool.list_redirects.description'),
43
+ inputSchema: z.object({}),
44
+ annotations: READ_ONLY,
45
+ }, run(async () => ({ redirects: await redirectsJson(deps, await deps.core.listRedirects()) })));
46
+ server.registerTool('create_redirect', {
47
+ title: t('mcp.tool.create_redirect.title'),
48
+ description: t('mcp.tool.create_redirect.description'),
49
+ inputSchema: createInput,
50
+ annotations: EDIT,
51
+ }, run(async (args) => {
52
+ if (typeof args.to === 'object')
53
+ await checkGroupId(deps, args.to.document);
54
+ const created = await deps.core.createRedirect({
55
+ from: args.from,
56
+ to: args.to,
57
+ ...(args.status !== undefined && { status: args.status }),
58
+ ...(args.note !== undefined && { note: args.note }),
59
+ }, ctx);
60
+ const [redirect] = await redirectsJson(deps, [created]);
61
+ if (!redirect)
62
+ throw new InlayError('not_found', 'error.redirectNotFound');
63
+ return redirect;
64
+ }));
65
+ server.registerTool('delete_redirect', {
66
+ title: t('mcp.tool.delete_redirect.title'),
67
+ description: t('mcp.tool.delete_redirect.description'),
68
+ inputSchema: deleteInput,
69
+ annotations: DESTRUCTIVE,
70
+ }, run(async (args) => {
71
+ await deps.core.deleteRedirect(args.id, ctx);
72
+ return { deleted: args.id };
73
+ }));
74
+ }
@@ -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
+ /** `update_document`, `create_entry`, `create_translation`, `delete_entry`, `list_pending_changes` and `get_preview_link`. */
5
+ export declare function register(server: McpServer, deps: McpDeps, ctx: Ctx): void;
@@ -0,0 +1,304 @@
1
+ import { z } from 'zod';
2
+ import { contentFromAgent, fromAgent, parsePath } from '../../../core/agent/format.js';
3
+ import { formatDiff } from '../../../core/content/diff.js';
4
+ import { patchProblems, unknownContentKeys } from '../../../core/content/patch.js';
5
+ import { docLabels, documentRefsWithPaths, normalizeContent } from '../../../core/content/schema.js';
6
+ import { contentIssue, mergeIssues, validateContent } from '../../../core/content/validate.js';
7
+ import { InlayError } from '../../../core/errors.js';
8
+ import { defOf, unwrap } from '../../../core/fields/zod-internals.js';
9
+ import { t } from '../../../core/messages/index.js';
10
+ import { previewLink } from '../../site/preview.js';
11
+ import { pageUrl } from '../agent-refs.js';
12
+ import { DESTRUCTIVE, documentOf, EDIT, livePath, READ_ONLY } from '../documents.js';
13
+ import { ok, tool } from '../results.js';
14
+ const updateDocumentInput = z.object({
15
+ id: z.string().describe(t('mcp.param.id')),
16
+ baseRevisionId: z.number().int().describe(t('mcp.param.baseRevisionId')),
17
+ changes: z
18
+ .array(z.object({
19
+ path: z.string().describe(t('mcp.param.changePath')),
20
+ value: z.unknown().describe(t('mcp.param.changeValue')).optional(),
21
+ remove: z.literal(true).describe(t('mcp.param.changeRemove')).optional(),
22
+ }))
23
+ .min(1)
24
+ .max(100)
25
+ .describe(t('mcp.param.changes')),
26
+ message: z.string().describe(t('mcp.param.message')).optional(),
27
+ });
28
+ const createEntryInput = z.object({
29
+ collection: z.string().describe(t('mcp.param.collection')),
30
+ content: z
31
+ .object({
32
+ slug: z.string().optional(),
33
+ path: z.string().optional(),
34
+ fields: z.record(z.string(), z.unknown()).optional(),
35
+ slots: z
36
+ .record(z.string(), z.object({ enabled: z.boolean().optional(), data: z.record(z.string(), z.unknown()).optional() }))
37
+ .optional(),
38
+ })
39
+ .describe(t('mcp.param.content')),
40
+ message: z.string().describe(t('mcp.param.message')).optional(),
41
+ });
42
+ const createTranslationInput = z.object({
43
+ id: z.string().describe(t('mcp.param.translateId')),
44
+ locale: z.string().describe(t('mcp.param.translateLocale')),
45
+ });
46
+ const deleteEntryInput = z.object({ id: z.string().describe(t('mcp.param.entryId')) });
47
+ const previewLinkInput = z.object({ id: z.string().describe(t('mcp.param.previewId')).optional() });
48
+ /** What `create_entry` and `create_translation` return about the new draft. */
49
+ async function created(deps, doc) {
50
+ const path = await livePath(deps, doc);
51
+ return {
52
+ id: doc.id,
53
+ groupId: doc.groupId,
54
+ revisionId: doc.headRev,
55
+ title: doc.title,
56
+ url: pageUrl(deps.baseUrl, await livePath(deps, doc, 'published')),
57
+ previewUrl: previewLink(deps, path ?? '/'),
58
+ };
59
+ }
60
+ const validation = (issues) => new InlayError('validation', 'error.validation', {}, { issues });
61
+ /** The schema of the field at `path`, or `null` when the path doesn't lead plainly to one (the patch then reports it). */
62
+ function fieldAt(registry, type, path) {
63
+ const { template } = registry.getType(type);
64
+ const [head, key, part, ...more] = path;
65
+ let current;
66
+ let rest;
67
+ if (head === 'fields') {
68
+ current = template.fields;
69
+ rest = path.slice(1);
70
+ }
71
+ else if (head === 'slots' && typeof key === 'string' && Object.hasOwn(template.slots, key) && part === 'data') {
72
+ current = template.slots[key].block.schema;
73
+ rest = more;
74
+ }
75
+ else {
76
+ return null;
77
+ }
78
+ if (rest.length === 0)
79
+ return null;
80
+ for (const segment of rest) {
81
+ const def = defOf(unwrap(current));
82
+ if (def.type === 'object' && def.shape && typeof segment === 'string' && Object.hasOwn(def.shape, segment)) {
83
+ current = def.shape[segment];
84
+ }
85
+ else if (def.type === 'array' && def.element && typeof segment === 'number') {
86
+ current = def.element;
87
+ }
88
+ else {
89
+ return null;
90
+ }
91
+ }
92
+ return current;
93
+ }
94
+ /** `ops` laid out as a document, so the references they write can be found with their full paths. */
95
+ function opsAsData(ops) {
96
+ const root = { fields: {}, slots: {} };
97
+ for (const op of ops) {
98
+ if (op.value === undefined || op.path.length === 0)
99
+ continue;
100
+ let parent = root;
101
+ op.path.forEach((segment, i) => {
102
+ const container = parent;
103
+ if (i === op.path.length - 1) {
104
+ container[segment] = op.value;
105
+ return;
106
+ }
107
+ const existing = container[segment];
108
+ const next = typeof existing === 'object' && existing !== null ? existing : typeof op.path[i + 1] === 'number' ? [] : {};
109
+ container[segment] = next;
110
+ parent = next;
111
+ });
112
+ }
113
+ return root;
114
+ }
115
+ /**
116
+ * References and links that give a document id where the entry's `groupId` belongs, naming the right one.
117
+ * Assistants mix the two up, and the document id would otherwise only be reported as missing content.
118
+ */
119
+ async function groupIdIssues(deps, type, data) {
120
+ const { core } = deps;
121
+ const found = documentRefsWithPaths(core.registry, type, data).filter((r) => r.ref.kind === 'document');
122
+ const documents = new Map();
123
+ for (const id of new Set(found.map((r) => r.ref.id))) {
124
+ const doc = await core.getDocument(id);
125
+ documents.set(id, doc && doc.groupId !== id ? doc.groupId : null);
126
+ }
127
+ const issues = [];
128
+ for (const { path, ref } of found) {
129
+ const groupId = documents.get(ref.id);
130
+ if (groupId == null)
131
+ continue;
132
+ const labels = docLabels(core.registry, type, path) ?? path.map(String);
133
+ issues.push(contentIssue(path, labels, 'invalid', 'mcp.useGroupId', { id: ref.id, groupId }));
134
+ }
135
+ return issues;
136
+ }
137
+ /** The change list as patch operations, converted from the agent format, and the problems of the changes that can't be. */
138
+ function toOps(deps, type, changes) {
139
+ const { registry } = deps.core;
140
+ const issues = [];
141
+ const ops = [];
142
+ for (const change of changes) {
143
+ const path = parsePath(change.path);
144
+ if (path === null) {
145
+ issues.push(contentIssue([], [], 'invalid', 'mcp.change.badPath', { path: change.path }));
146
+ continue;
147
+ }
148
+ const hasValue = change.value !== undefined;
149
+ const remove = change.remove === true;
150
+ if (hasValue === remove) {
151
+ const labels = docLabels(registry, type, path) ?? path.map(String);
152
+ issues.push(contentIssue(path, labels, 'invalid', hasValue ? 'mcp.change.both' : 'mcp.change.neither'));
153
+ continue;
154
+ }
155
+ if (remove) {
156
+ // Drafts may leave required fields empty, but removing one on purpose is a mistake worth reporting.
157
+ const field = fieldAt(registry, type, path);
158
+ if (field && !z.safeParse(field, undefined).success) {
159
+ const labels = docLabels(registry, type, path) ?? path.map(String);
160
+ issues.push(contentIssue(path, labels, 'required', 'mcp.change.required'));
161
+ }
162
+ else {
163
+ ops.push({ path });
164
+ }
165
+ continue;
166
+ }
167
+ const result = fromAgent(registry, type, path, change.value);
168
+ if (result.ok)
169
+ ops.push({ path, value: result.value });
170
+ else
171
+ issues.push(...result.issues);
172
+ }
173
+ return { ops, issues };
174
+ }
175
+ /**
176
+ * Saves the changes as a draft. Any problem is reported with every other one: the changes that can't be read,
177
+ * the references that need a groupId, then what applying and checking the rest finds.
178
+ */
179
+ async function updateDocument(deps, args, ctx) {
180
+ const doc = await documentOf(deps, args.id);
181
+ const { ops, issues } = toOps(deps, doc.type, args.changes);
182
+ issues.push(...(await groupIdIssues(deps, doc.type, opsAsData(ops))));
183
+ if (issues.length > 0)
184
+ throw validation(mergeIssues(issues, patchProblems(deps.core.registry, doc.type, doc.data, ops)));
185
+ let result;
186
+ try {
187
+ result = await deps.core.patchDraft(doc.id, { baseRevisionId: args.baseRevisionId, ops, ...(args.message !== undefined && { message: args.message }) }, ctx);
188
+ }
189
+ catch (e) {
190
+ if (e instanceof InlayError && e.code === 'conflict')
191
+ throw new InlayError('conflict', 'mcp.conflict', e.params, e.details);
192
+ throw e;
193
+ }
194
+ const path = await livePath(deps, result.document);
195
+ return {
196
+ id: result.document.id,
197
+ revisionId: result.document.headRev,
198
+ changed: result.changed,
199
+ changes: formatDiff(result.diff),
200
+ previewUrl: previewLink(deps, path ?? '/'),
201
+ };
202
+ }
203
+ async function createEntry(deps, args, ctx) {
204
+ const { core } = deps;
205
+ const { registry } = core;
206
+ const def = registry.getType(args.collection);
207
+ if (def.kind !== 'collection') {
208
+ const collections = registry.site.collections.map((c) => c.name).join(', ');
209
+ throw new InlayError('invalid_operation', 'mcp.notCollection', { type: def.name, collections });
210
+ }
211
+ const converted = contentFromAgent(registry, def.name, args.content);
212
+ const { fields = {}, slots = {} } = converted.content;
213
+ const issues = [
214
+ ...(converted.ok ? [] : converted.issues),
215
+ ...unknownContentKeys(registry, def.name, args.content),
216
+ ...(await groupIdIssues(deps, def.name, { fields, slots })),
217
+ ];
218
+ if (issues.length > 0) {
219
+ // Saving would check the rest; it is checked here so every problem is reported at once.
220
+ const checked = validateContent(registry, def.name, normalizeContent(registry, def.name, converted.content), 'draft');
221
+ throw validation(mergeIssues(issues, checked.ok ? [] : checked.issues));
222
+ }
223
+ const doc = await core.createEntry(def.name, { ...converted.content, ...(args.message !== undefined && { message: args.message }) }, ctx);
224
+ return created(deps, doc);
225
+ }
226
+ async function createTranslation(deps, args, ctx) {
227
+ const source = await documentOf(deps, args.id);
228
+ return created(deps, await deps.core.createTranslation(source.groupId, args.locale, ctx));
229
+ }
230
+ async function deleteEntry(deps, args, ctx) {
231
+ const { core } = deps;
232
+ const doc = await documentOf(deps, args.id);
233
+ const translations = [];
234
+ for (const locale of core.registry.locales) {
235
+ const found = await core.findTranslation(doc.groupId, locale);
236
+ if (found && found.deletedAt === null)
237
+ translations.push(found);
238
+ }
239
+ const main = translations.find((d) => d.locale === core.registry.defaultLocale) ?? doc;
240
+ await core.deleteEntry(doc.groupId, ctx);
241
+ return { deleted: { groupId: doc.groupId, title: main.title, locales: translations.map((d) => d.locale) } };
242
+ }
243
+ async function listPendingChanges(deps) {
244
+ const { core } = deps;
245
+ const pending = await core.listPendingChanges();
246
+ const described = await core.describeChanges(pending.map((d) => d.id));
247
+ return {
248
+ changes: described.map(({ document: d, isNew, lines }) => ({
249
+ id: d.id,
250
+ groupId: d.groupId,
251
+ type: d.type,
252
+ locale: d.locale,
253
+ title: d.title,
254
+ isNew,
255
+ lines,
256
+ })),
257
+ };
258
+ }
259
+ async function getPreviewLink(deps, args) {
260
+ if (args.id === undefined)
261
+ return { previewUrl: previewLink(deps, '/') };
262
+ const path = await livePath(deps, await documentOf(deps, args.id));
263
+ return { previewUrl: previewLink(deps, path ?? '/') };
264
+ }
265
+ /** `update_document`, `create_entry`, `create_translation`, `delete_entry`, `list_pending_changes` and `get_preview_link`. */
266
+ export function register(server, deps, ctx) {
267
+ const run = (fn) => tool(async (args) => ok(await fn(args)), deps.log);
268
+ server.registerTool('update_document', {
269
+ title: t('mcp.tool.update_document.title'),
270
+ description: t('mcp.tool.update_document.description'),
271
+ inputSchema: updateDocumentInput,
272
+ annotations: EDIT,
273
+ }, run((args) => updateDocument(deps, args, ctx)));
274
+ server.registerTool('create_entry', {
275
+ title: t('mcp.tool.create_entry.title'),
276
+ description: t('mcp.tool.create_entry.description'),
277
+ inputSchema: createEntryInput,
278
+ annotations: EDIT,
279
+ }, run((args) => createEntry(deps, args, ctx)));
280
+ server.registerTool('create_translation', {
281
+ title: t('mcp.tool.create_translation.title'),
282
+ description: t('mcp.tool.create_translation.description'),
283
+ inputSchema: createTranslationInput,
284
+ annotations: EDIT,
285
+ }, run((args) => createTranslation(deps, args, ctx)));
286
+ server.registerTool('delete_entry', {
287
+ title: t('mcp.tool.delete_entry.title'),
288
+ description: t('mcp.tool.delete_entry.description'),
289
+ inputSchema: deleteEntryInput,
290
+ annotations: DESTRUCTIVE,
291
+ }, run((args) => deleteEntry(deps, args, ctx)));
292
+ server.registerTool('list_pending_changes', {
293
+ title: t('mcp.tool.list_pending_changes.title'),
294
+ description: t('mcp.tool.list_pending_changes.description'),
295
+ inputSchema: z.object({}),
296
+ annotations: READ_ONLY,
297
+ }, run(() => listPendingChanges(deps)));
298
+ server.registerTool('get_preview_link', {
299
+ title: t('mcp.tool.get_preview_link.title'),
300
+ description: t('mcp.tool.get_preview_link.description'),
301
+ inputSchema: previewLinkInput,
302
+ annotations: READ_ONLY,
303
+ }, run((args) => getPreviewLink(deps, args)));
304
+ }
@@ -0,0 +1,8 @@
1
+ export interface BackupSchedule {
2
+ stop(): Promise<void>;
3
+ }
4
+ /** Runs `run` now and then every `intervalMs`, skipping a tick while one is still running. */
5
+ export declare function startBackupSchedule(run: () => Promise<unknown>, opts: {
6
+ intervalMs: number;
7
+ onError(e: unknown): void;
8
+ }): BackupSchedule;