skybridge 0.0.0-dev.bdbb6a7 → 0.0.0-dev.bdcad16
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 +124 -124
- package/dist/cli/build-helpers.d.ts +10 -0
- package/dist/cli/build-helpers.js +93 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +89 -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 +68 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.d.ts +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/header.js.map +1 -1
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/run-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/start-tunnel-view-build.d.ts +13 -0
- package/dist/cli/start-tunnel-view-build.js +28 -0
- package/dist/cli/start-tunnel-view-build.js.map +1 -0
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/tunnel-control-server.js.map +1 -1
- package/dist/cli/tunnel-control-server.test.js.map +1 -1
- package/dist/cli/tunnel-handler.js.map +1 -1
- package/dist/cli/tunnel-handler.test.js.map +1 -1
- package/dist/cli/tunnel.js +2 -2
- package/dist/cli/tunnel.js.map +1 -1
- package/dist/cli/tunnel.test.js.map +1 -1
- 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 +14 -0
- package/dist/cli/use-nodemon.js +72 -52
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-open-browser.js.map +1 -1
- 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 -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 +61 -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/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/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 +18 -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 +18 -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 +48 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +16 -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 +28 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +24 -0
- package/dist/server/auth/providers/custom.js +37 -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 +107 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +15 -0
- package/dist/server/auth/providers/descope.js +33 -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 +37 -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 +12 -0
- package/dist/server/auth/providers/stytch.js +13 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +12 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -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 +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -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 +100 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth.d.ts +20 -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/content-helpers.test.js.map +1 -1
- package/dist/server/express.d.ts +1 -5
- package/dist/server/express.js +13 -4
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +214 -71
- 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/index.d.ts +11 -2
- package/dist/server/index.js +9 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js.map +1 -1
- 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 +242 -8
- package/dist/server/server.js +380 -177
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js.map +1 -1
- package/dist/server/tunnel-proxy-router.js.map +1 -1
- package/dist/server/tunnel-proxy-router.test.js.map +1 -1
- 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 +212 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +109 -96
- package/dist/test/view.test.js.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +330 -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 +208 -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 +68 -4
- 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.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/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 +108 -3
- 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 +17 -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/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 +4 -0
- package/dist/web/hooks/index.js +4 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +6 -2
- package/dist/web/hooks/test/utils.js +13 -2
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +62 -27
- 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-d.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-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 +19 -1
- package/dist/web/hooks/use-send-follow-up-message.js +19 -2
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +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.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +6 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/index.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/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +28 -0
- package/dist/web/plugin/plugin.js +33 -0
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.js.map +1 -1
- package/dist/web/plugin/scan-views.test.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
- package/dist/web/plugin/validate-view.js.map +1 -1
- package/dist/web/plugin/validate-view.test.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 +25 -16
- 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/server/server.js
CHANGED
|
@@ -5,9 +5,12 @@ import path from "node:path";
|
|
|
5
5
|
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
|
+
import express, {} from "express";
|
|
9
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
8
10
|
import { createApp } from "./express.js";
|
|
9
11
|
import { createMiddlewareEntry } from "./metric.js";
|
|
10
12
|
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
13
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
11
14
|
import { templateHelper } from "./templateHelper.js";
|
|
12
15
|
const mergeWithUnion = (target, source) => {
|
|
13
16
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -16,6 +19,34 @@ const mergeWithUnion = (target, source) => {
|
|
|
16
19
|
}
|
|
17
20
|
});
|
|
18
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
24
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
25
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
26
|
+
*/
|
|
27
|
+
function normalizeForwardedPrefix(raw) {
|
|
28
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
29
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
30
|
+
if (trimmed === "") {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
37
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
38
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
39
|
+
*/
|
|
40
|
+
function stripQuery(uri) {
|
|
41
|
+
const queryIndex = uri.indexOf("?");
|
|
42
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
46
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
47
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
48
|
+
* who build content lazily can apply the same normalization.
|
|
49
|
+
*/
|
|
19
50
|
export function normalizeContent(content) {
|
|
20
51
|
if (content === undefined) {
|
|
21
52
|
return [];
|
|
@@ -29,32 +60,109 @@ export function normalizeContent(content) {
|
|
|
29
60
|
return [content];
|
|
30
61
|
}
|
|
31
62
|
const McpServerBaseOmitted = McpServerBase;
|
|
63
|
+
/**
|
|
64
|
+
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
65
|
+
* registry, view resources, an embedded Express app, and protocol-level
|
|
66
|
+
* middleware. Construct it with the same `Implementation` info you would pass
|
|
67
|
+
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
68
|
+
* then call {@link McpServer.run} to start the HTTP server.
|
|
69
|
+
*
|
|
70
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
71
|
+
* shape, so `typeof server` carries enough information for view-side helpers
|
|
72
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
73
|
+
*
|
|
74
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
75
|
+
* chaining; you almost never set this manually.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
80
|
+
* .registerTool({
|
|
81
|
+
* name: "search",
|
|
82
|
+
* inputSchema: { query: z.string() },
|
|
83
|
+
* view: { component: "search" },
|
|
84
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
85
|
+
*
|
|
86
|
+
* await server.run();
|
|
87
|
+
* export type AppType = typeof server;
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
91
|
+
*/
|
|
92
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
93
|
+
// Set at module scope rather than passed through the constructor because the
|
|
94
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
95
|
+
// threading it through every call site (including user templates) is exactly
|
|
96
|
+
// the boilerplate this design is trying to hide.
|
|
97
|
+
let pendingBuildManifest = null;
|
|
98
|
+
/**
|
|
99
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
100
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
101
|
+
* user-facing API.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export function __setBuildManifest(manifest) {
|
|
106
|
+
pendingBuildManifest = manifest;
|
|
107
|
+
}
|
|
32
108
|
export class McpServer extends McpServerBaseOmitted {
|
|
109
|
+
/**
|
|
110
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
111
|
+
* custom routes, middleware, or settings — e.g.
|
|
112
|
+
* `server.express.get("/health", ...)`.
|
|
113
|
+
*
|
|
114
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
115
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
116
|
+
* Register your handlers before `run()`;
|
|
117
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
118
|
+
* error handler are appended in that order.
|
|
119
|
+
*
|
|
120
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
121
|
+
* locally and on self-hosted deployments.
|
|
122
|
+
*/
|
|
33
123
|
express;
|
|
34
|
-
customMiddleware = [];
|
|
35
124
|
customErrorMiddleware = [];
|
|
36
125
|
mcpMiddlewareEntries = [];
|
|
37
126
|
mcpMiddlewareApplied = false;
|
|
38
127
|
claimedViews = new Map();
|
|
128
|
+
viewMetaBuilders = new Map();
|
|
129
|
+
/**
|
|
130
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
131
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
132
|
+
* underlying view no matter which version param the consumer sends, since
|
|
133
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
134
|
+
*/
|
|
135
|
+
viewUriByPath = new Map();
|
|
39
136
|
viteManifest = null;
|
|
40
137
|
serverInfo;
|
|
41
138
|
serverOptions;
|
|
42
|
-
constructor(serverInfo, options) {
|
|
139
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
43
140
|
super(serverInfo, options);
|
|
44
141
|
this.serverInfo = serverInfo;
|
|
45
142
|
this.serverOptions = options;
|
|
143
|
+
this.express = express();
|
|
144
|
+
this.express.use(express.json(skybridgeOptions?.json));
|
|
145
|
+
if (skybridgeOptions?.oauth) {
|
|
146
|
+
setupOAuth(this.express, skybridgeOptions.oauth);
|
|
147
|
+
}
|
|
148
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
149
|
+
// user code. Consume-once: clear after the first construction so a
|
|
150
|
+
// subsequent test that doesn't prime can't inherit stale state.
|
|
151
|
+
// Explicit `setViteManifest` calls still win because they happen after
|
|
152
|
+
// construction.
|
|
153
|
+
if (pendingBuildManifest) {
|
|
154
|
+
this.setViteManifest(pendingBuildManifest);
|
|
155
|
+
pendingBuildManifest = null;
|
|
156
|
+
}
|
|
46
157
|
}
|
|
47
158
|
use(pathOrHandler, ...handlers) {
|
|
159
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
160
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
48
161
|
if (typeof pathOrHandler === "string") {
|
|
49
|
-
this.
|
|
50
|
-
path: pathOrHandler,
|
|
51
|
-
handlers,
|
|
52
|
-
});
|
|
162
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
53
163
|
}
|
|
54
164
|
else {
|
|
55
|
-
this.
|
|
56
|
-
handlers: [pathOrHandler, ...handlers],
|
|
57
|
-
});
|
|
165
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
58
166
|
}
|
|
59
167
|
return this;
|
|
60
168
|
}
|
|
@@ -98,10 +206,69 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
98
206
|
return;
|
|
99
207
|
}
|
|
100
208
|
this.mcpMiddlewareApplied = true;
|
|
209
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
210
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
211
|
+
const viewListMetaEntry = {
|
|
212
|
+
filter: "resources/list",
|
|
213
|
+
handler: async (_req, extra, next) => {
|
|
214
|
+
const result = (await next());
|
|
215
|
+
for (const resource of result.resources) {
|
|
216
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
217
|
+
if (!builder) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const meta = builder(extra);
|
|
221
|
+
resource._meta = {
|
|
222
|
+
...(resource._meta ?? {}),
|
|
223
|
+
...meta,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
230
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
231
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
232
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
233
|
+
// canonical registered one, then restore the requested URI on the response
|
|
234
|
+
// so the consumer-facing URI is never rewritten.
|
|
235
|
+
const viewReadResolveEntry = {
|
|
236
|
+
filter: "resources/read",
|
|
237
|
+
handler: async (req, _extra, next) => {
|
|
238
|
+
const requested = req.params.uri;
|
|
239
|
+
if (typeof requested !== "string") {
|
|
240
|
+
return next();
|
|
241
|
+
}
|
|
242
|
+
const path = stripQuery(requested);
|
|
243
|
+
const canonical = this.viewUriByPath.get(path);
|
|
244
|
+
if (!canonical) {
|
|
245
|
+
return next();
|
|
246
|
+
}
|
|
247
|
+
req.params.uri = canonical;
|
|
248
|
+
try {
|
|
249
|
+
const result = (await next());
|
|
250
|
+
for (const content of result.contents ?? []) {
|
|
251
|
+
if (typeof content.uri === "string" &&
|
|
252
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
253
|
+
content.uri = requested;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
// Restore the shared request params so middleware outer to us never
|
|
260
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
261
|
+
req.params.uri = requested;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
};
|
|
101
265
|
const monitoringEntry = createMiddlewareEntry();
|
|
102
|
-
const entries =
|
|
103
|
-
? [monitoringEntry
|
|
104
|
-
|
|
266
|
+
const entries = [
|
|
267
|
+
...(monitoringEntry ? [monitoringEntry] : []),
|
|
268
|
+
viewListMetaEntry,
|
|
269
|
+
viewReadResolveEntry,
|
|
270
|
+
...this.mcpMiddlewareEntries,
|
|
271
|
+
];
|
|
105
272
|
if (entries.length === 0) {
|
|
106
273
|
return;
|
|
107
274
|
}
|
|
@@ -116,6 +283,14 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
116
283
|
instrumentMap(requestHandlers, false);
|
|
117
284
|
instrumentMap(notificationHandlers, true);
|
|
118
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
288
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
289
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
290
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
291
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
292
|
+
* throw afterwards.
|
|
293
|
+
*/
|
|
119
294
|
async connect(transport) {
|
|
120
295
|
this.applyMcpMiddleware();
|
|
121
296
|
return McpServerBase.prototype.connect.call(this, transport);
|
|
@@ -139,17 +314,38 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
139
314
|
target._notificationHandlers = notificationHandlers;
|
|
140
315
|
await fresh.connect(transport);
|
|
141
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
319
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
320
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
321
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
322
|
+
*
|
|
323
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
324
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
325
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
326
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
327
|
+
* Node, returns `undefined` once listening.
|
|
328
|
+
*/
|
|
142
329
|
async run() {
|
|
143
330
|
this.applyMcpMiddleware();
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
331
|
+
if (process.env.VERCEL === "1") {
|
|
332
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
333
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
334
|
+
// bare object passed to satisfy the required parameter.
|
|
335
|
+
const httpServer = http.createServer();
|
|
336
|
+
await createApp({
|
|
147
337
|
mcpServer: this,
|
|
148
338
|
httpServer,
|
|
149
|
-
customMiddleware: this.customMiddleware,
|
|
150
339
|
errorMiddleware: this.customErrorMiddleware,
|
|
151
340
|
});
|
|
341
|
+
return this.express;
|
|
152
342
|
}
|
|
343
|
+
const httpServer = http.createServer();
|
|
344
|
+
await createApp({
|
|
345
|
+
mcpServer: this,
|
|
346
|
+
httpServer,
|
|
347
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
348
|
+
});
|
|
153
349
|
httpServer.on("request", this.express);
|
|
154
350
|
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
155
351
|
await new Promise((resolve, reject) => {
|
|
@@ -191,189 +387,188 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
191
387
|
}
|
|
192
388
|
this.claimedViews.set(component, toolName);
|
|
193
389
|
}
|
|
390
|
+
resolveViewRequestContext(extra) {
|
|
391
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
392
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
393
|
+
const header = (key) => {
|
|
394
|
+
const val = headers[key];
|
|
395
|
+
return Array.isArray(val) ? val[0] : val;
|
|
396
|
+
};
|
|
397
|
+
const isClaude = header("user-agent") === "Claude-User";
|
|
398
|
+
const serverUrl = resolveServerOrigin(header);
|
|
399
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
400
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
401
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
402
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
403
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
404
|
+
const connectDomains = [serverUrl];
|
|
405
|
+
if (!isProduction) {
|
|
406
|
+
const wsUrl = new URL(serverUrl);
|
|
407
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
408
|
+
connectDomains.push(wsUrl.origin);
|
|
409
|
+
}
|
|
410
|
+
let contentMetaOverrides = {};
|
|
411
|
+
if (isClaude) {
|
|
412
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
413
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
414
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
415
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
416
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
417
|
+
const hash = crypto
|
|
418
|
+
.createHash("sha256")
|
|
419
|
+
.update(url)
|
|
420
|
+
.digest("hex")
|
|
421
|
+
.slice(0, 32);
|
|
422
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
423
|
+
}
|
|
424
|
+
// In dev, serve remote hosts the bundled build instead of the unbundled
|
|
425
|
+
// dev entry — the per-module waterfall is what makes the first render slow
|
|
426
|
+
// through the tunnel. A remote origin in dev means the request came through
|
|
427
|
+
// a tunnel (started via `--tunnel` or the DevTools UI), which is what the
|
|
428
|
+
// CLI keys the watch build off. Localhost/DevTools keep the unbundled entry
|
|
429
|
+
// so HMR is untouched.
|
|
430
|
+
const isLocalhost = serverUrl.startsWith("http://localhost") ||
|
|
431
|
+
serverUrl.startsWith("http://127.0.0.1");
|
|
432
|
+
const useBundledDevTemplate = !isProduction && !isLocalhost;
|
|
433
|
+
return {
|
|
434
|
+
serverUrl,
|
|
435
|
+
assetsBasePath,
|
|
436
|
+
connectDomains,
|
|
437
|
+
contentMetaOverrides,
|
|
438
|
+
useBundledDevTemplate,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
194
441
|
registerViewResources(toolName, view, toolMeta) {
|
|
195
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
196
442
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
197
443
|
// their cache when the bundle changes, but keep the URI stable across
|
|
198
444
|
// `tools/list` calls when the bundle hasn't changed.
|
|
199
445
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
"openai/widgetDomain": domain,
|
|
212
|
-
"openai/widgetDescription": view.description,
|
|
213
|
-
};
|
|
214
|
-
const fromView = {
|
|
215
|
-
"openai/widgetCSP": {
|
|
216
|
-
resource_domains: view.csp?.resourceDomains,
|
|
217
|
-
connect_domains: view.csp?.connectDomains,
|
|
218
|
-
frame_domains: view.csp?.frameDomains,
|
|
219
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
220
|
-
},
|
|
221
|
-
"openai/widgetDomain": view.domain,
|
|
222
|
-
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
223
|
-
};
|
|
224
|
-
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
225
|
-
"openai/widgetDomain": overrides.domain,
|
|
226
|
-
});
|
|
227
|
-
if (view._meta) {
|
|
228
|
-
return { ...base, ...view._meta };
|
|
229
|
-
}
|
|
230
|
-
return base;
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
this.registerViewResource({
|
|
234
|
-
name: toolName,
|
|
235
|
-
viewResource,
|
|
236
|
-
view,
|
|
237
|
-
});
|
|
238
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
239
|
-
}
|
|
240
|
-
if (hosts.includes("mcp-app")) {
|
|
241
|
-
const viewResource = {
|
|
242
|
-
hostType: "mcp-app",
|
|
243
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
244
|
-
mimeType: "text/html;profile=mcp-app",
|
|
245
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
246
|
-
const defaults = {
|
|
247
|
-
ui: {
|
|
248
|
-
csp: {
|
|
249
|
-
resourceDomains,
|
|
250
|
-
connectDomains,
|
|
251
|
-
baseUriDomains,
|
|
252
|
-
},
|
|
253
|
-
domain,
|
|
446
|
+
const viewResource = {
|
|
447
|
+
hostType: "mcp-app",
|
|
448
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
449
|
+
mimeType: "text/html;profile=mcp-app",
|
|
450
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
451
|
+
const defaults = {
|
|
452
|
+
ui: {
|
|
453
|
+
csp: {
|
|
454
|
+
resourceDomains,
|
|
455
|
+
connectDomains,
|
|
456
|
+
baseUriDomains,
|
|
254
457
|
},
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
458
|
+
domain,
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
const fromView = {
|
|
462
|
+
ui: {
|
|
463
|
+
...(view.description && { description: view.description }),
|
|
464
|
+
...(view.prefersBorder !== undefined && {
|
|
465
|
+
prefersBorder: view.prefersBorder,
|
|
466
|
+
}),
|
|
467
|
+
...(view.domain && { domain: view.domain }),
|
|
468
|
+
csp: {
|
|
469
|
+
...(view.csp?.resourceDomains && {
|
|
470
|
+
resourceDomains: view.csp.resourceDomains,
|
|
471
|
+
}),
|
|
472
|
+
...(view.csp?.connectDomains && {
|
|
473
|
+
connectDomains: view.csp.connectDomains,
|
|
474
|
+
}),
|
|
475
|
+
...(view.csp?.frameDomains && {
|
|
476
|
+
frameDomains: view.csp.frameDomains,
|
|
477
|
+
}),
|
|
478
|
+
...(view.csp?.baseUriDomains && {
|
|
479
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
261
480
|
}),
|
|
262
|
-
...(view.domain && { domain: view.domain }),
|
|
263
|
-
csp: {
|
|
264
|
-
...(view.csp?.resourceDomains && {
|
|
265
|
-
resourceDomains: view.csp.resourceDomains,
|
|
266
|
-
}),
|
|
267
|
-
...(view.csp?.connectDomains && {
|
|
268
|
-
connectDomains: view.csp.connectDomains,
|
|
269
|
-
}),
|
|
270
|
-
...(view.csp?.frameDomains && {
|
|
271
|
-
frameDomains: view.csp.frameDomains,
|
|
272
|
-
}),
|
|
273
|
-
...(view.csp?.baseUriDomains && {
|
|
274
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
275
|
-
}),
|
|
276
|
-
...(view.csp?.redirectDomains && {
|
|
277
|
-
redirectDomains: view.csp.redirectDomains,
|
|
278
|
-
}),
|
|
279
|
-
},
|
|
280
481
|
},
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
485
|
+
ui: overrides,
|
|
486
|
+
});
|
|
487
|
+
const base = {
|
|
488
|
+
...ui,
|
|
489
|
+
...(view.description && {
|
|
490
|
+
"openai/widgetDescription": view.description,
|
|
491
|
+
}),
|
|
492
|
+
...(view.csp?.redirectDomains && {
|
|
493
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
494
|
+
}),
|
|
495
|
+
};
|
|
496
|
+
if (view._meta) {
|
|
497
|
+
return { ...base, ...view._meta };
|
|
498
|
+
}
|
|
499
|
+
return base;
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
503
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
504
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
505
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
506
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
507
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
508
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
509
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
300
510
|
}
|
|
301
511
|
registerViewResource({ name, viewResource, view, }) {
|
|
302
512
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
513
|
+
const buildMeta = (extra) => {
|
|
514
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
515
|
+
return buildContentMeta({
|
|
516
|
+
resourceDomains: [serverUrl],
|
|
517
|
+
connectDomains,
|
|
518
|
+
domain: serverUrl,
|
|
519
|
+
baseUriDomains: [serverUrl],
|
|
520
|
+
}, contentMetaOverrides);
|
|
521
|
+
};
|
|
522
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
523
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
524
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
303
525
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
304
526
|
const isProduction = process.env.NODE_ENV === "production";
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
527
|
+
const { serverUrl, assetsBasePath, useBundledDevTemplate } = this.resolveViewRequestContext(extra);
|
|
528
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
529
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
530
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
531
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
532
|
+
const renderBundled = () => templateHelper.renderProduction({
|
|
533
|
+
hostType,
|
|
534
|
+
serverUrl: viewBase,
|
|
535
|
+
viewFile: this.lookupViewFile(view.component),
|
|
536
|
+
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
537
|
+
});
|
|
538
|
+
const renderUnbundled = () => templateHelper.renderDevelopment({
|
|
539
|
+
hostType,
|
|
540
|
+
serverUrl: viewBase,
|
|
541
|
+
viewName: view.component,
|
|
542
|
+
});
|
|
543
|
+
let html;
|
|
544
|
+
if (isProduction) {
|
|
545
|
+
html = renderBundled();
|
|
321
546
|
}
|
|
322
|
-
else if (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
547
|
+
else if (useBundledDevTemplate) {
|
|
548
|
+
try {
|
|
549
|
+
html = renderBundled();
|
|
550
|
+
}
|
|
551
|
+
catch {
|
|
552
|
+
// The watch build hasn't emitted a manifest yet — fall back to the
|
|
553
|
+
// unbundled dev entry so the first render still works (just slow).
|
|
554
|
+
html = renderUnbundled();
|
|
555
|
+
}
|
|
327
556
|
}
|
|
328
557
|
else {
|
|
329
|
-
|
|
330
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
558
|
+
html = renderUnbundled();
|
|
331
559
|
}
|
|
332
|
-
const html = isProduction
|
|
333
|
-
? templateHelper.renderProduction({
|
|
334
|
-
hostType,
|
|
335
|
-
serverUrl,
|
|
336
|
-
viewFile: this.lookupViewFile(view.component),
|
|
337
|
-
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
338
|
-
})
|
|
339
|
-
: templateHelper.renderDevelopment({
|
|
340
|
-
hostType,
|
|
341
|
-
serverUrl,
|
|
342
|
-
viewName: view.component,
|
|
343
|
-
});
|
|
344
|
-
const connectDomains = [serverUrl];
|
|
345
|
-
if (!isProduction) {
|
|
346
|
-
const wsUrl = new URL(serverUrl);
|
|
347
|
-
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
348
|
-
connectDomains.push(wsUrl.origin);
|
|
349
|
-
}
|
|
350
|
-
let contentMetaOverrides = {};
|
|
351
|
-
if (isClaude) {
|
|
352
|
-
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
353
|
-
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
354
|
-
// Strip a lone trailing slash so the hash matches the connector URL
|
|
355
|
-
// as registered with Claude (which has no trailing slash on bare origins).
|
|
356
|
-
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
357
|
-
const hash = crypto
|
|
358
|
-
.createHash("sha256")
|
|
359
|
-
.update(url)
|
|
360
|
-
.digest("hex")
|
|
361
|
-
.slice(0, 32);
|
|
362
|
-
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
363
|
-
}
|
|
364
|
-
const contentMeta = buildContentMeta({
|
|
365
|
-
resourceDomains: [serverUrl],
|
|
366
|
-
connectDomains,
|
|
367
|
-
domain: serverUrl,
|
|
368
|
-
baseUriDomains: [serverUrl],
|
|
369
|
-
}, contentMetaOverrides);
|
|
370
560
|
return {
|
|
371
561
|
contents: [
|
|
372
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
562
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
373
563
|
],
|
|
374
564
|
};
|
|
375
565
|
});
|
|
376
566
|
}
|
|
567
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
568
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
569
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
570
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
571
|
+
}
|
|
377
572
|
wrapHandler(cb, { attachViewUUID }) {
|
|
378
573
|
return async (args, extra) => {
|
|
379
574
|
const result = await cb(args, extra);
|
|
@@ -446,8 +641,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
446
641
|
}
|
|
447
642
|
const config = args[0];
|
|
448
643
|
const cb = args[1];
|
|
449
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
644
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
450
645
|
const toolMeta = { ...userToolMeta };
|
|
646
|
+
if (securitySchemes) {
|
|
647
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
648
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
649
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
650
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
651
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
652
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
653
|
+
}
|
|
451
654
|
if (view) {
|
|
452
655
|
this.enforceOneToolPerView(view.component, name);
|
|
453
656
|
this.registerViewResources(name, view, toolMeta);
|