skybridge 0.0.0-dev.f792261 → 0.0.0-dev.f7943e6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -124
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +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 +9 -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 +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +14 -0
- package/dist/cli/use-nodemon.js +71 -60
- 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 +71 -68
- 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/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 +1 -0
- package/dist/commands/dev.js +48 -0
- 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/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +16 -1
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +32 -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 +44 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +40 -0
- package/dist/server/auth/providers/auth0.js +31 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +50 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +140 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +51 -0
- package/dist/server/auth/providers/clerk.js +19 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +30 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +40 -0
- package/dist/server/auth/providers/custom.js +56 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +158 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +44 -0
- package/dist/server/auth/providers/descope.js +44 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +62 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +25 -0
- package/dist/server/auth/providers/stytch.js +16 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +33 -0
- package/dist/server/auth/providers/workos.js +15 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +6 -0
- package/dist/server/auth/setup.js +92 -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 +508 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +46 -0
- package/dist/server/auth/verify.js +62 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +149 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth-extra.test-d.js +82 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +58 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.test.js +61 -0
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/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 +15 -2
- package/dist/server/index.js +13 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.d.ts +47 -9
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test.js +37 -1
- 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 +26 -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 +291 -19
- package/dist/server/server.js +458 -178
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +79 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +29 -0
- package/dist/server/skills.js +195 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +247 -0
- package/dist/server/skills.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 +171 -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 +3 -3
- package/dist/test/view.test.js +125 -96
- package/dist/test/view.test.js.map +1 -1
- package/dist/views/index.d.ts +3 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/{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 +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 +6 -1
- package/dist/web/bridges/apps-sdk/bridge.js +15 -3
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +2 -0
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +9 -7
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +15 -2
- package/dist/web/bridges/mcp-app/bridge.js +73 -7
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.d.ts +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/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 +104 -1
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +34 -1
- package/dist/web/data-llm.js +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +18 -5
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +4 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/hooks/index.d.ts +5 -0
- package/dist/web/hooks/index.js +5 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +7 -2
- package/dist/web/hooks/test/utils.js +14 -3
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +62 -23
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +20 -0
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +56 -20
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +5 -0
- package/dist/web/hooks/use-download.js +8 -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 +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host-info.d.ts +22 -0
- package/dist/web/hooks/use-host-info.js +30 -0
- package/dist/web/hooks/use-host-info.js.map +1 -0
- package/dist/web/hooks/use-host-info.test.d.ts +1 -0
- package/dist/web/hooks/use-host-info.test.js +59 -0
- package/dist/web/hooks/use-host-info.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +2 -0
- package/dist/web/hooks/use-layout.js +2 -0
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +47 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +20 -0
- package/dist/web/hooks/use-request-size.js +24 -0
- package/dist/web/hooks/use-request-size.js.map +1 -0
- package/dist/web/hooks/use-request-size.test.d.ts +1 -0
- package/dist/web/hooks/use-request-size.test.js +47 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +17 -0
- package/dist/web/hooks/use-send-follow-up-message.js +17 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +42 -32
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +21 -0
- 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 +37 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/mount-view.d.ts +19 -0
- package/dist/web/mount-view.js +19 -0
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +29 -23
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -24
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -96
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -48
- package/dist/web/bridges/mcp-app/adaptor.js +0 -263
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- package/dist/web/plugin/data-llm.test.js +0 -81
- package/dist/web/plugin/data-llm.test.js.map +0 -1
- package/dist/web/plugin/plugin.d.ts +0 -5
- package/dist/web/plugin/plugin.js +0 -156
- 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/plugin/data-llm.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → context-warnings.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
|
@@ -6,9 +6,15 @@ import { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js"
|
|
|
6
6
|
import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
7
|
import { mergeWith, union } from "es-toolkit";
|
|
8
8
|
import express, {} from "express";
|
|
9
|
+
import { warnOnLargeToolOutput } from "../context-warnings.js";
|
|
10
|
+
import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
11
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
9
12
|
import { createApp } from "./express.js";
|
|
13
|
+
import { hostFromUserAgent } from "./host.js";
|
|
10
14
|
import { createMiddlewareEntry } from "./metric.js";
|
|
11
|
-
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
15
|
+
import { buildMiddlewareChain, captureToolError, getHandlerMaps, } from "./middleware.js";
|
|
16
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
17
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
12
18
|
import { templateHelper } from "./templateHelper.js";
|
|
13
19
|
const mergeWithUnion = (target, source) => {
|
|
14
20
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -17,6 +23,35 @@ const mergeWithUnion = (target, source) => {
|
|
|
17
23
|
}
|
|
18
24
|
});
|
|
19
25
|
};
|
|
26
|
+
const SKILLS_DIR = "src/skills";
|
|
27
|
+
/**
|
|
28
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
29
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
30
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
31
|
+
*/
|
|
32
|
+
function normalizeForwardedPrefix(raw) {
|
|
33
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
34
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
35
|
+
if (trimmed === "") {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
42
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
43
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
44
|
+
*/
|
|
45
|
+
function stripQuery(uri) {
|
|
46
|
+
const queryIndex = uri.indexOf("?");
|
|
47
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
51
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
52
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
53
|
+
* who build content lazily can apply the same normalization.
|
|
54
|
+
*/
|
|
20
55
|
export function normalizeContent(content) {
|
|
21
56
|
if (content === undefined) {
|
|
22
57
|
return [];
|
|
@@ -30,13 +65,101 @@ export function normalizeContent(content) {
|
|
|
30
65
|
return [content];
|
|
31
66
|
}
|
|
32
67
|
const McpServerBaseOmitted = McpServerBase;
|
|
68
|
+
/**
|
|
69
|
+
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
70
|
+
* registry, view resources, an embedded Express app, and protocol-level
|
|
71
|
+
* middleware. Construct it with the same `Implementation` info you would pass
|
|
72
|
+
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
73
|
+
* then call {@link McpServer.run} to start the HTTP server.
|
|
74
|
+
*
|
|
75
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
76
|
+
* shape, so `typeof server` carries enough information for view-side helpers
|
|
77
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
78
|
+
*
|
|
79
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
80
|
+
* chaining; you almost never set this manually.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
85
|
+
* .registerTool({
|
|
86
|
+
* name: "search",
|
|
87
|
+
* inputSchema: { query: z.string() },
|
|
88
|
+
* view: { component: "search" },
|
|
89
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
90
|
+
*
|
|
91
|
+
* await server.run();
|
|
92
|
+
* export type AppType = typeof server;
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
96
|
+
*/
|
|
97
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
98
|
+
// Set at module scope rather than passed through the constructor because the
|
|
99
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
100
|
+
// threading it through every call site (including user templates) is exactly
|
|
101
|
+
// the boilerplate this design is trying to hide.
|
|
102
|
+
let pendingBuildManifest = null;
|
|
103
|
+
/**
|
|
104
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
105
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
106
|
+
* user-facing API.
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
export function __setBuildManifest(manifest) {
|
|
111
|
+
pendingBuildManifest = manifest;
|
|
112
|
+
}
|
|
113
|
+
let pendingSkillsManifest = null;
|
|
114
|
+
export function __setSkillsManifest(manifest) {
|
|
115
|
+
pendingSkillsManifest = manifest;
|
|
116
|
+
}
|
|
117
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
118
|
+
// exists — the capability must be present for the `initialize` response.
|
|
119
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
120
|
+
if (!skybridgeOptions?.skills) {
|
|
121
|
+
return options;
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
...options,
|
|
125
|
+
capabilities: {
|
|
126
|
+
...options?.capabilities,
|
|
127
|
+
extensions: {
|
|
128
|
+
...options?.capabilities?.extensions,
|
|
129
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Collapses registerTool's two overloads into a single { config, cb } shape.
|
|
135
|
+
// registerTool("greet", { description }, handler)
|
|
136
|
+
// -> { config: { name: "greet", description }, cb: handler }
|
|
137
|
+
// registerTool({ name: "greet", description }, handler)
|
|
138
|
+
// -> { config: { name: "greet", description }, cb: handler }
|
|
139
|
+
function normalizeRegisterToolArgs(args) {
|
|
140
|
+
if (typeof args[0] === "string") {
|
|
141
|
+
return {
|
|
142
|
+
config: {
|
|
143
|
+
name: args[0],
|
|
144
|
+
...args[1],
|
|
145
|
+
},
|
|
146
|
+
cb: args[2],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
config: args[0],
|
|
151
|
+
cb: args[1],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
33
154
|
export class McpServer extends McpServerBaseOmitted {
|
|
34
155
|
/**
|
|
35
156
|
* The underlying Express app. Use this to extend the HTTP server with
|
|
36
157
|
* custom routes, middleware, or settings — e.g.
|
|
37
158
|
* `server.express.get("/health", ...)`.
|
|
38
159
|
*
|
|
39
|
-
* `express.json()` is pre-applied
|
|
160
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
161
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
162
|
+
* Register your handlers before `run()`;
|
|
40
163
|
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
41
164
|
* error handler are appended in that order.
|
|
42
165
|
*
|
|
@@ -48,15 +171,53 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
48
171
|
mcpMiddlewareEntries = [];
|
|
49
172
|
mcpMiddlewareApplied = false;
|
|
50
173
|
claimedViews = new Map();
|
|
174
|
+
viewMetaBuilders = new Map();
|
|
175
|
+
/**
|
|
176
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
177
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
178
|
+
* underlying view no matter which version param the consumer sends, since
|
|
179
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
180
|
+
*/
|
|
181
|
+
viewUriByPath = new Map();
|
|
51
182
|
viteManifest = null;
|
|
52
183
|
serverInfo;
|
|
53
184
|
serverOptions;
|
|
54
|
-
|
|
55
|
-
|
|
185
|
+
oauthEnabled = false;
|
|
186
|
+
resolveResourceMetadataUrl;
|
|
187
|
+
securitySchemesByTool = new Map();
|
|
188
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
189
|
+
const mergedOptions = withSkillsCapability(options, skybridgeOptions);
|
|
190
|
+
super(serverInfo, mergedOptions);
|
|
56
191
|
this.serverInfo = serverInfo;
|
|
57
|
-
this.serverOptions =
|
|
192
|
+
this.serverOptions = mergedOptions;
|
|
58
193
|
this.express = express();
|
|
59
|
-
this.express.use(express.json());
|
|
194
|
+
this.express.use(express.json(skybridgeOptions?.json));
|
|
195
|
+
if (skybridgeOptions?.oauth) {
|
|
196
|
+
this.oauthEnabled = true;
|
|
197
|
+
this.resolveResourceMetadataUrl = setupOAuth(this.express, skybridgeOptions.oauth, this.securitySchemesByTool);
|
|
198
|
+
}
|
|
199
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
200
|
+
// user code. Consume-once: clear after the first construction so a
|
|
201
|
+
// subsequent test that doesn't prime can't inherit stale state.
|
|
202
|
+
// Explicit `setViteManifest` calls still win because they happen after
|
|
203
|
+
// construction.
|
|
204
|
+
if (pendingBuildManifest) {
|
|
205
|
+
this.setViteManifest(pendingBuildManifest);
|
|
206
|
+
pendingBuildManifest = null;
|
|
207
|
+
}
|
|
208
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
209
|
+
}
|
|
210
|
+
setupSkills(enabled) {
|
|
211
|
+
const manifest = pendingSkillsManifest;
|
|
212
|
+
pendingSkillsManifest = null;
|
|
213
|
+
if (!enabled) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const skills = manifest ?? discoverSkills(SKILLS_DIR);
|
|
217
|
+
if (skills.length === 0) {
|
|
218
|
+
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.`);
|
|
219
|
+
}
|
|
220
|
+
registerSkills(this, skills);
|
|
60
221
|
}
|
|
61
222
|
use(pathOrHandler, ...handlers) {
|
|
62
223
|
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
@@ -109,13 +270,89 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
109
270
|
return;
|
|
110
271
|
}
|
|
111
272
|
this.mcpMiddlewareApplied = true;
|
|
273
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
274
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
275
|
+
const viewListMetaEntry = {
|
|
276
|
+
filter: "resources/list",
|
|
277
|
+
handler: async (_req, extra, next) => {
|
|
278
|
+
const result = (await next());
|
|
279
|
+
for (const resource of result.resources) {
|
|
280
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
281
|
+
if (!builder) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const meta = builder(extra);
|
|
285
|
+
resource._meta = {
|
|
286
|
+
...(resource._meta ?? {}),
|
|
287
|
+
...meta,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
294
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
295
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
296
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
297
|
+
// canonical registered one, then restore the requested URI on the response
|
|
298
|
+
// so the consumer-facing URI is never rewritten.
|
|
299
|
+
const viewReadResolveEntry = {
|
|
300
|
+
filter: "resources/read",
|
|
301
|
+
handler: async (req, _extra, next) => {
|
|
302
|
+
const requested = req.params.uri;
|
|
303
|
+
if (typeof requested !== "string") {
|
|
304
|
+
return next();
|
|
305
|
+
}
|
|
306
|
+
const path = stripQuery(requested);
|
|
307
|
+
const canonical = this.viewUriByPath.get(path);
|
|
308
|
+
if (!canonical) {
|
|
309
|
+
return next();
|
|
310
|
+
}
|
|
311
|
+
req.params.uri = canonical;
|
|
312
|
+
try {
|
|
313
|
+
const result = (await next());
|
|
314
|
+
for (const content of result.contents ?? []) {
|
|
315
|
+
if (typeof content.uri === "string" &&
|
|
316
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
317
|
+
content.uri = requested;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
// Restore the shared request params so middleware outer to us never
|
|
324
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
325
|
+
req.params.uri = requested;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
// ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
|
|
330
|
+
// still Draft), but the SDK's registerTool strips unknown top-level fields, so
|
|
331
|
+
// it's stashed in `_meta` at registration. This restores it to the top level
|
|
332
|
+
// on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
|
|
333
|
+
// { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
|
|
334
|
+
// -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
|
|
335
|
+
const toolsListSecuritySchemesEntry = {
|
|
336
|
+
filter: "tools/list",
|
|
337
|
+
handler: async (_req, _extra, next) => {
|
|
338
|
+
const result = (await next());
|
|
339
|
+
for (const tool of result.tools) {
|
|
340
|
+
const schemes = tool._meta?.securitySchemes;
|
|
341
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
342
|
+
tool.securitySchemes = schemes;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return result;
|
|
346
|
+
},
|
|
347
|
+
};
|
|
112
348
|
const monitoringEntry = createMiddlewareEntry();
|
|
113
|
-
const entries =
|
|
114
|
-
? [monitoringEntry
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
349
|
+
const entries = [
|
|
350
|
+
...(monitoringEntry ? [monitoringEntry] : []),
|
|
351
|
+
viewListMetaEntry,
|
|
352
|
+
viewReadResolveEntry,
|
|
353
|
+
toolsListSecuritySchemesEntry,
|
|
354
|
+
...this.mcpMiddlewareEntries,
|
|
355
|
+
];
|
|
119
356
|
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
120
357
|
const instrumentMap = (map, isNotification) => {
|
|
121
358
|
for (const [method, handler] of map) {
|
|
@@ -127,6 +364,14 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
127
364
|
instrumentMap(requestHandlers, false);
|
|
128
365
|
instrumentMap(notificationHandlers, true);
|
|
129
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
369
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
370
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
371
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
372
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
373
|
+
* throw afterwards.
|
|
374
|
+
*/
|
|
130
375
|
async connect(transport) {
|
|
131
376
|
this.applyMcpMiddleware();
|
|
132
377
|
return McpServerBase.prototype.connect.call(this, transport);
|
|
@@ -150,8 +395,35 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
150
395
|
target._notificationHandlers = notificationHandlers;
|
|
151
396
|
await fresh.connect(transport);
|
|
152
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
400
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
401
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
402
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
403
|
+
*
|
|
404
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
405
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
406
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
407
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
408
|
+
* Node, returns `undefined` once listening. When the process was spawned
|
|
409
|
+
* with an IPC channel, the bound port is reported to the parent as
|
|
410
|
+
* `{ type: "skybridge:listening", port }`, the readiness signal test runners
|
|
411
|
+
* wait on instead of polling.
|
|
412
|
+
*/
|
|
153
413
|
async run() {
|
|
154
414
|
this.applyMcpMiddleware();
|
|
415
|
+
if (process.env.VERCEL === "1") {
|
|
416
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
417
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
418
|
+
// bare object passed to satisfy the required parameter.
|
|
419
|
+
const httpServer = http.createServer();
|
|
420
|
+
await createApp({
|
|
421
|
+
mcpServer: this,
|
|
422
|
+
httpServer,
|
|
423
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
424
|
+
});
|
|
425
|
+
return this.express;
|
|
426
|
+
}
|
|
155
427
|
const httpServer = http.createServer();
|
|
156
428
|
await createApp({
|
|
157
429
|
mcpServer: this,
|
|
@@ -159,16 +431,18 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
159
431
|
errorMiddleware: this.customErrorMiddleware,
|
|
160
432
|
});
|
|
161
433
|
httpServer.on("request", this.express);
|
|
162
|
-
const
|
|
434
|
+
const intendedPort = parseInt(process.env.__PORT ?? "3000", 10);
|
|
163
435
|
await new Promise((resolve, reject) => {
|
|
164
436
|
httpServer.on("error", (error) => {
|
|
165
437
|
console.error("Failed to start server:", error);
|
|
166
438
|
reject(error);
|
|
167
439
|
});
|
|
168
|
-
httpServer.listen(
|
|
440
|
+
httpServer.listen(intendedPort, () => {
|
|
169
441
|
resolve();
|
|
170
442
|
});
|
|
171
443
|
});
|
|
444
|
+
const { port } = httpServer.address();
|
|
445
|
+
process.send?.({ type: "skybridge:listening", port });
|
|
172
446
|
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
173
447
|
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
174
448
|
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
@@ -199,192 +473,179 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
199
473
|
}
|
|
200
474
|
this.claimedViews.set(component, toolName);
|
|
201
475
|
}
|
|
476
|
+
resolveViewRequestContext(extra) {
|
|
477
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
478
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
479
|
+
const header = (key) => {
|
|
480
|
+
const val = headers[key];
|
|
481
|
+
return Array.isArray(val) ? val[0] : val;
|
|
482
|
+
};
|
|
483
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
484
|
+
const serverUrl = resolveServerOrigin(header);
|
|
485
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
486
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
487
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
488
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
489
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
490
|
+
const connectDomains = [serverUrl];
|
|
491
|
+
if (!isProduction) {
|
|
492
|
+
const wsUrl = new URL(serverUrl);
|
|
493
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
494
|
+
connectDomains.push(wsUrl.origin);
|
|
495
|
+
}
|
|
496
|
+
let contentMetaOverrides = {};
|
|
497
|
+
if (isClaude) {
|
|
498
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
499
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
500
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
501
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
502
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
503
|
+
const hash = crypto
|
|
504
|
+
.createHash("sha256")
|
|
505
|
+
.update(url)
|
|
506
|
+
.digest("hex")
|
|
507
|
+
.slice(0, 32);
|
|
508
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
509
|
+
}
|
|
510
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
511
|
+
}
|
|
202
512
|
registerViewResources(toolName, view, toolMeta) {
|
|
203
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
204
513
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
205
514
|
// their cache when the bundle changes, but keep the URI stable across
|
|
206
515
|
// `tools/list` calls when the bundle hasn't changed.
|
|
207
516
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
517
|
+
const viewResource = {
|
|
518
|
+
hostType: "mcp-app",
|
|
519
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
520
|
+
mimeType: "text/html;profile=mcp-app",
|
|
521
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
522
|
+
const defaults = {
|
|
523
|
+
ui: {
|
|
524
|
+
csp: {
|
|
525
|
+
resourceDomains,
|
|
526
|
+
connectDomains,
|
|
527
|
+
baseUriDomains,
|
|
218
528
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
this.registerViewResource({
|
|
242
|
-
name: toolName,
|
|
243
|
-
viewResource,
|
|
244
|
-
view,
|
|
245
|
-
});
|
|
246
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
247
|
-
}
|
|
248
|
-
if (hosts.includes("mcp-app")) {
|
|
249
|
-
const viewResource = {
|
|
250
|
-
hostType: "mcp-app",
|
|
251
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
252
|
-
mimeType: "text/html;profile=mcp-app",
|
|
253
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
254
|
-
const defaults = {
|
|
255
|
-
ui: {
|
|
256
|
-
csp: {
|
|
257
|
-
resourceDomains,
|
|
258
|
-
connectDomains,
|
|
259
|
-
baseUriDomains,
|
|
260
|
-
},
|
|
261
|
-
domain,
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
const fromView = {
|
|
265
|
-
ui: {
|
|
266
|
-
...(view.description && { description: view.description }),
|
|
267
|
-
...(view.prefersBorder !== undefined && {
|
|
268
|
-
prefersBorder: view.prefersBorder,
|
|
529
|
+
domain,
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
const fromView = {
|
|
533
|
+
ui: {
|
|
534
|
+
...(view.description && { description: view.description }),
|
|
535
|
+
...(view.prefersBorder !== undefined && {
|
|
536
|
+
prefersBorder: view.prefersBorder,
|
|
537
|
+
}),
|
|
538
|
+
...(view.domain && { domain: view.domain }),
|
|
539
|
+
csp: {
|
|
540
|
+
...(view.csp?.resourceDomains && {
|
|
541
|
+
resourceDomains: view.csp.resourceDomains,
|
|
542
|
+
}),
|
|
543
|
+
...(view.csp?.connectDomains && {
|
|
544
|
+
connectDomains: view.csp.connectDomains,
|
|
545
|
+
}),
|
|
546
|
+
...(view.csp?.frameDomains && {
|
|
547
|
+
frameDomains: view.csp.frameDomains,
|
|
548
|
+
}),
|
|
549
|
+
...(view.csp?.baseUriDomains && {
|
|
550
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
269
551
|
}),
|
|
270
|
-
...(view.domain && { domain: view.domain }),
|
|
271
|
-
csp: {
|
|
272
|
-
...(view.csp?.resourceDomains && {
|
|
273
|
-
resourceDomains: view.csp.resourceDomains,
|
|
274
|
-
}),
|
|
275
|
-
...(view.csp?.connectDomains && {
|
|
276
|
-
connectDomains: view.csp.connectDomains,
|
|
277
|
-
}),
|
|
278
|
-
...(view.csp?.frameDomains && {
|
|
279
|
-
frameDomains: view.csp.frameDomains,
|
|
280
|
-
}),
|
|
281
|
-
...(view.csp?.baseUriDomains && {
|
|
282
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
283
|
-
}),
|
|
284
|
-
...(view.csp?.redirectDomains && {
|
|
285
|
-
redirectDomains: view.csp.redirectDomains,
|
|
286
|
-
}),
|
|
287
|
-
},
|
|
288
552
|
},
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
556
|
+
ui: overrides,
|
|
557
|
+
});
|
|
558
|
+
const base = {
|
|
559
|
+
...ui,
|
|
560
|
+
...(view.description && {
|
|
561
|
+
"openai/widgetDescription": view.description,
|
|
562
|
+
}),
|
|
563
|
+
...(view.csp?.redirectDomains && {
|
|
564
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
565
|
+
}),
|
|
566
|
+
};
|
|
567
|
+
if (view._meta) {
|
|
568
|
+
return { ...base, ...view._meta };
|
|
569
|
+
}
|
|
570
|
+
return base;
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
574
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
575
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
576
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
577
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
578
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
579
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
580
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
308
581
|
}
|
|
309
582
|
registerViewResource({ name, viewResource, view, }) {
|
|
310
583
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
584
|
+
const buildMeta = (extra) => {
|
|
585
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
586
|
+
return buildContentMeta({
|
|
587
|
+
resourceDomains: [serverUrl],
|
|
588
|
+
connectDomains,
|
|
589
|
+
domain: serverUrl,
|
|
590
|
+
baseUriDomains: [serverUrl],
|
|
591
|
+
}, contentMetaOverrides);
|
|
592
|
+
};
|
|
593
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
594
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
595
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
311
596
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
312
597
|
const isProduction = process.env.NODE_ENV === "production";
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
};
|
|
319
|
-
let serverUrl;
|
|
320
|
-
const forwardedHost = header("x-forwarded-host");
|
|
321
|
-
const origin = header("origin");
|
|
322
|
-
const host = header("host");
|
|
323
|
-
if (forwardedHost) {
|
|
324
|
-
const proto = header("x-forwarded-proto") || "https";
|
|
325
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
326
|
-
}
|
|
327
|
-
else if (origin) {
|
|
328
|
-
serverUrl = origin;
|
|
329
|
-
}
|
|
330
|
-
else if (host) {
|
|
331
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
332
|
-
? "http"
|
|
333
|
-
: "https";
|
|
334
|
-
serverUrl = `${proto}://${host}`;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
const devPort = process.env.__PORT || "3000";
|
|
338
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
339
|
-
}
|
|
598
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
599
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
600
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
601
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
602
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
340
603
|
const html = isProduction
|
|
341
604
|
? templateHelper.renderProduction({
|
|
342
605
|
hostType,
|
|
343
|
-
serverUrl,
|
|
606
|
+
serverUrl: viewBase,
|
|
344
607
|
viewFile: this.lookupViewFile(view.component),
|
|
345
608
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
346
609
|
})
|
|
347
610
|
: templateHelper.renderDevelopment({
|
|
348
611
|
hostType,
|
|
349
|
-
serverUrl,
|
|
612
|
+
serverUrl: viewBase,
|
|
350
613
|
viewName: view.component,
|
|
351
614
|
});
|
|
352
|
-
const connectDomains = [serverUrl];
|
|
353
|
-
if (!isProduction) {
|
|
354
|
-
const wsUrl = new URL(serverUrl);
|
|
355
|
-
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
356
|
-
connectDomains.push(wsUrl.origin);
|
|
357
|
-
}
|
|
358
|
-
let contentMetaOverrides = {};
|
|
359
|
-
if (isClaude) {
|
|
360
|
-
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
361
|
-
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
362
|
-
// Strip a lone trailing slash so the hash matches the connector URL
|
|
363
|
-
// as registered with Claude (which has no trailing slash on bare origins).
|
|
364
|
-
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
365
|
-
const hash = crypto
|
|
366
|
-
.createHash("sha256")
|
|
367
|
-
.update(url)
|
|
368
|
-
.digest("hex")
|
|
369
|
-
.slice(0, 32);
|
|
370
|
-
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
371
|
-
}
|
|
372
|
-
const contentMeta = buildContentMeta({
|
|
373
|
-
resourceDomains: [serverUrl],
|
|
374
|
-
connectDomains,
|
|
375
|
-
domain: serverUrl,
|
|
376
|
-
baseUriDomains: [serverUrl],
|
|
377
|
-
}, contentMetaOverrides);
|
|
378
615
|
return {
|
|
379
616
|
contents: [
|
|
380
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
617
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
381
618
|
],
|
|
382
619
|
};
|
|
383
620
|
});
|
|
384
621
|
}
|
|
385
|
-
|
|
622
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
623
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
624
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
625
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
626
|
+
}
|
|
627
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
386
628
|
return async (args, extra) => {
|
|
387
|
-
|
|
629
|
+
if (this.oauthEnabled) {
|
|
630
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.authInfo);
|
|
631
|
+
if (failure) {
|
|
632
|
+
const headers = extra.requestInfo?.headers ?? {};
|
|
633
|
+
const header = (key) => {
|
|
634
|
+
const value = headers[key];
|
|
635
|
+
return Array.isArray(value) ? value[0] : value;
|
|
636
|
+
};
|
|
637
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
let result;
|
|
641
|
+
try {
|
|
642
|
+
result = await cb(args, extra);
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
captureToolError(extra, error);
|
|
646
|
+
throw error;
|
|
647
|
+
}
|
|
648
|
+
warnOnLargeToolOutput(result, toolName);
|
|
388
649
|
return {
|
|
389
650
|
...result,
|
|
390
651
|
content: normalizeContent(result.content),
|
|
@@ -448,20 +709,39 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
448
709
|
}
|
|
449
710
|
registerTool(...args) {
|
|
450
711
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
712
|
+
const { config, cb } = normalizeRegisterToolArgs(args);
|
|
713
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
714
|
+
const authNeedsProvider = auth !== undefined &&
|
|
715
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
716
|
+
if (rawSecuritySchemes === undefined &&
|
|
717
|
+
authNeedsProvider &&
|
|
718
|
+
!this.oauthEnabled) {
|
|
719
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
454
720
|
}
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
721
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
722
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
458
723
|
const toolMeta = { ...userToolMeta };
|
|
724
|
+
this.securitySchemesByTool.set(name, securitySchemes);
|
|
725
|
+
if (securitySchemes) {
|
|
726
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
727
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
728
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
729
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
730
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
731
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
732
|
+
}
|
|
459
733
|
if (view) {
|
|
460
734
|
this.enforceOneToolPerView(view.component, name);
|
|
461
735
|
this.registerViewResources(name, view, toolMeta);
|
|
462
736
|
}
|
|
463
|
-
const wrappedCb = this.
|
|
464
|
-
|
|
737
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
738
|
+
attachViewUUID: Boolean(view),
|
|
739
|
+
securitySchemes,
|
|
740
|
+
toolName: name,
|
|
741
|
+
});
|
|
742
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, toolFields.inputSchema === undefined
|
|
743
|
+
? (extra) => wrappedCb({}, extra)
|
|
744
|
+
: wrappedCb);
|
|
465
745
|
return this;
|
|
466
746
|
}
|
|
467
747
|
}
|