skybridge 0.0.0-dev.f40327b → 0.0.0-dev.f40afe0
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 +1 -0
- package/dist/cli/build-helpers.d.ts +10 -0
- package/dist/cli/build-helpers.js +93 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +89 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +68 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.d.ts +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/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-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/start-tunnel-view-build.d.ts +1 -0
- package/dist/cli/start-tunnel-view-build.js +16 -0
- package/dist/cli/start-tunnel-view-build.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +14 -0
- package/dist/cli/use-nodemon.js +71 -60
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +70 -67
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +2 -73
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +57 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +32 -0
- package/dist/server/auth/discovery.js +56 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +18 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +18 -0
- package/dist/server/auth/providers/auth0.js +31 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +48 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +16 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +28 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +24 -0
- package/dist/server/auth/providers/custom.js +37 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +107 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +15 -0
- package/dist/server/auth/providers/descope.js +33 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +37 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +12 -0
- package/dist/server/auth/providers/stytch.js +13 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +12 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +100 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/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/express.js +3 -0
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +61 -0
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/index.d.ts +9 -2
- package/dist/server/index.js +7 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +56 -35
- package/dist/server/server.js +232 -136
- package/dist/server/server.js.map +1 -1
- package/dist/server/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +207 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/test/view.test.js +69 -101
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +330 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +208 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
- package/dist/web/bridges/apps-sdk/bridge.js +15 -4
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +4 -4
- package/dist/web/bridges/get-adaptor.js +6 -11
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +15 -3
- package/dist/web/bridges/mcp-app/bridge.js +68 -5
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +44 -1
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +1 -1
- package/dist/web/data-llm.test.js +17 -5
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +4 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/hooks/index.d.ts +1 -0
- package/dist/web/hooks/index.js +1 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +37 -23
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +56 -20
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +11 -3
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +25 -7
- package/dist/web/hooks/use-tool-info.js +5 -8
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +42 -32
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +6 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/plugin/plugin.js +0 -1
- package/dist/web/plugin/plugin.js.map +1 -1
- package/package.json +22 -19
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -28
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -113
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -52
- package/dist/web/bridges/mcp-app/adaptor.js +0 -280
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
package/dist/server/server.js
CHANGED
|
@@ -6,9 +6,11 @@ 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
8
|
import express, {} from "express";
|
|
9
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
9
10
|
import { createApp } from "./express.js";
|
|
10
11
|
import { createMiddlewareEntry } from "./metric.js";
|
|
11
12
|
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
13
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
12
14
|
import { templateHelper } from "./templateHelper.js";
|
|
13
15
|
const mergeWithUnion = (target, source) => {
|
|
14
16
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -17,6 +19,28 @@ const mergeWithUnion = (target, source) => {
|
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
24
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
25
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
26
|
+
*/
|
|
27
|
+
function normalizeForwardedPrefix(raw) {
|
|
28
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
29
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
30
|
+
if (trimmed === "") {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
37
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
38
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
39
|
+
*/
|
|
40
|
+
function stripQuery(uri) {
|
|
41
|
+
const queryIndex = uri.indexOf("?");
|
|
42
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
43
|
+
}
|
|
20
44
|
/**
|
|
21
45
|
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
22
46
|
* become a single `TextContent`; a single block is wrapped in an array;
|
|
@@ -65,13 +89,31 @@ const McpServerBaseOmitted = McpServerBase;
|
|
|
65
89
|
*
|
|
66
90
|
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
67
91
|
*/
|
|
92
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
93
|
+
// Set at module scope rather than passed through the constructor because the
|
|
94
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
95
|
+
// threading it through every call site (including user templates) is exactly
|
|
96
|
+
// the boilerplate this design is trying to hide.
|
|
97
|
+
let pendingBuildManifest = null;
|
|
98
|
+
/**
|
|
99
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
100
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
101
|
+
* user-facing API.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export function __setBuildManifest(manifest) {
|
|
106
|
+
pendingBuildManifest = manifest;
|
|
107
|
+
}
|
|
68
108
|
export class McpServer extends McpServerBaseOmitted {
|
|
69
109
|
/**
|
|
70
110
|
* The underlying Express app. Use this to extend the HTTP server with
|
|
71
111
|
* custom routes, middleware, or settings — e.g.
|
|
72
112
|
* `server.express.get("/health", ...)`.
|
|
73
113
|
*
|
|
74
|
-
* `express.json()` is pre-applied
|
|
114
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
115
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
116
|
+
* Register your handlers before `run()`;
|
|
75
117
|
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
76
118
|
* error handler are appended in that order.
|
|
77
119
|
*
|
|
@@ -84,15 +126,34 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
84
126
|
mcpMiddlewareApplied = false;
|
|
85
127
|
claimedViews = new Map();
|
|
86
128
|
viewMetaBuilders = new Map();
|
|
129
|
+
/**
|
|
130
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
131
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
132
|
+
* underlying view no matter which version param the consumer sends, since
|
|
133
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
134
|
+
*/
|
|
135
|
+
viewUriByPath = new Map();
|
|
87
136
|
viteManifest = null;
|
|
88
137
|
serverInfo;
|
|
89
138
|
serverOptions;
|
|
90
|
-
constructor(serverInfo, options) {
|
|
139
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
91
140
|
super(serverInfo, options);
|
|
92
141
|
this.serverInfo = serverInfo;
|
|
93
142
|
this.serverOptions = options;
|
|
94
143
|
this.express = express();
|
|
95
|
-
this.express.use(express.json());
|
|
144
|
+
this.express.use(express.json(skybridgeOptions?.json));
|
|
145
|
+
if (skybridgeOptions?.oauth) {
|
|
146
|
+
setupOAuth(this.express, skybridgeOptions.oauth);
|
|
147
|
+
}
|
|
148
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
149
|
+
// user code. Consume-once: clear after the first construction so a
|
|
150
|
+
// subsequent test that doesn't prime can't inherit stale state.
|
|
151
|
+
// Explicit `setViteManifest` calls still win because they happen after
|
|
152
|
+
// construction.
|
|
153
|
+
if (pendingBuildManifest) {
|
|
154
|
+
this.setViteManifest(pendingBuildManifest);
|
|
155
|
+
pendingBuildManifest = null;
|
|
156
|
+
}
|
|
96
157
|
}
|
|
97
158
|
use(pathOrHandler, ...handlers) {
|
|
98
159
|
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
@@ -165,10 +226,47 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
165
226
|
return result;
|
|
166
227
|
},
|
|
167
228
|
};
|
|
229
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
230
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
231
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
232
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
233
|
+
// canonical registered one, then restore the requested URI on the response
|
|
234
|
+
// so the consumer-facing URI is never rewritten.
|
|
235
|
+
const viewReadResolveEntry = {
|
|
236
|
+
filter: "resources/read",
|
|
237
|
+
handler: async (req, _extra, next) => {
|
|
238
|
+
const requested = req.params.uri;
|
|
239
|
+
if (typeof requested !== "string") {
|
|
240
|
+
return next();
|
|
241
|
+
}
|
|
242
|
+
const path = stripQuery(requested);
|
|
243
|
+
const canonical = this.viewUriByPath.get(path);
|
|
244
|
+
if (!canonical) {
|
|
245
|
+
return next();
|
|
246
|
+
}
|
|
247
|
+
req.params.uri = canonical;
|
|
248
|
+
try {
|
|
249
|
+
const result = (await next());
|
|
250
|
+
for (const content of result.contents ?? []) {
|
|
251
|
+
if (typeof content.uri === "string" &&
|
|
252
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
253
|
+
content.uri = requested;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
// Restore the shared request params so middleware outer to us never
|
|
260
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
261
|
+
req.params.uri = requested;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
};
|
|
168
265
|
const monitoringEntry = createMiddlewareEntry();
|
|
169
266
|
const entries = [
|
|
170
267
|
...(monitoringEntry ? [monitoringEntry] : []),
|
|
171
268
|
viewListMetaEntry,
|
|
269
|
+
viewReadResolveEntry,
|
|
172
270
|
...this.mcpMiddlewareEntries,
|
|
173
271
|
];
|
|
174
272
|
if (entries.length === 0) {
|
|
@@ -224,10 +322,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
224
322
|
*
|
|
225
323
|
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
226
324
|
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
325
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
326
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
227
327
|
* Node, returns `undefined` once listening.
|
|
228
328
|
*/
|
|
229
329
|
async run() {
|
|
230
330
|
this.applyMcpMiddleware();
|
|
331
|
+
if (process.env.VERCEL === "1") {
|
|
332
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
333
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
334
|
+
// bare object passed to satisfy the required parameter.
|
|
335
|
+
const httpServer = http.createServer();
|
|
336
|
+
await createApp({
|
|
337
|
+
mcpServer: this,
|
|
338
|
+
httpServer,
|
|
339
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
340
|
+
});
|
|
341
|
+
return this.express;
|
|
342
|
+
}
|
|
231
343
|
const httpServer = http.createServer();
|
|
232
344
|
await createApp({
|
|
233
345
|
mcpServer: this,
|
|
@@ -283,27 +395,12 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
283
395
|
return Array.isArray(val) ? val[0] : val;
|
|
284
396
|
};
|
|
285
397
|
const isClaude = header("user-agent") === "Claude-User";
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
}
|
|
398
|
+
const serverUrl = resolveServerOrigin(header);
|
|
399
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
400
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
401
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
402
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
403
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
307
404
|
const connectDomains = [serverUrl];
|
|
308
405
|
if (!isProduction) {
|
|
309
406
|
const wsUrl = new URL(serverUrl);
|
|
@@ -324,114 +421,88 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
324
421
|
.slice(0, 32);
|
|
325
422
|
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
326
423
|
}
|
|
327
|
-
|
|
424
|
+
const serverHostname = new URL(serverUrl).hostname;
|
|
425
|
+
const isLocalhost = serverHostname === "localhost" ||
|
|
426
|
+
serverHostname === "127.0.0.1" ||
|
|
427
|
+
serverHostname === "[::1]";
|
|
428
|
+
const useBundledDevTemplate = !isProduction && !isLocalhost;
|
|
429
|
+
return {
|
|
430
|
+
serverUrl,
|
|
431
|
+
assetsBasePath,
|
|
432
|
+
connectDomains,
|
|
433
|
+
contentMetaOverrides,
|
|
434
|
+
useBundledDevTemplate,
|
|
435
|
+
};
|
|
328
436
|
}
|
|
329
437
|
registerViewResources(toolName, view, toolMeta) {
|
|
330
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
331
438
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
332
439
|
// their cache when the bundle changes, but keep the URI stable across
|
|
333
440
|
// `tools/list` calls when the bundle hasn't changed.
|
|
334
441
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
"openai/widgetDomain": domain,
|
|
347
|
-
"openai/widgetDescription": view.description,
|
|
348
|
-
};
|
|
349
|
-
const fromView = {
|
|
350
|
-
"openai/widgetCSP": {
|
|
351
|
-
resource_domains: view.csp?.resourceDomains,
|
|
352
|
-
connect_domains: view.csp?.connectDomains,
|
|
353
|
-
frame_domains: view.csp?.frameDomains,
|
|
354
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
355
|
-
},
|
|
356
|
-
"openai/widgetDomain": view.domain,
|
|
357
|
-
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
358
|
-
};
|
|
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;
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
this.registerViewResource({
|
|
369
|
-
name: toolName,
|
|
370
|
-
viewResource,
|
|
371
|
-
view,
|
|
372
|
-
});
|
|
373
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
374
|
-
}
|
|
375
|
-
if (hosts.includes("mcp-app")) {
|
|
376
|
-
const viewResource = {
|
|
377
|
-
hostType: "mcp-app",
|
|
378
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
379
|
-
mimeType: "text/html;profile=mcp-app",
|
|
380
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
381
|
-
const defaults = {
|
|
382
|
-
ui: {
|
|
383
|
-
csp: {
|
|
384
|
-
resourceDomains,
|
|
385
|
-
connectDomains,
|
|
386
|
-
baseUriDomains,
|
|
387
|
-
},
|
|
388
|
-
domain,
|
|
442
|
+
const viewResource = {
|
|
443
|
+
hostType: "mcp-app",
|
|
444
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
445
|
+
mimeType: "text/html;profile=mcp-app",
|
|
446
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
447
|
+
const defaults = {
|
|
448
|
+
ui: {
|
|
449
|
+
csp: {
|
|
450
|
+
resourceDomains,
|
|
451
|
+
connectDomains,
|
|
452
|
+
baseUriDomains,
|
|
389
453
|
},
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
454
|
+
domain,
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
const fromView = {
|
|
458
|
+
ui: {
|
|
459
|
+
...(view.description && { description: view.description }),
|
|
460
|
+
...(view.prefersBorder !== undefined && {
|
|
461
|
+
prefersBorder: view.prefersBorder,
|
|
462
|
+
}),
|
|
463
|
+
...(view.domain && { domain: view.domain }),
|
|
464
|
+
csp: {
|
|
465
|
+
...(view.csp?.resourceDomains && {
|
|
466
|
+
resourceDomains: view.csp.resourceDomains,
|
|
467
|
+
}),
|
|
468
|
+
...(view.csp?.connectDomains && {
|
|
469
|
+
connectDomains: view.csp.connectDomains,
|
|
470
|
+
}),
|
|
471
|
+
...(view.csp?.frameDomains && {
|
|
472
|
+
frameDomains: view.csp.frameDomains,
|
|
473
|
+
}),
|
|
474
|
+
...(view.csp?.baseUriDomains && {
|
|
475
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
396
476
|
}),
|
|
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
477
|
},
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
478
|
+
},
|
|
479
|
+
};
|
|
480
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
481
|
+
ui: overrides,
|
|
482
|
+
});
|
|
483
|
+
const base = {
|
|
484
|
+
...ui,
|
|
485
|
+
...(view.description && {
|
|
486
|
+
"openai/widgetDescription": view.description,
|
|
487
|
+
}),
|
|
488
|
+
...(view.csp?.redirectDomains && {
|
|
489
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
490
|
+
}),
|
|
491
|
+
};
|
|
492
|
+
if (view._meta) {
|
|
493
|
+
return { ...base, ...view._meta };
|
|
494
|
+
}
|
|
495
|
+
return base;
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
499
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
500
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
501
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
502
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
503
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
504
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
505
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
435
506
|
}
|
|
436
507
|
registerViewResource({ name, viewResource, view, }) {
|
|
437
508
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
@@ -445,21 +516,41 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
445
516
|
}, contentMetaOverrides);
|
|
446
517
|
};
|
|
447
518
|
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
519
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
520
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
448
521
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
449
522
|
const isProduction = process.env.NODE_ENV === "production";
|
|
450
|
-
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
:
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
523
|
+
const { serverUrl, assetsBasePath, useBundledDevTemplate } = this.resolveViewRequestContext(extra);
|
|
524
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
525
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
526
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
527
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
528
|
+
const renderBundled = () => templateHelper.renderProduction({
|
|
529
|
+
hostType,
|
|
530
|
+
serverUrl: viewBase,
|
|
531
|
+
viewFile: this.lookupViewFile(view.component),
|
|
532
|
+
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
533
|
+
});
|
|
534
|
+
const renderUnbundled = () => templateHelper.renderDevelopment({
|
|
535
|
+
hostType,
|
|
536
|
+
serverUrl: viewBase,
|
|
537
|
+
viewName: view.component,
|
|
538
|
+
});
|
|
539
|
+
let html;
|
|
540
|
+
if (isProduction) {
|
|
541
|
+
html = renderBundled();
|
|
542
|
+
}
|
|
543
|
+
else if (useBundledDevTemplate) {
|
|
544
|
+
try {
|
|
545
|
+
html = renderBundled();
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
html = renderUnbundled();
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
html = renderUnbundled();
|
|
553
|
+
}
|
|
463
554
|
return {
|
|
464
555
|
contents: [
|
|
465
556
|
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
@@ -467,6 +558,11 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
467
558
|
};
|
|
468
559
|
});
|
|
469
560
|
}
|
|
561
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
562
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
563
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
564
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
565
|
+
}
|
|
470
566
|
wrapHandler(cb, { attachViewUUID }) {
|
|
471
567
|
return async (args, extra) => {
|
|
472
568
|
const result = await cb(args, extra);
|