skybridge 0.0.0-dev.b0a6e24 → 0.0.0-dev.b0d461b
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 -124
- 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 +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.js.map +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.d.ts +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.js.map +1 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.js.map +1 -1
- package/dist/cli/use-nodemon.js +11 -2
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +1 -1
- package/dist/cli/use-tunnel.js +102 -68
- package/dist/cli/use-tunnel.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +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 +42 -19
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +49 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +17 -2
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +80 -1
- 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 +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/content-helpers.test.js.map +1 -1
- package/dist/server/express.d.ts +1 -5
- package/dist/server/express.js +31 -7
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +271 -69
- 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 +4 -2
- package/dist/server/index.js +3 -1
- 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.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/server.d.ts +229 -8
- package/dist/server/server.js +278 -76
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +0 -2
- 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.js.map +1 -1
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +156 -42
- package/dist/test/view.test.js.map +1 -1
- package/dist/version.js +1 -3
- package/dist/version.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +8 -3
- package/dist/web/bridges/apps-sdk/adaptor.js +35 -5
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
- 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.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +8 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +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 +12 -7
- package/dist/web/bridges/mcp-app/adaptor.js +45 -30
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +4 -2
- package/dist/web/bridges/mcp-app/bridge.js +23 -1
- 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 +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +103 -8
- 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 +1 -1
- 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 +35 -9
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +14 -16
- 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 +22 -22
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +11 -9
- 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 -1
- 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 +13 -2
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +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-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 +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js.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.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.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 +1 -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.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +5 -5
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js.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-widget-state.test.js → use-view-state.test.js} +17 -17
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -3
- 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 +28 -0
- package/dist/web/plugin/plugin.js +65 -17
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +8 -0
- package/dist/web/plugin/scan-views.js +26 -8
- package/dist/web/plugin/scan-views.js.map +1 -1
- package/dist/web/plugin/scan-views.test.js +33 -1
- package/dist/web/plugin/scan-views.test.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
- package/dist/web/plugin/validate-view.js.map +1 -1
- package/dist/web/plugin/validate-view.test.js.map +1 -1
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +30 -18
- package/dist/server/templates/development.hbs +0 -12
- package/dist/server/templates/production.hbs +0 -6
- 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.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js.map +0 -1
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
package/dist/server/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
6
|
import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
7
|
import { mergeWith, union } from "es-toolkit";
|
|
8
|
+
import express, {} from "express";
|
|
8
9
|
import { createApp } from "./express.js";
|
|
9
10
|
import { createMiddlewareEntry } from "./metric.js";
|
|
10
11
|
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
@@ -16,6 +17,12 @@ const mergeWithUnion = (target, source) => {
|
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
19
|
};
|
|
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
|
+
*/
|
|
19
26
|
export function normalizeContent(content) {
|
|
20
27
|
if (content === undefined) {
|
|
21
28
|
return [];
|
|
@@ -29,31 +36,99 @@ export function normalizeContent(content) {
|
|
|
29
36
|
return [content];
|
|
30
37
|
}
|
|
31
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
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
69
|
+
// Set at module scope rather than passed through the constructor because the
|
|
70
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
71
|
+
// threading it through every call site (including user templates) is exactly
|
|
72
|
+
// the boilerplate this design is trying to hide.
|
|
73
|
+
let pendingBuildManifest = null;
|
|
74
|
+
/**
|
|
75
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
76
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
77
|
+
* user-facing API.
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export function __setBuildManifest(manifest) {
|
|
82
|
+
pendingBuildManifest = manifest;
|
|
83
|
+
}
|
|
32
84
|
export class McpServer extends McpServerBaseOmitted {
|
|
85
|
+
/**
|
|
86
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
87
|
+
* custom routes, middleware, or settings — e.g.
|
|
88
|
+
* `server.express.get("/health", ...)`.
|
|
89
|
+
*
|
|
90
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
91
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
92
|
+
* Register your handlers before `run()`;
|
|
93
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
94
|
+
* error handler are appended in that order.
|
|
95
|
+
*
|
|
96
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
97
|
+
* locally and on self-hosted deployments.
|
|
98
|
+
*/
|
|
33
99
|
express;
|
|
34
|
-
customMiddleware = [];
|
|
35
100
|
customErrorMiddleware = [];
|
|
36
101
|
mcpMiddlewareEntries = [];
|
|
37
102
|
mcpMiddlewareApplied = false;
|
|
38
103
|
claimedViews = new Map();
|
|
104
|
+
viewMetaBuilders = new Map();
|
|
105
|
+
viteManifest = null;
|
|
39
106
|
serverInfo;
|
|
40
107
|
serverOptions;
|
|
41
|
-
constructor(serverInfo, options) {
|
|
108
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
42
109
|
super(serverInfo, options);
|
|
43
110
|
this.serverInfo = serverInfo;
|
|
44
111
|
this.serverOptions = options;
|
|
112
|
+
this.express = express();
|
|
113
|
+
this.express.use(express.json(skybridgeOptions?.json));
|
|
114
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
115
|
+
// user code. Consume-once: clear after the first construction so a
|
|
116
|
+
// subsequent test that doesn't prime can't inherit stale state.
|
|
117
|
+
// Explicit `setViteManifest` calls still win because they happen after
|
|
118
|
+
// construction.
|
|
119
|
+
if (pendingBuildManifest) {
|
|
120
|
+
this.setViteManifest(pendingBuildManifest);
|
|
121
|
+
pendingBuildManifest = null;
|
|
122
|
+
}
|
|
45
123
|
}
|
|
46
124
|
use(pathOrHandler, ...handlers) {
|
|
125
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
126
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
47
127
|
if (typeof pathOrHandler === "string") {
|
|
48
|
-
this.
|
|
49
|
-
path: pathOrHandler,
|
|
50
|
-
handlers,
|
|
51
|
-
});
|
|
128
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
52
129
|
}
|
|
53
130
|
else {
|
|
54
|
-
this.
|
|
55
|
-
handlers: [pathOrHandler, ...handlers],
|
|
56
|
-
});
|
|
131
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
57
132
|
}
|
|
58
133
|
return this;
|
|
59
134
|
}
|
|
@@ -97,10 +172,32 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
97
172
|
return;
|
|
98
173
|
}
|
|
99
174
|
this.mcpMiddlewareApplied = true;
|
|
175
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
176
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
177
|
+
const viewListMetaEntry = {
|
|
178
|
+
filter: "resources/list",
|
|
179
|
+
handler: async (_req, extra, next) => {
|
|
180
|
+
const result = (await next());
|
|
181
|
+
for (const resource of result.resources) {
|
|
182
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
183
|
+
if (!builder) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const meta = builder(extra);
|
|
187
|
+
resource._meta = {
|
|
188
|
+
...(resource._meta ?? {}),
|
|
189
|
+
...meta,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
},
|
|
194
|
+
};
|
|
100
195
|
const monitoringEntry = createMiddlewareEntry();
|
|
101
|
-
const entries =
|
|
102
|
-
? [monitoringEntry
|
|
103
|
-
|
|
196
|
+
const entries = [
|
|
197
|
+
...(monitoringEntry ? [monitoringEntry] : []),
|
|
198
|
+
viewListMetaEntry,
|
|
199
|
+
...this.mcpMiddlewareEntries,
|
|
200
|
+
];
|
|
104
201
|
if (entries.length === 0) {
|
|
105
202
|
return;
|
|
106
203
|
}
|
|
@@ -115,6 +212,14 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
115
212
|
instrumentMap(requestHandlers, false);
|
|
116
213
|
instrumentMap(notificationHandlers, true);
|
|
117
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
217
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
218
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
219
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
220
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
221
|
+
* throw afterwards.
|
|
222
|
+
*/
|
|
118
223
|
async connect(transport) {
|
|
119
224
|
this.applyMcpMiddleware();
|
|
120
225
|
return McpServerBase.prototype.connect.call(this, transport);
|
|
@@ -138,28 +243,71 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
138
243
|
target._notificationHandlers = notificationHandlers;
|
|
139
244
|
await fresh.connect(transport);
|
|
140
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
248
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
249
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
250
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
251
|
+
*
|
|
252
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
253
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
254
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
255
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
256
|
+
* Node, returns `undefined` once listening.
|
|
257
|
+
*/
|
|
141
258
|
async run() {
|
|
142
259
|
this.applyMcpMiddleware();
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
260
|
+
if (process.env.VERCEL === "1") {
|
|
261
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
262
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
263
|
+
// bare object passed to satisfy the required parameter.
|
|
264
|
+
const httpServer = http.createServer();
|
|
265
|
+
await createApp({
|
|
146
266
|
mcpServer: this,
|
|
147
267
|
httpServer,
|
|
148
|
-
customMiddleware: this.customMiddleware,
|
|
149
268
|
errorMiddleware: this.customErrorMiddleware,
|
|
150
269
|
});
|
|
270
|
+
return this.express;
|
|
151
271
|
}
|
|
272
|
+
const httpServer = http.createServer();
|
|
273
|
+
await createApp({
|
|
274
|
+
mcpServer: this,
|
|
275
|
+
httpServer,
|
|
276
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
277
|
+
});
|
|
152
278
|
httpServer.on("request", this.express);
|
|
153
|
-
|
|
279
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
280
|
+
await new Promise((resolve, reject) => {
|
|
154
281
|
httpServer.on("error", (error) => {
|
|
155
282
|
console.error("Failed to start server:", error);
|
|
156
283
|
reject(error);
|
|
157
284
|
});
|
|
158
|
-
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
159
285
|
httpServer.listen(port, () => {
|
|
160
286
|
resolve();
|
|
161
287
|
});
|
|
162
288
|
});
|
|
289
|
+
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
290
|
+
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
291
|
+
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
292
|
+
if (typeof navigator !== "undefined" &&
|
|
293
|
+
navigator.userAgent === "Cloudflare-Workers") {
|
|
294
|
+
const cloudflareNode = "cloudflare:node";
|
|
295
|
+
const { httpServerHandler } = await import(cloudflareNode);
|
|
296
|
+
return httpServerHandler({ port });
|
|
297
|
+
}
|
|
298
|
+
const shutdown = () => {
|
|
299
|
+
// Drop both handlers so a second signal falls through to Node's default
|
|
300
|
+
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
301
|
+
process.off("SIGTERM", shutdown);
|
|
302
|
+
process.off("SIGINT", shutdown);
|
|
303
|
+
httpServer.close(() => process.exit(0));
|
|
304
|
+
// Force exit if connections don't drain in time so the port is still
|
|
305
|
+
// released promptly (e.g. for nodemon restarts).
|
|
306
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
307
|
+
};
|
|
308
|
+
process.on("SIGTERM", shutdown);
|
|
309
|
+
process.on("SIGINT", shutdown);
|
|
310
|
+
return undefined;
|
|
163
311
|
}
|
|
164
312
|
enforceOneToolPerView(component, toolName) {
|
|
165
313
|
const existingTool = this.claimedViews.get(component);
|
|
@@ -168,12 +316,67 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
168
316
|
}
|
|
169
317
|
this.claimedViews.set(component, toolName);
|
|
170
318
|
}
|
|
319
|
+
resolveViewRequestContext(extra) {
|
|
320
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
321
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
322
|
+
const header = (key) => {
|
|
323
|
+
const val = headers[key];
|
|
324
|
+
return Array.isArray(val) ? val[0] : val;
|
|
325
|
+
};
|
|
326
|
+
const isClaude = header("user-agent") === "Claude-User";
|
|
327
|
+
let serverUrl;
|
|
328
|
+
const forwardedHost = header("x-forwarded-host");
|
|
329
|
+
const origin = header("origin");
|
|
330
|
+
const host = header("host");
|
|
331
|
+
if (forwardedHost) {
|
|
332
|
+
const proto = header("x-forwarded-proto") || "https";
|
|
333
|
+
serverUrl = `${proto}://${forwardedHost}`;
|
|
334
|
+
}
|
|
335
|
+
else if (origin) {
|
|
336
|
+
serverUrl = origin;
|
|
337
|
+
}
|
|
338
|
+
else if (host) {
|
|
339
|
+
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
340
|
+
? "http"
|
|
341
|
+
: "https";
|
|
342
|
+
serverUrl = `${proto}://${host}`;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
const devPort = process.env.__PORT || "3000";
|
|
346
|
+
serverUrl = `http://localhost:${devPort}`;
|
|
347
|
+
}
|
|
348
|
+
const connectDomains = [serverUrl];
|
|
349
|
+
if (!isProduction) {
|
|
350
|
+
const wsUrl = new URL(serverUrl);
|
|
351
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
352
|
+
connectDomains.push(wsUrl.origin);
|
|
353
|
+
}
|
|
354
|
+
let contentMetaOverrides = {};
|
|
355
|
+
if (isClaude) {
|
|
356
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
357
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
358
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
359
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
360
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
361
|
+
const hash = crypto
|
|
362
|
+
.createHash("sha256")
|
|
363
|
+
.update(url)
|
|
364
|
+
.digest("hex")
|
|
365
|
+
.slice(0, 32);
|
|
366
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
367
|
+
}
|
|
368
|
+
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
369
|
+
}
|
|
171
370
|
registerViewResources(toolName, view, toolMeta) {
|
|
172
371
|
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
372
|
+
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
373
|
+
// their cache when the bundle changes, but keep the URI stable across
|
|
374
|
+
// `tools/list` calls when the bundle hasn't changed.
|
|
375
|
+
const versionParam = this.computeViewVersionParam(view.component);
|
|
173
376
|
if (hosts.includes("apps-sdk")) {
|
|
174
377
|
const viewResource = {
|
|
175
378
|
hostType: "apps-sdk",
|
|
176
|
-
uri: `ui://
|
|
379
|
+
uri: `ui://views/apps-sdk/${view.component}.html${versionParam}`,
|
|
177
380
|
mimeType: "text/html+skybridge",
|
|
178
381
|
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
179
382
|
const defaults = {
|
|
@@ -213,7 +416,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
213
416
|
if (hosts.includes("mcp-app")) {
|
|
214
417
|
const viewResource = {
|
|
215
418
|
hostType: "mcp-app",
|
|
216
|
-
uri: `ui://
|
|
419
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
217
420
|
mimeType: "text/html;profile=mcp-app",
|
|
218
421
|
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
219
422
|
const defaults = {
|
|
@@ -268,40 +471,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
268
471
|
});
|
|
269
472
|
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
270
473
|
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
271
|
-
toolMeta.ui = { resourceUri: viewResource.uri };
|
|
474
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
272
475
|
}
|
|
273
476
|
}
|
|
274
477
|
registerViewResource({ name, viewResource, view, }) {
|
|
275
478
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
479
|
+
const buildMeta = (extra) => {
|
|
480
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
481
|
+
return buildContentMeta({
|
|
482
|
+
resourceDomains: [serverUrl],
|
|
483
|
+
connectDomains,
|
|
484
|
+
domain: serverUrl,
|
|
485
|
+
baseUriDomains: [serverUrl],
|
|
486
|
+
}, contentMetaOverrides);
|
|
487
|
+
};
|
|
488
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
276
489
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
277
490
|
const isProduction = process.env.NODE_ENV === "production";
|
|
278
|
-
const
|
|
279
|
-
const headers = extra?.requestInfo?.headers || {};
|
|
280
|
-
const header = (key) => {
|
|
281
|
-
const val = headers[key];
|
|
282
|
-
return Array.isArray(val) ? val[0] : val;
|
|
283
|
-
};
|
|
284
|
-
let serverUrl;
|
|
285
|
-
const forwardedHost = header("x-forwarded-host");
|
|
286
|
-
const origin = header("origin");
|
|
287
|
-
const host = header("host");
|
|
288
|
-
if (forwardedHost) {
|
|
289
|
-
const proto = header("x-forwarded-proto") || "https";
|
|
290
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
291
|
-
}
|
|
292
|
-
else if (origin) {
|
|
293
|
-
serverUrl = origin;
|
|
294
|
-
}
|
|
295
|
-
else if (host) {
|
|
296
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
297
|
-
? "http"
|
|
298
|
-
: "https";
|
|
299
|
-
serverUrl = `${proto}://${host}`;
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
const devPort = process.env.__PORT || "3000";
|
|
303
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
304
|
-
}
|
|
491
|
+
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
305
492
|
const html = isProduction
|
|
306
493
|
? templateHelper.renderProduction({
|
|
307
494
|
hostType,
|
|
@@ -314,35 +501,9 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
314
501
|
serverUrl,
|
|
315
502
|
viewName: view.component,
|
|
316
503
|
});
|
|
317
|
-
const connectDomains = [serverUrl];
|
|
318
|
-
if (!isProduction) {
|
|
319
|
-
const wsUrl = new URL(serverUrl);
|
|
320
|
-
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
321
|
-
connectDomains.push(wsUrl.origin);
|
|
322
|
-
}
|
|
323
|
-
let contentMetaOverrides = {};
|
|
324
|
-
if (isClaude) {
|
|
325
|
-
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
326
|
-
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
327
|
-
// Strip a lone trailing slash so the hash matches the connector URL
|
|
328
|
-
// as registered with Claude (which has no trailing slash on bare origins).
|
|
329
|
-
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
330
|
-
const hash = crypto
|
|
331
|
-
.createHash("sha256")
|
|
332
|
-
.update(url)
|
|
333
|
-
.digest("hex")
|
|
334
|
-
.slice(0, 32);
|
|
335
|
-
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
336
|
-
}
|
|
337
|
-
const contentMeta = buildContentMeta({
|
|
338
|
-
resourceDomains: [serverUrl],
|
|
339
|
-
connectDomains,
|
|
340
|
-
domain: serverUrl,
|
|
341
|
-
baseUriDomains: [serverUrl],
|
|
342
|
-
}, contentMetaOverrides);
|
|
343
504
|
return {
|
|
344
505
|
contents: [
|
|
345
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
506
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
346
507
|
],
|
|
347
508
|
};
|
|
348
509
|
});
|
|
@@ -362,6 +523,26 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
362
523
|
};
|
|
363
524
|
};
|
|
364
525
|
}
|
|
526
|
+
computeViewVersionParam(viewName) {
|
|
527
|
+
if (process.env.NODE_ENV !== "production") {
|
|
528
|
+
return "";
|
|
529
|
+
}
|
|
530
|
+
try {
|
|
531
|
+
const viewFile = this.lookupViewFile(viewName);
|
|
532
|
+
const styleFile = this.lookupDistFile("style.css") ?? "";
|
|
533
|
+
const hash = crypto
|
|
534
|
+
.createHash("sha256")
|
|
535
|
+
.update(viewFile)
|
|
536
|
+
.update("\0")
|
|
537
|
+
.update(styleFile)
|
|
538
|
+
.digest("hex")
|
|
539
|
+
.slice(0, 8);
|
|
540
|
+
return `?v=${hash}`;
|
|
541
|
+
}
|
|
542
|
+
catch {
|
|
543
|
+
return "";
|
|
544
|
+
}
|
|
545
|
+
}
|
|
365
546
|
lookupViewFile(viewName) {
|
|
366
547
|
const manifest = this.readManifest();
|
|
367
548
|
for (const entry of Object.values(manifest)) {
|
|
@@ -375,7 +556,20 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
375
556
|
const manifest = this.readManifest();
|
|
376
557
|
return manifest[key]?.file;
|
|
377
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
561
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
562
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
563
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
564
|
+
*/
|
|
565
|
+
setViteManifest(manifest) {
|
|
566
|
+
this.viteManifest = manifest;
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
378
569
|
readManifest() {
|
|
570
|
+
if (this.viteManifest) {
|
|
571
|
+
return this.viteManifest;
|
|
572
|
+
}
|
|
379
573
|
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
380
574
|
}
|
|
381
575
|
registerTool(...args) {
|
|
@@ -386,8 +580,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
386
580
|
}
|
|
387
581
|
const config = args[0];
|
|
388
582
|
const cb = args[1];
|
|
389
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
583
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
390
584
|
const toolMeta = { ...userToolMeta };
|
|
585
|
+
if (securitySchemes) {
|
|
586
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
587
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
588
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
589
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
590
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
591
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
592
|
+
}
|
|
391
593
|
if (view) {
|
|
392
594
|
this.enforceOneToolPerView(view.component, name);
|
|
393
595
|
this.registerViewResources(name, view, toolMeta);
|