skybridge 0.0.0-dev.a830bd9 → 0.0.0-dev.a843396
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/detect-port.js.map +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.js.map +1 -1
- package/dist/cli/tunnel-control-server.test.js.map +1 -1
- package/dist/cli/tunnel-handler.js.map +1 -1
- package/dist/cli/tunnel-handler.test.js.map +1 -1
- package/dist/cli/tunnel.js +2 -2
- package/dist/cli/tunnel.js.map +1 -1
- package/dist/cli/tunnel.test.js.map +1 -1
- 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.js.map +1 -1
- package/dist/cli/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/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 +7 -0
- package/dist/commands/dev.js.map +1 -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 +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.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 +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 +2 -4
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +153 -71
- 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 +3 -1
- package/dist/server/index.js +2 -0
- 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 +218 -5
- package/dist/server/server.js +176 -75
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js.map +1 -1
- package/dist/server/tunnel-proxy-router.js.map +1 -1
- package/dist/server/tunnel-proxy-router.test.js.map +1 -1
- 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.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 +35 -9
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.js.map +1 -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 +9 -2
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
|
}
|
|
47
|
+
/** Union of valid view component names. Narrowed by {@link ViewNameRegistry}. */
|
|
28
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,31 +141,139 @@ 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
|
+
* 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
|
+
*/
|
|
98
230
|
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
|
|
99
231
|
readonly $types: McpServerTypes<TTools>;
|
|
100
|
-
|
|
101
|
-
|
|
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;
|
|
102
245
|
private customErrorMiddleware;
|
|
103
246
|
private mcpMiddlewareEntries;
|
|
104
247
|
private mcpMiddlewareApplied;
|
|
105
248
|
private claimedViews;
|
|
249
|
+
private viewMetaBuilders;
|
|
106
250
|
private viteManifest;
|
|
107
251
|
private readonly serverInfo;
|
|
108
252
|
private readonly serverOptions?;
|
|
109
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
|
+
*/
|
|
110
262
|
use(...handlers: RequestHandler[]): this;
|
|
111
263
|
use(path: string, ...handlers: RequestHandler[]): this;
|
|
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
|
+
*/
|
|
112
277
|
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
113
278
|
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
114
279
|
/** Register MCP protocol-level middleware (catch-all). */
|
|
@@ -143,6 +308,14 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
143
308
|
*/
|
|
144
309
|
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
145
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
|
+
*/
|
|
146
319
|
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
147
320
|
/**
|
|
148
321
|
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
@@ -155,10 +328,21 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
155
328
|
* read side and fails fast on SDK field renames.
|
|
156
329
|
*/
|
|
157
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
|
+
*/
|
|
158
341
|
run(): Promise<{
|
|
159
342
|
fetch: (...args: unknown[]) => unknown;
|
|
160
343
|
} | undefined>;
|
|
161
344
|
private enforceOneToolPerView;
|
|
345
|
+
private resolveViewRequestContext;
|
|
162
346
|
private registerViewResources;
|
|
163
347
|
private registerViewResource;
|
|
164
348
|
private wrapHandler;
|
|
@@ -175,6 +359,35 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
175
359
|
file: string;
|
|
176
360
|
}>): this;
|
|
177
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
|
+
*/
|
|
178
391
|
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
179
392
|
content?: HandlerContent;
|
|
180
393
|
}>(config: ToolConfig<InputArgs> & {
|
package/dist/server/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
6
|
import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
7
|
import { mergeWith, union } from "es-toolkit";
|
|
8
|
+
import express, {} from "express";
|
|
8
9
|
import { createApp } from "./express.js";
|
|
9
10
|
import { createMiddlewareEntry } from "./metric.js";
|
|
10
11
|
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
@@ -16,6 +17,12 @@ const mergeWithUnion = (target, source) => {
|
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
22
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
23
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
24
|
+
* who build content lazily can apply the same normalization.
|
|
25
|
+
*/
|
|
19
26
|
export function normalizeContent(content) {
|
|
20
27
|
if (content === undefined) {
|
|
21
28
|
return [];
|
|
@@ -29,13 +36,54 @@ export function normalizeContent(content) {
|
|
|
29
36
|
return [content];
|
|
30
37
|
}
|
|
31
38
|
const McpServerBaseOmitted = McpServerBase;
|
|
39
|
+
/**
|
|
40
|
+
* The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
41
|
+
* registry, view resources, an embedded Express app, and protocol-level
|
|
42
|
+
* middleware. Construct it with the same `Implementation` info you would pass
|
|
43
|
+
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
44
|
+
* then call {@link McpServer.run} to start the HTTP server.
|
|
45
|
+
*
|
|
46
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
47
|
+
* shape, so `typeof server` carries enough information for view-side helpers
|
|
48
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
51
|
+
* chaining; you almost never set this manually.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
56
|
+
* .registerTool({
|
|
57
|
+
* name: "search",
|
|
58
|
+
* inputSchema: { query: z.string() },
|
|
59
|
+
* view: { component: "search" },
|
|
60
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
61
|
+
*
|
|
62
|
+
* await server.run();
|
|
63
|
+
* export type AppType = typeof server;
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see https://docs.skybridge.tech/api-reference/mcp-server
|
|
67
|
+
*/
|
|
32
68
|
export class McpServer extends McpServerBaseOmitted {
|
|
69
|
+
/**
|
|
70
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
71
|
+
* custom routes, middleware, or settings — e.g.
|
|
72
|
+
* `server.express.get("/health", ...)`.
|
|
73
|
+
*
|
|
74
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
75
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
76
|
+
* error handler are appended in that order.
|
|
77
|
+
*
|
|
78
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
79
|
+
* locally and on self-hosted deployments.
|
|
80
|
+
*/
|
|
33
81
|
express;
|
|
34
|
-
customMiddleware = [];
|
|
35
82
|
customErrorMiddleware = [];
|
|
36
83
|
mcpMiddlewareEntries = [];
|
|
37
84
|
mcpMiddlewareApplied = false;
|
|
38
85
|
claimedViews = new Map();
|
|
86
|
+
viewMetaBuilders = new Map();
|
|
39
87
|
viteManifest = null;
|
|
40
88
|
serverInfo;
|
|
41
89
|
serverOptions;
|
|
@@ -43,18 +91,17 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
43
91
|
super(serverInfo, options);
|
|
44
92
|
this.serverInfo = serverInfo;
|
|
45
93
|
this.serverOptions = options;
|
|
94
|
+
this.express = express();
|
|
95
|
+
this.express.use(express.json());
|
|
46
96
|
}
|
|
47
97
|
use(pathOrHandler, ...handlers) {
|
|
98
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
99
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
48
100
|
if (typeof pathOrHandler === "string") {
|
|
49
|
-
this.
|
|
50
|
-
path: pathOrHandler,
|
|
51
|
-
handlers,
|
|
52
|
-
});
|
|
101
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
53
102
|
}
|
|
54
103
|
else {
|
|
55
|
-
this.
|
|
56
|
-
handlers: [pathOrHandler, ...handlers],
|
|
57
|
-
});
|
|
104
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
58
105
|
}
|
|
59
106
|
return this;
|
|
60
107
|
}
|
|
@@ -98,10 +145,32 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
98
145
|
return;
|
|
99
146
|
}
|
|
100
147
|
this.mcpMiddlewareApplied = true;
|
|
148
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
149
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
150
|
+
const viewListMetaEntry = {
|
|
151
|
+
filter: "resources/list",
|
|
152
|
+
handler: async (_req, extra, next) => {
|
|
153
|
+
const result = (await next());
|
|
154
|
+
for (const resource of result.resources) {
|
|
155
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
156
|
+
if (!builder) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const meta = builder(extra);
|
|
160
|
+
resource._meta = {
|
|
161
|
+
...(resource._meta ?? {}),
|
|
162
|
+
...meta,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
},
|
|
167
|
+
};
|
|
101
168
|
const monitoringEntry = createMiddlewareEntry();
|
|
102
|
-
const entries =
|
|
103
|
-
? [monitoringEntry
|
|
104
|
-
|
|
169
|
+
const entries = [
|
|
170
|
+
...(monitoringEntry ? [monitoringEntry] : []),
|
|
171
|
+
viewListMetaEntry,
|
|
172
|
+
...this.mcpMiddlewareEntries,
|
|
173
|
+
];
|
|
105
174
|
if (entries.length === 0) {
|
|
106
175
|
return;
|
|
107
176
|
}
|
|
@@ -116,6 +185,14 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
116
185
|
instrumentMap(requestHandlers, false);
|
|
117
186
|
instrumentMap(notificationHandlers, true);
|
|
118
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
190
|
+
* when you're embedding Skybridge in a host that already manages its own
|
|
191
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
192
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
193
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
194
|
+
* throw afterwards.
|
|
195
|
+
*/
|
|
119
196
|
async connect(transport) {
|
|
120
197
|
this.applyMcpMiddleware();
|
|
121
198
|
return McpServerBase.prototype.connect.call(this, transport);
|
|
@@ -139,17 +216,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
139
216
|
target._notificationHandlers = notificationHandlers;
|
|
140
217
|
await fresh.connect(transport);
|
|
141
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
221
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
222
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
223
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
224
|
+
*
|
|
225
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
226
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
227
|
+
* Node, returns `undefined` once listening.
|
|
228
|
+
*/
|
|
142
229
|
async run() {
|
|
143
230
|
this.applyMcpMiddleware();
|
|
144
231
|
const httpServer = http.createServer();
|
|
145
|
-
|
|
146
|
-
this
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
errorMiddleware: this.customErrorMiddleware,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
232
|
+
await createApp({
|
|
233
|
+
mcpServer: this,
|
|
234
|
+
httpServer,
|
|
235
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
236
|
+
});
|
|
153
237
|
httpServer.on("request", this.express);
|
|
154
238
|
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
155
239
|
await new Promise((resolve, reject) => {
|
|
@@ -191,6 +275,57 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
191
275
|
}
|
|
192
276
|
this.claimedViews.set(component, toolName);
|
|
193
277
|
}
|
|
278
|
+
resolveViewRequestContext(extra) {
|
|
279
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
280
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
281
|
+
const header = (key) => {
|
|
282
|
+
const val = headers[key];
|
|
283
|
+
return Array.isArray(val) ? val[0] : val;
|
|
284
|
+
};
|
|
285
|
+
const isClaude = header("user-agent") === "Claude-User";
|
|
286
|
+
let serverUrl;
|
|
287
|
+
const forwardedHost = header("x-forwarded-host");
|
|
288
|
+
const origin = header("origin");
|
|
289
|
+
const host = header("host");
|
|
290
|
+
if (forwardedHost) {
|
|
291
|
+
const proto = header("x-forwarded-proto") || "https";
|
|
292
|
+
serverUrl = `${proto}://${forwardedHost}`;
|
|
293
|
+
}
|
|
294
|
+
else if (origin) {
|
|
295
|
+
serverUrl = origin;
|
|
296
|
+
}
|
|
297
|
+
else if (host) {
|
|
298
|
+
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
299
|
+
? "http"
|
|
300
|
+
: "https";
|
|
301
|
+
serverUrl = `${proto}://${host}`;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const devPort = process.env.__PORT || "3000";
|
|
305
|
+
serverUrl = `http://localhost:${devPort}`;
|
|
306
|
+
}
|
|
307
|
+
const connectDomains = [serverUrl];
|
|
308
|
+
if (!isProduction) {
|
|
309
|
+
const wsUrl = new URL(serverUrl);
|
|
310
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
311
|
+
connectDomains.push(wsUrl.origin);
|
|
312
|
+
}
|
|
313
|
+
let contentMetaOverrides = {};
|
|
314
|
+
if (isClaude) {
|
|
315
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
316
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
317
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
318
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
319
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
320
|
+
const hash = crypto
|
|
321
|
+
.createHash("sha256")
|
|
322
|
+
.update(url)
|
|
323
|
+
.digest("hex")
|
|
324
|
+
.slice(0, 32);
|
|
325
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
326
|
+
}
|
|
327
|
+
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
328
|
+
}
|
|
194
329
|
registerViewResources(toolName, view, toolMeta) {
|
|
195
330
|
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
196
331
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
@@ -295,40 +430,24 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
295
430
|
});
|
|
296
431
|
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
297
432
|
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
298
|
-
toolMeta.ui = { resourceUri: viewResource.uri };
|
|
433
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
299
434
|
}
|
|
300
435
|
}
|
|
301
436
|
registerViewResource({ name, viewResource, view, }) {
|
|
302
437
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
438
|
+
const buildMeta = (extra) => {
|
|
439
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
440
|
+
return buildContentMeta({
|
|
441
|
+
resourceDomains: [serverUrl],
|
|
442
|
+
connectDomains,
|
|
443
|
+
domain: serverUrl,
|
|
444
|
+
baseUriDomains: [serverUrl],
|
|
445
|
+
}, contentMetaOverrides);
|
|
446
|
+
};
|
|
447
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
303
448
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
304
449
|
const isProduction = process.env.NODE_ENV === "production";
|
|
305
|
-
const
|
|
306
|
-
const headers = extra?.requestInfo?.headers || {};
|
|
307
|
-
const header = (key) => {
|
|
308
|
-
const val = headers[key];
|
|
309
|
-
return Array.isArray(val) ? val[0] : val;
|
|
310
|
-
};
|
|
311
|
-
let serverUrl;
|
|
312
|
-
const forwardedHost = header("x-forwarded-host");
|
|
313
|
-
const origin = header("origin");
|
|
314
|
-
const host = header("host");
|
|
315
|
-
if (forwardedHost) {
|
|
316
|
-
const proto = header("x-forwarded-proto") || "https";
|
|
317
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
318
|
-
}
|
|
319
|
-
else if (origin) {
|
|
320
|
-
serverUrl = origin;
|
|
321
|
-
}
|
|
322
|
-
else if (host) {
|
|
323
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
324
|
-
? "http"
|
|
325
|
-
: "https";
|
|
326
|
-
serverUrl = `${proto}://${host}`;
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
const devPort = process.env.__PORT || "3000";
|
|
330
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
331
|
-
}
|
|
450
|
+
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
332
451
|
const html = isProduction
|
|
333
452
|
? templateHelper.renderProduction({
|
|
334
453
|
hostType,
|
|
@@ -341,35 +460,9 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
341
460
|
serverUrl,
|
|
342
461
|
viewName: view.component,
|
|
343
462
|
});
|
|
344
|
-
const connectDomains = [serverUrl];
|
|
345
|
-
if (!isProduction) {
|
|
346
|
-
const wsUrl = new URL(serverUrl);
|
|
347
|
-
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
348
|
-
connectDomains.push(wsUrl.origin);
|
|
349
|
-
}
|
|
350
|
-
let contentMetaOverrides = {};
|
|
351
|
-
if (isClaude) {
|
|
352
|
-
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
353
|
-
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
354
|
-
// Strip a lone trailing slash so the hash matches the connector URL
|
|
355
|
-
// as registered with Claude (which has no trailing slash on bare origins).
|
|
356
|
-
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
357
|
-
const hash = crypto
|
|
358
|
-
.createHash("sha256")
|
|
359
|
-
.update(url)
|
|
360
|
-
.digest("hex")
|
|
361
|
-
.slice(0, 32);
|
|
362
|
-
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
363
|
-
}
|
|
364
|
-
const contentMeta = buildContentMeta({
|
|
365
|
-
resourceDomains: [serverUrl],
|
|
366
|
-
connectDomains,
|
|
367
|
-
domain: serverUrl,
|
|
368
|
-
baseUriDomains: [serverUrl],
|
|
369
|
-
}, contentMetaOverrides);
|
|
370
463
|
return {
|
|
371
464
|
contents: [
|
|
372
|
-
{ uri: uri.href, mimeType, text: html, _meta:
|
|
465
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
373
466
|
],
|
|
374
467
|
};
|
|
375
468
|
});
|
|
@@ -446,8 +539,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
446
539
|
}
|
|
447
540
|
const config = args[0];
|
|
448
541
|
const cb = args[1];
|
|
449
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
542
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
450
543
|
const toolMeta = { ...userToolMeta };
|
|
544
|
+
if (securitySchemes) {
|
|
545
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
546
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
547
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
548
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
549
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
550
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
551
|
+
}
|
|
451
552
|
if (view) {
|
|
452
553
|
this.enforceOneToolPerView(view.component, name);
|
|
453
554
|
this.registerViewResources(name, view, toolMeta);
|