skybridge 0.0.0-dev.aa91bd6 → 0.0.0-dev.aac44d3
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 +10 -7
- 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 +2 -2
- package/dist/cli/detect-port.js +8 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/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-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +90 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/telemetry.js +2 -0
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +25 -1
- package/dist/cli/use-nodemon.js +96 -63
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +70 -67
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +2 -73
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +51 -3
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/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/auth/discovery.d.ts +33 -0
- package/dist/server/auth/discovery.js +56 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +48 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +40 -0
- package/dist/server/auth/providers/auth0.js +36 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +50 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +143 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +51 -0
- package/dist/server/auth/providers/clerk.js +19 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +30 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +42 -0
- package/dist/server/auth/providers/custom.js +59 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +161 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +44 -0
- package/dist/server/auth/providers/descope.js +44 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +62 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +25 -0
- package/dist/server/auth/providers/stytch.js +16 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +34 -0
- package/dist/server/auth/providers/workos.js +16 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +6 -0
- package/dist/server/auth/setup.js +91 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +514 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +48 -0
- package/dist/server/auth/verify.js +62 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +165 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth-extra.test-d.js +130 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +43 -6
- package/dist/server/auth.js +4 -5
- package/dist/server/auth.js.map +1 -1
- 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 +1 -1
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.d.ts +23 -3
- package/dist/server/express.js +38 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +268 -90
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +1 -1
- package/dist/server/file-ref.js +1 -1
- package/dist/server/file-ref.js.map +1 -1
- 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 +17 -3
- package/dist/server/index.js +14 -2
- package/dist/server/index.js.map +1 -1
- 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/middleware.d.ts +35 -10
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +242 -134
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +110 -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 +257 -122
- package/dist/server/server.js +390 -330
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +86 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +27 -0
- package/dist/server/skills.js +188 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +243 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/templateHelper.d.ts +0 -3
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js +4 -8
- package/dist/server/templates.generated.js.map +1 -1
- 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/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +176 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +9 -11
- package/dist/test/utils.js +220 -201
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +105 -133
- package/dist/test/view.test.js.map +1 -1
- package/dist/views/index.d.ts +10 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/{web/plugin → views}/scan-views.js +1 -1
- 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.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/{web/plugin → views}/validate-view.js +2 -2
- package/dist/views/validate-view.js.map +1 -0
- package/dist/views/validate-view.test.d.ts +1 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +56 -0
- package/dist/web/bridges/adaptor.js +397 -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 +264 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
- package/dist/web/bridges/apps-sdk/bridge.js +15 -4
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +4 -4
- package/dist/web/bridges/get-adaptor.js +6 -11
- 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/mcp-app/bridge.d.ts +15 -3
- package/dist/web/bridges/mcp-app/bridge.js +80 -8
- 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 +25 -2
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +83 -9
- 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/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.test.js +10 -7
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +1 -1
- package/dist/web/data-llm.js +3 -2
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +26 -7
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +23 -19
- package/dist/web/generate-helpers.js +21 -17
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +7 -5
- 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/hooks/index.d.ts +6 -1
- package/dist/web/hooks/index.js +6 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
- package/dist/web/hooks/openai-extensions.test.js +114 -0
- package/dist/web/hooks/openai-extensions.test.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +2 -1
- package/dist/web/hooks/test/utils.js +1 -1
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +2 -2
- package/dist/web/hooks/use-call-tool.js +15 -10
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +50 -25
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-deep-link.d.ts +22 -0
- package/dist/web/hooks/use-deep-link.js +59 -0
- package/dist/web/hooks/use-deep-link.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +1 -1
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +57 -21
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +1 -3
- package/dist/web/hooks/use-download.js +1 -2
- package/dist/web/hooks/use-download.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +18 -10
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +11 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +44 -0
- package/dist/web/hooks/use-host.js +45 -0
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/use-host.test.js +59 -0
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-model-context.d.ts +44 -0
- package/dist/web/hooks/use-model-context.js +62 -0
- package/dist/web/hooks/use-model-context.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +15 -5
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-open-file.d.ts +19 -0
- package/dist/web/hooks/use-open-file.js +24 -0
- package/dist/web/hooks/use-open-file.js.map +1 -0
- package/dist/web/hooks/use-register-view-tool.d.ts +37 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +11 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +1 -1
- package/dist/web/hooks/use-request-size.js +1 -1
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-send-follow-up-message.d.ts +8 -2
- package/dist/web/hooks/use-send-follow-up-message.js +6 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +26 -12
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +18 -19
- package/dist/web/hooks/use-tool-info.js +4 -8
- 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 +3 -2
- package/dist/web/hooks/use-user.js +4 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +85 -37
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +39 -4
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- 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/mount-view.d.ts +3 -2
- package/dist/web/mount-view.js +5 -8
- package/dist/web/mount-view.js.map +1 -1
- package/package.json +32 -26
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -28
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -113
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -52
- package/dist/web/bridges/mcp-app/adaptor.js +0 -280
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -24
- package/dist/web/hooks/use-layout.js +0 -25
- 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/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 -33
- package/dist/web/plugin/plugin.js +0 -189
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/scan-views.js.map +0 -1
- package/dist/web/plugin/scan-views.test.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.d.ts +0 -12
- package/dist/web/plugin/transform-data-llm.js +0 -96
- package/dist/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.test.js +0 -81
- package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/web/plugin/validate-view.d.ts +0 -1
- package/dist/web/plugin/validate-view.js.map +0 -1
- package/dist/web/plugin/validate-view.test.js.map +0 -1
- /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
- /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
- /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
package/dist/server/server.js
CHANGED
|
@@ -1,22 +1,54 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import http from "node:http";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
4
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/server";
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
|
+
import { warnOnLargeToolOutput } from "../context-warnings.js";
|
|
7
|
+
import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
8
|
+
import { hostFromUserAgent } from "./host.js";
|
|
9
|
+
import { captureToolError } from "./middleware.js";
|
|
10
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
11
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
12
12
|
import { templateHelper } from "./templateHelper.js";
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
13
|
+
const unionOf = (base, extra) => extra ? [...new Set([...base, ...extra])] : base;
|
|
14
|
+
function mergeOpenAIUi(meta, values) {
|
|
15
|
+
const defined = Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
|
|
16
|
+
if (Object.keys(defined).length > 0) {
|
|
17
|
+
meta["openai/ui"] = { ...meta["openai/ui"], ...defined };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function acceptsEmptyInput(inputSchema) {
|
|
21
|
+
if (inputSchema === undefined) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const checks = "~standard" in inputSchema
|
|
25
|
+
? [inputSchema["~standard"].validate({})]
|
|
26
|
+
: Object.values(inputSchema).map((schema) => schema["~standard"].validate(undefined));
|
|
27
|
+
return checks.every((result) => result instanceof Promise || result.issues === undefined);
|
|
28
|
+
}
|
|
29
|
+
const SKILLS_DIR = "src/skills";
|
|
30
|
+
/**
|
|
31
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
32
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
33
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
34
|
+
*/
|
|
35
|
+
function normalizeForwardedPrefix(raw) {
|
|
36
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
37
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
38
|
+
if (trimmed === "") {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
45
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
46
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
47
|
+
*/
|
|
48
|
+
function stripQuery(uri) {
|
|
49
|
+
const queryIndex = uri.indexOf("?");
|
|
50
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
51
|
+
}
|
|
20
52
|
/**
|
|
21
53
|
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
22
54
|
* become a single `TextContent`; a single block is wrapped in an array;
|
|
@@ -36,15 +68,56 @@ export function normalizeContent(content) {
|
|
|
36
68
|
return [content];
|
|
37
69
|
}
|
|
38
70
|
const McpServerBaseOmitted = McpServerBase;
|
|
71
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
72
|
+
// Set at module scope rather than passed through the constructor because the
|
|
73
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
74
|
+
// threading it through every call site (including user templates) is exactly
|
|
75
|
+
// the boilerplate this design is trying to hide.
|
|
76
|
+
let pendingBuildManifest = null;
|
|
77
|
+
/**
|
|
78
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
79
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
80
|
+
* user-facing API.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export function __setBuildManifest(manifest) {
|
|
85
|
+
pendingBuildManifest = manifest;
|
|
86
|
+
}
|
|
87
|
+
let pendingSkillsManifest = null;
|
|
88
|
+
let cachedDiskManifest = null;
|
|
89
|
+
let discoveredSkills = null;
|
|
90
|
+
let warnedOnMissingSkills = false;
|
|
91
|
+
export function __setSkillsManifest(manifest) {
|
|
92
|
+
pendingSkillsManifest = manifest;
|
|
93
|
+
discoveredSkills = null;
|
|
94
|
+
}
|
|
95
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
96
|
+
// exists — the capability must be present for the `initialize` response.
|
|
97
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
98
|
+
if (!skybridgeOptions?.skills) {
|
|
99
|
+
return options;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...options,
|
|
103
|
+
capabilities: {
|
|
104
|
+
...options?.capabilities,
|
|
105
|
+
extensions: {
|
|
106
|
+
...options?.capabilities?.extensions,
|
|
107
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
39
112
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
113
|
+
* Typed registration sugar over the MCP SDK's `McpServer`: a tool registry
|
|
114
|
+
* that carries input/output/meta shapes, view resources, per-tool security
|
|
115
|
+
* schemes, and prompt/resource registration. A {@link Skybridge} app builds
|
|
116
|
+
* one of these per request and hands it to your `handler`; chain
|
|
117
|
+
* {@link McpServer.registerTool} calls on it and return the result.
|
|
45
118
|
*
|
|
46
119
|
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
47
|
-
* shape, so `typeof
|
|
120
|
+
* shape, so `typeof app` carries enough information for view-side helpers
|
|
48
121
|
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
49
122
|
*
|
|
50
123
|
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
@@ -52,85 +125,89 @@ const McpServerBaseOmitted = McpServerBase;
|
|
|
52
125
|
*
|
|
53
126
|
* @example
|
|
54
127
|
* ```ts
|
|
55
|
-
* const
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
128
|
+
* export const app = new Skybridge({
|
|
129
|
+
* name: "my-app",
|
|
130
|
+
* version: "1.0.0",
|
|
131
|
+
* handler: (server) =>
|
|
132
|
+
* server.registerTool({
|
|
133
|
+
* name: "search",
|
|
134
|
+
* inputSchema: { query: z.string() },
|
|
135
|
+
* view: { component: "search" },
|
|
136
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` })),
|
|
137
|
+
* });
|
|
64
138
|
* ```
|
|
65
139
|
*
|
|
66
140
|
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
67
141
|
*/
|
|
68
142
|
export class McpServer extends McpServerBaseOmitted {
|
|
69
|
-
/**
|
|
70
|
-
* The underlying Express app. Use this to extend the HTTP server with
|
|
71
|
-
* custom routes, middleware, or settings — e.g.
|
|
72
|
-
* `server.express.get("/health", ...)`.
|
|
73
|
-
*
|
|
74
|
-
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
75
|
-
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
76
|
-
* error handler are appended in that order.
|
|
77
|
-
*
|
|
78
|
-
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
79
|
-
* locally and on self-hosted deployments.
|
|
80
|
-
*/
|
|
81
|
-
express;
|
|
82
|
-
customErrorMiddleware = [];
|
|
83
|
-
mcpMiddlewareEntries = [];
|
|
84
|
-
mcpMiddlewareApplied = false;
|
|
85
143
|
claimedViews = new Map();
|
|
86
144
|
viewMetaBuilders = new Map();
|
|
145
|
+
/**
|
|
146
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
147
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
148
|
+
* underlying view no matter which version param the consumer sends, since
|
|
149
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
150
|
+
*/
|
|
151
|
+
viewUriByPath = new Map();
|
|
87
152
|
viteManifest = null;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (typeof pathOrHandler === "string") {
|
|
101
|
-
this.express.use(pathOrHandler, ...handlers);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.express.use(pathOrHandler, ...handlers);
|
|
153
|
+
oauthEnabled = false;
|
|
154
|
+
resolveResourceMetadataUrl;
|
|
155
|
+
toolSecuritySchemes = new Map();
|
|
156
|
+
userMiddlewareEntries = [];
|
|
157
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
158
|
+
super(serverInfo, withSkillsCapability(options, skybridgeOptions));
|
|
159
|
+
this.oauthEnabled = Boolean(skybridgeOptions?.oauth);
|
|
160
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
161
|
+
// user code. Explicit `setViteManifest` calls still win because they
|
|
162
|
+
// happen after construction.
|
|
163
|
+
if (pendingBuildManifest) {
|
|
164
|
+
this.setViteManifest(pendingBuildManifest);
|
|
105
165
|
}
|
|
166
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The per-tool security schemes collected during registration, keyed by tool
|
|
170
|
+
* name. Read by the OAuth layer to decide whether anonymous requests are
|
|
171
|
+
* allowed and which schemes gate a given `tools/call`.
|
|
172
|
+
*
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
get securitySchemesByTool() {
|
|
176
|
+
return this.toolSecuritySchemes;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Inject the resolver the app uses to build the protected-resource metadata
|
|
180
|
+
* URL, so tool handlers can emit in-band auth challenges.
|
|
181
|
+
*
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
setResourceMetadataUrlResolver(resolve) {
|
|
185
|
+
this.resolveResourceMetadataUrl = resolve;
|
|
106
186
|
return this;
|
|
107
187
|
}
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
188
|
+
setupSkills(enabled) {
|
|
189
|
+
if (!enabled) {
|
|
190
|
+
return;
|
|
111
191
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
192
|
+
discoveredSkills ??= pendingSkillsManifest ?? discoverSkills(SKILLS_DIR);
|
|
193
|
+
if (discoveredSkills.length === 0 && !warnedOnMissingSkills) {
|
|
194
|
+
warnedOnMissingSkills = true;
|
|
195
|
+
console.warn(`skybridge: the "skills" option is enabled but no skills were found in "${SKILLS_DIR}". Add a <name>/SKILL.md there, or remove the option.`);
|
|
116
196
|
}
|
|
117
|
-
|
|
197
|
+
registerSkills(this, discoveredSkills);
|
|
118
198
|
}
|
|
119
199
|
mcpMiddleware(filterOrHandler,
|
|
120
200
|
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
121
201
|
maybeHandler) {
|
|
122
|
-
if (this.mcpMiddlewareApplied) {
|
|
123
|
-
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
124
|
-
}
|
|
125
202
|
const handler = maybeHandler;
|
|
126
203
|
if (typeof filterOrHandler === "function") {
|
|
127
|
-
this.
|
|
204
|
+
this.userMiddlewareEntries.push({
|
|
128
205
|
filter: null,
|
|
129
206
|
handler: filterOrHandler,
|
|
130
207
|
});
|
|
131
208
|
}
|
|
132
209
|
else if (handler) {
|
|
133
|
-
this.
|
|
210
|
+
this.userMiddlewareEntries.push({
|
|
134
211
|
filter: filterOrHandler,
|
|
135
212
|
handler,
|
|
136
213
|
});
|
|
@@ -140,11 +217,15 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
140
217
|
}
|
|
141
218
|
return this;
|
|
142
219
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
220
|
+
/**
|
|
221
|
+
* This instance's protocol-level middleware: the framework's own entries
|
|
222
|
+
* (view `_meta` on `resources/list`, version-agnostic view resolution on
|
|
223
|
+
* `resources/read`, the top-level `securitySchemes` mirror on `tools/list`)
|
|
224
|
+
* followed by the ones registered via {@link McpServer.mcpMiddleware}.
|
|
225
|
+
*
|
|
226
|
+
* @internal
|
|
227
|
+
*/
|
|
228
|
+
protocolMiddlewareEntries() {
|
|
148
229
|
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
149
230
|
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
150
231
|
const viewListMetaEntry = {
|
|
@@ -165,108 +246,67 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
165
246
|
return result;
|
|
166
247
|
},
|
|
167
248
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
249
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
250
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
251
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
252
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
253
|
+
// canonical registered one, then restore the requested URI on the response
|
|
254
|
+
// so the consumer-facing URI is never rewritten.
|
|
255
|
+
const viewReadResolveEntry = {
|
|
256
|
+
filter: "resources/read",
|
|
257
|
+
handler: async (req, _extra, next) => {
|
|
258
|
+
const requested = req.params.uri;
|
|
259
|
+
if (typeof requested !== "string") {
|
|
260
|
+
return next();
|
|
261
|
+
}
|
|
262
|
+
const path = stripQuery(requested);
|
|
263
|
+
const canonical = this.viewUriByPath.get(path);
|
|
264
|
+
if (!canonical) {
|
|
265
|
+
return next();
|
|
266
|
+
}
|
|
267
|
+
req.params.uri = canonical;
|
|
268
|
+
try {
|
|
269
|
+
const result = (await next());
|
|
270
|
+
for (const content of result.contents ?? []) {
|
|
271
|
+
if (typeof content.uri === "string" &&
|
|
272
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
273
|
+
content.uri = requested;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
// Restore the shared request params so middleware outer to us never
|
|
280
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
281
|
+
req.params.uri = requested;
|
|
282
|
+
}
|
|
283
|
+
},
|
|
184
284
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
204
|
-
* factory, but that would break Skybridge's singleton API — so instead
|
|
205
|
-
* we build a fresh underlying `Server` per request and share the main
|
|
206
|
-
* server's handler maps by reference. The cast is unavoidable: there's
|
|
207
|
-
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
208
|
-
* read side and fails fast on SDK field renames.
|
|
209
|
-
*/
|
|
210
|
-
async connectStatelessTransport(transport) {
|
|
211
|
-
this.applyMcpMiddleware();
|
|
212
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
213
|
-
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
214
|
-
const target = fresh;
|
|
215
|
-
target._requestHandlers = requestHandlers;
|
|
216
|
-
target._notificationHandlers = notificationHandlers;
|
|
217
|
-
await fresh.connect(transport);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
221
|
-
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
222
|
-
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
223
|
-
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
224
|
-
*
|
|
225
|
-
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
226
|
-
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
227
|
-
* Node, returns `undefined` once listening.
|
|
228
|
-
*/
|
|
229
|
-
async run() {
|
|
230
|
-
this.applyMcpMiddleware();
|
|
231
|
-
const httpServer = http.createServer();
|
|
232
|
-
await createApp({
|
|
233
|
-
mcpServer: this,
|
|
234
|
-
httpServer,
|
|
235
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
236
|
-
});
|
|
237
|
-
httpServer.on("request", this.express);
|
|
238
|
-
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
239
|
-
await new Promise((resolve, reject) => {
|
|
240
|
-
httpServer.on("error", (error) => {
|
|
241
|
-
console.error("Failed to start server:", error);
|
|
242
|
-
reject(error);
|
|
243
|
-
});
|
|
244
|
-
httpServer.listen(port, () => {
|
|
245
|
-
resolve();
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
249
|
-
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
250
|
-
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
251
|
-
if (typeof navigator !== "undefined" &&
|
|
252
|
-
navigator.userAgent === "Cloudflare-Workers") {
|
|
253
|
-
const cloudflareNode = "cloudflare:node";
|
|
254
|
-
const { httpServerHandler } = await import(cloudflareNode);
|
|
255
|
-
return httpServerHandler({ port });
|
|
256
|
-
}
|
|
257
|
-
const shutdown = () => {
|
|
258
|
-
// Drop both handlers so a second signal falls through to Node's default
|
|
259
|
-
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
260
|
-
process.off("SIGTERM", shutdown);
|
|
261
|
-
process.off("SIGINT", shutdown);
|
|
262
|
-
httpServer.close(() => process.exit(0));
|
|
263
|
-
// Force exit if connections don't drain in time so the port is still
|
|
264
|
-
// released promptly (e.g. for nodemon restarts).
|
|
265
|
-
setTimeout(() => process.exit(0), 3000).unref();
|
|
285
|
+
// ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
|
|
286
|
+
// still Draft), but the SDK's registerTool strips unknown top-level fields, so
|
|
287
|
+
// it's stashed in `_meta` at registration. This restores it to the top level
|
|
288
|
+
// on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
|
|
289
|
+
// { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
|
|
290
|
+
// -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
|
|
291
|
+
const toolsListSecuritySchemesEntry = {
|
|
292
|
+
filter: "tools/list",
|
|
293
|
+
handler: async (_req, _extra, next) => {
|
|
294
|
+
const result = (await next());
|
|
295
|
+
for (const tool of result.tools) {
|
|
296
|
+
const schemes = tool._meta?.securitySchemes;
|
|
297
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
298
|
+
tool.securitySchemes = schemes;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return result;
|
|
302
|
+
},
|
|
266
303
|
};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
304
|
+
return [
|
|
305
|
+
viewListMetaEntry,
|
|
306
|
+
viewReadResolveEntry,
|
|
307
|
+
toolsListSecuritySchemesEntry,
|
|
308
|
+
...this.userMiddlewareEntries,
|
|
309
|
+
];
|
|
270
310
|
}
|
|
271
311
|
enforceOneToolPerView(component, toolName) {
|
|
272
312
|
const existingTool = this.claimedViews.get(component);
|
|
@@ -275,35 +315,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
275
315
|
}
|
|
276
316
|
this.claimedViews.set(component, toolName);
|
|
277
317
|
}
|
|
278
|
-
resolveViewRequestContext(
|
|
318
|
+
resolveViewRequestContext(ctx) {
|
|
279
319
|
const isProduction = process.env.NODE_ENV === "production";
|
|
280
|
-
const
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
const origin = header("origin");
|
|
289
|
-
const host = header("host");
|
|
290
|
-
if (forwardedHost) {
|
|
291
|
-
const proto = header("x-forwarded-proto") || "https";
|
|
292
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
293
|
-
}
|
|
294
|
-
else if (origin) {
|
|
295
|
-
serverUrl = origin;
|
|
296
|
-
}
|
|
297
|
-
else if (host) {
|
|
298
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
299
|
-
? "http"
|
|
300
|
-
: "https";
|
|
301
|
-
serverUrl = `${proto}://${host}`;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
const devPort = process.env.__PORT || "3000";
|
|
305
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
306
|
-
}
|
|
320
|
+
const header = (key) => ctx?.http?.req?.headers.get(key) ?? undefined;
|
|
321
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
322
|
+
const serverUrl = resolveServerOrigin(header);
|
|
323
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
324
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
325
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
326
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
327
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
307
328
|
const connectDomains = [serverUrl];
|
|
308
329
|
if (!isProduction) {
|
|
309
330
|
const wsUrl = new URL(serverUrl);
|
|
@@ -312,7 +333,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
312
333
|
}
|
|
313
334
|
let contentMetaOverrides = {};
|
|
314
335
|
if (isClaude) {
|
|
315
|
-
const pathname =
|
|
336
|
+
const pathname = ctx?.http?.req ? new URL(ctx.http.req.url).pathname : "";
|
|
316
337
|
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
317
338
|
// Strip a lone trailing slash so the hash matches the connector URL
|
|
318
339
|
// as registered with Claude (which has no trailing slash on bare origins).
|
|
@@ -324,117 +345,62 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
324
345
|
.slice(0, 32);
|
|
325
346
|
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
326
347
|
}
|
|
327
|
-
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
348
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
328
349
|
}
|
|
329
|
-
registerViewResources(toolName, view, toolMeta) {
|
|
330
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
350
|
+
registerViewResources(toolName, view, toolMeta, openai) {
|
|
331
351
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
332
352
|
// their cache when the bundle changes, but keep the URI stable across
|
|
333
353
|
// `tools/list` calls when the bundle hasn't changed.
|
|
334
354
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
connect_domains: view.csp?.connectDomains,
|
|
353
|
-
frame_domains: view.csp?.frameDomains,
|
|
354
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
355
|
-
},
|
|
356
|
-
"openai/widgetDomain": view.domain,
|
|
357
|
-
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
358
|
-
};
|
|
359
|
-
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
360
|
-
"openai/widgetDomain": overrides.domain,
|
|
361
|
-
});
|
|
362
|
-
if (view._meta) {
|
|
363
|
-
return { ...base, ...view._meta };
|
|
364
|
-
}
|
|
365
|
-
return base;
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
this.registerViewResource({
|
|
369
|
-
name: toolName,
|
|
370
|
-
viewResource,
|
|
371
|
-
view,
|
|
372
|
-
});
|
|
373
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
374
|
-
}
|
|
375
|
-
if (hosts.includes("mcp-app")) {
|
|
376
|
-
const viewResource = {
|
|
377
|
-
hostType: "mcp-app",
|
|
378
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
379
|
-
mimeType: "text/html;profile=mcp-app",
|
|
380
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
381
|
-
const defaults = {
|
|
382
|
-
ui: {
|
|
383
|
-
csp: {
|
|
384
|
-
resourceDomains,
|
|
385
|
-
connectDomains,
|
|
386
|
-
baseUriDomains,
|
|
387
|
-
},
|
|
388
|
-
domain,
|
|
389
|
-
},
|
|
390
|
-
};
|
|
391
|
-
const fromView = {
|
|
392
|
-
ui: {
|
|
393
|
-
...(view.description && { description: view.description }),
|
|
394
|
-
...(view.prefersBorder !== undefined && {
|
|
395
|
-
prefersBorder: view.prefersBorder,
|
|
355
|
+
const viewResource = {
|
|
356
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
357
|
+
mimeType: "text/html;profile=mcp-app",
|
|
358
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
359
|
+
const ui = {
|
|
360
|
+
ui: {
|
|
361
|
+
...(view.description && { description: view.description }),
|
|
362
|
+
...(view.prefersBorder !== undefined && {
|
|
363
|
+
prefersBorder: view.prefersBorder,
|
|
364
|
+
}),
|
|
365
|
+
domain: overrides.domain ?? view.domain ?? domain,
|
|
366
|
+
csp: {
|
|
367
|
+
resourceDomains: unionOf(resourceDomains, view.csp?.resourceDomains),
|
|
368
|
+
connectDomains: unionOf(connectDomains, view.csp?.connectDomains),
|
|
369
|
+
baseUriDomains: unionOf(baseUriDomains, view.csp?.baseUriDomains),
|
|
370
|
+
...(view.csp?.frameDomains && {
|
|
371
|
+
frameDomains: view.csp.frameDomains,
|
|
396
372
|
}),
|
|
397
|
-
...(view.domain && { domain: view.domain }),
|
|
398
|
-
csp: {
|
|
399
|
-
...(view.csp?.resourceDomains && {
|
|
400
|
-
resourceDomains: view.csp.resourceDomains,
|
|
401
|
-
}),
|
|
402
|
-
...(view.csp?.connectDomains && {
|
|
403
|
-
connectDomains: view.csp.connectDomains,
|
|
404
|
-
}),
|
|
405
|
-
...(view.csp?.frameDomains && {
|
|
406
|
-
frameDomains: view.csp.frameDomains,
|
|
407
|
-
}),
|
|
408
|
-
...(view.csp?.baseUriDomains && {
|
|
409
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
410
|
-
}),
|
|
411
|
-
...(view.csp?.redirectDomains && {
|
|
412
|
-
redirectDomains: view.csp.redirectDomains,
|
|
413
|
-
}),
|
|
414
|
-
},
|
|
415
373
|
},
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
const base = {
|
|
377
|
+
...ui,
|
|
378
|
+
...(view.description && {
|
|
379
|
+
"openai/widgetDescription": view.description,
|
|
380
|
+
}),
|
|
381
|
+
...(view.csp?.redirectDomains && {
|
|
382
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
383
|
+
}),
|
|
384
|
+
};
|
|
385
|
+
const meta = { ...base, ...view._meta };
|
|
386
|
+
mergeOpenAIUi(meta, {
|
|
387
|
+
availableDisplayModes: openai?.availableDisplayModes,
|
|
388
|
+
preferredDisplayMode: openai?.preferredDisplayMode,
|
|
389
|
+
});
|
|
390
|
+
return meta;
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
394
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
395
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
396
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
397
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
398
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
399
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
400
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
435
401
|
}
|
|
436
402
|
registerViewResource({ name, viewResource, view, }) {
|
|
437
|
-
const {
|
|
403
|
+
const { uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
438
404
|
const buildMeta = (extra) => {
|
|
439
405
|
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
440
406
|
return buildContentMeta({
|
|
@@ -445,19 +411,23 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
445
411
|
}, contentMetaOverrides);
|
|
446
412
|
};
|
|
447
413
|
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
414
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
415
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
448
416
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
449
417
|
const isProduction = process.env.NODE_ENV === "production";
|
|
450
|
-
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
418
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
419
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
420
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
421
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
422
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
451
423
|
const html = isProduction
|
|
452
424
|
? templateHelper.renderProduction({
|
|
453
|
-
|
|
454
|
-
serverUrl,
|
|
425
|
+
serverUrl: viewBase,
|
|
455
426
|
viewFile: this.lookupViewFile(view.component),
|
|
456
427
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
457
428
|
})
|
|
458
429
|
: templateHelper.renderDevelopment({
|
|
459
|
-
|
|
460
|
-
serverUrl,
|
|
430
|
+
serverUrl: viewBase,
|
|
461
431
|
viewName: view.component,
|
|
462
432
|
});
|
|
463
433
|
return {
|
|
@@ -467,9 +437,29 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
467
437
|
};
|
|
468
438
|
});
|
|
469
439
|
}
|
|
470
|
-
|
|
440
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
441
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
442
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
443
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
444
|
+
}
|
|
445
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
471
446
|
return async (args, extra) => {
|
|
472
|
-
|
|
447
|
+
if (this.oauthEnabled) {
|
|
448
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.http?.authInfo);
|
|
449
|
+
if (failure) {
|
|
450
|
+
const header = (key) => extra.http?.req?.headers.get(key) ?? undefined;
|
|
451
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
let result;
|
|
455
|
+
try {
|
|
456
|
+
result = await cb(args, extra);
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
captureToolError(extra, error);
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
warnOnLargeToolOutput(result, toolName);
|
|
473
463
|
return {
|
|
474
464
|
...result,
|
|
475
465
|
content: normalizeContent(result.content),
|
|
@@ -529,18 +519,63 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
529
519
|
if (this.viteManifest) {
|
|
530
520
|
return this.viteManifest;
|
|
531
521
|
}
|
|
532
|
-
|
|
522
|
+
cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
523
|
+
return cachedDiskManifest ?? {};
|
|
533
524
|
}
|
|
534
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Register the composer at-mention search for ChatGPT, from the OpenAI MCP
|
|
527
|
+
* extensions. When the user types `@` and your app name, ChatGPT calls
|
|
528
|
+
* `handler` with the typed text and lists the returned resource links.
|
|
529
|
+
* Skybridge registers it as a tool hidden from the model.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* server.registerMentions({
|
|
534
|
+
* name: "search_parts",
|
|
535
|
+
* handler: async ({ query }) => ({
|
|
536
|
+
* items: findParts(query).map((part) => ({
|
|
537
|
+
* type: "resource_link",
|
|
538
|
+
* uri: `parts://${part.id}`,
|
|
539
|
+
* name: part.name,
|
|
540
|
+
* })),
|
|
541
|
+
* }),
|
|
542
|
+
* });
|
|
543
|
+
* ```
|
|
544
|
+
*
|
|
545
|
+
* @see https://docs.skybridge.tech/api-reference/register-mentions
|
|
546
|
+
*/
|
|
547
|
+
registerMentions(config) {
|
|
548
|
+
this.registerTool({
|
|
549
|
+
name: config.name,
|
|
550
|
+
description: config.description ?? "Search items to mention.",
|
|
551
|
+
annotations: { readOnlyHint: true },
|
|
552
|
+
inputSchema: { query: z.string() },
|
|
553
|
+
_meta: {
|
|
554
|
+
"openai/extensions": { "mentions/search": {} },
|
|
555
|
+
ui: { visibility: ["app"] },
|
|
556
|
+
},
|
|
557
|
+
}, async ({ query }, extra) => ({
|
|
558
|
+
content: [],
|
|
559
|
+
structuredContent: await config.handler({ query }, extra),
|
|
560
|
+
}));
|
|
561
|
+
return this;
|
|
562
|
+
}
|
|
563
|
+
registerTool(rawConfig, rawCb) {
|
|
535
564
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
565
|
+
const config = rawConfig;
|
|
566
|
+
const cb = rawCb;
|
|
567
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, openai, _meta: userToolMeta, ...toolFields } = config;
|
|
568
|
+
const authNeedsProvider = auth !== undefined &&
|
|
569
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
570
|
+
if (rawSecuritySchemes === undefined &&
|
|
571
|
+
authNeedsProvider &&
|
|
572
|
+
!this.oauthEnabled) {
|
|
573
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
539
574
|
}
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
575
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
576
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
543
577
|
const toolMeta = { ...userToolMeta };
|
|
578
|
+
this.toolSecuritySchemes.set(name, securitySchemes);
|
|
544
579
|
if (securitySchemes) {
|
|
545
580
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
546
581
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
@@ -549,12 +584,37 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
549
584
|
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
550
585
|
toolMeta.securitySchemes = securitySchemes;
|
|
551
586
|
}
|
|
587
|
+
if (openai) {
|
|
588
|
+
if (!view) {
|
|
589
|
+
throw new Error(`skybridge: tool "${name}" sets \`openai\` options but has no \`view\`.`);
|
|
590
|
+
}
|
|
591
|
+
const opensWithoutInput = openai.entrypoints?.some(({ type }) => type === "global" || type === "thread");
|
|
592
|
+
if (opensWithoutInput && !acceptsEmptyInput(toolFields.inputSchema)) {
|
|
593
|
+
throw new Error(`skybridge: tool "${name}" has a global or thread entrypoint, so ChatGPT calls it with \`{}\`, but its input schema rejects \`{}\`. Make every input optional.`);
|
|
594
|
+
}
|
|
595
|
+
const badExtension = openai.entrypoints
|
|
596
|
+
?.flatMap((entrypoint) => entrypoint.type === "file" ? entrypoint.extensions : [])
|
|
597
|
+
.find((extension) => !extension.startsWith("."));
|
|
598
|
+
if (badExtension !== undefined) {
|
|
599
|
+
throw new Error(`skybridge: tool "${name}" has a file entrypoint extension "${badExtension}" that doesn't start with ".".`);
|
|
600
|
+
}
|
|
601
|
+
mergeOpenAIUi(toolMeta, {
|
|
602
|
+
entrypoints: openai.entrypoints,
|
|
603
|
+
preferredModelDisplayMode: openai.preferredModelDisplayMode,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
552
606
|
if (view) {
|
|
553
607
|
this.enforceOneToolPerView(view.component, name);
|
|
554
|
-
this.registerViewResources(name, view, toolMeta);
|
|
608
|
+
this.registerViewResources(name, view, toolMeta, openai);
|
|
555
609
|
}
|
|
556
|
-
const wrappedCb = this.
|
|
557
|
-
|
|
610
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
611
|
+
attachViewUUID: Boolean(view),
|
|
612
|
+
securitySchemes,
|
|
613
|
+
toolName: name,
|
|
614
|
+
});
|
|
615
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, toolFields.inputSchema === undefined
|
|
616
|
+
? (extra) => wrappedCb({}, extra)
|
|
617
|
+
: wrappedCb);
|
|
558
618
|
return this;
|
|
559
619
|
}
|
|
560
620
|
}
|