skybridge 0.0.0-dev.f03017e → 0.0.0-dev.f0394fc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -124
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +113 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +143 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +84 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +72 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +8 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/resolve-skybridge-config.d.ts +6 -0
- package/dist/cli/resolve-skybridge-config.js +28 -0
- package/dist/cli/resolve-skybridge-config.js.map +1 -0
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/run-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +90 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/telemetry.js +2 -0
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/tunnel-control-server.d.ts +9 -0
- package/dist/cli/tunnel-control-server.js +31 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.js +105 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel.d.ts +57 -0
- package/dist/cli/tunnel.js +154 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.js.map +1 -1
- package/dist/cli/use-nodemon.d.ts +25 -1
- package/dist/cli/use-nodemon.js +97 -55
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +1 -1
- package/dist/cli/use-tunnel.js +102 -68
- package/dist/cli/use-tunnel.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +9 -2
- package/dist/cli/use-typescript-check.js +91 -51
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +2 -38
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +2 -0
- package/dist/commands/dev.js +84 -5
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/context-warnings.d.ts +5 -0
- package/dist/context-warnings.js +31 -0
- package/dist/context-warnings.js.map +1 -0
- package/dist/context-warnings.test.js +28 -0
- package/dist/context-warnings.test.js.map +1 -0
- package/dist/server/app.d.ts +211 -0
- package/dist/server/app.js +277 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/app.test.d.ts +1 -0
- package/dist/server/app.test.js +178 -0
- package/dist/server/app.test.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +17 -2
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +80 -1
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +33 -0
- package/dist/server/auth/discovery.js +56 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +48 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +40 -0
- package/dist/server/auth/providers/auth0.js +36 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +50 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +143 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +51 -0
- package/dist/server/auth/providers/clerk.js +19 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +30 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +42 -0
- package/dist/server/auth/providers/custom.js +59 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +161 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +44 -0
- package/dist/server/auth/providers/descope.js +44 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +62 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +25 -0
- package/dist/server/auth/providers/stytch.js +16 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +34 -0
- package/dist/server/auth/providers/workos.js +16 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +6 -0
- package/dist/server/auth/setup.js +91 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +514 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +48 -0
- package/dist/server/auth/verify.js +62 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +165 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth-extra.test-d.d.ts +1 -0
- package/dist/server/auth-extra.test-d.js +130 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +57 -0
- package/dist/server/auth.js +27 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +28 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +41 -1
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/content-helpers.test.js.map +1 -1
- package/dist/server/events.d.ts +113 -0
- package/dist/server/events.js +318 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/events.test.d.ts +1 -0
- package/dist/server/events.test.js +172 -0
- package/dist/server/events.test.js.map +1 -0
- package/dist/server/express.d.ts +24 -7
- package/dist/server/express.js +66 -30
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +445 -81
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/form-input.d.ts +120 -0
- package/dist/server/form-input.js +89 -0
- package/dist/server/form-input.js.map +1 -0
- package/dist/server/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.d.ts +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +20 -2
- package/dist/server/index.js +17 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/mcp-errors.test.d.ts +1 -0
- package/dist/server/mcp-errors.test.js +229 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/metric.d.ts +5 -3
- package/dist/server/metric.js +5 -5
- package/dist/server/metric.js.map +1 -1
- package/dist/server/middleware.d.ts +51 -13
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +242 -134
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +230 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +548 -56
- package/dist/server/server.js +685 -286
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +86 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +27 -0
- package/dist/server/skills.js +188 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +243 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/templateHelper.d.ts +0 -5
- package/dist/server/templateHelper.js +3 -22
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.d.ts +4 -0
- package/dist/server/templates.generated.js +43 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +167 -0
- package/dist/server/tool-extra.test.js.map +1 -0
- package/dist/server/tunnel-proxy-router.d.ts +7 -0
- package/dist/server/tunnel-proxy-router.js +110 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -0
- package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +176 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +9 -11
- package/dist/test/utils.js +220 -201
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +199 -113
- package/dist/test/view.test.js.map +1 -1
- package/dist/version.js +1 -3
- package/dist/version.js.map +1 -1
- package/dist/views/index.d.ts +10 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/{web/plugin → views}/scan-views.d.ts +8 -0
- package/dist/{web/plugin → views}/scan-views.js +26 -8
- package/dist/views/scan-views.js.map +1 -0
- package/dist/views/scan-views.test.d.ts +1 -0
- package/dist/{web/plugin → views}/scan-views.test.js +33 -1
- package/dist/views/scan-views.test.js.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/{web/plugin → views}/validate-view.js +2 -2
- package/dist/views/validate-view.js.map +1 -0
- package/dist/views/validate-view.test.d.ts +1 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +62 -0
- package/dist/web/bridges/adaptor.js +477 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +281 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -1
- package/dist/web/bridges/apps-sdk/bridge.js +15 -3
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +10 -4
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +9 -7
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +15 -2
- package/dist/web/bridges/mcp-app/bridge.js +80 -7
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.d.ts +19 -2
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +13 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +174 -11
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +35 -9
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +24 -23
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +35 -2
- package/dist/web/data-llm.js +34 -5
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +48 -29
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +25 -19
- package/dist/web/generate-helpers.js +23 -17
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +14 -12
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +11 -11
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +11 -2
- package/dist/web/hooks/index.js +11 -2
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
- package/dist/web/hooks/openai-extensions.test.js +107 -0
- package/dist/web/hooks/openai-extensions.test.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +7 -2
- package/dist/web/hooks/test/utils.js +14 -3
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +47 -2
- package/dist/web/hooks/use-call-tool.js +43 -10
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +75 -29
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-deep-link.d.ts +22 -0
- package/dist/web/hooks/use-deep-link.js +34 -0
- package/dist/web/hooks/use-deep-link.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +20 -0
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +57 -21
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +3 -0
- package/dist/web/hooks/use-download.js +7 -0
- package/dist/web/hooks/use-download.js.map +1 -0
- package/dist/web/hooks/use-download.test.d.ts +1 -0
- package/dist/web/hooks/use-download.test.js +103 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-file-resource.d.ts +37 -0
- package/dist/web/hooks/use-file-resource.js +98 -0
- package/dist/web/hooks/use-file-resource.js.map +1 -0
- package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
- package/dist/web/hooks/use-file-resource.test.js +65 -0
- package/dist/web/hooks/use-file-resource.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +11 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +44 -0
- package/dist/web/hooks/use-host.js +45 -0
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/use-host.test.js +59 -0
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-model-context.d.ts +44 -0
- package/dist/web/hooks/use-model-context.js +63 -0
- package/dist/web/hooks/use-model-context.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +15 -5
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-open-file.d.ts +20 -0
- package/dist/web/hooks/use-open-file.js +25 -0
- package/dist/web/hooks/use-open-file.js.map +1 -0
- package/dist/web/hooks/use-register-view-tool.d.ts +37 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +47 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +19 -4
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +12 -2
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +20 -0
- package/dist/web/hooks/use-request-size.js +24 -0
- package/dist/web/hooks/use-request-size.js.map +1 -0
- package/dist/web/hooks/use-request-size.test.d.ts +1 -0
- package/dist/web/hooks/use-request-size.test.js +47 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +25 -1
- package/dist/web/hooks/use-send-follow-up-message.js +25 -2
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +26 -12
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +46 -14
- package/dist/web/hooks/use-tool-info.js +29 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -34
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +42 -37
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +5 -2
- package/dist/web/hooks/use-user.js +6 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +85 -37
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +25 -0
- package/dist/web/hooks/use-view-state.js +42 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/{use-widget-state.test.js → use-view-state.test.js} +56 -21
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/use-viewport.test.d.ts +1 -0
- package/dist/web/hooks/use-viewport.test.js +109 -0
- package/dist/web/hooks/use-viewport.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -3
- package/dist/web/index.js +1 -2
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +21 -0
- package/dist/web/mount-view.js +43 -0
- package/dist/web/mount-view.js.map +1 -0
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +46 -28
- package/dist/server/templates/development.hbs +0 -12
- package/dist/server/templates/production.hbs +0 -6
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -24
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -87
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -48
- package/dist/web/bridges/mcp-app/adaptor.js +0 -268
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -22
- package/dist/web/hooks/use-layout.js +0 -23
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.js +0 -96
- package/dist/web/hooks/use-layout.test.js.map +0 -1
- package/dist/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/web/hooks/use-widget-state.js +0 -32
- package/dist/web/hooks/use-widget-state.js.map +0 -1
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js +0 -27
- package/dist/web/mount-widget.js.map +0 -1
- package/dist/web/plugin/data-llm.test.js +0 -81
- package/dist/web/plugin/data-llm.test.js.map +0 -1
- package/dist/web/plugin/plugin.d.ts +0 -5
- package/dist/web/plugin/plugin.js +0 -141
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/scan-views.js.map +0 -1
- package/dist/web/plugin/scan-views.test.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.d.ts +0 -12
- package/dist/web/plugin/transform-data-llm.js +0 -96
- package/dist/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.test.js +0 -81
- package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/web/plugin/validate-view.d.ts +0 -1
- package/dist/web/plugin/validate-view.js.map +0 -1
- package/dist/web/plugin/validate-view.test.js.map +0 -1
- /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
package/dist/server/server.js
CHANGED
|
@@ -1,21 +1,67 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import http from "node:http";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
4
|
+
import { isInputRequiredResult, McpServer as McpServerBase, } from "@modelcontextprotocol/server";
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
|
+
import { warnOnLargeToolOutput } from "../context-warnings.js";
|
|
7
|
+
import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
8
|
+
import { EventRegistry, } from "./events.js";
|
|
9
|
+
import { hostFromUserAgent } from "./host.js";
|
|
10
|
+
import { captureToolError } from "./middleware.js";
|
|
11
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
12
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
11
13
|
import { templateHelper } from "./templateHelper.js";
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
14
|
+
const unionOf = (base, extra) => extra ? [...new Set([...base, ...extra])] : base;
|
|
15
|
+
function mergeOpenAIUi(meta, values) {
|
|
16
|
+
const defined = Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
|
|
17
|
+
if (Object.keys(defined).length > 0) {
|
|
18
|
+
meta["openai/ui"] = { ...meta["openai/ui"], ...defined };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function acceptsEmptyInput(inputSchema) {
|
|
22
|
+
if (inputSchema === undefined) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const checks = "~standard" in inputSchema
|
|
26
|
+
? [inputSchema["~standard"].validate({})]
|
|
27
|
+
: Object.values(inputSchema).map((schema) => schema["~standard"].validate(undefined));
|
|
28
|
+
return checks.every((result) => result instanceof Promise || result.issues === undefined);
|
|
29
|
+
}
|
|
30
|
+
const SKILLS_DIR = "src/skills";
|
|
31
|
+
/**
|
|
32
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
33
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
34
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
35
|
+
*/
|
|
36
|
+
function normalizeForwardedPrefix(raw) {
|
|
37
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
38
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
39
|
+
if (trimmed === "") {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
43
|
+
}
|
|
44
|
+
const fileEntrypointInput = {
|
|
45
|
+
file: z.object({
|
|
46
|
+
name: z.string().min(1),
|
|
47
|
+
resourceUri: z.string().trim().min(1),
|
|
48
|
+
}),
|
|
18
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
52
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
53
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
54
|
+
*/
|
|
55
|
+
function stripQuery(uri) {
|
|
56
|
+
const queryIndex = uri.indexOf("?");
|
|
57
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
61
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
62
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
63
|
+
* who build content lazily can apply the same normalization.
|
|
64
|
+
*/
|
|
19
65
|
export function normalizeContent(content) {
|
|
20
66
|
if (content === undefined) {
|
|
21
67
|
return [];
|
|
@@ -29,60 +75,147 @@ export function normalizeContent(content) {
|
|
|
29
75
|
return [content];
|
|
30
76
|
}
|
|
31
77
|
const McpServerBaseOmitted = McpServerBase;
|
|
78
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
79
|
+
// Set at module scope rather than passed through the constructor because the
|
|
80
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
81
|
+
// threading it through every call site (including user templates) is exactly
|
|
82
|
+
// the boilerplate this design is trying to hide.
|
|
83
|
+
let pendingBuildManifest = null;
|
|
84
|
+
/**
|
|
85
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
86
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
87
|
+
* user-facing API.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export function __setBuildManifest(manifest) {
|
|
92
|
+
pendingBuildManifest = manifest;
|
|
93
|
+
}
|
|
94
|
+
let pendingSkillsManifest = null;
|
|
95
|
+
let cachedDiskManifest = null;
|
|
96
|
+
let discoveredSkills = null;
|
|
97
|
+
let warnedOnMissingSkills = false;
|
|
98
|
+
export function __setSkillsManifest(manifest) {
|
|
99
|
+
pendingSkillsManifest = manifest;
|
|
100
|
+
discoveredSkills = null;
|
|
101
|
+
}
|
|
102
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
103
|
+
// exists — the capability must be present for the `initialize` response.
|
|
104
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
105
|
+
if (!skybridgeOptions?.skills) {
|
|
106
|
+
return options;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...options,
|
|
110
|
+
capabilities: {
|
|
111
|
+
...options?.capabilities,
|
|
112
|
+
extensions: {
|
|
113
|
+
...options?.capabilities?.extensions,
|
|
114
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Typed registration sugar over the MCP SDK's `McpServer`: a tool registry
|
|
121
|
+
* that carries input/output/meta shapes, view resources, per-tool security
|
|
122
|
+
* schemes, and prompt/resource registration. A {@link Skybridge} app builds
|
|
123
|
+
* one of these per request and hands it to your `handler`; chain
|
|
124
|
+
* {@link McpServer.registerTool} calls on it and return the result.
|
|
125
|
+
*
|
|
126
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
127
|
+
* shape, so `typeof app` carries enough information for view-side helpers
|
|
128
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
129
|
+
*
|
|
130
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
131
|
+
* chaining; you almost never set this manually.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* export const app = new Skybridge({
|
|
136
|
+
* name: "my-app",
|
|
137
|
+
* version: "1.0.0",
|
|
138
|
+
* handler: (server) =>
|
|
139
|
+
* server.registerTool({
|
|
140
|
+
* name: "search",
|
|
141
|
+
* inputSchema: { query: z.string() },
|
|
142
|
+
* view: { component: "search" },
|
|
143
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` })),
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
148
|
+
*/
|
|
32
149
|
export class McpServer extends McpServerBaseOmitted {
|
|
33
|
-
express;
|
|
34
|
-
customMiddleware = [];
|
|
35
|
-
customErrorMiddleware = [];
|
|
36
|
-
mcpMiddlewareEntries = [];
|
|
37
|
-
mcpMiddlewareApplied = false;
|
|
38
150
|
claimedViews = new Map();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
151
|
+
viewMetaBuilders = new Map();
|
|
152
|
+
/**
|
|
153
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
154
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
155
|
+
* underlying view no matter which version param the consumer sends, since
|
|
156
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
157
|
+
*/
|
|
158
|
+
viewUriByPath = new Map();
|
|
159
|
+
viteManifest = null;
|
|
160
|
+
oauthEnabled = false;
|
|
161
|
+
resolveResourceMetadataUrl;
|
|
162
|
+
toolSecuritySchemes = new Map();
|
|
163
|
+
userMiddlewareEntries = [];
|
|
164
|
+
eventRegistry;
|
|
165
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
166
|
+
super(serverInfo, withSkillsCapability(options, skybridgeOptions));
|
|
167
|
+
this.oauthEnabled = Boolean(skybridgeOptions?.oauth);
|
|
168
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
169
|
+
// user code. Explicit `setViteManifest` calls still win because they
|
|
170
|
+
// happen after construction.
|
|
171
|
+
if (pendingBuildManifest) {
|
|
172
|
+
this.setViteManifest(pendingBuildManifest);
|
|
57
173
|
}
|
|
174
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The per-tool security schemes collected during registration, keyed by tool
|
|
178
|
+
* name. Read by the OAuth layer to decide whether anonymous requests are
|
|
179
|
+
* allowed and which schemes gate a given `tools/call`.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
get securitySchemesByTool() {
|
|
184
|
+
return this.toolSecuritySchemes;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Inject the resolver the app uses to build the protected-resource metadata
|
|
188
|
+
* URL, so tool handlers can emit in-band auth challenges.
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
setResourceMetadataUrlResolver(resolve) {
|
|
193
|
+
this.resolveResourceMetadataUrl = resolve;
|
|
58
194
|
return this;
|
|
59
195
|
}
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
196
|
+
setupSkills(enabled) {
|
|
197
|
+
if (!enabled) {
|
|
198
|
+
return;
|
|
63
199
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
200
|
+
discoveredSkills ??= pendingSkillsManifest ?? discoverSkills(SKILLS_DIR);
|
|
201
|
+
if (discoveredSkills.length === 0 && !warnedOnMissingSkills) {
|
|
202
|
+
warnedOnMissingSkills = true;
|
|
203
|
+
console.warn(`skybridge: the "skills" option is enabled but no skills were found in "${SKILLS_DIR}". Add a <name>/SKILL.md there, or remove the option.`);
|
|
68
204
|
}
|
|
69
|
-
|
|
205
|
+
registerSkills(this, discoveredSkills);
|
|
70
206
|
}
|
|
71
207
|
mcpMiddleware(filterOrHandler,
|
|
72
208
|
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
73
209
|
maybeHandler) {
|
|
74
|
-
if (this.mcpMiddlewareApplied) {
|
|
75
|
-
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
76
|
-
}
|
|
77
210
|
const handler = maybeHandler;
|
|
78
211
|
if (typeof filterOrHandler === "function") {
|
|
79
|
-
this.
|
|
212
|
+
this.userMiddlewareEntries.push({
|
|
80
213
|
filter: null,
|
|
81
214
|
handler: filterOrHandler,
|
|
82
215
|
});
|
|
83
216
|
}
|
|
84
217
|
else if (handler) {
|
|
85
|
-
this.
|
|
218
|
+
this.userMiddlewareEntries.push({
|
|
86
219
|
filter: filterOrHandler,
|
|
87
220
|
handler,
|
|
88
221
|
});
|
|
@@ -92,74 +225,96 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
92
225
|
}
|
|
93
226
|
return this;
|
|
94
227
|
}
|
|
95
|
-
applyMcpMiddleware() {
|
|
96
|
-
if (this.mcpMiddlewareApplied) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
this.mcpMiddlewareApplied = true;
|
|
100
|
-
const monitoringEntry = createMiddlewareEntry();
|
|
101
|
-
const entries = monitoringEntry
|
|
102
|
-
? [monitoringEntry, ...this.mcpMiddlewareEntries]
|
|
103
|
-
: this.mcpMiddlewareEntries;
|
|
104
|
-
if (entries.length === 0) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
108
|
-
const instrumentMap = (map, isNotification) => {
|
|
109
|
-
for (const [method, handler] of map) {
|
|
110
|
-
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
111
|
-
}
|
|
112
|
-
const originalSet = map.set.bind(map);
|
|
113
|
-
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
114
|
-
};
|
|
115
|
-
instrumentMap(requestHandlers, false);
|
|
116
|
-
instrumentMap(notificationHandlers, true);
|
|
117
|
-
}
|
|
118
|
-
async connect(transport) {
|
|
119
|
-
this.applyMcpMiddleware();
|
|
120
|
-
return McpServerBase.prototype.connect.call(this, transport);
|
|
121
|
-
}
|
|
122
228
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
130
|
-
* read side and fails fast on SDK field renames.
|
|
229
|
+
* This instance's protocol-level middleware: the framework's own entries
|
|
230
|
+
* (view `_meta` on `resources/list`, version-agnostic view resolution on
|
|
231
|
+
* `resources/read`, the top-level `securitySchemes` mirror on `tools/list`)
|
|
232
|
+
* followed by the ones registered via {@link McpServer.mcpMiddleware}.
|
|
233
|
+
*
|
|
234
|
+
* @internal
|
|
131
235
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
236
|
+
protocolMiddlewareEntries() {
|
|
237
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
238
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
239
|
+
const viewListMetaEntry = {
|
|
240
|
+
filter: "resources/list",
|
|
241
|
+
handler: async (_req, extra, next) => {
|
|
242
|
+
const result = (await next());
|
|
243
|
+
for (const resource of result.resources) {
|
|
244
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
245
|
+
if (!builder) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const meta = builder(extra);
|
|
249
|
+
resource._meta = {
|
|
250
|
+
...(resource._meta ?? {}),
|
|
251
|
+
...meta,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
258
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
259
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
260
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
261
|
+
// canonical registered one, then restore the requested URI on the response
|
|
262
|
+
// so the consumer-facing URI is never rewritten.
|
|
263
|
+
const viewReadResolveEntry = {
|
|
264
|
+
filter: "resources/read",
|
|
265
|
+
handler: async (req, _extra, next) => {
|
|
266
|
+
const requested = req.params.uri;
|
|
267
|
+
if (typeof requested !== "string") {
|
|
268
|
+
return next();
|
|
269
|
+
}
|
|
270
|
+
const path = stripQuery(requested);
|
|
271
|
+
const canonical = this.viewUriByPath.get(path);
|
|
272
|
+
if (!canonical) {
|
|
273
|
+
return next();
|
|
274
|
+
}
|
|
275
|
+
req.params.uri = canonical;
|
|
276
|
+
try {
|
|
277
|
+
const result = (await next());
|
|
278
|
+
for (const content of result.contents ?? []) {
|
|
279
|
+
if (typeof content.uri === "string" &&
|
|
280
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
281
|
+
content.uri = requested;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
// Restore the shared request params so middleware outer to us never
|
|
288
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
289
|
+
req.params.uri = requested;
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
// ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
|
|
294
|
+
// still Draft), but the SDK's registerTool strips unknown top-level fields, so
|
|
295
|
+
// it's stashed in `_meta` at registration. This restores it to the top level
|
|
296
|
+
// on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
|
|
297
|
+
// { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
|
|
298
|
+
// -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
|
|
299
|
+
const toolsListSecuritySchemesEntry = {
|
|
300
|
+
filter: "tools/list",
|
|
301
|
+
handler: async (_req, _extra, next) => {
|
|
302
|
+
const result = (await next());
|
|
303
|
+
for (const tool of result.tools) {
|
|
304
|
+
const schemes = tool._meta?.securitySchemes;
|
|
305
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
306
|
+
tool.securitySchemes = schemes;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
return [
|
|
313
|
+
viewListMetaEntry,
|
|
314
|
+
viewReadResolveEntry,
|
|
315
|
+
toolsListSecuritySchemesEntry,
|
|
316
|
+
...this.userMiddlewareEntries,
|
|
317
|
+
];
|
|
163
318
|
}
|
|
164
319
|
enforceOneToolPerView(component, toolName) {
|
|
165
320
|
const existingTool = this.claimedViews.get(component);
|
|
@@ -168,188 +323,154 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
168
323
|
}
|
|
169
324
|
this.claimedViews.set(component, toolName);
|
|
170
325
|
}
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
const fromView = {
|
|
188
|
-
"openai/widgetCSP": {
|
|
189
|
-
resource_domains: view.csp?.resourceDomains,
|
|
190
|
-
connect_domains: view.csp?.connectDomains,
|
|
191
|
-
frame_domains: view.csp?.frameDomains,
|
|
192
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
193
|
-
},
|
|
194
|
-
"openai/widgetDomain": view.domain,
|
|
195
|
-
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
196
|
-
};
|
|
197
|
-
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
198
|
-
"openai/widgetDomain": overrides.domain,
|
|
199
|
-
});
|
|
200
|
-
if (view._meta) {
|
|
201
|
-
return { ...base, ...view._meta };
|
|
202
|
-
}
|
|
203
|
-
return base;
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
this.registerViewResource({
|
|
207
|
-
name: toolName,
|
|
208
|
-
viewResource,
|
|
209
|
-
view,
|
|
210
|
-
});
|
|
211
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
326
|
+
resolveViewRequestContext(ctx) {
|
|
327
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
328
|
+
const header = (key) => ctx?.http?.req?.headers.get(key) ?? undefined;
|
|
329
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
330
|
+
const serverUrl = resolveServerOrigin(header);
|
|
331
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
332
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
333
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
334
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
335
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
336
|
+
const connectDomains = [serverUrl];
|
|
337
|
+
if (!isProduction) {
|
|
338
|
+
const wsUrl = new URL(serverUrl);
|
|
339
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
340
|
+
connectDomains.push(wsUrl.origin);
|
|
212
341
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
342
|
+
let contentMetaOverrides = {};
|
|
343
|
+
if (isClaude) {
|
|
344
|
+
const pathname = ctx?.http?.req ? new URL(ctx.http.req.url).pathname : "";
|
|
345
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
346
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
347
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
348
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
349
|
+
const hash = crypto
|
|
350
|
+
.createHash("sha256")
|
|
351
|
+
.update(url)
|
|
352
|
+
.digest("hex")
|
|
353
|
+
.slice(0, 32);
|
|
354
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
355
|
+
}
|
|
356
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
357
|
+
}
|
|
358
|
+
registerViewResources(toolName, view, toolMeta, openai) {
|
|
359
|
+
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
360
|
+
// their cache when the bundle changes, but keep the URI stable across
|
|
361
|
+
// `tools/list` calls when the bundle hasn't changed.
|
|
362
|
+
const versionParam = this.computeViewVersionParam(view.component);
|
|
363
|
+
const viewResource = {
|
|
364
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
365
|
+
mimeType: "text/html;profile=mcp-app",
|
|
366
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
367
|
+
const ui = {
|
|
368
|
+
ui: {
|
|
369
|
+
...(view.description && { description: view.description }),
|
|
370
|
+
...(view.prefersBorder !== undefined && {
|
|
371
|
+
prefersBorder: view.prefersBorder,
|
|
372
|
+
}),
|
|
373
|
+
domain: overrides.domain ?? view.domain ?? domain,
|
|
374
|
+
csp: {
|
|
375
|
+
resourceDomains: unionOf(resourceDomains, view.csp?.resourceDomains),
|
|
376
|
+
connectDomains: unionOf(connectDomains, view.csp?.connectDomains),
|
|
377
|
+
baseUriDomains: unionOf(baseUriDomains, view.csp?.baseUriDomains),
|
|
378
|
+
...(view.csp?.frameDomains && {
|
|
379
|
+
frameDomains: view.csp.frameDomains,
|
|
234
380
|
}),
|
|
235
|
-
...(view.domain && { domain: view.domain }),
|
|
236
|
-
csp: {
|
|
237
|
-
...(view.csp?.resourceDomains && {
|
|
238
|
-
resourceDomains: view.csp.resourceDomains,
|
|
239
|
-
}),
|
|
240
|
-
...(view.csp?.connectDomains && {
|
|
241
|
-
connectDomains: view.csp.connectDomains,
|
|
242
|
-
}),
|
|
243
|
-
...(view.csp?.frameDomains && {
|
|
244
|
-
frameDomains: view.csp.frameDomains,
|
|
245
|
-
}),
|
|
246
|
-
...(view.csp?.baseUriDomains && {
|
|
247
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
248
|
-
}),
|
|
249
|
-
...(view.csp?.redirectDomains && {
|
|
250
|
-
redirectDomains: view.csp.redirectDomains,
|
|
251
|
-
}),
|
|
252
|
-
},
|
|
253
381
|
},
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
const base = {
|
|
385
|
+
...ui,
|
|
386
|
+
...(view.description && {
|
|
387
|
+
"openai/widgetDescription": view.description,
|
|
388
|
+
}),
|
|
389
|
+
...(view.csp?.redirectDomains && {
|
|
390
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
391
|
+
}),
|
|
392
|
+
};
|
|
393
|
+
const meta = { ...base, ...view._meta };
|
|
394
|
+
mergeOpenAIUi(meta, {
|
|
395
|
+
availableDisplayModes: openai?.availableDisplayModes,
|
|
396
|
+
preferredDisplayMode: openai?.preferredDisplayMode,
|
|
397
|
+
});
|
|
398
|
+
return meta;
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
402
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
403
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
404
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
405
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
406
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
407
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
408
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
273
409
|
}
|
|
274
410
|
registerViewResource({ name, viewResource, view, }) {
|
|
275
|
-
const {
|
|
411
|
+
const { uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
412
|
+
const buildMeta = (extra) => {
|
|
413
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
414
|
+
return buildContentMeta({
|
|
415
|
+
resourceDomains: [serverUrl],
|
|
416
|
+
connectDomains,
|
|
417
|
+
domain: serverUrl,
|
|
418
|
+
baseUriDomains: [serverUrl],
|
|
419
|
+
}, contentMetaOverrides);
|
|
420
|
+
};
|
|
421
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
422
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
423
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
276
424
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
277
425
|
const isProduction = process.env.NODE_ENV === "production";
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
};
|
|
284
|
-
let serverUrl;
|
|
285
|
-
const forwardedHost = header("x-forwarded-host");
|
|
286
|
-
const origin = header("origin");
|
|
287
|
-
const host = header("host");
|
|
288
|
-
if (forwardedHost) {
|
|
289
|
-
const proto = header("x-forwarded-proto") || "https";
|
|
290
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
291
|
-
}
|
|
292
|
-
else if (origin) {
|
|
293
|
-
serverUrl = origin;
|
|
294
|
-
}
|
|
295
|
-
else if (host) {
|
|
296
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
297
|
-
? "http"
|
|
298
|
-
: "https";
|
|
299
|
-
serverUrl = `${proto}://${host}`;
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
const devPort = process.env.__PORT || "3000";
|
|
303
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
304
|
-
}
|
|
426
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
427
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
428
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
429
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
430
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
305
431
|
const html = isProduction
|
|
306
432
|
? templateHelper.renderProduction({
|
|
307
|
-
|
|
308
|
-
serverUrl,
|
|
433
|
+
serverUrl: viewBase,
|
|
309
434
|
viewFile: this.lookupViewFile(view.component),
|
|
310
435
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
311
436
|
})
|
|
312
437
|
: templateHelper.renderDevelopment({
|
|
313
|
-
|
|
314
|
-
serverUrl,
|
|
438
|
+
serverUrl: viewBase,
|
|
315
439
|
viewName: view.component,
|
|
316
440
|
});
|
|
317
|
-
const connectDomains = [serverUrl];
|
|
318
|
-
if (!isProduction) {
|
|
319
|
-
const wsUrl = new URL(serverUrl);
|
|
320
|
-
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
321
|
-
connectDomains.push(wsUrl.origin);
|
|
322
|
-
}
|
|
323
|
-
let contentMetaOverrides = {};
|
|
324
|
-
if (isClaude) {
|
|
325
|
-
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
326
|
-
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
327
|
-
// Strip a lone trailing slash so the hash matches the connector URL
|
|
328
|
-
// as registered with Claude (which has no trailing slash on bare origins).
|
|
329
|
-
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
330
|
-
const hash = crypto
|
|
331
|
-
.createHash("sha256")
|
|
332
|
-
.update(url)
|
|
333
|
-
.digest("hex")
|
|
334
|
-
.slice(0, 32);
|
|
335
|
-
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
336
|
-
}
|
|
337
|
-
const contentMeta = buildContentMeta({
|
|
338
|
-
resourceDomains: [serverUrl],
|
|
339
|
-
connectDomains,
|
|
340
|
-
domain: serverUrl,
|
|
341
|
-
baseUriDomains: [serverUrl],
|
|
342
|
-
}, contentMetaOverrides);
|
|
343
441
|
return {
|
|
344
442
|
contents: [
|
|
345
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
443
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
346
444
|
],
|
|
347
445
|
};
|
|
348
446
|
});
|
|
349
447
|
}
|
|
350
|
-
|
|
448
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
449
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
450
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
451
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
452
|
+
}
|
|
453
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
351
454
|
return async (args, extra) => {
|
|
352
|
-
|
|
455
|
+
if (this.oauthEnabled) {
|
|
456
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.http?.authInfo);
|
|
457
|
+
if (failure) {
|
|
458
|
+
const header = (key) => extra.http?.req?.headers.get(key) ?? undefined;
|
|
459
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
let result;
|
|
463
|
+
try {
|
|
464
|
+
result = await cb(args, extra);
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
captureToolError(extra, error);
|
|
468
|
+
throw error;
|
|
469
|
+
}
|
|
470
|
+
if (isInputRequiredResult(result)) {
|
|
471
|
+
return result;
|
|
472
|
+
}
|
|
473
|
+
warnOnLargeToolOutput(result, toolName);
|
|
353
474
|
return {
|
|
354
475
|
...result,
|
|
355
476
|
content: normalizeContent(result.content),
|
|
@@ -362,6 +483,26 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
362
483
|
};
|
|
363
484
|
};
|
|
364
485
|
}
|
|
486
|
+
computeViewVersionParam(viewName) {
|
|
487
|
+
if (process.env.NODE_ENV !== "production") {
|
|
488
|
+
return "";
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
const viewFile = this.lookupViewFile(viewName);
|
|
492
|
+
const styleFile = this.lookupDistFile("style.css") ?? "";
|
|
493
|
+
const hash = crypto
|
|
494
|
+
.createHash("sha256")
|
|
495
|
+
.update(viewFile)
|
|
496
|
+
.update("\0")
|
|
497
|
+
.update(styleFile)
|
|
498
|
+
.digest("hex")
|
|
499
|
+
.slice(0, 8);
|
|
500
|
+
return `?v=${hash}`;
|
|
501
|
+
}
|
|
502
|
+
catch {
|
|
503
|
+
return "";
|
|
504
|
+
}
|
|
505
|
+
}
|
|
365
506
|
lookupViewFile(viewName) {
|
|
366
507
|
const manifest = this.readManifest();
|
|
367
508
|
for (const entry of Object.values(manifest)) {
|
|
@@ -375,25 +516,283 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
375
516
|
const manifest = this.readManifest();
|
|
376
517
|
return manifest[key]?.file;
|
|
377
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
521
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
522
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
523
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
524
|
+
*/
|
|
525
|
+
setViteManifest(manifest) {
|
|
526
|
+
this.viteManifest = manifest;
|
|
527
|
+
return this;
|
|
528
|
+
}
|
|
378
529
|
readManifest() {
|
|
379
|
-
|
|
530
|
+
if (this.viteManifest) {
|
|
531
|
+
return this.viteManifest;
|
|
532
|
+
}
|
|
533
|
+
cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
534
|
+
return cachedDiskManifest ?? {};
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* @experimental Register an MCP Events type that hosts can subscribe to, per
|
|
538
|
+
* the Triggers & Events working group draft. Skybridge serves `events/list`,
|
|
539
|
+
* `events/subscribe` and `events/unsubscribe`, checks auth and arguments,
|
|
540
|
+
* verifies the callback URL, then hands each subscription to `onSubscribe`.
|
|
541
|
+
* Delivering the events is up to you, for example with {@link deliverEvent}.
|
|
542
|
+
* API may change.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* server.registerEvent(
|
|
547
|
+
* {
|
|
548
|
+
* name: "comment.created",
|
|
549
|
+
* description: "Fires when someone comments on a document",
|
|
550
|
+
* inputSchema: { documentId: z.string() },
|
|
551
|
+
* payloadSchema: { documentId: z.string(), excerpt: z.string() },
|
|
552
|
+
* },
|
|
553
|
+
* {
|
|
554
|
+
* onSubscribe: ({ documentId }, { subscription }) =>
|
|
555
|
+
* webhooks.upsert({ ...subscription, filter: { documentId } }),
|
|
556
|
+
* onUnsubscribe: (_args, { subscription }) =>
|
|
557
|
+
* webhooks.remove(subscription.id),
|
|
558
|
+
* },
|
|
559
|
+
* );
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* @see https://docs.skybridge.tech/api-reference/register-event
|
|
563
|
+
*/
|
|
564
|
+
registerEvent(config, hooks) {
|
|
565
|
+
if (!this.eventRegistry) {
|
|
566
|
+
this.server.registerCapabilities({ events: {} });
|
|
567
|
+
this.eventRegistry = new EventRegistry(this.server);
|
|
568
|
+
}
|
|
569
|
+
this.eventRegistry.add(config, hooks);
|
|
570
|
+
return this;
|
|
380
571
|
}
|
|
381
|
-
|
|
572
|
+
/**
|
|
573
|
+
* Register a ChatGPT file viewer, from the OpenAI MCP extensions: a tool
|
|
574
|
+
* with a file entrypoint for `extensions` and a view. ChatGPT desktop calls
|
|
575
|
+
* it with the file the user opened, as `{ file: { name, resourceUri } }`.
|
|
576
|
+
* Read and save the file from the view with `useFileResource`.
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* server.registerFileViewer(
|
|
581
|
+
* {
|
|
582
|
+
* name: "part-viewer",
|
|
583
|
+
* title: "Part Viewer",
|
|
584
|
+
* extensions: [".stl", ".step"],
|
|
585
|
+
* view: { component: "part-viewer" },
|
|
586
|
+
* },
|
|
587
|
+
* async ({ file }) => ({ structuredContent: { name: file.name } }),
|
|
588
|
+
* );
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @see https://docs.skybridge.tech/api-reference/register-file-viewer
|
|
592
|
+
*/
|
|
593
|
+
registerFileViewer(config, cb) {
|
|
594
|
+
const { extensions, openai, ...toolConfig } = config;
|
|
595
|
+
return this.registerTool({
|
|
596
|
+
...toolConfig,
|
|
597
|
+
inputSchema: fileEntrypointInput,
|
|
598
|
+
openai: { ...openai, entrypoints: [{ type: "file", extensions }] },
|
|
599
|
+
}, cb);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Register the composer at-mention search for ChatGPT, from the OpenAI MCP
|
|
603
|
+
* extensions. When the user types `@` and your app name, ChatGPT calls
|
|
604
|
+
* `handler` with the typed text and lists the returned resource links.
|
|
605
|
+
* Skybridge registers it as a tool hidden from the model.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```ts
|
|
609
|
+
* server.registerMentions({
|
|
610
|
+
* name: "search_parts",
|
|
611
|
+
* handler: async ({ query }) => ({
|
|
612
|
+
* items: findParts(query).map((part) => ({
|
|
613
|
+
* type: "resource_link",
|
|
614
|
+
* uri: `parts://${part.id}`,
|
|
615
|
+
* name: part.name,
|
|
616
|
+
* })),
|
|
617
|
+
* }),
|
|
618
|
+
* });
|
|
619
|
+
* ```
|
|
620
|
+
*
|
|
621
|
+
* @see https://docs.skybridge.tech/api-reference/register-mentions
|
|
622
|
+
*/
|
|
623
|
+
registerMentions(config) {
|
|
624
|
+
this.registerTool({
|
|
625
|
+
name: config.name,
|
|
626
|
+
description: config.description ?? "Search items to mention.",
|
|
627
|
+
annotations: { readOnlyHint: true },
|
|
628
|
+
inputSchema: { query: z.string() },
|
|
629
|
+
_meta: {
|
|
630
|
+
"openai/extensions": { "mentions/search": {} },
|
|
631
|
+
ui: { visibility: ["app"] },
|
|
632
|
+
},
|
|
633
|
+
}, async ({ query }, extra) => ({
|
|
634
|
+
content: [],
|
|
635
|
+
structuredContent: await config.handler({ query }, extra),
|
|
636
|
+
}));
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Register app settings for ChatGPT, from the OpenAI MCP extensions.
|
|
641
|
+
* Skybridge registers a read tool and an update tool from `fields`, and
|
|
642
|
+
* advertises them in the `openai/settings` server capability. ChatGPT shows
|
|
643
|
+
* the settings page and calls `update` with the changed fields only. Store
|
|
644
|
+
* the values yourself, for example per user.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```ts
|
|
648
|
+
* server.registerSettings({
|
|
649
|
+
* fields: {
|
|
650
|
+
* units: { title: "Units", schema: z.enum(["mm", "in"]) },
|
|
651
|
+
* showGrid: { title: "Show grid", schema: z.boolean() },
|
|
652
|
+
* },
|
|
653
|
+
* read: (extra) => loadSettings(extra),
|
|
654
|
+
* update: (set, extra) => saveSettings(set, extra),
|
|
655
|
+
* });
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @see https://docs.skybridge.tech/api-reference/register-settings
|
|
659
|
+
*/
|
|
660
|
+
registerSettings(config) {
|
|
661
|
+
const { fields, layout, readTool = "settings.read", updateTool = "settings.update", } = config;
|
|
662
|
+
const values = z
|
|
663
|
+
.strictObject(Object.fromEntries(Object.entries(fields).map(([name, { schema, title, description }]) => [
|
|
664
|
+
name,
|
|
665
|
+
schema.meta({
|
|
666
|
+
title,
|
|
667
|
+
...(description !== undefined && { description }),
|
|
668
|
+
}),
|
|
669
|
+
])))
|
|
670
|
+
.required();
|
|
671
|
+
const { $schema: _, ...schema } = z.toJSONSchema(values);
|
|
672
|
+
for (const [name, property] of Object.entries(schema.properties ?? {})) {
|
|
673
|
+
if (fields[name]?.schema.safeParse(undefined).data !== undefined) {
|
|
674
|
+
throw new Error(`Setting "${name}" declares a default: return current values from \`read\` instead.`);
|
|
675
|
+
}
|
|
676
|
+
if (typeof property === "boolean" ||
|
|
677
|
+
!["boolean", "string", "number", "integer"].includes(String(property.type)) ||
|
|
678
|
+
(property.enum !== undefined && property.type !== "string")) {
|
|
679
|
+
throw new Error(`Setting "${name}" must be a boolean, string, string enum, number or integer.`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
const placed = new Set();
|
|
683
|
+
for (const group of layout ?? []) {
|
|
684
|
+
for (const item of group.items) {
|
|
685
|
+
if (item.kind !== "property") {
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
if (!Object.hasOwn(fields, item.property) ||
|
|
689
|
+
placed.has(item.property)) {
|
|
690
|
+
throw new Error(`Settings layout names an unknown or duplicate field "${item.property}".`);
|
|
691
|
+
}
|
|
692
|
+
placed.add(item.property);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
this.registerTool({
|
|
696
|
+
name: readTool,
|
|
697
|
+
description: "Read the app settings.",
|
|
698
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
699
|
+
inputSchema: {},
|
|
700
|
+
outputSchema: {
|
|
701
|
+
schema: z.record(z.string(), z.unknown()),
|
|
702
|
+
values,
|
|
703
|
+
layout: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
704
|
+
},
|
|
705
|
+
}, async (_args, extra) => ({
|
|
706
|
+
content: [],
|
|
707
|
+
structuredContent: {
|
|
708
|
+
schema,
|
|
709
|
+
values: values.parse(await config.read(extra)),
|
|
710
|
+
layout,
|
|
711
|
+
},
|
|
712
|
+
}));
|
|
713
|
+
this.registerTool({
|
|
714
|
+
name: updateTool,
|
|
715
|
+
description: "Update the app settings.",
|
|
716
|
+
annotations: {
|
|
717
|
+
destructiveHint: false,
|
|
718
|
+
idempotentHint: true,
|
|
719
|
+
openWorldHint: false,
|
|
720
|
+
},
|
|
721
|
+
inputSchema: {
|
|
722
|
+
set: values
|
|
723
|
+
.partial()
|
|
724
|
+
.refine((set) => Object.keys(set).length > 0)
|
|
725
|
+
.meta({ minProperties: 1 }),
|
|
726
|
+
},
|
|
727
|
+
outputSchema: { values },
|
|
728
|
+
}, async ({ set }, extra) => ({
|
|
729
|
+
content: [],
|
|
730
|
+
structuredContent: {
|
|
731
|
+
values: values.parse(await config.update(set, extra)),
|
|
732
|
+
},
|
|
733
|
+
}));
|
|
734
|
+
const capability = { readTool, updateTool };
|
|
735
|
+
this.server.registerCapabilities({
|
|
736
|
+
extensions: { "openai/settings": capability },
|
|
737
|
+
experimental: { "openai/settings": capability },
|
|
738
|
+
});
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
registerTool(rawConfig, rawCb) {
|
|
382
742
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
743
|
+
const config = rawConfig;
|
|
744
|
+
const cb = rawCb;
|
|
745
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, openai, _meta: userToolMeta, ...toolFields } = config;
|
|
746
|
+
const authNeedsProvider = auth !== undefined &&
|
|
747
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
748
|
+
if (rawSecuritySchemes === undefined &&
|
|
749
|
+
authNeedsProvider &&
|
|
750
|
+
!this.oauthEnabled) {
|
|
751
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
386
752
|
}
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
753
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
754
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
390
755
|
const toolMeta = { ...userToolMeta };
|
|
756
|
+
this.toolSecuritySchemes.set(name, securitySchemes);
|
|
757
|
+
if (securitySchemes) {
|
|
758
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
759
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
760
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
761
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
762
|
+
// ChatGPT plugin reference until SEP-1488 lands in the spec.
|
|
763
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
764
|
+
}
|
|
765
|
+
if (openai) {
|
|
766
|
+
if (!view) {
|
|
767
|
+
throw new Error(`skybridge: tool "${name}" sets \`openai\` options but has no \`view\`.`);
|
|
768
|
+
}
|
|
769
|
+
const opensWithoutInput = openai.entrypoints?.some(({ type }) => type === "global" || type === "thread");
|
|
770
|
+
if (opensWithoutInput && !acceptsEmptyInput(toolFields.inputSchema)) {
|
|
771
|
+
throw new Error(`skybridge: tool "${name}" has a global or thread entrypoint, so ChatGPT calls it with \`{}\`, but its input schema rejects \`{}\`. Make every input optional.`);
|
|
772
|
+
}
|
|
773
|
+
const badExtension = openai.entrypoints
|
|
774
|
+
?.flatMap((entrypoint) => entrypoint.type === "file" ? entrypoint.extensions : [])
|
|
775
|
+
.find((extension) => !extension.startsWith("."));
|
|
776
|
+
if (badExtension !== undefined) {
|
|
777
|
+
throw new Error(`skybridge: tool "${name}" has a file entrypoint extension "${badExtension}" that doesn't start with ".".`);
|
|
778
|
+
}
|
|
779
|
+
mergeOpenAIUi(toolMeta, {
|
|
780
|
+
entrypoints: openai.entrypoints,
|
|
781
|
+
preferredModelDisplayMode: openai.preferredModelDisplayMode,
|
|
782
|
+
});
|
|
783
|
+
}
|
|
391
784
|
if (view) {
|
|
392
785
|
this.enforceOneToolPerView(view.component, name);
|
|
393
|
-
this.registerViewResources(name, view, toolMeta);
|
|
786
|
+
this.registerViewResources(name, view, toolMeta, openai);
|
|
394
787
|
}
|
|
395
|
-
const wrappedCb = this.
|
|
396
|
-
|
|
788
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
789
|
+
attachViewUUID: Boolean(view),
|
|
790
|
+
securitySchemes,
|
|
791
|
+
toolName: name,
|
|
792
|
+
});
|
|
793
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, toolFields.inputSchema === undefined
|
|
794
|
+
? (extra) => wrappedCb({}, extra)
|
|
795
|
+
: wrappedCb);
|
|
397
796
|
return this;
|
|
398
797
|
}
|
|
399
798
|
}
|