skybridge 0.0.0-dev.ed29eee → 0.0.0-dev.ed38f16
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 +8 -7
- package/dist/cli/build-helpers.d.ts +1 -1
- package/dist/cli/build-helpers.js +4 -4
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +2 -2
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.js +1 -1
- 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/run-plain.js +2 -1
- package/dist/cli/run-plain.js.map +1 -1
- package/dist/cli/telemetry.js +2 -0
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +11 -1
- package/dist/cli/use-nodemon.js +30 -8
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/dev.js +4 -4
- 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/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 +21 -17
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/providers/auth0.d.ts +2 -2
- 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 +1 -1
- package/dist/server/auth/providers/auth0.test.js.map +1 -1
- package/dist/server/auth/providers/authplane.d.ts +2 -2
- package/dist/server/auth/providers/authplane.js.map +1 -1
- package/dist/server/auth/providers/authplane.test.js +10 -7
- package/dist/server/auth/providers/authplane.test.js.map +1 -1
- package/dist/server/auth/providers/clerk.d.ts +2 -2
- package/dist/server/auth/providers/clerk.js.map +1 -1
- package/dist/server/auth/providers/clerk.test.js +1 -1
- package/dist/server/auth/providers/clerk.test.js.map +1 -1
- package/dist/server/auth/providers/custom.d.ts +8 -6
- package/dist/server/auth/providers/custom.js +5 -2
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +13 -10
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +2 -2
- package/dist/server/auth/providers/descope.js.map +1 -1
- package/dist/server/auth/providers/descope.test.js +3 -3
- package/dist/server/auth/providers/descope.test.js.map +1 -1
- package/dist/server/auth/providers/stytch.d.ts +2 -2
- package/dist/server/auth/providers/stytch.js.map +1 -1
- package/dist/server/auth/providers/workos.d.ts +5 -4
- package/dist/server/auth/providers/workos.js +2 -1
- package/dist/server/auth/providers/workos.js.map +1 -1
- package/dist/server/auth/setup.d.ts +1 -1
- package/dist/server/auth/setup.js +3 -4
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +83 -77
- package/dist/server/auth/setup.test.js.map +1 -1
- package/dist/server/auth/verify.d.ts +5 -3
- package/dist/server/auth/verify.js +2 -2
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth/verify.test.js +16 -0
- package/dist/server/auth/verify.test.js.map +1 -1
- package/dist/server/auth-extra.test-d.js +97 -49
- package/dist/server/auth-extra.test-d.js.map +1 -1
- package/dist/server/auth.d.ts +7 -8
- 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/index.d.ts +6 -3
- package/dist/server/index.js +3 -1
- package/dist/server/index.js.map +1 -1
- 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 +6 -6
- 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 +222 -150
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.js +77 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/server.d.ts +149 -119
- package/dist/server/server.js +146 -303
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.js +19 -12
- package/dist/server/skills-integration.test.js.map +1 -1
- package/dist/server/skills.d.ts +3 -5
- package/dist/server/skills.js +17 -24
- package/dist/server/skills.js.map +1 -1
- package/dist/server/skills.test.js +8 -12
- package/dist/server/skills.test.js.map +1 -1
- 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.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/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 +25 -37
- 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.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.js.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +6 -2
- package/dist/web/bridges/adaptor.js +47 -10
- package/dist/web/bridges/adaptor.js.map +1 -1
- package/dist/web/bridges/adaptor.test.js +1 -1
- package/dist/web/bridges/adaptor.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
- 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 +10 -3
- 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 +26 -3
- 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 +33 -14
- package/dist/web/bridges/types.js.map +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.js +3 -2
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +8 -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 +4 -2
- package/dist/web/hooks/index.js +4 -2
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/openai-extensions.test.js +104 -0
- package/dist/web/hooks/openai-extensions.test.js.map +1 -0
- 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 +9 -2
- 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 +60 -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-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-info.test.js → use-host.test.js} +7 -7
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-model-context.d.ts +42 -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-register-view-tool.d.ts +2 -3
- 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.test.js +2 -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 +14 -12
- package/dist/web/hooks/use-host-info.d.ts +0 -22
- package/dist/web/hooks/use-host-info.js +0 -30
- package/dist/web/hooks/use-host-info.js.map +0 -1
- package/dist/web/hooks/use-host-info.test.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-build.test.js +0 -54
- package/dist/web/plugin/plugin-build.test.js.map +0 -1
- package/dist/web/plugin/plugin.d.ts +0 -39
- package/dist/web/plugin/plugin.js +0 -200
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/plugin.test.js +0 -61
- package/dist/web/plugin/plugin.test.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-host-info.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-layout.test.d.ts → server/mcp-errors.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → server/register-tool.test.d.ts} +0 -0
- /package/dist/{web/plugin/plugin-build.test.d.ts → server/tool-extra.test.d.ts} +0 -0
- /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
- /package/dist/{web/plugin → views}/scan-views.test.d.ts +0 -0
- /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.d.ts +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
- /package/dist/web/{plugin/plugin.test.d.ts → hooks/openai-extensions.test.d.ts} +0 -0
- /package/dist/web/{plugin/transform-data-llm.test.d.ts → hooks/use-host.test.d.ts} +0 -0
package/dist/server/server.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
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 { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
-
import { mergeWith, union } from "es-toolkit";
|
|
8
|
-
import express, {} from "express";
|
|
4
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/server";
|
|
9
5
|
import { warnOnLargeToolOutput } from "../context-warnings.js";
|
|
10
6
|
import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
|
|
11
|
-
import { setupOAuth } from "./auth/setup.js";
|
|
12
|
-
import { createApp } from "./express.js";
|
|
13
7
|
import { hostFromUserAgent } from "./host.js";
|
|
14
|
-
import {
|
|
15
|
-
import { buildMiddlewareChain, captureToolError, getHandlerMaps, } from "./middleware.js";
|
|
8
|
+
import { captureToolError } from "./middleware.js";
|
|
16
9
|
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
17
10
|
import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
|
|
18
11
|
import { templateHelper } from "./templateHelper.js";
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
const unionOf = (base, extra) => extra ? [...new Set([...base, ...extra])] : base;
|
|
13
|
+
function definedEntries(values) {
|
|
14
|
+
return Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
|
|
15
|
+
}
|
|
16
|
+
function acceptsEmptyInput(inputSchema) {
|
|
17
|
+
if (inputSchema === undefined) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const checks = "~standard" in inputSchema
|
|
21
|
+
? [inputSchema["~standard"].validate({})]
|
|
22
|
+
: Object.values(inputSchema).map((schema) => schema["~standard"].validate(undefined));
|
|
23
|
+
return checks.every((result) => result instanceof Promise || result.issues === undefined);
|
|
24
|
+
}
|
|
26
25
|
const SKILLS_DIR = "src/skills";
|
|
27
26
|
/**
|
|
28
27
|
* Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
|
|
@@ -65,35 +64,6 @@ export function normalizeContent(content) {
|
|
|
65
64
|
return [content];
|
|
66
65
|
}
|
|
67
66
|
const McpServerBaseOmitted = McpServerBase;
|
|
68
|
-
/**
|
|
69
|
-
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
70
|
-
* registry, view resources, an embedded Express app, and protocol-level
|
|
71
|
-
* middleware. Construct it with the same `Implementation` info you would pass
|
|
72
|
-
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
73
|
-
* then call {@link McpServer.run} to start the HTTP server.
|
|
74
|
-
*
|
|
75
|
-
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
76
|
-
* shape, so `typeof server` carries enough information for view-side helpers
|
|
77
|
-
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
78
|
-
*
|
|
79
|
-
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
80
|
-
* chaining; you almost never set this manually.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
85
|
-
* .registerTool({
|
|
86
|
-
* name: "search",
|
|
87
|
-
* inputSchema: { query: z.string() },
|
|
88
|
-
* view: { component: "search" },
|
|
89
|
-
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
90
|
-
*
|
|
91
|
-
* await server.run();
|
|
92
|
-
* export type AppType = typeof server;
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
96
|
-
*/
|
|
97
67
|
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
98
68
|
// Set at module scope rather than passed through the constructor because the
|
|
99
69
|
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
@@ -111,8 +81,12 @@ export function __setBuildManifest(manifest) {
|
|
|
111
81
|
pendingBuildManifest = manifest;
|
|
112
82
|
}
|
|
113
83
|
let pendingSkillsManifest = null;
|
|
84
|
+
let cachedDiskManifest = null;
|
|
85
|
+
let discoveredSkills = null;
|
|
86
|
+
let warnedOnMissingSkills = false;
|
|
114
87
|
export function __setSkillsManifest(manifest) {
|
|
115
88
|
pendingSkillsManifest = manifest;
|
|
89
|
+
discoveredSkills = null;
|
|
116
90
|
}
|
|
117
91
|
// Pure and `this`-free so it can run inside the `super(...)` call, before `this`
|
|
118
92
|
// exists — the capability must be present for the `initialize` response.
|
|
@@ -131,45 +105,37 @@ function withSkillsCapability(options, skybridgeOptions) {
|
|
|
131
105
|
},
|
|
132
106
|
};
|
|
133
107
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Typed registration sugar over the MCP SDK's `McpServer`: a tool registry
|
|
110
|
+
* that carries input/output/meta shapes, view resources, per-tool security
|
|
111
|
+
* schemes, and prompt/resource registration. A {@link Skybridge} app builds
|
|
112
|
+
* one of these per request and hands it to your `handler`; chain
|
|
113
|
+
* {@link McpServer.registerTool} calls on it and return the result.
|
|
114
|
+
*
|
|
115
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
116
|
+
* shape, so `typeof app` carries enough information for view-side helpers
|
|
117
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
118
|
+
*
|
|
119
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
120
|
+
* chaining; you almost never set this manually.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* export const app = new Skybridge({
|
|
125
|
+
* name: "my-app",
|
|
126
|
+
* version: "1.0.0",
|
|
127
|
+
* handler: (server) =>
|
|
128
|
+
* server.registerTool({
|
|
129
|
+
* name: "search",
|
|
130
|
+
* inputSchema: { query: z.string() },
|
|
131
|
+
* view: { component: "search" },
|
|
132
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` })),
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
137
|
+
*/
|
|
154
138
|
export class McpServer extends McpServerBaseOmitted {
|
|
155
|
-
/**
|
|
156
|
-
* The underlying Express app. Use this to extend the HTTP server with
|
|
157
|
-
* custom routes, middleware, or settings — e.g.
|
|
158
|
-
* `server.express.get("/health", ...)`.
|
|
159
|
-
*
|
|
160
|
-
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
161
|
-
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
162
|
-
* Register your handlers before `run()`;
|
|
163
|
-
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
164
|
-
* error handler are appended in that order.
|
|
165
|
-
*
|
|
166
|
-
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
167
|
-
* locally and on self-hosted deployments.
|
|
168
|
-
*/
|
|
169
|
-
express;
|
|
170
|
-
customErrorMiddleware = [];
|
|
171
|
-
mcpMiddlewareEntries = [];
|
|
172
|
-
mcpMiddlewareApplied = false;
|
|
173
139
|
claimedViews = new Map();
|
|
174
140
|
viewMetaBuilders = new Map();
|
|
175
141
|
/**
|
|
@@ -180,82 +146,64 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
180
146
|
*/
|
|
181
147
|
viewUriByPath = new Map();
|
|
182
148
|
viteManifest = null;
|
|
183
|
-
serverInfo;
|
|
184
|
-
serverOptions;
|
|
185
149
|
oauthEnabled = false;
|
|
186
150
|
resolveResourceMetadataUrl;
|
|
187
|
-
|
|
151
|
+
toolSecuritySchemes = new Map();
|
|
152
|
+
userMiddlewareEntries = [];
|
|
188
153
|
constructor(serverInfo, options, skybridgeOptions) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.serverInfo = serverInfo;
|
|
192
|
-
this.serverOptions = mergedOptions;
|
|
193
|
-
this.express = express();
|
|
194
|
-
this.express.use(express.json(skybridgeOptions?.json));
|
|
195
|
-
if (skybridgeOptions?.oauth) {
|
|
196
|
-
this.oauthEnabled = true;
|
|
197
|
-
this.resolveResourceMetadataUrl = setupOAuth(this.express, skybridgeOptions.oauth, this.securitySchemesByTool);
|
|
198
|
-
}
|
|
154
|
+
super(serverInfo, withSkillsCapability(options, skybridgeOptions));
|
|
155
|
+
this.oauthEnabled = Boolean(skybridgeOptions?.oauth);
|
|
199
156
|
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
200
|
-
// user code.
|
|
201
|
-
//
|
|
202
|
-
// Explicit `setViteManifest` calls still win because they happen after
|
|
203
|
-
// construction.
|
|
157
|
+
// user code. Explicit `setViteManifest` calls still win because they
|
|
158
|
+
// happen after construction.
|
|
204
159
|
if (pendingBuildManifest) {
|
|
205
160
|
this.setViteManifest(pendingBuildManifest);
|
|
206
|
-
pendingBuildManifest = null;
|
|
207
161
|
}
|
|
208
162
|
this.setupSkills(Boolean(skybridgeOptions?.skills));
|
|
209
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* The per-tool security schemes collected during registration, keyed by tool
|
|
166
|
+
* name. Read by the OAuth layer to decide whether anonymous requests are
|
|
167
|
+
* allowed and which schemes gate a given `tools/call`.
|
|
168
|
+
*
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
get securitySchemesByTool() {
|
|
172
|
+
return this.toolSecuritySchemes;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Inject the resolver the app uses to build the protected-resource metadata
|
|
176
|
+
* URL, so tool handlers can emit in-band auth challenges.
|
|
177
|
+
*
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
setResourceMetadataUrlResolver(resolve) {
|
|
181
|
+
this.resolveResourceMetadataUrl = resolve;
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
210
184
|
setupSkills(enabled) {
|
|
211
|
-
const manifest = pendingSkillsManifest;
|
|
212
|
-
pendingSkillsManifest = null;
|
|
213
185
|
if (!enabled) {
|
|
214
186
|
return;
|
|
215
187
|
}
|
|
216
|
-
|
|
217
|
-
if (
|
|
188
|
+
discoveredSkills ??= pendingSkillsManifest ?? discoverSkills(SKILLS_DIR);
|
|
189
|
+
if (discoveredSkills.length === 0 && !warnedOnMissingSkills) {
|
|
190
|
+
warnedOnMissingSkills = true;
|
|
218
191
|
console.warn(`skybridge: the "skills" option is enabled but no skills were found in "${SKILLS_DIR}". Add a <name>/SKILL.md there, or remove the option.`);
|
|
219
192
|
}
|
|
220
|
-
registerSkills(this,
|
|
221
|
-
}
|
|
222
|
-
use(pathOrHandler, ...handlers) {
|
|
223
|
-
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
224
|
-
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
225
|
-
if (typeof pathOrHandler === "string") {
|
|
226
|
-
this.express.use(pathOrHandler, ...handlers);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
this.express.use(pathOrHandler, ...handlers);
|
|
230
|
-
}
|
|
231
|
-
return this;
|
|
232
|
-
}
|
|
233
|
-
useOnError(pathOrHandler, ...handlers) {
|
|
234
|
-
if (typeof pathOrHandler === "string") {
|
|
235
|
-
this.customErrorMiddleware.push({ path: pathOrHandler, handlers });
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
this.customErrorMiddleware.push({
|
|
239
|
-
handlers: [pathOrHandler, ...handlers],
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
return this;
|
|
193
|
+
registerSkills(this, discoveredSkills);
|
|
243
194
|
}
|
|
244
195
|
mcpMiddleware(filterOrHandler,
|
|
245
196
|
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
246
197
|
maybeHandler) {
|
|
247
|
-
if (this.mcpMiddlewareApplied) {
|
|
248
|
-
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
249
|
-
}
|
|
250
198
|
const handler = maybeHandler;
|
|
251
199
|
if (typeof filterOrHandler === "function") {
|
|
252
|
-
this.
|
|
200
|
+
this.userMiddlewareEntries.push({
|
|
253
201
|
filter: null,
|
|
254
202
|
handler: filterOrHandler,
|
|
255
203
|
});
|
|
256
204
|
}
|
|
257
205
|
else if (handler) {
|
|
258
|
-
this.
|
|
206
|
+
this.userMiddlewareEntries.push({
|
|
259
207
|
filter: filterOrHandler,
|
|
260
208
|
handler,
|
|
261
209
|
});
|
|
@@ -265,11 +213,15 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
265
213
|
}
|
|
266
214
|
return this;
|
|
267
215
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
216
|
+
/**
|
|
217
|
+
* This instance's protocol-level middleware: the framework's own entries
|
|
218
|
+
* (view `_meta` on `resources/list`, version-agnostic view resolution on
|
|
219
|
+
* `resources/read`, the top-level `securitySchemes` mirror on `tools/list`)
|
|
220
|
+
* followed by the ones registered via {@link McpServer.mcpMiddleware}.
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
protocolMiddlewareEntries() {
|
|
273
225
|
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
274
226
|
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
275
227
|
const viewListMetaEntry = {
|
|
@@ -345,121 +297,12 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
345
297
|
return result;
|
|
346
298
|
},
|
|
347
299
|
};
|
|
348
|
-
|
|
349
|
-
const entries = [
|
|
350
|
-
...(monitoringEntry ? [monitoringEntry] : []),
|
|
300
|
+
return [
|
|
351
301
|
viewListMetaEntry,
|
|
352
302
|
viewReadResolveEntry,
|
|
353
303
|
toolsListSecuritySchemesEntry,
|
|
354
|
-
...this.
|
|
304
|
+
...this.userMiddlewareEntries,
|
|
355
305
|
];
|
|
356
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
357
|
-
const instrumentMap = (map, isNotification) => {
|
|
358
|
-
for (const [method, handler] of map) {
|
|
359
|
-
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
360
|
-
}
|
|
361
|
-
const originalSet = map.set.bind(map);
|
|
362
|
-
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
363
|
-
};
|
|
364
|
-
instrumentMap(requestHandlers, false);
|
|
365
|
-
instrumentMap(notificationHandlers, true);
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
369
|
-
* when you're embedding Skybridge in a host that already manages its own
|
|
370
|
-
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
371
|
-
* which sets the transport up for you. Locks in any middleware registered
|
|
372
|
-
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
373
|
-
* throw afterwards.
|
|
374
|
-
*/
|
|
375
|
-
async connect(transport) {
|
|
376
|
-
this.applyMcpMiddleware();
|
|
377
|
-
return McpServerBase.prototype.connect.call(this, transport);
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
381
|
-
* transport per instance, so we can't reuse this `McpServer` across
|
|
382
|
-
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
383
|
-
* factory, but that would break Skybridge's singleton API — so instead
|
|
384
|
-
* we build a fresh underlying `Server` per request and share the main
|
|
385
|
-
* server's handler maps by reference. The cast is unavoidable: there's
|
|
386
|
-
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
387
|
-
* read side and fails fast on SDK field renames.
|
|
388
|
-
*/
|
|
389
|
-
async connectStatelessTransport(transport) {
|
|
390
|
-
this.applyMcpMiddleware();
|
|
391
|
-
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
392
|
-
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
393
|
-
const target = fresh;
|
|
394
|
-
target._requestHandlers = requestHandlers;
|
|
395
|
-
target._notificationHandlers = notificationHandlers;
|
|
396
|
-
await fresh.connect(transport);
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
400
|
-
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
401
|
-
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
402
|
-
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
403
|
-
*
|
|
404
|
-
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
405
|
-
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
406
|
-
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
407
|
-
* serverless function entry can call it as a `(req, res)` handler. On
|
|
408
|
-
* Node, returns `undefined` once listening.
|
|
409
|
-
*/
|
|
410
|
-
async run() {
|
|
411
|
-
this.applyMcpMiddleware();
|
|
412
|
-
if (process.env.VERCEL === "1") {
|
|
413
|
-
// createApp only reads httpServer inside its dev-only branch
|
|
414
|
-
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
415
|
-
// bare object passed to satisfy the required parameter.
|
|
416
|
-
const httpServer = http.createServer();
|
|
417
|
-
await createApp({
|
|
418
|
-
mcpServer: this,
|
|
419
|
-
httpServer,
|
|
420
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
421
|
-
});
|
|
422
|
-
return this.express;
|
|
423
|
-
}
|
|
424
|
-
const httpServer = http.createServer();
|
|
425
|
-
await createApp({
|
|
426
|
-
mcpServer: this,
|
|
427
|
-
httpServer,
|
|
428
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
429
|
-
});
|
|
430
|
-
httpServer.on("request", this.express);
|
|
431
|
-
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
432
|
-
await new Promise((resolve, reject) => {
|
|
433
|
-
httpServer.on("error", (error) => {
|
|
434
|
-
console.error("Failed to start server:", error);
|
|
435
|
-
reject(error);
|
|
436
|
-
});
|
|
437
|
-
httpServer.listen(port, () => {
|
|
438
|
-
resolve();
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
442
|
-
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
443
|
-
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
444
|
-
if (typeof navigator !== "undefined" &&
|
|
445
|
-
navigator.userAgent === "Cloudflare-Workers") {
|
|
446
|
-
const cloudflareNode = "cloudflare:node";
|
|
447
|
-
const { httpServerHandler } = await import(cloudflareNode);
|
|
448
|
-
return httpServerHandler({ port });
|
|
449
|
-
}
|
|
450
|
-
const shutdown = () => {
|
|
451
|
-
// Drop both handlers so a second signal falls through to Node's default
|
|
452
|
-
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
453
|
-
process.off("SIGTERM", shutdown);
|
|
454
|
-
process.off("SIGINT", shutdown);
|
|
455
|
-
httpServer.close(() => process.exit(0));
|
|
456
|
-
// Force exit if connections don't drain in time so the port is still
|
|
457
|
-
// released promptly (e.g. for nodemon restarts).
|
|
458
|
-
setTimeout(() => process.exit(0), 3000).unref();
|
|
459
|
-
};
|
|
460
|
-
process.on("SIGTERM", shutdown);
|
|
461
|
-
process.on("SIGINT", shutdown);
|
|
462
|
-
return undefined;
|
|
463
306
|
}
|
|
464
307
|
enforceOneToolPerView(component, toolName) {
|
|
465
308
|
const existingTool = this.claimedViews.get(component);
|
|
@@ -468,13 +311,9 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
468
311
|
}
|
|
469
312
|
this.claimedViews.set(component, toolName);
|
|
470
313
|
}
|
|
471
|
-
resolveViewRequestContext(
|
|
314
|
+
resolveViewRequestContext(ctx) {
|
|
472
315
|
const isProduction = process.env.NODE_ENV === "production";
|
|
473
|
-
const
|
|
474
|
-
const header = (key) => {
|
|
475
|
-
const val = headers[key];
|
|
476
|
-
return Array.isArray(val) ? val[0] : val;
|
|
477
|
-
};
|
|
316
|
+
const header = (key) => ctx?.http?.req?.headers.get(key) ?? undefined;
|
|
478
317
|
const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
|
|
479
318
|
const serverUrl = resolveServerOrigin(header);
|
|
480
319
|
// Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
|
|
@@ -490,7 +329,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
490
329
|
}
|
|
491
330
|
let contentMetaOverrides = {};
|
|
492
331
|
if (isClaude) {
|
|
493
|
-
const pathname =
|
|
332
|
+
const pathname = ctx?.http?.req ? new URL(ctx.http.req.url).pathname : "";
|
|
494
333
|
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
495
334
|
// Strip a lone trailing slash so the hash matches the connector URL
|
|
496
335
|
// as registered with Claude (which has no trailing slash on bare origins).
|
|
@@ -504,52 +343,32 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
504
343
|
}
|
|
505
344
|
return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
|
|
506
345
|
}
|
|
507
|
-
registerViewResources(toolName, view, toolMeta) {
|
|
346
|
+
registerViewResources(toolName, view, toolMeta, openaiResourceMeta) {
|
|
508
347
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
509
348
|
// their cache when the bundle changes, but keep the URI stable across
|
|
510
349
|
// `tools/list` calls when the bundle hasn't changed.
|
|
511
350
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
512
351
|
const viewResource = {
|
|
513
|
-
hostType: "mcp-app",
|
|
514
352
|
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
515
353
|
mimeType: "text/html;profile=mcp-app",
|
|
516
354
|
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
517
|
-
const
|
|
518
|
-
ui: {
|
|
519
|
-
csp: {
|
|
520
|
-
resourceDomains,
|
|
521
|
-
connectDomains,
|
|
522
|
-
baseUriDomains,
|
|
523
|
-
},
|
|
524
|
-
domain,
|
|
525
|
-
},
|
|
526
|
-
};
|
|
527
|
-
const fromView = {
|
|
355
|
+
const ui = {
|
|
528
356
|
ui: {
|
|
529
357
|
...(view.description && { description: view.description }),
|
|
530
358
|
...(view.prefersBorder !== undefined && {
|
|
531
359
|
prefersBorder: view.prefersBorder,
|
|
532
360
|
}),
|
|
533
|
-
|
|
361
|
+
domain: overrides.domain ?? view.domain ?? domain,
|
|
534
362
|
csp: {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
...(view.csp?.connectDomains && {
|
|
539
|
-
connectDomains: view.csp.connectDomains,
|
|
540
|
-
}),
|
|
363
|
+
resourceDomains: unionOf(resourceDomains, view.csp?.resourceDomains),
|
|
364
|
+
connectDomains: unionOf(connectDomains, view.csp?.connectDomains),
|
|
365
|
+
baseUriDomains: unionOf(baseUriDomains, view.csp?.baseUriDomains),
|
|
541
366
|
...(view.csp?.frameDomains && {
|
|
542
367
|
frameDomains: view.csp.frameDomains,
|
|
543
368
|
}),
|
|
544
|
-
...(view.csp?.baseUriDomains && {
|
|
545
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
546
|
-
}),
|
|
547
369
|
},
|
|
548
370
|
},
|
|
549
371
|
};
|
|
550
|
-
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
551
|
-
ui: overrides,
|
|
552
|
-
});
|
|
553
372
|
const base = {
|
|
554
373
|
...ui,
|
|
555
374
|
...(view.description && {
|
|
@@ -559,10 +378,14 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
559
378
|
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
560
379
|
}),
|
|
561
380
|
};
|
|
562
|
-
|
|
563
|
-
|
|
381
|
+
const meta = { ...base, ...view._meta };
|
|
382
|
+
if (openaiResourceMeta && Object.keys(openaiResourceMeta).length > 0) {
|
|
383
|
+
meta["openai/ui"] = {
|
|
384
|
+
...view._meta?.["openai/ui"],
|
|
385
|
+
...openaiResourceMeta,
|
|
386
|
+
};
|
|
564
387
|
}
|
|
565
|
-
return
|
|
388
|
+
return meta;
|
|
566
389
|
},
|
|
567
390
|
};
|
|
568
391
|
this.registerViewResource({ name: toolName, viewResource, view });
|
|
@@ -575,7 +398,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
575
398
|
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
576
399
|
}
|
|
577
400
|
registerViewResource({ name, viewResource, view, }) {
|
|
578
|
-
const {
|
|
401
|
+
const { uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
579
402
|
const buildMeta = (extra) => {
|
|
580
403
|
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
581
404
|
return buildContentMeta({
|
|
@@ -597,13 +420,11 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
597
420
|
const viewBase = `${serverUrl}${assetsBasePath}`;
|
|
598
421
|
const html = isProduction
|
|
599
422
|
? templateHelper.renderProduction({
|
|
600
|
-
hostType,
|
|
601
423
|
serverUrl: viewBase,
|
|
602
424
|
viewFile: this.lookupViewFile(view.component),
|
|
603
425
|
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
604
426
|
})
|
|
605
427
|
: templateHelper.renderDevelopment({
|
|
606
|
-
hostType,
|
|
607
428
|
serverUrl: viewBase,
|
|
608
429
|
viewName: view.component,
|
|
609
430
|
});
|
|
@@ -621,15 +442,10 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
621
442
|
}
|
|
622
443
|
decorateToolHandler(cb, { attachViewUUID, securitySchemes, toolName, }) {
|
|
623
444
|
return async (args, extra) => {
|
|
624
|
-
const toolExtra = extra ?? args;
|
|
625
445
|
if (this.oauthEnabled) {
|
|
626
|
-
const failure = evaluateSecuritySchemes(securitySchemes,
|
|
446
|
+
const failure = evaluateSecuritySchemes(securitySchemes, extra.http?.authInfo);
|
|
627
447
|
if (failure) {
|
|
628
|
-
const
|
|
629
|
-
const header = (key) => {
|
|
630
|
-
const value = headers[key];
|
|
631
|
-
return Array.isArray(value) ? value[0] : value;
|
|
632
|
-
};
|
|
448
|
+
const header = (key) => extra.http?.req?.headers.get(key) ?? undefined;
|
|
633
449
|
return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
|
|
634
450
|
}
|
|
635
451
|
}
|
|
@@ -638,7 +454,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
638
454
|
result = await cb(args, extra);
|
|
639
455
|
}
|
|
640
456
|
catch (error) {
|
|
641
|
-
captureToolError(
|
|
457
|
+
captureToolError(extra, error);
|
|
642
458
|
throw error;
|
|
643
459
|
}
|
|
644
460
|
warnOnLargeToolOutput(result, toolName);
|
|
@@ -701,12 +517,14 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
701
517
|
if (this.viteManifest) {
|
|
702
518
|
return this.viteManifest;
|
|
703
519
|
}
|
|
704
|
-
|
|
520
|
+
cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
521
|
+
return cachedDiskManifest ?? {};
|
|
705
522
|
}
|
|
706
|
-
registerTool(
|
|
523
|
+
registerTool(rawConfig, rawCb) {
|
|
707
524
|
const baseFn = McpServerBase.prototype.registerTool;
|
|
708
|
-
const
|
|
709
|
-
const
|
|
525
|
+
const config = rawConfig;
|
|
526
|
+
const cb = rawCb;
|
|
527
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, openai, _meta: userToolMeta, ...toolFields } = config;
|
|
710
528
|
const authNeedsProvider = auth !== undefined &&
|
|
711
529
|
(!auth.allowsAnonymous || Boolean(auth.scopes?.length));
|
|
712
530
|
if (rawSecuritySchemes === undefined &&
|
|
@@ -717,7 +535,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
717
535
|
const securitySchemes = rawSecuritySchemes ??
|
|
718
536
|
(auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
|
|
719
537
|
const toolMeta = { ...userToolMeta };
|
|
720
|
-
this.
|
|
538
|
+
this.toolSecuritySchemes.set(name, securitySchemes);
|
|
721
539
|
if (securitySchemes) {
|
|
722
540
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
723
541
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
@@ -726,16 +544,41 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
726
544
|
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
727
545
|
toolMeta.securitySchemes = securitySchemes;
|
|
728
546
|
}
|
|
547
|
+
if (openai) {
|
|
548
|
+
if (!view) {
|
|
549
|
+
throw new Error(`skybridge: tool "${name}" sets \`openai\` options but has no \`view\`.`);
|
|
550
|
+
}
|
|
551
|
+
const opensWithoutInput = openai.entrypoints?.some(({ type }) => type === "global" || type === "thread");
|
|
552
|
+
if (opensWithoutInput && !acceptsEmptyInput(toolFields.inputSchema)) {
|
|
553
|
+
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.`);
|
|
554
|
+
}
|
|
555
|
+
const openaiUi = definedEntries({
|
|
556
|
+
entrypoints: openai.entrypoints,
|
|
557
|
+
preferredModelDisplayMode: openai.preferredModelDisplayMode,
|
|
558
|
+
});
|
|
559
|
+
if (Object.keys(openaiUi).length > 0) {
|
|
560
|
+
toolMeta["openai/ui"] = {
|
|
561
|
+
...userToolMeta?.["openai/ui"],
|
|
562
|
+
...openaiUi,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
}
|
|
729
566
|
if (view) {
|
|
730
567
|
this.enforceOneToolPerView(view.component, name);
|
|
731
|
-
this.registerViewResources(name, view, toolMeta
|
|
568
|
+
this.registerViewResources(name, view, toolMeta, openai &&
|
|
569
|
+
definedEntries({
|
|
570
|
+
availableDisplayModes: openai.availableDisplayModes,
|
|
571
|
+
preferredDisplayMode: openai.preferredDisplayMode,
|
|
572
|
+
}));
|
|
732
573
|
}
|
|
733
574
|
const wrappedCb = this.decorateToolHandler(cb, {
|
|
734
575
|
attachViewUUID: Boolean(view),
|
|
735
576
|
securitySchemes,
|
|
736
577
|
toolName: name,
|
|
737
578
|
});
|
|
738
|
-
baseFn.call(this, name, { ...toolFields, _meta: toolMeta },
|
|
579
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, toolFields.inputSchema === undefined
|
|
580
|
+
? (extra) => wrappedCb({}, extra)
|
|
581
|
+
: wrappedCb);
|
|
739
582
|
return this;
|
|
740
583
|
}
|
|
741
584
|
}
|