skybridge 0.0.0-dev.fec1c58 → 0.0.0-dev.fef24cf
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 +123 -116
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.js +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/tunnel-control-server.d.ts +9 -0
- package/dist/cli/tunnel-control-server.js +31 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.js +105 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel.d.ts +57 -0
- package/dist/cli/tunnel.js +154 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.d.ts +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +2 -6
- package/dist/cli/use-nodemon.js +18 -14
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +1 -0
- package/dist/cli/use-typescript-check.js +42 -7
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.js +63 -7
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +4 -1
- package/dist/commands/dev.js +57 -8
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +30 -9
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +6 -6
- package/dist/server/asset-base-url-transform-plugin.js +25 -11
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth.d.ts +20 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/content-helpers.d.ts +67 -0
- package/dist/server/content-helpers.js +79 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +7 -5
- package/dist/server/express.js +60 -28
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +381 -25
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/index.d.ts +7 -3
- package/dist/server/index.js +5 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +137 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +358 -69
- package/dist/server/server.js +469 -102
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +5 -8
- package/dist/server/templateHelper.js +3 -22
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.d.ts +4 -0
- package/dist/server/templates.generated.js +47 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tunnel-proxy-router.d.ts +7 -0
- package/dist/server/tunnel-proxy-router.js +110 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -0
- package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +16 -244
- package/dist/test/utils.js +42 -37
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +568 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +13 -7
- package/dist/web/bridges/apps-sdk/adaptor.js +62 -29
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +2 -1
- package/dist/web/bridges/apps-sdk/bridge.js +1 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +26 -11
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +7 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +25 -9
- package/dist/web/bridges/mcp-app/adaptor.js +156 -66
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +14 -30
- package/dist/web/bridges/mcp-app/bridge.js +44 -196
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +17 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
- 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 -41
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +87 -14
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.js +3 -5
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +43 -3
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +21 -18
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +34 -1
- package/dist/web/data-llm.js +31 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +24 -23
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -18
- package/dist/web/generate-helpers.js +22 -18
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +26 -26
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +11 -11
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +5 -2
- package/dist/web/hooks/index.js +4 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +6 -2
- package/dist/web/hooks/test/utils.js +17 -2
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +27 -6
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +23 -3
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +5 -0
- package/dist/web/hooks/use-download.js +8 -0
- package/dist/web/hooks/use-download.js.map +1 -0
- package/dist/web/hooks/use-download.test.d.ts +1 -0
- package/dist/web/hooks/use-download.test.js +95 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +34 -1
- package/dist/web/hooks/use-files.js +33 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +22 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.d.ts +2 -0
- package/dist/web/hooks/use-layout.js +2 -0
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +3 -3
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +20 -1
- package/dist/web/hooks/use-open-external.js +17 -1
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +26 -11
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +52 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +19 -4
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +5 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +20 -0
- package/dist/web/hooks/use-request-size.js +24 -0
- package/dist/web/hooks/use-request-size.js.map +1 -0
- package/dist/web/hooks/use-request-size.test.d.ts +1 -0
- package/dist/web/hooks/use-request-size.test.js +65 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
- package/dist/web/hooks/use-send-follow-up-message.js +19 -2
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +5 -11
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +33 -0
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +1 -1
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +20 -2
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +29 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +25 -0
- package/dist/web/hooks/use-view-state.js +32 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +177 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -2
- package/dist/web/index.js +1 -2
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +20 -0
- package/dist/web/{mount-widget.js → mount-view.js} +21 -2
- package/dist/web/mount-view.js.map +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +32 -1
- package/dist/web/plugin/plugin.js +161 -18
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +16 -0
- package/dist/web/plugin/scan-views.js +88 -0
- package/dist/web/plugin/scan-views.js.map +1 -0
- package/dist/web/plugin/scan-views.test.d.ts +1 -0
- package/dist/web/plugin/scan-views.test.js +99 -0
- package/dist/web/plugin/scan-views.test.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.js +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
- package/dist/web/plugin/validate-view.d.ts +1 -0
- package/dist/web/plugin/validate-view.js +9 -0
- package/dist/web/plugin/validate-view.js.map +1 -0
- package/dist/web/plugin/validate-view.test.d.ts +1 -0
- package/dist/web/plugin/validate-view.test.js +24 -0
- package/dist/web/plugin/validate-view.test.js.map +1 -0
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +42 -25
- package/tsconfig.base.json +33 -0
- package/dist/server/templates/development.hbs +0 -67
- package/dist/server/templates/production.hbs +0 -6
- package/dist/server/widgetsDevServer.d.ts +0 -12
- package/dist/server/widgetsDevServer.js +0 -57
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -261
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/web/hooks/use-widget-state.js +0 -32
- package/dist/web/hooks/use-widget-state.js.map +0 -1
- package/dist/web/hooks/use-widget-state.test.js +0 -62
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
package/dist/server/server.d.ts
CHANGED
|
@@ -1,44 +1,125 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { McpUiToolMeta } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { type ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
4
5
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
|
-
import type {
|
|
6
|
-
import type
|
|
6
|
+
import type { ContentBlock, Implementation, RequestMeta, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
7
|
+
import { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
|
|
8
|
+
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
9
|
+
/**
|
|
10
|
+
* Type marker for a registered tool — carries its input, output, and response
|
|
11
|
+
* metadata shapes so views can infer types from `typeof server`.
|
|
12
|
+
*
|
|
13
|
+
* You normally never construct this by hand; it is produced by `registerTool`
|
|
14
|
+
* and consumed by helpers like {@link InferTools} and {@link generateHelpers}.
|
|
15
|
+
*/
|
|
7
16
|
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
8
17
|
input: TInput;
|
|
9
18
|
output: TOutput;
|
|
10
19
|
responseMetadata: TResponseMetadata;
|
|
11
20
|
};
|
|
21
|
+
/** Which host runtime a view targets — `"apps-sdk"` (ChatGPT) or `"mcp-app"` (MCP Apps spec). */
|
|
22
|
+
export type ViewHostType = "apps-sdk" | "mcp-app";
|
|
12
23
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
24
|
+
* Content Security Policy origins attached to a view's resource. Each list is
|
|
25
|
+
* passed through to the host's CSP for the view iframe; omit a field to inherit
|
|
26
|
+
* the host's default for that directive.
|
|
16
27
|
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
export interface ViewCsp {
|
|
29
|
+
/** Origins for static assets (images, fonts, scripts, styles). */
|
|
30
|
+
resourceDomains?: string[];
|
|
31
|
+
/** Origins the view may contact via fetch/XHR. */
|
|
32
|
+
connectDomains?: string[];
|
|
33
|
+
/** Origins allowed for iframe embeds (opts into stricter app review). */
|
|
34
|
+
frameDomains?: string[];
|
|
35
|
+
/** Origins that can receive openExternal redirects without the safe-link modal. */
|
|
22
36
|
redirectDomains?: string[];
|
|
37
|
+
/** Origins allowed in `<base href>` tags (mcp-apps only). */
|
|
38
|
+
baseUriDomains?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Registry of view component names. The Skybridge Vite plugin augments this
|
|
42
|
+
* interface in the generated `.skybridge/views.d.ts` with one key per view
|
|
43
|
+
* file, which narrows {@link ViewName} from `string` to the concrete union.
|
|
44
|
+
*/
|
|
45
|
+
export interface ViewNameRegistry {
|
|
46
|
+
}
|
|
47
|
+
/** Union of valid view component names. Narrowed by {@link ViewNameRegistry}. */
|
|
48
|
+
export type ViewName = keyof ViewNameRegistry & string;
|
|
49
|
+
/**
|
|
50
|
+
* Pass under `view` in a tool's `registerTool` config to render the tool's
|
|
51
|
+
* result through a Skybridge view instead of a plain text response.
|
|
52
|
+
*/
|
|
53
|
+
export interface ViewConfig {
|
|
54
|
+
/** Filename of the view module (without extension) — matches a file in your `viewsDir`. */
|
|
55
|
+
component: ViewName;
|
|
56
|
+
/** Human-readable label the host may show alongside the view. */
|
|
57
|
+
description?: string;
|
|
58
|
+
/** Restrict where the view is rendered. Defaults to all known hosts. */
|
|
59
|
+
hosts?: ViewHostType[];
|
|
60
|
+
/** Apps SDK only: request a visible border around the widget. */
|
|
61
|
+
prefersBorder?: boolean;
|
|
62
|
+
/** Apps SDK only: override the iframe's served domain (advanced). */
|
|
63
|
+
domain?: string;
|
|
64
|
+
/** Per-view CSP overrides — see {@link ViewCsp}. */
|
|
65
|
+
csp?: ViewCsp;
|
|
66
|
+
/** Free-form metadata forwarded on the view resource's `_meta`. */
|
|
67
|
+
_meta?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
export type SecurityScheme = {
|
|
70
|
+
type: "noauth";
|
|
71
|
+
} | {
|
|
72
|
+
type: "oauth2";
|
|
73
|
+
scopes?: string[];
|
|
23
74
|
};
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Well-known keys recognized by host runtimes when set on a tool's `_meta`.
|
|
77
|
+
* Use {@link ToolMeta} to also pass arbitrary custom metadata alongside these.
|
|
78
|
+
*
|
|
79
|
+
* @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters
|
|
80
|
+
*/
|
|
81
|
+
export interface KnownToolMeta {
|
|
82
|
+
/** Apps SDK: allow the rendered view to call this tool from inside its iframe. */
|
|
83
|
+
"openai/widgetAccessible"?: boolean;
|
|
84
|
+
/** Apps SDK: status text shown while the tool is running (e.g. `"Searching trips"`). */
|
|
85
|
+
"openai/toolInvocation/invoking"?: string;
|
|
86
|
+
/** Apps SDK: status text shown once the tool returns (e.g. `"Found 3 trips"`). */
|
|
87
|
+
"openai/toolInvocation/invoked"?: string;
|
|
88
|
+
/** Apps SDK: input parameters that hold file references — the host attaches uploaded files to them. */
|
|
89
|
+
"openai/fileParams"?: string[];
|
|
90
|
+
/** MCP Apps: control whether the tool is exposed to the model, the app, or both. */
|
|
91
|
+
ui?: Pick<McpUiToolMeta, "visibility">;
|
|
92
|
+
securitySchemes?: SecurityScheme[];
|
|
93
|
+
}
|
|
94
|
+
/** {@link KnownToolMeta} merged with arbitrary string-keyed metadata for custom flags. */
|
|
95
|
+
export type ToolMeta = KnownToolMeta & Record<string, unknown>;
|
|
96
|
+
/**
|
|
97
|
+
* Convenient return type for tool handlers — a plain string, a single
|
|
98
|
+
* {@link ContentBlock}, or an array. Skybridge normalizes it to the MCP
|
|
99
|
+
* `content: ContentBlock[]` shape before responding.
|
|
100
|
+
*/
|
|
101
|
+
export type HandlerContent = string | ContentBlock | ContentBlock[];
|
|
102
|
+
/**
|
|
103
|
+
* Type-level marker interface for cross-package type inference.
|
|
104
|
+
*
|
|
105
|
+
* Consumers infer tool types via the structural `$types` property rather than
|
|
106
|
+
* the `McpServer` class generic, because class-generic inference breaks when
|
|
107
|
+
* `McpServer` comes from different package installations (e.g. a consumer
|
|
108
|
+
* with its own `skybridge` dep vs. the in-tree workspace version).
|
|
109
|
+
*
|
|
110
|
+
* Inspired by tRPC's `_def` pattern and Hono's type markers.
|
|
111
|
+
*/
|
|
112
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
113
|
+
readonly tools: TTools;
|
|
114
|
+
}
|
|
39
115
|
type Simplify<T> = {
|
|
40
116
|
[K in keyof T]: T[K];
|
|
41
117
|
};
|
|
118
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
119
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
120
|
+
} & {
|
|
121
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
122
|
+
}>;
|
|
42
123
|
type ExtractStructuredContent<T> = T extends {
|
|
43
124
|
structuredContent: infer SC;
|
|
44
125
|
} ? Simplify<SC> : never;
|
|
@@ -49,61 +130,269 @@ type ExtractMeta<T> = [Extract<T, {
|
|
|
49
130
|
}> extends {
|
|
50
131
|
_meta: infer M;
|
|
51
132
|
} ? Simplify<M> : unknown;
|
|
52
|
-
/**
|
|
53
|
-
* Type-level marker interface for cross-package type inference.
|
|
54
|
-
* This enables TypeScript to infer tool types across package boundaries
|
|
55
|
-
* using structural typing on the $types property, rather than relying on
|
|
56
|
-
* class generic inference which fails when McpServer comes from different
|
|
57
|
-
* package installations.
|
|
58
|
-
*
|
|
59
|
-
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
60
|
-
*/
|
|
61
|
-
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
62
|
-
readonly tools: TTools;
|
|
63
|
-
}
|
|
64
|
-
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
65
|
-
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
66
|
-
} & {
|
|
67
|
-
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
68
|
-
}>;
|
|
69
133
|
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
70
134
|
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
run(): Promise<void>;
|
|
75
|
-
};
|
|
76
|
-
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
135
|
+
}>;
|
|
136
|
+
interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
|
|
137
|
+
name: string;
|
|
77
138
|
title?: string;
|
|
78
139
|
description?: string;
|
|
79
140
|
inputSchema?: TInput;
|
|
80
141
|
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
81
142
|
annotations?: ToolAnnotations;
|
|
82
|
-
|
|
143
|
+
view?: ViewConfig;
|
|
144
|
+
/**
|
|
145
|
+
* Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
|
|
146
|
+
* Lets clients label tools that require sign-in before calling, and pass
|
|
147
|
+
* the right scopes through the OAuth flow. Listing both `noauth` and
|
|
148
|
+
* `oauth2` signals that the tool works for anonymous callers and gives
|
|
149
|
+
* enhanced behavior to authenticated ones.
|
|
150
|
+
*/
|
|
151
|
+
securitySchemes?: SecurityScheme[];
|
|
152
|
+
_meta?: ToolMeta;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Optional client-supplied hints attached to `params._meta` on every tool call
|
|
156
|
+
* by the Apps SDK host. Hints only: never use for authorization, and tolerate
|
|
157
|
+
* absence.
|
|
158
|
+
* @see https://developers.openai.com/apps-sdk/reference#_meta-fields-the-client-provides
|
|
159
|
+
*/
|
|
160
|
+
export interface ClientHintsMeta {
|
|
161
|
+
/** Requested locale (BCP-47, e.g. `"en-US"`). */
|
|
162
|
+
"openai/locale"?: string;
|
|
163
|
+
/** Browser user-agent */
|
|
164
|
+
"openai/userAgent"?: string;
|
|
165
|
+
/** Coarse user location. May be partially populated. */
|
|
166
|
+
"openai/userLocation"?: {
|
|
167
|
+
city?: string;
|
|
168
|
+
region?: string;
|
|
169
|
+
country?: string;
|
|
170
|
+
timezone?: string;
|
|
171
|
+
longitude?: number;
|
|
172
|
+
latitude?: number;
|
|
173
|
+
};
|
|
174
|
+
/** Anonymized user id. */
|
|
175
|
+
"openai/subject"?: string;
|
|
176
|
+
/** Anonymized conversation id, stable within a ChatGPT session. */
|
|
177
|
+
"openai/session"?: string;
|
|
178
|
+
/** Anonymized organization id, when the user account is part of an organization. */
|
|
179
|
+
"openai/organization"?: string;
|
|
180
|
+
/** Stable id for the currently mounted widget instance. */
|
|
181
|
+
"openai/widgetSessionId"?: string;
|
|
182
|
+
}
|
|
183
|
+
type ToolHandlerExtra = Omit<RequestHandlerExtra<ServerRequest, ServerNotification>, "_meta"> & {
|
|
184
|
+
_meta?: RequestMeta & ClientHintsMeta;
|
|
83
185
|
};
|
|
84
186
|
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
85
|
-
content
|
|
86
|
-
} =
|
|
87
|
-
|
|
187
|
+
content?: HandlerContent;
|
|
188
|
+
} = {
|
|
189
|
+
content?: HandlerContent;
|
|
190
|
+
}> = (args: ShapeOutput<TInput>, extra: ToolHandlerExtra) => TReturn | Promise<TReturn>;
|
|
191
|
+
/**
|
|
192
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
193
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
194
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
195
|
+
* who build content lazily can apply the same normalization.
|
|
196
|
+
*/
|
|
197
|
+
export declare function normalizeContent(content: HandlerContent | undefined): ContentBlock[];
|
|
198
|
+
interface McpServerBaseOmitted extends Omit<McpServerBase, "registerTool" | "connect"> {
|
|
199
|
+
}
|
|
200
|
+
declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof McpServerBase>) => McpServerBaseOmitted;
|
|
201
|
+
/**
|
|
202
|
+
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
203
|
+
* registry, view resources, an embedded Express app, and protocol-level
|
|
204
|
+
* middleware. Construct it with the same `Implementation` info you would pass
|
|
205
|
+
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
206
|
+
* then call {@link McpServer.run} to start the HTTP server.
|
|
207
|
+
*
|
|
208
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
209
|
+
* shape, so `typeof server` carries enough information for view-side helpers
|
|
210
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
211
|
+
*
|
|
212
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
213
|
+
* chaining; you almost never set this manually.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
218
|
+
* .registerTool({
|
|
219
|
+
* name: "search",
|
|
220
|
+
* inputSchema: { query: z.string() },
|
|
221
|
+
* view: { component: "search" },
|
|
222
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
223
|
+
*
|
|
224
|
+
* await server.run();
|
|
225
|
+
* export type AppType = typeof server;
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
229
|
+
*/
|
|
230
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
|
|
88
231
|
readonly $types: McpServerTypes<TTools>;
|
|
89
|
-
|
|
90
|
-
|
|
232
|
+
/**
|
|
233
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
234
|
+
* custom routes, middleware, or settings — e.g.
|
|
235
|
+
* `server.express.get("/health", ...)`.
|
|
236
|
+
*
|
|
237
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
238
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
239
|
+
* error handler are appended in that order.
|
|
240
|
+
*
|
|
241
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
242
|
+
* locally and on self-hosted deployments.
|
|
243
|
+
*/
|
|
244
|
+
readonly express: Express;
|
|
245
|
+
private customErrorMiddleware;
|
|
246
|
+
private mcpMiddlewareEntries;
|
|
247
|
+
private mcpMiddlewareApplied;
|
|
248
|
+
private claimedViews;
|
|
249
|
+
private viewMetaBuilders;
|
|
250
|
+
private viteManifest;
|
|
251
|
+
private readonly serverInfo;
|
|
252
|
+
private readonly serverOptions?;
|
|
253
|
+
constructor(serverInfo: Implementation, options?: ServerOptions);
|
|
254
|
+
/**
|
|
255
|
+
* Register Express middleware on the underlying app. Mirrors `app.use` —
|
|
256
|
+
* pass handlers directly or a path-prefixed handler list. Register before
|
|
257
|
+
* {@link McpServer.run}; ordering matches Express.
|
|
258
|
+
*
|
|
259
|
+
* Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work
|
|
260
|
+
* locally and on self-hosted deployments.
|
|
261
|
+
*/
|
|
91
262
|
use(...handlers: RequestHandler[]): this;
|
|
92
263
|
use(path: string, ...handlers: RequestHandler[]): this;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Register Express error-handling middleware to run after the built-in
|
|
266
|
+
* `/mcp` route (or your custom route). Use this to log or transform errors
|
|
267
|
+
* thrown by tool handlers before the default error handler responds.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* server.useOnError((err, _req, _res, next) => {
|
|
272
|
+
* logger.error(err);
|
|
273
|
+
* next(err);
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
278
|
+
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
279
|
+
/** Register MCP protocol-level middleware (catch-all). */
|
|
280
|
+
mcpMiddleware(handler: McpMiddlewareFn): this;
|
|
281
|
+
/** Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`). */
|
|
282
|
+
mcpMiddleware(filter: "request", handler: (request: {
|
|
283
|
+
method: string;
|
|
284
|
+
params: Record<string, unknown>;
|
|
285
|
+
}, extra: McpExtra, next: () => Promise<ServerResult>) => Promise<unknown> | unknown): this;
|
|
286
|
+
/** Register MCP protocol-level middleware for all notifications (`extra` is `undefined`). */
|
|
287
|
+
mcpMiddleware(filter: "notification", handler: (request: {
|
|
288
|
+
method: string;
|
|
289
|
+
params: Record<string, unknown>;
|
|
290
|
+
}, extra: undefined, next: () => Promise<undefined>) => Promise<unknown> | unknown): this;
|
|
291
|
+
/**
|
|
292
|
+
* Register MCP protocol-level middleware for an exact method.
|
|
293
|
+
* Narrows `params`, `extra`, and `next()` result based on the method string.
|
|
294
|
+
*/
|
|
295
|
+
mcpMiddleware<M extends McpMethodString>(filter: M, handler: McpTypedMiddlewareFn<M>): this;
|
|
296
|
+
/**
|
|
297
|
+
* Register MCP protocol-level middleware for a wildcard pattern (e.g. `"tools/*"`).
|
|
298
|
+
* `next()` returns the union of result types for matching methods.
|
|
299
|
+
*/
|
|
300
|
+
mcpMiddleware<W extends McpWildcard>(filter: W, handler: (request: {
|
|
301
|
+
method: string;
|
|
302
|
+
params: Record<string, unknown>;
|
|
303
|
+
}, extra: McpExtraFor<W>, next: () => Promise<McpResultFor<W>>) => Promise<unknown> | unknown): this;
|
|
304
|
+
/**
|
|
305
|
+
* Register MCP protocol-level middleware with a method filter.
|
|
306
|
+
* Filter can be an exact method (`"tools/call"`), wildcard (`"tools/*"`),
|
|
307
|
+
* category (`"request"` | `"notification"`), or an array of those.
|
|
308
|
+
*/
|
|
309
|
+
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
310
|
+
private applyMcpMiddleware;
|
|
311
|
+
/**
|
|
312
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
313
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
314
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
315
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
316
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
317
|
+
* throw afterwards.
|
|
318
|
+
*/
|
|
319
|
+
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
322
|
+
* transport per instance, so we can't reuse this `McpServer` across
|
|
323
|
+
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
324
|
+
* factory, but that would break Skybridge's singleton API — so instead
|
|
325
|
+
* we build a fresh underlying `Server` per request and share the main
|
|
326
|
+
* server's handler maps by reference. The cast is unavoidable: there's
|
|
327
|
+
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
328
|
+
* read side and fails fast on SDK field renames.
|
|
329
|
+
*/
|
|
330
|
+
connectStatelessTransport(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
333
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
334
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
335
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
336
|
+
*
|
|
337
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
338
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
339
|
+
* Node, returns `undefined` once listening.
|
|
340
|
+
*/
|
|
341
|
+
run(): Promise<{
|
|
342
|
+
fetch: (...args: unknown[]) => unknown;
|
|
343
|
+
} | undefined>;
|
|
344
|
+
private enforceOneToolPerView;
|
|
345
|
+
private resolveViewRequestContext;
|
|
346
|
+
private registerViewResources;
|
|
347
|
+
private registerViewResource;
|
|
348
|
+
private wrapHandler;
|
|
349
|
+
private computeViewVersionParam;
|
|
350
|
+
private lookupViewFile;
|
|
105
351
|
private lookupDistFile;
|
|
106
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
354
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
355
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
356
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
357
|
+
*/
|
|
358
|
+
setViteManifest(manifest: Record<string, {
|
|
359
|
+
file: string;
|
|
360
|
+
}>): this;
|
|
107
361
|
private readManifest;
|
|
362
|
+
/**
|
|
363
|
+
* Register a tool. Pass a `config` describing the tool (name, schemas,
|
|
364
|
+
* optional {@link ViewConfig}, optional {@link ToolMeta}) and a handler that
|
|
365
|
+
* returns the tool's result.
|
|
366
|
+
*
|
|
367
|
+
* Chain calls to build up a server: each call returns a new `McpServer`
|
|
368
|
+
* type that captures the tool's input/output/`_meta` shape so the
|
|
369
|
+
* resulting `typeof server` can drive {@link generateHelpers}.
|
|
370
|
+
*
|
|
371
|
+
* The handler's return shape determines the output types: the
|
|
372
|
+
* `structuredContent` field becomes the tool's typed output, and `_meta`
|
|
373
|
+
* becomes its `responseMetadata`. The `content` field is normalized through
|
|
374
|
+
* {@link normalizeContent}.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts
|
|
378
|
+
* server.registerTool({
|
|
379
|
+
* name: "search",
|
|
380
|
+
* inputSchema: { query: z.string() },
|
|
381
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
382
|
+
* view: { component: "search" },
|
|
383
|
+
* }, async ({ query }) => ({
|
|
384
|
+
* content: `Found results for ${query}`,
|
|
385
|
+
* structuredContent: { results: [...] },
|
|
386
|
+
* }));
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* @see https://docs.skybridge.tech/api-reference/register-tool
|
|
390
|
+
*/
|
|
391
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
392
|
+
content?: HandlerContent;
|
|
393
|
+
}>(config: ToolConfig<InputArgs> & {
|
|
394
|
+
name: TName;
|
|
395
|
+
}, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
396
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): this;
|
|
108
397
|
}
|
|
109
398
|
export {};
|