skybridge 0.0.0-dev.db8be9c → 0.0.0-dev.dbab7df
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 +155 -0
- package/bin/run.js +0 -4
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +107 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +132 -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 +73 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +50 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/header.js +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/resolve-skybridge-config.d.ts +5 -0
- package/dist/cli/resolve-skybridge-config.js +18 -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 +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/{hooks → cli}/telemetry.js +1 -3
- package/dist/cli/telemetry.js.map +1 -0
- 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.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +2 -1
- package/dist/cli/use-execute-steps.js +6 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +16 -0
- package/dist/cli/use-nodemon.js +84 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- 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 +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +15 -0
- package/dist/cli/use-typescript-check.js +97 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +3 -16
- 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 +7 -1
- package/dist/commands/dev.js +117 -9
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +37 -15
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js +4 -3
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js +3 -2
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js +3 -2
- 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.d.ts +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 +180 -0
- package/dist/server/app.js +266 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +48 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +134 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- 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 +30 -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 +31 -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 +140 -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 +40 -0
- package/dist/server/auth/providers/custom.js +56 -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 +158 -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 +33 -0
- package/dist/server/auth/providers/workos.js +15 -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 +512 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +46 -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 +149 -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 +70 -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 +67 -0
- package/dist/server/content-helpers.js +79 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +13 -0
- package/dist/server/express.js +77 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +519 -0
- package/dist/server/express.test.js.map +1 -0
- 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/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 +21 -3
- package/dist/server/index.js +16 -2
- 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 +37 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +162 -0
- package/dist/server/middleware.js +126 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +559 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +23 -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 +387 -65
- package/dist/server/server.js +532 -99
- 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 +79 -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 +5 -7
- 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 +47 -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 +72 -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 +172 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +48 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/standard-schema.d.ts +3 -0
- package/dist/standard-schema.js +2 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/test/utils.d.ts +21 -31
- package/dist/test/utils.js +55 -45
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +536 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/views/index.d.ts +3 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/views/scan-views.d.ts +16 -0
- package/dist/views/scan-views.js +88 -0
- package/dist/views/scan-views.js.map +1 -0
- package/dist/views/scan-views.test.d.ts +1 -0
- package/dist/views/scan-views.test.js +99 -0
- package/dist/views/scan-views.test.js.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/views/validate-view.js +9 -0
- 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 +24 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +327 -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 +225 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +7 -2
- 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 +1 -2
- 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 +38 -26
- 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 +27 -31
- package/dist/web/bridges/mcp-app/bridge.js +111 -198
- 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 +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +17 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
- 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 -41
- 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 +160 -12
- 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 +4 -0
- package/dist/web/components/modal-provider.js +46 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +43 -3
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +32 -26
- 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 +31 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +52 -36
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +32 -27
- package/dist/web/generate-helpers.js +29 -24
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +33 -31
- 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 +9 -3
- package/dist/web/hooks/index.js +8 -2
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +7 -2
- package/dist/web/hooks/test/utils.js +18 -3
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- 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 +64 -29
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +23 -3
- 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.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- 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-files.d.ts +35 -6
- package/dist/web/hooks/use-files.js +37 -2
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +36 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +22 -0
- package/dist/web/hooks/use-host.js +30 -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-open-external.d.ts +20 -1
- package/dist/web/hooks/use-open-external.js +17 -1
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +39 -14
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- 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 +18 -3
- package/dist/web/hooks/use-request-modal.js +25 -8
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +16 -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 +19 -1
- package/dist/web/hooks/use-send-follow-up-message.js +19 -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 +18 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +25 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +63 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
- 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 +23 -4
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +104 -28
- 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-view-state.test.js +212 -0
- 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 +2 -2
- 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 +47 -0
- package/dist/web/mount-view.js.map +1 -0
- package/dist/web/proxy.js +0 -1
- 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 +59 -33
- package/tsconfig.base.json +33 -0
- package/dist/commands/telemetry.d.ts +0 -9
- package/dist/commands/telemetry.js +0 -39
- package/dist/commands/telemetry.js.map +0 -1
- package/dist/hooks/telemetry.js.map +0 -1
- package/dist/server/templates/development.hbs +0 -66
- package/dist/server/templates/production.hbs +0 -7
- package/dist/server/widgetsDevServer.d.ts +0 -12
- package/dist/server/widgetsDevServer.js +0 -47
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -255
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -14
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -39
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -19
- package/dist/web/bridges/mcp-app/adaptor.js +0 -145
- 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 +0 -61
- 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 -19
- 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 -2
- package/dist/web/plugin/plugin.js +0 -39
- package/dist/web/plugin/plugin.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/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{hooks → cli}/telemetry.d.ts +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type Implementation, type McpHttpHandler, type Server as SdkServer, type ServerOptions, type ServerResult } from "@modelcontextprotocol/server";
|
|
2
|
+
import { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
|
|
3
|
+
import type { ExtraClaims } from "./auth.js";
|
|
4
|
+
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
5
|
+
import { McpServer, type McpServerTypes, type SkybridgeServerOptions, type ToolDef } from "./server.js";
|
|
6
|
+
/**
|
|
7
|
+
* Everything a Skybridge app needs in one bag: the MCP implementation info
|
|
8
|
+
* (`name`, `version`, …), the SDK's {@link ServerOptions} (`capabilities`,
|
|
9
|
+
* `instructions`, …), and the Skybridge-specific options (`oauth`, `json`,
|
|
10
|
+
* `skills`).
|
|
11
|
+
*/
|
|
12
|
+
export type SkybridgeConfig<TAuthExtra extends ExtraClaims = ExtraClaims> = Implementation & ServerOptions & SkybridgeServerOptions<TAuthExtra>;
|
|
13
|
+
/**
|
|
14
|
+
* The factory that declares an app's MCP surface. Called with a fresh
|
|
15
|
+
* {@link McpServer} for every request, it must **return** the chained server so
|
|
16
|
+
* `typeof app` carries the registered tool types.
|
|
17
|
+
*/
|
|
18
|
+
export type SkybridgeSetup<TTools extends Record<string, ToolDef>, TAuthExtra extends ExtraClaims> = (server: McpServer<Record<never, ToolDef>, TAuthExtra>) => McpServer<TTools, TAuthExtra>;
|
|
19
|
+
/**
|
|
20
|
+
* A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`
|
|
21
|
+
* route) plus a factory that builds the MCP server for each request.
|
|
22
|
+
*
|
|
23
|
+
* The factory runs once per request, so tools, resources, prompts and views
|
|
24
|
+
* are always registered on the instance that serves the request. It also runs
|
|
25
|
+
* once at construction time, which surfaces registration errors at boot and
|
|
26
|
+
* gives the OAuth layer the set of per-tool security schemes.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TTools - Accumulated tool registry, inferred from the server the
|
|
29
|
+
* factory returns. You almost never set this manually.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export const app = new Skybridge(
|
|
34
|
+
* { name: "my-app", version: "1.0.0", capabilities: {} },
|
|
35
|
+
* (server) =>
|
|
36
|
+
* server.registerTool(
|
|
37
|
+
* {
|
|
38
|
+
* name: "search",
|
|
39
|
+
* inputSchema: { query: z.string() },
|
|
40
|
+
* view: { component: "search" },
|
|
41
|
+
* },
|
|
42
|
+
* async ({ query }) => ({ content: `Results for ${query}` }),
|
|
43
|
+
* ),
|
|
44
|
+
* );
|
|
45
|
+
*
|
|
46
|
+
* export type AppType = typeof app;
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
50
|
+
*/
|
|
51
|
+
export declare class Skybridge<TTools extends Record<string, ToolDef> = Record<never, ToolDef>, TAuthExtra extends ExtraClaims = ExtraClaims> {
|
|
52
|
+
readonly $types: McpServerTypes<TTools>;
|
|
53
|
+
private readonly serverInfo;
|
|
54
|
+
private readonly serverOptions;
|
|
55
|
+
private readonly skybridgeOptions;
|
|
56
|
+
private readonly setup;
|
|
57
|
+
private readonly expressApp;
|
|
58
|
+
private readonly errorMiddleware;
|
|
59
|
+
private readonly mcpMiddlewareEntries;
|
|
60
|
+
private middlewareLocked;
|
|
61
|
+
private monitoringEntry;
|
|
62
|
+
private resolveResourceMetadataUrl?;
|
|
63
|
+
private cachedFetchHandler?;
|
|
64
|
+
constructor(config: SkybridgeConfig<TAuthExtra>, setup: SkybridgeSetup<TTools, TAuthExtra>);
|
|
65
|
+
/**
|
|
66
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
67
|
+
* custom routes, middleware, or settings — e.g.
|
|
68
|
+
* `app.express.get("/health", ...)`.
|
|
69
|
+
*
|
|
70
|
+
* `express.json()` is pre-applied — tune it via the `json` config field,
|
|
71
|
+
* e.g. `new Skybridge({ name, version, json: { limit: "10mb" } }, setup)`.
|
|
72
|
+
* Register your handlers before `run()`; after `run()`, dev-mode middleware,
|
|
73
|
+
* the `/mcp` route, and the default error handler are appended in that order.
|
|
74
|
+
*
|
|
75
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
76
|
+
* locally and on self-hosted deployments.
|
|
77
|
+
*/
|
|
78
|
+
get express(): Express;
|
|
79
|
+
/**
|
|
80
|
+
* The app's fetch handler for `/mcp`: a `Request` → `Response` function that
|
|
81
|
+
* builds a fresh MCP server per request. Memoized, so the same handler is
|
|
82
|
+
* reused across requests.
|
|
83
|
+
*/
|
|
84
|
+
get fetchHandler(): McpHttpHandler;
|
|
85
|
+
/**
|
|
86
|
+
* Build a fresh server for one stateless HTTP request, as
|
|
87
|
+
* `createMcpHandler`'s factory contract requires: the factory runs again so
|
|
88
|
+
* the SDK's handler closures belong to the instance whose protocol era it
|
|
89
|
+
* stamps. Sharing one instance's handler maps instead would bind them to an
|
|
90
|
+
* instance that is never marked, pinning every request to the 2025 codec and
|
|
91
|
+
* letting concurrent callers overwrite each other's negotiated version.
|
|
92
|
+
*/
|
|
93
|
+
createServerInstance(): SdkServer;
|
|
94
|
+
/**
|
|
95
|
+
* Connect a Skybridge app to an MCP transport. Use this when you're
|
|
96
|
+
* embedding Skybridge in a host that already manages its own transport
|
|
97
|
+
* (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}
|
|
98
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
99
|
+
* via {@link Skybridge.mcpMiddleware} — further calls to that method will
|
|
100
|
+
* throw afterwards.
|
|
101
|
+
*/
|
|
102
|
+
connect(transport: Parameters<SdkServer["connect"]>[0]): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Register Express middleware on the underlying app. Mirrors `app.use` —
|
|
105
|
+
* pass handlers directly or a path-prefixed handler list. Register before
|
|
106
|
+
* {@link Skybridge.run}; ordering matches Express.
|
|
107
|
+
*
|
|
108
|
+
* Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work
|
|
109
|
+
* locally and on self-hosted deployments.
|
|
110
|
+
*/
|
|
111
|
+
use(...handlers: RequestHandler[]): this;
|
|
112
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
113
|
+
/**
|
|
114
|
+
* Register Express error-handling middleware to run after the built-in
|
|
115
|
+
* `/mcp` route (or your custom route). Use this to log or transform errors
|
|
116
|
+
* thrown by tool handlers before the default error handler responds.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* app.useOnError((err, _req, _res, next) => {
|
|
121
|
+
* logger.error(err);
|
|
122
|
+
* next(err);
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
127
|
+
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
128
|
+
/** Register MCP protocol-level middleware (catch-all). */
|
|
129
|
+
mcpMiddleware(handler: McpMiddlewareFn<TAuthExtra>): this;
|
|
130
|
+
/** Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`). */
|
|
131
|
+
mcpMiddleware(filter: "request", handler: (request: {
|
|
132
|
+
method: string;
|
|
133
|
+
params: Record<string, unknown>;
|
|
134
|
+
}, extra: McpExtra<TAuthExtra>, next: () => Promise<ServerResult>) => Promise<unknown> | unknown): this;
|
|
135
|
+
/** Register MCP protocol-level middleware for all notifications (`extra` is `undefined`). */
|
|
136
|
+
mcpMiddleware(filter: "notification", handler: (request: {
|
|
137
|
+
method: string;
|
|
138
|
+
params: Record<string, unknown>;
|
|
139
|
+
}, extra: undefined, next: () => Promise<undefined>) => Promise<unknown> | unknown): this;
|
|
140
|
+
/**
|
|
141
|
+
* Register MCP protocol-level middleware for an exact method.
|
|
142
|
+
* Narrows `params`, `extra`, and `next()` result based on the method string.
|
|
143
|
+
*/
|
|
144
|
+
mcpMiddleware<M extends McpMethodString>(filter: M, handler: McpTypedMiddlewareFn<M, TAuthExtra>): this;
|
|
145
|
+
/**
|
|
146
|
+
* Register MCP protocol-level middleware for a wildcard pattern (e.g. `"tools/*"`).
|
|
147
|
+
* `next()` returns the union of result types for matching methods.
|
|
148
|
+
*/
|
|
149
|
+
mcpMiddleware<W extends McpWildcard>(filter: W, handler: (request: {
|
|
150
|
+
method: string;
|
|
151
|
+
params: Record<string, unknown>;
|
|
152
|
+
}, extra: McpExtraFor<W, TAuthExtra>, next: () => Promise<McpResultFor<W>>) => Promise<unknown> | unknown): this;
|
|
153
|
+
/**
|
|
154
|
+
* Register MCP protocol-level middleware with a method filter.
|
|
155
|
+
* Filter can be an exact method (`"tools/call"`), wildcard (`"tools/*"`),
|
|
156
|
+
* category (`"request"` | `"notification"`), or an array of those.
|
|
157
|
+
*/
|
|
158
|
+
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn<TAuthExtra>): this;
|
|
159
|
+
/**
|
|
160
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
161
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
162
|
+
* via {@link Skybridge.use} / {@link Skybridge.useOnError}, and locks in
|
|
163
|
+
* any MCP middleware registered via {@link Skybridge.mcpMiddleware}.
|
|
164
|
+
*
|
|
165
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
166
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
167
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
168
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
169
|
+
* Node, returns `undefined` once listening. When the process was spawned
|
|
170
|
+
* with an IPC channel, the bound port is reported to the parent as
|
|
171
|
+
* `{ type: "skybridge:listening", port }`, the readiness signal test runners
|
|
172
|
+
* wait on instead of polling.
|
|
173
|
+
*/
|
|
174
|
+
run(): Promise<{
|
|
175
|
+
fetch: (...args: unknown[]) => unknown;
|
|
176
|
+
} | Express | undefined>;
|
|
177
|
+
private buildServer;
|
|
178
|
+
private middlewareEntries;
|
|
179
|
+
private instrumentHandlers;
|
|
180
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { createMcpHandler, } from "@modelcontextprotocol/server";
|
|
3
|
+
import express, {} from "express";
|
|
4
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
5
|
+
import { createApp } from "./express.js";
|
|
6
|
+
import { createMiddlewareEntry } from "./metric.js";
|
|
7
|
+
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
8
|
+
import { McpServer, } from "./server.js";
|
|
9
|
+
/**
|
|
10
|
+
* A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`
|
|
11
|
+
* route) plus a factory that builds the MCP server for each request.
|
|
12
|
+
*
|
|
13
|
+
* The factory runs once per request, so tools, resources, prompts and views
|
|
14
|
+
* are always registered on the instance that serves the request. It also runs
|
|
15
|
+
* once at construction time, which surfaces registration errors at boot and
|
|
16
|
+
* gives the OAuth layer the set of per-tool security schemes.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam TTools - Accumulated tool registry, inferred from the server the
|
|
19
|
+
* factory returns. You almost never set this manually.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* export const app = new Skybridge(
|
|
24
|
+
* { name: "my-app", version: "1.0.0", capabilities: {} },
|
|
25
|
+
* (server) =>
|
|
26
|
+
* server.registerTool(
|
|
27
|
+
* {
|
|
28
|
+
* name: "search",
|
|
29
|
+
* inputSchema: { query: z.string() },
|
|
30
|
+
* view: { component: "search" },
|
|
31
|
+
* },
|
|
32
|
+
* async ({ query }) => ({ content: `Results for ${query}` }),
|
|
33
|
+
* ),
|
|
34
|
+
* );
|
|
35
|
+
*
|
|
36
|
+
* export type AppType = typeof app;
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
40
|
+
*/
|
|
41
|
+
export class Skybridge {
|
|
42
|
+
serverInfo;
|
|
43
|
+
serverOptions;
|
|
44
|
+
skybridgeOptions;
|
|
45
|
+
setup;
|
|
46
|
+
expressApp;
|
|
47
|
+
errorMiddleware = [];
|
|
48
|
+
mcpMiddlewareEntries = [];
|
|
49
|
+
middlewareLocked = false;
|
|
50
|
+
monitoringEntry = null;
|
|
51
|
+
resolveResourceMetadataUrl;
|
|
52
|
+
cachedFetchHandler;
|
|
53
|
+
constructor(config, setup) {
|
|
54
|
+
const { name, title, version, description, icons, websiteUrl, json, oauth, skills, ...serverOptions } = config;
|
|
55
|
+
this.serverInfo = { name, title, version, description, icons, websiteUrl };
|
|
56
|
+
this.serverOptions = serverOptions;
|
|
57
|
+
this.skybridgeOptions = { json, oauth, skills };
|
|
58
|
+
this.setup = setup;
|
|
59
|
+
const sample = this.buildServer();
|
|
60
|
+
this.expressApp = express();
|
|
61
|
+
this.expressApp.use(express.json(json));
|
|
62
|
+
if (oauth) {
|
|
63
|
+
this.resolveResourceMetadataUrl = setupOAuth(this.expressApp, oauth, sample.securitySchemesByTool);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
68
|
+
* custom routes, middleware, or settings — e.g.
|
|
69
|
+
* `app.express.get("/health", ...)`.
|
|
70
|
+
*
|
|
71
|
+
* `express.json()` is pre-applied — tune it via the `json` config field,
|
|
72
|
+
* e.g. `new Skybridge({ name, version, json: { limit: "10mb" } }, setup)`.
|
|
73
|
+
* Register your handlers before `run()`; after `run()`, dev-mode middleware,
|
|
74
|
+
* the `/mcp` route, and the default error handler are appended in that order.
|
|
75
|
+
*
|
|
76
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
77
|
+
* locally and on self-hosted deployments.
|
|
78
|
+
*/
|
|
79
|
+
get express() {
|
|
80
|
+
return this.expressApp;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The app's fetch handler for `/mcp`: a `Request` → `Response` function that
|
|
84
|
+
* builds a fresh MCP server per request. Memoized, so the same handler is
|
|
85
|
+
* reused across requests.
|
|
86
|
+
*/
|
|
87
|
+
get fetchHandler() {
|
|
88
|
+
this.cachedFetchHandler ??= createMcpHandler(() => this.createServerInstance(), {
|
|
89
|
+
onerror: (error) => {
|
|
90
|
+
console.error("Error handling MCP request:", error);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
return this.cachedFetchHandler;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Build a fresh server for one stateless HTTP request, as
|
|
97
|
+
* `createMcpHandler`'s factory contract requires: the factory runs again so
|
|
98
|
+
* the SDK's handler closures belong to the instance whose protocol era it
|
|
99
|
+
* stamps. Sharing one instance's handler maps instead would bind them to an
|
|
100
|
+
* instance that is never marked, pinning every request to the 2025 codec and
|
|
101
|
+
* letting concurrent callers overwrite each other's negotiated version.
|
|
102
|
+
*/
|
|
103
|
+
createServerInstance() {
|
|
104
|
+
const server = this.buildServer();
|
|
105
|
+
this.instrumentHandlers(server);
|
|
106
|
+
return server.server;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Connect a Skybridge app to an MCP transport. Use this when you're
|
|
110
|
+
* embedding Skybridge in a host that already manages its own transport
|
|
111
|
+
* (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}
|
|
112
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
113
|
+
* via {@link Skybridge.mcpMiddleware} — further calls to that method will
|
|
114
|
+
* throw afterwards.
|
|
115
|
+
*/
|
|
116
|
+
async connect(transport) {
|
|
117
|
+
await this.createServerInstance().connect(transport);
|
|
118
|
+
}
|
|
119
|
+
use(pathOrHandler, ...handlers) {
|
|
120
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
121
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
122
|
+
if (typeof pathOrHandler === "string") {
|
|
123
|
+
this.expressApp.use(pathOrHandler, ...handlers);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.expressApp.use(pathOrHandler, ...handlers);
|
|
127
|
+
}
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
useOnError(pathOrHandler, ...handlers) {
|
|
131
|
+
if (typeof pathOrHandler === "string") {
|
|
132
|
+
this.errorMiddleware.push({ path: pathOrHandler, handlers });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.errorMiddleware.push({ handlers: [pathOrHandler, ...handlers] });
|
|
136
|
+
}
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
mcpMiddleware(filterOrHandler,
|
|
140
|
+
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
141
|
+
maybeHandler) {
|
|
142
|
+
if (this.middlewareLocked) {
|
|
143
|
+
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
144
|
+
}
|
|
145
|
+
const handler = maybeHandler;
|
|
146
|
+
if (typeof filterOrHandler === "function") {
|
|
147
|
+
this.mcpMiddlewareEntries.push({
|
|
148
|
+
filter: null,
|
|
149
|
+
handler: filterOrHandler,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else if (handler) {
|
|
153
|
+
this.mcpMiddlewareEntries.push({
|
|
154
|
+
filter: filterOrHandler,
|
|
155
|
+
handler,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
throw new Error("mcpMiddleware requires a handler function when a filter is provided");
|
|
160
|
+
}
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
165
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
166
|
+
* via {@link Skybridge.use} / {@link Skybridge.useOnError}, and locks in
|
|
167
|
+
* any MCP middleware registered via {@link Skybridge.mcpMiddleware}.
|
|
168
|
+
*
|
|
169
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
170
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
171
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
172
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
173
|
+
* Node, returns `undefined` once listening. When the process was spawned
|
|
174
|
+
* with an IPC channel, the bound port is reported to the parent as
|
|
175
|
+
* `{ type: "skybridge:listening", port }`, the readiness signal test runners
|
|
176
|
+
* wait on instead of polling.
|
|
177
|
+
*/
|
|
178
|
+
async run() {
|
|
179
|
+
this.middlewareLocked = true;
|
|
180
|
+
if (process.env.VERCEL === "1") {
|
|
181
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
182
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
183
|
+
// bare object passed to satisfy the required parameter.
|
|
184
|
+
const httpServer = http.createServer();
|
|
185
|
+
await createApp({
|
|
186
|
+
app: this,
|
|
187
|
+
httpServer,
|
|
188
|
+
errorMiddleware: this.errorMiddleware,
|
|
189
|
+
});
|
|
190
|
+
return this.expressApp;
|
|
191
|
+
}
|
|
192
|
+
const httpServer = http.createServer();
|
|
193
|
+
await createApp({
|
|
194
|
+
app: this,
|
|
195
|
+
httpServer,
|
|
196
|
+
errorMiddleware: this.errorMiddleware,
|
|
197
|
+
});
|
|
198
|
+
httpServer.on("request", this.expressApp);
|
|
199
|
+
const intendedPort = parseInt(process.env.__PORT ?? "3000", 10);
|
|
200
|
+
await new Promise((resolve, reject) => {
|
|
201
|
+
httpServer.on("error", (error) => {
|
|
202
|
+
console.error("Failed to start server:", error);
|
|
203
|
+
reject(error);
|
|
204
|
+
});
|
|
205
|
+
httpServer.listen(intendedPort, () => {
|
|
206
|
+
resolve();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
const { port } = httpServer.address();
|
|
210
|
+
process.send?.({ type: "skybridge:listening", port });
|
|
211
|
+
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
212
|
+
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
213
|
+
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
214
|
+
if (typeof navigator !== "undefined" &&
|
|
215
|
+
navigator.userAgent === "Cloudflare-Workers") {
|
|
216
|
+
const cloudflareNode = "cloudflare:node";
|
|
217
|
+
const { httpServerHandler } = await import(cloudflareNode);
|
|
218
|
+
return httpServerHandler({ port });
|
|
219
|
+
}
|
|
220
|
+
const shutdown = () => {
|
|
221
|
+
// Drop both handlers so a second signal falls through to Node's default
|
|
222
|
+
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
223
|
+
process.off("SIGTERM", shutdown);
|
|
224
|
+
process.off("SIGINT", shutdown);
|
|
225
|
+
httpServer.close(() => process.exit(0));
|
|
226
|
+
// Force exit if connections don't drain in time so the port is still
|
|
227
|
+
// released promptly (e.g. for nodemon restarts).
|
|
228
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
229
|
+
};
|
|
230
|
+
process.on("SIGTERM", shutdown);
|
|
231
|
+
process.on("SIGINT", shutdown);
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
buildServer() {
|
|
235
|
+
const server = new McpServer(this.serverInfo, this.serverOptions, this.skybridgeOptions);
|
|
236
|
+
if (this.resolveResourceMetadataUrl) {
|
|
237
|
+
server.setResourceMetadataUrlResolver(this.resolveResourceMetadataUrl);
|
|
238
|
+
}
|
|
239
|
+
return this.setup(server);
|
|
240
|
+
}
|
|
241
|
+
middlewareEntries(server) {
|
|
242
|
+
if (!this.middlewareLocked) {
|
|
243
|
+
this.middlewareLocked = true;
|
|
244
|
+
this.monitoringEntry = createMiddlewareEntry();
|
|
245
|
+
}
|
|
246
|
+
return [
|
|
247
|
+
...(this.monitoringEntry ? [this.monitoringEntry] : []),
|
|
248
|
+
...server.protocolMiddlewareEntries(),
|
|
249
|
+
...this.mcpMiddlewareEntries,
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
instrumentHandlers(server) {
|
|
253
|
+
const entries = this.middlewareEntries(server);
|
|
254
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(server.server);
|
|
255
|
+
const instrumentMap = (map, isNotification) => {
|
|
256
|
+
for (const [method, handler] of map) {
|
|
257
|
+
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
258
|
+
}
|
|
259
|
+
const originalSet = map.set.bind(map);
|
|
260
|
+
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
261
|
+
};
|
|
262
|
+
instrumentMap(requestHandlers, false);
|
|
263
|
+
instrumentMap(notificationHandlers, true);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,gBAAgB,GAMjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,OAAO,EAAE,EAIf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAoC,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAYpD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,SAAS,GAIV,MAAM,aAAa,CAAC;AA4BrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,SAAS;IAKH,UAAU,CAAiB;IAC3B,aAAa,CAAgB;IAC7B,gBAAgB,CAAqC;IACrD,KAAK,CAAqC;IAC1C,UAAU,CAAU;IACpB,eAAe,GAA4B,EAAE,CAAC;IAC9C,oBAAoB,GAAyB,EAAE,CAAC;IACzD,gBAAgB,GAAG,KAAK,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ACpB,GAA0D,EAC1D,cAAuB,EACvB,EAAE;YACF,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;gBACpC,GAAG,CAAC,GAAG,CACL,MAAM,EACN,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,CAC/D,CAAC;YACJ,CAAC;YACD,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtC,GAAG,CAAC,GAAG,GAAG,CACR,MAAc,EACd,OAAiD,EACjD,EAAE,CACF,WAAW,CACT,MAAM,EACN,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,CAC/D,CAAC;QACN,CAAC,CAAC;QAEF,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QACtC,aAAa,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import http from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\nimport {\n createMcpHandler,\n type Implementation,\n type McpHttpHandler,\n type Server as SdkServer,\n type ServerOptions,\n type ServerResult,\n} from \"@modelcontextprotocol/server\";\nimport express, {\n type ErrorRequestHandler,\n type Express,\n type RequestHandler,\n} from \"express\";\nimport { type ResourceMetadataUrlResolver, setupOAuth } from \"./auth/setup.js\";\nimport type { ExtraClaims } from \"./auth.js\";\nimport { createApp } from \"./express.js\";\nimport { createMiddlewareEntry } from \"./metric.js\";\nimport type {\n McpExtra,\n McpExtraFor,\n McpMethodString,\n McpMiddlewareEntry,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nimport { buildMiddlewareChain, getHandlerMaps } from \"./middleware.js\";\nimport {\n McpServer,\n type McpServerTypes,\n type SkybridgeServerOptions,\n type ToolDef,\n} from \"./server.js\";\n\ntype ErrorMiddlewareConfig = {\n path?: string;\n handlers: ErrorRequestHandler[];\n};\n\n/**\n * Everything a Skybridge app needs in one bag: the MCP implementation info\n * (`name`, `version`, …), the SDK's {@link ServerOptions} (`capabilities`,\n * `instructions`, …), and the Skybridge-specific options (`oauth`, `json`,\n * `skills`).\n */\nexport type SkybridgeConfig<TAuthExtra extends ExtraClaims = ExtraClaims> =\n Implementation & ServerOptions & SkybridgeServerOptions<TAuthExtra>;\n\n/**\n * The factory that declares an app's MCP surface. Called with a fresh\n * {@link McpServer} for every request, it must **return** the chained server so\n * `typeof app` carries the registered tool types.\n */\nexport type SkybridgeSetup<\n TTools extends Record<string, ToolDef>,\n TAuthExtra extends ExtraClaims,\n> = (\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n) => McpServer<TTools, TAuthExtra>;\n\n/**\n * A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`\n * route) plus a factory that builds the MCP server for each request.\n *\n * The factory runs once per request, so tools, resources, prompts and views\n * are always registered on the instance that serves the request. It also runs\n * once at construction time, which surfaces registration errors at boot and\n * gives the OAuth layer the set of per-tool security schemes.\n *\n * @typeParam TTools - Accumulated tool registry, inferred from the server the\n * factory returns. You almost never set this manually.\n *\n * @example\n * ```ts\n * export const app = new Skybridge(\n * { name: \"my-app\", version: \"1.0.0\", capabilities: {} },\n * (server) =>\n * server.registerTool(\n * {\n * name: \"search\",\n * inputSchema: { query: z.string() },\n * view: { component: \"search\" },\n * },\n * async ({ query }) => ({ content: `Results for ${query}` }),\n * ),\n * );\n *\n * export type AppType = typeof app;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/mcp-server\n */\nexport class Skybridge<\n TTools extends Record<string, ToolDef> = Record<never, ToolDef>,\n TAuthExtra extends ExtraClaims = ExtraClaims,\n> {\n declare readonly $types: McpServerTypes<TTools>;\n private readonly serverInfo: Implementation;\n private readonly serverOptions: ServerOptions;\n private readonly skybridgeOptions: SkybridgeServerOptions<TAuthExtra>;\n private readonly setup: SkybridgeSetup<TTools, TAuthExtra>;\n private readonly expressApp: Express;\n private readonly errorMiddleware: ErrorMiddlewareConfig[] = [];\n private readonly mcpMiddlewareEntries: McpMiddlewareEntry[] = [];\n private middlewareLocked = false;\n private monitoringEntry: McpMiddlewareEntry | null = null;\n private resolveResourceMetadataUrl?: ResourceMetadataUrlResolver;\n private cachedFetchHandler?: McpHttpHandler;\n\n constructor(\n config: SkybridgeConfig<TAuthExtra>,\n setup: SkybridgeSetup<TTools, TAuthExtra>,\n ) {\n const {\n name,\n title,\n version,\n description,\n icons,\n websiteUrl,\n json,\n oauth,\n skills,\n ...serverOptions\n } = config;\n\n this.serverInfo = { name, title, version, description, icons, websiteUrl };\n this.serverOptions = serverOptions;\n this.skybridgeOptions = { json, oauth, skills };\n this.setup = setup;\n\n const sample = this.buildServer();\n\n this.expressApp = express();\n this.expressApp.use(express.json(json));\n if (oauth) {\n this.resolveResourceMetadataUrl = setupOAuth(\n this.expressApp,\n oauth,\n sample.securitySchemesByTool,\n );\n }\n }\n\n /**\n * The underlying Express app. Use this to extend the HTTP server with\n * custom routes, middleware, or settings — e.g.\n * `app.express.get(\"/health\", ...)`.\n *\n * `express.json()` is pre-applied — tune it via the `json` config field,\n * e.g. `new Skybridge({ name, version, json: { limit: \"10mb\" } }, setup)`.\n * Register your handlers before `run()`; after `run()`, dev-mode middleware,\n * the `/mcp` route, and the default error handler are appended in that order.\n *\n * Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work\n * locally and on self-hosted deployments.\n */\n get express(): Express {\n return this.expressApp;\n }\n\n /**\n * The app's fetch handler for `/mcp`: a `Request` → `Response` function that\n * builds a fresh MCP server per request. Memoized, so the same handler is\n * reused across requests.\n */\n get fetchHandler(): McpHttpHandler {\n this.cachedFetchHandler ??= createMcpHandler(\n () => this.createServerInstance(),\n {\n onerror: (error) => {\n console.error(\"Error handling MCP request:\", error);\n },\n },\n );\n return this.cachedFetchHandler;\n }\n\n /**\n * Build a fresh server for one stateless HTTP request, as\n * `createMcpHandler`'s factory contract requires: the factory runs again so\n * the SDK's handler closures belong to the instance whose protocol era it\n * stamps. Sharing one instance's handler maps instead would bind them to an\n * instance that is never marked, pinning every request to the 2025 codec and\n * letting concurrent callers overwrite each other's negotiated version.\n */\n createServerInstance(): SdkServer {\n const server = this.buildServer();\n this.instrumentHandlers(server);\n return server.server;\n }\n\n /**\n * Connect a Skybridge app to an MCP transport. Use this when you're\n * embedding Skybridge in a host that already manages its own transport\n * (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}\n * which sets the transport up for you. Locks in any middleware registered\n * via {@link Skybridge.mcpMiddleware} — further calls to that method will\n * throw afterwards.\n */\n async connect(transport: Parameters<SdkServer[\"connect\"]>[0]): Promise<void> {\n await this.createServerInstance().connect(transport);\n }\n\n /**\n * Register Express middleware on the underlying app. Mirrors `app.use` —\n * pass handlers directly or a path-prefixed handler list. Register before\n * {@link Skybridge.run}; ordering matches Express.\n *\n * Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work\n * locally and on self-hosted deployments.\n */\n use(...handlers: RequestHandler[]): this;\n use(path: string, ...handlers: RequestHandler[]): this;\n use(\n pathOrHandler: string | RequestHandler,\n ...handlers: RequestHandler[]\n ): this {\n // Branching is load-bearing: Express's `app.use` overloads can't be\n // resolved against a `string | RequestHandler` union, so we narrow.\n if (typeof pathOrHandler === \"string\") {\n this.expressApp.use(pathOrHandler, ...handlers);\n } else {\n this.expressApp.use(pathOrHandler, ...handlers);\n }\n return this;\n }\n\n /**\n * Register Express error-handling middleware to run after the built-in\n * `/mcp` route (or your custom route). Use this to log or transform errors\n * thrown by tool handlers before the default error handler responds.\n *\n * @example\n * ```ts\n * app.useOnError((err, _req, _res, next) => {\n * logger.error(err);\n * next(err);\n * });\n * ```\n */\n useOnError(...handlers: ErrorRequestHandler[]): this;\n useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;\n useOnError(\n pathOrHandler: string | ErrorRequestHandler,\n ...handlers: ErrorRequestHandler[]\n ): this {\n if (typeof pathOrHandler === \"string\") {\n this.errorMiddleware.push({ path: pathOrHandler, handlers });\n } else {\n this.errorMiddleware.push({ handlers: [pathOrHandler, ...handlers] });\n }\n return this;\n }\n\n /** Register MCP protocol-level middleware (catch-all). */\n mcpMiddleware(handler: McpMiddlewareFn<TAuthExtra>): this;\n /** Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`). */\n mcpMiddleware(\n filter: \"request\",\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtra<TAuthExtra>,\n next: () => Promise<ServerResult>,\n ) => Promise<unknown> | unknown,\n ): this;\n /** Register MCP protocol-level middleware for all notifications (`extra` is `undefined`). */\n mcpMiddleware(\n filter: \"notification\",\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: undefined,\n next: () => Promise<undefined>,\n ) => Promise<unknown> | unknown,\n ): this;\n /**\n * Register MCP protocol-level middleware for an exact method.\n * Narrows `params`, `extra`, and `next()` result based on the method string.\n */\n mcpMiddleware<M extends McpMethodString>(\n filter: M,\n handler: McpTypedMiddlewareFn<M, TAuthExtra>,\n ): this;\n /**\n * Register MCP protocol-level middleware for a wildcard pattern (e.g. `\"tools/*\"`).\n * `next()` returns the union of result types for matching methods.\n */\n mcpMiddleware<W extends McpWildcard>(\n filter: W,\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtraFor<W, TAuthExtra>,\n next: () => Promise<McpResultFor<W>>,\n ) => Promise<unknown> | unknown,\n ): this;\n /**\n * Register MCP protocol-level middleware with a method filter.\n * Filter can be an exact method (`\"tools/call\"`), wildcard (`\"tools/*\"`),\n * category (`\"request\"` | `\"notification\"`), or an array of those.\n */\n mcpMiddleware(\n filter: McpMiddlewareFilter,\n handler: McpMiddlewareFn<TAuthExtra>,\n ): this;\n mcpMiddleware(\n filterOrHandler: McpMiddlewareFilter | McpMiddlewareFn<TAuthExtra>,\n // biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants\n maybeHandler?: any,\n ): this {\n if (this.middlewareLocked) {\n throw new Error(\n \"Cannot register MCP middleware after run() or connect() has been called\",\n );\n }\n\n const handler = maybeHandler as McpMiddlewareFn | undefined;\n\n if (typeof filterOrHandler === \"function\") {\n this.mcpMiddlewareEntries.push({\n filter: null,\n handler: filterOrHandler as McpMiddlewareFn,\n });\n } else if (handler) {\n this.mcpMiddlewareEntries.push({\n filter: filterOrHandler,\n handler,\n });\n } else {\n throw new Error(\n \"mcpMiddleware requires a handler function when a filter is provided\",\n );\n }\n\n return this;\n }\n\n /**\n * Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),\n * mounts the `/mcp` route, applies any custom Express middleware registered\n * via {@link Skybridge.use} / {@link Skybridge.useOnError}, and locks in\n * any MCP middleware registered via {@link Skybridge.mcpMiddleware}.\n *\n * On Cloudflare Workers / workerd, returns an object exposing `fetch` so\n * the runtime can bridge incoming requests to the Node HTTP server. On\n * Vercel (`VERCEL === \"1\"`), returns the Express app directly so the\n * serverless function entry can call it as a `(req, res)` handler. On\n * Node, returns `undefined` once listening. When the process was spawned\n * with an IPC channel, the bound port is reported to the parent as\n * `{ type: \"skybridge:listening\", port }`, the readiness signal test runners\n * wait on instead of polling.\n */\n async run(): Promise<\n { fetch: (...args: unknown[]) => unknown } | Express | undefined\n > {\n this.middlewareLocked = true;\n if (process.env.VERCEL === \"1\") {\n // createApp only reads httpServer inside its dev-only branch\n // (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a\n // bare object passed to satisfy the required parameter.\n const httpServer = http.createServer();\n await createApp({\n app: this,\n httpServer,\n errorMiddleware: this.errorMiddleware,\n });\n return this.expressApp;\n }\n\n const httpServer = http.createServer();\n\n await createApp({\n app: this,\n httpServer,\n errorMiddleware: this.errorMiddleware,\n });\n\n httpServer.on(\"request\", this.expressApp);\n const intendedPort = parseInt(process.env.__PORT ?? \"3000\", 10);\n await new Promise<void>((resolve, reject) => {\n httpServer.on(\"error\", (error: Error) => {\n console.error(\"Failed to start server:\", error);\n reject(error);\n });\n httpServer.listen(intendedPort, () => {\n resolve();\n });\n });\n\n const { port } = httpServer.address() as AddressInfo;\n process.send?.({ type: \"skybridge:listening\", port });\n\n // On workerd, bridge the Node http server to a Workers fetch handler.\n // The specifier is held in a variable to sidestep tsc's module resolution\n // (`cloudflare:node` only exists under wrangler/workerd).\n if (\n typeof navigator !== \"undefined\" &&\n navigator.userAgent === \"Cloudflare-Workers\"\n ) {\n const cloudflareNode = \"cloudflare:node\";\n const { httpServerHandler } = await import(cloudflareNode);\n return httpServerHandler({ port });\n }\n\n const shutdown = () => {\n // Drop both handlers so a second signal falls through to Node's default\n // (force-quit on a second Ctrl+C while drain is hanging).\n process.off(\"SIGTERM\", shutdown);\n process.off(\"SIGINT\", shutdown);\n httpServer.close(() => process.exit(0));\n // Force exit if connections don't drain in time so the port is still\n // released promptly (e.g. for nodemon restarts).\n setTimeout(() => process.exit(0), 3000).unref();\n };\n process.on(\"SIGTERM\", shutdown);\n process.on(\"SIGINT\", shutdown);\n return undefined;\n }\n\n private buildServer(): McpServer<TTools, TAuthExtra> {\n const server = new McpServer<Record<never, ToolDef>, TAuthExtra>(\n this.serverInfo,\n this.serverOptions,\n this.skybridgeOptions,\n );\n if (this.resolveResourceMetadataUrl) {\n server.setResourceMetadataUrlResolver(this.resolveResourceMetadataUrl);\n }\n return this.setup(server);\n }\n\n private middlewareEntries(\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n ): McpMiddlewareEntry[] {\n if (!this.middlewareLocked) {\n this.middlewareLocked = true;\n this.monitoringEntry = createMiddlewareEntry();\n }\n return [\n ...(this.monitoringEntry ? [this.monitoringEntry] : []),\n ...server.protocolMiddlewareEntries(),\n ...this.mcpMiddlewareEntries,\n ];\n }\n\n private instrumentHandlers(\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n ): void {\n const entries = this.middlewareEntries(server);\n const { requestHandlers, notificationHandlers } = getHandlerMaps(\n server.server,\n );\n\n const instrumentMap = (\n map: Map<string, (...args: unknown[]) => Promise<unknown>>,\n isNotification: boolean,\n ) => {\n for (const [method, handler] of map) {\n map.set(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n }\n const originalSet = map.set.bind(map);\n map.set = (\n method: string,\n handler: (...args: unknown[]) => Promise<unknown>,\n ) =>\n originalSet(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n };\n\n instrumentMap(requestHandlers, false);\n instrumentMap(notificationHandlers, true);\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export declare function isCssRequest(id: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,
|
|
5
|
+
* so they work both locally and behind tunnels.
|
|
6
|
+
*/
|
|
7
|
+
export declare function assetBaseUrlTransform(code: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assetBaseUrlTransformPlugin(): Plugin;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Mirrors Vite's own `isCSSRequest`: matches the css family of extensions
|
|
2
|
+
// either at the end of the id or right before the query string. Catches both
|
|
3
|
+
// plain `.css` requests and SFC style blocks (e.g. `Foo.vue?vue&type=style&lang.css`).
|
|
4
|
+
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
5
|
+
export function isCssRequest(id) {
|
|
6
|
+
return CSS_LANGS_RE.test(id);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,
|
|
10
|
+
* so they work both locally and behind tunnels.
|
|
11
|
+
*/
|
|
12
|
+
export function assetBaseUrlTransform(code) {
|
|
13
|
+
const assetStringPattern = /(?<!\bfrom\s)(?<!https?:\/\/)(["'`])(\/[^"'`]+\.(svg|png|jpeg|jpg|gif|webp|mp3|mp4|woff|woff2|ttf|eot))\1/g;
|
|
14
|
+
code = code.replace(assetStringPattern, (_match, _quote, assetPath) => {
|
|
15
|
+
return `(window.skybridge?.serverUrl ?? "") + "${assetPath}"`;
|
|
16
|
+
});
|
|
17
|
+
return code;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.
|
|
21
|
+
*/
|
|
22
|
+
export function assetBaseUrlTransformPlugin() {
|
|
23
|
+
return {
|
|
24
|
+
name: "asset-base-url-transform",
|
|
25
|
+
transform(code, id) {
|
|
26
|
+
if (!code) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
// Vite serves CSS modules as JS that embeds the stylesheet as a string
|
|
30
|
+
// literal. Rewriting `url("/foo.woff2")` inside that string to a JS
|
|
31
|
+
// concatenation expression produces invalid CSS once it lands in a
|
|
32
|
+
// <style> tag. CSS asset URLs are already handled at build time by
|
|
33
|
+
// `experimental.renderBuiltUrl`, so skip CSS requests here.
|
|
34
|
+
if (isCssRequest(id)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const transformedCode = assetBaseUrlTransform(code);
|
|
38
|
+
if (transformedCode === code) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
code: transformedCode,
|
|
43
|
+
map: null,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=asset-base-url-transform-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-base-url-transform-plugin.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,6EAA6E;AAC7E,uFAAuF;AACvF,MAAM,YAAY,GAChB,6DAA6D,CAAC;AAEhE,MAAM,UAAU,YAAY,CAAC,EAAU;IACrC,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,kBAAkB,GACtB,4GAA4G,CAAC;IAE/G,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE;QACpE,OAAO,0CAA0C,SAAS,GAAG,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,SAAS,CAAC,IAAI,EAAE,EAAE;YAChB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YACd,CAAC;YAED,uEAAuE;YACvE,oEAAoE;YACpE,mEAAmE;YACnE,mEAAmE;YACnE,4DAA4D;YAC5D,IAAI,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;gBACrB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,eAAe,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;YAEpD,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,GAAG,EAAE,IAAI;aACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from \"vite\";\n\n// Mirrors Vite's own `isCSSRequest`: matches the css family of extensions\n// either at the end of the id or right before the query string. Catches both\n// plain `.css` requests and SFC style blocks (e.g. `Foo.vue?vue&type=style&lang.css`).\nconst CSS_LANGS_RE =\n /\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\\?)/;\n\nexport function isCssRequest(id: string): boolean {\n return CSS_LANGS_RE.test(id);\n}\n\n/**\n * Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,\n * so they work both locally and behind tunnels.\n */\nexport function assetBaseUrlTransform(code: string): string {\n const assetStringPattern =\n /(?<!\\bfrom\\s)(?<!https?:\\/\\/)([\"'`])(\\/[^\"'`]+\\.(svg|png|jpeg|jpg|gif|webp|mp3|mp4|woff|woff2|ttf|eot))\\1/g;\n\n code = code.replace(assetStringPattern, (_match, _quote, assetPath) => {\n return `(window.skybridge?.serverUrl ?? \"\") + \"${assetPath}\"`;\n });\n\n return code;\n}\n\n/**\n * Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.\n */\nexport function assetBaseUrlTransformPlugin(): Plugin {\n return {\n name: \"asset-base-url-transform\",\n transform(code, id) {\n if (!code) {\n return null;\n }\n\n // Vite serves CSS modules as JS that embeds the stylesheet as a string\n // literal. Rewriting `url(\"/foo.woff2\")` inside that string to a JS\n // concatenation expression produces invalid CSS once it lands in a\n // <style> tag. CSS asset URLs are already handled at build time by\n // `experimental.renderBuiltUrl`, so skip CSS requests here.\n if (isCssRequest(id)) {\n return null;\n }\n\n const transformedCode = assetBaseUrlTransform(code);\n\n if (transformedCode === code) {\n return null;\n }\n\n return {\n code: transformedCode,\n map: null,\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|