skybridge 0.0.0-dev.e112094 → 0.0.0-dev.e11ecfc
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 -124
- package/dist/cli/build-helpers.d.ts +3 -0
- package/dist/cli/build-helpers.js +23 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +36 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- 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.d.ts +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.d.ts +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.js.map +1 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.js.map +1 -1
- package/dist/cli/use-nodemon.js +11 -2
- 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 +1 -1
- package/dist/cli/use-tunnel.js +102 -68
- package/dist/cli/use-tunnel.js.map +1 -1
- 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 +43 -17
- 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 +1 -0
- package/dist/commands/dev.js +49 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- 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 +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +17 -2
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +80 -1
- 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/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +16 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/content-helpers.test.js.map +1 -1
- package/dist/server/express.d.ts +1 -5
- package/dist/server/express.js +31 -7
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +210 -69
- 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 +4 -2
- package/dist/server/index.js +3 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/server.d.ts +213 -7
- package/dist/server/server.js +236 -77
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +0 -2
- 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.js.map +1 -1
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +45 -0
- package/dist/test/view.test.js.map +1 -1
- package/dist/version.js +1 -3
- package/dist/version.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +6 -2
- package/dist/web/bridges/apps-sdk/adaptor.js +23 -3
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
- 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.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +8 -1
- 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 +6 -2
- package/dist/web/bridges/mcp-app/adaptor.js +18 -6
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.js +1 -0
- 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 +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- 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.map +1 -1
- package/dist/web/bridges/types.d.ts +65 -3
- 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.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +33 -0
- package/dist/web/data-llm.js +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- 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.js.map +1 -1
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +3 -0
- package/dist/web/hooks/index.js +3 -0
- 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 +13 -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 +20 -0
- 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.js.map +1 -1
- 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 +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- 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.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- 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 +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -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.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.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +21 -0
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +19 -0
- package/dist/web/mount-view.js +19 -0
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +28 -0
- package/dist/web/plugin/plugin.js +63 -15
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +8 -0
- package/dist/web/plugin/scan-views.js +26 -8
- package/dist/web/plugin/scan-views.js.map +1 -1
- package/dist/web/plugin/scan-views.test.js +33 -1
- package/dist/web/plugin/scan-views.test.js.map +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.js.map +1 -1
- package/dist/web/plugin/validate-view.test.js.map +1 -1
- 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 +13 -7
- package/dist/server/templates/development.hbs +0 -12
- package/dist/server/templates/production.hbs +0 -6
package/dist/server/server.d.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
+
import type { McpUiToolMeta } from "@modelcontextprotocol/ext-apps";
|
|
1
2
|
import { type ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
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 { ContentBlock, Implementation, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
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";
|
|
7
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
|
+
*/
|
|
8
16
|
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
9
17
|
input: TInput;
|
|
10
18
|
output: TOutput;
|
|
11
19
|
responseMetadata: TResponseMetadata;
|
|
12
20
|
};
|
|
21
|
+
/** Which host runtime a view targets — `"apps-sdk"` (ChatGPT) or `"mcp-app"` (MCP Apps spec). */
|
|
13
22
|
export type ViewHostType = "apps-sdk" | "mcp-app";
|
|
23
|
+
/**
|
|
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.
|
|
27
|
+
*/
|
|
14
28
|
export interface ViewCsp {
|
|
15
29
|
/** Origins for static assets (images, fonts, scripts, styles). */
|
|
16
30
|
resourceDomains?: string[];
|
|
@@ -23,24 +37,67 @@ export interface ViewCsp {
|
|
|
23
37
|
/** Origins allowed in `<base href>` tags (mcp-apps only). */
|
|
24
38
|
baseUriDomains?: string[];
|
|
25
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
|
+
*/
|
|
26
45
|
export interface ViewNameRegistry {
|
|
27
46
|
}
|
|
28
|
-
|
|
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
|
+
*/
|
|
29
53
|
export interface ViewConfig {
|
|
54
|
+
/** Filename of the view module (without extension) — matches a file in your `viewsDir`. */
|
|
30
55
|
component: ViewName;
|
|
56
|
+
/** Human-readable label the host may show alongside the view. */
|
|
31
57
|
description?: string;
|
|
58
|
+
/** Restrict where the view is rendered. Defaults to all known hosts. */
|
|
32
59
|
hosts?: ViewHostType[];
|
|
60
|
+
/** Apps SDK only: request a visible border around the widget. */
|
|
33
61
|
prefersBorder?: boolean;
|
|
62
|
+
/** Apps SDK only: override the iframe's served domain (advanced). */
|
|
34
63
|
domain?: string;
|
|
64
|
+
/** Per-view CSP overrides — see {@link ViewCsp}. */
|
|
35
65
|
csp?: ViewCsp;
|
|
66
|
+
/** Free-form metadata forwarded on the view resource's `_meta`. */
|
|
36
67
|
_meta?: Record<string, unknown>;
|
|
37
68
|
}
|
|
69
|
+
export type SecurityScheme = {
|
|
70
|
+
type: "noauth";
|
|
71
|
+
} | {
|
|
72
|
+
type: "oauth2";
|
|
73
|
+
scopes?: string[];
|
|
74
|
+
};
|
|
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
|
+
*/
|
|
38
81
|
export interface KnownToolMeta {
|
|
82
|
+
/** Apps SDK: allow the rendered view to call this tool from inside its iframe. */
|
|
39
83
|
"openai/widgetAccessible"?: boolean;
|
|
84
|
+
/** Apps SDK: status text shown while the tool is running (e.g. `"Searching trips"`). */
|
|
40
85
|
"openai/toolInvocation/invoking"?: string;
|
|
86
|
+
/** Apps SDK: status text shown once the tool returns (e.g. `"Found 3 trips"`). */
|
|
41
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[];
|
|
42
93
|
}
|
|
94
|
+
/** {@link KnownToolMeta} merged with arbitrary string-keyed metadata for custom flags. */
|
|
43
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
|
+
*/
|
|
44
101
|
export type HandlerContent = string | ContentBlock | ContentBlock[];
|
|
45
102
|
/**
|
|
46
103
|
* Type-level marker interface for cross-package type inference.
|
|
@@ -84,30 +141,120 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
|
|
|
84
141
|
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
85
142
|
annotations?: ToolAnnotations;
|
|
86
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[];
|
|
87
152
|
_meta?: ToolMeta;
|
|
88
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;
|
|
185
|
+
};
|
|
89
186
|
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
90
187
|
content?: HandlerContent;
|
|
91
188
|
} = {
|
|
92
189
|
content?: HandlerContent;
|
|
93
|
-
}> = (args: ShapeOutput<TInput>, extra:
|
|
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
|
+
*/
|
|
94
197
|
export declare function normalizeContent(content: HandlerContent | undefined): ContentBlock[];
|
|
95
198
|
interface McpServerBaseOmitted extends Omit<McpServerBase, "registerTool" | "connect"> {
|
|
96
199
|
}
|
|
97
200
|
declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof McpServerBase>) => McpServerBaseOmitted;
|
|
201
|
+
/**
|
|
202
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
203
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
204
|
+
* user-facing API.
|
|
205
|
+
*
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
export declare function __setBuildManifest(manifest: Record<string, {
|
|
209
|
+
file: string;
|
|
210
|
+
}>): void;
|
|
98
211
|
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
|
|
99
212
|
readonly $types: McpServerTypes<TTools>;
|
|
100
|
-
|
|
101
|
-
|
|
213
|
+
/**
|
|
214
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
215
|
+
* custom routes, middleware, or settings — e.g.
|
|
216
|
+
* `server.express.get("/health", ...)`.
|
|
217
|
+
*
|
|
218
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
219
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
220
|
+
* error handler are appended in that order.
|
|
221
|
+
*
|
|
222
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
223
|
+
* locally and on self-hosted deployments.
|
|
224
|
+
*/
|
|
225
|
+
readonly express: Express;
|
|
102
226
|
private customErrorMiddleware;
|
|
103
227
|
private mcpMiddlewareEntries;
|
|
104
228
|
private mcpMiddlewareApplied;
|
|
105
229
|
private claimedViews;
|
|
230
|
+
private viewMetaBuilders;
|
|
231
|
+
private viteManifest;
|
|
106
232
|
private readonly serverInfo;
|
|
107
233
|
private readonly serverOptions?;
|
|
108
234
|
constructor(serverInfo: Implementation, options?: ServerOptions);
|
|
235
|
+
/**
|
|
236
|
+
* Register Express middleware on the underlying app. Mirrors `app.use` —
|
|
237
|
+
* pass handlers directly or a path-prefixed handler list. Register before
|
|
238
|
+
* {@link McpServer.run}; ordering matches Express.
|
|
239
|
+
*
|
|
240
|
+
* Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work
|
|
241
|
+
* locally and on self-hosted deployments.
|
|
242
|
+
*/
|
|
109
243
|
use(...handlers: RequestHandler[]): this;
|
|
110
244
|
use(path: string, ...handlers: RequestHandler[]): this;
|
|
245
|
+
/**
|
|
246
|
+
* Register Express error-handling middleware to run after the built-in
|
|
247
|
+
* `/mcp` route (or your custom route). Use this to log or transform errors
|
|
248
|
+
* thrown by tool handlers before the default error handler responds.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* server.useOnError((err, _req, _res, next) => {
|
|
253
|
+
* logger.error(err);
|
|
254
|
+
* next(err);
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
111
258
|
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
112
259
|
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
113
260
|
/** Register MCP protocol-level middleware (catch-all). */
|
|
@@ -142,6 +289,14 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
142
289
|
*/
|
|
143
290
|
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
144
291
|
private applyMcpMiddleware;
|
|
292
|
+
/**
|
|
293
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
294
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
295
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
296
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
297
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
298
|
+
* throw afterwards.
|
|
299
|
+
*/
|
|
145
300
|
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
146
301
|
/**
|
|
147
302
|
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
@@ -154,15 +309,66 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
154
309
|
* read side and fails fast on SDK field renames.
|
|
155
310
|
*/
|
|
156
311
|
connectStatelessTransport(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
157
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
314
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
315
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
316
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
317
|
+
*
|
|
318
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
319
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
320
|
+
* Node, returns `undefined` once listening.
|
|
321
|
+
*/
|
|
322
|
+
run(): Promise<{
|
|
323
|
+
fetch: (...args: unknown[]) => unknown;
|
|
324
|
+
} | undefined>;
|
|
158
325
|
private enforceOneToolPerView;
|
|
326
|
+
private resolveViewRequestContext;
|
|
159
327
|
private registerViewResources;
|
|
160
328
|
private registerViewResource;
|
|
161
329
|
private wrapHandler;
|
|
162
330
|
private computeViewVersionParam;
|
|
163
331
|
private lookupViewFile;
|
|
164
332
|
private lookupDistFile;
|
|
333
|
+
/**
|
|
334
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
335
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
336
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
337
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
338
|
+
*/
|
|
339
|
+
setViteManifest(manifest: Record<string, {
|
|
340
|
+
file: string;
|
|
341
|
+
}>): this;
|
|
165
342
|
private readManifest;
|
|
343
|
+
/**
|
|
344
|
+
* Register a tool. Pass a `config` describing the tool (name, schemas,
|
|
345
|
+
* optional {@link ViewConfig}, optional {@link ToolMeta}) and a handler that
|
|
346
|
+
* returns the tool's result.
|
|
347
|
+
*
|
|
348
|
+
* Chain calls to build up a server: each call returns a new `McpServer`
|
|
349
|
+
* type that captures the tool's input/output/`_meta` shape so the
|
|
350
|
+
* resulting `typeof server` can drive {@link generateHelpers}.
|
|
351
|
+
*
|
|
352
|
+
* The handler's return shape determines the output types: the
|
|
353
|
+
* `structuredContent` field becomes the tool's typed output, and `_meta`
|
|
354
|
+
* becomes its `responseMetadata`. The `content` field is normalized through
|
|
355
|
+
* {@link normalizeContent}.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* server.registerTool({
|
|
360
|
+
* name: "search",
|
|
361
|
+
* inputSchema: { query: z.string() },
|
|
362
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
363
|
+
* view: { component: "search" },
|
|
364
|
+
* }, async ({ query }) => ({
|
|
365
|
+
* content: `Found results for ${query}`,
|
|
366
|
+
* structuredContent: { results: [...] },
|
|
367
|
+
* }));
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @see https://docs.skybridge.tech/api-reference/register-tool
|
|
371
|
+
*/
|
|
166
372
|
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
167
373
|
content?: HandlerContent;
|
|
168
374
|
}>(config: ToolConfig<InputArgs> & {
|