skybridge 0.0.0-dev.ecf87cf → 0.0.0-dev.ed005a8
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/LICENSE +21 -0
- package/README.md +155 -0
- package/bin/run.js +5 -0
- 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 +49 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- 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.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- 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/cli/telemetry.d.ts +7 -0
- package/dist/cli/telemetry.js +123 -0
- 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.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +11 -0
- package/dist/cli/use-execute-steps.js +36 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- 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 +92 -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 +6 -0
- package/dist/commands/build.js +31 -0
- package/dist/commands/build.js.map +1 -0
- 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 +13 -0
- package/dist/commands/dev.js +128 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.js +55 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- 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 +194 -0
- package/dist/server/app.js +266 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/app.test.js +97 -0
- package/dist/server/app.test.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.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.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.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.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.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 +59 -0
- package/dist/server/auth/providers/custom.js.map +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.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.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.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.js +514 -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.js +149 -0
- package/dist/server/auth/verify.test.js.map +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.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 +31 -0
- package/dist/server/express.js +107 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +608 -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 +22 -0
- package/dist/server/index.js +18 -0
- package/dist/server/index.js.map +1 -0
- package/dist/{src/server → server}/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/mcp-errors.test.d.ts +1 -0
- package/dist/server/mcp-errors.test.js +41 -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 +601 -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 +27 -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 +420 -0
- package/dist/server/server.js +546 -0
- package/dist/server/server.js.map +1 -0
- 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/{src/server → server}/templateHelper.d.ts +2 -7
- package/dist/server/templateHelper.js +11 -0
- package/dist/server/templateHelper.js.map +1 -0
- 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 +88 -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.d.ts +14 -0
- package/dist/server/viewsDevServer.js +48 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/{src/test → test}/utils.d.ts +21 -31
- package/dist/test/utils.js +266 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +540 -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 +10 -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 +15 -0
- package/dist/web/bridges/apps-sdk/bridge.js +58 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +4 -0
- package/dist/web/bridges/apps-sdk/index.js +4 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/web/bridges/apps-sdk/types.d.ts +133 -0
- package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +13 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +18 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +9 -0
- package/dist/web/bridges/get-adaptor.js +10 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- 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.d.ts +5 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +39 -0
- package/dist/web/bridges/mcp-app/bridge.js +168 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- 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 +3 -0
- package/dist/web/bridges/mcp-app/index.js +3 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +10 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +19 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +19 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- 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 +219 -0
- package/dist/web/bridges/types.js +15 -0
- package/dist/web/bridges/types.js.map +1 -0
- 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 +7 -0
- package/dist/web/bridges/use-host-context.js +13 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- 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 +29 -0
- package/dist/web/create-store.js +64 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.d.ts +1 -0
- package/dist/web/create-store.test.js +132 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/web/data-llm.d.ts +47 -0
- package/dist/{src/web → web}/data-llm.js +39 -7
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.d.ts +1 -0
- package/dist/web/data-llm.test.js +155 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +41 -32
- package/dist/{src/web → web}/generate-helpers.js +36 -28
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +35 -30
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.d.ts +1 -0
- package/dist/{src/web → web}/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.d.ts +1 -0
- package/dist/{src/web → web}/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/web/hooks/index.d.ts +16 -0
- package/dist/web/hooks/index.js +17 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +21 -0
- package/dist/web/hooks/test/utils.js +75 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +47 -1
- package/dist/web/hooks/use-call-tool.js +96 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +84 -24
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +24 -0
- package/dist/web/hooks/use-display-mode.js +29 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- 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.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test.js +77 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- 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 +39 -0
- package/dist/web/hooks/use-files.js +42 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/web/hooks/use-files.test.d.ts +1 -0
- package/dist/web/hooks/use-files.test.js +62 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- 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 -0
- package/dist/web/hooks/use-open-external.js +24 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/web/hooks/use-open-external.test.js +75 -0
- package/dist/web/hooks/use-open-external.test.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 +24 -0
- package/dist/web/hooks/use-request-modal.js +31 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-request-modal.test.js +16 -2
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- 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 -0
- package/dist/web/hooks/use-send-follow-up-message.js +25 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- 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 +57 -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 +68 -0
- package/dist/web/hooks/use-tool-info.js +48 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +19 -6
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test.js +135 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-user.d.ts +5 -2
- package/dist/web/hooks/use-user.js +38 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +170 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- 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/{src/web → web}/index.d.ts +1 -2
- package/dist/{src/web → web}/index.js +1 -2
- package/dist/web/index.js.map +1 -0
- 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/{src/web → web}/proxy.js +0 -1
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +20 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +86 -41
- package/tsconfig.base.json +33 -0
- package/dist/src/server/devtoolsStaticServer.d.ts +0 -15
- package/dist/src/server/devtoolsStaticServer.js +0 -38
- package/dist/src/server/devtoolsStaticServer.js.map +0 -1
- package/dist/src/server/index.d.ts +0 -5
- package/dist/src/server/index.js +0 -4
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/inferUtilityTypes.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -74
- package/dist/src/server/server.js +0 -82
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js +0 -30
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -13
- package/dist/src/server/templates/production.hbs +0 -7
- package/dist/src/server/widgetsDevServer.d.ts +0 -12
- package/dist/src/server/widgetsDevServer.js +0 -39
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.js +0 -242
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -146
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/bridges/apps-sdk-adapter.d.ts +0 -2
- package/dist/src/web/bridges/apps-sdk-adapter.js +0 -4
- package/dist/src/web/bridges/apps-sdk-adapter.js.map +0 -1
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -8
- package/dist/src/web/bridges/apps-sdk-bridge.js +0 -41
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/get-bridge-methods.d.ts +0 -2
- package/dist/src/web/bridges/get-bridge-methods.js +0 -8
- package/dist/src/web/bridges/get-bridge-methods.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +0 -7
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-bridge.js +0 -90
- package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -4
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -58
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
- package/dist/src/web/bridges/index.d.ts +0 -4
- package/dist/src/web/bridges/index.js +0 -5
- package/dist/src/web/bridges/index.js.map +0 -1
- package/dist/src/web/bridges/mcp-app-adapter.d.ts +0 -2
- package/dist/src/web/bridges/mcp-app-adapter.js +0 -12
- package/dist/src/web/bridges/mcp-app-adapter.js.map +0 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -30
- package/dist/src/web/bridges/mcp-app-bridge.js +0 -139
- package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/types.d.ts +0 -32
- package/dist/src/web/bridges/types.js.map +0 -1
- package/dist/src/web/create-store.d.ts +0 -3
- package/dist/src/web/create-store.js +0 -25
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/create-store.test.js +0 -70
- package/dist/src/web/create-store.test.js.map +0 -1
- package/dist/src/web/data-llm.d.ts +0 -14
- package/dist/src/web/data-llm.js.map +0 -1
- package/dist/src/web/data-llm.test.js +0 -76
- package/dist/src/web/data-llm.test.js.map +0 -1
- package/dist/src/web/generate-helpers.js.map +0 -1
- package/dist/src/web/generate-helpers.test-d.js.map +0 -1
- package/dist/src/web/generate-helpers.test.js.map +0 -1
- package/dist/src/web/helpers/state.js +0 -40
- package/dist/src/web/helpers/state.js.map +0 -1
- package/dist/src/web/helpers/state.test.js.map +0 -1
- package/dist/src/web/hooks/index.d.ts +0 -11
- package/dist/src/web/hooks/index.js +0 -12
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js +0 -60
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +0 -4
- package/dist/src/web/hooks/use-display-mode.js +0 -10
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js +0 -41
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-files.d.ts +0 -10
- package/dist/src/web/hooks/use-files.js +0 -7
- package/dist/src/web/hooks/use-files.js.map +0 -1
- package/dist/src/web/hooks/use-files.test.js +0 -29
- package/dist/src/web/hooks/use-files.test.js.map +0 -1
- package/dist/src/web/hooks/use-layout.d.ts +0 -22
- package/dist/src/web/hooks/use-layout.js +0 -23
- package/dist/src/web/hooks/use-layout.js.map +0 -1
- package/dist/src/web/hooks/use-layout.test.js +0 -46
- package/dist/src/web/hooks/use-layout.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.d.ts +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
- package/dist/src/web/hooks/use-openai-global.js +0 -6
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -9
- package/dist/src/web/hooks/use-request-modal.js +0 -14
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.d.ts +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +0 -25
- package/dist/src/web/hooks/use-tool-info.js +0 -20
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -60
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-user.js +0 -19
- package/dist/src/web/hooks/use-user.js.map +0 -1
- package/dist/src/web/hooks/use-user.test.js +0 -44
- package/dist/src/web/hooks/use-user.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/src/web/hooks/use-widget-state.js +0 -32
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js +0 -61
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.d.ts +0 -1
- package/dist/src/web/mount-widget.js +0 -19
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin/data-llm.test.js +0 -81
- package/dist/src/web/plugin/data-llm.test.js.map +0 -1
- package/dist/src/web/plugin/plugin.d.ts +0 -2
- package/dist/src/web/plugin/plugin.js +0 -39
- package/dist/src/web/plugin/plugin.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.d.ts +0 -12
- package/dist/src/web/plugin/transform-data-llm.js +0 -93
- package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.test.js +0 -81
- package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/src/web/proxy.js.map +0 -1
- package/dist/src/web/types.d.ts +0 -151
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{src/web/create-store.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{src/web/bridges → cli}/types.js +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{src/web/helpers/state.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → server/auth/discovery.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → server/auth/providers/auth0.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-layout.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → server/auth/providers/clerk.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → server/auth/providers/custom.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → server/auth/providers/descope.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → server/auth/providers/shared.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → server/auth/setup.test.d.ts} +0 -0
- /package/dist/{src/web/plugin/data-llm.test.d.ts → server/auth/verify.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → server/build-manifest.test.d.ts} +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +0 -0
- /package/dist/{src/web → web}/proxy.d.ts +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { Implementation, Server as SdkServer, ServerOptions } from "@modelcontextprotocol/server";
|
|
2
|
+
import type { ErrorRequestHandler, Express, RequestHandler } from "express";
|
|
3
|
+
import type { OAuthConfig, OAuthProvider } from "./auth/index.js";
|
|
4
|
+
import type { ExtraClaims } from "./auth.js";
|
|
5
|
+
import { type JsonOptions, McpServer, type McpServerTypes, type ToolDef } from "./server.js";
|
|
6
|
+
/**
|
|
7
|
+
* The `handler` field of {@link SkybridgeConfig}: builds the app's MCP
|
|
8
|
+
* surface. Runs again for **every incoming request**, on a fresh
|
|
9
|
+
* {@link McpServer}, so keep it to registration: pools, clients and any other
|
|
10
|
+
* one-time work belong in `setup`, whose result is the second argument. It
|
|
11
|
+
* must **return** the chained server so `typeof app` carries the registered
|
|
12
|
+
* tool types.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam TConfig - What `setup` resolved to, passed as the second argument.
|
|
15
|
+
*/
|
|
16
|
+
export type SkybridgeHandler<TTools extends Record<string, ToolDef>, TConfig, TAuthExtra extends ExtraClaims> = (server: McpServer<Record<never, ToolDef>, TAuthExtra>, config: TConfig) => McpServer<TTools, TAuthExtra>;
|
|
17
|
+
/**
|
|
18
|
+
* What the `oauth` field accepts: an {@link OAuthConfig}, a provider
|
|
19
|
+
* (`oauth: auth0Provider(...)`), or a function of the `setup` result returning
|
|
20
|
+
* either. Providers and functions resolve once, at {@link Skybridge.run} or on
|
|
21
|
+
* the first request, never at module import. Anything asynchronous belongs in
|
|
22
|
+
* a provider's `resolve`.
|
|
23
|
+
*/
|
|
24
|
+
export type SkybridgeOAuthInput<TConfig, TExtra extends ExtraClaims> = OAuthConfig<TExtra> | OAuthProvider<TExtra> | ((config: TConfig) => OAuthConfig<TExtra> | OAuthProvider<TExtra>);
|
|
25
|
+
/**
|
|
26
|
+
* Everything a Skybridge app needs in one bag: the MCP implementation info
|
|
27
|
+
* (`name`, `version`, …), the SDK's {@link ServerOptions} (`capabilities`,
|
|
28
|
+
* `instructions`, …), the Express and skills options, and the app's behavior
|
|
29
|
+
* (`setup`, `oauth`, `handler`).
|
|
30
|
+
*
|
|
31
|
+
* All type parameters are inferred from the value: the config from `setup`,
|
|
32
|
+
* the auth claims from `oauth`, and the tool registry from the server
|
|
33
|
+
* `handler` returns.
|
|
34
|
+
*/
|
|
35
|
+
export type SkybridgeConfig<TTools extends Record<string, ToolDef> = Record<never, ToolDef>, TConfig = undefined, TAuthExtra extends ExtraClaims = ExtraClaims> = Implementation & ServerOptions & {
|
|
36
|
+
/** Options for the built-in `express.json()` middleware, e.g. `{ limit: "10mb" }`. */
|
|
37
|
+
json?: JsonOptions;
|
|
38
|
+
/**
|
|
39
|
+
* @experimental Serve Agent Skills from `src/skills` over MCP (SEP-2640).
|
|
40
|
+
* API may change.
|
|
41
|
+
*/
|
|
42
|
+
skills?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Loads whatever the app needs up front (remote config, secrets, datasets,
|
|
45
|
+
* …). Runs **once** — at {@link Skybridge.run} or on the first request,
|
|
46
|
+
* never at module import — and its awaited return value is passed to an
|
|
47
|
+
* `oauth` function and to `handler` as the second argument.
|
|
48
|
+
*/
|
|
49
|
+
setup?: () => TConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Resource-server OAuth. When set, mounts the well-known metadata routes
|
|
52
|
+
* and bearer auth on `/mcp`, and the verifier's claims type
|
|
53
|
+
* `extra.http.authInfo.extra` in tool handlers.
|
|
54
|
+
*/
|
|
55
|
+
oauth?: SkybridgeOAuthInput<Awaited<TConfig>, TAuthExtra>;
|
|
56
|
+
/** Registers the MCP surface, per request. See {@link SkybridgeHandler}. */
|
|
57
|
+
handler: SkybridgeHandler<TTools, Awaited<TConfig>, TAuthExtra>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`
|
|
61
|
+
* route) plus a handler that builds the MCP server for each request.
|
|
62
|
+
*
|
|
63
|
+
* The handler runs for every request, so tools, resources, prompts and views
|
|
64
|
+
* are always registered on the instance that serves the request. Anything in
|
|
65
|
+
* the handler body other than registration therefore runs per request too.
|
|
66
|
+
* Anything asynchronous the app needs (remote config, secrets, …) goes in
|
|
67
|
+
* `setup`, which runs once and feeds the handler's second argument.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* export const app = new Skybridge({
|
|
72
|
+
* name: "my-app",
|
|
73
|
+
* version: "1.0.0",
|
|
74
|
+
* setup: async () => loadConfig(),
|
|
75
|
+
* oauth: (config) => descopeProvider({ url: config.mcpServerUrl }),
|
|
76
|
+
* handler: (server, config) =>
|
|
77
|
+
* server.registerTool(
|
|
78
|
+
* {
|
|
79
|
+
* name: "search",
|
|
80
|
+
* inputSchema: { query: z.string() },
|
|
81
|
+
* view: { component: "search" },
|
|
82
|
+
* },
|
|
83
|
+
* async ({ query }) => ({ content: `Results for ${query}` }),
|
|
84
|
+
* ),
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* export type AppType = typeof app;
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
91
|
+
*/
|
|
92
|
+
export declare class Skybridge<TTools extends Record<string, ToolDef> = Record<never, ToolDef>, TConfig = undefined, TAuthExtra extends ExtraClaims = ExtraClaims> {
|
|
93
|
+
readonly $types: McpServerTypes<TTools>;
|
|
94
|
+
private readonly serverInfo;
|
|
95
|
+
private readonly serverOptions;
|
|
96
|
+
private readonly skills?;
|
|
97
|
+
private oauthEnabled;
|
|
98
|
+
private readonly handler;
|
|
99
|
+
private readonly setup?;
|
|
100
|
+
private readonly oauthInput?;
|
|
101
|
+
private config?;
|
|
102
|
+
private readonly expressApp;
|
|
103
|
+
private readonly errorMiddleware;
|
|
104
|
+
private readonly monitoringEntry;
|
|
105
|
+
private resolveResourceMetadataUrl?;
|
|
106
|
+
private readyPromise?;
|
|
107
|
+
private slowHandlerWarned;
|
|
108
|
+
constructor({ name, title, version, description, icons, websiteUrl, json, skills, setup, oauth, handler, ...serverOptions }: SkybridgeConfig<TTools, TConfig, TAuthExtra>);
|
|
109
|
+
/**
|
|
110
|
+
* Resolve `setup` and `oauth`, then wire OAuth onto the Express app. Runs
|
|
111
|
+
* once; every entry point that needs a built server awaits it, and a failed
|
|
112
|
+
* attempt is retried on the next call.
|
|
113
|
+
*
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
ready(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
119
|
+
* custom routes, middleware, or settings — e.g.
|
|
120
|
+
* `app.express.get("/health", ...)`.
|
|
121
|
+
*
|
|
122
|
+
* `express.json()` is pre-applied — tune it via the `json` config field,
|
|
123
|
+
* e.g. `new Skybridge({ name, version, json: { limit: "10mb" }, handler })`.
|
|
124
|
+
* Register your handlers before `run()`; after `run()`, dev-mode middleware,
|
|
125
|
+
* the `/mcp` route, and the default error handler are appended in that order.
|
|
126
|
+
*
|
|
127
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
128
|
+
* locally and on self-hosted deployments.
|
|
129
|
+
*/
|
|
130
|
+
get express(): Express;
|
|
131
|
+
/**
|
|
132
|
+
* Build a fresh server for one stateless HTTP request, as
|
|
133
|
+
* `createMcpHandler`'s factory contract requires: the handler runs again so
|
|
134
|
+
* the SDK's handler closures belong to the instance whose protocol era it
|
|
135
|
+
* stamps. Sharing one instance's handler maps instead would bind them to an
|
|
136
|
+
* instance that is never marked, pinning every request to the 2025 codec and
|
|
137
|
+
* letting concurrent callers overwrite each other's negotiated version.
|
|
138
|
+
*
|
|
139
|
+
* Awaits `setup` and the `oauth` input on first use.
|
|
140
|
+
*/
|
|
141
|
+
createServerInstance(): Promise<SdkServer>;
|
|
142
|
+
/**
|
|
143
|
+
* Connect a Skybridge app to an MCP transport. Use this when you're
|
|
144
|
+
* embedding Skybridge in a host that already manages its own transport
|
|
145
|
+
* (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}
|
|
146
|
+
* which sets the transport up for you.
|
|
147
|
+
*/
|
|
148
|
+
connect(transport: Parameters<SdkServer["connect"]>[0]): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Register Express middleware on the underlying app. Mirrors `app.use` —
|
|
151
|
+
* pass handlers directly or a path-prefixed handler list. Register before
|
|
152
|
+
* {@link Skybridge.run}; ordering matches Express.
|
|
153
|
+
*
|
|
154
|
+
* Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work
|
|
155
|
+
* locally and on self-hosted deployments.
|
|
156
|
+
*/
|
|
157
|
+
use(...handlers: RequestHandler[]): this;
|
|
158
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
159
|
+
/**
|
|
160
|
+
* Register Express error-handling middleware to run after the built-in
|
|
161
|
+
* `/mcp` route (or your custom route). Use this to log or transform errors
|
|
162
|
+
* thrown by tool handlers before the default error handler responds.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* app.useOnError((err, _req, _res, next) => {
|
|
167
|
+
* logger.error(err);
|
|
168
|
+
* next(err);
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
173
|
+
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
174
|
+
/**
|
|
175
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
176
|
+
* mounts the `/mcp` route, and applies any custom Express middleware
|
|
177
|
+
* registered via {@link Skybridge.use} / {@link Skybridge.useOnError}.
|
|
178
|
+
*
|
|
179
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
180
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
181
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
182
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
183
|
+
* Node, returns `undefined` once listening. When the process was spawned
|
|
184
|
+
* with an IPC channel, the bound port is reported to the parent as
|
|
185
|
+
* `{ type: "skybridge:listening", port }`, the readiness signal test runners
|
|
186
|
+
* wait on instead of polling.
|
|
187
|
+
*/
|
|
188
|
+
run(): Promise<{
|
|
189
|
+
fetch: (...args: unknown[]) => unknown;
|
|
190
|
+
} | Express | undefined>;
|
|
191
|
+
private buildServer;
|
|
192
|
+
private middlewareEntries;
|
|
193
|
+
private instrumentHandlers;
|
|
194
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
3
|
+
import { buildMcpHandler, createApp, createBaseApp } from "./express.js";
|
|
4
|
+
import { createMiddlewareEntry } from "./metric.js";
|
|
5
|
+
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
6
|
+
import { McpServer, } from "./server.js";
|
|
7
|
+
const SLOW_HANDLER_THRESHOLD_MS = 50;
|
|
8
|
+
async function resolveOAuthInput(input, config) {
|
|
9
|
+
const resolved = typeof input === "function" ? input(config) : input;
|
|
10
|
+
return resolved && "resolve" in resolved
|
|
11
|
+
? await resolved.resolve()
|
|
12
|
+
: resolved;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`
|
|
16
|
+
* route) plus a handler that builds the MCP server for each request.
|
|
17
|
+
*
|
|
18
|
+
* The handler runs for every request, so tools, resources, prompts and views
|
|
19
|
+
* are always registered on the instance that serves the request. Anything in
|
|
20
|
+
* the handler body other than registration therefore runs per request too.
|
|
21
|
+
* Anything asynchronous the app needs (remote config, secrets, …) goes in
|
|
22
|
+
* `setup`, which runs once and feeds the handler's second argument.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* export const app = new Skybridge({
|
|
27
|
+
* name: "my-app",
|
|
28
|
+
* version: "1.0.0",
|
|
29
|
+
* setup: async () => loadConfig(),
|
|
30
|
+
* oauth: (config) => descopeProvider({ url: config.mcpServerUrl }),
|
|
31
|
+
* handler: (server, config) =>
|
|
32
|
+
* server.registerTool(
|
|
33
|
+
* {
|
|
34
|
+
* name: "search",
|
|
35
|
+
* inputSchema: { query: z.string() },
|
|
36
|
+
* view: { component: "search" },
|
|
37
|
+
* },
|
|
38
|
+
* async ({ query }) => ({ content: `Results for ${query}` }),
|
|
39
|
+
* ),
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* export type AppType = typeof app;
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
46
|
+
*/
|
|
47
|
+
export class Skybridge {
|
|
48
|
+
serverInfo;
|
|
49
|
+
serverOptions;
|
|
50
|
+
skills;
|
|
51
|
+
oauthEnabled = false;
|
|
52
|
+
handler;
|
|
53
|
+
setup;
|
|
54
|
+
oauthInput;
|
|
55
|
+
config;
|
|
56
|
+
expressApp;
|
|
57
|
+
errorMiddleware = [];
|
|
58
|
+
monitoringEntry = createMiddlewareEntry();
|
|
59
|
+
resolveResourceMetadataUrl;
|
|
60
|
+
readyPromise;
|
|
61
|
+
slowHandlerWarned = false;
|
|
62
|
+
constructor({ name, title, version, description, icons, websiteUrl, json, skills, setup, oauth, handler, ...serverOptions }) {
|
|
63
|
+
this.serverInfo = { name, title, version, description, icons, websiteUrl };
|
|
64
|
+
this.serverOptions = serverOptions;
|
|
65
|
+
this.skills = skills;
|
|
66
|
+
this.setup = setup;
|
|
67
|
+
this.oauthInput = oauth;
|
|
68
|
+
this.handler = handler;
|
|
69
|
+
this.expressApp = createBaseApp(json);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolve `setup` and `oauth`, then wire OAuth onto the Express app. Runs
|
|
73
|
+
* once; every entry point that needs a built server awaits it, and a failed
|
|
74
|
+
* attempt is retried on the next call.
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
ready() {
|
|
79
|
+
this.readyPromise ??= (async () => {
|
|
80
|
+
if (this.setup) {
|
|
81
|
+
this.config = await this.setup();
|
|
82
|
+
}
|
|
83
|
+
const oauth = await resolveOAuthInput(this.oauthInput, this.config);
|
|
84
|
+
this.oauthEnabled = Boolean(oauth);
|
|
85
|
+
const sample = this.buildServer();
|
|
86
|
+
if (oauth) {
|
|
87
|
+
this.resolveResourceMetadataUrl = setupOAuth(this.expressApp, oauth, sample.securitySchemesByTool);
|
|
88
|
+
}
|
|
89
|
+
})().catch((error) => {
|
|
90
|
+
this.readyPromise = undefined;
|
|
91
|
+
throw error;
|
|
92
|
+
});
|
|
93
|
+
return this.readyPromise;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
97
|
+
* custom routes, middleware, or settings — e.g.
|
|
98
|
+
* `app.express.get("/health", ...)`.
|
|
99
|
+
*
|
|
100
|
+
* `express.json()` is pre-applied — tune it via the `json` config field,
|
|
101
|
+
* e.g. `new Skybridge({ name, version, json: { limit: "10mb" }, handler })`.
|
|
102
|
+
* Register your handlers before `run()`; after `run()`, dev-mode middleware,
|
|
103
|
+
* the `/mcp` route, and the default error handler are appended in that order.
|
|
104
|
+
*
|
|
105
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
106
|
+
* locally and on self-hosted deployments.
|
|
107
|
+
*/
|
|
108
|
+
get express() {
|
|
109
|
+
return this.expressApp;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Build a fresh server for one stateless HTTP request, as
|
|
113
|
+
* `createMcpHandler`'s factory contract requires: the handler runs again so
|
|
114
|
+
* the SDK's handler closures belong to the instance whose protocol era it
|
|
115
|
+
* stamps. Sharing one instance's handler maps instead would bind them to an
|
|
116
|
+
* instance that is never marked, pinning every request to the 2025 codec and
|
|
117
|
+
* letting concurrent callers overwrite each other's negotiated version.
|
|
118
|
+
*
|
|
119
|
+
* Awaits `setup` and the `oauth` input on first use.
|
|
120
|
+
*/
|
|
121
|
+
async createServerInstance() {
|
|
122
|
+
await this.ready();
|
|
123
|
+
const server = this.buildServer();
|
|
124
|
+
this.instrumentHandlers(server);
|
|
125
|
+
return server.server;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Connect a Skybridge app to an MCP transport. Use this when you're
|
|
129
|
+
* embedding Skybridge in a host that already manages its own transport
|
|
130
|
+
* (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}
|
|
131
|
+
* which sets the transport up for you.
|
|
132
|
+
*/
|
|
133
|
+
async connect(transport) {
|
|
134
|
+
const instance = await this.createServerInstance();
|
|
135
|
+
await instance.connect(transport);
|
|
136
|
+
}
|
|
137
|
+
use(pathOrHandler, ...handlers) {
|
|
138
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
139
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
140
|
+
if (typeof pathOrHandler === "string") {
|
|
141
|
+
this.expressApp.use(pathOrHandler, ...handlers);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.expressApp.use(pathOrHandler, ...handlers);
|
|
145
|
+
}
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
useOnError(pathOrHandler, ...handlers) {
|
|
149
|
+
if (typeof pathOrHandler === "string") {
|
|
150
|
+
this.errorMiddleware.push({ path: pathOrHandler, handlers });
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.errorMiddleware.push({ handlers: [pathOrHandler, ...handlers] });
|
|
154
|
+
}
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
159
|
+
* mounts the `/mcp` route, and applies any custom Express middleware
|
|
160
|
+
* registered via {@link Skybridge.use} / {@link Skybridge.useOnError}.
|
|
161
|
+
*
|
|
162
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
163
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
164
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
165
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
166
|
+
* Node, returns `undefined` once listening. When the process was spawned
|
|
167
|
+
* with an IPC channel, the bound port is reported to the parent as
|
|
168
|
+
* `{ type: "skybridge:listening", port }`, the readiness signal test runners
|
|
169
|
+
* wait on instead of polling.
|
|
170
|
+
*/
|
|
171
|
+
async run() {
|
|
172
|
+
if (process.env.VERCEL === "1") {
|
|
173
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
174
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
175
|
+
// bare object passed to satisfy the required parameter.
|
|
176
|
+
const httpServer = http.createServer();
|
|
177
|
+
await createApp({
|
|
178
|
+
app: this,
|
|
179
|
+
httpServer,
|
|
180
|
+
errorMiddleware: this.errorMiddleware,
|
|
181
|
+
});
|
|
182
|
+
return this.expressApp;
|
|
183
|
+
}
|
|
184
|
+
const httpServer = http.createServer();
|
|
185
|
+
const mcpHandler = buildMcpHandler(this);
|
|
186
|
+
await createApp({
|
|
187
|
+
app: this,
|
|
188
|
+
httpServer,
|
|
189
|
+
mcpHandler,
|
|
190
|
+
errorMiddleware: this.errorMiddleware,
|
|
191
|
+
});
|
|
192
|
+
httpServer.on("request", this.expressApp);
|
|
193
|
+
const intendedPort = parseInt(process.env.__PORT ?? "3000", 10);
|
|
194
|
+
await new Promise((resolve, reject) => {
|
|
195
|
+
httpServer.on("error", (error) => {
|
|
196
|
+
console.error("Failed to start server:", error);
|
|
197
|
+
reject(error);
|
|
198
|
+
});
|
|
199
|
+
httpServer.listen(intendedPort, () => {
|
|
200
|
+
resolve();
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
const { port } = httpServer.address();
|
|
204
|
+
process.send?.({ type: "skybridge:listening", port });
|
|
205
|
+
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
206
|
+
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
207
|
+
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
208
|
+
if (typeof navigator !== "undefined" &&
|
|
209
|
+
navigator.userAgent === "Cloudflare-Workers") {
|
|
210
|
+
const cloudflareNode = "cloudflare:node";
|
|
211
|
+
const { httpServerHandler } = await import(cloudflareNode);
|
|
212
|
+
return httpServerHandler({ port });
|
|
213
|
+
}
|
|
214
|
+
const shutdown = () => {
|
|
215
|
+
// Drop both handlers so a second signal falls through to Node's default
|
|
216
|
+
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
217
|
+
process.off("SIGTERM", shutdown);
|
|
218
|
+
process.off("SIGINT", shutdown);
|
|
219
|
+
mcpHandler.close().catch(() => { });
|
|
220
|
+
httpServer.close(() => process.exit(0));
|
|
221
|
+
// Force exit if connections don't drain in time so the port is still
|
|
222
|
+
// released promptly (e.g. for nodemon restarts).
|
|
223
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
224
|
+
};
|
|
225
|
+
process.on("SIGTERM", shutdown);
|
|
226
|
+
process.on("SIGINT", shutdown);
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
buildServer() {
|
|
230
|
+
const server = new McpServer(this.serverInfo, this.serverOptions, { skills: this.skills, oauth: this.oauthEnabled });
|
|
231
|
+
if (this.resolveResourceMetadataUrl) {
|
|
232
|
+
server.setResourceMetadataUrlResolver(this.resolveResourceMetadataUrl);
|
|
233
|
+
}
|
|
234
|
+
const startedAt = performance.now();
|
|
235
|
+
const built = this.handler(server, this.config);
|
|
236
|
+
const elapsed = performance.now() - startedAt;
|
|
237
|
+
if (typeof built.then === "function") {
|
|
238
|
+
throw new Error("The Skybridge handler must be synchronous — it runs on every request. Load config or secrets in `setup` instead and read them from the handler's second argument.");
|
|
239
|
+
}
|
|
240
|
+
if (elapsed > SLOW_HANDLER_THRESHOLD_MS && !this.slowHandlerWarned) {
|
|
241
|
+
this.slowHandlerWarned = true;
|
|
242
|
+
console.warn(`The Skybridge handler took ${Math.round(elapsed)}ms — it runs on every request, so this cost is paid per request. Move expensive work into \`setup\`, whose result is passed to the handler.`);
|
|
243
|
+
}
|
|
244
|
+
return built;
|
|
245
|
+
}
|
|
246
|
+
middlewareEntries(server) {
|
|
247
|
+
return [
|
|
248
|
+
...(this.monitoringEntry ? [this.monitoringEntry] : []),
|
|
249
|
+
...server.protocolMiddlewareEntries(),
|
|
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;AAS7B,OAAO,EAAoC,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,cAA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ACtC,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 type {\n Implementation,\n Server as SdkServer,\n ServerOptions,\n} from \"@modelcontextprotocol/server\";\nimport type { ErrorRequestHandler, Express, RequestHandler } from \"express\";\nimport type { OAuthConfig, OAuthProvider } from \"./auth/index.js\";\nimport { type ResourceMetadataUrlResolver, setupOAuth } from \"./auth/setup.js\";\nimport type { ExtraClaims } from \"./auth.js\";\nimport { buildMcpHandler, createApp, createBaseApp } from \"./express.js\";\nimport { createMiddlewareEntry } from \"./metric.js\";\nimport type { McpMiddlewareEntry } from \"./middleware.js\";\nimport { buildMiddlewareChain, getHandlerMaps } from \"./middleware.js\";\nimport {\n type JsonOptions,\n McpServer,\n type McpServerTypes,\n type ToolDef,\n} from \"./server.js\";\n\nconst SLOW_HANDLER_THRESHOLD_MS = 50;\n\ntype ErrorMiddlewareConfig = {\n path?: string;\n handlers: ErrorRequestHandler[];\n};\n\n/**\n * The `handler` field of {@link SkybridgeConfig}: builds the app's MCP\n * surface. Runs again for **every incoming request**, on a fresh\n * {@link McpServer}, so keep it to registration: pools, clients and any other\n * one-time work belong in `setup`, whose result is the second argument. It\n * must **return** the chained server so `typeof app` carries the registered\n * tool types.\n *\n * @typeParam TConfig - What `setup` resolved to, passed as the second argument.\n */\nexport type SkybridgeHandler<\n TTools extends Record<string, ToolDef>,\n TConfig,\n TAuthExtra extends ExtraClaims,\n> = (\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n config: TConfig,\n) => McpServer<TTools, TAuthExtra>;\n\n/**\n * What the `oauth` field accepts: an {@link OAuthConfig}, a provider\n * (`oauth: auth0Provider(...)`), or a function of the `setup` result returning\n * either. Providers and functions resolve once, at {@link Skybridge.run} or on\n * the first request, never at module import. Anything asynchronous belongs in\n * a provider's `resolve`.\n */\nexport type SkybridgeOAuthInput<TConfig, TExtra extends ExtraClaims> =\n | OAuthConfig<TExtra>\n | OAuthProvider<TExtra>\n | ((config: TConfig) => OAuthConfig<TExtra> | OAuthProvider<TExtra>);\n\nasync function resolveOAuthInput<TConfig, TExtra extends ExtraClaims>(\n input: SkybridgeOAuthInput<TConfig, TExtra> | undefined,\n config: TConfig,\n): Promise<OAuthConfig<TExtra> | undefined> {\n const resolved = typeof input === \"function\" ? input(config) : input;\n return resolved && \"resolve\" in resolved\n ? await resolved.resolve()\n : resolved;\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`, …), the Express and skills options, and the app's behavior\n * (`setup`, `oauth`, `handler`).\n *\n * All type parameters are inferred from the value: the config from `setup`,\n * the auth claims from `oauth`, and the tool registry from the server\n * `handler` returns.\n */\nexport type SkybridgeConfig<\n TTools extends Record<string, ToolDef> = Record<never, ToolDef>,\n TConfig = undefined,\n TAuthExtra extends ExtraClaims = ExtraClaims,\n> = Implementation &\n ServerOptions & {\n /** Options for the built-in `express.json()` middleware, e.g. `{ limit: \"10mb\" }`. */\n json?: JsonOptions;\n /**\n * @experimental Serve Agent Skills from `src/skills` over MCP (SEP-2640).\n * API may change.\n */\n skills?: boolean;\n /**\n * Loads whatever the app needs up front (remote config, secrets, datasets,\n * …). Runs **once** — at {@link Skybridge.run} or on the first request,\n * never at module import — and its awaited return value is passed to an\n * `oauth` function and to `handler` as the second argument.\n */\n setup?: () => TConfig;\n /**\n * Resource-server OAuth. When set, mounts the well-known metadata routes\n * and bearer auth on `/mcp`, and the verifier's claims type\n * `extra.http.authInfo.extra` in tool handlers.\n */\n oauth?: SkybridgeOAuthInput<Awaited<TConfig>, TAuthExtra>;\n /** Registers the MCP surface, per request. See {@link SkybridgeHandler}. */\n handler: SkybridgeHandler<TTools, Awaited<TConfig>, TAuthExtra>;\n };\n\n/**\n * A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`\n * route) plus a handler that builds the MCP server for each request.\n *\n * The handler runs for every request, so tools, resources, prompts and views\n * are always registered on the instance that serves the request. Anything in\n * the handler body other than registration therefore runs per request too.\n * Anything asynchronous the app needs (remote config, secrets, …) goes in\n * `setup`, which runs once and feeds the handler's second argument.\n *\n * @example\n * ```ts\n * export const app = new Skybridge({\n * name: \"my-app\",\n * version: \"1.0.0\",\n * setup: async () => loadConfig(),\n * oauth: (config) => descopeProvider({ url: config.mcpServerUrl }),\n * handler: (server, config) =>\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 TConfig = undefined,\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 skills?: boolean;\n private oauthEnabled = false;\n private readonly handler: SkybridgeHandler<\n TTools,\n Awaited<TConfig>,\n TAuthExtra\n >;\n private readonly setup?: () => TConfig;\n private readonly oauthInput?: SkybridgeOAuthInput<\n Awaited<TConfig>,\n TAuthExtra\n >;\n private config?: Awaited<TConfig>;\n private readonly expressApp: Express;\n private readonly errorMiddleware: ErrorMiddlewareConfig[] = [];\n private readonly monitoringEntry: McpMiddlewareEntry | null =\n createMiddlewareEntry();\n private resolveResourceMetadataUrl?: ResourceMetadataUrlResolver;\n private readyPromise?: Promise<void>;\n private slowHandlerWarned = false;\n\n constructor({\n name,\n title,\n version,\n description,\n icons,\n websiteUrl,\n json,\n skills,\n setup,\n oauth,\n handler,\n ...serverOptions\n }: SkybridgeConfig<TTools, TConfig, TAuthExtra>) {\n this.serverInfo = { name, title, version, description, icons, websiteUrl };\n this.serverOptions = serverOptions;\n this.skills = skills;\n this.setup = setup;\n this.oauthInput = oauth;\n this.handler = handler;\n this.expressApp = createBaseApp(json);\n }\n\n /**\n * Resolve `setup` and `oauth`, then wire OAuth onto the Express app. Runs\n * once; every entry point that needs a built server awaits it, and a failed\n * attempt is retried on the next call.\n *\n * @internal\n */\n ready(): Promise<void> {\n this.readyPromise ??= (async () => {\n if (this.setup) {\n this.config = await this.setup();\n }\n const oauth = await resolveOAuthInput(\n this.oauthInput,\n this.config as Awaited<TConfig>,\n );\n this.oauthEnabled = Boolean(oauth);\n const sample = this.buildServer();\n if (oauth) {\n this.resolveResourceMetadataUrl = setupOAuth(\n this.expressApp,\n oauth,\n sample.securitySchemesByTool,\n );\n }\n })().catch((error) => {\n this.readyPromise = undefined;\n throw error;\n });\n return this.readyPromise;\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\" }, handler })`.\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 * Build a fresh server for one stateless HTTP request, as\n * `createMcpHandler`'s factory contract requires: the handler 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 * Awaits `setup` and the `oauth` input on first use.\n */\n async createServerInstance(): Promise<SdkServer> {\n await this.ready();\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.\n */\n async connect(transport: Parameters<SdkServer[\"connect\"]>[0]): Promise<void> {\n const instance = await this.createServerInstance();\n await instance.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 /**\n * Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),\n * mounts the `/mcp` route, and applies any custom Express middleware\n * registered via {@link Skybridge.use} / {@link Skybridge.useOnError}.\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 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 const mcpHandler = buildMcpHandler(this);\n\n await createApp({\n app: this,\n httpServer,\n mcpHandler,\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 mcpHandler.close().catch(() => {});\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 { skills: this.skills, oauth: this.oauthEnabled },\n );\n if (this.resolveResourceMetadataUrl) {\n server.setResourceMetadataUrlResolver(this.resolveResourceMetadataUrl);\n }\n const startedAt = performance.now();\n const built = this.handler(server, this.config as Awaited<TConfig>);\n const elapsed = performance.now() - startedAt;\n if (typeof (built as { then?: unknown }).then === \"function\") {\n throw new Error(\n \"The Skybridge handler must be synchronous — it runs on every request. Load config or secrets in `setup` instead and read them from the handler's second argument.\",\n );\n }\n if (elapsed > SLOW_HANDLER_THRESHOLD_MS && !this.slowHandlerWarned) {\n this.slowHandlerWarned = true;\n console.warn(\n `The Skybridge handler took ${Math.round(elapsed)}ms — it runs on every request, so this cost is paid per request. Move expensive work into \\`setup\\`, whose result is passed to the handler.`,\n );\n }\n return built;\n }\n\n private middlewareEntries(\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n ): McpMiddlewareEntry[] {\n return [\n ...(this.monitoringEntry ? [this.monitoringEntry] : []),\n ...server.protocolMiddlewareEntries(),\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,97 @@
|
|
|
1
|
+
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { Skybridge } from "./app.js";
|
|
4
|
+
const oauthConfig = {
|
|
5
|
+
oauthMetadata: {
|
|
6
|
+
issuer: "https://issuer.example.com",
|
|
7
|
+
authorization_endpoint: "https://issuer.example.com/authorize",
|
|
8
|
+
token_endpoint: "https://issuer.example.com/token",
|
|
9
|
+
response_types_supported: ["code"],
|
|
10
|
+
},
|
|
11
|
+
verifier: {
|
|
12
|
+
verifyAccessToken: async () => ({
|
|
13
|
+
token: "t",
|
|
14
|
+
clientId: "c",
|
|
15
|
+
scopes: [],
|
|
16
|
+
extra: {},
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
describe("Skybridge setup and handler", () => {
|
|
21
|
+
it("resolves setup once and passes the context to the per-request handler", async () => {
|
|
22
|
+
let loads = 0;
|
|
23
|
+
const app = new Skybridge({
|
|
24
|
+
name: "test",
|
|
25
|
+
version: "1.0.0",
|
|
26
|
+
setup: async () => {
|
|
27
|
+
loads++;
|
|
28
|
+
return { greeting: await Promise.resolve("hello") };
|
|
29
|
+
},
|
|
30
|
+
handler: (server, { greeting }) => server.registerTool({ name: "greet", description: "greet" }, async () => ({ content: [{ type: "text", text: greeting }] })),
|
|
31
|
+
});
|
|
32
|
+
expect(loads).toBe(0);
|
|
33
|
+
const call = async () => {
|
|
34
|
+
const client = new Client({ name: "client", version: "1.0.0" });
|
|
35
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
36
|
+
await app.connect(serverTransport);
|
|
37
|
+
await client.connect(clientTransport);
|
|
38
|
+
const result = await client.callTool({ name: "greet" });
|
|
39
|
+
await client.close();
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
expect(await call()).toMatchObject({
|
|
43
|
+
content: [{ type: "text", text: "hello" }],
|
|
44
|
+
});
|
|
45
|
+
expect(await call()).toMatchObject({
|
|
46
|
+
content: [{ type: "text", text: "hello" }],
|
|
47
|
+
});
|
|
48
|
+
expect(loads).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
it("retries setup after a failed first resolution", async () => {
|
|
51
|
+
let attempts = 0;
|
|
52
|
+
const app = new Skybridge({
|
|
53
|
+
name: "test",
|
|
54
|
+
version: "1.0.0",
|
|
55
|
+
setup: async () => {
|
|
56
|
+
attempts++;
|
|
57
|
+
if (attempts === 1) {
|
|
58
|
+
throw new Error("transient");
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
handler: (server) => server,
|
|
62
|
+
});
|
|
63
|
+
const [, first] = InMemoryTransport.createLinkedPair();
|
|
64
|
+
await expect(app.connect(first)).rejects.toThrow("transient");
|
|
65
|
+
const [, second] = InMemoryTransport.createLinkedPair();
|
|
66
|
+
await expect(app.connect(second)).resolves.toBeUndefined();
|
|
67
|
+
expect(attempts).toBe(2);
|
|
68
|
+
});
|
|
69
|
+
it("rejects a handler that returns a promise", async () => {
|
|
70
|
+
const app = new Skybridge({
|
|
71
|
+
name: "test",
|
|
72
|
+
version: "1.0.0",
|
|
73
|
+
// @ts-expect-error the handler runs per request and must stay synchronous
|
|
74
|
+
handler: async (server) => server,
|
|
75
|
+
});
|
|
76
|
+
const [, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
77
|
+
await expect(app.connect(serverTransport)).rejects.toThrow(/must be synchronous/);
|
|
78
|
+
});
|
|
79
|
+
it("resolves an oauth function with the setup config before wiring the routes", async () => {
|
|
80
|
+
let seen;
|
|
81
|
+
const app = new Skybridge({
|
|
82
|
+
name: "test",
|
|
83
|
+
version: "1.0.0",
|
|
84
|
+
setup: () => ({ issuer: "https://issuer.example.com" }),
|
|
85
|
+
oauth: (config) => {
|
|
86
|
+
seen = config;
|
|
87
|
+
return oauthConfig;
|
|
88
|
+
},
|
|
89
|
+
handler: (server) => server,
|
|
90
|
+
});
|
|
91
|
+
expect(seen).toBeUndefined();
|
|
92
|
+
const [, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
93
|
+
await app.connect(serverTransport);
|
|
94
|
+
expect(seen).toEqual({ issuer: "https://issuer.example.com" });
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=app.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.test.js","sourceRoot":"","sources":["../../src/server/app.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,WAAW,GAAG;IAClB,aAAa,EAAE;QACb,MAAM,EAAE,4BAA4B;QACpC,sBAAsB,EAAE,sCAAsC;QAC9D,cAAc,EAAE,kCAAkC;QAClD,wBAAwB,EAAE,CAAC,MAAM,CAAC;KACnC;IACD,QAAQ,EAAE;QACR,iBAAiB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YAC9B,KAAK,EAAE,GAAG;YACV,QAAQ,EAAE,GAAG;YACb,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;SACV,CAAC;KACH;CACF,CAAC;AAEF,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;QACrF,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC;YACxB,IAAI,EAAE,M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,GAAG,GAAG,IAAI,SAAS,CAAC;YACxB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO;YAChB,0EAA0E;YAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM;SAClC,CAAC,CAAC;QACH,MAAM,CAAC,EAAE,eAAe,CAAC,GAAG,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;QACjE,MAAM,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACxD,qBAAqB,CACtB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2EAA2E,EAAE,KAAK,IAAI,EAAE;QACzF,IAAI,IAAa,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC;YACxB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO;YAChB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,4BAA4B,EAAE,CAAC;YACvD,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE;gBAChB,IAAI,GAAG,MAAM,CAAC;gBACd,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;SAC5B,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;QAC7B,MAAM,CAAC,EAAE,eAAe,CAAC,GAAG,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;QACjE,MAAM,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,4BAA4B,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Client, InMemoryTransport } from \"@modelcontextprotocol/client\";\nimport { describe, expect, it } from \"vitest\";\nimport { Skybridge } from \"./app.js\";\n\nconst oauthConfig = {\n oauthMetadata: {\n issuer: \"https://issuer.example.com\",\n authorization_endpoint: \"https://issuer.example.com/authorize\",\n token_endpoint: \"https://issuer.example.com/token\",\n response_types_supported: [\"code\"],\n },\n verifier: {\n verifyAccessToken: async () => ({\n token: \"t\",\n clientId: \"c\",\n scopes: [],\n extra: {},\n }),\n },\n};\n\ndescribe(\"Skybridge setup and handler\", () => {\n it(\"resolves setup once and passes the context to the per-request handler\", async () => {\n let loads = 0;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: async () => {\n loads++;\n return { greeting: await Promise.resolve(\"hello\") };\n },\n handler: (server, { greeting }) =>\n server.registerTool(\n { name: \"greet\", description: \"greet\" },\n async () => ({ content: [{ type: \"text\", text: greeting }] }),\n ),\n });\n\n expect(loads).toBe(0);\n\n const call = async () => {\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await app.connect(serverTransport);\n await client.connect(clientTransport);\n const result = await client.callTool({ name: \"greet\" });\n await client.close();\n return result;\n };\n\n expect(await call()).toMatchObject({\n content: [{ type: \"text\", text: \"hello\" }],\n });\n expect(await call()).toMatchObject({\n content: [{ type: \"text\", text: \"hello\" }],\n });\n expect(loads).toBe(1);\n });\n\n it(\"retries setup after a failed first resolution\", async () => {\n let attempts = 0;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: async () => {\n attempts++;\n if (attempts === 1) {\n throw new Error(\"transient\");\n }\n },\n handler: (server) => server,\n });\n\n const [, first] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(first)).rejects.toThrow(\"transient\");\n\n const [, second] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(second)).resolves.toBeUndefined();\n expect(attempts).toBe(2);\n });\n\n it(\"rejects a handler that returns a promise\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n // @ts-expect-error the handler runs per request and must stay synchronous\n handler: async (server) => server,\n });\n const [, serverTransport] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(serverTransport)).rejects.toThrow(\n /must be synchronous/,\n );\n });\n\n it(\"resolves an oauth function with the setup config before wiring the routes\", async () => {\n let seen: unknown;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: () => ({ issuer: \"https://issuer.example.com\" }),\n oauth: (config) => {\n seen = config;\n return oauthConfig;\n },\n handler: (server) => server,\n });\n\n expect(seen).toBeUndefined();\n const [, serverTransport] = InMemoryTransport.createLinkedPair();\n await app.connect(serverTransport);\n expect(seen).toEqual({ issuer: \"https://issuer.example.com\" });\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;
|