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