skybridge 0.0.0-dev.c432538 → 0.0.0-dev.c43e7d9
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 +11 -0
- package/dist/cli/build-helpers.js +102 -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 +119 -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 +73 -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/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 +71 -68
- 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/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 +48 -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 +30 -0
- package/dist/server/auth/providers/custom.js +40 -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 +128 -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 +35 -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 +39 -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/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/express.test.js +61 -0
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/index.d.ts +11 -2
- package/dist/server/index.js +9 -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 +81 -35
- package/dist/server/server.js +311 -163
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +63 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +178 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +210 -0
- package/dist/server/skills.test.js.map +1 -0
- 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 +171 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/test/view.test.js +109 -96
- 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 +51 -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 +2 -0
- package/dist/web/hooks/index.js +2 -0
- 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.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.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 +103 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- 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-send-follow-up-message.d.ts +2 -1
- package/dist/web/hooks/use-send-follow-up-message.js +2 -1
- 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 +2 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +2 -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 +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 +29 -9
- package/dist/web/hooks/use-tool-info.js +9 -10
- 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 +27 -19
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -27
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -109
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -51
- package/dist/web/bridges/mcp-app/adaptor.js +0 -272
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
package/dist/server/server.js
CHANGED
|
@@ -6,9 +6,12 @@ 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";
|
|
14
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
12
15
|
import { templateHelper } from "./templateHelper.js";
|
|
13
16
|
const mergeWithUnion = (target, source) => {
|
|
14
17
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -17,6 +20,29 @@ const mergeWithUnion = (target, source) => {
|
|
|
17
20
|
}
|
|
18
21
|
});
|
|
19
22
|
};
|
|
23
|
+
const SKILLS_DIR = "src/skills";
|
|
24
|
+
/**
|
|
25
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
26
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
27
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
28
|
+
*/
|
|
29
|
+
function normalizeForwardedPrefix(raw) {
|
|
30
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
31
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
32
|
+
if (trimmed === "") {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
39
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
40
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
41
|
+
*/
|
|
42
|
+
function stripQuery(uri) {
|
|
43
|
+
const queryIndex = uri.indexOf("?");
|
|
44
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
45
|
+
}
|
|
20
46
|
/**
|
|
21
47
|
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
22
48
|
* become a single `TextContent`; a single block is wrapped in an array;
|
|
@@ -65,13 +91,52 @@ const McpServerBaseOmitted = McpServerBase;
|
|
|
65
91
|
*
|
|
66
92
|
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
67
93
|
*/
|
|
94
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
95
|
+
// Set at module scope rather than passed through the constructor because the
|
|
96
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
97
|
+
// threading it through every call site (including user templates) is exactly
|
|
98
|
+
// the boilerplate this design is trying to hide.
|
|
99
|
+
let pendingBuildManifest = null;
|
|
100
|
+
/**
|
|
101
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
102
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
103
|
+
* user-facing API.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export function __setBuildManifest(manifest) {
|
|
108
|
+
pendingBuildManifest = manifest;
|
|
109
|
+
}
|
|
110
|
+
let pendingSkillsManifest = null;
|
|
111
|
+
export function __setSkillsManifest(manifest) {
|
|
112
|
+
pendingSkillsManifest = manifest;
|
|
113
|
+
}
|
|
114
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
115
|
+
// exists — the capability must be present for the `initialize` response.
|
|
116
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
117
|
+
if (!skybridgeOptions?.skills) {
|
|
118
|
+
return options;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
...options,
|
|
122
|
+
capabilities: {
|
|
123
|
+
...options?.capabilities,
|
|
124
|
+
extensions: {
|
|
125
|
+
...options?.capabilities?.extensions,
|
|
126
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
68
131
|
export class McpServer extends McpServerBaseOmitted {
|
|
69
132
|
/**
|
|
70
133
|
* The underlying Express app. Use this to extend the HTTP server with
|
|
71
134
|
* custom routes, middleware, or settings — e.g.
|
|
72
135
|
* `server.express.get("/health", ...)`.
|
|
73
136
|
*
|
|
74
|
-
* `express.json()` is pre-applied
|
|
137
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
138
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
139
|
+
* Register your handlers before `run()`;
|
|
75
140
|
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
76
141
|
* error handler are appended in that order.
|
|
77
142
|
*
|
|
@@ -83,15 +148,49 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
83
148
|
mcpMiddlewareEntries = [];
|
|
84
149
|
mcpMiddlewareApplied = false;
|
|
85
150
|
claimedViews = new Map();
|
|
151
|
+
viewMetaBuilders = new Map();
|
|
152
|
+
/**
|
|
153
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
154
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
155
|
+
* underlying view no matter which version param the consumer sends, since
|
|
156
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
157
|
+
*/
|
|
158
|
+
viewUriByPath = new Map();
|
|
86
159
|
viteManifest = null;
|
|
87
160
|
serverInfo;
|
|
88
161
|
serverOptions;
|
|
89
|
-
constructor(serverInfo, options) {
|
|
90
|
-
|
|
162
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
163
|
+
const mergedOptions = withSkillsCapability(options, skybridgeOptions);
|
|
164
|
+
super(serverInfo, mergedOptions);
|
|
91
165
|
this.serverInfo = serverInfo;
|
|
92
|
-
this.serverOptions =
|
|
166
|
+
this.serverOptions = mergedOptions;
|
|
93
167
|
this.express = express();
|
|
94
|
-
this.express.use(express.json());
|
|
168
|
+
this.express.use(express.json(skybridgeOptions?.json));
|
|
169
|
+
if (skybridgeOptions?.oauth) {
|
|
170
|
+
setupOAuth(this.express, skybridgeOptions.oauth);
|
|
171
|
+
}
|
|
172
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
173
|
+
// user code. Consume-once: clear after the first construction so a
|
|
174
|
+
// subsequent test that doesn't prime can't inherit stale state.
|
|
175
|
+
// Explicit `setViteManifest` calls still win because they happen after
|
|
176
|
+
// construction.
|
|
177
|
+
if (pendingBuildManifest) {
|
|
178
|
+
this.setViteManifest(pendingBuildManifest);
|
|
179
|
+
pendingBuildManifest = null;
|
|
180
|
+
}
|
|
181
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
182
|
+
}
|
|
183
|
+
setupSkills(enabled) {
|
|
184
|
+
const manifest = pendingSkillsManifest;
|
|
185
|
+
pendingSkillsManifest = null;
|
|
186
|
+
if (!enabled) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const skills = manifest ?? discoverSkills(SKILLS_DIR);
|
|
190
|
+
if (skills.length === 0) {
|
|
191
|
+
console.warn(`skybridge: the "skills" option is enabled but no skills were found in "${SKILLS_DIR}". Add a <name>/SKILL.md there, or remove the option.`);
|
|
192
|
+
}
|
|
193
|
+
registerSkills(this, skills);
|
|
95
194
|
}
|
|
96
195
|
use(pathOrHandler, ...handlers) {
|
|
97
196
|
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
@@ -144,10 +243,69 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
144
243
|
return;
|
|
145
244
|
}
|
|
146
245
|
this.mcpMiddlewareApplied = true;
|
|
246
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
247
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
248
|
+
const viewListMetaEntry = {
|
|
249
|
+
filter: "resources/list",
|
|
250
|
+
handler: async (_req, extra, next) => {
|
|
251
|
+
const result = (await next());
|
|
252
|
+
for (const resource of result.resources) {
|
|
253
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
254
|
+
if (!builder) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const meta = builder(extra);
|
|
258
|
+
resource._meta = {
|
|
259
|
+
...(resource._meta ?? {}),
|
|
260
|
+
...meta,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
267
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
268
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
269
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
270
|
+
// canonical registered one, then restore the requested URI on the response
|
|
271
|
+
// so the consumer-facing URI is never rewritten.
|
|
272
|
+
const viewReadResolveEntry = {
|
|
273
|
+
filter: "resources/read",
|
|
274
|
+
handler: async (req, _extra, next) => {
|
|
275
|
+
const requested = req.params.uri;
|
|
276
|
+
if (typeof requested !== "string") {
|
|
277
|
+
return next();
|
|
278
|
+
}
|
|
279
|
+
const path = stripQuery(requested);
|
|
280
|
+
const canonical = this.viewUriByPath.get(path);
|
|
281
|
+
if (!canonical) {
|
|
282
|
+
return next();
|
|
283
|
+
}
|
|
284
|
+
req.params.uri = canonical;
|
|
285
|
+
try {
|
|
286
|
+
const result = (await next());
|
|
287
|
+
for (const content of result.contents ?? []) {
|
|
288
|
+
if (typeof content.uri === "string" &&
|
|
289
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
290
|
+
content.uri = requested;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return result;
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
// Restore the shared request params so middleware outer to us never
|
|
297
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
298
|
+
req.params.uri = requested;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
};
|
|
147
302
|
const monitoringEntry = createMiddlewareEntry();
|
|
148
|
-
const entries =
|
|
149
|
-
? [monitoringEntry
|
|
150
|
-
|
|
303
|
+
const entries = [
|
|
304
|
+
...(monitoringEntry ? [monitoringEntry] : []),
|
|
305
|
+
viewListMetaEntry,
|
|
306
|
+
viewReadResolveEntry,
|
|
307
|
+
...this.mcpMiddlewareEntries,
|
|
308
|
+
];
|
|
151
309
|
if (entries.length === 0) {
|
|
152
310
|
return;
|
|
153
311
|
}
|
|
@@ -201,10 +359,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
201
359
|
*
|
|
202
360
|
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
203
361
|
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
362
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
363
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
204
364
|
* Node, returns `undefined` once listening.
|
|
205
365
|
*/
|
|
206
366
|
async run() {
|
|
207
367
|
this.applyMcpMiddleware();
|
|
368
|
+
if (process.env.VERCEL === "1") {
|
|
369
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
370
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
371
|
+
// bare object passed to satisfy the required parameter.
|
|
372
|
+
const httpServer = http.createServer();
|
|
373
|
+
await createApp({
|
|
374
|
+
mcpServer: this,
|
|
375
|
+
httpServer,
|
|
376
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
377
|
+
});
|
|
378
|
+
return this.express;
|
|
379
|
+
}
|
|
208
380
|
const httpServer = http.createServer();
|
|
209
381
|
await createApp({
|
|
210
382
|
mcpServer: this,
|
|
@@ -252,189 +424,157 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
252
424
|
}
|
|
253
425
|
this.claimedViews.set(component, toolName);
|
|
254
426
|
}
|
|
427
|
+
resolveViewRequestContext(extra) {
|
|
428
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
429
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
430
|
+
const header = (key) => {
|
|
431
|
+
const val = headers[key];
|
|
432
|
+
return Array.isArray(val) ? val[0] : val;
|
|
433
|
+
};
|
|
434
|
+
const isClaude = header("user-agent") === "Claude-User";
|
|
435
|
+
const serverUrl = resolveServerOrigin(header);
|
|
436
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
437
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
438
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
439
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
440
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
441
|
+
const connectDomains = [serverUrl];
|
|
442
|
+
if (!isProduction) {
|
|
443
|
+
const wsUrl = new URL(serverUrl);
|
|
444
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
445
|
+
connectDomains.push(wsUrl.origin);
|
|
446
|
+
}
|
|
447
|
+
let contentMetaOverrides = {};
|
|
448
|
+
if (isClaude) {
|
|
449
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
450
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
451
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
452
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
453
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
454
|
+
const hash = crypto
|
|
455
|
+
.createHash("sha256")
|
|
456
|
+
.update(url)
|
|
457
|
+
.digest("hex")
|
|
458
|
+
.slice(0, 32);
|
|
459
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
460
|
+
}
|
|
461
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
462
|
+
}
|
|
255
463
|
registerViewResources(toolName, view, toolMeta) {
|
|
256
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
257
464
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
258
465
|
// their cache when the bundle changes, but keep the URI stable across
|
|
259
466
|
// `tools/list` calls when the bundle hasn't changed.
|
|
260
467
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
468
|
+
const viewResource = {
|
|
469
|
+
hostType: "mcp-app",
|
|
470
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
471
|
+
mimeType: "text/html;profile=mcp-app",
|
|
472
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
473
|
+
const defaults = {
|
|
474
|
+
ui: {
|
|
475
|
+
csp: {
|
|
476
|
+
resourceDomains,
|
|
477
|
+
connectDomains,
|
|
478
|
+
baseUriDomains,
|
|
271
479
|
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
this.registerViewResource({
|
|
295
|
-
name: toolName,
|
|
296
|
-
viewResource,
|
|
297
|
-
view,
|
|
298
|
-
});
|
|
299
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
300
|
-
}
|
|
301
|
-
if (hosts.includes("mcp-app")) {
|
|
302
|
-
const viewResource = {
|
|
303
|
-
hostType: "mcp-app",
|
|
304
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
305
|
-
mimeType: "text/html;profile=mcp-app",
|
|
306
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
307
|
-
const defaults = {
|
|
308
|
-
ui: {
|
|
309
|
-
csp: {
|
|
310
|
-
resourceDomains,
|
|
311
|
-
connectDomains,
|
|
312
|
-
baseUriDomains,
|
|
313
|
-
},
|
|
314
|
-
domain,
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
const fromView = {
|
|
318
|
-
ui: {
|
|
319
|
-
...(view.description && { description: view.description }),
|
|
320
|
-
...(view.prefersBorder !== undefined && {
|
|
321
|
-
prefersBorder: view.prefersBorder,
|
|
480
|
+
domain,
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
const fromView = {
|
|
484
|
+
ui: {
|
|
485
|
+
...(view.description && { description: view.description }),
|
|
486
|
+
...(view.prefersBorder !== undefined && {
|
|
487
|
+
prefersBorder: view.prefersBorder,
|
|
488
|
+
}),
|
|
489
|
+
...(view.domain && { domain: view.domain }),
|
|
490
|
+
csp: {
|
|
491
|
+
...(view.csp?.resourceDomains && {
|
|
492
|
+
resourceDomains: view.csp.resourceDomains,
|
|
493
|
+
}),
|
|
494
|
+
...(view.csp?.connectDomains && {
|
|
495
|
+
connectDomains: view.csp.connectDomains,
|
|
496
|
+
}),
|
|
497
|
+
...(view.csp?.frameDomains && {
|
|
498
|
+
frameDomains: view.csp.frameDomains,
|
|
499
|
+
}),
|
|
500
|
+
...(view.csp?.baseUriDomains && {
|
|
501
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
322
502
|
}),
|
|
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
503
|
},
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
507
|
+
ui: overrides,
|
|
508
|
+
});
|
|
509
|
+
const base = {
|
|
510
|
+
...ui,
|
|
511
|
+
...(view.description && {
|
|
512
|
+
"openai/widgetDescription": view.description,
|
|
513
|
+
}),
|
|
514
|
+
...(view.csp?.redirectDomains && {
|
|
515
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
516
|
+
}),
|
|
517
|
+
};
|
|
518
|
+
if (view._meta) {
|
|
519
|
+
return { ...base, ...view._meta };
|
|
520
|
+
}
|
|
521
|
+
return base;
|
|
522
|
+
},
|
|
523
|
+
};
|
|
524
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
525
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
526
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
527
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
528
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
529
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
530
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
531
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
361
532
|
}
|
|
362
533
|
registerViewResource({ name, viewResource, view, }) {
|
|
363
534
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
535
|
+
const buildMeta = (extra) => {
|
|
536
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
537
|
+
return buildContentMeta({
|
|
538
|
+
resourceDomains: [serverUrl],
|
|
539
|
+
connectDomains,
|
|
540
|
+
domain: serverUrl,
|
|
541
|
+
baseUriDomains: [serverUrl],
|
|
542
|
+
}, contentMetaOverrides);
|
|
543
|
+
};
|
|
544
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
545
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
546
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
364
547
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
365
548
|
const isProduction = process.env.NODE_ENV === "production";
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
}
|
|
549
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
550
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
551
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
552
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
553
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
393
554
|
const html = isProduction
|
|
394
555
|
? templateHelper.renderProduction({
|
|
395
556
|
hostType,
|
|
396
|
-
serverUrl,
|
|
557
|
+
serverUrl: viewBase,
|
|
397
558
|
viewFile: this.lookupViewFile(view.component),
|
|
398
559
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
399
560
|
})
|
|
400
561
|
: templateHelper.renderDevelopment({
|
|
401
562
|
hostType,
|
|
402
|
-
serverUrl,
|
|
563
|
+
serverUrl: viewBase,
|
|
403
564
|
viewName: view.component,
|
|
404
565
|
});
|
|
405
|
-
const connectDomains = [serverUrl];
|
|
406
|
-
if (!isProduction) {
|
|
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` };
|
|
424
|
-
}
|
|
425
|
-
const contentMeta = buildContentMeta({
|
|
426
|
-
resourceDomains: [serverUrl],
|
|
427
|
-
connectDomains,
|
|
428
|
-
domain: serverUrl,
|
|
429
|
-
baseUriDomains: [serverUrl],
|
|
430
|
-
}, contentMetaOverrides);
|
|
431
566
|
return {
|
|
432
567
|
contents: [
|
|
433
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
568
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
434
569
|
],
|
|
435
570
|
};
|
|
436
571
|
});
|
|
437
572
|
}
|
|
573
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
574
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
575
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
576
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
577
|
+
}
|
|
438
578
|
wrapHandler(cb, { attachViewUUID }) {
|
|
439
579
|
return async (args, extra) => {
|
|
440
580
|
const result = await cb(args, extra);
|
|
@@ -507,8 +647,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
507
647
|
}
|
|
508
648
|
const config = args[0];
|
|
509
649
|
const cb = args[1];
|
|
510
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
650
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
511
651
|
const toolMeta = { ...userToolMeta };
|
|
652
|
+
if (securitySchemes) {
|
|
653
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
654
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
655
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
656
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
657
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
658
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
659
|
+
}
|
|
512
660
|
if (view) {
|
|
513
661
|
this.enforceOneToolPerView(view.component, name);
|
|
514
662
|
this.registerViewResources(name, view, toolMeta);
|