skybridge 0.0.0-dev.f864975 → 0.0.0-dev.f865597
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 +2 -0
- package/dist/cli/build-helpers.d.ts +6 -2
- package/dist/cli/build-helpers.js +37 -12
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +69 -3
- package/dist/cli/build-helpers.test.js.map +1 -1
- 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.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/resolve-skybridge-config.d.ts +5 -0
- package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
- package/dist/cli/resolve-skybridge-config.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 +70 -67
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -2
- package/dist/commands/build.js +2 -61
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +34 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +28 -7
- package/dist/server/auth/discovery.js +26 -8
- package/dist/server/auth/discovery.js.map +1 -1
- package/dist/server/auth/discovery.test.js +12 -0
- package/dist/server/auth/discovery.test.js.map +1 -1
- 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.js +48 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/authplane.d.ts +47 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +138 -0
- package/dist/server/auth/providers/authplane.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 +20 -2
- package/dist/server/auth/providers/custom.js +33 -12
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +68 -25
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +9 -7
- package/dist/server/auth/providers/descope.js +38 -8
- package/dist/server/auth/providers/descope.js.map +1 -1
- package/dist/server/auth/providers/descope.test.js +40 -15
- package/dist/server/auth/providers/descope.test.js.map +1 -1
- 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 +2 -1
- package/dist/server/auth/providers/stytch.js +1 -5
- package/dist/server/auth/providers/stytch.js.map +1 -1
- package/dist/server/auth/providers/workos.d.ts +2 -1
- package/dist/server/auth/providers/workos.js +1 -5
- package/dist/server/auth/providers/workos.js.map +1 -1
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +3 -1
- package/dist/server/auth/setup.js +64 -23
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +291 -2
- package/dist/server/auth/setup.test.js.map +1 -1
- package/dist/server/auth/verify.d.ts +3 -2
- package/dist/server/auth/verify.js +2 -1
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth/verify.test.js +13 -0
- package/dist/server/auth/verify.test.js.map +1 -1
- package/dist/server/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.d.ts +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.js +5 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/server.d.ts +61 -9
- package/dist/server/server.js +208 -118
- 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.js +93 -10
- package/dist/server/view-resource-resolution.test.js.map +1 -1
- package/dist/server/viewsDevServer.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/view.test.js +70 -102
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +341 -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 +224 -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 +13 -2
- package/dist/web/bridges/mcp-app/bridge.js +51 -7
- 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/types.d.ts +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +10 -0
- 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/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/test/utils.d.ts +2 -1
- package/dist/web/hooks/test/utils.js +1 -1
- 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.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-host-info.d.ts +22 -0
- package/dist/web/hooks/use-host-info.js +30 -0
- package/dist/web/hooks/use-host-info.js.map +1 -0
- package/dist/web/hooks/use-host-info.test.d.ts +1 -0
- package/dist/web/hooks/use-host-info.test.js +59 -0
- package/dist/web/hooks/use-host-info.test.js.map +1 -0
- 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-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.test.js +37 -27
- 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.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +37 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +6 -0
- package/dist/web/plugin/plugin.js +3 -3
- package/dist/web/plugin/plugin.js.map +1 -1
- package/package.json +21 -20
- package/dist/cli/resolve-views-dir.d.ts +0 -1
- package/dist/cli/resolve-views-dir.js.map +0 -1
- package/dist/server/auth/providers/stytch.test.js +0 -33
- package/dist/server/auth/providers/stytch.test.js.map +0 -1
- package/dist/server/auth/providers/workos.test.js +0 -41
- package/dist/server/auth/providers/workos.test.js.map +0 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
- package/dist/web/bridges/mcp-app/adaptor.js +0 -283
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- /package/dist/{server/auth/providers/stytch.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/server/auth/providers/{workos.test.d.ts → auth0.test.d.ts} +0 -0
package/dist/server/server.js
CHANGED
|
@@ -6,11 +6,14 @@ 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 { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
9
10
|
import { setupOAuth } from "./auth/setup.js";
|
|
10
11
|
import { createApp } from "./express.js";
|
|
12
|
+
import { hostFromUserAgent } from "./host.js";
|
|
11
13
|
import { createMiddlewareEntry } from "./metric.js";
|
|
12
14
|
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
13
15
|
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
16
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
14
17
|
import { templateHelper } from "./templateHelper.js";
|
|
15
18
|
const mergeWithUnion = (target, source) => {
|
|
16
19
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -19,6 +22,20 @@ const mergeWithUnion = (target, source) => {
|
|
|
19
22
|
}
|
|
20
23
|
});
|
|
21
24
|
};
|
|
25
|
+
const SKILLS_DIR = "src/skills";
|
|
26
|
+
/**
|
|
27
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
28
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
29
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
30
|
+
*/
|
|
31
|
+
function normalizeForwardedPrefix(raw) {
|
|
32
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
33
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
34
|
+
if (trimmed === "") {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
38
|
+
}
|
|
22
39
|
/**
|
|
23
40
|
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
24
41
|
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
@@ -92,6 +109,47 @@ let pendingBuildManifest = null;
|
|
|
92
109
|
export function __setBuildManifest(manifest) {
|
|
93
110
|
pendingBuildManifest = manifest;
|
|
94
111
|
}
|
|
112
|
+
let pendingSkillsManifest = null;
|
|
113
|
+
export function __setSkillsManifest(manifest) {
|
|
114
|
+
pendingSkillsManifest = manifest;
|
|
115
|
+
}
|
|
116
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
117
|
+
// exists — the capability must be present for the `initialize` response.
|
|
118
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
119
|
+
if (!skybridgeOptions?.skills) {
|
|
120
|
+
return options;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
...options,
|
|
124
|
+
capabilities: {
|
|
125
|
+
...options?.capabilities,
|
|
126
|
+
extensions: {
|
|
127
|
+
...options?.capabilities?.extensions,
|
|
128
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Collapses registerTool's two overloads into a single { config, cb } shape.
|
|
134
|
+
// registerTool("greet", { description }, handler)
|
|
135
|
+
// -> { config: { name: "greet", description }, cb: handler }
|
|
136
|
+
// registerTool({ name: "greet", description }, handler)
|
|
137
|
+
// -> { config: { name: "greet", description }, cb: handler }
|
|
138
|
+
function normalizeRegisterToolArgs(args) {
|
|
139
|
+
if (typeof args[0] === "string") {
|
|
140
|
+
return {
|
|
141
|
+
config: {
|
|
142
|
+
name: args[0],
|
|
143
|
+
...args[1],
|
|
144
|
+
},
|
|
145
|
+
cb: args[2],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
config: args[0],
|
|
150
|
+
cb: args[1],
|
|
151
|
+
};
|
|
152
|
+
}
|
|
95
153
|
export class McpServer extends McpServerBaseOmitted {
|
|
96
154
|
/**
|
|
97
155
|
* The underlying Express app. Use this to extend the HTTP server with
|
|
@@ -123,14 +181,19 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
123
181
|
viteManifest = null;
|
|
124
182
|
serverInfo;
|
|
125
183
|
serverOptions;
|
|
184
|
+
oauthEnabled = false;
|
|
185
|
+
resolveResourceMetadataUrl;
|
|
186
|
+
securitySchemesByTool = new Map();
|
|
126
187
|
constructor(serverInfo, options, skybridgeOptions) {
|
|
127
|
-
|
|
188
|
+
const mergedOptions = withSkillsCapability(options, skybridgeOptions);
|
|
189
|
+
super(serverInfo, mergedOptions);
|
|
128
190
|
this.serverInfo = serverInfo;
|
|
129
|
-
this.serverOptions =
|
|
191
|
+
this.serverOptions = mergedOptions;
|
|
130
192
|
this.express = express();
|
|
131
193
|
this.express.use(express.json(skybridgeOptions?.json));
|
|
132
194
|
if (skybridgeOptions?.oauth) {
|
|
133
|
-
|
|
195
|
+
this.oauthEnabled = true;
|
|
196
|
+
this.resolveResourceMetadataUrl = setupOAuth(this.express, skybridgeOptions.oauth, this.securitySchemesByTool);
|
|
134
197
|
}
|
|
135
198
|
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
136
199
|
// user code. Consume-once: clear after the first construction so a
|
|
@@ -141,6 +204,19 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
141
204
|
this.setViteManifest(pendingBuildManifest);
|
|
142
205
|
pendingBuildManifest = null;
|
|
143
206
|
}
|
|
207
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
208
|
+
}
|
|
209
|
+
setupSkills(enabled) {
|
|
210
|
+
const manifest = pendingSkillsManifest;
|
|
211
|
+
pendingSkillsManifest = null;
|
|
212
|
+
if (!enabled) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const skills = manifest ?? discoverSkills(SKILLS_DIR);
|
|
216
|
+
if (skills.length === 0) {
|
|
217
|
+
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.`);
|
|
218
|
+
}
|
|
219
|
+
registerSkills(this, skills);
|
|
144
220
|
}
|
|
145
221
|
use(pathOrHandler, ...handlers) {
|
|
146
222
|
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
@@ -236,7 +312,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
236
312
|
const result = (await next());
|
|
237
313
|
for (const content of result.contents ?? []) {
|
|
238
314
|
if (typeof content.uri === "string" &&
|
|
239
|
-
stripQuery(content.uri) ===
|
|
315
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
240
316
|
content.uri = requested;
|
|
241
317
|
}
|
|
242
318
|
}
|
|
@@ -249,16 +325,33 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
249
325
|
}
|
|
250
326
|
},
|
|
251
327
|
};
|
|
328
|
+
// ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
|
|
329
|
+
// still Draft), but the SDK's registerTool strips unknown top-level fields, so
|
|
330
|
+
// it's stashed in `_meta` at registration. This restores it to the top level
|
|
331
|
+
// on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
|
|
332
|
+
// { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
|
|
333
|
+
// -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
|
|
334
|
+
const toolsListSecuritySchemesEntry = {
|
|
335
|
+
filter: "tools/list",
|
|
336
|
+
handler: async (_req, _extra, next) => {
|
|
337
|
+
const result = (await next());
|
|
338
|
+
for (const tool of result.tools) {
|
|
339
|
+
const schemes = tool._meta?.securitySchemes;
|
|
340
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
341
|
+
tool.securitySchemes = schemes;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return result;
|
|
345
|
+
},
|
|
346
|
+
};
|
|
252
347
|
const monitoringEntry = createMiddlewareEntry();
|
|
253
348
|
const entries = [
|
|
254
349
|
...(monitoringEntry ? [monitoringEntry] : []),
|
|
255
350
|
viewListMetaEntry,
|
|
256
351
|
viewReadResolveEntry,
|
|
352
|
+
toolsListSecuritySchemesEntry,
|
|
257
353
|
...this.mcpMiddlewareEntries,
|
|
258
354
|
];
|
|
259
|
-
if (entries.length === 0) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
355
|
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
263
356
|
const instrumentMap = (map, isNotification) => {
|
|
264
357
|
for (const [method, handler] of map) {
|
|
@@ -381,8 +474,13 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
381
474
|
const val = headers[key];
|
|
382
475
|
return Array.isArray(val) ? val[0] : val;
|
|
383
476
|
};
|
|
384
|
-
const isClaude = header("user-agent") === "
|
|
477
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
385
478
|
const serverUrl = resolveServerOrigin(header);
|
|
479
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
480
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
481
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
482
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
483
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
386
484
|
const connectDomains = [serverUrl];
|
|
387
485
|
if (!isProduction) {
|
|
388
486
|
const wsUrl = new URL(serverUrl);
|
|
@@ -403,114 +501,77 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
403
501
|
.slice(0, 32);
|
|
404
502
|
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
405
503
|
}
|
|
406
|
-
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
504
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
407
505
|
}
|
|
408
506
|
registerViewResources(toolName, view, toolMeta) {
|
|
409
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
410
507
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
411
508
|
// their cache when the bundle changes, but keep the URI stable across
|
|
412
509
|
// `tools/list` calls when the bundle hasn't changed.
|
|
413
510
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
"openai/widgetDomain": domain,
|
|
426
|
-
"openai/widgetDescription": view.description,
|
|
427
|
-
};
|
|
428
|
-
const fromView = {
|
|
429
|
-
"openai/widgetCSP": {
|
|
430
|
-
resource_domains: view.csp?.resourceDomains,
|
|
431
|
-
connect_domains: view.csp?.connectDomains,
|
|
432
|
-
frame_domains: view.csp?.frameDomains,
|
|
433
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
511
|
+
const viewResource = {
|
|
512
|
+
hostType: "mcp-app",
|
|
513
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
514
|
+
mimeType: "text/html;profile=mcp-app",
|
|
515
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
516
|
+
const defaults = {
|
|
517
|
+
ui: {
|
|
518
|
+
csp: {
|
|
519
|
+
resourceDomains,
|
|
520
|
+
connectDomains,
|
|
521
|
+
baseUriDomains,
|
|
434
522
|
},
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
458
|
-
mimeType: "text/html;profile=mcp-app",
|
|
459
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
460
|
-
const defaults = {
|
|
461
|
-
ui: {
|
|
462
|
-
csp: {
|
|
463
|
-
resourceDomains,
|
|
464
|
-
connectDomains,
|
|
465
|
-
baseUriDomains,
|
|
466
|
-
},
|
|
467
|
-
domain,
|
|
468
|
-
},
|
|
469
|
-
};
|
|
470
|
-
const fromView = {
|
|
471
|
-
ui: {
|
|
472
|
-
...(view.description && { description: view.description }),
|
|
473
|
-
...(view.prefersBorder !== undefined && {
|
|
474
|
-
prefersBorder: view.prefersBorder,
|
|
523
|
+
domain,
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
const fromView = {
|
|
527
|
+
ui: {
|
|
528
|
+
...(view.description && { description: view.description }),
|
|
529
|
+
...(view.prefersBorder !== undefined && {
|
|
530
|
+
prefersBorder: view.prefersBorder,
|
|
531
|
+
}),
|
|
532
|
+
...(view.domain && { domain: view.domain }),
|
|
533
|
+
csp: {
|
|
534
|
+
...(view.csp?.resourceDomains && {
|
|
535
|
+
resourceDomains: view.csp.resourceDomains,
|
|
536
|
+
}),
|
|
537
|
+
...(view.csp?.connectDomains && {
|
|
538
|
+
connectDomains: view.csp.connectDomains,
|
|
539
|
+
}),
|
|
540
|
+
...(view.csp?.frameDomains && {
|
|
541
|
+
frameDomains: view.csp.frameDomains,
|
|
542
|
+
}),
|
|
543
|
+
...(view.csp?.baseUriDomains && {
|
|
544
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
475
545
|
}),
|
|
476
|
-
...(view.domain && { domain: view.domain }),
|
|
477
|
-
csp: {
|
|
478
|
-
...(view.csp?.resourceDomains && {
|
|
479
|
-
resourceDomains: view.csp.resourceDomains,
|
|
480
|
-
}),
|
|
481
|
-
...(view.csp?.connectDomains && {
|
|
482
|
-
connectDomains: view.csp.connectDomains,
|
|
483
|
-
}),
|
|
484
|
-
...(view.csp?.frameDomains && {
|
|
485
|
-
frameDomains: view.csp.frameDomains,
|
|
486
|
-
}),
|
|
487
|
-
...(view.csp?.baseUriDomains && {
|
|
488
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
489
|
-
}),
|
|
490
|
-
...(view.csp?.redirectDomains && {
|
|
491
|
-
redirectDomains: view.csp.redirectDomains,
|
|
492
|
-
}),
|
|
493
|
-
},
|
|
494
546
|
},
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
550
|
+
ui: overrides,
|
|
551
|
+
});
|
|
552
|
+
const base = {
|
|
553
|
+
...ui,
|
|
554
|
+
...(view.description && {
|
|
555
|
+
"openai/widgetDescription": view.description,
|
|
556
|
+
}),
|
|
557
|
+
...(view.csp?.redirectDomains && {
|
|
558
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
559
|
+
}),
|
|
560
|
+
};
|
|
561
|
+
if (view._meta) {
|
|
562
|
+
return { ...base, ...view._meta };
|
|
563
|
+
}
|
|
564
|
+
return base;
|
|
565
|
+
},
|
|
566
|
+
};
|
|
567
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
568
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
569
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
570
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
571
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
572
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
573
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
574
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
514
575
|
}
|
|
515
576
|
registerViewResource({ name, viewResource, view, }) {
|
|
516
577
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
@@ -525,19 +586,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
525
586
|
};
|
|
526
587
|
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
527
588
|
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
589
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
528
590
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
529
591
|
const isProduction = process.env.NODE_ENV === "production";
|
|
530
|
-
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
592
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
593
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
594
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
595
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
596
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
531
597
|
const html = isProduction
|
|
532
598
|
? templateHelper.renderProduction({
|
|
533
599
|
hostType,
|
|
534
|
-
serverUrl,
|
|
600
|
+
serverUrl: viewBase,
|
|
535
601
|
viewFile: this.lookupViewFile(view.component),
|
|
536
602
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
537
603
|
})
|
|
538
604
|
: templateHelper.renderDevelopment({
|
|
539
605
|
hostType,
|
|
540
|
-
serverUrl,
|
|
606
|
+
serverUrl: viewBase,
|
|
541
607
|
viewName: view.component,
|
|
542
608
|
});
|
|
543
609
|
return {
|
|
@@ -547,8 +613,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
547
613
|
};
|
|
548
614
|
});
|
|
549
615
|
}
|
|
550
|
-
|
|
616
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
617
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
618
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
619
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
620
|
+
}
|
|
621
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, }) {
|
|
551
622
|
return async (args, extra) => {
|
|
623
|
+
if (this.oauthEnabled) {
|
|
624
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.authInfo);
|
|
625
|
+
if (failure) {
|
|
626
|
+
const headers = extra?.requestInfo?.headers ?? {};
|
|
627
|
+
const header = (key) => {
|
|
628
|
+
const value = headers[key];
|
|
629
|
+
return Array.isArray(value) ? value[0] : value;
|
|
630
|
+
};
|
|
631
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
632
|
+
}
|
|
633
|
+
}
|
|
552
634
|
const result = await cb(args, extra);
|
|
553
635
|
return {
|
|
554
636
|
...result,
|
|
@@ -613,14 +695,19 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
613
695
|
}
|
|
614
696
|
registerTool(...args) {
|
|
615
697
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
698
|
+
const { config, cb } = normalizeRegisterToolArgs(args);
|
|
699
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
700
|
+
const authNeedsProvider = auth !== undefined &&
|
|
701
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
702
|
+
if (rawSecuritySchemes === undefined &&
|
|
703
|
+
authNeedsProvider &&
|
|
704
|
+
!this.oauthEnabled) {
|
|
705
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
619
706
|
}
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
707
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
708
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
623
709
|
const toolMeta = { ...userToolMeta };
|
|
710
|
+
this.securitySchemesByTool.set(name, securitySchemes);
|
|
624
711
|
if (securitySchemes) {
|
|
625
712
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
626
713
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
@@ -633,7 +720,10 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
633
720
|
this.enforceOneToolPerView(view.component, name);
|
|
634
721
|
this.registerViewResources(name, view, toolMeta);
|
|
635
722
|
}
|
|
636
|
-
const wrappedCb = this.
|
|
723
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
724
|
+
attachViewUUID: Boolean(view),
|
|
725
|
+
securitySchemes,
|
|
726
|
+
});
|
|
637
727
|
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
|
|
638
728
|
return this;
|
|
639
729
|
}
|