@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.
- package/CHANGELOG.md +15 -0
- package/README.md +175 -0
- package/dist/createServer.d.ts +11 -0
- package/dist/createServer.js +36 -0
- package/dist/createServer.test.d.ts +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +21 -0
- package/dist/modules/ai/AIEngine.d.ts +20 -0
- package/dist/modules/ai/AIEngine.js +120 -0
- package/dist/modules/ai/index.d.ts +4 -0
- package/dist/modules/ai/toolkit.d.ts +17 -0
- package/dist/modules/ai/toolkit.js +59 -0
- package/dist/modules/ai/toolkit.test.d.ts +1 -0
- package/dist/modules/mcp/apps/apps.test.d.ts +1 -0
- package/dist/modules/mcp/apps/example/index.d.ts +8 -0
- package/dist/modules/mcp/apps/example/view/index.tsx +70 -0
- package/dist/modules/mcp/apps/index.d.ts +11 -0
- package/dist/modules/mcp/apps/index.js +16 -0
- package/dist/modules/mcp/apps/render/index.d.ts +4 -0
- package/dist/modules/mcp/apps/render/index.js +17 -0
- package/dist/modules/mcp/apps/render/styles.d.ts +10 -0
- package/dist/modules/mcp/apps/render/styles.js +54 -0
- package/dist/modules/mcp/apps/render/styles.test.d.ts +1 -0
- package/dist/modules/mcp/apps/render/view/heldBatch.ts +107 -0
- package/dist/modules/mcp/apps/render/view/index.tsx +314 -0
- package/dist/modules/mcp/apps/render/view/streamProgress.ts +137 -0
- package/dist/modules/mcp/apps/shared/assets.d.ts +10 -0
- package/dist/modules/mcp/apps/shared/assets.js +10 -0
- package/dist/modules/mcp/apps/shared/bundle.d.ts +4 -0
- package/dist/modules/mcp/apps/shared/bundle.js +23 -0
- package/dist/modules/mcp/apps/shared/index.d.ts +3 -0
- package/dist/modules/mcp/apps/shared/page.d.ts +2 -0
- package/dist/modules/mcp/apps/shared/page.js +34 -0
- package/dist/modules/mcp/apps/shared/registerApp.d.ts +5 -0
- package/dist/modules/mcp/apps/shared/registerApp.js +43 -0
- package/dist/modules/mcp/apps/shared/resolve.d.ts +1 -0
- package/dist/modules/mcp/apps/shared/resolve.js +5 -0
- package/dist/modules/mcp/apps/shared/shell.ejs +59 -0
- package/dist/modules/mcp/apps/shared/zodEnglishOnly.d.ts +4 -0
- package/dist/modules/mcp/apps/shared/zodEnglishOnly.js +23 -0
- package/dist/modules/mcp/catalogs/builtinCallbacks.d.ts +19 -0
- package/dist/modules/mcp/catalogs/builtinCallbacks.js +139 -0
- package/dist/modules/mcp/catalogs/builtinComponents.d.ts +4 -0
- package/dist/modules/mcp/catalogs/builtinComponents.js +165 -0
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.d.ts +17 -0
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +50 -0
- package/dist/modules/mcp/catalogs/builtinTransformers.d.ts +28 -0
- package/dist/modules/mcp/catalogs/builtinTransformers.js +148 -0
- package/dist/modules/mcp/catalogs/builtinTransformers.test.d.ts +1 -0
- package/dist/modules/mcp/catalogs/builtinUtilities.d.ts +15 -0
- package/dist/modules/mcp/catalogs/builtinUtilities.js +90 -0
- package/dist/modules/mcp/catalogs/cssCatalog/border.d.ts +4 -0
- package/dist/modules/mcp/catalogs/cssCatalog/border.js +30 -0
- package/dist/modules/mcp/catalogs/cssCatalog/box.d.ts +4 -0
- package/dist/modules/mcp/catalogs/cssCatalog/box.js +31 -0
- package/dist/modules/mcp/catalogs/cssCatalog/cssCatalog.test.d.ts +1 -0
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.d.ts +34 -0
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +185 -0
- package/dist/modules/mcp/catalogs/cssCatalog/index.d.ts +18 -0
- package/dist/modules/mcp/catalogs/cssCatalog/index.js +131 -0
- package/dist/modules/mcp/catalogs/cssCatalog/layout.d.ts +9 -0
- package/dist/modules/mcp/catalogs/cssCatalog/layout.js +99 -0
- package/dist/modules/mcp/catalogs/cssCatalog/visual.d.ts +8 -0
- package/dist/modules/mcp/catalogs/cssCatalog/visual.js +147 -0
- package/dist/modules/mcp/catalogs/index.d.ts +9 -0
- package/dist/modules/mcp/catalogs/observed.d.ts +46 -0
- package/dist/modules/mcp/catalogs/observed.js +90 -0
- package/dist/modules/mcp/catalogs/paramSpec.d.ts +39 -0
- package/dist/modules/mcp/catalogs/paramSpec.js +69 -0
- package/dist/modules/mcp/catalogs/registry.d.ts +35 -0
- package/dist/modules/mcp/catalogs/registry.js +89 -0
- package/dist/modules/mcp/e2e/connector.test.d.ts +1 -0
- package/dist/modules/mcp/e2e/host.test.d.ts +1 -0
- package/dist/modules/mcp/e2e/index.d.ts +6 -0
- package/dist/modules/mcp/e2e/mcpEndpoint.d.ts +27 -0
- package/dist/modules/mcp/e2e/oauthConnector.test.d.ts +1 -0
- package/dist/modules/mcp/e2e/postMessageChannel.d.ts +22 -0
- package/dist/modules/mcp/e2e/renderingHost.d.ts +39 -0
- package/dist/modules/mcp/handler.d.ts +22 -0
- package/dist/modules/mcp/handler.js +83 -0
- package/dist/modules/mcp/helpers/agentPrompt.d.ts +4 -0
- package/dist/modules/mcp/helpers/agentPrompt.js +104 -0
- package/dist/modules/mcp/helpers/computeVersion.d.ts +1 -0
- package/dist/modules/mcp/helpers/computeVersion.js +16 -0
- package/dist/modules/mcp/helpers/guide.d.ts +4 -0
- package/dist/modules/mcp/helpers/guide.js +608 -0
- package/dist/modules/mcp/helpers/index.d.ts +8 -0
- package/dist/modules/mcp/helpers/interactions.d.ts +30 -0
- package/dist/modules/mcp/helpers/interactions.js +123 -0
- package/dist/modules/mcp/helpers/log.d.ts +8 -0
- package/dist/modules/mcp/helpers/log.js +64 -0
- package/dist/modules/mcp/helpers/log.test.d.ts +1 -0
- package/dist/modules/mcp/helpers/opResult.d.ts +13 -0
- package/dist/modules/mcp/helpers/opResult.js +18 -0
- package/dist/modules/mcp/helpers/space.d.ts +126 -0
- package/dist/modules/mcp/helpers/space.js +314 -0
- package/dist/modules/mcp/helpers/uris.d.ts +33 -0
- package/dist/modules/mcp/helpers/uris.js +50 -0
- package/dist/modules/mcp/index.d.ts +13 -0
- package/dist/modules/mcp/mcp.bench.d.ts +1 -0
- package/dist/modules/mcp/previewClient.d.ts +13 -0
- package/dist/modules/mcp/previewClient.js +31 -0
- package/dist/modules/mcp/proxy/config.d.ts +20 -0
- package/dist/modules/mcp/proxy/config.js +62 -0
- package/dist/modules/mcp/proxy/endpoint.test.d.ts +1 -0
- package/dist/modules/mcp/proxy/fetch.d.ts +18 -0
- package/dist/modules/mcp/proxy/fetch.js +91 -0
- package/dist/modules/mcp/proxy/grant.d.ts +25 -0
- package/dist/modules/mcp/proxy/grant.js +67 -0
- package/dist/modules/mcp/proxy/guard.d.ts +6 -0
- package/dist/modules/mcp/proxy/guard.js +38 -0
- package/dist/modules/mcp/proxy/handler.d.ts +8 -0
- package/dist/modules/mcp/proxy/handler.js +99 -0
- package/dist/modules/mcp/proxy/index.d.ts +8 -0
- package/dist/modules/mcp/proxy/payload.d.ts +8 -0
- package/dist/modules/mcp/proxy/payload.js +29 -0
- package/dist/modules/mcp/proxy/proxy.test.d.ts +1 -0
- package/dist/modules/mcp/proxy/rewrite.d.ts +18 -0
- package/dist/modules/mcp/proxy/rewrite.js +138 -0
- package/dist/modules/mcp/proxy/sign.d.ts +6 -0
- package/dist/modules/mcp/proxy/sign.js +15 -0
- package/dist/modules/mcp/proxy/types.d.ts +45 -0
- package/dist/modules/mcp/proxy/types.js +9 -0
- package/dist/modules/mcp/proxy/wiring.test.d.ts +1 -0
- package/dist/modules/mcp/resources/canonical.d.ts +6 -0
- package/dist/modules/mcp/resources/canonical.js +30 -0
- package/dist/modules/mcp/resources/connectors.d.ts +22 -0
- package/dist/modules/mcp/resources/connectors.js +46 -0
- package/dist/modules/mcp/resources/core.d.ts +5 -0
- package/dist/modules/mcp/resources/core.js +18 -0
- package/dist/modules/mcp/resources/envelope.d.ts +10 -0
- package/dist/modules/mcp/resources/envelope.js +14 -0
- package/dist/modules/mcp/resources/index.d.ts +9 -0
- package/dist/modules/mcp/resources/primer.d.ts +7 -0
- package/dist/modules/mcp/resources/primer.js +33 -0
- package/dist/modules/mcp/resources/register.d.ts +10 -0
- package/dist/modules/mcp/resources/register.js +205 -0
- package/dist/modules/mcp/resources/renderGuide.d.ts +10 -0
- package/dist/modules/mcp/resources/renderGuide.js +451 -0
- package/dist/modules/mcp/resources/router.d.ts +10 -0
- package/dist/modules/mcp/resources/router.js +39 -0
- package/dist/modules/mcp/resources/schema.d.ts +5 -0
- package/dist/modules/mcp/resources/schema.js +43 -0
- package/dist/modules/mcp/resources/style.d.ts +5 -0
- package/dist/modules/mcp/resources/style.js +34 -0
- package/dist/modules/mcp/screenshotClient.d.ts +13 -0
- package/dist/modules/mcp/screenshotClient.js +47 -0
- package/dist/modules/mcp/server.d.ts +31 -0
- package/dist/modules/mcp/server.js +127 -0
- package/dist/modules/mcp/tests/apply.test.d.ts +1 -0
- package/dist/modules/mcp/tests/bindings.test.d.ts +1 -0
- package/dist/modules/mcp/tests/connectors.test.d.ts +1 -0
- package/dist/modules/mcp/tests/css.test.d.ts +1 -0
- package/dist/modules/mcp/tests/helpers.d.ts +13 -0
- package/dist/modules/mcp/tests/interactions.test.d.ts +1 -0
- package/dist/modules/mcp/tests/pages.test.d.ts +1 -0
- package/dist/modules/mcp/tests/reads.test.d.ts +1 -0
- package/dist/modules/mcp/tests/schemaIds.test.d.ts +1 -0
- package/dist/modules/mcp/tests/search.test.d.ts +1 -0
- package/dist/modules/mcp/tests/skill.test.d.ts +1 -0
- package/dist/modules/mcp/tests/styles.test.d.ts +1 -0
- package/dist/modules/mcp/tests/tools.test.d.ts +1 -0
- package/dist/modules/mcp/tests/validation.test.d.ts +1 -0
- package/dist/modules/mcp/tools/apply/dispatch.d.ts +6 -0
- package/dist/modules/mcp/tools/apply/dispatch.js +128 -0
- package/dist/modules/mcp/tools/apply/index.d.ts +656 -0
- package/dist/modules/mcp/tools/apply/index.js +161 -0
- package/dist/modules/mcp/tools/apply/writeResult.d.ts +8 -0
- package/dist/modules/mcp/tools/apply/writeResult.js +37 -0
- package/dist/modules/mcp/tools/index.d.ts +18 -0
- package/dist/modules/mcp/tools/index.js +24 -0
- package/dist/modules/mcp/tools/operations/connectors/deleteConnector.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/connectors/deleteConnector.js +20 -0
- package/dist/modules/mcp/tools/operations/connectors/index.d.ts +188 -0
- package/dist/modules/mcp/tools/operations/connectors/index.js +12 -0
- package/dist/modules/mcp/tools/operations/connectors/manifest.d.ts +89 -0
- package/dist/modules/mcp/tools/operations/connectors/manifest.js +70 -0
- package/dist/modules/mcp/tools/operations/connectors/patchConnector.d.ts +94 -0
- package/dist/modules/mcp/tools/operations/connectors/patchConnector.js +58 -0
- package/dist/modules/mcp/tools/operations/connectors/upsertConnector.d.ts +98 -0
- package/dist/modules/mcp/tools/operations/connectors/upsertConnector.js +64 -0
- package/dist/modules/mcp/tools/operations/index.d.ts +2235 -0
- package/dist/modules/mcp/tools/operations/index.js +55 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +17 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +32 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +25 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +36 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +27 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +47 -0
- package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.d.ts +10 -0
- package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +29 -0
- package/dist/modules/mcp/tools/operations/schema/elements/moveElement.d.ts +16 -0
- package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +41 -0
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +27 -0
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +60 -0
- package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.d.ts +55 -0
- package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +148 -0
- package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.d.ts +16 -0
- package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +66 -0
- package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +32 -0
- package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.d.ts +12 -0
- package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +49 -0
- package/dist/modules/mcp/tools/operations/schema/index.d.ts +21 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +12 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +52 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +18 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +47 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +27 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +44 -0
- package/dist/modules/mcp/tools/operations/schema/operations.d.ts +236 -0
- package/dist/modules/mcp/tools/operations/schema/operations.js +41 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deletePage.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +25 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +14 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +77 -0
- package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +36 -0
- package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +44 -0
- package/dist/modules/mcp/tools/operations/schema/shared.d.ts +106 -0
- package/dist/modules/mcp/tools/operations/schema/shared.js +131 -0
- package/dist/modules/mcp/tools/operations/schema/translator.d.ts +12 -0
- package/dist/modules/mcp/tools/operations/schema/translator.js +216 -0
- package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +18 -0
- package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.d.ts +16 -0
- package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.js +42 -0
- package/dist/modules/mcp/tools/operations/schema/write.d.ts +42 -0
- package/dist/modules/mcp/tools/operations/schema/write.js +112 -0
- package/dist/modules/mcp/tools/operations/schemaIds.d.ts +6 -0
- package/dist/modules/mcp/tools/operations/schemaIds.js +58 -0
- package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +21 -0
- package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.d.ts +37 -0
- package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +28 -0
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.d.ts +37 -0
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.js +24 -0
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.d.ts +41 -0
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.js +40 -0
- package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +21 -0
- package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.d.ts +37 -0
- package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +28 -0
- package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.d.ts +37 -0
- package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.js +24 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +21 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +37 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +28 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +37 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +24 -0
- package/dist/modules/mcp/tools/operations/style/index.d.ts +15 -0
- package/dist/modules/mcp/tools/operations/style/operations.d.ts +264 -0
- package/dist/modules/mcp/tools/operations/style/operations.js +29 -0
- package/dist/modules/mcp/tools/operations/style/shared.d.ts +116 -0
- package/dist/modules/mcp/tools/operations/style/shared.js +59 -0
- package/dist/modules/mcp/tools/operations/style/translator.d.ts +12 -0
- package/dist/modules/mcp/tools/operations/style/translator.js +101 -0
- package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.d.ts +15 -0
- package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +21 -0
- package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.d.ts +20 -0
- package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.js +22 -0
- package/dist/modules/mcp/tools/operations/style/write.d.ts +12 -0
- package/dist/modules/mcp/tools/operations/style/write.js +108 -0
- package/dist/modules/mcp/tools/preview.d.ts +472 -0
- package/dist/modules/mcp/tools/preview.js +37 -0
- package/dist/modules/mcp/tools/read.d.ts +9 -0
- package/dist/modules/mcp/tools/read.js +51 -0
- package/dist/modules/mcp/tools/render.d.ts +506 -0
- package/dist/modules/mcp/tools/render.js +184 -0
- package/dist/modules/mcp/tools/render.test.d.ts +1 -0
- package/dist/modules/mcp/tools/screenshot.d.ts +656 -0
- package/dist/modules/mcp/tools/screenshot.js +83 -0
- package/dist/modules/mcp/tools/search.d.ts +15 -0
- package/dist/modules/mcp/tools/search.js +115 -0
- package/dist/modules/mcp/tools/shared/expandOperations.d.ts +13 -0
- package/dist/modules/mcp/tools/shared/expandOperations.js +44 -0
- package/dist/modules/mcp/tools/shared/tool.d.ts +72 -0
- package/dist/modules/mcp/tools/shared/tool.js +33 -0
- package/dist/modules/mcp/tools/shared/validator/audit.d.ts +4 -0
- package/dist/modules/mcp/tools/shared/validator/audit.js +124 -0
- package/dist/modules/mcp/tools/shared/validator/batch.d.ts +5 -0
- package/dist/modules/mcp/tools/shared/validator/batch.js +39 -0
- package/dist/modules/mcp/tools/shared/validator/bindings.d.ts +6 -0
- package/dist/modules/mcp/tools/shared/validator/bindings.js +70 -0
- package/dist/modules/mcp/tools/shared/validator/connectors.d.ts +19 -0
- package/dist/modules/mcp/tools/shared/validator/connectors.js +76 -0
- package/dist/modules/mcp/tools/shared/validator/context.d.ts +38 -0
- package/dist/modules/mcp/tools/shared/validator/context.js +35 -0
- package/dist/modules/mcp/tools/shared/validator/css.d.ts +4 -0
- package/dist/modules/mcp/tools/shared/validator/css.js +39 -0
- package/dist/modules/mcp/tools/shared/validator/elements.d.ts +7 -0
- package/dist/modules/mcp/tools/shared/validator/elements.js +68 -0
- package/dist/modules/mcp/tools/shared/validator/index.d.ts +8 -0
- package/dist/modules/mcp/tools/shared/validator/index.js +268 -0
- package/dist/modules/mcp/tools/shared/validator/interactions.d.ts +3 -0
- package/dist/modules/mcp/tools/shared/validator/interactions.js +103 -0
- package/dist/modules/mcp/tools/shared/validator/refs.d.ts +4 -0
- package/dist/modules/mcp/tools/shared/validator/refs.js +28 -0
- package/dist/modules/mcp/tools/validate.d.ts +653 -0
- package/dist/modules/mcp/tools/validate.js +47 -0
- package/dist/modules/mcp/types/aiSchema.d.ts +226 -0
- package/dist/modules/mcp/types/appTypes.d.ts +26 -0
- package/dist/modules/mcp/types/index.d.ts +5 -0
- package/dist/modules/mcp/types/previewTypes.d.ts +25 -0
- package/dist/modules/mcp/types/screenshotTypes.d.ts +29 -0
- package/dist/modules/mcp/types/toolTypes.d.ts +145 -0
- package/dist/modules/oauth/authorize.d.ts +7 -0
- package/dist/modules/oauth/authorize.js +177 -0
- package/dist/modules/oauth/challenge.d.ts +11 -0
- package/dist/modules/oauth/challenge.js +33 -0
- package/dist/modules/oauth/consentPage.d.ts +7 -0
- package/dist/modules/oauth/consentPage.js +118 -0
- package/dist/modules/oauth/metadata.d.ts +40 -0
- package/dist/modules/oauth/metadata.js +69 -0
- package/dist/modules/oauth/oauth.test.d.ts +1 -0
- package/dist/modules/oauth/params.d.ts +5 -0
- package/dist/modules/oauth/params.js +5 -0
- package/dist/modules/oauth/pkce.d.ts +6 -0
- package/dist/modules/oauth/pkce.js +15 -0
- package/dist/modules/oauth/records.d.ts +71 -0
- package/dist/modules/oauth/records.js +46 -0
- package/dist/modules/oauth/register.d.ts +5 -0
- package/dist/modules/oauth/register.js +55 -0
- package/dist/modules/oauth/respond.d.ts +13 -0
- package/dist/modules/oauth/respond.js +44 -0
- package/dist/modules/oauth/token.d.ts +5 -0
- package/dist/modules/oauth/token.js +100 -0
- package/dist/options.d.ts +73 -0
- package/dist/packageBoundary.test.d.ts +1 -0
- package/dist/pipeline.d.ts +12 -0
- package/dist/pipeline.js +29 -0
- package/dist/pipeline.test.d.ts +1 -0
- package/dist/preview/createPreview.d.ts +10 -0
- package/dist/preview/createPreview.js +83 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +7 -0
- package/dist/stages/mcp.d.ts +4 -0
- package/dist/stages/mcp.js +30 -0
- package/dist/stages/oauth.d.ts +19 -0
- package/dist/stages/oauth.js +114 -0
- package/dist/stages/preview.d.ts +2 -0
- package/dist/stages/preview.js +37 -0
- package/dist/stages/proxy.d.ts +3 -0
- package/dist/stages/proxy.js +14 -0
- package/dist/tests/httpRequest.d.ts +14 -0
- package/package.json +77 -0
- package/skills/plitzi-render/SKILL.md +174 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @plitzi/sdk-mcp
|
|
2
|
+
|
|
3
|
+
The AI surface for Plitzi spaces: an [MCP](https://modelcontextprotocol.io) server that lets an agent read and
|
|
4
|
+
edit a space, the tool engine behind it, the widget renderer, and the draft-preview endpoint.
|
|
5
|
+
|
|
6
|
+
It is a sibling of [`@plitzi/sdk-server`](../server/README.md), not a layer on top of it. That package serves
|
|
7
|
+
pages; this one serves agents. They share only the HTTP kernel, which this package imports from
|
|
8
|
+
`@plitzi/sdk-server/kernel` — a narrow entry that carries the dispatcher and the transports and nothing else, so
|
|
9
|
+
a page-only deployment installs none of this and an MCP deployment loads no page renderer.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add @plitzi/sdk-mcp
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Two topologies
|
|
18
|
+
|
|
19
|
+
### Dedicated MCP server
|
|
20
|
+
|
|
21
|
+
The shape a real MCP deployment has: it owns its whole sub-domain and answers JSON-RPC on **every** path, not
|
|
22
|
+
under `/mcp`.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { createServer } from '@plitzi/sdk-mcp/server';
|
|
26
|
+
|
|
27
|
+
const server = createServer({
|
|
28
|
+
httpVersion: 1,
|
|
29
|
+
adapters: { getGrant, getSchema, getStyle, saveSchema, saveStyle }
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
server.listen(8891);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Import from `@plitzi/sdk-mcp/server`, not the package root. The root barrel also carries the draft-preview
|
|
36
|
+
endpoint, which reaches into the SSR renderer; a dedicated MCP process constructs none of that.
|
|
37
|
+
|
|
38
|
+
### Alongside pages, on one port
|
|
39
|
+
|
|
40
|
+
Hand the stages to a page server. Order is the page pipeline's invariant, so they travel by slot rather than as a
|
|
41
|
+
list — see [Extending the pipeline](../server/README.md#extending-the-pipeline):
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createServer } from '@plitzi/sdk-server';
|
|
45
|
+
import { mcpExtensions } from '@plitzi/sdk-mcp';
|
|
46
|
+
|
|
47
|
+
const server = createServer({ adapters }, mcpExtensions());
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`mcpExtensions()` contributes three stages, all in the `preAuth` slot because each gates itself: the MCP endpoint
|
|
51
|
+
under `/mcp` (self-authenticating), the widget proxy (must stay reachable without a credential), and
|
|
52
|
+
draft-preview (off unless `preview.enabled`, then guarded by a shared secret). Import them individually when you
|
|
53
|
+
want only some:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { previewStage } from '@plitzi/sdk-mcp';
|
|
57
|
+
|
|
58
|
+
const server = createServer({ adapters, preview: { enabled: true, secret } }, { preAuth: [previewStage] });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Adapters
|
|
62
|
+
|
|
63
|
+
The server is stateless: it resolves the space per request and reads and writes through adapters you supply.
|
|
64
|
+
|
|
65
|
+
| Adapter | Required | Purpose |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `getGrant(req)` | yes | The space this request operates on **and whether the caller may change it** (`{ spaceId, scope, userId?, canWrite }`), decoded from the verified `Authorization` bearer. You own the JWT secret and the authorization model, so both are decided on your side. Return `undefined` for a missing or invalid token. |
|
|
68
|
+
| `getSchema(spaceId, env)` | yes | The element schema the tools read and mutate. |
|
|
69
|
+
| `getStyle(spaceId, env)` | yes | The full style document, including `platform`/`mode`. |
|
|
70
|
+
| `saveSchema(spaceId, env, schema)` | for writes | Persist a mutated schema. Without it, `plitzi_apply` reports `persisted: false`. |
|
|
71
|
+
| `saveStyle(spaceId, env, style)` | for writes | Persist a mutated style document. |
|
|
72
|
+
| `getOfflineData(spaceId, env, rev)` | for preview | Read side of draft-preview. Only the preview endpoint calls it. |
|
|
73
|
+
|
|
74
|
+
Schema and style are read as **separate documents** on purpose: `getOfflineData` is SSR-shaped and strips
|
|
75
|
+
`style.platform`, which the style resources need.
|
|
76
|
+
|
|
77
|
+
Without a `getGrant` that resolves, the server still answers its public surface — the handshake, the tool list,
|
|
78
|
+
the guide, the CSS-property catalog — and asks for a space only when a tool or resource needs one. A grant that
|
|
79
|
+
resolves with `canWrite: false` reads everything and is refused at every write tool.
|
|
80
|
+
|
|
81
|
+
## Tools
|
|
82
|
+
|
|
83
|
+
| Tool | Access | What it does |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| `plitzi_search` | read | Find elements, pages, styles and bindings; returns ready-made URIs |
|
|
86
|
+
| `plitzi_read` | read | Read one or more resources in detail by URI |
|
|
87
|
+
| `plitzi_validate` | read | Dry-run a batch of operations and report what would fail |
|
|
88
|
+
| `plitzi_apply` | write | Apply a batch of operations and persist |
|
|
89
|
+
| `plitzi_preview` | read | Render a draft to HTML through an SSR server |
|
|
90
|
+
| `plitzi_render` | read | Render a self-contained UI widget, offline, with no space |
|
|
91
|
+
|
|
92
|
+
Reads follow a filesystem model: list cheap, read one item in detail on demand. Agents are told never to
|
|
93
|
+
hand-build a URI — every write and search response hands back the URI to use next.
|
|
94
|
+
|
|
95
|
+
The tool functions are exported directly (`apply`, `search`, `read`, `validate`, `tools`), so a consumer can run
|
|
96
|
+
them in-process and wrap them as its own agent's tools instead of speaking MCP over HTTP.
|
|
97
|
+
|
|
98
|
+
## Draft preview
|
|
99
|
+
|
|
100
|
+
The two halves live in different packages, joined by a one-shot token:
|
|
101
|
+
|
|
102
|
+
1. `previewStage` (this package) runs **inside an SSR server**, because rendering needs that server's singletons.
|
|
103
|
+
It applies unsaved operations to a clone, renders the result, and stashes the draft under a token.
|
|
104
|
+
2. A normal render carrying `?__pt=<token>` (handled by `@plitzi/sdk-server`) serves that draft instead of the
|
|
105
|
+
persisted state, exactly once.
|
|
106
|
+
|
|
107
|
+
That is why applying operations lives here and the render lives there: interpreting an operation is the tool
|
|
108
|
+
engine's job, not the renderer's.
|
|
109
|
+
|
|
110
|
+
## OAuth
|
|
111
|
+
|
|
112
|
+
Opt-in and inert unless configured. With `oauth` set, an unauthenticated JSON-RPC call gets a `401` plus a
|
|
113
|
+
`WWW-Authenticate` challenge pointing at the discovery document — which is what makes a host such as Claude
|
|
114
|
+
Desktop start the flow. Without it, the server stays anonymous, discovery answers `404`, and every caller reaches
|
|
115
|
+
the public surface.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
createServer({
|
|
119
|
+
adapters,
|
|
120
|
+
oauth: { adapters: oauthAdapters, issuer, guest: { target: widgetsOnlyTarget } }
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Publish the connector URL **with a path** (`https://host/mcp`), not the bare origin.
|
|
125
|
+
|
|
126
|
+
## Agent skill
|
|
127
|
+
|
|
128
|
+
This package ships an [Agent Skill](https://agentskills.io/) for `plitzi_render`. It teaches an agent when to show
|
|
129
|
+
a widget instead of writing prose, the shape of a good call, the layout and theme traps that make a widget look
|
|
130
|
+
wrong in a chat panel, and how to iterate on one it already rendered.
|
|
131
|
+
|
|
132
|
+
It lives in [`skills/plitzi-render`](./skills/plitzi-render/SKILL.md) as a plain `SKILL.md`, so it installs by
|
|
133
|
+
copying that folder into your agent's skills directory (Claude Code, VS Code / Copilot, Codex, Gemini CLI, Cline,
|
|
134
|
+
Goose…):
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cp -R node_modules/@plitzi/sdk-mcp/skills/plitzi-render ~/.claude/skills/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
It only pays off with this server connected: it defers every detail to the `plitzi://render/guide` resource the
|
|
141
|
+
server publishes, so the two never drift apart.
|
|
142
|
+
|
|
143
|
+
## Running it locally
|
|
144
|
+
|
|
145
|
+
The package ships a small harness in [`dev/`](./dev) — file-backed adapters over a sample space — so you can
|
|
146
|
+
drive the tools without standing up a platform:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
yarn start # MCP on :3003 against dev/sample
|
|
150
|
+
yarn start:dev # same, restarting on change
|
|
151
|
+
yarn inspector # the official MCP Inspector, to point at it
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`MCP_PORT` and `MCP_HOST` move it; `LOG_REQUESTS=0` quiets the request log. Writes land back in `dev/sample`, so
|
|
155
|
+
`git restore dev/sample` resets a session.
|
|
156
|
+
|
|
157
|
+
`dev/` is not part of the published package and nothing in `src/` imports it — it consumes this package's public
|
|
158
|
+
API exactly as a consumer would.
|
|
159
|
+
|
|
160
|
+
## Examples
|
|
161
|
+
|
|
162
|
+
Runnable setups live in [`examples/`](../../examples) — [03-ai/01](../../examples/03-ai/01-mcp-server) is a dedicated MCP
|
|
163
|
+
server, [03-ai/02](../../examples/03-ai/02-ssr-preview) is the combined topology with draft preview. Each starts with
|
|
164
|
+
`yarn start`.
|
|
165
|
+
|
|
166
|
+
## Entry points
|
|
167
|
+
|
|
168
|
+
| Import | Carries |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `@plitzi/sdk-mcp/server` | The dedicated MCP server and its clients. What an MCP deployment wires. |
|
|
171
|
+
| `@plitzi/sdk-mcp` | Everything above plus the pipeline stages, `createPreview`, the tool engine and the AI engine. |
|
|
172
|
+
|
|
173
|
+
The split is about weight, not taste: ESM re-exports load eagerly, so the barrel pulls the draft-preview path and
|
|
174
|
+
the renderer it reaches into. A `no-restricted-imports` rule and a test in `src/packageBoundary.test.ts` keep this
|
|
175
|
+
package off the `@plitzi/sdk-server` root barrel for the same reason.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { McpOptions } from './options';
|
|
2
|
+
import { SSRServer, SSRServerConfig } from '@plitzi/sdk-shared';
|
|
3
|
+
/** The server this package makes: the lean mcp-ai pipeline over the bare context — no render template, caches
|
|
4
|
+
* or plugin manager. `config` is the HTTP server's (port, TLS, health, logger, adapters); `options` is what MCP
|
|
5
|
+
* itself serves, and lives here rather than in that config because the server does not need to know. Pair it with
|
|
6
|
+
* the MCP adapters (getGrant + getSchema/getStyle/saveSchema/saveStyle) — the page adapters are not required, and
|
|
7
|
+
* a dedicated MCP server has nothing to answer them with.
|
|
8
|
+
*
|
|
9
|
+
* It owns its whole sub-domain, answering JSON-RPC on every path rather than under /mcp. To serve MCP alongside
|
|
10
|
+
* pages on one port instead, hand `mcpExtensions(options)` to createServer from `@plitzi/sdk-server`. */
|
|
11
|
+
export declare const createServer: (config: SSRServerConfig, options?: McpOptions) => SSRServer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { buildMCPPipeline } from "./pipeline.js";
|
|
2
|
+
import { createHttpServer, makeHandler } from "@plitzi/sdk-server/kernel";
|
|
3
|
+
//#region src/createServer.ts
|
|
4
|
+
var noPlugins = {
|
|
5
|
+
register: () => void 0,
|
|
6
|
+
invalidate: () => Promise.resolve()
|
|
7
|
+
};
|
|
8
|
+
/** The server this package makes: the lean mcp-ai pipeline over the bare context — no render template, caches
|
|
9
|
+
* or plugin manager. `config` is the HTTP server's (port, TLS, health, logger, adapters); `options` is what MCP
|
|
10
|
+
* itself serves, and lives here rather than in that config because the server does not need to know. Pair it with
|
|
11
|
+
* the MCP adapters (getGrant + getSchema/getStyle/saveSchema/saveStyle) — the page adapters are not required, and
|
|
12
|
+
* a dedicated MCP server has nothing to answer them with.
|
|
13
|
+
*
|
|
14
|
+
* It owns its whole sub-domain, answering JSON-RPC on every path rather than under /mcp. To serve MCP alongside
|
|
15
|
+
* pages on one port instead, hand `mcpExtensions(options)` to createServer from `@plitzi/sdk-server`. */
|
|
16
|
+
var createServer = (config, options = {}) => {
|
|
17
|
+
const stages = buildMCPPipeline(options);
|
|
18
|
+
const makeHandlerForPort = (port) => {
|
|
19
|
+
const buildContext = (raw, rawRes, req, res) => ({
|
|
20
|
+
raw,
|
|
21
|
+
rawRes,
|
|
22
|
+
req,
|
|
23
|
+
res,
|
|
24
|
+
config,
|
|
25
|
+
port
|
|
26
|
+
});
|
|
27
|
+
return makeHandler("MCP", buildContext, stages, config.compression);
|
|
28
|
+
};
|
|
29
|
+
return createHttpServer(config, makeHandlerForPort, {
|
|
30
|
+
label: "MCP",
|
|
31
|
+
cache: null,
|
|
32
|
+
plugins: noPlugins
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createServer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Everything this package offers: the MCP server, the tool engine that backs it, the AI engine a consumer wraps
|
|
2
|
+
* its own agent around, and the stages that mount all of it inside somebody else's page server.
|
|
3
|
+
*
|
|
4
|
+
* A dedicated MCP deployment wants `@plitzi/sdk-mcp/server` instead — this barrel also pulls the draft-preview
|
|
5
|
+
* endpoint, which reaches into the SSR renderer. */
|
|
6
|
+
export { createServer } from './createServer';
|
|
7
|
+
export { buildMCPPipeline, mcpExtensions } from './pipeline';
|
|
8
|
+
export { createMcpOnlyStage, createMcpStage } from './stages/mcp';
|
|
9
|
+
export { createOAuthGuardStage, createOAuthStage } from './stages/oauth';
|
|
10
|
+
export { previewStage } from './stages/preview';
|
|
11
|
+
export { createWidgetProxyStage } from './stages/proxy';
|
|
12
|
+
export { createPreview } from './preview/createPreview';
|
|
13
|
+
export { AIEngine, toolResponseOk, toolResponseErr, zodToJsonSchema, getAllowedModes, bindTools, isToolActive, resolveToolHandler, isCallToolResult, toolResponseFromResult } from './modules/ai';
|
|
14
|
+
export { createMcpServer, handleMcp, serveMcp, readMcpBody, buildAgentGuide, createHttpPreviewClient, createHttpScreenshotClient } from './modules/mcp';
|
|
15
|
+
export { apply, search, read, validate, applyShape, searchShape, readShape, validateShape, operation, tools } from './modules/mcp/tools';
|
|
16
|
+
export type { McpServerContext, McpRequestOptions, PreviewClient, PreviewRequestBody, PreviewResult, HttpPreviewClientConfig, ScreenshotClient, ScreenshotImage, ScreenshotResult, Viewport, HttpScreenshotClientConfig } from './modules/mcp';
|
|
17
|
+
export type { ApplyInput, SearchInput, SearchResponse, SearchHit, ReadInput, ReadResponse, ReadHit, ValidateInput, WriteResponse, WriteElement, Persisters, Operation, ToolDef, ToolContext } from './modules/mcp/tools';
|
|
18
|
+
export type { Space } from './modules/mcp/helpers';
|
|
19
|
+
export type { Env } from './modules/mcp/types';
|
|
20
|
+
export type { McpOptions, McpProxyOptions } from './options';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildAgentGuide } from "./modules/mcp/helpers/agentPrompt.js";
|
|
2
|
+
import { operation } from "./modules/mcp/tools/operations/index.js";
|
|
3
|
+
import { apply, applyShape } from "./modules/mcp/tools/apply/index.js";
|
|
4
|
+
import { read, readShape } from "./modules/mcp/tools/read.js";
|
|
5
|
+
import { search, searchShape } from "./modules/mcp/tools/search.js";
|
|
6
|
+
import { validate, validateShape } from "./modules/mcp/tools/validate.js";
|
|
7
|
+
import { tools } from "./modules/mcp/tools/index.js";
|
|
8
|
+
import { bindTools, getAllowedModes, isCallToolResult, isToolActive, resolveToolHandler, toolResponseErr, toolResponseFromResult, toolResponseOk, zodToJsonSchema } from "./modules/ai/toolkit.js";
|
|
9
|
+
import { createMcpServer } from "./modules/mcp/server.js";
|
|
10
|
+
import { handleMcp, readMcpBody, serveMcp } from "./modules/mcp/handler.js";
|
|
11
|
+
import { createHttpPreviewClient } from "./modules/mcp/previewClient.js";
|
|
12
|
+
import { createHttpScreenshotClient } from "./modules/mcp/screenshotClient.js";
|
|
13
|
+
import { createMcpOnlyStage, createMcpStage } from "./stages/mcp.js";
|
|
14
|
+
import { createOAuthGuardStage, createOAuthStage } from "./stages/oauth.js";
|
|
15
|
+
import { createPreview } from "./preview/createPreview.js";
|
|
16
|
+
import { previewStage } from "./stages/preview.js";
|
|
17
|
+
import { createWidgetProxyStage } from "./stages/proxy.js";
|
|
18
|
+
import { buildMCPPipeline, mcpExtensions } from "./pipeline.js";
|
|
19
|
+
import { createServer } from "./createServer.js";
|
|
20
|
+
import AIEngine from "./modules/ai/AIEngine.js";
|
|
21
|
+
export { AIEngine, apply, applyShape, bindTools, buildAgentGuide, buildMCPPipeline, createHttpPreviewClient, createHttpScreenshotClient, createMcpOnlyStage, createMcpServer, createMcpStage, createOAuthGuardStage, createOAuthStage, createPreview, createServer, createWidgetProxyStage, getAllowedModes, handleMcp, isCallToolResult, isToolActive, mcpExtensions, operation, previewStage, read, readMcpBody, readShape, resolveToolHandler, search, searchShape, serveMcp, toolResponseErr, toolResponseFromResult, toolResponseOk, tools, validate, validateShape, zodToJsonSchema };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AiMode, AiContext, McpPromptHandler, McpToolHandler, McpToolLifecycleHooks, StreamCallbacks, McpTool, McpToolHandlerResult } from '@plitzi/sdk-shared';
|
|
2
|
+
declare class AIEngine implements McpToolLifecycleHooks {
|
|
3
|
+
private readonly mode;
|
|
4
|
+
readonly callbacks: StreamCallbacks;
|
|
5
|
+
private toolsAvailables;
|
|
6
|
+
private toolsAvailablesMap;
|
|
7
|
+
ctx: AiContext;
|
|
8
|
+
constructor(mode: AiMode | undefined, callbacks: StreamCallbacks, ctx: Omit<AiContext, 'mode'>);
|
|
9
|
+
readonly readResource: (name: string, uri: string) => void;
|
|
10
|
+
readonly setToolsAvailables: (tools: McpTool[]) => void;
|
|
11
|
+
readonly can: (name: string) => boolean;
|
|
12
|
+
readonly before: (name: string, args: Record<string, unknown>) => Promise<boolean>;
|
|
13
|
+
readonly after: (name: string, args: Record<string, unknown>, result: McpToolHandlerResult) => Promise<void>;
|
|
14
|
+
private readonly validateToolInput;
|
|
15
|
+
private readonly validateToolOutput;
|
|
16
|
+
private readonly runPipeline;
|
|
17
|
+
readonly execute: (name: string, handlerFn?: McpToolHandler) => (args: Record<string, unknown>) => Promise<McpToolHandlerResult>;
|
|
18
|
+
readonly executePrompt: (_name: string, handlerFn: McpPromptHandler) => (args: Record<string, unknown>) => Promise<import('@plitzi/sdk-shared').McpPromptHandlerResult>;
|
|
19
|
+
}
|
|
20
|
+
export default AIEngine;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { firstText, toolResponseErr } from "./toolkit.js";
|
|
2
|
+
//#region src/modules/ai/AIEngine.ts
|
|
3
|
+
var AIEngine = class {
|
|
4
|
+
mode;
|
|
5
|
+
callbacks;
|
|
6
|
+
toolsAvailables = /* @__PURE__ */ new Map();
|
|
7
|
+
toolsAvailablesMap = /* @__PURE__ */ new Map();
|
|
8
|
+
ctx;
|
|
9
|
+
constructor(mode, callbacks, ctx) {
|
|
10
|
+
this.mode = mode;
|
|
11
|
+
this.callbacks = callbacks;
|
|
12
|
+
this.ctx = {
|
|
13
|
+
...ctx,
|
|
14
|
+
mode: mode || "plan"
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
readResource = (name, uri) => {
|
|
18
|
+
this.callbacks.onResourceRead?.(name, uri);
|
|
19
|
+
};
|
|
20
|
+
setToolsAvailables = (tools) => {
|
|
21
|
+
this.toolsAvailables = new Map(tools.map((t) => [t.name, t]));
|
|
22
|
+
this.toolsAvailablesMap = new Map(tools.map((t) => [t.name, t.definition.allowedModes]));
|
|
23
|
+
};
|
|
24
|
+
can = (name) => {
|
|
25
|
+
if (!this.mode || !this.toolsAvailablesMap.has(name)) return false;
|
|
26
|
+
const allowedModes = this.toolsAvailablesMap.get(name);
|
|
27
|
+
return !allowedModes || allowedModes.includes(this.mode);
|
|
28
|
+
};
|
|
29
|
+
before = async (name, args) => {
|
|
30
|
+
this.callbacks.onBeforeTool?.(name, args);
|
|
31
|
+
if (!this.toolsAvailables.has(name)) {
|
|
32
|
+
this.callbacks.onLog?.("error", `tool rejected: '${name}' has no definition — possible security violation`);
|
|
33
|
+
await this.after(name, args, toolResponseErr(`Tool '${name}' is not defined and cannot be executed`));
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!this.can(name)) {
|
|
37
|
+
this.callbacks.onLog?.("info", `tool blocked: '${name}' is not permitted in ${this.mode} mode`);
|
|
38
|
+
await this.after(name, args, toolResponseErr(`Tool '${name}' is not permitted in ${this.mode} mode`));
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
after = (name, args, result) => {
|
|
44
|
+
let resultParsed;
|
|
45
|
+
if (result.data !== void 0) resultParsed = result.data;
|
|
46
|
+
else try {
|
|
47
|
+
resultParsed = JSON.parse(firstText(result.content) ?? "");
|
|
48
|
+
} catch {}
|
|
49
|
+
if (result.isError) this.callbacks.onToolError?.({
|
|
50
|
+
name,
|
|
51
|
+
args,
|
|
52
|
+
result: resultParsed ?? { error: firstText(result.content) ?? "Tool failed" }
|
|
53
|
+
});
|
|
54
|
+
else this.callbacks.onToolSuccess?.({
|
|
55
|
+
name,
|
|
56
|
+
args,
|
|
57
|
+
result: resultParsed
|
|
58
|
+
});
|
|
59
|
+
return Promise.resolve();
|
|
60
|
+
};
|
|
61
|
+
validateToolInput = (name, args) => {
|
|
62
|
+
const tool = this.toolsAvailables.get(name);
|
|
63
|
+
if (!tool || !tool.mcpDefinition.inputSchema) return {
|
|
64
|
+
success: true,
|
|
65
|
+
data: args
|
|
66
|
+
};
|
|
67
|
+
const parsed = tool.mcpDefinition.inputSchema.safeParse(args);
|
|
68
|
+
if (!parsed.success) return {
|
|
69
|
+
success: false,
|
|
70
|
+
error: parsed.error.message
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
data: parsed.data
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
validateToolOutput = (name, result) => {
|
|
78
|
+
const tool = this.toolsAvailables.get(name);
|
|
79
|
+
if (!tool || !tool.mcpDefinition.outputSchema || result.isError) return;
|
|
80
|
+
if (result.data === void 0) return;
|
|
81
|
+
const parsed = tool.mcpDefinition.outputSchema.safeParse(result.data);
|
|
82
|
+
if (!parsed.success) return parsed.error.message;
|
|
83
|
+
};
|
|
84
|
+
runPipeline = async (name, args, handler) => {
|
|
85
|
+
const parsedArgs = this.validateToolInput(name, args);
|
|
86
|
+
if (!parsedArgs.success) {
|
|
87
|
+
this.callbacks.onLog?.("error", `tool validation error: ${name} error=${parsedArgs.error}`);
|
|
88
|
+
const err = toolResponseErr(parsedArgs.error);
|
|
89
|
+
await this.after(name, args, err);
|
|
90
|
+
return err;
|
|
91
|
+
}
|
|
92
|
+
const t0 = Date.now();
|
|
93
|
+
const result = await handler(parsedArgs.data, this.ctx);
|
|
94
|
+
this.callbacks.onLog?.("debug", `tool done: ${name} ms=${Date.now() - t0} result=${JSON.stringify(result).slice(0, 200)}`);
|
|
95
|
+
const outputError = this.validateToolOutput(name, result);
|
|
96
|
+
if (outputError) this.callbacks.onLog?.("info", `tool output schema drift: ${name} — ${outputError}`);
|
|
97
|
+
const tool = this.toolsAvailables.get(name);
|
|
98
|
+
if (!result.isError && tool?.mcpDefinition.outputSchema && result.data !== void 0 && result.data !== null) result.structuredContent = typeof result.data === "object" && !Array.isArray(result.data) ? result.data : { data: result.data };
|
|
99
|
+
if (result.isError) this.callbacks.onLog?.("error", `tool failed: ${name} error=${firstText(result.content) ?? "unknown"}`);
|
|
100
|
+
await this.after(name, args, result);
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
execute = (name, handlerFn) => async (args) => {
|
|
104
|
+
if (!await this.before(name, args)) return toolResponseErr(`Tool '${name}' execution was blocked`);
|
|
105
|
+
const handler = handlerFn ?? this.toolsAvailables.get(name)?.handler;
|
|
106
|
+
if (!handler) {
|
|
107
|
+
this.callbacks.onLog?.("error", `no handler registered for tool: ${name}`);
|
|
108
|
+
const err = toolResponseErr(`Tool '${name}' has no handler`);
|
|
109
|
+
await this.after(name, args, err);
|
|
110
|
+
return err;
|
|
111
|
+
}
|
|
112
|
+
this.callbacks.onLog?.("debug", `tool exec: ${name} args=${JSON.stringify(args).slice(0, 200)}`);
|
|
113
|
+
return this.runPipeline(name, args, handler);
|
|
114
|
+
};
|
|
115
|
+
executePrompt = (_name, handlerFn) => async (args) => {
|
|
116
|
+
return handlerFn(args, this.ctx);
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
export { AIEngine as default };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as AIEngine } from './AIEngine';
|
|
2
|
+
export * from './AIEngine';
|
|
3
|
+
export { zodToJsonSchema, getAllowedModes, toolResponseOk, toolResponseErr, bindTools, isToolActive, resolveToolHandler, isCallToolResult, toolResponseFromResult } from './toolkit';
|
|
4
|
+
export { AIEngine };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { AiMode, McpContent, McpTool, McpToolHandler, McpToolHandlerResult, ToolOperationType } from '@plitzi/sdk-shared';
|
|
3
|
+
/** Convert a Zod schema to the JSON Schema an AI provider (Anthropic / OpenAI) expects in a tool definition.
|
|
4
|
+
* Delegates to Zod v4's built-in converter — one implementation, so descriptions, literal discriminators,
|
|
5
|
+
* enums, nested objects and recursive (z.lazy) shapes all survive and the provider sees the same contract an
|
|
6
|
+
* MCP client does. `io: 'input'` describes what the agent must SEND; `unrepresentable: 'any'` degrades an
|
|
7
|
+
* exotic type to an empty schema instead of throwing, so one unusual tool never breaks the whole tool list. */
|
|
8
|
+
export declare const zodToJsonSchema: (schema: unknown) => Record<string, unknown>;
|
|
9
|
+
export declare const firstText: (content: McpContent[]) => string | undefined;
|
|
10
|
+
export declare const getAllowedModes: (operationType: ToolOperationType) => AiMode[];
|
|
11
|
+
export declare const toolResponseOk: (data: unknown, agentMessage?: string) => McpToolHandlerResult;
|
|
12
|
+
export declare const toolResponseErr: (error: Error | string) => McpToolHandlerResult;
|
|
13
|
+
export declare const isCallToolResult: (result: unknown) => result is CallToolResult;
|
|
14
|
+
export declare const toolResponseFromResult: (result: CallToolResult) => McpToolHandlerResult;
|
|
15
|
+
export declare const isToolActive: (tool: McpTool) => boolean;
|
|
16
|
+
export declare const resolveToolHandler: (tool: McpTool) => McpToolHandler | undefined;
|
|
17
|
+
export declare const bindTools: (tools: McpTool[]) => McpTool[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/modules/ai/toolkit.ts
|
|
3
|
+
/** Convert a Zod schema to the JSON Schema an AI provider (Anthropic / OpenAI) expects in a tool definition.
|
|
4
|
+
* Delegates to Zod v4's built-in converter — one implementation, so descriptions, literal discriminators,
|
|
5
|
+
* enums, nested objects and recursive (z.lazy) shapes all survive and the provider sees the same contract an
|
|
6
|
+
* MCP client does. `io: 'input'` describes what the agent must SEND; `unrepresentable: 'any'` degrades an
|
|
7
|
+
* exotic type to an empty schema instead of throwing, so one unusual tool never breaks the whole tool list. */
|
|
8
|
+
var zodToJsonSchema = (schema) => {
|
|
9
|
+
const json = z.toJSONSchema(schema, {
|
|
10
|
+
target: "draft-7",
|
|
11
|
+
io: "input",
|
|
12
|
+
unrepresentable: "any"
|
|
13
|
+
});
|
|
14
|
+
delete json.$schema;
|
|
15
|
+
return json;
|
|
16
|
+
};
|
|
17
|
+
var firstText = (content) => content.find((block) => block.type === "text")?.text;
|
|
18
|
+
var getAllowedModes = (operationType) => {
|
|
19
|
+
return operationType === "write" ? ["build"] : ["plan", "build"];
|
|
20
|
+
};
|
|
21
|
+
var toolResponseOk = (data, agentMessage) => {
|
|
22
|
+
return {
|
|
23
|
+
content: [{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: agentMessage ?? JSON.stringify(data ?? null, null, 2)
|
|
26
|
+
}],
|
|
27
|
+
data
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var toolResponseErr = (error) => ({
|
|
31
|
+
content: [{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: error instanceof Error ? error.message : error
|
|
34
|
+
}],
|
|
35
|
+
isError: true
|
|
36
|
+
});
|
|
37
|
+
var isCallToolResult = (result) => typeof result === "object" && result !== null && Array.isArray(result.content);
|
|
38
|
+
var toolResponseFromResult = (result) => {
|
|
39
|
+
const content = [];
|
|
40
|
+
for (const block of result.content) if (block.type === "text") content.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: block.text
|
|
43
|
+
});
|
|
44
|
+
else if (block.type === "image") content.push({
|
|
45
|
+
type: "image",
|
|
46
|
+
data: block.data,
|
|
47
|
+
mimeType: block.mimeType
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
content,
|
|
51
|
+
data: result.structuredContent,
|
|
52
|
+
isError: result.isError ? true : void 0
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
var isToolActive = (tool) => Boolean(tool.handler);
|
|
56
|
+
var resolveToolHandler = (tool) => tool.handler;
|
|
57
|
+
var bindTools = (tools) => tools.filter(isToolActive);
|
|
58
|
+
//#endregion
|
|
59
|
+
export { bindTools, firstText, getAllowedModes, isCallToolResult, isToolActive, resolveToolHandler, toolResponseErr, toolResponseFromResult, toolResponseOk, zodToJsonSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { McpApp } from '../../types';
|
|
2
|
+
/** The reference app: the smallest definition that works, kept as the template a new app is copied from.
|
|
3
|
+
*
|
|
4
|
+
* It is deliberately NOT in the `apps` list — nothing renders it, since no tool points at it — so it costs a
|
|
5
|
+
* real deployment nothing while the test suite still builds it, which is what keeps it from rotting. To turn it
|
|
6
|
+
* into a real app: add it to `apps` in ../index.ts and give a tool `ui: { resourceUri: EXAMPLE_APP_URI }`. */
|
|
7
|
+
export declare const EXAMPLE_APP_URI = "ui://plitzi/example.html";
|
|
8
|
+
export declare const exampleApp: McpApp;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-disable react-refresh/only-export-components -- one bundled entry: components cannot move out. */
|
|
2
|
+
import { useApp, useHostStyles } from '@modelcontextprotocol/ext-apps/react';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
|
|
6
|
+
import type { McpUiHostContext } from '@modelcontextprotocol/ext-apps';
|
|
7
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
|
|
9
|
+
/** The smallest MCP App view there is — copy this folder to start a new one. It shows the whole contract:
|
|
10
|
+
* connect, receive the tool call and its result, call a tool back, and inherit the host's look. Everything it
|
|
11
|
+
* imports is bundled into the page, so a view that stays this small stays a few KB. */
|
|
12
|
+
|
|
13
|
+
// Host CSS variables: the chat's own palette and fonts, applied by useHostStyles below.
|
|
14
|
+
const panel = {
|
|
15
|
+
padding: 16,
|
|
16
|
+
font: 'var(--font-sans, system-ui, sans-serif)',
|
|
17
|
+
color: 'var(--color-text-primary, #0f172a)',
|
|
18
|
+
background: 'var(--color-background-secondary, #f8fafc)',
|
|
19
|
+
borderRadius: 'var(--border-radius-md, 8px)'
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
const textOf = (result: CallToolResult): string => result.content.find(entry => entry.type === 'text')?.text ?? '';
|
|
23
|
+
|
|
24
|
+
const ExampleApp = () => {
|
|
25
|
+
const [result, setResult] = useState<CallToolResult | null>(null);
|
|
26
|
+
const [context, setContext] = useState<McpUiHostContext | undefined>(undefined);
|
|
27
|
+
|
|
28
|
+
// useApp creates the App, runs onAppCreated so every handler is in place BEFORE the handshake, and connects.
|
|
29
|
+
const { app, error } = useApp({
|
|
30
|
+
appInfo: { name: 'Plitzi Example', version: '1.0.0' },
|
|
31
|
+
capabilities: {},
|
|
32
|
+
onAppCreated: instance => {
|
|
33
|
+
// The result of the tool that opened this view. `ontoolinput` gives its arguments instead.
|
|
34
|
+
instance.ontoolresult = setResult;
|
|
35
|
+
instance.onhostcontextchanged = params => setContext(previous => ({ ...previous, ...params }));
|
|
36
|
+
instance.onteardown = () => ({});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
useHostStyles(app, context);
|
|
41
|
+
|
|
42
|
+
if (error) {
|
|
43
|
+
return <div style={panel}>Could not connect to the host: {error.message}</div>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!app) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const insets = context?.safeAreaInsets;
|
|
51
|
+
const message = result ? textOf(result) : 'Waiting for the tool result…';
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div style={{ ...panel, margin: `${insets?.top ?? 0}px ${insets?.right ?? 0}px` }}>
|
|
55
|
+
<p>{message}</p>
|
|
56
|
+
{/* An app can call the server's tools on its own — each call is a round-trip, so plan for latency. */}
|
|
57
|
+
<button
|
|
58
|
+
type="button"
|
|
59
|
+
onClick={() => void app.callServerTool({ name: 'plitzi_search', arguments: {} }).then(setResult)}
|
|
60
|
+
>
|
|
61
|
+
Call plitzi_search
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const root = document.getElementById('app');
|
|
68
|
+
if (root) {
|
|
69
|
+
createRoot(root).render(<ExampleApp />);
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { McpApp, McpViewSettings } from '../types';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
/** What a view gets when the deployment says nothing: streaming on, because a host that streams no arguments
|
|
4
|
+
* paints exactly what it painted before. */
|
|
5
|
+
export declare const DEFAULT_VIEW_SETTINGS: McpViewSettings;
|
|
6
|
+
/** Every MCP App this server serves. A new one is a folder beside `render/` (its definition + its view) and one
|
|
7
|
+
* line here — the tool that opens it points at its `uri` through `ui: { resourceUri }`. Start from `example/`,
|
|
8
|
+
* which is that same shape stripped to the minimum. */
|
|
9
|
+
export declare const apps: McpApp[];
|
|
10
|
+
export declare const registerApps: (server: McpServer, settings?: McpViewSettings) => void;
|
|
11
|
+
export { iconFontCss, RENDER_APP_URI } from './render';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { registerApp } from "./shared/registerApp.js";
|
|
2
|
+
import { iconFontCss } from "./render/styles.js";
|
|
3
|
+
import { RENDER_APP_URI, renderApp } from "./render/index.js";
|
|
4
|
+
//#region src/modules/mcp/apps/index.ts
|
|
5
|
+
/** What a view gets when the deployment says nothing: streaming on, because a host that streams no arguments
|
|
6
|
+
* paints exactly what it painted before. */
|
|
7
|
+
var DEFAULT_VIEW_SETTINGS = { streaming: true };
|
|
8
|
+
/** Every MCP App this server serves. A new one is a folder beside `render/` (its definition + its view) and one
|
|
9
|
+
* line here — the tool that opens it points at its `uri` through `ui: { resourceUri }`. Start from `example/`,
|
|
10
|
+
* which is that same shape stripped to the minimum. */
|
|
11
|
+
var apps = [renderApp];
|
|
12
|
+
var registerApps = (server, settings = DEFAULT_VIEW_SETTINGS) => {
|
|
13
|
+
for (const app of apps) registerApp(server, app, settings);
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { DEFAULT_VIEW_SETTINGS, RENDER_APP_URI, apps, iconFontCss, registerApps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VIEW_DIR } from "../shared/assets.js";
|
|
2
|
+
import { iconFontCss, widgetCss } from "./styles.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region src/modules/mcp/apps/render/index.ts
|
|
6
|
+
var RENDER_APP_URI = "ui://plitzi/render.html";
|
|
7
|
+
var HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
var renderApp = {
|
|
9
|
+
uri: RENDER_APP_URI,
|
|
10
|
+
name: "plitzi-render-app",
|
|
11
|
+
title: "Plitzi widget",
|
|
12
|
+
description: "Interactive view that renders a plitzi_render widget with the Plitzi SDK.",
|
|
13
|
+
entry: path.join(HERE, VIEW_DIR, "index.tsx"),
|
|
14
|
+
styles: () => [widgetCss()]
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { RENDER_APP_URI, iconFontCss, renderApp };
|