skybridge 0.0.0-dev.a955b71 → 0.0.0-dev.a961973
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 +11 -17
- package/dist/cli/build-helpers.d.ts +6 -2
- package/dist/cli/build-helpers.js +39 -14
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +73 -5
- 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/detect-port.js +0 -1
- package/dist/cli/detect-port.js.map +1 -1
- 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 +90 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +25 -1
- package/dist/cli/use-nodemon.js +96 -63
- 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 +38 -6
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +2 -2
- package/dist/commands/start.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/app.d.ts +194 -0
- package/dist/server/app.js +266 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/app.test.js +97 -0
- package/dist/server/app.test.js.map +1 -0
- package/dist/server/auth/discovery.d.ts +2 -1
- package/dist/server/auth/discovery.js +2 -2
- package/dist/server/auth/discovery.js.map +1 -1
- package/dist/server/auth/index.d.ts +35 -5
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/providers/auth0.d.ts +25 -3
- package/dist/server/auth/providers/auth0.js +13 -8
- package/dist/server/auth/providers/auth0.js.map +1 -1
- package/dist/server/auth/providers/auth0.test.js +5 -3
- 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.js +143 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +40 -3
- 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 +20 -4
- package/dist/server/auth/providers/custom.js +33 -11
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +71 -17
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +32 -3
- package/dist/server/auth/providers/descope.js +13 -2
- 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 +16 -3
- 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 +25 -3
- 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 +66 -26
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +349 -20
- 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 +27 -3
- 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.js +130 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +43 -6
- package/dist/server/auth.js +4 -5
- package/dist/server/auth.js.map +1 -1
- package/dist/server/build-manifest.test.js +7 -6
- package/dist/server/build-manifest.test.js.map +1 -1
- package/dist/server/content-helpers.d.ts +1 -1
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.d.ts +23 -3
- package/dist/server/express.js +38 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +220 -103
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +1 -1
- package/dist/server/file-ref.js +1 -1
- package/dist/server/file-ref.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 +16 -9
- package/dist/server/index.js +9 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp-errors.test.d.ts +1 -0
- package/dist/server/mcp-errors.test.js +41 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/middleware.d.ts +35 -10
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +242 -134
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +27 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/server.d.ts +138 -129
- package/dist/server/server.js +210 -272
- 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 +86 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +27 -0
- package/dist/server/skills.js +188 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +243 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/templateHelper.d.ts +0 -3
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js +4 -8
- package/dist/server/templates.generated.js.map +1 -1
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +88 -0
- package/dist/server/tool-extra.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 +81 -8
- 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 +9 -11
- package/dist/test/utils.js +220 -201
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +44 -40
- package/dist/test/view.test.js.map +1 -1
- package/dist/views/index.d.ts +10 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/{web/plugin → views}/scan-views.js +1 -1
- package/dist/views/scan-views.js.map +1 -0
- package/dist/views/scan-views.test.d.ts +1 -0
- package/dist/views/scan-views.test.js.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/{web/plugin → views}/validate-view.js +2 -2
- package/dist/views/validate-view.js.map +1 -0
- package/dist/views/validate-view.test.d.ts +1 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.js +22 -5
- package/dist/web/bridges/adaptor.js.map +1 -1
- package/dist/web/bridges/adaptor.test.js +34 -6
- package/dist/web/bridges/adaptor.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.js +1 -1
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +4 -4
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +4 -4
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.js +2 -2
- package/dist/web/bridges/get-adaptor.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.js +6 -4
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.js +2 -2
- package/dist/web/bridges/mcp-app/bridge.test.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/use-mcp-app-context.d.ts +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +18 -13
- package/dist/web/bridges/types.js +1 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/create-store.test.js +2 -2
- 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 +11 -2
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -18
- package/dist/web/generate-helpers.js +19 -15
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +3 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +2 -1
- package/dist/web/hooks/index.js +2 -1
- 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 +2 -2
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +1 -1
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +1 -1
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +1 -3
- package/dist/web/hooks/use-download.js +1 -2
- package/dist/web/hooks/use-download.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +7 -7
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +1 -1
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +22 -0
- package/dist/web/hooks/use-host.js +30 -0
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/use-host.test.js +59 -0
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +2 -2
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +3 -4
- package/dist/web/hooks/use-register-view-tool.js +1 -1
- package/dist/web/hooks/use-register-view-tool.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +1 -1
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +1 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +1 -1
- package/dist/web/hooks/use-request-size.js +1 -1
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +1 -1
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +2 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +1 -20
- package/dist/web/hooks/use-tool-info.js +0 -1
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +0 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +2 -7
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +3 -2
- package/dist/web/hooks/use-user.js +4 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +5 -3
- 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 +33 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/use-viewport.test.d.ts +1 -0
- package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +12 -32
- package/dist/web/hooks/use-viewport.test.js.map +1 -0
- package/dist/web/mount-view.d.ts +3 -2
- package/dist/web/mount-view.js +5 -8
- package/dist/web/mount-view.js.map +1 -1
- package/package.json +31 -28
- package/dist/cli/resolve-views-dir.d.ts +0 -1
- package/dist/cli/resolve-views-dir.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -24
- package/dist/web/hooks/use-layout.js +0 -25
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.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.js.map +0 -1
- 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.map +0 -1
- package/dist/web/plugin/validate-view.test.js.map +0 -1
- /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/providers/authplane.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/{web/plugin → views}/scan-views.d.ts +0 -0
- /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
package/dist/server/server.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import http from "node:http";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import { createApp } from "./express.js";
|
|
11
|
-
import { createMiddlewareEntry } from "./metric.js";
|
|
12
|
-
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
4
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/server";
|
|
5
|
+
import { warnOnLargeToolOutput } from "../context-warnings.js";
|
|
6
|
+
import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
7
|
+
import { hostFromUserAgent } from "./host.js";
|
|
8
|
+
import { captureToolError } from "./middleware.js";
|
|
13
9
|
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
10
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
14
11
|
import { templateHelper } from "./templateHelper.js";
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
const unionOf = (base, extra) => extra ? [...new Set([...base, ...extra])] : base;
|
|
13
|
+
const SKILLS_DIR = "src/skills";
|
|
14
|
+
/**
|
|
15
|
+
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
16
|
+
* path. Takes the first hop of a comma-separated proxy chain.
|
|
17
|
+
* "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
|
|
18
|
+
*/
|
|
19
|
+
function normalizeForwardedPrefix(raw) {
|
|
20
|
+
const firstHop = raw?.split(",")[0]?.trim() ?? "";
|
|
21
|
+
const trimmed = firstHop.replace(/\/+$/, "");
|
|
22
|
+
if (trimmed === "") {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
26
|
+
}
|
|
22
27
|
/**
|
|
23
28
|
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
24
29
|
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
@@ -47,35 +52,6 @@ export function normalizeContent(content) {
|
|
|
47
52
|
return [content];
|
|
48
53
|
}
|
|
49
54
|
const McpServerBaseOmitted = McpServerBase;
|
|
50
|
-
/**
|
|
51
|
-
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
52
|
-
* registry, view resources, an embedded Express app, and protocol-level
|
|
53
|
-
* middleware. Construct it with the same `Implementation` info you would pass
|
|
54
|
-
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
55
|
-
* then call {@link McpServer.run} to start the HTTP server.
|
|
56
|
-
*
|
|
57
|
-
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
58
|
-
* shape, so `typeof server` carries enough information for view-side helpers
|
|
59
|
-
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
60
|
-
*
|
|
61
|
-
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
62
|
-
* chaining; you almost never set this manually.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
67
|
-
* .registerTool({
|
|
68
|
-
* name: "search",
|
|
69
|
-
* inputSchema: { query: z.string() },
|
|
70
|
-
* view: { component: "search" },
|
|
71
|
-
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
72
|
-
*
|
|
73
|
-
* await server.run();
|
|
74
|
-
* export type AppType = typeof server;
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
78
|
-
*/
|
|
79
55
|
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
80
56
|
// Set at module scope rather than passed through the constructor because the
|
|
81
57
|
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
@@ -92,25 +68,62 @@ let pendingBuildManifest = null;
|
|
|
92
68
|
export function __setBuildManifest(manifest) {
|
|
93
69
|
pendingBuildManifest = manifest;
|
|
94
70
|
}
|
|
71
|
+
let pendingSkillsManifest = null;
|
|
72
|
+
let cachedDiskManifest = null;
|
|
73
|
+
let discoveredSkills = null;
|
|
74
|
+
let warnedOnMissingSkills = false;
|
|
75
|
+
export function __setSkillsManifest(manifest) {
|
|
76
|
+
pendingSkillsManifest = manifest;
|
|
77
|
+
discoveredSkills = null;
|
|
78
|
+
}
|
|
79
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
80
|
+
// exists — the capability must be present for the `initialize` response.
|
|
81
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
82
|
+
if (!skybridgeOptions?.skills) {
|
|
83
|
+
return options;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
...options,
|
|
87
|
+
capabilities: {
|
|
88
|
+
...options?.capabilities,
|
|
89
|
+
extensions: {
|
|
90
|
+
...options?.capabilities?.extensions,
|
|
91
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Typed registration sugar over the MCP SDK's `McpServer`: a tool registry
|
|
98
|
+
* that carries input/output/meta shapes, view resources, per-tool security
|
|
99
|
+
* schemes, and prompt/resource registration. A {@link Skybridge} app builds
|
|
100
|
+
* one of these per request and hands it to your `handler`; chain
|
|
101
|
+
* {@link McpServer.registerTool} calls on it and return the result.
|
|
102
|
+
*
|
|
103
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
104
|
+
* shape, so `typeof app` carries enough information for view-side helpers
|
|
105
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
106
|
+
*
|
|
107
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
108
|
+
* chaining; you almost never set this manually.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* export const app = new Skybridge({
|
|
113
|
+
* name: "my-app",
|
|
114
|
+
* version: "1.0.0",
|
|
115
|
+
* handler: (server) =>
|
|
116
|
+
* server.registerTool({
|
|
117
|
+
* name: "search",
|
|
118
|
+
* inputSchema: { query: z.string() },
|
|
119
|
+
* view: { component: "search" },
|
|
120
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` })),
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
125
|
+
*/
|
|
95
126
|
export class McpServer extends McpServerBaseOmitted {
|
|
96
|
-
/**
|
|
97
|
-
* The underlying Express app. Use this to extend the HTTP server with
|
|
98
|
-
* custom routes, middleware, or settings — e.g.
|
|
99
|
-
* `server.express.get("/health", ...)`.
|
|
100
|
-
*
|
|
101
|
-
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
102
|
-
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
103
|
-
* Register your handlers before `run()`;
|
|
104
|
-
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
105
|
-
* error handler are appended in that order.
|
|
106
|
-
*
|
|
107
|
-
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
108
|
-
* locally and on self-hosted deployments.
|
|
109
|
-
*/
|
|
110
|
-
express;
|
|
111
|
-
customErrorMiddleware = [];
|
|
112
|
-
mcpMiddlewareEntries = [];
|
|
113
|
-
mcpMiddlewareApplied = false;
|
|
114
127
|
claimedViews = new Map();
|
|
115
128
|
viewMetaBuilders = new Map();
|
|
116
129
|
/**
|
|
@@ -121,64 +134,64 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
121
134
|
*/
|
|
122
135
|
viewUriByPath = new Map();
|
|
123
136
|
viteManifest = null;
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
oauthEnabled = false;
|
|
138
|
+
resolveResourceMetadataUrl;
|
|
139
|
+
toolSecuritySchemes = new Map();
|
|
140
|
+
userMiddlewareEntries = [];
|
|
126
141
|
constructor(serverInfo, options, skybridgeOptions) {
|
|
127
|
-
super(serverInfo, options);
|
|
128
|
-
this.
|
|
129
|
-
this.serverOptions = options;
|
|
130
|
-
this.express = express();
|
|
131
|
-
this.express.use(express.json(skybridgeOptions?.json));
|
|
132
|
-
if (skybridgeOptions?.oauth) {
|
|
133
|
-
setupOAuth(this.express, skybridgeOptions.oauth);
|
|
134
|
-
}
|
|
142
|
+
super(serverInfo, withSkillsCapability(options, skybridgeOptions));
|
|
143
|
+
this.oauthEnabled = Boolean(skybridgeOptions?.oauth);
|
|
135
144
|
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
136
|
-
// user code.
|
|
137
|
-
//
|
|
138
|
-
// Explicit `setViteManifest` calls still win because they happen after
|
|
139
|
-
// construction.
|
|
145
|
+
// user code. Explicit `setViteManifest` calls still win because they
|
|
146
|
+
// happen after construction.
|
|
140
147
|
if (pendingBuildManifest) {
|
|
141
148
|
this.setViteManifest(pendingBuildManifest);
|
|
142
|
-
pendingBuildManifest = null;
|
|
143
149
|
}
|
|
150
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
144
151
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The per-tool security schemes collected during registration, keyed by tool
|
|
154
|
+
* name. Read by the OAuth layer to decide whether anonymous requests are
|
|
155
|
+
* allowed and which schemes gate a given `tools/call`.
|
|
156
|
+
*
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
get securitySchemesByTool() {
|
|
160
|
+
return this.toolSecuritySchemes;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Inject the resolver the app uses to build the protected-resource metadata
|
|
164
|
+
* URL, so tool handlers can emit in-band auth challenges.
|
|
165
|
+
*
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
setResourceMetadataUrlResolver(resolve) {
|
|
169
|
+
this.resolveResourceMetadataUrl = resolve;
|
|
154
170
|
return this;
|
|
155
171
|
}
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
|
|
172
|
+
setupSkills(enabled) {
|
|
173
|
+
if (!enabled) {
|
|
174
|
+
return;
|
|
159
175
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
176
|
+
discoveredSkills ??= pendingSkillsManifest ?? discoverSkills(SKILLS_DIR);
|
|
177
|
+
if (discoveredSkills.length === 0 && !warnedOnMissingSkills) {
|
|
178
|
+
warnedOnMissingSkills = true;
|
|
179
|
+
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.`);
|
|
164
180
|
}
|
|
165
|
-
|
|
181
|
+
registerSkills(this, discoveredSkills);
|
|
166
182
|
}
|
|
167
183
|
mcpMiddleware(filterOrHandler,
|
|
168
184
|
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
169
185
|
maybeHandler) {
|
|
170
|
-
if (this.mcpMiddlewareApplied) {
|
|
171
|
-
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
172
|
-
}
|
|
173
186
|
const handler = maybeHandler;
|
|
174
187
|
if (typeof filterOrHandler === "function") {
|
|
175
|
-
this.
|
|
188
|
+
this.userMiddlewareEntries.push({
|
|
176
189
|
filter: null,
|
|
177
190
|
handler: filterOrHandler,
|
|
178
191
|
});
|
|
179
192
|
}
|
|
180
193
|
else if (handler) {
|
|
181
|
-
this.
|
|
194
|
+
this.userMiddlewareEntries.push({
|
|
182
195
|
filter: filterOrHandler,
|
|
183
196
|
handler,
|
|
184
197
|
});
|
|
@@ -188,11 +201,15 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
188
201
|
}
|
|
189
202
|
return this;
|
|
190
203
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
/**
|
|
205
|
+
* This instance's protocol-level middleware: the framework's own entries
|
|
206
|
+
* (view `_meta` on `resources/list`, version-agnostic view resolution on
|
|
207
|
+
* `resources/read`, the top-level `securitySchemes` mirror on `tools/list`)
|
|
208
|
+
* followed by the ones registered via {@link McpServer.mcpMiddleware}.
|
|
209
|
+
*
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
protocolMiddlewareEntries() {
|
|
196
213
|
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
197
214
|
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
198
215
|
const viewListMetaEntry = {
|
|
@@ -249,123 +266,31 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
249
266
|
}
|
|
250
267
|
},
|
|
251
268
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
269
|
+
// ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
|
|
270
|
+
// still Draft), but the SDK's registerTool strips unknown top-level fields, so
|
|
271
|
+
// it's stashed in `_meta` at registration. This restores it to the top level
|
|
272
|
+
// on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
|
|
273
|
+
// { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
|
|
274
|
+
// -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
|
|
275
|
+
const toolsListSecuritySchemesEntry = {
|
|
276
|
+
filter: "tools/list",
|
|
277
|
+
handler: async (_req, _extra, next) => {
|
|
278
|
+
const result = (await next());
|
|
279
|
+
for (const tool of result.tools) {
|
|
280
|
+
const schemes = tool._meta?.securitySchemes;
|
|
281
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
282
|
+
tool.securitySchemes = schemes;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
return [
|
|
255
289
|
viewListMetaEntry,
|
|
256
290
|
viewReadResolveEntry,
|
|
257
|
-
|
|
291
|
+
toolsListSecuritySchemesEntry,
|
|
292
|
+
...this.userMiddlewareEntries,
|
|
258
293
|
];
|
|
259
|
-
if (entries.length === 0) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
263
|
-
const instrumentMap = (map, isNotification) => {
|
|
264
|
-
for (const [method, handler] of map) {
|
|
265
|
-
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
266
|
-
}
|
|
267
|
-
const originalSet = map.set.bind(map);
|
|
268
|
-
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
269
|
-
};
|
|
270
|
-
instrumentMap(requestHandlers, false);
|
|
271
|
-
instrumentMap(notificationHandlers, true);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
275
|
-
* when you're embedding Skybridge in a host that already manages its own
|
|
276
|
-
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
277
|
-
* which sets the transport up for you. Locks in any middleware registered
|
|
278
|
-
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
279
|
-
* throw afterwards.
|
|
280
|
-
*/
|
|
281
|
-
async connect(transport) {
|
|
282
|
-
this.applyMcpMiddleware();
|
|
283
|
-
return McpServerBase.prototype.connect.call(this, transport);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
287
|
-
* transport per instance, so we can't reuse this `McpServer` across
|
|
288
|
-
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
289
|
-
* factory, but that would break Skybridge's singleton API — so instead
|
|
290
|
-
* we build a fresh underlying `Server` per request and share the main
|
|
291
|
-
* server's handler maps by reference. The cast is unavoidable: there's
|
|
292
|
-
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
293
|
-
* read side and fails fast on SDK field renames.
|
|
294
|
-
*/
|
|
295
|
-
async connectStatelessTransport(transport) {
|
|
296
|
-
this.applyMcpMiddleware();
|
|
297
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
298
|
-
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
299
|
-
const target = fresh;
|
|
300
|
-
target._requestHandlers = requestHandlers;
|
|
301
|
-
target._notificationHandlers = notificationHandlers;
|
|
302
|
-
await fresh.connect(transport);
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
306
|
-
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
307
|
-
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
308
|
-
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
309
|
-
*
|
|
310
|
-
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
311
|
-
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
312
|
-
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
313
|
-
* serverless function entry can call it as a `(req, res)` handler. On
|
|
314
|
-
* Node, returns `undefined` once listening.
|
|
315
|
-
*/
|
|
316
|
-
async run() {
|
|
317
|
-
this.applyMcpMiddleware();
|
|
318
|
-
if (process.env.VERCEL === "1") {
|
|
319
|
-
// createApp only reads httpServer inside its dev-only branch
|
|
320
|
-
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
321
|
-
// bare object passed to satisfy the required parameter.
|
|
322
|
-
const httpServer = http.createServer();
|
|
323
|
-
await createApp({
|
|
324
|
-
mcpServer: this,
|
|
325
|
-
httpServer,
|
|
326
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
327
|
-
});
|
|
328
|
-
return this.express;
|
|
329
|
-
}
|
|
330
|
-
const httpServer = http.createServer();
|
|
331
|
-
await createApp({
|
|
332
|
-
mcpServer: this,
|
|
333
|
-
httpServer,
|
|
334
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
335
|
-
});
|
|
336
|
-
httpServer.on("request", this.express);
|
|
337
|
-
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
338
|
-
await new Promise((resolve, reject) => {
|
|
339
|
-
httpServer.on("error", (error) => {
|
|
340
|
-
console.error("Failed to start server:", error);
|
|
341
|
-
reject(error);
|
|
342
|
-
});
|
|
343
|
-
httpServer.listen(port, () => {
|
|
344
|
-
resolve();
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
348
|
-
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
349
|
-
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
350
|
-
if (typeof navigator !== "undefined" &&
|
|
351
|
-
navigator.userAgent === "Cloudflare-Workers") {
|
|
352
|
-
const cloudflareNode = "cloudflare:node";
|
|
353
|
-
const { httpServerHandler } = await import(cloudflareNode);
|
|
354
|
-
return httpServerHandler({ port });
|
|
355
|
-
}
|
|
356
|
-
const shutdown = () => {
|
|
357
|
-
// Drop both handlers so a second signal falls through to Node's default
|
|
358
|
-
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
359
|
-
process.off("SIGTERM", shutdown);
|
|
360
|
-
process.off("SIGINT", shutdown);
|
|
361
|
-
httpServer.close(() => process.exit(0));
|
|
362
|
-
// Force exit if connections don't drain in time so the port is still
|
|
363
|
-
// released promptly (e.g. for nodemon restarts).
|
|
364
|
-
setTimeout(() => process.exit(0), 3000).unref();
|
|
365
|
-
};
|
|
366
|
-
process.on("SIGTERM", shutdown);
|
|
367
|
-
process.on("SIGINT", shutdown);
|
|
368
|
-
return undefined;
|
|
369
294
|
}
|
|
370
295
|
enforceOneToolPerView(component, toolName) {
|
|
371
296
|
const existingTool = this.claimedViews.get(component);
|
|
@@ -374,15 +299,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
374
299
|
}
|
|
375
300
|
this.claimedViews.set(component, toolName);
|
|
376
301
|
}
|
|
377
|
-
resolveViewRequestContext(
|
|
302
|
+
resolveViewRequestContext(ctx) {
|
|
378
303
|
const isProduction = process.env.NODE_ENV === "production";
|
|
379
|
-
const
|
|
380
|
-
const
|
|
381
|
-
const val = headers[key];
|
|
382
|
-
return Array.isArray(val) ? val[0] : val;
|
|
383
|
-
};
|
|
384
|
-
const isClaude = header("user-agent") === "Claude-User";
|
|
304
|
+
const header = (key) => ctx?.http?.req?.headers.get(key) ?? undefined;
|
|
305
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
385
306
|
const serverUrl = resolveServerOrigin(header);
|
|
307
|
+
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
308
|
+
// per-request so one process can serve many hosts/prefixes at once: the
|
|
309
|
+
// origin is recovered from x-forwarded-host, the prefix from
|
|
310
|
+
// x-forwarded-prefix. Empty when served at the origin root.
|
|
311
|
+
const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
|
|
386
312
|
const connectDomains = [serverUrl];
|
|
387
313
|
if (!isProduction) {
|
|
388
314
|
const wsUrl = new URL(serverUrl);
|
|
@@ -391,7 +317,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
391
317
|
}
|
|
392
318
|
let contentMetaOverrides = {};
|
|
393
319
|
if (isClaude) {
|
|
394
|
-
const pathname =
|
|
320
|
+
const pathname = ctx?.http?.req ? new URL(ctx.http.req.url).pathname : "";
|
|
395
321
|
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
396
322
|
// Strip a lone trailing slash so the hash matches the connector URL
|
|
397
323
|
// as registered with Claude (which has no trailing slash on bare origins).
|
|
@@ -403,7 +329,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
403
329
|
.slice(0, 32);
|
|
404
330
|
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
405
331
|
}
|
|
406
|
-
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
332
|
+
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
407
333
|
}
|
|
408
334
|
registerViewResources(toolName, view, toolMeta) {
|
|
409
335
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
@@ -411,46 +337,26 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
411
337
|
// `tools/list` calls when the bundle hasn't changed.
|
|
412
338
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
413
339
|
const viewResource = {
|
|
414
|
-
hostType: "mcp-app",
|
|
415
340
|
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
416
341
|
mimeType: "text/html;profile=mcp-app",
|
|
417
342
|
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
418
|
-
const
|
|
419
|
-
ui: {
|
|
420
|
-
csp: {
|
|
421
|
-
resourceDomains,
|
|
422
|
-
connectDomains,
|
|
423
|
-
baseUriDomains,
|
|
424
|
-
},
|
|
425
|
-
domain,
|
|
426
|
-
},
|
|
427
|
-
};
|
|
428
|
-
const fromView = {
|
|
343
|
+
const ui = {
|
|
429
344
|
ui: {
|
|
430
345
|
...(view.description && { description: view.description }),
|
|
431
346
|
...(view.prefersBorder !== undefined && {
|
|
432
347
|
prefersBorder: view.prefersBorder,
|
|
433
348
|
}),
|
|
434
|
-
|
|
349
|
+
domain: overrides.domain ?? view.domain ?? domain,
|
|
435
350
|
csp: {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
...(view.csp?.connectDomains && {
|
|
440
|
-
connectDomains: view.csp.connectDomains,
|
|
441
|
-
}),
|
|
351
|
+
resourceDomains: unionOf(resourceDomains, view.csp?.resourceDomains),
|
|
352
|
+
connectDomains: unionOf(connectDomains, view.csp?.connectDomains),
|
|
353
|
+
baseUriDomains: unionOf(baseUriDomains, view.csp?.baseUriDomains),
|
|
442
354
|
...(view.csp?.frameDomains && {
|
|
443
355
|
frameDomains: view.csp.frameDomains,
|
|
444
356
|
}),
|
|
445
|
-
...(view.csp?.baseUriDomains && {
|
|
446
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
447
|
-
}),
|
|
448
357
|
},
|
|
449
358
|
},
|
|
450
359
|
};
|
|
451
|
-
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
452
|
-
ui: overrides,
|
|
453
|
-
});
|
|
454
360
|
const base = {
|
|
455
361
|
...ui,
|
|
456
362
|
...(view.description && {
|
|
@@ -476,7 +382,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
476
382
|
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
477
383
|
}
|
|
478
384
|
registerViewResource({ name, viewResource, view, }) {
|
|
479
|
-
const {
|
|
385
|
+
const { uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
480
386
|
const buildMeta = (extra) => {
|
|
481
387
|
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
482
388
|
return buildContentMeta({
|
|
@@ -491,17 +397,19 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
491
397
|
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
492
398
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
493
399
|
const isProduction = process.env.NODE_ENV === "production";
|
|
494
|
-
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
400
|
+
const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
|
|
401
|
+
// The view resolves all assets (template imports + runtime lazy chunks
|
|
402
|
+
// via `window.skybridge.serverUrl`) against this base, so it carries the
|
|
403
|
+
// proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
|
|
404
|
+
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
495
405
|
const html = isProduction
|
|
496
406
|
? templateHelper.renderProduction({
|
|
497
|
-
|
|
498
|
-
serverUrl,
|
|
407
|
+
serverUrl: viewBase,
|
|
499
408
|
viewFile: this.lookupViewFile(view.component),
|
|
500
409
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
501
410
|
})
|
|
502
411
|
: templateHelper.renderDevelopment({
|
|
503
|
-
|
|
504
|
-
serverUrl,
|
|
412
|
+
serverUrl: viewBase,
|
|
505
413
|
viewName: view.component,
|
|
506
414
|
});
|
|
507
415
|
return {
|
|
@@ -513,10 +421,27 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
513
421
|
}
|
|
514
422
|
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
515
423
|
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
424
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
425
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
516
426
|
}
|
|
517
|
-
|
|
427
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
518
428
|
return async (args, extra) => {
|
|
519
|
-
|
|
429
|
+
if (this.oauthEnabled) {
|
|
430
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.http?.authInfo);
|
|
431
|
+
if (failure) {
|
|
432
|
+
const header = (key) => extra.http?.req?.headers.get(key) ?? undefined;
|
|
433
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
let result;
|
|
437
|
+
try {
|
|
438
|
+
result = await cb(args, extra);
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
captureToolError(extra, error);
|
|
442
|
+
throw error;
|
|
443
|
+
}
|
|
444
|
+
warnOnLargeToolOutput(result, toolName);
|
|
520
445
|
return {
|
|
521
446
|
...result,
|
|
522
447
|
content: normalizeContent(result.content),
|
|
@@ -576,32 +501,45 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
576
501
|
if (this.viteManifest) {
|
|
577
502
|
return this.viteManifest;
|
|
578
503
|
}
|
|
579
|
-
|
|
504
|
+
cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
505
|
+
return cachedDiskManifest ?? {};
|
|
580
506
|
}
|
|
581
|
-
registerTool(
|
|
507
|
+
registerTool(rawConfig, rawCb) {
|
|
582
508
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
509
|
+
const config = rawConfig;
|
|
510
|
+
const cb = rawCb;
|
|
511
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
512
|
+
const authNeedsProvider = auth !== undefined &&
|
|
513
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
514
|
+
if (rawSecuritySchemes === undefined &&
|
|
515
|
+
authNeedsProvider &&
|
|
516
|
+
!this.oauthEnabled) {
|
|
517
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
586
518
|
}
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
519
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
520
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
590
521
|
const toolMeta = { ...userToolMeta };
|
|
522
|
+
this.toolSecuritySchemes.set(name, securitySchemes);
|
|
591
523
|
if (securitySchemes) {
|
|
592
524
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
593
525
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
594
526
|
// fields, so the canonical spot isn't reachable without intercepting
|
|
595
527
|
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
596
|
-
//
|
|
528
|
+
// ChatGPT plugin reference until SEP-1488 lands in the spec.
|
|
597
529
|
toolMeta.securitySchemes = securitySchemes;
|
|
598
530
|
}
|
|
599
531
|
if (view) {
|
|
600
532
|
this.enforceOneToolPerView(view.component, name);
|
|
601
533
|
this.registerViewResources(name, view, toolMeta);
|
|
602
534
|
}
|
|
603
|
-
const wrappedCb = this.
|
|
604
|
-
|
|
535
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
536
|
+
attachViewUUID: Boolean(view),
|
|
537
|
+
securitySchemes,
|
|
538
|
+
toolName: name,
|
|
539
|
+
});
|
|
540
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, toolFields.inputSchema === undefined
|
|
541
|
+
? (extra) => wrappedCb({}, extra)
|
|
542
|
+
: wrappedCb);
|
|
605
543
|
return this;
|
|
606
544
|
}
|
|
607
545
|
}
|