skybridge 0.0.0-dev.f8d2f8c → 0.0.0-dev.f8ef758
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 +7 -0
- package/dist/cli/build-helpers.js +82 -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 +64 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.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/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +18 -30
- 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.js +16 -0
- 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/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +16 -1
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +11 -0
- package/dist/server/auth/discovery.js +51 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +18 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +13 -0
- package/dist/server/auth/providers/auth0.js +18 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +33 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +20 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +48 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +17 -0
- package/dist/server/auth/providers/custom.js +28 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +91 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +14 -0
- package/dist/server/auth/providers/descope.js +14 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +35 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +12 -0
- package/dist/server/auth/providers/stytch.js +17 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/stytch.test.d.ts +1 -0
- package/dist/server/auth/providers/stytch.test.js +33 -0
- package/dist/server/auth/providers/stytch.test.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +16 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/providers/workos.test.d.ts +1 -0
- package/dist/server/auth/providers/workos.test.js +41 -0
- package/dist/server/auth/providers/workos.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +100 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- 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 +27 -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/express.test.js +61 -0
- 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 +11 -2
- package/dist/server/index.js +9 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +213 -6
- package/dist/server/server.js +235 -62
- package/dist/server/server.js.map +1 -1
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +88 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/test/view.test.js +45 -0
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +6 -1
- package/dist/web/bridges/apps-sdk/adaptor.js +22 -1
- 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/types.d.ts +2 -0
- 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/mcp-app/adaptor.d.ts +6 -1
- package/dist/web/bridges/mcp-app/adaptor.js +20 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +4 -2
- package/dist/web/bridges/mcp-app/bridge.js +23 -1
- package/dist/web/bridges/mcp-app/bridge.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/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +94 -1
- 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/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/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/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 +4 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/hooks/index.d.ts +4 -0
- package/dist/web/hooks/index.js +4 -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.js +27 -2
- 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-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-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-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-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- 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-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 +17 -0
- package/dist/web/hooks/use-send-follow-up-message.js +17 -0
- 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-tool-info.d.ts +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +5 -5
- 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-view-state.d.ts +21 -0
- package/dist/web/hooks/use-view-state.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/plugin.d.ts +28 -0
- package/dist/web/plugin/plugin.js +33 -0
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +10 -3
package/dist/server/server.d.ts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
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 ErrorRequestHandler, type Express, type RequestHandler } from "express";
|
|
6
|
+
import type { ContentBlock, Implementation, RequestMeta, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
7
|
+
import express, { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
|
|
8
|
+
import type { OAuthConfig } from "./auth/index.js";
|
|
7
9
|
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
10
|
+
/**
|
|
11
|
+
* Type marker for a registered tool — carries its input, output, and response
|
|
12
|
+
* metadata shapes so views can infer types from `typeof server`.
|
|
13
|
+
*
|
|
14
|
+
* You normally never construct this by hand; it is produced by `registerTool`
|
|
15
|
+
* and consumed by helpers like {@link InferTools} and {@link generateHelpers}.
|
|
16
|
+
*/
|
|
8
17
|
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
9
18
|
input: TInput;
|
|
10
19
|
output: TOutput;
|
|
11
20
|
responseMetadata: TResponseMetadata;
|
|
12
21
|
};
|
|
22
|
+
/** Which host runtime a view targets — `"apps-sdk"` (ChatGPT) or `"mcp-app"` (MCP Apps spec). */
|
|
13
23
|
export type ViewHostType = "apps-sdk" | "mcp-app";
|
|
24
|
+
/**
|
|
25
|
+
* Content Security Policy origins attached to a view's resource. Each list is
|
|
26
|
+
* passed through to the host's CSP for the view iframe; omit a field to inherit
|
|
27
|
+
* the host's default for that directive.
|
|
28
|
+
*/
|
|
14
29
|
export interface ViewCsp {
|
|
15
30
|
/** Origins for static assets (images, fonts, scripts, styles). */
|
|
16
31
|
resourceDomains?: string[];
|
|
@@ -23,24 +38,79 @@ export interface ViewCsp {
|
|
|
23
38
|
/** Origins allowed in `<base href>` tags (mcp-apps only). */
|
|
24
39
|
baseUriDomains?: string[];
|
|
25
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Registry of view component names. The Skybridge Vite plugin augments this
|
|
43
|
+
* interface in the generated `.skybridge/views.d.ts` with one key per view
|
|
44
|
+
* file, which narrows {@link ViewName} from `string` to the concrete union.
|
|
45
|
+
*/
|
|
26
46
|
export interface ViewNameRegistry {
|
|
27
47
|
}
|
|
48
|
+
/** Union of valid view component names. Narrowed by {@link ViewNameRegistry}. */
|
|
28
49
|
export type ViewName = keyof ViewNameRegistry & string;
|
|
50
|
+
/**
|
|
51
|
+
* Pass under `view` in a tool's `registerTool` config to render the tool's
|
|
52
|
+
* result through a Skybridge view instead of a plain text response.
|
|
53
|
+
*/
|
|
29
54
|
export interface ViewConfig {
|
|
55
|
+
/** Filename of the view module (without extension) — matches a file in your `viewsDir`. */
|
|
30
56
|
component: ViewName;
|
|
57
|
+
/** Human-readable label the host may show alongside the view. */
|
|
31
58
|
description?: string;
|
|
59
|
+
/** Restrict where the view is rendered. Defaults to all known hosts. */
|
|
32
60
|
hosts?: ViewHostType[];
|
|
61
|
+
/** Apps SDK only: request a visible border around the widget. */
|
|
33
62
|
prefersBorder?: boolean;
|
|
63
|
+
/** Apps SDK only: override the iframe's served domain (advanced). */
|
|
34
64
|
domain?: string;
|
|
65
|
+
/** Per-view CSP overrides — see {@link ViewCsp}. */
|
|
35
66
|
csp?: ViewCsp;
|
|
67
|
+
/** Free-form metadata forwarded on the view resource's `_meta`. */
|
|
36
68
|
_meta?: Record<string, unknown>;
|
|
37
69
|
}
|
|
70
|
+
export type SecurityScheme = {
|
|
71
|
+
type: "noauth";
|
|
72
|
+
} | {
|
|
73
|
+
type: "oauth2";
|
|
74
|
+
scopes?: string[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Options forwarded to the built-in `express.json()` body parser. Derived
|
|
78
|
+
* from Express's own types so the public API doesn't depend on `body-parser`.
|
|
79
|
+
*/
|
|
80
|
+
export type JsonOptions = NonNullable<Parameters<typeof express.json>[0]>;
|
|
81
|
+
/** Skybridge-specific server options, passed as the third `McpServer` constructor argument. */
|
|
82
|
+
export interface SkybridgeServerOptions {
|
|
83
|
+
/** Options for the built-in `express.json()` middleware, e.g. `{ limit: "10mb" }`. */
|
|
84
|
+
json?: JsonOptions;
|
|
85
|
+
/** Resource-server OAuth config. When set, mounts well-known metadata and bearer auth on `/mcp`. */
|
|
86
|
+
oauth?: OAuthConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Well-known keys recognized by host runtimes when set on a tool's `_meta`.
|
|
90
|
+
* Use {@link ToolMeta} to also pass arbitrary custom metadata alongside these.
|
|
91
|
+
*
|
|
92
|
+
* @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters
|
|
93
|
+
*/
|
|
38
94
|
export interface KnownToolMeta {
|
|
95
|
+
/** Apps SDK: allow the rendered view to call this tool from inside its iframe. */
|
|
39
96
|
"openai/widgetAccessible"?: boolean;
|
|
97
|
+
/** Apps SDK: status text shown while the tool is running (e.g. `"Searching trips"`). */
|
|
40
98
|
"openai/toolInvocation/invoking"?: string;
|
|
99
|
+
/** Apps SDK: status text shown once the tool returns (e.g. `"Found 3 trips"`). */
|
|
41
100
|
"openai/toolInvocation/invoked"?: string;
|
|
101
|
+
/** Apps SDK: input parameters that hold file references — the host attaches uploaded files to them. */
|
|
102
|
+
"openai/fileParams"?: string[];
|
|
103
|
+
/** MCP Apps: control whether the tool is exposed to the model, the app, or both. */
|
|
104
|
+
ui?: Pick<McpUiToolMeta, "visibility">;
|
|
105
|
+
securitySchemes?: SecurityScheme[];
|
|
42
106
|
}
|
|
107
|
+
/** {@link KnownToolMeta} merged with arbitrary string-keyed metadata for custom flags. */
|
|
43
108
|
export type ToolMeta = KnownToolMeta & Record<string, unknown>;
|
|
109
|
+
/**
|
|
110
|
+
* Convenient return type for tool handlers — a plain string, a single
|
|
111
|
+
* {@link ContentBlock}, or an array. Skybridge normalizes it to the MCP
|
|
112
|
+
* `content: ContentBlock[]` shape before responding.
|
|
113
|
+
*/
|
|
44
114
|
export type HandlerContent = string | ContentBlock | ContentBlock[];
|
|
45
115
|
/**
|
|
46
116
|
* Type-level marker interface for cross-package type inference.
|
|
@@ -84,17 +154,73 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
|
|
|
84
154
|
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
85
155
|
annotations?: ToolAnnotations;
|
|
86
156
|
view?: ViewConfig;
|
|
157
|
+
/**
|
|
158
|
+
* Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
|
|
159
|
+
* Lets clients label tools that require sign-in before calling, and pass
|
|
160
|
+
* the right scopes through the OAuth flow. Listing both `noauth` and
|
|
161
|
+
* `oauth2` signals that the tool works for anonymous callers and gives
|
|
162
|
+
* enhanced behavior to authenticated ones.
|
|
163
|
+
*/
|
|
164
|
+
securitySchemes?: SecurityScheme[];
|
|
87
165
|
_meta?: ToolMeta;
|
|
88
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Optional client-supplied hints attached to `params._meta` on every tool call
|
|
169
|
+
* by the Apps SDK host. Hints only: never use for authorization, and tolerate
|
|
170
|
+
* absence.
|
|
171
|
+
* @see https://developers.openai.com/apps-sdk/reference#_meta-fields-the-client-provides
|
|
172
|
+
*/
|
|
173
|
+
export interface ClientHintsMeta {
|
|
174
|
+
/** Requested locale (BCP-47, e.g. `"en-US"`). */
|
|
175
|
+
"openai/locale"?: string;
|
|
176
|
+
/** Browser user-agent */
|
|
177
|
+
"openai/userAgent"?: string;
|
|
178
|
+
/** Coarse user location. May be partially populated. */
|
|
179
|
+
"openai/userLocation"?: {
|
|
180
|
+
city?: string;
|
|
181
|
+
region?: string;
|
|
182
|
+
country?: string;
|
|
183
|
+
timezone?: string;
|
|
184
|
+
longitude?: number;
|
|
185
|
+
latitude?: number;
|
|
186
|
+
};
|
|
187
|
+
/** Anonymized user id. */
|
|
188
|
+
"openai/subject"?: string;
|
|
189
|
+
/** Anonymized conversation id, stable within a ChatGPT session. */
|
|
190
|
+
"openai/session"?: string;
|
|
191
|
+
/** Anonymized organization id, when the user account is part of an organization. */
|
|
192
|
+
"openai/organization"?: string;
|
|
193
|
+
/** Stable id for the currently mounted widget instance. */
|
|
194
|
+
"openai/widgetSessionId"?: string;
|
|
195
|
+
}
|
|
196
|
+
type ToolHandlerExtra = Omit<RequestHandlerExtra<ServerRequest, ServerNotification>, "_meta"> & {
|
|
197
|
+
_meta?: RequestMeta & ClientHintsMeta;
|
|
198
|
+
};
|
|
89
199
|
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
90
200
|
content?: HandlerContent;
|
|
91
201
|
} = {
|
|
92
202
|
content?: HandlerContent;
|
|
93
|
-
}> = (args: ShapeOutput<TInput>, extra:
|
|
203
|
+
}> = (args: ShapeOutput<TInput>, extra: ToolHandlerExtra) => TReturn | Promise<TReturn>;
|
|
204
|
+
/**
|
|
205
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
206
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
207
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
208
|
+
* who build content lazily can apply the same normalization.
|
|
209
|
+
*/
|
|
94
210
|
export declare function normalizeContent(content: HandlerContent | undefined): ContentBlock[];
|
|
95
211
|
interface McpServerBaseOmitted extends Omit<McpServerBase, "registerTool" | "connect"> {
|
|
96
212
|
}
|
|
97
213
|
declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof McpServerBase>) => McpServerBaseOmitted;
|
|
214
|
+
/**
|
|
215
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
216
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
217
|
+
* user-facing API.
|
|
218
|
+
*
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
export declare function __setBuildManifest(manifest: Record<string, {
|
|
222
|
+
file: string;
|
|
223
|
+
}>): void;
|
|
98
224
|
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
|
|
99
225
|
readonly $types: McpServerTypes<TTools>;
|
|
100
226
|
/**
|
|
@@ -102,7 +228,9 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
102
228
|
* custom routes, middleware, or settings — e.g.
|
|
103
229
|
* `server.express.get("/health", ...)`.
|
|
104
230
|
*
|
|
105
|
-
* `express.json()` is pre-applied
|
|
231
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
232
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
233
|
+
* Register your handlers before `run()`;
|
|
106
234
|
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
107
235
|
* error handler are appended in that order.
|
|
108
236
|
*
|
|
@@ -114,12 +242,41 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
114
242
|
private mcpMiddlewareEntries;
|
|
115
243
|
private mcpMiddlewareApplied;
|
|
116
244
|
private claimedViews;
|
|
245
|
+
private viewMetaBuilders;
|
|
246
|
+
/**
|
|
247
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
248
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
249
|
+
* underlying view no matter which version param the consumer sends, since
|
|
250
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
251
|
+
*/
|
|
252
|
+
private viewUriByPath;
|
|
117
253
|
private viteManifest;
|
|
118
254
|
private readonly serverInfo;
|
|
119
255
|
private readonly serverOptions?;
|
|
120
|
-
constructor(serverInfo: Implementation, options?: ServerOptions);
|
|
256
|
+
constructor(serverInfo: Implementation, options?: ServerOptions, skybridgeOptions?: SkybridgeServerOptions);
|
|
257
|
+
/**
|
|
258
|
+
* Register Express middleware on the underlying app. Mirrors `app.use` —
|
|
259
|
+
* pass handlers directly or a path-prefixed handler list. Register before
|
|
260
|
+
* {@link McpServer.run}; ordering matches Express.
|
|
261
|
+
*
|
|
262
|
+
* Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work
|
|
263
|
+
* locally and on self-hosted deployments.
|
|
264
|
+
*/
|
|
121
265
|
use(...handlers: RequestHandler[]): this;
|
|
122
266
|
use(path: string, ...handlers: RequestHandler[]): this;
|
|
267
|
+
/**
|
|
268
|
+
* Register Express error-handling middleware to run after the built-in
|
|
269
|
+
* `/mcp` route (or your custom route). Use this to log or transform errors
|
|
270
|
+
* thrown by tool handlers before the default error handler responds.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* server.useOnError((err, _req, _res, next) => {
|
|
275
|
+
* logger.error(err);
|
|
276
|
+
* next(err);
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
123
280
|
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
124
281
|
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
125
282
|
/** Register MCP protocol-level middleware (catch-all). */
|
|
@@ -154,6 +311,14 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
154
311
|
*/
|
|
155
312
|
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
156
313
|
private applyMcpMiddleware;
|
|
314
|
+
/**
|
|
315
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
316
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
317
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
318
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
319
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
320
|
+
* throw afterwards.
|
|
321
|
+
*/
|
|
157
322
|
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
158
323
|
/**
|
|
159
324
|
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
@@ -166,10 +331,23 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
166
331
|
* read side and fails fast on SDK field renames.
|
|
167
332
|
*/
|
|
168
333
|
connectStatelessTransport(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
336
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
337
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
338
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
339
|
+
*
|
|
340
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
341
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
342
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
343
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
344
|
+
* Node, returns `undefined` once listening.
|
|
345
|
+
*/
|
|
169
346
|
run(): Promise<{
|
|
170
347
|
fetch: (...args: unknown[]) => unknown;
|
|
171
|
-
} | undefined>;
|
|
348
|
+
} | Express | undefined>;
|
|
172
349
|
private enforceOneToolPerView;
|
|
350
|
+
private resolveViewRequestContext;
|
|
173
351
|
private registerViewResources;
|
|
174
352
|
private registerViewResource;
|
|
175
353
|
private wrapHandler;
|
|
@@ -186,6 +364,35 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
186
364
|
file: string;
|
|
187
365
|
}>): this;
|
|
188
366
|
private readManifest;
|
|
367
|
+
/**
|
|
368
|
+
* Register a tool. Pass a `config` describing the tool (name, schemas,
|
|
369
|
+
* optional {@link ViewConfig}, optional {@link ToolMeta}) and a handler that
|
|
370
|
+
* returns the tool's result.
|
|
371
|
+
*
|
|
372
|
+
* Chain calls to build up a server: each call returns a new `McpServer`
|
|
373
|
+
* type that captures the tool's input/output/`_meta` shape so the
|
|
374
|
+
* resulting `typeof server` can drive {@link generateHelpers}.
|
|
375
|
+
*
|
|
376
|
+
* The handler's return shape determines the output types: the
|
|
377
|
+
* `structuredContent` field becomes the tool's typed output, and `_meta`
|
|
378
|
+
* becomes its `responseMetadata`. The `content` field is normalized through
|
|
379
|
+
* {@link normalizeContent}.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* server.registerTool({
|
|
384
|
+
* name: "search",
|
|
385
|
+
* inputSchema: { query: z.string() },
|
|
386
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
387
|
+
* view: { component: "search" },
|
|
388
|
+
* }, async ({ query }) => ({
|
|
389
|
+
* content: `Found results for ${query}`,
|
|
390
|
+
* structuredContent: { results: [...] },
|
|
391
|
+
* }));
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @see https://docs.skybridge.tech/api-reference/register-tool
|
|
395
|
+
*/
|
|
189
396
|
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
190
397
|
content?: HandlerContent;
|
|
191
398
|
}>(config: ToolConfig<InputArgs> & {
|