skybridge 0.0.0-dev.9b039a8 → 0.0.0-dev.9b61b33
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/dist/commands/dev.js +1 -3
- package/dist/commands/dev.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +32 -0
- package/dist/server/auth/discovery.js +56 -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 +18 -0
- package/dist/server/auth/providers/auth0.js +31 -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 +48 -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 +16 -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 +28 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +24 -0
- package/dist/server/auth/providers/custom.js +37 -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 +107 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +15 -0
- package/dist/server/auth/providers/descope.js +33 -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 +37 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +12 -0
- package/dist/server/auth/providers/stytch.js +13 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +12 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/security-schemes.d.ts +13 -0
- package/dist/server/auth/security-schemes.js +55 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +89 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +11 -0
- package/dist/server/auth/setup.js +95 -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 +407 -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/express.test.js +31 -0
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/index.d.ts +8 -1
- package/dist/server/index.js +6 -0
- package/dist/server/index.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 +53 -8
- package/dist/server/server.js +172 -123
- package/dist/server/server.js.map +1 -1
- package/dist/server/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +103 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/test/view.test.js +69 -101
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +310 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +197 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
- package/dist/web/bridges/apps-sdk/bridge.js +15 -4
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +4 -4
- package/dist/web/bridges/get-adaptor.js +6 -11
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
- package/dist/web/bridges/mcp-app/bridge.js +46 -4
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +10 -0
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.test.js +9 -5
- package/dist/web/data-llm.test.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/use-call-tool.test.js +37 -23
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +56 -20
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +11 -3
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +25 -7
- package/dist/web/hooks/use-tool-info.js +5 -8
- 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 +42 -32
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +6 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/package.json +3 -2
- package/dist/cli/use-open-tunnel-browser.d.ts +0 -6
- package/dist/cli/use-open-tunnel-browser.js +0 -19
- package/dist/cli/use-open-tunnel-browser.js.map +0 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
- package/dist/web/bridges/mcp-app/adaptor.js +0 -283
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
package/dist/server/server.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp
|
|
|
4
4
|
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
5
5
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
6
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
|
+
import express, { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
|
|
8
|
+
import type { OAuthConfig } from "./auth/index.js";
|
|
8
9
|
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
9
10
|
/**
|
|
10
11
|
* Type marker for a registered tool — carries its input, output, and response
|
|
@@ -18,7 +19,11 @@ export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unk
|
|
|
18
19
|
output: TOutput;
|
|
19
20
|
responseMetadata: TResponseMetadata;
|
|
20
21
|
};
|
|
21
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Views now always emit a single ext-apps resource; host targeting
|
|
24
|
+
* no longer applies. Retained for backwards compatibility; will be removed in a
|
|
25
|
+
* future major.
|
|
26
|
+
*/
|
|
22
27
|
export type ViewHostType = "apps-sdk" | "mcp-app";
|
|
23
28
|
/**
|
|
24
29
|
* Content Security Policy origins attached to a view's resource. Each list is
|
|
@@ -44,8 +49,16 @@ export interface ViewCsp {
|
|
|
44
49
|
*/
|
|
45
50
|
export interface ViewNameRegistry {
|
|
46
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve view component names from a registry: the union of its keys, or
|
|
54
|
+
* `string` when the registry is empty. The empty case happens before
|
|
55
|
+
* `.skybridge/views.d.ts` is generated; falling back to `string` keeps valid
|
|
56
|
+
* view names from erroring on a fresh checkout, and narrowing kicks in once
|
|
57
|
+
* the generated file augments the registry.
|
|
58
|
+
*/
|
|
59
|
+
export type ViewNameFor<Registry> = [keyof Registry & string] extends [never] ? string : keyof Registry & string;
|
|
47
60
|
/** Union of valid view component names. Narrowed by {@link ViewNameRegistry}. */
|
|
48
|
-
export type ViewName =
|
|
61
|
+
export type ViewName = ViewNameFor<ViewNameRegistry>;
|
|
49
62
|
/**
|
|
50
63
|
* Pass under `view` in a tool's `registerTool` config to render the tool's
|
|
51
64
|
* result through a Skybridge view instead of a plain text response.
|
|
@@ -55,11 +68,14 @@ export interface ViewConfig {
|
|
|
55
68
|
component: ViewName;
|
|
56
69
|
/** Human-readable label the host may show alongside the view. */
|
|
57
70
|
description?: string;
|
|
58
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated No-op. Every view emits a single ext-apps resource regardless
|
|
73
|
+
* of this value. Will be removed in a future major.
|
|
74
|
+
*/
|
|
59
75
|
hosts?: ViewHostType[];
|
|
60
|
-
/**
|
|
76
|
+
/** Request a visible border around the view (forwarded as `ui.prefersBorder`). */
|
|
61
77
|
prefersBorder?: boolean;
|
|
62
|
-
/**
|
|
78
|
+
/** Override the iframe's served domain (advanced; forwarded as `ui.domain`). */
|
|
63
79
|
domain?: string;
|
|
64
80
|
/** Per-view CSP overrides — see {@link ViewCsp}. */
|
|
65
81
|
csp?: ViewCsp;
|
|
@@ -72,6 +88,21 @@ export type SecurityScheme = {
|
|
|
72
88
|
type: "oauth2";
|
|
73
89
|
scopes?: string[];
|
|
74
90
|
};
|
|
91
|
+
export type ToolAuth = "public" | "required" | {
|
|
92
|
+
scopes: string[];
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Options forwarded to the built-in `express.json()` body parser. Derived
|
|
96
|
+
* from Express's own types so the public API doesn't depend on `body-parser`.
|
|
97
|
+
*/
|
|
98
|
+
export type JsonOptions = NonNullable<Parameters<typeof express.json>[0]>;
|
|
99
|
+
/** Skybridge-specific server options, passed as the third `McpServer` constructor argument. */
|
|
100
|
+
export interface SkybridgeServerOptions {
|
|
101
|
+
/** Options for the built-in `express.json()` middleware, e.g. `{ limit: "10mb" }`. */
|
|
102
|
+
json?: JsonOptions;
|
|
103
|
+
/** Resource-server OAuth config. When set, mounts well-known metadata and bearer auth on `/mcp`. */
|
|
104
|
+
oauth?: OAuthConfig;
|
|
105
|
+
}
|
|
75
106
|
/**
|
|
76
107
|
* Well-known keys recognized by host runtimes when set on a tool's `_meta`.
|
|
77
108
|
* Use {@link ToolMeta} to also pass arbitrary custom metadata alongside these.
|
|
@@ -141,6 +172,7 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
|
|
|
141
172
|
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
142
173
|
annotations?: ToolAnnotations;
|
|
143
174
|
view?: ViewConfig;
|
|
175
|
+
auth?: ToolAuth;
|
|
144
176
|
/**
|
|
145
177
|
* Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
|
|
146
178
|
* Lets clients label tools that require sign-in before calling, and pass
|
|
@@ -215,7 +247,9 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
215
247
|
* custom routes, middleware, or settings — e.g.
|
|
216
248
|
* `server.express.get("/health", ...)`.
|
|
217
249
|
*
|
|
218
|
-
* `express.json()` is pre-applied
|
|
250
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
251
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
252
|
+
* Register your handlers before `run()`;
|
|
219
253
|
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
220
254
|
* error handler are appended in that order.
|
|
221
255
|
*
|
|
@@ -228,10 +262,20 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
228
262
|
private mcpMiddlewareApplied;
|
|
229
263
|
private claimedViews;
|
|
230
264
|
private viewMetaBuilders;
|
|
265
|
+
/**
|
|
266
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
267
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
268
|
+
* underlying view no matter which version param the consumer sends, since
|
|
269
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
270
|
+
*/
|
|
271
|
+
private viewUriByPath;
|
|
231
272
|
private viteManifest;
|
|
232
273
|
private readonly serverInfo;
|
|
233
274
|
private readonly serverOptions?;
|
|
234
|
-
|
|
275
|
+
private oauthEnabled;
|
|
276
|
+
private acceptsAnonymous;
|
|
277
|
+
private securitySchemesByTool;
|
|
278
|
+
constructor(serverInfo: Implementation, options?: ServerOptions, skybridgeOptions?: SkybridgeServerOptions);
|
|
235
279
|
/**
|
|
236
280
|
* Register Express middleware on the underlying app. Mirrors `app.use` —
|
|
237
281
|
* pass handlers directly or a path-prefixed handler list. Register before
|
|
@@ -328,6 +372,7 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
328
372
|
private resolveViewRequestContext;
|
|
329
373
|
private registerViewResources;
|
|
330
374
|
private registerViewResource;
|
|
375
|
+
private serveLegacyAppsSdkUrl;
|
|
331
376
|
private wrapHandler;
|
|
332
377
|
private computeViewVersionParam;
|
|
333
378
|
private lookupViewFile;
|
package/dist/server/server.js
CHANGED
|
@@ -6,9 +6,12 @@ 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
8
|
import express, {} from "express";
|
|
9
|
+
import { authToSecuritySchemes, securitySchemesAllowAnonymous, } from "./auth/security-schemes.js";
|
|
10
|
+
import { setupOAuth } from "./auth/setup.js";
|
|
9
11
|
import { createApp } from "./express.js";
|
|
10
12
|
import { createMiddlewareEntry } from "./metric.js";
|
|
11
13
|
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
14
|
+
import { resolveServerOrigin } from "./requestOrigin.js";
|
|
12
15
|
import { templateHelper } from "./templateHelper.js";
|
|
13
16
|
const mergeWithUnion = (target, source) => {
|
|
14
17
|
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
@@ -17,6 +20,15 @@ const mergeWithUnion = (target, source) => {
|
|
|
17
20
|
}
|
|
18
21
|
});
|
|
19
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Drop the query string from a `ui://` view URI, leaving the bare path. The
|
|
25
|
+
* `?v=` cache key is the only query we append, so a plain split is enough and
|
|
26
|
+
* sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
|
|
27
|
+
*/
|
|
28
|
+
function stripQuery(uri) {
|
|
29
|
+
const queryIndex = uri.indexOf("?");
|
|
30
|
+
return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
|
|
31
|
+
}
|
|
20
32
|
/**
|
|
21
33
|
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
22
34
|
* become a single `TextContent`; a single block is wrapped in an array;
|
|
@@ -87,7 +99,9 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
87
99
|
* custom routes, middleware, or settings — e.g.
|
|
88
100
|
* `server.express.get("/health", ...)`.
|
|
89
101
|
*
|
|
90
|
-
* `express.json()` is pre-applied
|
|
102
|
+
* `express.json()` is pre-applied — tune it via the constructor's third
|
|
103
|
+
* argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
|
|
104
|
+
* Register your handlers before `run()`;
|
|
91
105
|
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
92
106
|
* error handler are appended in that order.
|
|
93
107
|
*
|
|
@@ -100,15 +114,34 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
100
114
|
mcpMiddlewareApplied = false;
|
|
101
115
|
claimedViews = new Map();
|
|
102
116
|
viewMetaBuilders = new Map();
|
|
117
|
+
/**
|
|
118
|
+
* Maps a view resource's query-less path to its canonical registered URI
|
|
119
|
+
* (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
|
|
120
|
+
* underlying view no matter which version param the consumer sends, since
|
|
121
|
+
* the param is only a cache key, not part of the resource's identity.
|
|
122
|
+
*/
|
|
123
|
+
viewUriByPath = new Map();
|
|
103
124
|
viteManifest = null;
|
|
104
125
|
serverInfo;
|
|
105
126
|
serverOptions;
|
|
106
|
-
|
|
127
|
+
oauthEnabled = false;
|
|
128
|
+
acceptsAnonymous = false;
|
|
129
|
+
securitySchemesByTool = new Map();
|
|
130
|
+
constructor(serverInfo, options, skybridgeOptions) {
|
|
107
131
|
super(serverInfo, options);
|
|
108
132
|
this.serverInfo = serverInfo;
|
|
109
133
|
this.serverOptions = options;
|
|
110
134
|
this.express = express();
|
|
111
|
-
this.express.use(express.json());
|
|
135
|
+
this.express.use(express.json(skybridgeOptions?.json));
|
|
136
|
+
if (skybridgeOptions?.oauth) {
|
|
137
|
+
this.oauthEnabled = true;
|
|
138
|
+
setupOAuth(this.express, skybridgeOptions.oauth, {
|
|
139
|
+
acceptsAnonymous: () => this.acceptsAnonymous,
|
|
140
|
+
securitySchemesForTool: (name) => this.securitySchemesByTool.has(name)
|
|
141
|
+
? { schemes: this.securitySchemesByTool.get(name) }
|
|
142
|
+
: undefined,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
112
145
|
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
113
146
|
// user code. Consume-once: clear after the first construction so a
|
|
114
147
|
// subsequent test that doesn't prime can't inherit stale state.
|
|
@@ -190,10 +223,61 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
190
223
|
return result;
|
|
191
224
|
},
|
|
192
225
|
};
|
|
226
|
+
// Resolve a view's `resources/read` by its query-less path so the
|
|
227
|
+
// underlying asset is served no matter the `?v=` value (stale cache key,
|
|
228
|
+
// no param, etc.). The version param is a cache-busting hint for external
|
|
229
|
+
// consumers; it must not gate resolution. We rewrite the lookup URI to the
|
|
230
|
+
// canonical registered one, then restore the requested URI on the response
|
|
231
|
+
// so the consumer-facing URI is never rewritten.
|
|
232
|
+
const viewReadResolveEntry = {
|
|
233
|
+
filter: "resources/read",
|
|
234
|
+
handler: async (req, _extra, next) => {
|
|
235
|
+
const requested = req.params.uri;
|
|
236
|
+
if (typeof requested !== "string") {
|
|
237
|
+
return next();
|
|
238
|
+
}
|
|
239
|
+
const path = stripQuery(requested);
|
|
240
|
+
const canonical = this.viewUriByPath.get(path);
|
|
241
|
+
if (!canonical) {
|
|
242
|
+
return next();
|
|
243
|
+
}
|
|
244
|
+
req.params.uri = canonical;
|
|
245
|
+
try {
|
|
246
|
+
const result = (await next());
|
|
247
|
+
for (const content of result.contents ?? []) {
|
|
248
|
+
if (typeof content.uri === "string" &&
|
|
249
|
+
stripQuery(content.uri) === stripQuery(canonical)) {
|
|
250
|
+
content.uri = requested;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
// Restore the shared request params so middleware outer to us never
|
|
257
|
+
// observes the rewritten lookup URI after next() unwinds.
|
|
258
|
+
req.params.uri = requested;
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
const toolsListSecuritySchemesEntry = {
|
|
263
|
+
filter: "tools/list",
|
|
264
|
+
handler: async (_req, _extra, next) => {
|
|
265
|
+
const result = (await next());
|
|
266
|
+
for (const tool of result.tools) {
|
|
267
|
+
const schemes = tool._meta?.securitySchemes;
|
|
268
|
+
if (schemes && !("securitySchemes" in tool)) {
|
|
269
|
+
tool.securitySchemes = schemes;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return result;
|
|
273
|
+
},
|
|
274
|
+
};
|
|
193
275
|
const monitoringEntry = createMiddlewareEntry();
|
|
194
276
|
const entries = [
|
|
195
277
|
...(monitoringEntry ? [monitoringEntry] : []),
|
|
196
278
|
viewListMetaEntry,
|
|
279
|
+
viewReadResolveEntry,
|
|
280
|
+
toolsListSecuritySchemesEntry,
|
|
197
281
|
...this.mcpMiddlewareEntries,
|
|
198
282
|
];
|
|
199
283
|
if (entries.length === 0) {
|
|
@@ -322,27 +406,7 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
322
406
|
return Array.isArray(val) ? val[0] : val;
|
|
323
407
|
};
|
|
324
408
|
const isClaude = header("user-agent") === "Claude-User";
|
|
325
|
-
|
|
326
|
-
const forwardedHost = header("x-forwarded-host");
|
|
327
|
-
const origin = header("origin");
|
|
328
|
-
const host = header("host");
|
|
329
|
-
if (forwardedHost) {
|
|
330
|
-
const proto = header("x-forwarded-proto") || "https";
|
|
331
|
-
serverUrl = `${proto}://${forwardedHost}`;
|
|
332
|
-
}
|
|
333
|
-
else if (origin) {
|
|
334
|
-
serverUrl = origin;
|
|
335
|
-
}
|
|
336
|
-
else if (host) {
|
|
337
|
-
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
338
|
-
? "http"
|
|
339
|
-
: "https";
|
|
340
|
-
serverUrl = `${proto}://${host}`;
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
const devPort = process.env.__PORT || "3000";
|
|
344
|
-
serverUrl = `http://localhost:${devPort}`;
|
|
345
|
-
}
|
|
409
|
+
const serverUrl = resolveServerOrigin(header);
|
|
346
410
|
const connectDomains = [serverUrl];
|
|
347
411
|
if (!isProduction) {
|
|
348
412
|
const wsUrl = new URL(serverUrl);
|
|
@@ -366,111 +430,74 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
366
430
|
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
367
431
|
}
|
|
368
432
|
registerViewResources(toolName, view, toolMeta) {
|
|
369
|
-
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
370
433
|
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
371
434
|
// their cache when the bundle changes, but keep the URI stable across
|
|
372
435
|
// `tools/list` calls when the bundle hasn't changed.
|
|
373
436
|
const versionParam = this.computeViewVersionParam(view.component);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
"openai/widgetDomain": domain,
|
|
386
|
-
"openai/widgetDescription": view.description,
|
|
387
|
-
};
|
|
388
|
-
const fromView = {
|
|
389
|
-
"openai/widgetCSP": {
|
|
390
|
-
resource_domains: view.csp?.resourceDomains,
|
|
391
|
-
connect_domains: view.csp?.connectDomains,
|
|
392
|
-
frame_domains: view.csp?.frameDomains,
|
|
393
|
-
redirect_domains: view.csp?.redirectDomains,
|
|
437
|
+
const viewResource = {
|
|
438
|
+
hostType: "mcp-app",
|
|
439
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
440
|
+
mimeType: "text/html;profile=mcp-app",
|
|
441
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
442
|
+
const defaults = {
|
|
443
|
+
ui: {
|
|
444
|
+
csp: {
|
|
445
|
+
resourceDomains,
|
|
446
|
+
connectDomains,
|
|
447
|
+
baseUriDomains,
|
|
394
448
|
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
418
|
-
mimeType: "text/html;profile=mcp-app",
|
|
419
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
420
|
-
const defaults = {
|
|
421
|
-
ui: {
|
|
422
|
-
csp: {
|
|
423
|
-
resourceDomains,
|
|
424
|
-
connectDomains,
|
|
425
|
-
baseUriDomains,
|
|
426
|
-
},
|
|
427
|
-
domain,
|
|
428
|
-
},
|
|
429
|
-
};
|
|
430
|
-
const fromView = {
|
|
431
|
-
ui: {
|
|
432
|
-
...(view.description && { description: view.description }),
|
|
433
|
-
...(view.prefersBorder !== undefined && {
|
|
434
|
-
prefersBorder: view.prefersBorder,
|
|
449
|
+
domain,
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
const fromView = {
|
|
453
|
+
ui: {
|
|
454
|
+
...(view.description && { description: view.description }),
|
|
455
|
+
...(view.prefersBorder !== undefined && {
|
|
456
|
+
prefersBorder: view.prefersBorder,
|
|
457
|
+
}),
|
|
458
|
+
...(view.domain && { domain: view.domain }),
|
|
459
|
+
csp: {
|
|
460
|
+
...(view.csp?.resourceDomains && {
|
|
461
|
+
resourceDomains: view.csp.resourceDomains,
|
|
462
|
+
}),
|
|
463
|
+
...(view.csp?.connectDomains && {
|
|
464
|
+
connectDomains: view.csp.connectDomains,
|
|
465
|
+
}),
|
|
466
|
+
...(view.csp?.frameDomains && {
|
|
467
|
+
frameDomains: view.csp.frameDomains,
|
|
468
|
+
}),
|
|
469
|
+
...(view.csp?.baseUriDomains && {
|
|
470
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
435
471
|
}),
|
|
436
|
-
...(view.domain && { domain: view.domain }),
|
|
437
|
-
csp: {
|
|
438
|
-
...(view.csp?.resourceDomains && {
|
|
439
|
-
resourceDomains: view.csp.resourceDomains,
|
|
440
|
-
}),
|
|
441
|
-
...(view.csp?.connectDomains && {
|
|
442
|
-
connectDomains: view.csp.connectDomains,
|
|
443
|
-
}),
|
|
444
|
-
...(view.csp?.frameDomains && {
|
|
445
|
-
frameDomains: view.csp.frameDomains,
|
|
446
|
-
}),
|
|
447
|
-
...(view.csp?.baseUriDomains && {
|
|
448
|
-
baseUriDomains: view.csp.baseUriDomains,
|
|
449
|
-
}),
|
|
450
|
-
...(view.csp?.redirectDomains && {
|
|
451
|
-
redirectDomains: view.csp.redirectDomains,
|
|
452
|
-
}),
|
|
453
|
-
},
|
|
454
472
|
},
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
473
|
+
},
|
|
474
|
+
};
|
|
475
|
+
const ui = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
476
|
+
ui: overrides,
|
|
477
|
+
});
|
|
478
|
+
const base = {
|
|
479
|
+
...ui,
|
|
480
|
+
...(view.description && {
|
|
481
|
+
"openai/widgetDescription": view.description,
|
|
482
|
+
}),
|
|
483
|
+
...(view.csp?.redirectDomains && {
|
|
484
|
+
"openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
|
|
485
|
+
}),
|
|
486
|
+
};
|
|
487
|
+
if (view._meta) {
|
|
488
|
+
return { ...base, ...view._meta };
|
|
489
|
+
}
|
|
490
|
+
return base;
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
this.registerViewResource({ name: toolName, viewResource, view });
|
|
494
|
+
// Advertise via the MCP Apps standard pointer only — ChatGPT renders from
|
|
495
|
+
// ui.resourceUri (verified), and not emitting openai/outputTemplate lets us
|
|
496
|
+
// retire the legacy apps-sdk resource later. The legacy apps-sdk URL is still
|
|
497
|
+
// served (see registerViewResource) so already-published apps keep resolving.
|
|
498
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
499
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
500
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
474
501
|
}
|
|
475
502
|
registerViewResource({ name, viewResource, view, }) {
|
|
476
503
|
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
@@ -484,6 +511,8 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
484
511
|
}, contentMetaOverrides);
|
|
485
512
|
};
|
|
486
513
|
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
514
|
+
this.viewUriByPath.set(stripQuery(viewUri), viewUri);
|
|
515
|
+
this.serveLegacyAppsSdkUrl(view.component, viewUri);
|
|
487
516
|
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
488
517
|
const isProduction = process.env.NODE_ENV === "production";
|
|
489
518
|
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
@@ -506,6 +535,11 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
506
535
|
};
|
|
507
536
|
});
|
|
508
537
|
}
|
|
538
|
+
serveLegacyAppsSdkUrl(component, canonicalUri) {
|
|
539
|
+
this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
|
|
540
|
+
this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
|
|
541
|
+
this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
|
|
542
|
+
}
|
|
509
543
|
wrapHandler(cb, { attachViewUUID }) {
|
|
510
544
|
return async (args, extra) => {
|
|
511
545
|
const result = await cb(args, extra);
|
|
@@ -578,8 +612,20 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
578
612
|
}
|
|
579
613
|
const config = args[0];
|
|
580
614
|
const cb = args[1];
|
|
581
|
-
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
615
|
+
const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
616
|
+
if (auth !== undefined) {
|
|
617
|
+
if (rawSecuritySchemes) {
|
|
618
|
+
throw new Error(`Tool "${name}" sets both \`auth\` and \`securitySchemes\`; use one.`);
|
|
619
|
+
}
|
|
620
|
+
if (!this.oauthEnabled) {
|
|
621
|
+
throw new Error(`Tool "${name}" sets \`auth\` but the server has no \`oauth\` provider configured.`);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const securitySchemes = auth
|
|
625
|
+
? authToSecuritySchemes(auth)
|
|
626
|
+
: rawSecuritySchemes;
|
|
582
627
|
const toolMeta = { ...userToolMeta };
|
|
628
|
+
this.securitySchemesByTool.set(name, securitySchemes);
|
|
583
629
|
if (securitySchemes) {
|
|
584
630
|
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
585
631
|
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
@@ -587,6 +633,9 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
587
633
|
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
588
634
|
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
589
635
|
toolMeta.securitySchemes = securitySchemes;
|
|
636
|
+
if (securitySchemesAllowAnonymous(securitySchemes)) {
|
|
637
|
+
this.acceptsAnonymous = true;
|
|
638
|
+
}
|
|
590
639
|
}
|
|
591
640
|
if (view) {
|
|
592
641
|
this.enforceOneToolPerView(view.component, name);
|