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