@plitzi/sdk-mcp 0.33.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 (347) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +175 -0
  3. package/dist/createServer.d.ts +11 -0
  4. package/dist/createServer.js +36 -0
  5. package/dist/createServer.test.d.ts +1 -0
  6. package/dist/index.d.ts +20 -0
  7. package/dist/index.js +21 -0
  8. package/dist/modules/ai/AIEngine.d.ts +20 -0
  9. package/dist/modules/ai/AIEngine.js +120 -0
  10. package/dist/modules/ai/index.d.ts +4 -0
  11. package/dist/modules/ai/toolkit.d.ts +17 -0
  12. package/dist/modules/ai/toolkit.js +59 -0
  13. package/dist/modules/ai/toolkit.test.d.ts +1 -0
  14. package/dist/modules/mcp/apps/apps.test.d.ts +1 -0
  15. package/dist/modules/mcp/apps/example/index.d.ts +8 -0
  16. package/dist/modules/mcp/apps/example/view/index.tsx +70 -0
  17. package/dist/modules/mcp/apps/index.d.ts +11 -0
  18. package/dist/modules/mcp/apps/index.js +16 -0
  19. package/dist/modules/mcp/apps/render/index.d.ts +4 -0
  20. package/dist/modules/mcp/apps/render/index.js +17 -0
  21. package/dist/modules/mcp/apps/render/styles.d.ts +10 -0
  22. package/dist/modules/mcp/apps/render/styles.js +54 -0
  23. package/dist/modules/mcp/apps/render/styles.test.d.ts +1 -0
  24. package/dist/modules/mcp/apps/render/view/heldBatch.ts +107 -0
  25. package/dist/modules/mcp/apps/render/view/index.tsx +314 -0
  26. package/dist/modules/mcp/apps/render/view/streamProgress.ts +137 -0
  27. package/dist/modules/mcp/apps/shared/assets.d.ts +10 -0
  28. package/dist/modules/mcp/apps/shared/assets.js +10 -0
  29. package/dist/modules/mcp/apps/shared/bundle.d.ts +4 -0
  30. package/dist/modules/mcp/apps/shared/bundle.js +23 -0
  31. package/dist/modules/mcp/apps/shared/index.d.ts +3 -0
  32. package/dist/modules/mcp/apps/shared/page.d.ts +2 -0
  33. package/dist/modules/mcp/apps/shared/page.js +34 -0
  34. package/dist/modules/mcp/apps/shared/registerApp.d.ts +5 -0
  35. package/dist/modules/mcp/apps/shared/registerApp.js +43 -0
  36. package/dist/modules/mcp/apps/shared/resolve.d.ts +1 -0
  37. package/dist/modules/mcp/apps/shared/resolve.js +5 -0
  38. package/dist/modules/mcp/apps/shared/shell.ejs +59 -0
  39. package/dist/modules/mcp/apps/shared/zodEnglishOnly.d.ts +4 -0
  40. package/dist/modules/mcp/apps/shared/zodEnglishOnly.js +23 -0
  41. package/dist/modules/mcp/catalogs/builtinCallbacks.d.ts +19 -0
  42. package/dist/modules/mcp/catalogs/builtinCallbacks.js +139 -0
  43. package/dist/modules/mcp/catalogs/builtinComponents.d.ts +4 -0
  44. package/dist/modules/mcp/catalogs/builtinComponents.js +165 -0
  45. package/dist/modules/mcp/catalogs/builtinElementCallbacks.d.ts +17 -0
  46. package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +50 -0
  47. package/dist/modules/mcp/catalogs/builtinTransformers.d.ts +28 -0
  48. package/dist/modules/mcp/catalogs/builtinTransformers.js +148 -0
  49. package/dist/modules/mcp/catalogs/builtinTransformers.test.d.ts +1 -0
  50. package/dist/modules/mcp/catalogs/builtinUtilities.d.ts +15 -0
  51. package/dist/modules/mcp/catalogs/builtinUtilities.js +90 -0
  52. package/dist/modules/mcp/catalogs/cssCatalog/border.d.ts +4 -0
  53. package/dist/modules/mcp/catalogs/cssCatalog/border.js +30 -0
  54. package/dist/modules/mcp/catalogs/cssCatalog/box.d.ts +4 -0
  55. package/dist/modules/mcp/catalogs/cssCatalog/box.js +31 -0
  56. package/dist/modules/mcp/catalogs/cssCatalog/cssCatalog.test.d.ts +1 -0
  57. package/dist/modules/mcp/catalogs/cssCatalog/helpers.d.ts +34 -0
  58. package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +185 -0
  59. package/dist/modules/mcp/catalogs/cssCatalog/index.d.ts +18 -0
  60. package/dist/modules/mcp/catalogs/cssCatalog/index.js +131 -0
  61. package/dist/modules/mcp/catalogs/cssCatalog/layout.d.ts +9 -0
  62. package/dist/modules/mcp/catalogs/cssCatalog/layout.js +99 -0
  63. package/dist/modules/mcp/catalogs/cssCatalog/visual.d.ts +8 -0
  64. package/dist/modules/mcp/catalogs/cssCatalog/visual.js +147 -0
  65. package/dist/modules/mcp/catalogs/index.d.ts +9 -0
  66. package/dist/modules/mcp/catalogs/observed.d.ts +46 -0
  67. package/dist/modules/mcp/catalogs/observed.js +90 -0
  68. package/dist/modules/mcp/catalogs/paramSpec.d.ts +39 -0
  69. package/dist/modules/mcp/catalogs/paramSpec.js +69 -0
  70. package/dist/modules/mcp/catalogs/registry.d.ts +35 -0
  71. package/dist/modules/mcp/catalogs/registry.js +89 -0
  72. package/dist/modules/mcp/e2e/connector.test.d.ts +1 -0
  73. package/dist/modules/mcp/e2e/host.test.d.ts +1 -0
  74. package/dist/modules/mcp/e2e/index.d.ts +6 -0
  75. package/dist/modules/mcp/e2e/mcpEndpoint.d.ts +27 -0
  76. package/dist/modules/mcp/e2e/oauthConnector.test.d.ts +1 -0
  77. package/dist/modules/mcp/e2e/postMessageChannel.d.ts +22 -0
  78. package/dist/modules/mcp/e2e/renderingHost.d.ts +39 -0
  79. package/dist/modules/mcp/handler.d.ts +22 -0
  80. package/dist/modules/mcp/handler.js +83 -0
  81. package/dist/modules/mcp/helpers/agentPrompt.d.ts +4 -0
  82. package/dist/modules/mcp/helpers/agentPrompt.js +104 -0
  83. package/dist/modules/mcp/helpers/computeVersion.d.ts +1 -0
  84. package/dist/modules/mcp/helpers/computeVersion.js +16 -0
  85. package/dist/modules/mcp/helpers/guide.d.ts +4 -0
  86. package/dist/modules/mcp/helpers/guide.js +608 -0
  87. package/dist/modules/mcp/helpers/index.d.ts +8 -0
  88. package/dist/modules/mcp/helpers/interactions.d.ts +30 -0
  89. package/dist/modules/mcp/helpers/interactions.js +123 -0
  90. package/dist/modules/mcp/helpers/log.d.ts +8 -0
  91. package/dist/modules/mcp/helpers/log.js +64 -0
  92. package/dist/modules/mcp/helpers/log.test.d.ts +1 -0
  93. package/dist/modules/mcp/helpers/opResult.d.ts +13 -0
  94. package/dist/modules/mcp/helpers/opResult.js +18 -0
  95. package/dist/modules/mcp/helpers/space.d.ts +126 -0
  96. package/dist/modules/mcp/helpers/space.js +314 -0
  97. package/dist/modules/mcp/helpers/uris.d.ts +33 -0
  98. package/dist/modules/mcp/helpers/uris.js +50 -0
  99. package/dist/modules/mcp/index.d.ts +13 -0
  100. package/dist/modules/mcp/mcp.bench.d.ts +1 -0
  101. package/dist/modules/mcp/previewClient.d.ts +13 -0
  102. package/dist/modules/mcp/previewClient.js +31 -0
  103. package/dist/modules/mcp/proxy/config.d.ts +20 -0
  104. package/dist/modules/mcp/proxy/config.js +62 -0
  105. package/dist/modules/mcp/proxy/endpoint.test.d.ts +1 -0
  106. package/dist/modules/mcp/proxy/fetch.d.ts +18 -0
  107. package/dist/modules/mcp/proxy/fetch.js +91 -0
  108. package/dist/modules/mcp/proxy/grant.d.ts +25 -0
  109. package/dist/modules/mcp/proxy/grant.js +67 -0
  110. package/dist/modules/mcp/proxy/guard.d.ts +6 -0
  111. package/dist/modules/mcp/proxy/guard.js +38 -0
  112. package/dist/modules/mcp/proxy/handler.d.ts +8 -0
  113. package/dist/modules/mcp/proxy/handler.js +99 -0
  114. package/dist/modules/mcp/proxy/index.d.ts +8 -0
  115. package/dist/modules/mcp/proxy/payload.d.ts +8 -0
  116. package/dist/modules/mcp/proxy/payload.js +29 -0
  117. package/dist/modules/mcp/proxy/proxy.test.d.ts +1 -0
  118. package/dist/modules/mcp/proxy/rewrite.d.ts +18 -0
  119. package/dist/modules/mcp/proxy/rewrite.js +138 -0
  120. package/dist/modules/mcp/proxy/sign.d.ts +6 -0
  121. package/dist/modules/mcp/proxy/sign.js +15 -0
  122. package/dist/modules/mcp/proxy/types.d.ts +45 -0
  123. package/dist/modules/mcp/proxy/types.js +9 -0
  124. package/dist/modules/mcp/proxy/wiring.test.d.ts +1 -0
  125. package/dist/modules/mcp/resources/canonical.d.ts +6 -0
  126. package/dist/modules/mcp/resources/canonical.js +30 -0
  127. package/dist/modules/mcp/resources/connectors.d.ts +22 -0
  128. package/dist/modules/mcp/resources/connectors.js +46 -0
  129. package/dist/modules/mcp/resources/core.d.ts +5 -0
  130. package/dist/modules/mcp/resources/core.js +18 -0
  131. package/dist/modules/mcp/resources/envelope.d.ts +10 -0
  132. package/dist/modules/mcp/resources/envelope.js +14 -0
  133. package/dist/modules/mcp/resources/index.d.ts +9 -0
  134. package/dist/modules/mcp/resources/primer.d.ts +7 -0
  135. package/dist/modules/mcp/resources/primer.js +33 -0
  136. package/dist/modules/mcp/resources/register.d.ts +10 -0
  137. package/dist/modules/mcp/resources/register.js +205 -0
  138. package/dist/modules/mcp/resources/renderGuide.d.ts +10 -0
  139. package/dist/modules/mcp/resources/renderGuide.js +451 -0
  140. package/dist/modules/mcp/resources/router.d.ts +10 -0
  141. package/dist/modules/mcp/resources/router.js +39 -0
  142. package/dist/modules/mcp/resources/schema.d.ts +5 -0
  143. package/dist/modules/mcp/resources/schema.js +43 -0
  144. package/dist/modules/mcp/resources/style.d.ts +5 -0
  145. package/dist/modules/mcp/resources/style.js +34 -0
  146. package/dist/modules/mcp/screenshotClient.d.ts +13 -0
  147. package/dist/modules/mcp/screenshotClient.js +47 -0
  148. package/dist/modules/mcp/server.d.ts +31 -0
  149. package/dist/modules/mcp/server.js +127 -0
  150. package/dist/modules/mcp/tests/apply.test.d.ts +1 -0
  151. package/dist/modules/mcp/tests/bindings.test.d.ts +1 -0
  152. package/dist/modules/mcp/tests/connectors.test.d.ts +1 -0
  153. package/dist/modules/mcp/tests/css.test.d.ts +1 -0
  154. package/dist/modules/mcp/tests/helpers.d.ts +13 -0
  155. package/dist/modules/mcp/tests/interactions.test.d.ts +1 -0
  156. package/dist/modules/mcp/tests/pages.test.d.ts +1 -0
  157. package/dist/modules/mcp/tests/reads.test.d.ts +1 -0
  158. package/dist/modules/mcp/tests/schemaIds.test.d.ts +1 -0
  159. package/dist/modules/mcp/tests/search.test.d.ts +1 -0
  160. package/dist/modules/mcp/tests/skill.test.d.ts +1 -0
  161. package/dist/modules/mcp/tests/styles.test.d.ts +1 -0
  162. package/dist/modules/mcp/tests/tools.test.d.ts +1 -0
  163. package/dist/modules/mcp/tests/validation.test.d.ts +1 -0
  164. package/dist/modules/mcp/tools/apply/dispatch.d.ts +6 -0
  165. package/dist/modules/mcp/tools/apply/dispatch.js +128 -0
  166. package/dist/modules/mcp/tools/apply/index.d.ts +656 -0
  167. package/dist/modules/mcp/tools/apply/index.js +161 -0
  168. package/dist/modules/mcp/tools/apply/writeResult.d.ts +8 -0
  169. package/dist/modules/mcp/tools/apply/writeResult.js +37 -0
  170. package/dist/modules/mcp/tools/index.d.ts +18 -0
  171. package/dist/modules/mcp/tools/index.js +24 -0
  172. package/dist/modules/mcp/tools/operations/connectors/deleteConnector.d.ts +9 -0
  173. package/dist/modules/mcp/tools/operations/connectors/deleteConnector.js +20 -0
  174. package/dist/modules/mcp/tools/operations/connectors/index.d.ts +188 -0
  175. package/dist/modules/mcp/tools/operations/connectors/index.js +12 -0
  176. package/dist/modules/mcp/tools/operations/connectors/manifest.d.ts +89 -0
  177. package/dist/modules/mcp/tools/operations/connectors/manifest.js +70 -0
  178. package/dist/modules/mcp/tools/operations/connectors/patchConnector.d.ts +94 -0
  179. package/dist/modules/mcp/tools/operations/connectors/patchConnector.js +58 -0
  180. package/dist/modules/mcp/tools/operations/connectors/upsertConnector.d.ts +98 -0
  181. package/dist/modules/mcp/tools/operations/connectors/upsertConnector.js +64 -0
  182. package/dist/modules/mcp/tools/operations/index.d.ts +2235 -0
  183. package/dist/modules/mcp/tools/operations/index.js +55 -0
  184. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +17 -0
  185. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +32 -0
  186. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +25 -0
  187. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +36 -0
  188. package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +27 -0
  189. package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +47 -0
  190. package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.d.ts +10 -0
  191. package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +29 -0
  192. package/dist/modules/mcp/tools/operations/schema/elements/moveElement.d.ts +16 -0
  193. package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +41 -0
  194. package/dist/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +27 -0
  195. package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +60 -0
  196. package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.d.ts +55 -0
  197. package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +148 -0
  198. package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.d.ts +16 -0
  199. package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +66 -0
  200. package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.d.ts +9 -0
  201. package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +32 -0
  202. package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.d.ts +12 -0
  203. package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +49 -0
  204. package/dist/modules/mcp/tools/operations/schema/index.d.ts +21 -0
  205. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +12 -0
  206. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +52 -0
  207. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +18 -0
  208. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +47 -0
  209. package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +27 -0
  210. package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +44 -0
  211. package/dist/modules/mcp/tools/operations/schema/operations.d.ts +236 -0
  212. package/dist/modules/mcp/tools/operations/schema/operations.js +41 -0
  213. package/dist/modules/mcp/tools/operations/schema/pages/deletePage.d.ts +9 -0
  214. package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +25 -0
  215. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +14 -0
  216. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +77 -0
  217. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +36 -0
  218. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +44 -0
  219. package/dist/modules/mcp/tools/operations/schema/shared.d.ts +106 -0
  220. package/dist/modules/mcp/tools/operations/schema/shared.js +131 -0
  221. package/dist/modules/mcp/tools/operations/schema/translator.d.ts +12 -0
  222. package/dist/modules/mcp/tools/operations/schema/translator.js +216 -0
  223. package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.d.ts +9 -0
  224. package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +18 -0
  225. package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.d.ts +16 -0
  226. package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.js +42 -0
  227. package/dist/modules/mcp/tools/operations/schema/write.d.ts +42 -0
  228. package/dist/modules/mcp/tools/operations/schema/write.js +112 -0
  229. package/dist/modules/mcp/tools/operations/schemaIds.d.ts +6 -0
  230. package/dist/modules/mcp/tools/operations/schemaIds.js +58 -0
  231. package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.d.ts +9 -0
  232. package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +21 -0
  233. package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.d.ts +37 -0
  234. package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +28 -0
  235. package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.d.ts +37 -0
  236. package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.js +24 -0
  237. package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.d.ts +41 -0
  238. package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.js +40 -0
  239. package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.d.ts +9 -0
  240. package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +21 -0
  241. package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.d.ts +37 -0
  242. package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +28 -0
  243. package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.d.ts +37 -0
  244. package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.js +24 -0
  245. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +9 -0
  246. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +21 -0
  247. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +37 -0
  248. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +28 -0
  249. package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +37 -0
  250. package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +24 -0
  251. package/dist/modules/mcp/tools/operations/style/index.d.ts +15 -0
  252. package/dist/modules/mcp/tools/operations/style/operations.d.ts +264 -0
  253. package/dist/modules/mcp/tools/operations/style/operations.js +29 -0
  254. package/dist/modules/mcp/tools/operations/style/shared.d.ts +116 -0
  255. package/dist/modules/mcp/tools/operations/style/shared.js +59 -0
  256. package/dist/modules/mcp/tools/operations/style/translator.d.ts +12 -0
  257. package/dist/modules/mcp/tools/operations/style/translator.js +101 -0
  258. package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.d.ts +15 -0
  259. package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +21 -0
  260. package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.d.ts +20 -0
  261. package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.js +22 -0
  262. package/dist/modules/mcp/tools/operations/style/write.d.ts +12 -0
  263. package/dist/modules/mcp/tools/operations/style/write.js +108 -0
  264. package/dist/modules/mcp/tools/preview.d.ts +472 -0
  265. package/dist/modules/mcp/tools/preview.js +37 -0
  266. package/dist/modules/mcp/tools/read.d.ts +9 -0
  267. package/dist/modules/mcp/tools/read.js +51 -0
  268. package/dist/modules/mcp/tools/render.d.ts +506 -0
  269. package/dist/modules/mcp/tools/render.js +184 -0
  270. package/dist/modules/mcp/tools/render.test.d.ts +1 -0
  271. package/dist/modules/mcp/tools/screenshot.d.ts +656 -0
  272. package/dist/modules/mcp/tools/screenshot.js +83 -0
  273. package/dist/modules/mcp/tools/search.d.ts +15 -0
  274. package/dist/modules/mcp/tools/search.js +115 -0
  275. package/dist/modules/mcp/tools/shared/expandOperations.d.ts +13 -0
  276. package/dist/modules/mcp/tools/shared/expandOperations.js +44 -0
  277. package/dist/modules/mcp/tools/shared/tool.d.ts +72 -0
  278. package/dist/modules/mcp/tools/shared/tool.js +33 -0
  279. package/dist/modules/mcp/tools/shared/validator/audit.d.ts +4 -0
  280. package/dist/modules/mcp/tools/shared/validator/audit.js +124 -0
  281. package/dist/modules/mcp/tools/shared/validator/batch.d.ts +5 -0
  282. package/dist/modules/mcp/tools/shared/validator/batch.js +39 -0
  283. package/dist/modules/mcp/tools/shared/validator/bindings.d.ts +6 -0
  284. package/dist/modules/mcp/tools/shared/validator/bindings.js +70 -0
  285. package/dist/modules/mcp/tools/shared/validator/connectors.d.ts +19 -0
  286. package/dist/modules/mcp/tools/shared/validator/connectors.js +76 -0
  287. package/dist/modules/mcp/tools/shared/validator/context.d.ts +38 -0
  288. package/dist/modules/mcp/tools/shared/validator/context.js +35 -0
  289. package/dist/modules/mcp/tools/shared/validator/css.d.ts +4 -0
  290. package/dist/modules/mcp/tools/shared/validator/css.js +39 -0
  291. package/dist/modules/mcp/tools/shared/validator/elements.d.ts +7 -0
  292. package/dist/modules/mcp/tools/shared/validator/elements.js +68 -0
  293. package/dist/modules/mcp/tools/shared/validator/index.d.ts +8 -0
  294. package/dist/modules/mcp/tools/shared/validator/index.js +268 -0
  295. package/dist/modules/mcp/tools/shared/validator/interactions.d.ts +3 -0
  296. package/dist/modules/mcp/tools/shared/validator/interactions.js +103 -0
  297. package/dist/modules/mcp/tools/shared/validator/refs.d.ts +4 -0
  298. package/dist/modules/mcp/tools/shared/validator/refs.js +28 -0
  299. package/dist/modules/mcp/tools/validate.d.ts +653 -0
  300. package/dist/modules/mcp/tools/validate.js +47 -0
  301. package/dist/modules/mcp/types/aiSchema.d.ts +226 -0
  302. package/dist/modules/mcp/types/appTypes.d.ts +26 -0
  303. package/dist/modules/mcp/types/index.d.ts +5 -0
  304. package/dist/modules/mcp/types/previewTypes.d.ts +25 -0
  305. package/dist/modules/mcp/types/screenshotTypes.d.ts +29 -0
  306. package/dist/modules/mcp/types/toolTypes.d.ts +145 -0
  307. package/dist/modules/oauth/authorize.d.ts +7 -0
  308. package/dist/modules/oauth/authorize.js +177 -0
  309. package/dist/modules/oauth/challenge.d.ts +11 -0
  310. package/dist/modules/oauth/challenge.js +33 -0
  311. package/dist/modules/oauth/consentPage.d.ts +7 -0
  312. package/dist/modules/oauth/consentPage.js +118 -0
  313. package/dist/modules/oauth/metadata.d.ts +40 -0
  314. package/dist/modules/oauth/metadata.js +69 -0
  315. package/dist/modules/oauth/oauth.test.d.ts +1 -0
  316. package/dist/modules/oauth/params.d.ts +5 -0
  317. package/dist/modules/oauth/params.js +5 -0
  318. package/dist/modules/oauth/pkce.d.ts +6 -0
  319. package/dist/modules/oauth/pkce.js +15 -0
  320. package/dist/modules/oauth/records.d.ts +71 -0
  321. package/dist/modules/oauth/records.js +46 -0
  322. package/dist/modules/oauth/register.d.ts +5 -0
  323. package/dist/modules/oauth/register.js +55 -0
  324. package/dist/modules/oauth/respond.d.ts +13 -0
  325. package/dist/modules/oauth/respond.js +44 -0
  326. package/dist/modules/oauth/token.d.ts +5 -0
  327. package/dist/modules/oauth/token.js +100 -0
  328. package/dist/options.d.ts +73 -0
  329. package/dist/packageBoundary.test.d.ts +1 -0
  330. package/dist/pipeline.d.ts +12 -0
  331. package/dist/pipeline.js +29 -0
  332. package/dist/pipeline.test.d.ts +1 -0
  333. package/dist/preview/createPreview.d.ts +10 -0
  334. package/dist/preview/createPreview.js +83 -0
  335. package/dist/server.d.ts +15 -0
  336. package/dist/server.js +7 -0
  337. package/dist/stages/mcp.d.ts +4 -0
  338. package/dist/stages/mcp.js +30 -0
  339. package/dist/stages/oauth.d.ts +19 -0
  340. package/dist/stages/oauth.js +114 -0
  341. package/dist/stages/preview.d.ts +2 -0
  342. package/dist/stages/preview.js +37 -0
  343. package/dist/stages/proxy.d.ts +3 -0
  344. package/dist/stages/proxy.js +14 -0
  345. package/dist/tests/httpRequest.d.ts +14 -0
  346. package/package.json +77 -0
  347. package/skills/plitzi-render/SKILL.md +174 -0
@@ -0,0 +1,55 @@
1
+ import { randomId } from "./pkce.js";
2
+ import { getClientByFingerprint, putClient, putClientFingerprint } from "./records.js";
3
+ import { sendErrorJson, sendJson } from "./respond.js";
4
+ import { createHash } from "node:crypto";
5
+ //#region src/modules/oauth/register.ts
6
+ var isUsableRedirectUri = (value) => {
7
+ let url;
8
+ try {
9
+ url = new URL(value);
10
+ } catch {
11
+ return false;
12
+ }
13
+ if (url.protocol === "https:") return true;
14
+ return url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
15
+ };
16
+ var stringList = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
17
+ var nowSeconds = () => Math.floor(Date.now() / 1e3);
18
+ var fingerprintOf = (clientName, redirectUris) => createHash("sha256").update(JSON.stringify([clientName, [...redirectUris].sort()])).digest("base64url");
19
+ /** RFC 7591 dynamic client registration. A remote host has no way to be configured into this server ahead of
20
+ * time, so it registers itself on first connect; the record it gets back is only ever used to pin the redirect
21
+ * target, since a public client authenticates with PKCE rather than with credentials. */
22
+ var handleRegister = async (config, res, body) => {
23
+ if (typeof body !== "object" || body === null) {
24
+ sendErrorJson(res, 400, "invalid_request", "Expected a JSON client metadata object.");
25
+ return;
26
+ }
27
+ const metadata = body;
28
+ const redirectUris = stringList(metadata["redirect_uris"]).filter(isUsableRedirectUri);
29
+ if (redirectUris.length === 0) {
30
+ sendErrorJson(res, 400, "invalid_request", "redirect_uris must list at least one https (or loopback) URI.");
31
+ return;
32
+ }
33
+ const clientName = typeof metadata["client_name"] === "string" ? metadata["client_name"] : "MCP client";
34
+ const { store } = config.adapters;
35
+ const fingerprint = fingerprintOf(clientName, redirectUris);
36
+ const client = await getClientByFingerprint(store, fingerprint) ?? {
37
+ clientId: randomId(),
38
+ clientName,
39
+ redirectUris,
40
+ issuedAt: nowSeconds()
41
+ };
42
+ await putClient(store, client);
43
+ await putClientFingerprint(store, fingerprint, client.clientId);
44
+ sendJson(res, 201, {
45
+ client_id: client.clientId,
46
+ client_id_issued_at: client.issuedAt,
47
+ client_name: clientName,
48
+ redirect_uris: redirectUris,
49
+ grant_types: config.refreshTtlSeconds === 0 ? ["authorization_code"] : ["authorization_code", "refresh_token"],
50
+ response_types: ["code"],
51
+ token_endpoint_auth_method: "none"
52
+ });
53
+ };
54
+ //#endregion
55
+ export { handleRegister };
@@ -0,0 +1,13 @@
1
+ import { SSRResponseHelpers } from '@plitzi/sdk-shared';
2
+ /** The error codes RFC 6749 defines for the responses this server produces. */
3
+ export type OAuthErrorCode = 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'unsupported_response_type' | 'invalid_scope' | 'access_denied' | 'server_error';
4
+ export declare const sendJson: (res: SSRResponseHelpers, status: number, body: unknown) => void;
5
+ export declare const sendHtml: (res: SSRResponseHelpers, status: number, html: string) => void;
6
+ export declare const sendErrorJson: (res: SSRResponseHelpers, status: number, error: OAuthErrorCode, description: string) => void;
7
+ /** Shown when the authorization request itself is unusable — an unknown client, a `redirect_uri` that is not
8
+ * registered. Redirecting those back would turn the endpoint into an open redirector. */
9
+ export declare const sendErrorPage: (res: SSRResponseHelpers, title: string, detail: string) => void;
10
+ /** The other half of RFC 6749 error handling: once the redirect target is known to be legitimate, failures go
11
+ * back to the client so the host can report them, carrying `state` so it can match the response to its request. */
12
+ export declare const redirectWithError: (res: SSRResponseHelpers, redirectUri: string, error: OAuthErrorCode, description: string, state?: string) => void;
13
+ export declare const redirectWithCode: (res: SSRResponseHelpers, redirectUri: string, code: string, state?: string) => void;
@@ -0,0 +1,44 @@
1
+ import { renderErrorPage } from "./consentPage.js";
2
+ //#region src/modules/oauth/respond.ts
3
+ var sendJson = (res, status, body) => {
4
+ res.setStatus(status);
5
+ res.setHeader("Content-Type", "application/json");
6
+ res.setHeader("Cache-Control", "no-store, no-transform");
7
+ res.send(JSON.stringify(body));
8
+ };
9
+ var sendHtml = (res, status, html) => {
10
+ res.setStatus(status);
11
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
12
+ res.setHeader("Cache-Control", "no-store, no-transform");
13
+ res.send(html);
14
+ };
15
+ var sendErrorJson = (res, status, error, description) => sendJson(res, status, {
16
+ error,
17
+ error_description: description
18
+ });
19
+ /** Shown when the authorization request itself is unusable — an unknown client, a `redirect_uri` that is not
20
+ * registered. Redirecting those back would turn the endpoint into an open redirector. */
21
+ var sendErrorPage = (res, title, detail) => sendHtml(res, 400, renderErrorPage(title, detail));
22
+ /** The other half of RFC 6749 error handling: once the redirect target is known to be legitimate, failures go
23
+ * back to the client so the host can report them, carrying `state` so it can match the response to its request. */
24
+ var redirectWithError = (res, redirectUri, error, description, state) => {
25
+ const url = new URL(redirectUri);
26
+ url.searchParams.set("error", error);
27
+ url.searchParams.set("error_description", description);
28
+ if (state !== void 0) url.searchParams.set("state", state);
29
+ res.setStatus(302);
30
+ res.setHeader("Location", url.toString());
31
+ res.setHeader("Cache-Control", "no-store, no-transform");
32
+ res.end();
33
+ };
34
+ var redirectWithCode = (res, redirectUri, code, state) => {
35
+ const url = new URL(redirectUri);
36
+ url.searchParams.set("code", code);
37
+ if (state !== void 0) url.searchParams.set("state", state);
38
+ res.setStatus(302);
39
+ res.setHeader("Location", url.toString());
40
+ res.setHeader("Cache-Control", "no-store, no-transform");
41
+ res.end();
42
+ };
43
+ //#endregion
44
+ export { redirectWithCode, redirectWithError, sendErrorJson, sendErrorPage, sendHtml, sendJson };
@@ -0,0 +1,5 @@
1
+ import { OAuthParams } from './params';
2
+ import { OAuthConfig, SSRResponseHelpers } from '@plitzi/sdk-shared';
3
+ /** POST /token. Public clients only, so there is no client authentication to check — PKCE is what proves the
4
+ * caller is the one that started the flow. */
5
+ export declare const handleToken: (config: OAuthConfig, res: SSRResponseHelpers, params: OAuthParams) => Promise<void>;
@@ -0,0 +1,100 @@
1
+ import { scopesOf } from "./metadata.js";
2
+ import { field, optionalField } from "./params.js";
3
+ import { randomId, verifyChallenge } from "./pkce.js";
4
+ import { dropCode, dropRefresh, getCode, getRefresh, putAccess, putRefresh } from "./records.js";
5
+ import { sendErrorJson, sendJson } from "./respond.js";
6
+ //#region src/modules/oauth/token.ts
7
+ var DEFAULT_REFRESH_TTL_SECONDS = 2592e3;
8
+ var DEFAULT_ACCESS_TTL_SECONDS = 2592e3;
9
+ var refreshTtlOf = (config) => config.refreshTtlSeconds ?? DEFAULT_REFRESH_TTL_SECONDS;
10
+ var scopeOf = (config, requested) => requested ?? scopesOf(config).join(" ");
11
+ /** The token response, plus a rotated refresh grant when refresh is enabled. Rotation is unconditional: a refresh
12
+ * token is a long-lived credential, so the one just used never stays valid. */
13
+ var sendTokens = async (config, res, credential, expiresInSeconds, grant) => {
14
+ const ttl = refreshTtlOf(config);
15
+ const bearer = randomId();
16
+ await putAccess(config.adapters.store, bearer, {
17
+ credential,
18
+ clientId: grant.clientId,
19
+ user: grant.user,
20
+ target: grant.target
21
+ }, Math.max(expiresInSeconds ?? DEFAULT_ACCESS_TTL_SECONDS, 1));
22
+ const body = {
23
+ access_token: bearer,
24
+ token_type: "Bearer",
25
+ scope: scopeOf(config, grant.scope)
26
+ };
27
+ if (expiresInSeconds !== void 0) body["expires_in"] = expiresInSeconds;
28
+ if (ttl > 0) {
29
+ const refreshToken = randomId();
30
+ await putRefresh(config.adapters.store, refreshToken, grant, ttl);
31
+ body["refresh_token"] = refreshToken;
32
+ }
33
+ sendJson(res, 200, body);
34
+ };
35
+ var exchangeCode = async (config, res, params) => {
36
+ const code = field(params, "code");
37
+ const record = code ? await getCode(config.adapters.store, code) : void 0;
38
+ if (!record) {
39
+ sendErrorJson(res, 400, "invalid_grant", "The authorization code is unknown or has expired.");
40
+ return;
41
+ }
42
+ await dropCode(config.adapters.store, code);
43
+ if (record.clientId !== field(params, "client_id")) {
44
+ sendErrorJson(res, 400, "invalid_grant", "The authorization code was issued to another client.");
45
+ return;
46
+ }
47
+ const redirectUri = optionalField(params, "redirect_uri");
48
+ if (redirectUri !== void 0 && redirectUri !== record.redirectUri) {
49
+ sendErrorJson(res, 400, "invalid_grant", "redirect_uri does not match the authorization request.");
50
+ return;
51
+ }
52
+ if (!verifyChallenge(field(params, "code_verifier"), record.challenge)) {
53
+ sendErrorJson(res, 400, "invalid_grant", "The PKCE code verifier does not match the challenge.");
54
+ return;
55
+ }
56
+ await sendTokens(config, res, record.token, record.expiresInSeconds, {
57
+ clientId: record.clientId,
58
+ scope: record.scope,
59
+ user: record.user,
60
+ target: record.target
61
+ });
62
+ };
63
+ var exchangeRefresh = async (config, res, params) => {
64
+ if (refreshTtlOf(config) === 0) {
65
+ sendErrorJson(res, 400, "unsupported_grant_type", "This server issues no refresh tokens.");
66
+ return;
67
+ }
68
+ const refreshToken = field(params, "refresh_token");
69
+ const record = refreshToken ? await getRefresh(config.adapters.store, refreshToken) : void 0;
70
+ if (!record) {
71
+ sendErrorJson(res, 400, "invalid_grant", "The refresh token is unknown or has expired.");
72
+ return;
73
+ }
74
+ await dropRefresh(config.adapters.store, refreshToken);
75
+ if (record.clientId !== field(params, "client_id")) {
76
+ sendErrorJson(res, 400, "invalid_grant", "The refresh token was issued to another client.");
77
+ return;
78
+ }
79
+ const issued = await config.adapters.issueToken(record.user, record.target);
80
+ if (!issued) {
81
+ sendErrorJson(res, 400, "invalid_grant", "The account no longer has access to this resource.");
82
+ return;
83
+ }
84
+ await sendTokens(config, res, issued.token, issued.expiresInSeconds, record);
85
+ };
86
+ /** POST /token. Public clients only, so there is no client authentication to check — PKCE is what proves the
87
+ * caller is the one that started the flow. */
88
+ var handleToken = async (config, res, params) => {
89
+ switch (field(params, "grant_type")) {
90
+ case "authorization_code":
91
+ await exchangeCode(config, res, params);
92
+ return;
93
+ case "refresh_token":
94
+ await exchangeRefresh(config, res, params);
95
+ return;
96
+ default: sendErrorJson(res, 400, "unsupported_grant_type", "Supported grants: authorization_code, refresh_token.");
97
+ }
98
+ };
99
+ //#endregion
100
+ export { handleToken };
@@ -0,0 +1,73 @@
1
+ import { OAuthConfig } from '@plitzi/sdk-shared';
2
+ /** How a rendered widget reaches ANYTHING outside its sandbox — images, media, fonts, and the endpoints an
3
+ * apiContainer fetches. A widget runs in an iframe under a CSP the host builds from the origins this server
4
+ * declares on its `ui://` resource, which is read before any widget exists (and the spec allows no per-call CSP),
5
+ * so the origins an agent is about to author can never be declared. With a `secret` set, every external URL a
6
+ * render authored is rewritten to this server's own endpoint — which IS declared — and fetched here, which also
7
+ * settles the redirects, hotlink rules and missing CORS headers a null-origin sandbox cannot. The agent never
8
+ * sees this: it authors the real URL. Without a secret there is no endpoint and the URLs travel as authored,
9
+ * loading only where the host allows their origin. */
10
+ export type McpProxyOptions = {
11
+ /** Set false to serve no endpoint even with a secret configured. */
12
+ enabled?: boolean;
13
+ /** Where the endpoint answers. Default `/__proxy`. */
14
+ path?: string;
15
+ /** Signs each grant (target + kind + expiry + the connection that minted it), so the endpoint is not an open
16
+ * proxy. Required to enable it; any value stable across replicas works. */
17
+ secret?: string;
18
+ /** Absolute base for the URLs handed to widgets (`https://mcp.example.com`). Default: the origin each MCP
19
+ * request arrived on — right whenever the MCP server owns its sub-domain. */
20
+ baseUrl?: string;
21
+ /** Largest response the endpoint will pass through, in bytes. Default 8 MiB. */
22
+ maxBytes?: number;
23
+ /** How long a minted URL keeps working, in seconds. Default 7 days: a widget outlives the call that made it
24
+ * (it stays in the conversation), but a leaked URL should not work forever. */
25
+ ttl?: number;
26
+ /** Which MCP tools may be handed the endpoint at all. Defaults to `['plitzi_render']`, and that default is a
27
+ * guard rather than a convenience: a render is a throwaway widget, so a rewritten URL lives exactly as long as
28
+ * it does, while a tool that WRITES a space (plitzi_apply) would persist proxied URLs into content the user
29
+ * owns — their space would then depend on this server to show its own images, and those URLs expire. Listing a
30
+ * tool only makes the endpoint reachable from it; rewriting is something the tool has to implement, and today
31
+ * plitzi_render is the only one that does. */
32
+ tools?: string[];
33
+ };
34
+ /**
35
+ * Everything this package needs to serve MCP, and nothing the server it runs in has to know about.
36
+ *
37
+ * It is a SECOND argument — to `createServer` here, and to `mcpExtensions` for a page server — rather than a
38
+ * section of `SSRServerConfig`, because that config belongs to the HTTP/page server: a deployment that serves
39
+ * pages and never installs this package should not be reading about widget proxies and OAuth in the type it
40
+ * configures its renderer with. The stages close over what they were given instead of digging it back out of
41
+ * `ctx.config`, which is also what keeps them mountable in a server whose config this package has never seen.
42
+ */
43
+ export type McpOptions = {
44
+ /** Where MCP answers inside a server that also serves pages. Default `/mcp`; a dedicated MCP server owns its
45
+ * whole origin and ignores it. There is no `enabled` flag: handing the stages over IS the decision. */
46
+ path?: string;
47
+ /** Whether the plitzi_render view may paint from the tool arguments while the host is still STREAMING them: a
48
+ * placeholder that grows with the widget being authored, instead of the static "Rendering…" held for as long as
49
+ * the model takes to write the batch. Defaults to true; hosts that stream nothing are unaffected either way.
50
+ * Set false to keep every view blank until the finished widget arrives. */
51
+ renderStreaming?: boolean;
52
+ /** See {@link McpProxyOptions}. */
53
+ proxy?: McpProxyOptions;
54
+ /** For an MCP server that runs separately from the renderer (the CLIENT side): where to reach the SSR
55
+ * `/preview` endpoint so the visual-preview tools work. The SDK builds an HTTP preview client from this;
56
+ * absent → those tools report PREVIEW_UNAVAILABLE. */
57
+ previewClient?: {
58
+ url: string;
59
+ secret?: string;
60
+ };
61
+ /** Dedicated headless-browser service for plitzi_screenshot (off unless set). `serviceUrl` is the browser
62
+ * service that turns a URL into PNG(s); `renderBaseUrl` is the SSR base the browser navigates to (a page path
63
+ * + the one-shot `__pt` token are appended). When absent, plitzi_screenshot is not registered and only the HTML
64
+ * plitzi_preview is available; when the service is unreachable at call time the tool degrades to returning the
65
+ * HTML preview with a warning. */
66
+ screenshot?: {
67
+ serviceUrl: string;
68
+ renderBaseUrl: string;
69
+ };
70
+ /** OAuth 2.1 authorization for remote connectors (Claude Desktop, ChatGPT), which cannot send a custom header.
71
+ * Omit to keep the server anonymous: discovery 404s and every caller is served unauthenticated. */
72
+ oauth?: OAuthConfig;
73
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { McpOptions } from './options';
2
+ import { BaseContext, PipelineExtensions, Stage } from '@plitzi/sdk-server/kernel';
3
+ export declare const buildMCPPipeline: (options?: McpOptions) => Stage<BaseContext>[];
4
+ /** What this package contributes to somebody else's PAGE server: the MCP endpoint alongside SSR on one port.
5
+ * Every stage here gates itself — MCP is self-authenticating, the widget proxy must stay reachable without a
6
+ * credential, and draft-preview is off unless `config.preview.enabled` and guarded by a shared secret — so they
7
+ * all belong in the `preAuth` slot, ahead of the auth middleware chain.
8
+ *
9
+ * A page server that never calls this loads none of it: that is the whole point of handing it over as stages
10
+ * instead of a config flag. The options travel with them for the same reason — the page server's own config
11
+ * says nothing about MCP, so a deployment that serves pages only never reads a word of this. */
12
+ export declare const mcpExtensions: (options?: McpOptions) => PipelineExtensions;
@@ -0,0 +1,29 @@
1
+ import { createMcpOnlyStage, createMcpStage } from "./stages/mcp.js";
2
+ import { createOAuthGuardStage, createOAuthStage } from "./stages/oauth.js";
3
+ import { previewStage } from "./stages/preview.js";
4
+ import { createWidgetProxyStage } from "./stages/proxy.js";
5
+ import { configStaticStage, healthStage } from "@plitzi/sdk-server/kernel";
6
+ //#region src/pipeline.ts
7
+ var buildMCPPipeline = (options = {}) => [
8
+ healthStage,
9
+ configStaticStage,
10
+ createWidgetProxyStage(options),
11
+ createOAuthStage(options.oauth),
12
+ createOAuthGuardStage(options.oauth),
13
+ createMcpOnlyStage(options)
14
+ ];
15
+ /** What this package contributes to somebody else's PAGE server: the MCP endpoint alongside SSR on one port.
16
+ * Every stage here gates itself — MCP is self-authenticating, the widget proxy must stay reachable without a
17
+ * credential, and draft-preview is off unless `config.preview.enabled` and guarded by a shared secret — so they
18
+ * all belong in the `preAuth` slot, ahead of the auth middleware chain.
19
+ *
20
+ * A page server that never calls this loads none of it: that is the whole point of handing it over as stages
21
+ * instead of a config flag. The options travel with them for the same reason — the page server's own config
22
+ * says nothing about MCP, so a deployment that serves pages only never reads a word of this. */
23
+ var mcpExtensions = (options = {}) => ({ preAuth: [
24
+ createWidgetProxyStage(options),
25
+ createMcpStage(options),
26
+ previewStage
27
+ ] });
28
+ //#endregion
29
+ export { buildMCPPipeline, mcpExtensions };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { PreviewRequestBody, PreviewResult } from '../modules/mcp/types';
2
+ import { PluginManager, ServerCaches } from '@plitzi/sdk-server/ssr';
3
+ import { SSRPageServerConfig, SSRTemplateFn } from '@plitzi/sdk-shared';
4
+ /** Build a preview of a page: apply any unsaved `operations` to a clone (never persisted), render the resulting
5
+ * draft to full HTML via the SSR pipeline, and stash the draft under a one-shot token so a browser can fetch
6
+ * the exact same render at `?__pt=<token>` (for screenshots). With no operations it previews persisted state.
7
+ *
8
+ * Renders through the host page server's own singletons, which is why it takes them as arguments rather than
9
+ * building any: this runs as a stage INSIDE an SSR server, not in the MCP process that calls it over HTTP. */
10
+ export declare const createPreview: (body: PreviewRequestBody, config: SSRPageServerConfig, renderFn: SSRTemplateFn, pluginManager: PluginManager, caches: ServerCaches) => Promise<PreviewResult>;
@@ -0,0 +1,83 @@
1
+ import { computeVersion } from "../modules/mcp/helpers/computeVersion.js";
2
+ import { cloneSpace, findPageByRef, getPageElements } from "../modules/mcp/helpers/space.js";
3
+ import { applyOperations } from "../modules/mcp/tools/apply/dispatch.js";
4
+ import { validateOperations } from "../modules/mcp/tools/shared/validator/index.js";
5
+ import { randomUUID } from "node:crypto";
6
+ import { buildBody } from "@plitzi/sdk-server/ssr";
7
+ //#region src/preview/createPreview.ts
8
+ var resolvePagePath = (schema, pageRef) => {
9
+ const pages = getPageElements(schema);
10
+ const page = pageRef ? findPageByRef(schema, pageRef) : pages.find((p) => p.attributes.default) ?? pages[0];
11
+ const slug = page && typeof page.attributes.slug === "string" ? page.attributes.slug : "";
12
+ return slug.startsWith("/") ? slug : `/${slug}`;
13
+ };
14
+ var syntheticRequest = (pagePath) => ({
15
+ method: "GET",
16
+ path: pagePath,
17
+ search: "",
18
+ url: pagePath,
19
+ hostname: "localhost",
20
+ protocol: "https",
21
+ headers: {},
22
+ query: {},
23
+ ctx: {}
24
+ });
25
+ /** Build a preview of a page: apply any unsaved `operations` to a clone (never persisted), render the resulting
26
+ * draft to full HTML via the SSR pipeline, and stash the draft under a one-shot token so a browser can fetch
27
+ * the exact same render at `?__pt=<token>` (for screenshots). With no operations it previews persisted state.
28
+ *
29
+ * Renders through the host page server's own singletons, which is why it takes them as arguments rather than
30
+ * building any: this runs as a stage INSIDE an SSR server, not in the MCP process that calls it over HTTP. */
31
+ var createPreview = async (body, config, renderFn, pluginManager, caches) => {
32
+ const env = body.env ?? "main";
33
+ const revision = 0;
34
+ const offlineData = await config.adapters.getOfflineData(body.spaceId, env, revision);
35
+ if (!offlineData) return {
36
+ ok: false,
37
+ error: "NO_DATA",
38
+ message: `No offline data for space ${body.spaceId} (${env}).`
39
+ };
40
+ let draftOffline = offlineData;
41
+ if (body.operations && body.operations.length > 0) {
42
+ const draft = cloneSpace({
43
+ schema: offlineData.schema,
44
+ style: offlineData.style,
45
+ connectors: []
46
+ });
47
+ const validation = validateOperations(draft, body.operations);
48
+ if (!validation.valid) return {
49
+ ok: false,
50
+ error: "INVALID_OPERATIONS",
51
+ message: "The operations did not validate.",
52
+ errors: validation.errors
53
+ };
54
+ const outcome = applyOperations(draft, env, body.operations);
55
+ if (outcome.errors.length > 0) return {
56
+ ok: false,
57
+ error: "APPLY_FAILED",
58
+ message: "The operations could not be applied.",
59
+ errors: outcome.errors
60
+ };
61
+ draftOffline = {
62
+ ...offlineData,
63
+ schema: draft.schema,
64
+ style: draft.style
65
+ };
66
+ }
67
+ const pagePath = resolvePagePath(draftOffline.schema, body.pageRef);
68
+ const { body: html } = await buildBody(syntheticRequest(pagePath), config, body.spaceId, env, revision, renderFn, pluginManager, caches.offlineData, void 0, draftOffline);
69
+ let token;
70
+ if (config.draftStore) {
71
+ token = randomUUID();
72
+ await config.draftStore.put(token, draftOffline, config.preview?.ttlMs ?? 6e4);
73
+ }
74
+ return {
75
+ ok: true,
76
+ token,
77
+ pagePath,
78
+ html: html ?? "",
79
+ stateVersion: computeVersion(draftOffline)
80
+ };
81
+ };
82
+ //#endregion
83
+ export { createPreview };
@@ -0,0 +1,15 @@
1
+ /** The MCP role's entry point: everything a dedicated MCP deployment wires, and nothing else.
2
+ *
3
+ * Import it as `@plitzi/sdk-mcp/server`. The package root also carries the draft-preview endpoint, and that one
4
+ * reaches into the SSR render primitives — a dedicated MCP process constructs none of those, so pulling
5
+ * `createServer` from the barrel would load the page renderer and React with it. This entry loads the MCP
6
+ * server alone. */
7
+ export { createServer } from './createServer';
8
+ export { buildMCPPipeline } from './pipeline';
9
+ export { createMcpServer, handleMcp, serveMcp, readMcpBody } from './modules/mcp/handler';
10
+ export { createHttpPreviewClient } from './modules/mcp/previewClient';
11
+ export { createHttpScreenshotClient } from './modules/mcp/screenshotClient';
12
+ export type { McpRequestOptions } from './modules/mcp/handler';
13
+ export type { McpServerContext } from './modules/mcp/server';
14
+ export type { PreviewClient, ScreenshotClient } from './modules/mcp/types';
15
+ export type { McpOptions, McpProxyOptions } from './options';
package/dist/server.js ADDED
@@ -0,0 +1,7 @@
1
+ import { createMcpServer } from "./modules/mcp/server.js";
2
+ import { handleMcp, readMcpBody, serveMcp } from "./modules/mcp/handler.js";
3
+ import { createHttpPreviewClient } from "./modules/mcp/previewClient.js";
4
+ import { createHttpScreenshotClient } from "./modules/mcp/screenshotClient.js";
5
+ import { buildMCPPipeline } from "./pipeline.js";
6
+ import { createServer } from "./createServer.js";
7
+ export { buildMCPPipeline, createHttpPreviewClient, createHttpScreenshotClient, createMcpServer, createServer, handleMcp, readMcpBody, serveMcp };
@@ -0,0 +1,4 @@
1
+ import { McpOptions } from '../options';
2
+ import { Stage } from '@plitzi/sdk-server/kernel';
3
+ export declare const createMcpStage: (options?: McpOptions) => Stage;
4
+ export declare const createMcpOnlyStage: (options?: McpOptions) => Stage;
@@ -0,0 +1,30 @@
1
+ import { requestProxy } from "../modules/mcp/proxy/config.js";
2
+ import { handleMcp } from "../modules/mcp/handler.js";
3
+ import { createHttpPreviewClient } from "../modules/mcp/previewClient.js";
4
+ import { createHttpScreenshotClient } from "../modules/mcp/screenshotClient.js";
5
+ //#region src/stages/mcp.ts
6
+ var DEFAULT_PATH = "/mcp";
7
+ var serveMcp = async (ctx, options) => {
8
+ const { previewClient, screenshot } = options;
9
+ ctx.operation = await handleMcp(ctx.raw, ctx.rawRes, ctx.req, ctx.config.adapters, {
10
+ preview: previewClient ? createHttpPreviewClient(previewClient) : void 0,
11
+ screenshot: screenshot ? createHttpScreenshotClient(screenshot) : void 0,
12
+ logger: ctx.config.logger,
13
+ renderStreaming: options.renderStreaming,
14
+ proxy: requestProxy(options.proxy, ctx.req)
15
+ });
16
+ };
17
+ var createMcpStage = (options = {}) => {
18
+ const path = options.path ?? DEFAULT_PATH;
19
+ return async (ctx) => {
20
+ if (!ctx.req.path.startsWith(path)) return false;
21
+ await serveMcp(ctx, options);
22
+ return true;
23
+ };
24
+ };
25
+ var createMcpOnlyStage = (options = {}) => async (ctx) => {
26
+ await serveMcp(ctx, options);
27
+ return true;
28
+ };
29
+ //#endregion
30
+ export { createMcpOnlyStage, createMcpStage };
@@ -0,0 +1,19 @@
1
+ import { Stage } from '@plitzi/sdk-server/kernel';
2
+ import { OAuthConfig } from '@plitzi/sdk-shared';
3
+ /** OAuth 2.1 authorization for the MCP server, mounted ONLY when a deployment configures `oauth`. Without it the
4
+ * stage falls straight through and the server keeps its anonymous contract: discovery 404s, the public surface
5
+ * (handshake, listings, the guide, plitzi_render) answers without a token, and nothing below changes.
6
+ *
7
+ * It sits before the MCP stage because that one answers every path on a dedicated MCP server — these endpoints
8
+ * would otherwise be swallowed by the JSON-RPC transport, which is exactly the 406 a host hits on /register. */
9
+ export declare const createOAuthStage: (oauth?: OAuthConfig) => Stage;
10
+ /** The protected-resource half of OAuth: an MCP call that presents no bearer this server can verify is refused
11
+ * with RFC 6750's challenge instead of being served the anonymous surface. That 401 is the whole handshake — it
12
+ * is how a host learns the server needs authorization, where its metadata lives and which scopes to ask for, and
13
+ * a 200 tells it none of that. Only the JSON-RPC POST is guarded: the CORS preflight, the GET 405 and the
14
+ * discovery probes carry no credential and must keep answering as they do.
15
+ *
16
+ * Mounted only when `oauth` is configured. A deployment that configures none keeps the open server it had, where
17
+ * the whole public surface — handshake, listings, the guide, plitzi_render — answers without a token; with OAuth
18
+ * on, the grant that carries no space is what covers that same ground. */
19
+ export declare const createOAuthGuardStage: (oauth?: OAuthConfig) => Stage;
@@ -0,0 +1,114 @@
1
+ import { authorizationServerMetadata, protectedResourceMetadata } from "../modules/oauth/metadata.js";
2
+ import { getAccess } from "../modules/oauth/records.js";
3
+ import { sendErrorJson, sendJson } from "../modules/oauth/respond.js";
4
+ import { handleAuthorizeStart, handleAuthorizeSubmit } from "../modules/oauth/authorize.js";
5
+ import { bearerOf, sendChallenge } from "../modules/oauth/challenge.js";
6
+ import { handleRegister } from "../modules/oauth/register.js";
7
+ import { handleToken } from "../modules/oauth/token.js";
8
+ import { readRawBody } from "@plitzi/sdk-server/kernel";
9
+ //#region src/stages/oauth.ts
10
+ var matchesWellKnown = (path, wellKnown) => path === wellKnown || path.startsWith(`${wellKnown}/`);
11
+ var isOAuthPath = (path) => matchesWellKnown(path, "/.well-known/oauth-protected-resource") || matchesWellKnown(path, "/.well-known/oauth-authorization-server") || path === "/register" || path === "/authorize" || path === "/token";
12
+ var formParams = (req, body) => {
13
+ const params = { ...req.query };
14
+ for (const [key, value] of new URLSearchParams(body).entries()) params[key] = value;
15
+ return params;
16
+ };
17
+ var parseJson = (body) => {
18
+ try {
19
+ return JSON.parse(body);
20
+ } catch {
21
+ return;
22
+ }
23
+ };
24
+ /** OAuth 2.1 authorization for the MCP server, mounted ONLY when a deployment configures `oauth`. Without it the
25
+ * stage falls straight through and the server keeps its anonymous contract: discovery 404s, the public surface
26
+ * (handshake, listings, the guide, plitzi_render) answers without a token, and nothing below changes.
27
+ *
28
+ * It sits before the MCP stage because that one answers every path on a dedicated MCP server — these endpoints
29
+ * would otherwise be swallowed by the JSON-RPC transport, which is exactly the 406 a host hits on /register. */
30
+ var createOAuthStage = (oauth) => async (ctx) => {
31
+ const { path, method } = ctx.req;
32
+ if (!oauth || !isOAuthPath(path)) return false;
33
+ const { res } = ctx;
34
+ if (path !== "/authorize") {
35
+ res.setHeader("Access-Control-Allow-Origin", "*");
36
+ res.setHeader("Access-Control-Allow-Headers", "*");
37
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
38
+ }
39
+ if (method === "OPTIONS") {
40
+ res.setStatus(204);
41
+ res.end();
42
+ return true;
43
+ }
44
+ if (method === "GET" && matchesWellKnown(path, "/.well-known/oauth-protected-resource")) {
45
+ sendJson(res, 200, protectedResourceMetadata(oauth, ctx.req));
46
+ return true;
47
+ }
48
+ if (method === "GET" && matchesWellKnown(path, "/.well-known/oauth-authorization-server")) {
49
+ sendJson(res, 200, authorizationServerMetadata(oauth, ctx.req));
50
+ return true;
51
+ }
52
+ if (path === "/authorize" && method === "GET") {
53
+ await handleAuthorizeStart(oauth, res, ctx.req.query);
54
+ return true;
55
+ }
56
+ if (path === "/authorize" && method === "POST") {
57
+ await handleAuthorizeSubmit(oauth, res, formParams(ctx.req, await readRawBody(ctx.raw)));
58
+ return true;
59
+ }
60
+ if (path === "/token" && method === "POST") {
61
+ await handleToken(oauth, res, formParams(ctx.req, await readRawBody(ctx.raw)));
62
+ return true;
63
+ }
64
+ if (path === "/register" && method === "POST") {
65
+ await handleRegister(oauth, res, parseJson(await readRawBody(ctx.raw)));
66
+ return true;
67
+ }
68
+ sendErrorJson(res, 405, "invalid_request", `${method} is not allowed on ${path}.`);
69
+ return true;
70
+ };
71
+ var CHALLENGE_DESCRIPTIONS = {
72
+ "no-credential": "Authorization is required to use this server.",
73
+ "unknown-credential": "The access token is invalid, expired or revoked.",
74
+ "store-unreachable": "The access token could not be verified right now.",
75
+ "adapter-failed": "The access token could not be verified right now."
76
+ };
77
+ var challengeReason = async (oauth, ctx, token) => {
78
+ if (!token) return "no-credential";
79
+ try {
80
+ const record = await getAccess(oauth.adapters.store, token);
81
+ if (record) {
82
+ const credential = record.credential ?? token;
83
+ ctx.req.headers["x-access-token"] = credential;
84
+ ctx.req.headers.authorization = `Bearer ${credential}`;
85
+ return;
86
+ }
87
+ } catch {
88
+ return "store-unreachable";
89
+ }
90
+ try {
91
+ return await ctx.config.adapters.getGrant?.(ctx.req) === void 0 ? "unknown-credential" : void 0;
92
+ } catch {
93
+ return "adapter-failed";
94
+ }
95
+ };
96
+ /** The protected-resource half of OAuth: an MCP call that presents no bearer this server can verify is refused
97
+ * with RFC 6750's challenge instead of being served the anonymous surface. That 401 is the whole handshake — it
98
+ * is how a host learns the server needs authorization, where its metadata lives and which scopes to ask for, and
99
+ * a 200 tells it none of that. Only the JSON-RPC POST is guarded: the CORS preflight, the GET 405 and the
100
+ * discovery probes carry no credential and must keep answering as they do.
101
+ *
102
+ * Mounted only when `oauth` is configured. A deployment that configures none keeps the open server it had, where
103
+ * the whole public surface — handshake, listings, the guide, plitzi_render — answers without a token; with OAuth
104
+ * on, the grant that carries no space is what covers that same ground. */
105
+ var createOAuthGuardStage = (oauth) => async (ctx) => {
106
+ if (!oauth || ctx.req.method !== "POST") return false;
107
+ const reason = await challengeReason(oauth, ctx, bearerOf(ctx.req));
108
+ if (!reason) return false;
109
+ ctx.operation = `oauth-challenge:${reason}`;
110
+ sendChallenge(oauth, ctx.req, ctx.res, CHALLENGE_DESCRIPTIONS[reason]);
111
+ return true;
112
+ };
113
+ //#endregion
114
+ export { createOAuthGuardStage, createOAuthStage };
@@ -0,0 +1,2 @@
1
+ import { SSRContext, Stage } from '@plitzi/sdk-server/kernel';
2
+ export declare const previewStage: Stage<SSRContext>;