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