skybridge 0.0.0-dev.df033f6 → 0.0.0-dev.df0cfdd
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 +3 -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 +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.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 +35 -3
- 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.js +28 -0
- package/dist/context-warnings.test.js.map +1 -0
- 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.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +44 -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 +40 -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 +50 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- 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 +51 -0
- package/dist/server/auth/providers/clerk.js +19 -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 +30 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +40 -0
- package/dist/server/auth/providers/custom.js +56 -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 +158 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +44 -0
- package/dist/server/auth/providers/descope.js +44 -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 +62 -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 +25 -0
- package/dist/server/auth/providers/stytch.js +16 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- 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 +33 -0
- package/dist/server/auth/providers/workos.js +15 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- 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 +6 -0
- package/dist/server/auth/setup.js +92 -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 +508 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +46 -0
- package/dist/server/auth/verify.js +62 -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 +149 -0
- package/dist/server/auth/verify.test.js.map +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 +13 -2
- package/dist/server/index.js +11 -1
- 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/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 +93 -25
- package/dist/server/server.js +233 -142
- 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/package.json +21 -24
- 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/web/plugin/data-llm.test.js +0 -81
- package/dist/web/plugin/data-llm.test.js.map +0 -1
- package/dist/web/plugin/plugin.d.ts +0 -33
- package/dist/web/plugin/plugin.js +0 -189
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/scan-views.d.ts +0 -16
- package/dist/web/plugin/scan-views.js +0 -88
- package/dist/web/plugin/scan-views.js.map +0 -1
- package/dist/web/plugin/scan-views.test.js +0 -99
- package/dist/web/plugin/scan-views.test.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.d.ts +0 -12
- package/dist/web/plugin/transform-data-llm.js +0 -96
- package/dist/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.test.js +0 -81
- package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/web/plugin/validate-view.d.ts +0 -1
- package/dist/web/plugin/validate-view.js +0 -9
- package/dist/web/plugin/validate-view.js.map +0 -1
- package/dist/web/plugin/validate-view.test.js +0 -24
- package/dist/web/plugin/validate-view.test.js.map +0 -1
- /package/dist/{web/plugin/data-llm.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/discovery.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
package/dist/server/server.js
CHANGED
|
@@ -6,9 +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";
|
|
11
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
9
12
|
import { createApp } from "./express.js";
|
|
13
|
+
import { hostFromUserAgent } from "./host.js";
|
|
10
14
|
import { createMiddlewareEntry } from "./metric.js";
|
|
11
|
-
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
15
|
+
import { buildMiddlewareChain, captureToolError, getHandlerMaps, } from "./middleware.js";
|
|
16
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
17
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
12
18
|
import { templateHelper } from "./templateHelper.js";
|
|
13
19
|
const mergeWithUnion = (target, source) => {
|
|
14
20
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -17,6 +23,20 @@ const mergeWithUnion = (target, source) => {
|
|
|
17
23
|
}
|
|
18
24
|
});
|
|
19
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
|
+
}
|
|
20
40
|
/**
|
|
21
41
|
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
22
42
|
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
@@ -90,6 +110,47 @@ let pendingBuildManifest = null;
|
|
|
90
110
|
export function __setBuildManifest(manifest) {
|
|
91
111
|
pendingBuildManifest = manifest;
|
|
92
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
|
+
}
|
|
93
154
|
export class McpServer extends McpServerBaseOmitted {
|
|
94
155
|
/**
|
|
95
156
|
* The underlying Express app. Use this to extend the HTTP server with
|
|
@@ -121,12 +182,20 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
121
182
|
viteManifest = null;
|
|
122
183
|
serverInfo;
|
|
123
184
|
serverOptions;
|
|
185
|
+
oauthEnabled = false;
|
|
186
|
+
resolveResourceMetadataUrl;
|
|
187
|
+
securitySchemesByTool = new Map();
|
|
124
188
|
constructor(serverInfo, options, skybridgeOptions) {
|
|
125
|
-
|
|
189
|
+
const mergedOptions = withSkillsCapability(options, skybridgeOptions);
|
|
190
|
+
super(serverInfo, mergedOptions);
|
|
126
191
|
this.serverInfo = serverInfo;
|
|
127
|
-
this.serverOptions =
|
|
192
|
+
this.serverOptions = mergedOptions;
|
|
128
193
|
this.express = express();
|
|
129
194
|
this.express.use(express.json(skybridgeOptions?.json));
|
|
195
|
+
if (skybridgeOptions?.oauth) {
|
|
196
|
+
this.oauthEnabled = true;
|
|
197
|
+
this.resolveResourceMetadataUrl = setupOAuth(this.express, skybridgeOptions.oauth, this.securitySchemesByTool);
|
|
198
|
+
}
|
|
130
199
|
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
131
200
|
// user code. Consume-once: clear after the first construction so a
|
|
132
201
|
// subsequent test that doesn't prime can't inherit stale state.
|
|
@@ -136,6 +205,19 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
136
205
|
this.setViteManifest(pendingBuildManifest);
|
|
137
206
|
pendingBuildManifest = null;
|
|
138
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);
|
|
139
221
|
}
|
|
140
222
|
use(pathOrHandler, ...handlers) {
|
|
141
223
|
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
@@ -231,7 +313,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
231
313
|
const result = (await next());
|
|
232
314
|
for (const content of result.contents ?? []) {
|
|
233
315
|
if (typeof content.uri === "string" &&
|
|
234
|
-
stripQuery(content.uri) ===
|
|
316
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
235
317
|
content.uri = requested;
|
|
236
318
|
}
|
|
237
319
|
}
|
|
@@ -244,16 +326,33 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
244
326
|
}
|
|
245
327
|
},
|
|
246
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
|
+
};
|
|
247
348
|
const monitoringEntry = createMiddlewareEntry();
|
|
248
349
|
const entries = [
|
|
249
350
|
...(monitoringEntry ? [monitoringEntry] : []),
|
|
250
351
|
viewListMetaEntry,
|
|
251
352
|
viewReadResolveEntry,
|
|
353
|
+
toolsListSecuritySchemesEntry,
|
|
252
354
|
...this.mcpMiddlewareEntries,
|
|
253
355
|
];
|
|
254
|
-
if (entries.length === 0) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
356
|
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
258
357
|
const instrumentMap = (map, isNotification) => {
|
|
259
358
|
for (const [method, handler] of map) {
|
|
@@ -306,7 +405,10 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
306
405
|
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
307
406
|
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
308
407
|
* serverless function entry can call it as a `(req, res)` handler. On
|
|
309
|
-
* Node, returns `undefined` once listening.
|
|
408
|
+
* Node, returns `undefined` once listening. When the process was spawned
|
|
409
|
+
* with an IPC channel, the bound port is reported to the parent as
|
|
410
|
+
* `{ type: "skybridge:listening", port }`, the readiness signal test runners
|
|
411
|
+
* wait on instead of polling.
|
|
310
412
|
*/
|
|
311
413
|
async run() {
|
|
312
414
|
this.applyMcpMiddleware();
|
|
@@ -339,6 +441,8 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
339
441
|
resolve();
|
|
340
442
|
});
|
|
341
443
|
});
|
|
444
|
+
const { port: boundPort } = httpServer.address();
|
|
445
|
+
process.send?.({ type: "skybridge:listening", port: boundPort });
|
|
342
446
|
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
343
447
|
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
344
448
|
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
@@ -346,7 +450,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
346
450
|
navigator.userAgent === "Cloudflare-Workers") {
|
|
347
451
|
const cloudflareNode = "cloudflare:node";
|
|
348
452
|
const { httpServerHandler } = await import(cloudflareNode);
|
|
349
|
-
return httpServerHandler({ port });
|
|
453
|
+
return httpServerHandler({ port: boundPort });
|
|
350
454
|
}
|
|
351
455
|
const shutdown = () => {
|
|
352
456
|
// Drop both handlers so a second signal falls through to Node's default
|
|
@@ -376,28 +480,13 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
376
480
|
const val = headers[key];
|
|
377
481
|
return Array.isArray(val) ? val[0] : val;
|
|
378
482
|
};
|
|
379
|
-
const isClaude = header("user-agent") === "
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
387
|
-
}
|
|
388
|
-
else if (origin) {
|
|
389
|
-
serverUrl = origin;
|
|
390
|
-
}
|
|
391
|
-
else if (host) {
|
|
392
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
393
|
-
? "http"
|
|
394
|
-
: "https";
|
|
395
|
-
serverUrl = `${proto}://${host}`;
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
const devPort = process.env.__PORT || "3000";
|
|
399
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
400
|
-
}
|
|
483
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
484
|
+
const serverUrl = resolveServerOrigin(header);
|
|
485
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
486
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
487
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
488
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
489
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
401
490
|
const connectDomains = [serverUrl];
|
|
402
491
|
if (!isProduction) {
|
|
403
492
|
const wsUrl = new URL(serverUrl);
|
|
@@ -418,114 +507,77 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
418
507
|
.slice(0, 32);
|
|
419
508
|
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
420
509
|
}
|
|
421
|
-
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
510
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
422
511
|
}
|
|
423
512
|
registerViewResources(toolName, view, toolMeta) {
|
|
424
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
425
513
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
426
514
|
// their cache when the bundle changes, but keep the URI stable across
|
|
427
515
|
// `tools/list` calls when the bundle hasn't changed.
|
|
428
516
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
"openai/widgetDomain": domain,
|
|
441
|
-
"openai/widgetDescription": view.description,
|
|
442
|
-
};
|
|
443
|
-
const fromView = {
|
|
444
|
-
"openai/widgetCSP": {
|
|
445
|
-
resource_domains: view.csp?.resourceDomains,
|
|
446
|
-
connect_domains: view.csp?.connectDomains,
|
|
447
|
-
frame_domains: view.csp?.frameDomains,
|
|
448
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
449
|
-
},
|
|
450
|
-
"openai/widgetDomain": view.domain,
|
|
451
|
-
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
452
|
-
};
|
|
453
|
-
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
454
|
-
"openai/widgetDomain": overrides.domain,
|
|
455
|
-
});
|
|
456
|
-
if (view._meta) {
|
|
457
|
-
return { ...base, ...view._meta };
|
|
458
|
-
}
|
|
459
|
-
return base;
|
|
460
|
-
},
|
|
461
|
-
};
|
|
462
|
-
this.registerViewResource({
|
|
463
|
-
name: toolName,
|
|
464
|
-
viewResource,
|
|
465
|
-
view,
|
|
466
|
-
});
|
|
467
|
-
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
468
|
-
}
|
|
469
|
-
if (hosts.includes("mcp-app")) {
|
|
470
|
-
const viewResource = {
|
|
471
|
-
hostType: "mcp-app",
|
|
472
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
473
|
-
mimeType: "text/html;profile=mcp-app",
|
|
474
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
475
|
-
const defaults = {
|
|
476
|
-
ui: {
|
|
477
|
-
csp: {
|
|
478
|
-
resourceDomains,
|
|
479
|
-
connectDomains,
|
|
480
|
-
baseUriDomains,
|
|
481
|
-
},
|
|
482
|
-
domain,
|
|
517
|
+
const viewResource = {
|
|
518
|
+
hostType: "mcp-app",
|
|
519
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
520
|
+
mimeType: "text/html;profile=mcp-app",
|
|
521
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
522
|
+
const defaults = {
|
|
523
|
+
ui: {
|
|
524
|
+
csp: {
|
|
525
|
+
resourceDomains,
|
|
526
|
+
connectDomains,
|
|
527
|
+
baseUriDomains,
|
|
483
528
|
},
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
529
|
+
domain,
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
const fromView = {
|
|
533
|
+
ui: {
|
|
534
|
+
...(view.description && { description: view.description }),
|
|
535
|
+
...(view.prefersBorder !== undefined && {
|
|
536
|
+
prefersBorder: view.prefersBorder,
|
|
537
|
+
}),
|
|
538
|
+
...(view.domain && { domain: view.domain }),
|
|
539
|
+
csp: {
|
|
540
|
+
...(view.csp?.resourceDomains && {
|
|
541
|
+
resourceDomains: view.csp.resourceDomains,
|
|
542
|
+
}),
|
|
543
|
+
...(view.csp?.connectDomains && {
|
|
544
|
+
connectDomains: view.csp.connectDomains,
|
|
545
|
+
}),
|
|
546
|
+
...(view.csp?.frameDomains && {
|
|
547
|
+
frameDomains: view.csp.frameDomains,
|
|
548
|
+
}),
|
|
549
|
+
...(view.csp?.baseUriDomains && {
|
|
550
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
490
551
|
}),
|
|
491
|
-
...(view.domain && { domain: view.domain }),
|
|
492
|
-
csp: {
|
|
493
|
-
...(view.csp?.resourceDomains && {
|
|
494
|
-
resourceDomains: view.csp.resourceDomains,
|
|
495
|
-
}),
|
|
496
|
-
...(view.csp?.connectDomains && {
|
|
497
|
-
connectDomains: view.csp.connectDomains,
|
|
498
|
-
}),
|
|
499
|
-
...(view.csp?.frameDomains && {
|
|
500
|
-
frameDomains: view.csp.frameDomains,
|
|
501
|
-
}),
|
|
502
|
-
...(view.csp?.baseUriDomains && {
|
|
503
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
504
|
-
}),
|
|
505
|
-
...(view.csp?.redirectDomains && {
|
|
506
|
-
redirectDomains: view.csp.redirectDomains,
|
|
507
|
-
}),
|
|
508
|
-
},
|
|
509
552
|
},
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
556
|
+
ui: overrides,
|
|
557
|
+
});
|
|
558
|
+
const base = {
|
|
559
|
+
...ui,
|
|
560
|
+
...(view.description && {
|
|
561
|
+
"openai/widgetDescription": view.description,
|
|
562
|
+
}),
|
|
563
|
+
...(view.csp?.redirectDomains && {
|
|
564
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
565
|
+
}),
|
|
566
|
+
};
|
|
567
|
+
if (view._meta) {
|
|
568
|
+
return { ...base, ...view._meta };
|
|
569
|
+
}
|
|
570
|
+
return base;
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
574
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
575
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
576
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
577
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
578
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
579
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
580
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
529
581
|
}
|
|
530
582
|
registerViewResource({ name, viewResource, view, }) {
|
|
531
583
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
@@ -540,19 +592,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
540
592
|
};
|
|
541
593
|
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
542
594
|
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
595
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
543
596
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
544
597
|
const isProduction = process.env.NODE_ENV === "production";
|
|
545
|
-
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
598
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
599
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
600
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
601
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
602
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
546
603
|
const html = isProduction
|
|
547
604
|
? templateHelper.renderProduction({
|
|
548
605
|
hostType,
|
|
549
|
-
serverUrl,
|
|
606
|
+
serverUrl: viewBase,
|
|
550
607
|
viewFile: this.lookupViewFile(view.component),
|
|
551
608
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
552
609
|
})
|
|
553
610
|
: templateHelper.renderDevelopment({
|
|
554
611
|
hostType,
|
|
555
|
-
serverUrl,
|
|
612
|
+
serverUrl: viewBase,
|
|
556
613
|
viewName: view.component,
|
|
557
614
|
});
|
|
558
615
|
return {
|
|
@@ -562,9 +619,34 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
562
619
|
};
|
|
563
620
|
});
|
|
564
621
|
}
|
|
565
|
-
|
|
622
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
623
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
624
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
625
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
626
|
+
}
|
|
627
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
566
628
|
return async (args, extra) => {
|
|
567
|
-
const
|
|
629
|
+
const toolExtra = extra ?? args;
|
|
630
|
+
if (this.oauthEnabled) {
|
|
631
|
+
const failure = evaluateSecuritySchemes(securitySchemes, toolExtra?.authInfo);
|
|
632
|
+
if (failure) {
|
|
633
|
+
const headers = toolExtra?.requestInfo?.headers ?? {};
|
|
634
|
+
const header = (key) => {
|
|
635
|
+
const value = headers[key];
|
|
636
|
+
return Array.isArray(value) ? value[0] : value;
|
|
637
|
+
};
|
|
638
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
let result;
|
|
642
|
+
try {
|
|
643
|
+
result = await cb(args, extra);
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
captureToolError(toolExtra, error);
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
warnOnLargeToolOutput(result, toolName);
|
|
568
650
|
return {
|
|
569
651
|
...result,
|
|
570
652
|
content: normalizeContent(result.content),
|
|
@@ -628,14 +710,19 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
628
710
|
}
|
|
629
711
|
registerTool(...args) {
|
|
630
712
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
713
|
+
const { config, cb } = normalizeRegisterToolArgs(args);
|
|
714
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
715
|
+
const authNeedsProvider = auth !== undefined &&
|
|
716
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
717
|
+
if (rawSecuritySchemes === undefined &&
|
|
718
|
+
authNeedsProvider &&
|
|
719
|
+
!this.oauthEnabled) {
|
|
720
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
634
721
|
}
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
722
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
723
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
638
724
|
const toolMeta = { ...userToolMeta };
|
|
725
|
+
this.securitySchemesByTool.set(name, securitySchemes);
|
|
639
726
|
if (securitySchemes) {
|
|
640
727
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
641
728
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
@@ -648,7 +735,11 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
648
735
|
this.enforceOneToolPerView(view.component, name);
|
|
649
736
|
this.registerViewResources(name, view, toolMeta);
|
|
650
737
|
}
|
|
651
|
-
const wrappedCb = this.
|
|
738
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
739
|
+
attachViewUUID: Boolean(view),
|
|
740
|
+
securitySchemes,
|
|
741
|
+
toolName: name,
|
|
742
|
+
});
|
|
652
743
|
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
|
|
653
744
|
return this;
|
|
654
745
|
}
|