skybridge 0.0.0-dev.fec1c58 → 0.0.0-dev.fef24cf
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/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -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/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.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-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.js +63 -7
- 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 +57 -8
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +30 -9
- 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/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 +60 -28
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +381 -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 +358 -69
- package/dist/server/server.js +469 -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 +16 -244
- 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 +13 -7
- package/dist/web/bridges/apps-sdk/adaptor.js +62 -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 +25 -9
- package/dist/web/bridges/mcp-app/adaptor.js +156 -66
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +14 -30
- package/dist/web/bridges/mcp-app/bridge.js +44 -196
- 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/types.d.ts +87 -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 +5 -2
- package/dist/web/hooks/index.js +4 -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-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 +42 -25
- package/tsconfig.base.json +33 -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/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
package/dist/server/server.js
CHANGED
|
@@ -2,9 +2,13 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import http from "node:http";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
|
+
import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
7
|
import { mergeWith, union } from "es-toolkit";
|
|
7
|
-
import {
|
|
8
|
+
import express, {} from "express";
|
|
9
|
+
import { createApp } from "./express.js";
|
|
10
|
+
import { createMiddlewareEntry } from "./metric.js";
|
|
11
|
+
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
8
12
|
import { templateHelper } from "./templateHelper.js";
|
|
9
13
|
const mergeWithUnion = (target, source) => {
|
|
10
14
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -13,182 +17,545 @@ const mergeWithUnion = (target, source) => {
|
|
|
13
17
|
}
|
|
14
18
|
});
|
|
15
19
|
};
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
22
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
23
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
24
|
+
* who build content lazily can apply the same normalization.
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeContent(content) {
|
|
27
|
+
if (content === undefined) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
if (typeof content === "string") {
|
|
31
|
+
return [{ type: "text", text: content }];
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(content)) {
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
return [content];
|
|
37
|
+
}
|
|
38
|
+
const McpServerBaseOmitted = McpServerBase;
|
|
39
|
+
/**
|
|
40
|
+
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
41
|
+
* registry, view resources, an embedded Express app, and protocol-level
|
|
42
|
+
* middleware. Construct it with the same `Implementation` info you would pass
|
|
43
|
+
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
44
|
+
* then call {@link McpServer.run} to start the HTTP server.
|
|
45
|
+
*
|
|
46
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
47
|
+
* shape, so `typeof server` carries enough information for view-side helpers
|
|
48
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
51
|
+
* chaining; you almost never set this manually.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
56
|
+
* .registerTool({
|
|
57
|
+
* name: "search",
|
|
58
|
+
* inputSchema: { query: z.string() },
|
|
59
|
+
* view: { component: "search" },
|
|
60
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
61
|
+
*
|
|
62
|
+
* await server.run();
|
|
63
|
+
* export type AppType = typeof server;
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
67
|
+
*/
|
|
68
|
+
export class McpServer extends McpServerBaseOmitted {
|
|
69
|
+
/**
|
|
70
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
71
|
+
* custom routes, middleware, or settings — e.g.
|
|
72
|
+
* `server.express.get("/health", ...)`.
|
|
73
|
+
*
|
|
74
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
75
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
76
|
+
* error handler are appended in that order.
|
|
77
|
+
*
|
|
78
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
79
|
+
* locally and on self-hosted deployments.
|
|
80
|
+
*/
|
|
17
81
|
express;
|
|
18
|
-
|
|
82
|
+
customErrorMiddleware = [];
|
|
83
|
+
mcpMiddlewareEntries = [];
|
|
84
|
+
mcpMiddlewareApplied = false;
|
|
85
|
+
claimedViews = new Map();
|
|
86
|
+
viewMetaBuilders = new Map();
|
|
87
|
+
viteManifest = null;
|
|
88
|
+
serverInfo;
|
|
89
|
+
serverOptions;
|
|
90
|
+
constructor(serverInfo, options) {
|
|
91
|
+
super(serverInfo, options);
|
|
92
|
+
this.serverInfo = serverInfo;
|
|
93
|
+
this.serverOptions = options;
|
|
94
|
+
this.express = express();
|
|
95
|
+
this.express.use(express.json());
|
|
96
|
+
}
|
|
19
97
|
use(pathOrHandler, ...handlers) {
|
|
98
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
99
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
20
100
|
if (typeof pathOrHandler === "string") {
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
101
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
105
|
+
}
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
useOnError(pathOrHandler, ...handlers) {
|
|
109
|
+
if (typeof pathOrHandler === "string") {
|
|
110
|
+
this.customErrorMiddleware.push({ path: pathOrHandler, handlers });
|
|
25
111
|
}
|
|
26
112
|
else {
|
|
27
|
-
this.
|
|
113
|
+
this.customErrorMiddleware.push({
|
|
28
114
|
handlers: [pathOrHandler, ...handlers],
|
|
29
115
|
});
|
|
30
116
|
}
|
|
31
117
|
return this;
|
|
32
118
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
119
|
+
mcpMiddleware(filterOrHandler,
|
|
120
|
+
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
121
|
+
maybeHandler) {
|
|
122
|
+
if (this.mcpMiddlewareApplied) {
|
|
123
|
+
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
124
|
+
}
|
|
125
|
+
const handler = maybeHandler;
|
|
126
|
+
if (typeof filterOrHandler === "function") {
|
|
127
|
+
this.mcpMiddlewareEntries.push({
|
|
128
|
+
filter: null,
|
|
129
|
+
handler: filterOrHandler,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else if (handler) {
|
|
133
|
+
this.mcpMiddlewareEntries.push({
|
|
134
|
+
filter: filterOrHandler,
|
|
135
|
+
handler,
|
|
38
136
|
});
|
|
39
137
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
138
|
+
else {
|
|
139
|
+
throw new Error("mcpMiddleware requires a handler function when a filter is provided");
|
|
140
|
+
}
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
applyMcpMiddleware() {
|
|
144
|
+
if (this.mcpMiddlewareApplied) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this.mcpMiddlewareApplied = true;
|
|
148
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
149
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
150
|
+
const viewListMetaEntry = {
|
|
151
|
+
filter: "resources/list",
|
|
152
|
+
handler: async (_req, extra, next) => {
|
|
153
|
+
const result = (await next());
|
|
154
|
+
for (const resource of result.resources) {
|
|
155
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
156
|
+
if (!builder) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const meta = builder(extra);
|
|
160
|
+
resource._meta = {
|
|
161
|
+
...(resource._meta ?? {}),
|
|
162
|
+
...meta,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
const monitoringEntry = createMiddlewareEntry();
|
|
169
|
+
const entries = [
|
|
170
|
+
...(monitoringEntry ? [monitoringEntry] : []),
|
|
171
|
+
viewListMetaEntry,
|
|
172
|
+
...this.mcpMiddlewareEntries,
|
|
173
|
+
];
|
|
174
|
+
if (entries.length === 0) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
178
|
+
const instrumentMap = (map, isNotification) => {
|
|
179
|
+
for (const [method, handler] of map) {
|
|
180
|
+
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
181
|
+
}
|
|
182
|
+
const originalSet = map.set.bind(map);
|
|
183
|
+
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
184
|
+
};
|
|
185
|
+
instrumentMap(requestHandlers, false);
|
|
186
|
+
instrumentMap(notificationHandlers, true);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
190
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
191
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
192
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
193
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
194
|
+
* throw afterwards.
|
|
195
|
+
*/
|
|
196
|
+
async connect(transport) {
|
|
197
|
+
this.applyMcpMiddleware();
|
|
198
|
+
return McpServerBase.prototype.connect.call(this, transport);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
202
|
+
* transport per instance, so we can't reuse this `McpServer` across
|
|
203
|
+
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
204
|
+
* factory, but that would break Skybridge's singleton API — so instead
|
|
205
|
+
* we build a fresh underlying `Server` per request and share the main
|
|
206
|
+
* server's handler maps by reference. The cast is unavoidable: there's
|
|
207
|
+
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
208
|
+
* read side and fails fast on SDK field renames.
|
|
209
|
+
*/
|
|
210
|
+
async connectStatelessTransport(transport) {
|
|
211
|
+
this.applyMcpMiddleware();
|
|
212
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
213
|
+
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
214
|
+
const target = fresh;
|
|
215
|
+
target._requestHandlers = requestHandlers;
|
|
216
|
+
target._notificationHandlers = notificationHandlers;
|
|
217
|
+
await fresh.connect(transport);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
221
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
222
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
223
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
224
|
+
*
|
|
225
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
226
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
227
|
+
* Node, returns `undefined` once listening.
|
|
228
|
+
*/
|
|
229
|
+
async run() {
|
|
230
|
+
this.applyMcpMiddleware();
|
|
231
|
+
const httpServer = http.createServer();
|
|
232
|
+
await createApp({
|
|
233
|
+
mcpServer: this,
|
|
234
|
+
httpServer,
|
|
235
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
236
|
+
});
|
|
237
|
+
httpServer.on("request", this.express);
|
|
238
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
239
|
+
await new Promise((resolve, reject) => {
|
|
240
|
+
httpServer.on("error", (error) => {
|
|
44
241
|
console.error("Failed to start server:", error);
|
|
45
242
|
reject(error);
|
|
46
243
|
});
|
|
47
|
-
|
|
244
|
+
httpServer.listen(port, () => {
|
|
48
245
|
resolve();
|
|
49
246
|
});
|
|
50
247
|
});
|
|
248
|
+
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
249
|
+
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
250
|
+
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
251
|
+
if (typeof navigator !== "undefined" &&
|
|
252
|
+
navigator.userAgent === "Cloudflare-Workers") {
|
|
253
|
+
const cloudflareNode = "cloudflare:node";
|
|
254
|
+
const { httpServerHandler } = await import(cloudflareNode);
|
|
255
|
+
return httpServerHandler({ port });
|
|
256
|
+
}
|
|
257
|
+
const shutdown = () => {
|
|
258
|
+
// Drop both handlers so a second signal falls through to Node's default
|
|
259
|
+
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
260
|
+
process.off("SIGTERM", shutdown);
|
|
261
|
+
process.off("SIGINT", shutdown);
|
|
262
|
+
httpServer.close(() => process.exit(0));
|
|
263
|
+
// Force exit if connections don't drain in time so the port is still
|
|
264
|
+
// released promptly (e.g. for nodemon restarts).
|
|
265
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
266
|
+
};
|
|
267
|
+
process.on("SIGTERM", shutdown);
|
|
268
|
+
process.on("SIGINT", shutdown);
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
enforceOneToolPerView(component, toolName) {
|
|
272
|
+
const existingTool = this.claimedViews.get(component);
|
|
273
|
+
if (existingTool) {
|
|
274
|
+
throw new Error(`skybridge: view "${component}" is already used by tool "${existingTool}". Tool "${toolName}" cannot also reference it — each view backs exactly one tool.`);
|
|
275
|
+
}
|
|
276
|
+
this.claimedViews.set(component, toolName);
|
|
51
277
|
}
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
278
|
+
resolveViewRequestContext(extra) {
|
|
279
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
280
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
281
|
+
const header = (key) => {
|
|
282
|
+
const val = headers[key];
|
|
283
|
+
return Array.isArray(val) ? val[0] : val;
|
|
56
284
|
};
|
|
57
|
-
|
|
58
|
-
|
|
285
|
+
const isClaude = header("user-agent") === "Claude-User";
|
|
286
|
+
let serverUrl;
|
|
287
|
+
const forwardedHost = header("x-forwarded-host");
|
|
288
|
+
const origin = header("origin");
|
|
289
|
+
const host = header("host");
|
|
290
|
+
if (forwardedHost) {
|
|
291
|
+
const proto = header("x-forwarded-proto") || "https";
|
|
292
|
+
serverUrl = `${proto}://${forwardedHost}`;
|
|
293
|
+
}
|
|
294
|
+
else if (origin) {
|
|
295
|
+
serverUrl = origin;
|
|
296
|
+
}
|
|
297
|
+
else if (host) {
|
|
298
|
+
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
299
|
+
? "http"
|
|
300
|
+
: "https";
|
|
301
|
+
serverUrl = `${proto}://${host}`;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const devPort = process.env.__PORT || "3000";
|
|
305
|
+
serverUrl = `http://localhost:${devPort}`;
|
|
306
|
+
}
|
|
307
|
+
const connectDomains = [serverUrl];
|
|
308
|
+
if (!isProduction) {
|
|
309
|
+
const wsUrl = new URL(serverUrl);
|
|
310
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
311
|
+
connectDomains.push(wsUrl.origin);
|
|
312
|
+
}
|
|
313
|
+
let contentMetaOverrides = {};
|
|
314
|
+
if (isClaude) {
|
|
315
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
316
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
317
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
318
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
319
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
320
|
+
const hash = crypto
|
|
321
|
+
.createHash("sha256")
|
|
322
|
+
.update(url)
|
|
323
|
+
.digest("hex")
|
|
324
|
+
.slice(0, 32);
|
|
325
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
326
|
+
}
|
|
327
|
+
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
328
|
+
}
|
|
329
|
+
registerViewResources(toolName, view, toolMeta) {
|
|
330
|
+
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
331
|
+
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
332
|
+
// their cache when the bundle changes, but keep the URI stable across
|
|
333
|
+
// `tools/list` calls when the bundle hasn't changed.
|
|
334
|
+
const versionParam = this.computeViewVersionParam(view.component);
|
|
335
|
+
if (hosts.includes("apps-sdk")) {
|
|
336
|
+
const viewResource = {
|
|
59
337
|
hostType: "apps-sdk",
|
|
60
|
-
uri: `ui://
|
|
338
|
+
uri: `ui://views/apps-sdk/${view.component}.html${versionParam}`,
|
|
61
339
|
mimeType: "text/html+skybridge",
|
|
62
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain }) => {
|
|
63
|
-
const userUi = userMeta?.ui;
|
|
64
|
-
const userCsp = userUi?.csp;
|
|
340
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
65
341
|
const defaults = {
|
|
66
342
|
"openai/widgetCSP": {
|
|
67
343
|
resource_domains: resourceDomains,
|
|
68
344
|
connect_domains: connectDomains,
|
|
69
345
|
},
|
|
70
346
|
"openai/widgetDomain": domain,
|
|
71
|
-
"openai/widgetDescription":
|
|
347
|
+
"openai/widgetDescription": view.description,
|
|
72
348
|
};
|
|
73
|
-
const
|
|
349
|
+
const fromView = {
|
|
74
350
|
"openai/widgetCSP": {
|
|
75
|
-
resource_domains:
|
|
76
|
-
connect_domains:
|
|
77
|
-
frame_domains:
|
|
78
|
-
redirect_domains:
|
|
351
|
+
resource_domains: view.csp?.resourceDomains,
|
|
352
|
+
connect_domains: view.csp?.connectDomains,
|
|
353
|
+
frame_domains: view.csp?.frameDomains,
|
|
354
|
+
redirect_domains: view.csp?.redirectDomains,
|
|
79
355
|
},
|
|
80
|
-
"openai/widgetDomain":
|
|
81
|
-
"openai/widgetPrefersBorder":
|
|
356
|
+
"openai/widgetDomain": view.domain,
|
|
357
|
+
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
82
358
|
};
|
|
83
|
-
const
|
|
84
|
-
|
|
359
|
+
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
360
|
+
"openai/widgetDomain": overrides.domain,
|
|
361
|
+
});
|
|
362
|
+
if (view._meta) {
|
|
363
|
+
return { ...base, ...view._meta };
|
|
364
|
+
}
|
|
365
|
+
return base;
|
|
85
366
|
},
|
|
86
367
|
};
|
|
87
|
-
this.
|
|
88
|
-
name,
|
|
89
|
-
|
|
90
|
-
|
|
368
|
+
this.registerViewResource({
|
|
369
|
+
name: toolName,
|
|
370
|
+
viewResource,
|
|
371
|
+
view,
|
|
91
372
|
});
|
|
92
|
-
toolMeta["openai/outputTemplate"] =
|
|
373
|
+
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
93
374
|
}
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
375
|
+
if (hosts.includes("mcp-app")) {
|
|
376
|
+
const viewResource = {
|
|
96
377
|
hostType: "mcp-app",
|
|
97
|
-
uri: `ui://
|
|
378
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
98
379
|
mimeType: "text/html;profile=mcp-app",
|
|
99
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain }) => {
|
|
380
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
100
381
|
const defaults = {
|
|
101
382
|
ui: {
|
|
102
383
|
csp: {
|
|
103
384
|
resourceDomains,
|
|
104
385
|
connectDomains,
|
|
386
|
+
baseUriDomains,
|
|
105
387
|
},
|
|
106
388
|
domain,
|
|
107
389
|
},
|
|
108
390
|
};
|
|
109
|
-
|
|
391
|
+
const fromView = {
|
|
392
|
+
ui: {
|
|
393
|
+
...(view.description && { description: view.description }),
|
|
394
|
+
...(view.prefersBorder !== undefined && {
|
|
395
|
+
prefersBorder: view.prefersBorder,
|
|
396
|
+
}),
|
|
397
|
+
...(view.domain && { domain: view.domain }),
|
|
398
|
+
csp: {
|
|
399
|
+
...(view.csp?.resourceDomains && {
|
|
400
|
+
resourceDomains: view.csp.resourceDomains,
|
|
401
|
+
}),
|
|
402
|
+
...(view.csp?.connectDomains && {
|
|
403
|
+
connectDomains: view.csp.connectDomains,
|
|
404
|
+
}),
|
|
405
|
+
...(view.csp?.frameDomains && {
|
|
406
|
+
frameDomains: view.csp.frameDomains,
|
|
407
|
+
}),
|
|
408
|
+
...(view.csp?.baseUriDomains && {
|
|
409
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
410
|
+
}),
|
|
411
|
+
...(view.csp?.redirectDomains && {
|
|
412
|
+
redirectDomains: view.csp.redirectDomains,
|
|
413
|
+
}),
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
418
|
+
ui: overrides,
|
|
419
|
+
});
|
|
420
|
+
if (view._meta) {
|
|
421
|
+
return { ...base, ...view._meta };
|
|
422
|
+
}
|
|
423
|
+
return base;
|
|
110
424
|
},
|
|
111
425
|
};
|
|
112
|
-
this.
|
|
113
|
-
name,
|
|
114
|
-
|
|
115
|
-
|
|
426
|
+
this.registerViewResource({
|
|
427
|
+
name: toolName,
|
|
428
|
+
viewResource,
|
|
429
|
+
view,
|
|
116
430
|
});
|
|
117
431
|
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
118
|
-
toolMeta["ui/resourceUri"] =
|
|
119
|
-
toolMeta.ui = { resourceUri:
|
|
432
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
433
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
120
434
|
}
|
|
121
|
-
this.registerTool(name, {
|
|
122
|
-
...toolConfig,
|
|
123
|
-
_meta: toolMeta,
|
|
124
|
-
}, toolCallback);
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
registerTool(name, config, cb) {
|
|
128
|
-
super.registerTool(name, config, cb);
|
|
129
|
-
return this;
|
|
130
435
|
}
|
|
131
|
-
|
|
132
|
-
const { hostType, uri:
|
|
133
|
-
|
|
436
|
+
registerViewResource({ name, viewResource, view, }) {
|
|
437
|
+
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
438
|
+
const buildMeta = (extra) => {
|
|
439
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
440
|
+
return buildContentMeta({
|
|
441
|
+
resourceDomains: [serverUrl],
|
|
442
|
+
connectDomains,
|
|
443
|
+
domain: serverUrl,
|
|
444
|
+
baseUriDomains: [serverUrl],
|
|
445
|
+
}, contentMetaOverrides);
|
|
446
|
+
};
|
|
447
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
448
|
+
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
134
449
|
const isProduction = process.env.NODE_ENV === "production";
|
|
135
|
-
const
|
|
136
|
-
const isClaude = extra?.requestInfo?.headers?.["user-agent"] === "Claude-User";
|
|
137
|
-
const hostFromHeaders = extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
138
|
-
extra?.requestInfo?.headers?.host;
|
|
139
|
-
const useExternalHost = isProduction || useForwardedHost || isClaude;
|
|
140
|
-
const serverUrl = useExternalHost
|
|
141
|
-
? `https://${hostFromHeaders}`
|
|
142
|
-
: "http://localhost:3000";
|
|
450
|
+
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
143
451
|
const html = isProduction
|
|
144
452
|
? templateHelper.renderProduction({
|
|
145
453
|
hostType,
|
|
146
454
|
serverUrl,
|
|
147
|
-
|
|
148
|
-
styleFile: this.lookupDistFile("style.css"),
|
|
455
|
+
viewFile: this.lookupViewFile(view.component),
|
|
456
|
+
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
149
457
|
})
|
|
150
458
|
: templateHelper.renderDevelopment({
|
|
151
459
|
hostType,
|
|
152
460
|
serverUrl,
|
|
153
|
-
|
|
154
|
-
widgetName: name,
|
|
461
|
+
viewName: view.component,
|
|
155
462
|
});
|
|
156
|
-
const connectDomains = [serverUrl];
|
|
157
|
-
if (!isProduction) {
|
|
158
|
-
const VITE_HMR_WEBSOCKET_DEFAULT_URL = "ws://localhost:24678";
|
|
159
|
-
connectDomains.push(VITE_HMR_WEBSOCKET_DEFAULT_URL);
|
|
160
|
-
}
|
|
161
|
-
const contentMeta = buildContentMeta({
|
|
162
|
-
resourceDomains: [serverUrl],
|
|
163
|
-
connectDomains,
|
|
164
|
-
domain: isClaude
|
|
165
|
-
? `${crypto
|
|
166
|
-
.createHash("sha256")
|
|
167
|
-
.update(`https://${hostFromHeaders}/mcp`)
|
|
168
|
-
.digest("hex")
|
|
169
|
-
.slice(0, 32)}.claudemcpcontent.com`
|
|
170
|
-
: serverUrl,
|
|
171
|
-
baseUriDomains: [serverUrl],
|
|
172
|
-
});
|
|
173
463
|
return {
|
|
174
464
|
contents: [
|
|
175
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
465
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
176
466
|
],
|
|
177
467
|
};
|
|
178
468
|
});
|
|
179
469
|
}
|
|
470
|
+
wrapHandler(cb, { attachViewUUID }) {
|
|
471
|
+
return async (args, extra) => {
|
|
472
|
+
const result = await cb(args, extra);
|
|
473
|
+
return {
|
|
474
|
+
...result,
|
|
475
|
+
content: normalizeContent(result.content),
|
|
476
|
+
...(attachViewUUID && {
|
|
477
|
+
_meta: {
|
|
478
|
+
...result._meta,
|
|
479
|
+
viewUUID: crypto.randomUUID(),
|
|
480
|
+
},
|
|
481
|
+
}),
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
computeViewVersionParam(viewName) {
|
|
486
|
+
if (process.env.NODE_ENV !== "production") {
|
|
487
|
+
return "";
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
const viewFile = this.lookupViewFile(viewName);
|
|
491
|
+
const styleFile = this.lookupDistFile("style.css") ?? "";
|
|
492
|
+
const hash = crypto
|
|
493
|
+
.createHash("sha256")
|
|
494
|
+
.update(viewFile)
|
|
495
|
+
.update("\0")
|
|
496
|
+
.update(styleFile)
|
|
497
|
+
.digest("hex")
|
|
498
|
+
.slice(0, 8);
|
|
499
|
+
return `?v=${hash}`;
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
return "";
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
lookupViewFile(viewName) {
|
|
506
|
+
const manifest = this.readManifest();
|
|
507
|
+
for (const entry of Object.values(manifest)) {
|
|
508
|
+
if (entry?.isEntry && entry.name === viewName && entry.file) {
|
|
509
|
+
return entry.file;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
throw new Error(`View "${viewName}" not found in Vite manifest. Did the build complete successfully? Look for an entry with name "${viewName}" in dist/assets/.vite/manifest.json.`);
|
|
513
|
+
}
|
|
180
514
|
lookupDistFile(key) {
|
|
181
515
|
const manifest = this.readManifest();
|
|
182
516
|
return manifest[key]?.file;
|
|
183
517
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
518
|
+
/**
|
|
519
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
520
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
521
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
522
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
523
|
+
*/
|
|
524
|
+
setViteManifest(manifest) {
|
|
525
|
+
this.viteManifest = manifest;
|
|
526
|
+
return this;
|
|
189
527
|
}
|
|
190
528
|
readManifest() {
|
|
529
|
+
if (this.viteManifest) {
|
|
530
|
+
return this.viteManifest;
|
|
531
|
+
}
|
|
191
532
|
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
192
533
|
}
|
|
534
|
+
registerTool(...args) {
|
|
535
|
+
const baseFn = McpServerBase.prototype.registerTool;
|
|
536
|
+
if (typeof args[0] === "string") {
|
|
537
|
+
baseFn.call(this, args[0], args[1], args[2]);
|
|
538
|
+
return this;
|
|
539
|
+
}
|
|
540
|
+
const config = args[0];
|
|
541
|
+
const cb = args[1];
|
|
542
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
543
|
+
const toolMeta = { ...userToolMeta };
|
|
544
|
+
if (securitySchemes) {
|
|
545
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
546
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
547
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
548
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
549
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
550
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
551
|
+
}
|
|
552
|
+
if (view) {
|
|
553
|
+
this.enforceOneToolPerView(view.component, name);
|
|
554
|
+
this.registerViewResources(name, view, toolMeta);
|
|
555
|
+
}
|
|
556
|
+
const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });
|
|
557
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
|
|
558
|
+
return this;
|
|
559
|
+
}
|
|
193
560
|
}
|
|
194
561
|
//# sourceMappingURL=server.js.map
|