skybridge 0.0.0-dev.8e84184 → 0.0.0-dev.8ead776
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 +17 -14
- package/dist/cli/build-helpers.d.ts +3 -2
- package/dist/cli/build-helpers.js +24 -10
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +48 -5
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.js +10 -5
- package/dist/cli/build-steps.js.map +1 -1
- package/dist/cli/build-steps.test.js +3 -3
- package/dist/cli/build-steps.test.js.map +1 -1
- 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/telemetry.js +2 -0
- package/dist/cli/telemetry.js.map +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/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 +24 -6
- 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 +28 -5
- package/dist/server/auth/providers/workos.js +6 -2
- 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.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 +42 -6
- package/dist/server/auth/verify.js +27 -3
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth/verify.test.js +65 -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 +133 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/server.d.ts +283 -128
- package/dist/server/server.js +295 -274
- 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-resource-resolution.test.js +18 -13
- 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.d.ts +13 -3
- package/dist/web/bridges/adaptor.js +182 -16
- package/dist/web/bridges/adaptor.js.map +1 -1
- package/dist/web/bridges/adaptor.test.js +78 -11
- 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.d.ts +1 -1
- package/dist/web/bridges/mcp-app/bridge.js +15 -6
- 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 +19 -2
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
- 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 +77 -16
- 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.js +3 -2
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +17 -2
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +23 -19
- package/dist/web/generate-helpers.js +21 -17
- 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 +6 -1
- package/dist/web/hooks/index.js +6 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
- package/dist/web/hooks/openai-extensions.test.js +107 -0
- package/dist/web/hooks/openai-extensions.test.js.map +1 -0
- 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.d.ts +2 -2
- package/dist/web/hooks/use-call-tool.js +15 -10
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +15 -4
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-deep-link.d.ts +22 -0
- package/dist/web/hooks/use-deep-link.js +34 -0
- package/dist/web/hooks/use-deep-link.js.map +1 -0
- 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-file-resource.d.ts +37 -0
- package/dist/web/hooks/use-file-resource.js +101 -0
- package/dist/web/hooks/use-file-resource.js.map +1 -0
- package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
- package/dist/web/hooks/use-file-resource.test.js +65 -0
- package/dist/web/hooks/use-file-resource.test.js.map +1 -0
- 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 +44 -0
- package/dist/web/hooks/use-host.js +45 -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-model-context.d.ts +44 -0
- package/dist/web/hooks/use-model-context.js +63 -0
- package/dist/web/hooks/use-model-context.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-open-file.d.ts +20 -0
- package/dist/web/hooks/use-open-file.js +25 -0
- package/dist/web/hooks/use-open-file.js.map +1 -0
- 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-send-follow-up-message.d.ts +8 -2
- package/dist/web/hooks/use-send-follow-up-message.js +6 -0
- package/dist/web/hooks/use-send-follow-up-message.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 +32 -29
- 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 → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.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,32 @@
|
|
|
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 {
|
|
11
|
-
import { createMiddlewareEntry } from "./metric.js";
|
|
12
|
-
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
4
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/server";
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
|
+
import { warnOnLargeToolOutput } from "../context-warnings.js";
|
|
7
|
+
import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
8
|
+
import { hostFromUserAgent } from "./host.js";
|
|
9
|
+
import { captureToolError } from "./middleware.js";
|
|
13
10
|
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
11
|
+
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
14
12
|
import { templateHelper } from "./templateHelper.js";
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
13
|
+
const unionOf = (base, extra) => extra ? [...new Set([...base, ...extra])] : base;
|
|
14
|
+
function mergeOpenAIUi(meta, values) {
|
|
15
|
+
const defined = Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
|
|
16
|
+
if (Object.keys(defined).length > 0) {
|
|
17
|
+
meta["openai/ui"] = { ...meta["openai/ui"], ...defined };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function acceptsEmptyInput(inputSchema) {
|
|
21
|
+
if (inputSchema === undefined) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const checks = "~standard" in inputSchema
|
|
25
|
+
? [inputSchema["~standard"].validate({})]
|
|
26
|
+
: Object.values(inputSchema).map((schema) => schema["~standard"].validate(undefined));
|
|
27
|
+
return checks.every((result) => result instanceof Promise || result.issues === undefined);
|
|
28
|
+
}
|
|
29
|
+
const SKILLS_DIR = "src/skills";
|
|
22
30
|
/**
|
|
23
31
|
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
24
32
|
* path. Takes the first hop of a comma-separated proxy chain.
|
|
@@ -32,6 +40,9 @@ function normalizeForwardedPrefix(raw) {
|
|
|
32
40
|
}
|
|
33
41
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
34
42
|
}
|
|
43
|
+
const fileEntrypointInput = {
|
|
44
|
+
file: z.object({ name: z.string(), resourceUri: z.string() }),
|
|
45
|
+
};
|
|
35
46
|
/**
|
|
36
47
|
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
37
48
|
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
@@ -60,35 +71,6 @@ export function normalizeContent(content) {
|
|
|
60
71
|
return [content];
|
|
61
72
|
}
|
|
62
73
|
const McpServerBaseOmitted = McpServerBase;
|
|
63
|
-
/**
|
|
64
|
-
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
65
|
-
* registry, view resources, an embedded Express app, and protocol-level
|
|
66
|
-
* middleware. Construct it with the same `Implementation` info you would pass
|
|
67
|
-
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
68
|
-
* then call {@link McpServer.run} to start the HTTP server.
|
|
69
|
-
*
|
|
70
|
-
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
71
|
-
* shape, so `typeof server` carries enough information for view-side helpers
|
|
72
|
-
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
73
|
-
*
|
|
74
|
-
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
75
|
-
* chaining; you almost never set this manually.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
80
|
-
* .registerTool({
|
|
81
|
-
* name: "search",
|
|
82
|
-
* inputSchema: { query: z.string() },
|
|
83
|
-
* view: { component: "search" },
|
|
84
|
-
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
85
|
-
*
|
|
86
|
-
* await server.run();
|
|
87
|
-
* export type AppType = typeof server;
|
|
88
|
-
* ```
|
|
89
|
-
*
|
|
90
|
-
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
91
|
-
*/
|
|
92
74
|
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
93
75
|
// Set at module scope rather than passed through the constructor because the
|
|
94
76
|
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
@@ -105,25 +87,62 @@ let pendingBuildManifest = null;
|
|
|
105
87
|
export function __setBuildManifest(manifest) {
|
|
106
88
|
pendingBuildManifest = manifest;
|
|
107
89
|
}
|
|
90
|
+
let pendingSkillsManifest = null;
|
|
91
|
+
let cachedDiskManifest = null;
|
|
92
|
+
let discoveredSkills = null;
|
|
93
|
+
let warnedOnMissingSkills = false;
|
|
94
|
+
export function __setSkillsManifest(manifest) {
|
|
95
|
+
pendingSkillsManifest = manifest;
|
|
96
|
+
discoveredSkills = null;
|
|
97
|
+
}
|
|
98
|
+
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
99
|
+
// exists — the capability must be present for the `initialize` response.
|
|
100
|
+
function withSkillsCapability(options, skybridgeOptions) {
|
|
101
|
+
if (!skybridgeOptions?.skills) {
|
|
102
|
+
return options;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
...options,
|
|
106
|
+
capabilities: {
|
|
107
|
+
...options?.capabilities,
|
|
108
|
+
extensions: {
|
|
109
|
+
...options?.capabilities?.extensions,
|
|
110
|
+
[SKILLS_EXTENSION_KEY]: { directoryRead: true },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Typed registration sugar over the MCP SDK's `McpServer`: a tool registry
|
|
117
|
+
* that carries input/output/meta shapes, view resources, per-tool security
|
|
118
|
+
* schemes, and prompt/resource registration. A {@link Skybridge} app builds
|
|
119
|
+
* one of these per request and hands it to your `handler`; chain
|
|
120
|
+
* {@link McpServer.registerTool} calls on it and return the result.
|
|
121
|
+
*
|
|
122
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
123
|
+
* shape, so `typeof app` carries enough information for view-side helpers
|
|
124
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
127
|
+
* chaining; you almost never set this manually.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* export const app = new Skybridge({
|
|
132
|
+
* name: "my-app",
|
|
133
|
+
* version: "1.0.0",
|
|
134
|
+
* handler: (server) =>
|
|
135
|
+
* server.registerTool({
|
|
136
|
+
* name: "search",
|
|
137
|
+
* inputSchema: { query: z.string() },
|
|
138
|
+
* view: { component: "search" },
|
|
139
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` })),
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
144
|
+
*/
|
|
108
145
|
export class McpServer extends McpServerBaseOmitted {
|
|
109
|
-
/**
|
|
110
|
-
* The underlying Express app. Use this to extend the HTTP server with
|
|
111
|
-
* custom routes, middleware, or settings — e.g.
|
|
112
|
-
* `server.express.get("/health", ...)`.
|
|
113
|
-
*
|
|
114
|
-
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
115
|
-
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
116
|
-
* Register your handlers before `run()`;
|
|
117
|
-
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
118
|
-
* error handler are appended in that order.
|
|
119
|
-
*
|
|
120
|
-
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
121
|
-
* locally and on self-hosted deployments.
|
|
122
|
-
*/
|
|
123
|
-
express;
|
|
124
|
-
customErrorMiddleware = [];
|
|
125
|
-
mcpMiddlewareEntries = [];
|
|
126
|
-
mcpMiddlewareApplied = false;
|
|
127
146
|
claimedViews = new Map();
|
|
128
147
|
viewMetaBuilders = new Map();
|
|
129
148
|
/**
|
|
@@ -134,64 +153,64 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
134
153
|
*/
|
|
135
154
|
viewUriByPath = new Map();
|
|
136
155
|
viteManifest = null;
|
|
137
|
-
|
|
138
|
-
|
|
156
|
+
oauthEnabled = false;
|
|
157
|
+
resolveResourceMetadataUrl;
|
|
158
|
+
toolSecuritySchemes = new Map();
|
|
159
|
+
userMiddlewareEntries = [];
|
|
139
160
|
constructor(serverInfo, options, skybridgeOptions) {
|
|
140
|
-
super(serverInfo, options);
|
|
141
|
-
this.
|
|
142
|
-
this.serverOptions = options;
|
|
143
|
-
this.express = express();
|
|
144
|
-
this.express.use(express.json(skybridgeOptions?.json));
|
|
145
|
-
if (skybridgeOptions?.oauth) {
|
|
146
|
-
setupOAuth(this.express, skybridgeOptions.oauth);
|
|
147
|
-
}
|
|
161
|
+
super(serverInfo, withSkillsCapability(options, skybridgeOptions));
|
|
162
|
+
this.oauthEnabled = Boolean(skybridgeOptions?.oauth);
|
|
148
163
|
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
149
|
-
// user code.
|
|
150
|
-
//
|
|
151
|
-
// Explicit `setViteManifest` calls still win because they happen after
|
|
152
|
-
// construction.
|
|
164
|
+
// user code. Explicit `setViteManifest` calls still win because they
|
|
165
|
+
// happen after construction.
|
|
153
166
|
if (pendingBuildManifest) {
|
|
154
167
|
this.setViteManifest(pendingBuildManifest);
|
|
155
|
-
pendingBuildManifest = null;
|
|
156
168
|
}
|
|
169
|
+
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
157
170
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
/**
|
|
172
|
+
* The per-tool security schemes collected during registration, keyed by tool
|
|
173
|
+
* name. Read by the OAuth layer to decide whether anonymous requests are
|
|
174
|
+
* allowed and which schemes gate a given `tools/call`.
|
|
175
|
+
*
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
get securitySchemesByTool() {
|
|
179
|
+
return this.toolSecuritySchemes;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Inject the resolver the app uses to build the protected-resource metadata
|
|
183
|
+
* URL, so tool handlers can emit in-band auth challenges.
|
|
184
|
+
*
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
setResourceMetadataUrlResolver(resolve) {
|
|
188
|
+
this.resolveResourceMetadataUrl = resolve;
|
|
167
189
|
return this;
|
|
168
190
|
}
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
|
|
191
|
+
setupSkills(enabled) {
|
|
192
|
+
if (!enabled) {
|
|
193
|
+
return;
|
|
172
194
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
195
|
+
discoveredSkills ??= pendingSkillsManifest ?? discoverSkills(SKILLS_DIR);
|
|
196
|
+
if (discoveredSkills.length === 0 && !warnedOnMissingSkills) {
|
|
197
|
+
warnedOnMissingSkills = true;
|
|
198
|
+
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.`);
|
|
177
199
|
}
|
|
178
|
-
|
|
200
|
+
registerSkills(this, discoveredSkills);
|
|
179
201
|
}
|
|
180
202
|
mcpMiddleware(filterOrHandler,
|
|
181
203
|
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
182
204
|
maybeHandler) {
|
|
183
|
-
if (this.mcpMiddlewareApplied) {
|
|
184
|
-
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
185
|
-
}
|
|
186
205
|
const handler = maybeHandler;
|
|
187
206
|
if (typeof filterOrHandler === "function") {
|
|
188
|
-
this.
|
|
207
|
+
this.userMiddlewareEntries.push({
|
|
189
208
|
filter: null,
|
|
190
209
|
handler: filterOrHandler,
|
|
191
210
|
});
|
|
192
211
|
}
|
|
193
212
|
else if (handler) {
|
|
194
|
-
this.
|
|
213
|
+
this.userMiddlewareEntries.push({
|
|
195
214
|
filter: filterOrHandler,
|
|
196
215
|
handler,
|
|
197
216
|
});
|
|
@@ -201,11 +220,15 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
201
220
|
}
|
|
202
221
|
return this;
|
|
203
222
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
223
|
+
/**
|
|
224
|
+
* This instance's protocol-level middleware: the framework's own entries
|
|
225
|
+
* (view `_meta` on `resources/list`, version-agnostic view resolution on
|
|
226
|
+
* `resources/read`, the top-level `securitySchemes` mirror on `tools/list`)
|
|
227
|
+
* followed by the ones registered via {@link McpServer.mcpMiddleware}.
|
|
228
|
+
*
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
protocolMiddlewareEntries() {
|
|
209
232
|
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
210
233
|
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
211
234
|
const viewListMetaEntry = {
|
|
@@ -262,123 +285,31 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
262
285
|
}
|
|
263
286
|
},
|
|
264
287
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
288
|
+
// ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
|
|
289
|
+
// still Draft), but the SDK's registerTool strips unknown top-level fields, so
|
|
290
|
+
// it's stashed in `_meta` at registration. This restores it to the top level
|
|
291
|
+
// on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
|
|
292
|
+
// { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
|
|
293
|
+
// -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
|
|
294
|
+
const toolsListSecuritySchemesEntry = {
|
|
295
|
+
filter: "tools/list",
|
|
296
|
+
handler: async (_req, _extra, next) => {
|
|
297
|
+
const result = (await next());
|
|
298
|
+
for (const tool of result.tools) {
|
|
299
|
+
const schemes = tool._meta?.securitySchemes;
|
|
300
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
301
|
+
tool.securitySchemes = schemes;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
return [
|
|
268
308
|
viewListMetaEntry,
|
|
269
309
|
viewReadResolveEntry,
|
|
270
|
-
|
|
310
|
+
toolsListSecuritySchemesEntry,
|
|
311
|
+
...this.userMiddlewareEntries,
|
|
271
312
|
];
|
|
272
|
-
if (entries.length === 0) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
276
|
-
const instrumentMap = (map, isNotification) => {
|
|
277
|
-
for (const [method, handler] of map) {
|
|
278
|
-
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
279
|
-
}
|
|
280
|
-
const originalSet = map.set.bind(map);
|
|
281
|
-
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
282
|
-
};
|
|
283
|
-
instrumentMap(requestHandlers, false);
|
|
284
|
-
instrumentMap(notificationHandlers, true);
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
288
|
-
* when you're embedding Skybridge in a host that already manages its own
|
|
289
|
-
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
290
|
-
* which sets the transport up for you. Locks in any middleware registered
|
|
291
|
-
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
292
|
-
* throw afterwards.
|
|
293
|
-
*/
|
|
294
|
-
async connect(transport) {
|
|
295
|
-
this.applyMcpMiddleware();
|
|
296
|
-
return McpServerBase.prototype.connect.call(this, transport);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
300
|
-
* transport per instance, so we can't reuse this `McpServer` across
|
|
301
|
-
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
302
|
-
* factory, but that would break Skybridge's singleton API — so instead
|
|
303
|
-
* we build a fresh underlying `Server` per request and share the main
|
|
304
|
-
* server's handler maps by reference. The cast is unavoidable: there's
|
|
305
|
-
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
306
|
-
* read side and fails fast on SDK field renames.
|
|
307
|
-
*/
|
|
308
|
-
async connectStatelessTransport(transport) {
|
|
309
|
-
this.applyMcpMiddleware();
|
|
310
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
311
|
-
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
312
|
-
const target = fresh;
|
|
313
|
-
target._requestHandlers = requestHandlers;
|
|
314
|
-
target._notificationHandlers = notificationHandlers;
|
|
315
|
-
await fresh.connect(transport);
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
319
|
-
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
320
|
-
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
321
|
-
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
322
|
-
*
|
|
323
|
-
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
324
|
-
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
325
|
-
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
326
|
-
* serverless function entry can call it as a `(req, res)` handler. On
|
|
327
|
-
* Node, returns `undefined` once listening.
|
|
328
|
-
*/
|
|
329
|
-
async run() {
|
|
330
|
-
this.applyMcpMiddleware();
|
|
331
|
-
if (process.env.VERCEL === "1") {
|
|
332
|
-
// createApp only reads httpServer inside its dev-only branch
|
|
333
|
-
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
334
|
-
// bare object passed to satisfy the required parameter.
|
|
335
|
-
const httpServer = http.createServer();
|
|
336
|
-
await createApp({
|
|
337
|
-
mcpServer: this,
|
|
338
|
-
httpServer,
|
|
339
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
340
|
-
});
|
|
341
|
-
return this.express;
|
|
342
|
-
}
|
|
343
|
-
const httpServer = http.createServer();
|
|
344
|
-
await createApp({
|
|
345
|
-
mcpServer: this,
|
|
346
|
-
httpServer,
|
|
347
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
348
|
-
});
|
|
349
|
-
httpServer.on("request", this.express);
|
|
350
|
-
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
351
|
-
await new Promise((resolve, reject) => {
|
|
352
|
-
httpServer.on("error", (error) => {
|
|
353
|
-
console.error("Failed to start server:", error);
|
|
354
|
-
reject(error);
|
|
355
|
-
});
|
|
356
|
-
httpServer.listen(port, () => {
|
|
357
|
-
resolve();
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
361
|
-
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
362
|
-
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
363
|
-
if (typeof navigator !== "undefined" &&
|
|
364
|
-
navigator.userAgent === "Cloudflare-Workers") {
|
|
365
|
-
const cloudflareNode = "cloudflare:node";
|
|
366
|
-
const { httpServerHandler } = await import(cloudflareNode);
|
|
367
|
-
return httpServerHandler({ port });
|
|
368
|
-
}
|
|
369
|
-
const shutdown = () => {
|
|
370
|
-
// Drop both handlers so a second signal falls through to Node's default
|
|
371
|
-
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
372
|
-
process.off("SIGTERM", shutdown);
|
|
373
|
-
process.off("SIGINT", shutdown);
|
|
374
|
-
httpServer.close(() => process.exit(0));
|
|
375
|
-
// Force exit if connections don't drain in time so the port is still
|
|
376
|
-
// released promptly (e.g. for nodemon restarts).
|
|
377
|
-
setTimeout(() => process.exit(0), 3000).unref();
|
|
378
|
-
};
|
|
379
|
-
process.on("SIGTERM", shutdown);
|
|
380
|
-
process.on("SIGINT", shutdown);
|
|
381
|
-
return undefined;
|
|
382
313
|
}
|
|
383
314
|
enforceOneToolPerView(component, toolName) {
|
|
384
315
|
const existingTool = this.claimedViews.get(component);
|
|
@@ -387,14 +318,10 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
387
318
|
}
|
|
388
319
|
this.claimedViews.set(component, toolName);
|
|
389
320
|
}
|
|
390
|
-
resolveViewRequestContext(
|
|
321
|
+
resolveViewRequestContext(ctx) {
|
|
391
322
|
const isProduction = process.env.NODE_ENV === "production";
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
const val = headers[key];
|
|
395
|
-
return Array.isArray(val) ? val[0] : val;
|
|
396
|
-
};
|
|
397
|
-
const isClaude = header("user-agent") === "Claude-User";
|
|
323
|
+
const header = (key) => ctx?.http?.req?.headers.get(key) ?? undefined;
|
|
324
|
+
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
398
325
|
const serverUrl = resolveServerOrigin(header);
|
|
399
326
|
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
400
327
|
// per-request so one process can serve many hosts/prefixes at once: the
|
|
@@ -409,7 +336,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
409
336
|
}
|
|
410
337
|
let contentMetaOverrides = {};
|
|
411
338
|
if (isClaude) {
|
|
412
|
-
const pathname =
|
|
339
|
+
const pathname = ctx?.http?.req ? new URL(ctx.http.req.url).pathname : "";
|
|
413
340
|
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
414
341
|
// Strip a lone trailing slash so the hash matches the connector URL
|
|
415
342
|
// as registered with Claude (which has no trailing slash on bare origins).
|
|
@@ -423,52 +350,32 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
423
350
|
}
|
|
424
351
|
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
425
352
|
}
|
|
426
|
-
registerViewResources(toolName, view, toolMeta) {
|
|
353
|
+
registerViewResources(toolName, view, toolMeta, openai) {
|
|
427
354
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
428
355
|
// their cache when the bundle changes, but keep the URI stable across
|
|
429
356
|
// `tools/list` calls when the bundle hasn't changed.
|
|
430
357
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
431
358
|
const viewResource = {
|
|
432
|
-
hostType: "mcp-app",
|
|
433
359
|
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
434
360
|
mimeType: "text/html;profile=mcp-app",
|
|
435
361
|
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
436
|
-
const
|
|
437
|
-
ui: {
|
|
438
|
-
csp: {
|
|
439
|
-
resourceDomains,
|
|
440
|
-
connectDomains,
|
|
441
|
-
baseUriDomains,
|
|
442
|
-
},
|
|
443
|
-
domain,
|
|
444
|
-
},
|
|
445
|
-
};
|
|
446
|
-
const fromView = {
|
|
362
|
+
const ui = {
|
|
447
363
|
ui: {
|
|
448
364
|
...(view.description && { description: view.description }),
|
|
449
365
|
...(view.prefersBorder !== undefined && {
|
|
450
366
|
prefersBorder: view.prefersBorder,
|
|
451
367
|
}),
|
|
452
|
-
|
|
368
|
+
domain: overrides.domain ?? view.domain ?? domain,
|
|
453
369
|
csp: {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
...(view.csp?.connectDomains && {
|
|
458
|
-
connectDomains: view.csp.connectDomains,
|
|
459
|
-
}),
|
|
370
|
+
resourceDomains: unionOf(resourceDomains, view.csp?.resourceDomains),
|
|
371
|
+
connectDomains: unionOf(connectDomains, view.csp?.connectDomains),
|
|
372
|
+
baseUriDomains: unionOf(baseUriDomains, view.csp?.baseUriDomains),
|
|
460
373
|
...(view.csp?.frameDomains && {
|
|
461
374
|
frameDomains: view.csp.frameDomains,
|
|
462
375
|
}),
|
|
463
|
-
...(view.csp?.baseUriDomains && {
|
|
464
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
465
|
-
}),
|
|
466
376
|
},
|
|
467
377
|
},
|
|
468
378
|
};
|
|
469
|
-
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
470
|
-
ui: overrides,
|
|
471
|
-
});
|
|
472
379
|
const base = {
|
|
473
380
|
...ui,
|
|
474
381
|
...(view.description && {
|
|
@@ -478,10 +385,12 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
478
385
|
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
479
386
|
}),
|
|
480
387
|
};
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
388
|
+
const meta = { ...base, ...view._meta };
|
|
389
|
+
mergeOpenAIUi(meta, {
|
|
390
|
+
availableDisplayModes: openai?.availableDisplayModes,
|
|
391
|
+
preferredDisplayMode: openai?.preferredDisplayMode,
|
|
392
|
+
});
|
|
393
|
+
return meta;
|
|
485
394
|
},
|
|
486
395
|
};
|
|
487
396
|
this.registerViewResource({ name: toolName, viewResource, view });
|
|
@@ -494,7 +403,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
494
403
|
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
495
404
|
}
|
|
496
405
|
registerViewResource({ name, viewResource, view, }) {
|
|
497
|
-
const {
|
|
406
|
+
const { uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
498
407
|
const buildMeta = (extra) => {
|
|
499
408
|
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
500
409
|
return buildContentMeta({
|
|
@@ -516,13 +425,11 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
516
425
|
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
517
426
|
const html = isProduction
|
|
518
427
|
? templateHelper.renderProduction({
|
|
519
|
-
hostType,
|
|
520
428
|
serverUrl: viewBase,
|
|
521
429
|
viewFile: this.lookupViewFile(view.component),
|
|
522
430
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
523
431
|
})
|
|
524
432
|
: templateHelper.renderDevelopment({
|
|
525
|
-
hostType,
|
|
526
433
|
serverUrl: viewBase,
|
|
527
434
|
viewName: view.component,
|
|
528
435
|
});
|
|
@@ -538,9 +445,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
538
445
|
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
539
446
|
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
540
447
|
}
|
|
541
|
-
|
|
448
|
+
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
542
449
|
return async (args, extra) => {
|
|
543
|
-
|
|
450
|
+
if (this.oauthEnabled) {
|
|
451
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.http?.authInfo);
|
|
452
|
+
if (failure) {
|
|
453
|
+
const header = (key) => extra.http?.req?.headers.get(key) ?? undefined;
|
|
454
|
+
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
let result;
|
|
458
|
+
try {
|
|
459
|
+
result = await cb(args, extra);
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
captureToolError(extra, error);
|
|
463
|
+
throw error;
|
|
464
|
+
}
|
|
465
|
+
warnOnLargeToolOutput(result, toolName);
|
|
544
466
|
return {
|
|
545
467
|
...result,
|
|
546
468
|
content: normalizeContent(result.content),
|
|
@@ -600,32 +522,131 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
600
522
|
if (this.viteManifest) {
|
|
601
523
|
return this.viteManifest;
|
|
602
524
|
}
|
|
603
|
-
|
|
525
|
+
cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
526
|
+
return cachedDiskManifest ?? {};
|
|
604
527
|
}
|
|
605
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Register a ChatGPT file viewer, from the OpenAI MCP extensions: a tool
|
|
530
|
+
* with a file entrypoint for `extensions` and a view. ChatGPT desktop calls
|
|
531
|
+
* it with the file the user opened, as `{ file: { name, resourceUri } }`.
|
|
532
|
+
* Read and save the file from the view with `useFileResource`.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* server.registerFileViewer(
|
|
537
|
+
* {
|
|
538
|
+
* name: "part-viewer",
|
|
539
|
+
* title: "Part Viewer",
|
|
540
|
+
* extensions: [".stl", ".step"],
|
|
541
|
+
* view: { component: "part-viewer" },
|
|
542
|
+
* },
|
|
543
|
+
* async ({ file }) => ({ structuredContent: { name: file.name } }),
|
|
544
|
+
* );
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* @see https://docs.skybridge.tech/api-reference/register-file-viewer
|
|
548
|
+
*/
|
|
549
|
+
registerFileViewer(config, cb) {
|
|
550
|
+
const { extensions, openai, ...toolConfig } = config;
|
|
551
|
+
return this.registerTool({
|
|
552
|
+
...toolConfig,
|
|
553
|
+
inputSchema: fileEntrypointInput,
|
|
554
|
+
openai: { ...openai, entrypoints: [{ type: "file", extensions }] },
|
|
555
|
+
}, cb);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Register the composer at-mention search for ChatGPT, from the OpenAI MCP
|
|
559
|
+
* extensions. When the user types `@` and your app name, ChatGPT calls
|
|
560
|
+
* `handler` with the typed text and lists the returned resource links.
|
|
561
|
+
* Skybridge registers it as a tool hidden from the model.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* server.registerMentions({
|
|
566
|
+
* name: "search_parts",
|
|
567
|
+
* handler: async ({ query }) => ({
|
|
568
|
+
* items: findParts(query).map((part) => ({
|
|
569
|
+
* type: "resource_link",
|
|
570
|
+
* uri: `parts://${part.id}`,
|
|
571
|
+
* name: part.name,
|
|
572
|
+
* })),
|
|
573
|
+
* }),
|
|
574
|
+
* });
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @see https://docs.skybridge.tech/api-reference/register-mentions
|
|
578
|
+
*/
|
|
579
|
+
registerMentions(config) {
|
|
580
|
+
this.registerTool({
|
|
581
|
+
name: config.name,
|
|
582
|
+
description: config.description ?? "Search items to mention.",
|
|
583
|
+
annotations: { readOnlyHint: true },
|
|
584
|
+
inputSchema: { query: z.string() },
|
|
585
|
+
_meta: {
|
|
586
|
+
"openai/extensions": { "mentions/search": {} },
|
|
587
|
+
ui: { visibility: ["app"] },
|
|
588
|
+
},
|
|
589
|
+
}, async ({ query }, extra) => ({
|
|
590
|
+
content: [],
|
|
591
|
+
structuredContent: await config.handler({ query }, extra),
|
|
592
|
+
}));
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
registerTool(rawConfig, rawCb) {
|
|
606
596
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
597
|
+
const config = rawConfig;
|
|
598
|
+
const cb = rawCb;
|
|
599
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, openai, _meta: userToolMeta, ...toolFields } = config;
|
|
600
|
+
const authNeedsProvider = auth !== undefined &&
|
|
601
|
+
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
602
|
+
if (rawSecuritySchemes === undefined &&
|
|
603
|
+
authNeedsProvider &&
|
|
604
|
+
!this.oauthEnabled) {
|
|
605
|
+
throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
|
|
610
606
|
}
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
607
|
+
const securitySchemes = rawSecuritySchemes ??
|
|
608
|
+
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
614
609
|
const toolMeta = { ...userToolMeta };
|
|
610
|
+
this.toolSecuritySchemes.set(name, securitySchemes);
|
|
615
611
|
if (securitySchemes) {
|
|
616
612
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
617
613
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
618
614
|
// fields, so the canonical spot isn't reachable without intercepting
|
|
619
615
|
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
620
|
-
//
|
|
616
|
+
// ChatGPT plugin reference until SEP-1488 lands in the spec.
|
|
621
617
|
toolMeta.securitySchemes = securitySchemes;
|
|
622
618
|
}
|
|
619
|
+
if (openai) {
|
|
620
|
+
if (!view) {
|
|
621
|
+
throw new Error(`skybridge: tool "${name}" sets \`openai\` options but has no \`view\`.`);
|
|
622
|
+
}
|
|
623
|
+
const opensWithoutInput = openai.entrypoints?.some(({ type }) => type === "global" || type === "thread");
|
|
624
|
+
if (opensWithoutInput && !acceptsEmptyInput(toolFields.inputSchema)) {
|
|
625
|
+
throw new Error(`skybridge: tool "${name}" has a global or thread entrypoint, so ChatGPT calls it with \`{}\`, but its input schema rejects \`{}\`. Make every input optional.`);
|
|
626
|
+
}
|
|
627
|
+
const badExtension = openai.entrypoints
|
|
628
|
+
?.flatMap((entrypoint) => entrypoint.type === "file" ? entrypoint.extensions : [])
|
|
629
|
+
.find((extension) => !extension.startsWith("."));
|
|
630
|
+
if (badExtension !== undefined) {
|
|
631
|
+
throw new Error(`skybridge: tool "${name}" has a file entrypoint extension "${badExtension}" that doesn't start with ".".`);
|
|
632
|
+
}
|
|
633
|
+
mergeOpenAIUi(toolMeta, {
|
|
634
|
+
entrypoints: openai.entrypoints,
|
|
635
|
+
preferredModelDisplayMode: openai.preferredModelDisplayMode,
|
|
636
|
+
});
|
|
637
|
+
}
|
|
623
638
|
if (view) {
|
|
624
639
|
this.enforceOneToolPerView(view.component, name);
|
|
625
|
-
this.registerViewResources(name, view, toolMeta);
|
|
640
|
+
this.registerViewResources(name, view, toolMeta, openai);
|
|
626
641
|
}
|
|
627
|
-
const wrappedCb = this.
|
|
628
|
-
|
|
642
|
+
const wrappedCb = this.decorateToolHandler(cb, {
|
|
643
|
+
attachViewUUID: Boolean(view),
|
|
644
|
+
securitySchemes,
|
|
645
|
+
toolName: name,
|
|
646
|
+
});
|
|
647
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, toolFields.inputSchema === undefined
|
|
648
|
+
? (extra) => wrappedCb({}, extra)
|
|
649
|
+
: wrappedCb);
|
|
629
650
|
return this;
|
|
630
651
|
}
|
|
631
652
|
}
|