skybridge 0.0.0-dev.f29d75c → 0.0.0-dev.f2d6084
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 +123 -116
- package/dist/cli/build-helpers.d.ts +7 -0
- package/dist/cli/build-helpers.js +82 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +64 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +50 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.js +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/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.d.ts +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.d.ts +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +2 -6
- package/dist/cli/use-nodemon.js +18 -14
- 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-open-tunnel-browser.d.ts +6 -0
- package/dist/cli/use-open-tunnel-browser.js +19 -0
- package/dist/cli/use-open-tunnel-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +1 -0
- package/dist/cli/use-typescript-check.js +42 -7
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +52 -8
- 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 +4 -1
- package/dist/commands/dev.js +75 -8
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +34 -12
- 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 +6 -6
- package/dist/server/asset-base-url-transform-plugin.js +25 -11
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- 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 +67 -0
- package/dist/server/content-helpers.js +79 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +7 -5
- package/dist/server/express.js +52 -23
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +411 -25
- 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 +7 -3
- package/dist/server/index.js +5 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +137 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +340 -64
- package/dist/server/server.js +507 -102
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +5 -8
- 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 +47 -0
- package/dist/server/templates.generated.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/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +13 -21
- package/dist/test/utils.js +42 -37
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +568 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +14 -7
- package/dist/web/bridges/apps-sdk/adaptor.js +66 -29
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +2 -1
- package/dist/web/bridges/apps-sdk/bridge.js +1 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +26 -11
- 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 +7 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +26 -9
- package/dist/web/bridges/mcp-app/adaptor.js +159 -66
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +16 -31
- package/dist/web/bridges/mcp-app/bridge.js +65 -201
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -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 +17 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
- 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 -41
- 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 +144 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +120 -14
- package/dist/web/bridges/types.js.map +1 -1
- 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.js +3 -5
- 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 +43 -3
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +21 -18
- 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 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +24 -23
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -18
- package/dist/web/generate-helpers.js +22 -18
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +26 -26
- 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.d.ts +2 -2
- package/dist/web/helpers/state.js +11 -11
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +6 -2
- package/dist/web/hooks/index.js +5 -1
- 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 +17 -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 +27 -6
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +23 -3
- 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.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.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 +95 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +34 -1
- package/dist/web/hooks/use-files.js +33 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +22 -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 +3 -3
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +20 -1
- package/dist/web/hooks/use-open-external.js +17 -1
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +26 -11
- 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 +52 -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 +19 -4
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +5 -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 +65 -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 +5 -11
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +33 -0
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +1 -1
- 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 +20 -2
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +29 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +25 -0
- package/dist/web/hooks/use-view-state.js +32 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +177 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -2
- package/dist/web/index.js +1 -2
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +20 -0
- package/dist/web/{mount-widget.js → mount-view.js} +21 -2
- package/dist/web/mount-view.js.map +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +32 -1
- package/dist/web/plugin/plugin.js +161 -18
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +16 -0
- package/dist/web/plugin/scan-views.js +88 -0
- package/dist/web/plugin/scan-views.js.map +1 -0
- package/dist/web/plugin/scan-views.test.d.ts +1 -0
- package/dist/web/plugin/scan-views.test.js +99 -0
- package/dist/web/plugin/scan-views.test.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.js +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.d.ts +1 -0
- package/dist/web/plugin/validate-view.js +9 -0
- package/dist/web/plugin/validate-view.js.map +1 -0
- package/dist/web/plugin/validate-view.test.d.ts +1 -0
- package/dist/web/plugin/validate-view.test.js +24 -0
- package/dist/web/plugin/validate-view.test.js.map +1 -0
- 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 +39 -23
- package/tsconfig.base.json +5 -0
- package/dist/server/templates/development.hbs +0 -67
- package/dist/server/templates/production.hbs +0 -6
- package/dist/server/widgetsDevServer.d.ts +0 -12
- package/dist/server/widgetsDevServer.js +0 -57
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -261
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/web/hooks/use-widget-state.js +0 -32
- package/dist/web/hooks/use-widget-state.js.map +0 -1
- package/dist/web/hooks/use-widget-state.test.js +0 -62
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
JsonRpcErrorCode[JsonRpcErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
6
|
-
JsonRpcErrorCode[JsonRpcErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
7
|
-
JsonRpcErrorCode[JsonRpcErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
8
|
-
JsonRpcErrorCode[JsonRpcErrorCode["InternalError"] = -32603] = "InternalError";
|
|
9
|
-
})(JsonRpcErrorCode || (JsonRpcErrorCode = {}));
|
|
1
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */
|
|
10
5
|
export class McpAppBridge {
|
|
11
6
|
static instance = null;
|
|
12
7
|
context = {
|
|
@@ -15,34 +10,77 @@ export class McpAppBridge {
|
|
|
15
10
|
toolResult: null,
|
|
16
11
|
};
|
|
17
12
|
listeners = new Map();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
this.appInitializationOptions = {
|
|
28
|
-
appInfo: options.appInfo,
|
|
29
|
-
appCapabilities: {},
|
|
30
|
-
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
13
|
+
app;
|
|
14
|
+
connectPromise;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.app = new App(options.appInfo, { tools: { listChanged: true } });
|
|
17
|
+
this.app.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
18
|
+
tools: [],
|
|
19
|
+
}));
|
|
20
|
+
this.app.ontoolinput = (params) => {
|
|
21
|
+
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
31
22
|
};
|
|
32
|
-
this.
|
|
23
|
+
this.app.ontoolinputpartial = (params) => {
|
|
24
|
+
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
25
|
+
};
|
|
26
|
+
this.app.ontoolresult = (params) => {
|
|
27
|
+
this.updateContext({ toolResult: params });
|
|
28
|
+
};
|
|
29
|
+
this.app.ontoolcancelled = (params) => {
|
|
30
|
+
this.updateContext({ toolCancelled: params });
|
|
31
|
+
};
|
|
32
|
+
this.app.onhostcontextchanged = (params) => {
|
|
33
|
+
this.updateContext(params);
|
|
34
|
+
};
|
|
35
|
+
this.connectPromise = this.connect();
|
|
36
|
+
}
|
|
37
|
+
async connect() {
|
|
38
|
+
try {
|
|
39
|
+
await this.app.connect();
|
|
40
|
+
const hostContext = this.app.getHostContext();
|
|
41
|
+
if (hostContext) {
|
|
42
|
+
this.updateContext(hostContext);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.error(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async getApp() {
|
|
50
|
+
await this.connectPromise;
|
|
51
|
+
return this.app;
|
|
33
52
|
}
|
|
34
|
-
|
|
53
|
+
registerViewTool(config, handler) {
|
|
54
|
+
const inputSchema = config.inputSchema
|
|
55
|
+
? z.object(config.inputSchema)
|
|
56
|
+
: z.object({});
|
|
57
|
+
const registered = this.app.registerTool(config.name, {
|
|
58
|
+
...(config.title !== undefined ? { title: config.title } : {}),
|
|
59
|
+
...(config.description !== undefined
|
|
60
|
+
? { description: config.description }
|
|
61
|
+
: {}),
|
|
62
|
+
inputSchema,
|
|
63
|
+
...(config.annotations ? { annotations: config.annotations } : {}),
|
|
64
|
+
}, handler);
|
|
65
|
+
return () => {
|
|
66
|
+
registered.remove();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
static getInstance(options) {
|
|
35
70
|
if (window.skybridge.hostType !== "mcp-app") {
|
|
36
71
|
throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
|
|
37
72
|
}
|
|
38
|
-
if (McpAppBridge.instance &&
|
|
39
|
-
console.warn("McpAppBridge.getInstance: options
|
|
73
|
+
if (McpAppBridge.instance && options) {
|
|
74
|
+
console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
|
|
40
75
|
}
|
|
41
76
|
if (!McpAppBridge.instance) {
|
|
42
77
|
const defaultOptions = {
|
|
43
78
|
appInfo: { name: "skybridge-app", version: "0.0.1" },
|
|
44
79
|
};
|
|
45
|
-
McpAppBridge.instance = new McpAppBridge({
|
|
80
|
+
McpAppBridge.instance = new McpAppBridge({
|
|
81
|
+
...defaultOptions,
|
|
82
|
+
...options,
|
|
83
|
+
});
|
|
46
84
|
}
|
|
47
85
|
return McpAppBridge.instance;
|
|
48
86
|
}
|
|
@@ -63,14 +101,7 @@ export class McpAppBridge {
|
|
|
63
101
|
return this.context[key];
|
|
64
102
|
}
|
|
65
103
|
cleanup = () => {
|
|
66
|
-
window.removeEventListener("message", this.handleMessage);
|
|
67
|
-
this.pendingRequests.forEach((request) => {
|
|
68
|
-
clearTimeout(request.timeout);
|
|
69
|
-
});
|
|
70
|
-
this.pendingRequests.clear();
|
|
71
104
|
this.listeners.clear();
|
|
72
|
-
this.cleanupSizeObserver?.();
|
|
73
|
-
this.cleanupSizeObserver = null;
|
|
74
105
|
};
|
|
75
106
|
static resetInstance() {
|
|
76
107
|
if (McpAppBridge.instance) {
|
|
@@ -78,20 +109,6 @@ export class McpAppBridge {
|
|
|
78
109
|
McpAppBridge.instance = null;
|
|
79
110
|
}
|
|
80
111
|
}
|
|
81
|
-
request({ method, params, }) {
|
|
82
|
-
const id = this.nextId++;
|
|
83
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
84
|
-
this.pendingRequests.set(id, {
|
|
85
|
-
resolve: resolve,
|
|
86
|
-
reject,
|
|
87
|
-
timeout: setTimeout(() => {
|
|
88
|
-
reject(new Error("Request timed out"));
|
|
89
|
-
this.pendingRequests.delete(id);
|
|
90
|
-
}, this.requestTimeout),
|
|
91
|
-
});
|
|
92
|
-
window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
|
|
93
|
-
return promise;
|
|
94
|
-
}
|
|
95
112
|
emit(key) {
|
|
96
113
|
this.listeners.get(key)?.forEach((listener) => {
|
|
97
114
|
listener();
|
|
@@ -103,158 +120,5 @@ export class McpAppBridge {
|
|
|
103
120
|
this.emit(key);
|
|
104
121
|
}
|
|
105
122
|
}
|
|
106
|
-
init() {
|
|
107
|
-
if (this.initialized) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.initialized = true;
|
|
111
|
-
if (typeof window === "undefined" || window.parent === window) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
window.addEventListener("message", this.handleMessage);
|
|
115
|
-
this.connect();
|
|
116
|
-
}
|
|
117
|
-
handleMessage = (event) => {
|
|
118
|
-
const data = event.data;
|
|
119
|
-
if (data.jsonrpc !== "2.0") {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if ("id" in data) {
|
|
123
|
-
if ("method" in data) {
|
|
124
|
-
this.handleRequest(data);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
this.handleResponse(data);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
this.handleNotification(data);
|
|
131
|
-
};
|
|
132
|
-
handleResponse(response) {
|
|
133
|
-
const request = this.pendingRequests.get(response.id);
|
|
134
|
-
if (request) {
|
|
135
|
-
clearTimeout(request.timeout);
|
|
136
|
-
this.pendingRequests.delete(response.id);
|
|
137
|
-
if ("error" in response) {
|
|
138
|
-
request.reject(new Error(response.error.message));
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
request.resolve(response.result);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
handleNotification = (notification) => {
|
|
145
|
-
switch (notification.method) {
|
|
146
|
-
case "ui/notifications/host-context-changed":
|
|
147
|
-
this.updateContext(notification.params);
|
|
148
|
-
return;
|
|
149
|
-
case "ui/notifications/tool-input-partial":
|
|
150
|
-
this.updateContext({
|
|
151
|
-
toolInput: notification.params.arguments ?? {},
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
154
|
-
case "ui/notifications/tool-input":
|
|
155
|
-
this.updateContext({
|
|
156
|
-
toolInput: notification.params.arguments ?? {},
|
|
157
|
-
});
|
|
158
|
-
return;
|
|
159
|
-
case "ui/notifications/tool-result":
|
|
160
|
-
this.updateContext({
|
|
161
|
-
toolResult: notification.params,
|
|
162
|
-
});
|
|
163
|
-
return;
|
|
164
|
-
case "ui/notifications/tool-cancelled":
|
|
165
|
-
this.updateContext({
|
|
166
|
-
toolCancelled: notification.params,
|
|
167
|
-
});
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
handleRequest = (request) => {
|
|
172
|
-
switch (request.method) {
|
|
173
|
-
case "ui/resource-teardown":
|
|
174
|
-
this.cleanup();
|
|
175
|
-
window.parent.postMessage({
|
|
176
|
-
jsonrpc: "2.0",
|
|
177
|
-
id: request.id,
|
|
178
|
-
result: {},
|
|
179
|
-
}, "*");
|
|
180
|
-
return;
|
|
181
|
-
default:
|
|
182
|
-
window.parent.postMessage({
|
|
183
|
-
jsonrpc: "2.0",
|
|
184
|
-
id: request.id,
|
|
185
|
-
error: {
|
|
186
|
-
code: JsonRpcErrorCode.MethodNotFound,
|
|
187
|
-
message: "Unsupported Request",
|
|
188
|
-
},
|
|
189
|
-
}, "*");
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
async connect() {
|
|
193
|
-
try {
|
|
194
|
-
const result = await this.request({
|
|
195
|
-
method: "ui/initialize",
|
|
196
|
-
params: this.appInitializationOptions,
|
|
197
|
-
});
|
|
198
|
-
this.updateContext(result.hostContext);
|
|
199
|
-
this.notify({ method: "ui/notifications/initialized" });
|
|
200
|
-
this.cleanupSizeObserver = this.setupSizeChangedNotifications();
|
|
201
|
-
}
|
|
202
|
-
catch (err) {
|
|
203
|
-
console.error(err);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
notify(notification) {
|
|
207
|
-
window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
|
|
208
|
-
}
|
|
209
|
-
sendSizeChanged(params) {
|
|
210
|
-
this.notify({ method: "ui/notifications/size-changed", params });
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Set up automatic size change notifications using ResizeObserver.
|
|
214
|
-
* Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
|
|
215
|
-
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
|
|
216
|
-
*/
|
|
217
|
-
setupSizeChangedNotifications() {
|
|
218
|
-
let scheduled = false;
|
|
219
|
-
let lastWidth = 0;
|
|
220
|
-
let lastHeight = 0;
|
|
221
|
-
const sendBodySizeChanged = () => {
|
|
222
|
-
if (scheduled) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
scheduled = true;
|
|
226
|
-
requestAnimationFrame(() => {
|
|
227
|
-
scheduled = false;
|
|
228
|
-
let width;
|
|
229
|
-
let height;
|
|
230
|
-
// In fullscreen mode, use viewport size since the widget should fill
|
|
231
|
-
// the entire available space provided by the host.
|
|
232
|
-
if (this.context.displayMode === "fullscreen") {
|
|
233
|
-
width = window.innerWidth;
|
|
234
|
-
height = window.innerHeight;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
// Use scrollWidth/scrollHeight to measure actual rendered content size.
|
|
238
|
-
// This works better than fit-content for viewport-based layouts (vw/vh)
|
|
239
|
-
// and fluid elements like maps that want to fill available space.
|
|
240
|
-
const body = document.body;
|
|
241
|
-
width = Math.ceil(body.scrollWidth);
|
|
242
|
-
height = Math.ceil(body.scrollHeight);
|
|
243
|
-
}
|
|
244
|
-
// Only send if size actually changed (prevents feedback loops from
|
|
245
|
-
// style changes)
|
|
246
|
-
if (width !== lastWidth || height !== lastHeight) {
|
|
247
|
-
lastWidth = width;
|
|
248
|
-
lastHeight = height;
|
|
249
|
-
this.sendSizeChanged({ width, height });
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
sendBodySizeChanged();
|
|
254
|
-
const resizeObserver = new ResizeObserver(sendBodySizeChanged);
|
|
255
|
-
resizeObserver.observe(document.documentElement);
|
|
256
|
-
resizeObserver.observe(document.body);
|
|
257
|
-
return () => resizeObserver.disconnect();
|
|
258
|
-
}
|
|
259
123
|
}
|
|
260
124
|
//# sourceMappingURL=bridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"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","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport {\n type Implementation,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport * as z from \"zod\";\nimport type {\n AnyViewToolHandler,\n Bridge,\n Subscribe,\n ViewToolConfig,\n} from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo, { tools: { listChanged: true } });\n\n this.app.setRequestHandler(ListToolsRequestSchema, async () => ({\n tools: [],\n }));\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void {\n const inputSchema = config.inputSchema\n ? z.object(config.inputSchema)\n : z.object({});\n\n const registered = this.app.registerTool(\n config.name,\n {\n ...(config.title !== undefined ? { title: config.title } : {}),\n ...(config.description !== undefined\n ? { description: config.description }\n : {}),\n inputSchema,\n ...(config.annotations ? { annotations: config.annotations } : {}),\n },\n handler,\n );\n\n return () => {\n registered.remove();\n };\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (window.skybridge.hostType !== \"mcp-app\") {\n throw new Error(\"MCP App Bridge can only be used in the mcp-app runtime\");\n }\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppAdaptor } from \"./adaptor.js\";\nexport { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n McpUiHostContext,\n McpUiToolCancelledNotification,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\n\nexport type McpToolState = {\n toolInput: NonNullable<\n McpUiToolInputNotification[\"params\"][\"arguments\"]\n > | null;\n toolResult: McpUiToolResultNotification[\"params\"] | null;\n toolCancelled: McpUiToolCancelledNotification[\"params\"] | null;\n};\n\nexport type McpAppContext = McpUiHostContext & McpToolState;\n\nexport type McpAppContextKey = keyof McpAppContext;\n"]}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import type { McpAppContext } from "./types.js";
|
|
3
|
-
type McpAppInitializationOptions =
|
|
4
|
-
|
|
3
|
+
type McpAppInitializationOptions = {
|
|
4
|
+
appInfo: Implementation;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
8
|
+
*
|
|
9
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
10
|
+
* `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
11
|
+
* when you need protocol-level fields not surfaced by the public hooks.
|
|
12
|
+
*
|
|
13
|
+
* `options.appInfo` is honored only on the first call that creates the
|
|
14
|
+
* underlying bridge; subsequent calls reuse the singleton.
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
|
|
17
|
+
*/
|
|
18
|
+
export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
|
|
5
19
|
export {};
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { McpAppBridge } from "./bridge.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
5
|
+
*
|
|
6
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
7
|
+
* `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
8
|
+
* when you need protocol-level fields not surfaced by the public hooks.
|
|
9
|
+
*
|
|
10
|
+
* `options.appInfo` is honored only on the first call that creates the
|
|
11
|
+
* underlying bridge; subsequent calls reuse the singleton.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
|
|
14
|
+
*/
|
|
15
|
+
export function useMcpAppContext(key, options) {
|
|
16
|
+
const bridge = McpAppBridge.getInstance(options);
|
|
5
17
|
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
6
18
|
}
|
|
7
19
|
//# sourceMappingURL=use-mcp-app-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\n/**\n * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,\n * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this\n * when you need protocol-level fields not surfaced by the public hooks.\n *\n * `options.appInfo` is honored only on the first call that creates the\n * underlying bridge; subsequent calls reuse the singleton.\n *\n * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context\n */\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
3
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "../../hooks/test/utils.js";
|
|
4
4
|
import { McpAppBridge } from "./bridge.js";
|
|
@@ -22,45 +22,5 @@ describe("useMcpAppContext", () => {
|
|
|
22
22
|
expect(result.current).toBe("light");
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
-
it("should reject the request after timeout", async () => {
|
|
26
|
-
vi.useFakeTimers();
|
|
27
|
-
const consoleErrorSpy = vi
|
|
28
|
-
.spyOn(console, "error")
|
|
29
|
-
.mockImplementation(() => { });
|
|
30
|
-
const nonRespondingMock = vi.fn();
|
|
31
|
-
vi.stubGlobal("parent", { postMessage: nonRespondingMock });
|
|
32
|
-
renderHook(() => useMcpAppContext("theme", undefined, 100));
|
|
33
|
-
expect(nonRespondingMock).toHaveBeenCalledWith(expect.objectContaining({ method: "ui/initialize" }), "*");
|
|
34
|
-
await act(async () => {
|
|
35
|
-
await vi.advanceTimersByTimeAsync(100);
|
|
36
|
-
});
|
|
37
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(new Error("Request timed out"));
|
|
38
|
-
consoleErrorSpy.mockRestore();
|
|
39
|
-
vi.useRealTimers();
|
|
40
|
-
});
|
|
41
|
-
it("should send size-changed notification after successful initialization", async () => {
|
|
42
|
-
// Mock body dimensions to non-zero (size-changed only sends when dimensions change)
|
|
43
|
-
Object.defineProperty(document.body, "scrollWidth", {
|
|
44
|
-
value: 800,
|
|
45
|
-
configurable: true,
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(document.body, "scrollHeight", {
|
|
48
|
-
value: 600,
|
|
49
|
-
configurable: true,
|
|
50
|
-
});
|
|
51
|
-
const postMessageMock = getMcpAppHostPostMessageMock({ theme: "light" });
|
|
52
|
-
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
53
|
-
renderHook(() => useMcpAppContext("theme"));
|
|
54
|
-
await waitFor(() => {
|
|
55
|
-
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
56
|
-
jsonrpc: "2.0",
|
|
57
|
-
method: "ui/notifications/size-changed",
|
|
58
|
-
params: expect.objectContaining({
|
|
59
|
-
width: expect.any(Number),
|
|
60
|
-
height: expect.any(Number),
|
|
61
|
-
}),
|
|
62
|
-
}), "*");
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
25
|
});
|
|
66
26
|
//# sourceMappingURL=use-mcp-app-context.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-context.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"use-mcp-app-context.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QACpD,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QAE/D,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"../../hooks/test/utils.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n\ndescribe(\"useMcpAppContext\", () => {\n beforeEach(async () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"should return the theme value from host context and update on notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ theme: \"light\" }),\n });\n const { result } = renderHook(() => useMcpAppContext(\"theme\"));\n\n await waitFor(() => {\n expect(result.current).toBe(\"light\");\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { waitFor } from "@testing-library/react";
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
import { MockResizeObserver } from "../../hooks/test/utils.js";
|
|
6
|
+
import { McpAppAdaptor } from "./adaptor.js";
|
|
7
|
+
import { McpAppBridge } from "./bridge.js";
|
|
8
|
+
const outgoing = [];
|
|
9
|
+
/**
|
|
10
|
+
* Stand-in MCP Apps host: replies to `ui/initialize` and records every message
|
|
11
|
+
* the app posts so tests can assert on responses and notifications.
|
|
12
|
+
*/
|
|
13
|
+
function installHostMock() {
|
|
14
|
+
outgoing.length = 0;
|
|
15
|
+
const postMessage = vi.fn((message) => {
|
|
16
|
+
outgoing.push(message);
|
|
17
|
+
if (message.method === "ui/initialize" && message.id !== undefined) {
|
|
18
|
+
act(() => {
|
|
19
|
+
window.dispatchEvent(new MessageEvent("message", {
|
|
20
|
+
source: window.parent,
|
|
21
|
+
data: {
|
|
22
|
+
jsonrpc: "2.0",
|
|
23
|
+
id: message.id,
|
|
24
|
+
result: {
|
|
25
|
+
protocolVersion: "2025-06-18",
|
|
26
|
+
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
27
|
+
hostCapabilities: {},
|
|
28
|
+
hostContext: {},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
vi.stubGlobal("parent", { postMessage });
|
|
36
|
+
}
|
|
37
|
+
let nextId = 1000;
|
|
38
|
+
/** Send a host → app JSON-RPC request and resolve with the full response (result or error). */
|
|
39
|
+
async function callHost(method, params = {}) {
|
|
40
|
+
const id = ++nextId;
|
|
41
|
+
act(() => {
|
|
42
|
+
window.dispatchEvent(new MessageEvent("message", {
|
|
43
|
+
source: window.parent,
|
|
44
|
+
data: { jsonrpc: "2.0", id, method, params },
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
await waitFor(() => {
|
|
48
|
+
expect(outgoing.some((m) => m.id === id)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
return outgoing.find((m) => m.id === id);
|
|
51
|
+
}
|
|
52
|
+
describe("McpApp view tools", () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
55
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
56
|
+
McpAppBridge.resetInstance();
|
|
57
|
+
McpAppAdaptor.resetInstance();
|
|
58
|
+
installHostMock();
|
|
59
|
+
});
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
vi.unstubAllGlobals();
|
|
62
|
+
vi.clearAllMocks();
|
|
63
|
+
});
|
|
64
|
+
it("advertises the tools capability during ui/initialize", async () => {
|
|
65
|
+
await McpAppBridge.getInstance().getApp();
|
|
66
|
+
const init = outgoing.find((m) => m.method === "ui/initialize");
|
|
67
|
+
expect(init?.params?.appCapabilities).toMatchObject({
|
|
68
|
+
tools: { listChanged: true },
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it("lists a registered view tool with its input schema", async () => {
|
|
72
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
73
|
+
await McpAppBridge.getInstance().getApp();
|
|
74
|
+
adaptor.registerViewTool({
|
|
75
|
+
name: "chess_make_move",
|
|
76
|
+
description: "Play a move",
|
|
77
|
+
inputSchema: { san: z.string() },
|
|
78
|
+
annotations: { readOnlyHint: false },
|
|
79
|
+
}, () => ({ content: [{ type: "text", text: "ok" }] }));
|
|
80
|
+
const response = await callHost("tools/list");
|
|
81
|
+
const tools = response?.result?.tools;
|
|
82
|
+
expect(tools).toHaveLength(1);
|
|
83
|
+
const [tool] = tools;
|
|
84
|
+
expect(tool?.name).toBe("chess_make_move");
|
|
85
|
+
expect(tool?.description).toBe("Play a move");
|
|
86
|
+
expect(tool?.inputSchema.properties).toHaveProperty("san");
|
|
87
|
+
expect(tool?.annotations?.readOnlyHint).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
it("invokes the handler with validated args and returns its result", async () => {
|
|
90
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
91
|
+
await McpAppBridge.getInstance().getApp();
|
|
92
|
+
const handler = vi.fn(({ san }) => ({
|
|
93
|
+
content: [{ type: "text", text: `played ${san}` }],
|
|
94
|
+
structuredContent: { lastMove: san },
|
|
95
|
+
}));
|
|
96
|
+
adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
|
|
97
|
+
const response = await callHost("tools/call", {
|
|
98
|
+
name: "chess_make_move",
|
|
99
|
+
arguments: { san: "e4" },
|
|
100
|
+
});
|
|
101
|
+
const result = response?.result;
|
|
102
|
+
// ext-apps invokes the callback as `(args, extra)`; assert on the args only.
|
|
103
|
+
expect(handler.mock.calls[0]?.[0]).toEqual({ san: "e4" });
|
|
104
|
+
expect(result?.structuredContent).toEqual({ lastMove: "e4" });
|
|
105
|
+
expect(result?.isError).toBeFalsy();
|
|
106
|
+
expect(result?.content).toEqual([{ type: "text", text: "played e4" }]);
|
|
107
|
+
});
|
|
108
|
+
it("rejects the call without invoking the handler when args are invalid", async () => {
|
|
109
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
110
|
+
await McpAppBridge.getInstance().getApp();
|
|
111
|
+
const handler = vi.fn(() => ({ content: [] }));
|
|
112
|
+
adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
|
|
113
|
+
// ext-apps validates input against the schema and rejects with a JSON-RPC
|
|
114
|
+
// error before the handler runs.
|
|
115
|
+
const response = await callHost("tools/call", {
|
|
116
|
+
name: "chess_make_move",
|
|
117
|
+
arguments: { san: 42 },
|
|
118
|
+
});
|
|
119
|
+
expect(handler).not.toHaveBeenCalled();
|
|
120
|
+
expect(response?.error).toBeDefined();
|
|
121
|
+
});
|
|
122
|
+
it("rejects a call to an unknown tool", async () => {
|
|
123
|
+
await McpAppBridge.getInstance().getApp();
|
|
124
|
+
const response = await callHost("tools/call", {
|
|
125
|
+
name: "nope",
|
|
126
|
+
arguments: {},
|
|
127
|
+
});
|
|
128
|
+
expect(response?.error).toBeDefined();
|
|
129
|
+
});
|
|
130
|
+
it("removes the tool and notifies the host when unregistered", async () => {
|
|
131
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
132
|
+
await McpAppBridge.getInstance().getApp();
|
|
133
|
+
const unregister = adaptor.registerViewTool({ name: "chess_reset" }, () => ({ content: [{ type: "text", text: "reset" }] }));
|
|
134
|
+
await waitFor(() => {
|
|
135
|
+
expect(outgoing.some((m) => m.method === "notifications/tools/list_changed")).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
let listed = await callHost("tools/list");
|
|
138
|
+
expect(listed?.result?.tools).toHaveLength(1);
|
|
139
|
+
unregister();
|
|
140
|
+
listed = await callHost("tools/list");
|
|
141
|
+
expect(listed?.result?.tools).toHaveLength(0);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
//# sourceMappingURL=view-tools.test.js.map
|