skybridge 1.0.1 → 1.0.2
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/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.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/index.d.ts +2 -1
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/server.d.ts +15 -0
- package/dist/server/server.js +9 -1
- package/dist/server/server.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +2 -1
- package/dist/web/bridges/apps-sdk/adaptor.js +4 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +2 -1
- package/dist/web/bridges/mcp-app/adaptor.js +8 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/types.d.ts +8 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/hooks/index.d.ts +1 -0
- package/dist/web/hooks/index.js +1 -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-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/package.json +5 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command, type Command as CommandLoadable, Help } from "@oclif/core";
|
|
2
|
+
export default class Create extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static strict: boolean;
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare class SkybridgeHelp extends Help {
|
|
8
|
+
showCommandHelp(command: CommandLoadable.Loadable): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Command, Help } from "@oclif/core";
|
|
2
|
+
import spawn from "cross-spawn";
|
|
3
|
+
function passthrough(args) {
|
|
4
|
+
const { status, error } = spawn.sync("npx", ["--yes", "create-skybridge@latest", ...args], { stdio: "inherit" });
|
|
5
|
+
if (error) {
|
|
6
|
+
console.error(error);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
process.exit(status ?? 1);
|
|
10
|
+
}
|
|
11
|
+
export default class Create extends Command {
|
|
12
|
+
static description = "Scaffold a new Skybridge project";
|
|
13
|
+
static strict = false;
|
|
14
|
+
async run() {
|
|
15
|
+
passthrough(this.argv);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Registered as `oclif.helpClass` so that `skybridge create --help` forwards
|
|
19
|
+
// to `create-skybridge --help` (single source of truth for the help text)
|
|
20
|
+
// instead of rendering oclif's auto-generated help. All other commands fall
|
|
21
|
+
// through to the default `Help` behaviour.
|
|
22
|
+
export class SkybridgeHelp extends Help {
|
|
23
|
+
async showCommandHelp(command) {
|
|
24
|
+
if (command.id === "create") {
|
|
25
|
+
passthrough(["--help"]);
|
|
26
|
+
}
|
|
27
|
+
return super.showCommandHelp(command);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAmC,IAAI,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,SAAS,WAAW,CAAC,IAAc;IACjC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,IAAI,CAClC,KAAK,EACL,CAAC,OAAO,EAAE,yBAAyB,EAAE,GAAG,IAAI,CAAC,EAC7C,EAAE,KAAK,EAAE,SAAS,EAAE,CACrB,CAAC;IACF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,OAAO;IACzC,MAAM,CAAU,WAAW,GAAG,kCAAkC,CAAC;IACjE,MAAM,CAAU,MAAM,GAAG,KAAK,CAAC;IAExB,KAAK,CAAC,GAAG;QACd,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;;AAGH,6EAA6E;AAC7E,0EAA0E;AAC1E,4EAA4E;AAC5E,2CAA2C;AAC3C,MAAM,OAAO,aAAc,SAAQ,IAAI;IAC5B,KAAK,CAAC,eAAe,CAC5B,OAAiC;QAEjC,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC5B,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { Command, type Command as CommandLoadable, Help } from \"@oclif/core\";\nimport spawn from \"cross-spawn\";\n\nfunction passthrough(args: string[]): never {\n const { status, error } = spawn.sync(\n \"npx\",\n [\"--yes\", \"create-skybridge@latest\", ...args],\n { stdio: \"inherit\" },\n );\n if (error) {\n console.error(error);\n process.exit(1);\n }\n process.exit(status ?? 1);\n}\n\nexport default class Create extends Command {\n static override description = \"Scaffold a new Skybridge project\";\n static override strict = false;\n\n public async run(): Promise<void> {\n passthrough(this.argv);\n }\n}\n\n// Registered as `oclif.helpClass` so that `skybridge create --help` forwards\n// to `create-skybridge --help` (single source of truth for the help text)\n// instead of rendering oclif's auto-generated help. All other commands fall\n// through to the default `Help` behaviour.\nexport class SkybridgeHelp extends Help {\n override async showCommandHelp(\n command: CommandLoadable.Loadable,\n ): Promise<void> {\n if (command.id === \"create\") {\n passthrough([\"--help\"]);\n }\n return super.showCommandHelp(command);\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type BearerAuthMiddlewareOptions } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
2
|
+
import type { RequestHandler } from "express";
|
|
3
|
+
export { InvalidTokenError } from "@modelcontextprotocol/sdk/server/auth/errors.js";
|
|
4
|
+
export { type BearerAuthMiddlewareOptions, requireBearerAuth, } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
5
|
+
export { type AuthMetadataOptions, mcpAuthMetadataRouter, } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
6
|
+
export type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Like `requireBearerAuth`, but lets requests through when no
|
|
9
|
+
* `Authorization` header is present. Used for mixed-auth servers where some
|
|
10
|
+
* tools are public and others require sign-in: each tool enforces its own
|
|
11
|
+
* `securitySchemes` against `extra.authInfo`.
|
|
12
|
+
*
|
|
13
|
+
* Behavior:
|
|
14
|
+
* - No `Authorization` header → `next()` without `req.auth`.
|
|
15
|
+
* - Valid Bearer token → `req.auth` set, same as `requireBearerAuth`.
|
|
16
|
+
* - Invalid / malformed / expired / insufficient-scope → same error response
|
|
17
|
+
* as `requireBearerAuth` (401/403). Sending a bad token is still a client
|
|
18
|
+
* error.
|
|
19
|
+
*/
|
|
20
|
+
export declare function optionalBearerAuth(options: BearerAuthMiddlewareOptions): RequestHandler;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { requireBearerAuth, } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
2
|
+
export { InvalidTokenError } from "@modelcontextprotocol/sdk/server/auth/errors.js";
|
|
3
|
+
export { requireBearerAuth, } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
4
|
+
export { mcpAuthMetadataRouter, } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
5
|
+
/**
|
|
6
|
+
* Like `requireBearerAuth`, but lets requests through when no
|
|
7
|
+
* `Authorization` header is present. Used for mixed-auth servers where some
|
|
8
|
+
* tools are public and others require sign-in: each tool enforces its own
|
|
9
|
+
* `securitySchemes` against `extra.authInfo`.
|
|
10
|
+
*
|
|
11
|
+
* Behavior:
|
|
12
|
+
* - No `Authorization` header → `next()` without `req.auth`.
|
|
13
|
+
* - Valid Bearer token → `req.auth` set, same as `requireBearerAuth`.
|
|
14
|
+
* - Invalid / malformed / expired / insufficient-scope → same error response
|
|
15
|
+
* as `requireBearerAuth` (401/403). Sending a bad token is still a client
|
|
16
|
+
* error.
|
|
17
|
+
*/
|
|
18
|
+
export function optionalBearerAuth(options) {
|
|
19
|
+
const required = requireBearerAuth(options);
|
|
20
|
+
return (req, res, next) => {
|
|
21
|
+
if (!req.headers.authorization) {
|
|
22
|
+
next();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
return required(req, res, next);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAClB,MAAM,gEAAgE,CAAC;AAIxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACpF,OAAO,EAEL,iBAAiB,GAClB,MAAM,gEAAgE,CAAC;AACxE,OAAO,EAEL,qBAAqB,GACtB,MAAM,iDAAiD,CAAC;AAGzD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAoC;IAEpC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACxB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC/B,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QACD,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type BearerAuthMiddlewareOptions,\n requireBearerAuth,\n} from \"@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js\";\n\nimport type { RequestHandler } from \"express\";\n\nexport { InvalidTokenError } from \"@modelcontextprotocol/sdk/server/auth/errors.js\";\nexport {\n type BearerAuthMiddlewareOptions,\n requireBearerAuth,\n} from \"@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js\";\nexport {\n type AuthMetadataOptions,\n mcpAuthMetadataRouter,\n} from \"@modelcontextprotocol/sdk/server/auth/router.js\";\nexport type { AuthInfo } from \"@modelcontextprotocol/sdk/server/auth/types.js\";\n\n/**\n * Like `requireBearerAuth`, but lets requests through when no\n * `Authorization` header is present. Used for mixed-auth servers where some\n * tools are public and others require sign-in: each tool enforces its own\n * `securitySchemes` against `extra.authInfo`.\n *\n * Behavior:\n * - No `Authorization` header → `next()` without `req.auth`.\n * - Valid Bearer token → `req.auth` set, same as `requireBearerAuth`.\n * - Invalid / malformed / expired / insufficient-scope → same error response\n * as `requireBearerAuth` (401/403). Sending a bad token is still a client\n * error.\n */\nexport function optionalBearerAuth(\n options: BearerAuthMiddlewareOptions,\n): RequestHandler {\n const required = requireBearerAuth(options);\n return (req, res, next) => {\n if (!req.headers.authorization) {\n next();\n return;\n }\n return required(req, res, next);\n };\n}\n"]}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { type AuthInfo, type AuthMetadataOptions, type BearerAuthMiddlewareOptions, InvalidTokenError, mcpAuthMetadataRouter, optionalBearerAuth, requireBearerAuth, } from "./auth.js";
|
|
1
2
|
export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
|
|
2
3
|
export { FileRef } from "./file-ref.js";
|
|
3
4
|
export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
|
|
4
5
|
export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
|
|
5
|
-
export type { HandlerContent, KnownToolMeta, McpServerTypes, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewHostType, ViewName, ViewNameRegistry, } from "./server.js";
|
|
6
|
+
export type { HandlerContent, KnownToolMeta, McpServerTypes, SecurityScheme, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewHostType, ViewName, ViewNameRegistry, } from "./server.js";
|
|
6
7
|
export { McpServer, normalizeContent, } from "./server.js";
|
|
7
8
|
export { viewsDevServer } from "./viewsDevServer.js";
|
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { InvalidTokenError, mcpAuthMetadataRouter, optionalBearerAuth, requireBearerAuth, } from "./auth.js";
|
|
1
2
|
export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
|
|
2
3
|
export { FileRef } from "./file-ref.js";
|
|
3
4
|
export { McpServer, normalizeContent, } from "./server.js";
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA+BxC,OAAO,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type AuthInfo,\n type AuthMetadataOptions,\n type BearerAuthMiddlewareOptions,\n InvalidTokenError,\n mcpAuthMetadataRouter,\n optionalBearerAuth,\n requireBearerAuth,\n} from \"./auth.js\";\nexport {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\nexport { FileRef } from \"./file-ref.js\";\nexport type {\n AnyToolRegistry,\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"./inferUtilityTypes.js\";\nexport type {\n McpExtra,\n McpMethodString,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nexport type {\n HandlerContent,\n KnownToolMeta,\n McpServerTypes,\n SecurityScheme,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewHostType,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -36,12 +36,19 @@ export interface ViewConfig {
|
|
|
36
36
|
csp?: ViewCsp;
|
|
37
37
|
_meta?: Record<string, unknown>;
|
|
38
38
|
}
|
|
39
|
+
export type SecurityScheme = {
|
|
40
|
+
type: "noauth";
|
|
41
|
+
} | {
|
|
42
|
+
type: "oauth2";
|
|
43
|
+
scopes?: string[];
|
|
44
|
+
};
|
|
39
45
|
export interface KnownToolMeta {
|
|
40
46
|
"openai/widgetAccessible"?: boolean;
|
|
41
47
|
"openai/toolInvocation/invoking"?: string;
|
|
42
48
|
"openai/toolInvocation/invoked"?: string;
|
|
43
49
|
"openai/fileParams"?: string[];
|
|
44
50
|
ui?: Pick<McpUiToolMeta, "visibility">;
|
|
51
|
+
securitySchemes?: SecurityScheme[];
|
|
45
52
|
}
|
|
46
53
|
export type ToolMeta = KnownToolMeta & Record<string, unknown>;
|
|
47
54
|
export type HandlerContent = string | ContentBlock | ContentBlock[];
|
|
@@ -87,6 +94,14 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
|
|
|
87
94
|
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
88
95
|
annotations?: ToolAnnotations;
|
|
89
96
|
view?: ViewConfig;
|
|
97
|
+
/**
|
|
98
|
+
* Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
|
|
99
|
+
* Lets clients label tools that require sign-in before calling, and pass
|
|
100
|
+
* the right scopes through the OAuth flow. Listing both `noauth` and
|
|
101
|
+
* `oauth2` signals that the tool works for anonymous callers and gives
|
|
102
|
+
* enhanced behavior to authenticated ones.
|
|
103
|
+
*/
|
|
104
|
+
securitySchemes?: SecurityScheme[];
|
|
90
105
|
_meta?: ToolMeta;
|
|
91
106
|
}
|
|
92
107
|
/**
|
package/dist/server/server.js
CHANGED
|
@@ -454,8 +454,16 @@ export class McpServer extends McpServerBaseOmitted {
|
|
|
454
454
|
}
|
|
455
455
|
const config = args[0];
|
|
456
456
|
const cb = args[1];
|
|
457
|
-
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
457
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
458
458
|
const toolMeta = { ...userToolMeta };
|
|
459
|
+
if (securitySchemes) {
|
|
460
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
461
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
462
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
463
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
464
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
465
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
466
|
+
}
|
|
459
467
|
if (view) {
|
|
460
468
|
this.enforceOneToolPerView(view.component, name);
|
|
461
469
|
this.registerViewResources(name, view, toolMeta);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EACL,MAAM,IAAI,SAAS,GAEpB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAgBrF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,OAAO,EAAE,EAIf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAYpD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,cAAc,GAAG,CACrB,MAAS,EACT,MAAS,EACF,EAAE;IACT,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;QACxD,IAAI,KAAK,CAAC,OAAO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AAC;QACxD,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAmC,CAAC;QAErD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC;QAElE,MAAM,QAAQ,GAAqB,EAAE,GAAG,YAAY,EAAE,CAAC;QAEvD,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACjD,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE1E,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC;QAEvE,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import crypto from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport http from \"node:http\";\nimport path from \"node:path\";\nimport type {\n McpUiResourceMeta,\n McpUiToolMeta,\n} from \"@modelcontextprotocol/ext-apps\";\nimport {\n Server as SdkServer,\n type ServerOptions,\n} from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { McpServer as McpServerBase } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type {\n AnySchema,\n SchemaOutput,\n ZodRawShapeCompat,\n} from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n ContentBlock,\n Implementation,\n RequestMeta,\n ServerNotification,\n ServerRequest,\n ServerResult,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { mergeWith, union } from \"es-toolkit\";\nimport express, {\n type ErrorRequestHandler,\n type Express,\n type RequestHandler,\n} from \"express\";\nimport { createApp } from \"./express.js\";\nimport { createMiddlewareEntry } from \"./metric.js\";\nimport type {\n McpExtra,\n McpExtraFor,\n McpMethodString,\n McpMiddlewareEntry,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nimport { buildMiddlewareChain, getHandlerMaps } from \"./middleware.js\";\nimport { templateHelper } from \"./templateHelper.js\";\n\nconst mergeWithUnion = <T extends object, S extends object>(\n target: T,\n source: S,\n): T & S => {\n return mergeWith(target, source, (targetVal, sourceVal) => {\n if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {\n return union(targetVal, sourceVal);\n }\n });\n};\n\nexport type ToolDef<\n TInput = unknown,\n TOutput = unknown,\n TResponseMetadata = unknown,\n> = {\n input: TInput;\n output: TOutput;\n responseMetadata: TResponseMetadata;\n};\n\nexport type ViewHostType = \"apps-sdk\" | \"mcp-app\";\n\nexport interface ViewCsp {\n /** Origins for static assets (images, fonts, scripts, styles). */\n resourceDomains?: string[];\n /** Origins the view may contact via fetch/XHR. */\n connectDomains?: string[];\n /** Origins allowed for iframe embeds (opts into stricter app review). */\n frameDomains?: string[];\n /** Origins that can receive openExternal redirects without the safe-link modal. */\n redirectDomains?: string[];\n /** Origins allowed in `<base href>` tags (mcp-apps only). */\n baseUriDomains?: string[];\n}\n\n// Must be exported: TS module augmentation only merges with exported\n// declarations. Without `export`, `.skybridge/views.d.ts` augmentation\n// would create a separate interface and `ViewName` would stay `string`.\n// biome-ignore lint/suspicious/noEmptyInterface: register pattern — augmented by `.skybridge/views.d.ts` to narrow ViewName\nexport interface ViewNameRegistry {}\n\nexport type ViewName = keyof ViewNameRegistry & string;\n\nexport interface ViewConfig {\n component: ViewName;\n description?: string;\n hosts?: ViewHostType[];\n prefersBorder?: boolean;\n domain?: string;\n csp?: ViewCsp;\n _meta?: Record<string, unknown>;\n}\n\nexport interface KnownToolMeta {\n \"openai/widgetAccessible\"?: boolean;\n \"openai/toolInvocation/invoking\"?: string;\n \"openai/toolInvocation/invoked\"?: string;\n \"openai/fileParams\"?: string[];\n ui?: Pick<McpUiToolMeta, \"visibility\">;\n}\n\nexport type ToolMeta = KnownToolMeta & Record<string, unknown>;\n\nexport type HandlerContent = string | ContentBlock | ContentBlock[];\n\n/** @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters */\ntype ViteManifestEntry = {\n file: string;\n name?: string;\n src?: string;\n isEntry?: boolean;\n isDynamicEntry?: boolean;\n css?: string[];\n assets?: string[];\n imports?: string[];\n dynamicImports?: string[];\n};\n\ntype OpenaiToolMeta = {\n \"openai/outputTemplate\": string;\n \"openai/widgetAccessible\"?: boolean;\n \"openai/toolInvocation/invoking\"?: string;\n \"openai/toolInvocation/invoked\"?: string;\n \"openai/fileParams\"?: string[];\n};\n\n/** @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#resource-discovery */\ntype McpAppsToolMeta = {\n ui: McpUiToolMeta;\n};\n\ntype InternalToolMeta = Partial<OpenaiToolMeta & McpAppsToolMeta>;\n\n/** @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields */\ntype OpenaiViewCSP = {\n connect_domains: string[];\n resource_domains: string[];\n frame_domains?: string[];\n redirect_domains?: string[];\n};\n\ntype OpenaiResourceMeta = {\n \"openai/widgetDescription\"?: string;\n \"openai/widgetPrefersBorder\"?: boolean;\n \"openai/widgetCSP\"?: OpenaiViewCSP;\n \"openai/widgetDomain\"?: string;\n};\n\n/**\n * MCP Apps CSP extended with upcoming / Skybridge-specific fields.\n * @see https://github.com/modelcontextprotocol/ext-apps/pull/158\n */\ntype ExtendedMcpUiResourceCsp = McpUiResourceMeta[\"csp\"] & {\n /**\n * Origins that can receive openExternal redirects without the safe-link modal.\n * OpenAI-specific; mirrored into the mcp-apps CSP for cross-host parity.\n * @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields\n */\n redirectDomains?: string[];\n};\n\ntype ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, \"csp\"> & {\n csp?: ExtendedMcpUiResourceCsp;\n};\n\ntype McpAppsResourceMeta = {\n ui?: ExtendedMcpUiResourceMeta;\n};\n\ntype ResourceMeta = OpenaiResourceMeta | McpAppsResourceMeta;\n\ntype ViewResourceConfig<T extends ResourceMeta = ResourceMeta> = {\n hostType: ViewHostType;\n uri: string;\n mimeType: string;\n buildContentMeta: (\n defaults: {\n resourceDomains: string[];\n connectDomains: string[];\n domain: string;\n baseUriDomains: string[];\n },\n overrides: { domain?: string },\n ) => T;\n};\n\n/**\n * Type-level marker interface for cross-package type inference.\n *\n * Consumers infer tool types via the structural `$types` property rather than\n * the `McpServer` class generic, because class-generic inference breaks when\n * `McpServer` comes from different package installations (e.g. a consumer\n * with its own `skybridge` dep vs. the in-tree workspace version).\n *\n * Inspired by tRPC's `_def` pattern and Hono's type markers.\n */\nexport interface McpServerTypes<TTools extends Record<string, ToolDef>> {\n readonly tools: TTools;\n}\n\ntype Simplify<T> = { [K in keyof T]: T[K] };\n\ntype ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<\n {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? never\n : K]: SchemaOutput<Shape[K]>;\n } & {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? K\n : never]?: SchemaOutput<Shape[K]>;\n }\n>;\n\ntype ExtractStructuredContent<T> = T extends { structuredContent: infer SC }\n ? Simplify<SC>\n : never;\n\ntype ExtractMeta<T> = [Extract<T, { _meta: unknown }>] extends [never]\n ? unknown\n : Extract<T, { _meta: unknown }> extends { _meta: infer M }\n ? Simplify<M>\n : unknown;\n\ntype AddTool<\n TTools,\n TName extends string,\n TInput extends ZodRawShapeCompat,\n TOutput,\n TResponseMetadata = unknown,\n> = McpServer<\n TTools & {\n [K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;\n }\n>;\n\ninterface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {\n name: string;\n title?: string;\n description?: string;\n inputSchema?: TInput;\n outputSchema?: ZodRawShapeCompat | AnySchema;\n annotations?: ToolAnnotations;\n view?: ViewConfig;\n _meta?: ToolMeta;\n}\n\n/**\n * Optional client-supplied hints attached to `params._meta` on every tool call\n * by the Apps SDK host. Hints only: never use for authorization, and tolerate\n * absence.\n * @see https://developers.openai.com/apps-sdk/reference#_meta-fields-the-client-provides\n */\nexport interface ClientHintsMeta {\n /** Requested locale (BCP-47, e.g. `\"en-US\"`). */\n \"openai/locale\"?: string;\n /** Browser user-agent */\n \"openai/userAgent\"?: string;\n /** Coarse user location. May be partially populated. */\n \"openai/userLocation\"?: {\n city?: string;\n region?: string;\n country?: string;\n timezone?: string;\n longitude?: number;\n latitude?: number;\n };\n /** Anonymized user id. */\n \"openai/subject\"?: string;\n /** Anonymized conversation id, stable within a ChatGPT session. */\n \"openai/session\"?: string;\n /** Anonymized organization id, when the user account is part of an organization. */\n \"openai/organization\"?: string;\n /** Stable id for the currently mounted widget instance. */\n \"openai/widgetSessionId\"?: string;\n}\n\ntype ToolHandlerExtra = Omit<\n RequestHandlerExtra<ServerRequest, ServerNotification>,\n \"_meta\"\n> & {\n _meta?: RequestMeta & ClientHintsMeta;\n};\n\ntype ToolHandler<\n TInput extends ZodRawShapeCompat,\n TReturn extends { content?: HandlerContent } = { content?: HandlerContent },\n> = (\n args: ShapeOutput<TInput>,\n extra: ToolHandlerExtra,\n) => TReturn | Promise<TReturn>;\n\ntype ErrorMiddlewareConfig = {\n path?: string;\n handlers: ErrorRequestHandler[];\n};\n\nexport function normalizeContent(\n content: HandlerContent | undefined,\n): ContentBlock[] {\n if (content === undefined) {\n return [];\n }\n if (typeof content === \"string\") {\n return [{ type: \"text\", text: content }];\n }\n if (Array.isArray(content)) {\n return content;\n }\n return [content];\n}\n\n// We Omit `registerTool` from the base class at the type level so our\n// unified 2-arg signature can replace the SDK's 3-arg one without an\n// incompatible override. The runtime prototype chain is unaffected.\ninterface McpServerBaseOmitted\n extends Omit<McpServerBase, \"registerTool\" | \"connect\"> {}\nconst McpServerBaseOmitted = McpServerBase as unknown as new (\n ...args: ConstructorParameters<typeof McpServerBase>\n) => McpServerBaseOmitted;\n\nexport class McpServer<\n TTools extends Record<string, ToolDef> = Record<never, ToolDef>,\n> extends McpServerBaseOmitted {\n declare readonly $types: McpServerTypes<TTools>;\n /**\n * The underlying Express app. Use this to extend the HTTP server with\n * custom routes, middleware, or settings — e.g.\n * `server.express.get(\"/health\", ...)`.\n *\n * `express.json()` is pre-applied. Register your handlers before `run()`;\n * after `run()`, dev-mode middleware, the `/mcp` route, and the default\n * error handler are appended in that order.\n *\n * Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work\n * locally and on self-hosted deployments.\n */\n readonly express: Express;\n private customErrorMiddleware: ErrorMiddlewareConfig[] = [];\n private mcpMiddlewareEntries: McpMiddlewareEntry[] = [];\n private mcpMiddlewareApplied = false;\n private claimedViews = new Map<string, string>();\n private viteManifest: Record<string, ViteManifestEntry> | null = null;\n private readonly serverInfo: Implementation;\n private readonly serverOptions?: ServerOptions;\n\n constructor(serverInfo: Implementation, options?: ServerOptions) {\n super(serverInfo, options);\n this.serverInfo = serverInfo;\n this.serverOptions = options;\n this.express = express();\n this.express.use(express.json());\n }\n\n use(...handlers: RequestHandler[]): this;\n use(path: string, ...handlers: RequestHandler[]): this;\n use(\n pathOrHandler: string | RequestHandler,\n ...handlers: RequestHandler[]\n ): this {\n // Branching is load-bearing: Express's `app.use` overloads can't be\n // resolved against a `string | RequestHandler` union, so we narrow.\n if (typeof pathOrHandler === \"string\") {\n this.express.use(pathOrHandler, ...handlers);\n } else {\n this.express.use(pathOrHandler, ...handlers);\n }\n return this;\n }\n\n useOnError(...handlers: ErrorRequestHandler[]): this;\n useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;\n useOnError(\n pathOrHandler: string | ErrorRequestHandler,\n ...handlers: ErrorRequestHandler[]\n ): this {\n if (typeof pathOrHandler === \"string\") {\n this.customErrorMiddleware.push({ path: pathOrHandler, handlers });\n } else {\n this.customErrorMiddleware.push({\n handlers: [pathOrHandler, ...handlers],\n });\n }\n return this;\n }\n\n /** Register MCP protocol-level middleware (catch-all). */\n mcpMiddleware(handler: McpMiddlewareFn): this;\n /** Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`). */\n mcpMiddleware(\n filter: \"request\",\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtra,\n next: () => Promise<ServerResult>,\n ) => Promise<unknown> | unknown,\n ): this;\n /** Register MCP protocol-level middleware for all notifications (`extra` is `undefined`). */\n mcpMiddleware(\n filter: \"notification\",\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: undefined,\n next: () => Promise<undefined>,\n ) => Promise<unknown> | unknown,\n ): this;\n /**\n * Register MCP protocol-level middleware for an exact method.\n * Narrows `params`, `extra`, and `next()` result based on the method string.\n */\n mcpMiddleware<M extends McpMethodString>(\n filter: M,\n handler: McpTypedMiddlewareFn<M>,\n ): this;\n /**\n * Register MCP protocol-level middleware for a wildcard pattern (e.g. `\"tools/*\"`).\n * `next()` returns the union of result types for matching methods.\n */\n mcpMiddleware<W extends McpWildcard>(\n filter: W,\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtraFor<W>,\n next: () => Promise<McpResultFor<W>>,\n ) => Promise<unknown> | unknown,\n ): this;\n /**\n * Register MCP protocol-level middleware with a method filter.\n * Filter can be an exact method (`\"tools/call\"`), wildcard (`\"tools/*\"`),\n * category (`\"request\"` | `\"notification\"`), or an array of those.\n */\n mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;\n mcpMiddleware(\n filterOrHandler: McpMiddlewareFilter | McpMiddlewareFn,\n // biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants\n maybeHandler?: any,\n ): this {\n if (this.mcpMiddlewareApplied) {\n throw new Error(\n \"Cannot register MCP middleware after run() or connect() has been called\",\n );\n }\n\n const handler = maybeHandler as McpMiddlewareFn | undefined;\n\n if (typeof filterOrHandler === \"function\") {\n this.mcpMiddlewareEntries.push({\n filter: null,\n handler: filterOrHandler,\n });\n } else if (handler) {\n this.mcpMiddlewareEntries.push({\n filter: filterOrHandler,\n handler,\n });\n } else {\n throw new Error(\n \"mcpMiddleware requires a handler function when a filter is provided\",\n );\n }\n\n return this;\n }\n\n private applyMcpMiddleware(): void {\n if (this.mcpMiddlewareApplied) {\n return;\n }\n this.mcpMiddlewareApplied = true;\n\n const monitoringEntry = createMiddlewareEntry();\n const entries = monitoringEntry\n ? [monitoringEntry, ...this.mcpMiddlewareEntries]\n : this.mcpMiddlewareEntries;\n\n if (entries.length === 0) {\n return;\n }\n\n const { requestHandlers, notificationHandlers } = getHandlerMaps(\n this.server,\n );\n\n const instrumentMap = (\n map: Map<string, (...args: unknown[]) => Promise<unknown>>,\n isNotification: boolean,\n ) => {\n for (const [method, handler] of map) {\n map.set(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n }\n const originalSet = map.set.bind(map);\n map.set = (\n method: string,\n handler: (...args: unknown[]) => Promise<unknown>,\n ) =>\n originalSet(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n };\n\n instrumentMap(requestHandlers, false);\n instrumentMap(notificationHandlers, true);\n }\n\n async connect(\n transport: Parameters<typeof McpServerBase.prototype.connect>[0],\n ): Promise<void> {\n this.applyMcpMiddleware();\n return McpServerBase.prototype.connect.call(this, transport);\n }\n\n /**\n * Per-request stateless connect. The SDK's `Protocol` only allows one\n * transport per instance, so we can't reuse this `McpServer` across\n * concurrent requests. The SDK's idiomatic fix is a `() => McpServer`\n * factory, but that would break Skybridge's singleton API — so instead\n * we build a fresh underlying `Server` per request and share the main\n * server's handler maps by reference. The cast is unavoidable: there's\n * no public API to inject handler maps. `getHandlerMaps` validates the\n * read side and fails fast on SDK field renames.\n */\n async connectStatelessTransport(\n transport: Parameters<typeof McpServerBase.prototype.connect>[0],\n ): Promise<void> {\n this.applyMcpMiddleware();\n\n const { requestHandlers, notificationHandlers } = getHandlerMaps(\n this.server,\n );\n const fresh = new SdkServer(this.serverInfo, this.serverOptions);\n const target = fresh as unknown as {\n _requestHandlers: unknown;\n _notificationHandlers: unknown;\n };\n target._requestHandlers = requestHandlers;\n target._notificationHandlers = notificationHandlers;\n\n await fresh.connect(transport);\n }\n\n async run(): Promise<{ fetch: (...args: unknown[]) => unknown } | undefined> {\n this.applyMcpMiddleware();\n const httpServer = http.createServer();\n\n await createApp({\n mcpServer: this,\n httpServer,\n errorMiddleware: this.customErrorMiddleware,\n });\n\n httpServer.on(\"request\", this.express);\n const port = parseInt(process.env.__PORT ?? \"3000\", 10);\n await new Promise<void>((resolve, reject) => {\n httpServer.on(\"error\", (error: Error) => {\n console.error(\"Failed to start server:\", error);\n reject(error);\n });\n httpServer.listen(port, () => {\n resolve();\n });\n });\n\n // On workerd, bridge the Node http server to a Workers fetch handler.\n // The specifier is held in a variable to sidestep tsc's module resolution\n // (`cloudflare:node` only exists under wrangler/workerd).\n if (\n typeof navigator !== \"undefined\" &&\n navigator.userAgent === \"Cloudflare-Workers\"\n ) {\n const cloudflareNode = \"cloudflare:node\";\n const { httpServerHandler } = await import(cloudflareNode);\n return httpServerHandler({ port });\n }\n\n const shutdown = () => {\n // Drop both handlers so a second signal falls through to Node's default\n // (force-quit on a second Ctrl+C while drain is hanging).\n process.off(\"SIGTERM\", shutdown);\n process.off(\"SIGINT\", shutdown);\n httpServer.close(() => process.exit(0));\n // Force exit if connections don't drain in time so the port is still\n // released promptly (e.g. for nodemon restarts).\n setTimeout(() => process.exit(0), 3000).unref();\n };\n process.on(\"SIGTERM\", shutdown);\n process.on(\"SIGINT\", shutdown);\n return undefined;\n }\n\n private enforceOneToolPerView(component: string, toolName: string): void {\n const existingTool = this.claimedViews.get(component);\n if (existingTool) {\n throw new Error(\n `skybridge: view \"${component}\" is already used by tool \"${existingTool}\". Tool \"${toolName}\" cannot also reference it — each view backs exactly one tool.`,\n );\n }\n this.claimedViews.set(component, toolName);\n }\n\n private registerViewResources(\n toolName: string,\n view: ViewConfig,\n toolMeta: InternalToolMeta,\n ): void {\n const hosts = view.hosts ?? ([\"apps-sdk\", \"mcp-app\"] as const);\n\n // Append a content-derived version param so hosts (e.g. ChatGPT) bust\n // their cache when the bundle changes, but keep the URI stable across\n // `tools/list` calls when the bundle hasn't changed.\n const versionParam = this.computeViewVersionParam(view.component);\n\n if (hosts.includes(\"apps-sdk\")) {\n const viewResource: ViewResourceConfig<OpenaiResourceMeta> = {\n hostType: \"apps-sdk\",\n uri: `ui://views/apps-sdk/${view.component}.html${versionParam}`,\n mimeType: \"text/html+skybridge\",\n buildContentMeta: (\n { resourceDomains, connectDomains, domain },\n overrides,\n ) => {\n const defaults: OpenaiResourceMeta = {\n \"openai/widgetCSP\": {\n resource_domains: resourceDomains,\n connect_domains: connectDomains,\n },\n \"openai/widgetDomain\": domain,\n \"openai/widgetDescription\": view.description,\n };\n\n const fromView: Partial<\n Omit<\n OpenaiResourceMeta,\n \"openai/widgetCSP\" | \"openai/widgetDescription\"\n > & {\n \"openai/widgetCSP\": Partial<OpenaiViewCSP>;\n }\n > = {\n \"openai/widgetCSP\": {\n resource_domains: view.csp?.resourceDomains,\n connect_domains: view.csp?.connectDomains,\n frame_domains: view.csp?.frameDomains,\n redirect_domains: view.csp?.redirectDomains,\n },\n \"openai/widgetDomain\": view.domain,\n \"openai/widgetPrefersBorder\": view.prefersBorder,\n };\n\n const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {\n \"openai/widgetDomain\": overrides.domain,\n });\n\n if (view._meta) {\n return { ...base, ...view._meta } as OpenaiResourceMeta;\n }\n return base;\n },\n };\n this.registerViewResource({\n name: toolName,\n viewResource,\n view,\n });\n toolMeta[\"openai/outputTemplate\"] = viewResource.uri;\n }\n\n if (hosts.includes(\"mcp-app\")) {\n const viewResource: ViewResourceConfig<McpAppsResourceMeta> = {\n hostType: \"mcp-app\",\n uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,\n mimeType: \"text/html;profile=mcp-app\",\n buildContentMeta: (\n { resourceDomains, connectDomains, domain, baseUriDomains },\n overrides,\n ) => {\n const defaults: McpAppsResourceMeta = {\n ui: {\n csp: {\n resourceDomains,\n connectDomains,\n baseUriDomains,\n },\n domain,\n },\n };\n\n const fromView: McpAppsResourceMeta = {\n ui: {\n ...(view.description && { description: view.description }),\n ...(view.prefersBorder !== undefined && {\n prefersBorder: view.prefersBorder,\n }),\n ...(view.domain && { domain: view.domain }),\n csp: {\n ...(view.csp?.resourceDomains && {\n resourceDomains: view.csp.resourceDomains,\n }),\n ...(view.csp?.connectDomains && {\n connectDomains: view.csp.connectDomains,\n }),\n ...(view.csp?.frameDomains && {\n frameDomains: view.csp.frameDomains,\n }),\n ...(view.csp?.baseUriDomains && {\n baseUriDomains: view.csp.baseUriDomains,\n }),\n ...(view.csp?.redirectDomains && {\n redirectDomains: view.csp.redirectDomains,\n }),\n },\n },\n };\n\n const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {\n ui: overrides,\n });\n\n if (view._meta) {\n return { ...base, ...view._meta } as McpAppsResourceMeta;\n }\n return base;\n },\n };\n this.registerViewResource({\n name: toolName,\n viewResource,\n view,\n });\n // @ts-expect-error - For backwards compatibility with Claude current implementation of the specs\n toolMeta[\"ui/resourceUri\"] = viewResource.uri;\n\n toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };\n }\n }\n\n private registerViewResource({\n name,\n viewResource,\n view,\n }: {\n name: string;\n viewResource: ViewResourceConfig;\n view: ViewConfig;\n }): void {\n const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;\n\n this.registerResource(\n name,\n viewUri,\n { description: view.description },\n async (uri, extra) => {\n const isProduction = process.env.NODE_ENV === \"production\";\n const isClaude =\n extra?.requestInfo?.headers?.[\"user-agent\"] === \"Claude-User\";\n\n const headers = extra?.requestInfo?.headers || {};\n const header = (key: string) => {\n const val = headers[key];\n return Array.isArray(val) ? val[0] : val;\n };\n\n let serverUrl: string;\n\n const forwardedHost = header(\"x-forwarded-host\");\n const origin = header(\"origin\");\n const host = header(\"host\");\n\n if (forwardedHost) {\n const proto = header(\"x-forwarded-proto\") || \"https\";\n serverUrl = `${proto}://${forwardedHost}`;\n } else if (origin) {\n serverUrl = origin;\n } else if (host) {\n const proto = [\"127.0.0.1:\", \"localhost:\"].some((p) =>\n host.startsWith(p),\n )\n ? \"http\"\n : \"https\";\n serverUrl = `${proto}://${host}`;\n } else {\n const devPort = process.env.__PORT || \"3000\";\n serverUrl = `http://localhost:${devPort}`;\n }\n\n const html = isProduction\n ? templateHelper.renderProduction({\n hostType,\n serverUrl,\n viewFile: this.lookupViewFile(view.component),\n styleFile: this.lookupDistFile(\"style.css\") ?? \"\",\n })\n : templateHelper.renderDevelopment({\n hostType,\n serverUrl,\n viewName: view.component,\n });\n\n const connectDomains = [serverUrl];\n if (!isProduction) {\n const wsUrl = new URL(serverUrl);\n wsUrl.protocol = wsUrl.protocol === \"https:\" ? \"wss:\" : \"ws:\";\n connectDomains.push(wsUrl.origin);\n }\n\n let contentMetaOverrides: { domain?: string } = {};\n if (isClaude) {\n const pathname = extra?.requestInfo?.url?.pathname ?? \"\";\n const rawUrl =\n header(\"x-alpic-forwarded-url\") ?? `${serverUrl}${pathname}`;\n // Strip a lone trailing slash so the hash matches the connector URL\n // as registered with Claude (which has no trailing slash on bare origins).\n const url = rawUrl.endsWith(\"/\") ? rawUrl.slice(0, -1) : rawUrl;\n const hash = crypto\n .createHash(\"sha256\")\n .update(url)\n .digest(\"hex\")\n .slice(0, 32);\n contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };\n }\n\n const contentMeta = buildContentMeta(\n {\n resourceDomains: [serverUrl],\n connectDomains,\n domain: serverUrl,\n baseUriDomains: [serverUrl],\n },\n contentMetaOverrides,\n );\n\n return {\n contents: [\n { uri: uri.href, mimeType, text: html, _meta: contentMeta },\n ],\n };\n },\n );\n }\n\n private wrapHandler<InputArgs extends ZodRawShapeCompat>(\n cb: ToolHandler<InputArgs>,\n { attachViewUUID }: { attachViewUUID: boolean },\n ): ToolHandler<InputArgs> {\n return async (args, extra) => {\n const result = await cb(args, extra);\n return {\n ...result,\n content: normalizeContent(result.content),\n ...(attachViewUUID && {\n _meta: {\n ...(result as { _meta?: Record<string, unknown> })._meta,\n viewUUID: crypto.randomUUID(),\n },\n }),\n };\n };\n }\n\n private computeViewVersionParam(viewName: string): string {\n if (process.env.NODE_ENV !== \"production\") {\n return \"\";\n }\n try {\n const viewFile = this.lookupViewFile(viewName);\n const styleFile = this.lookupDistFile(\"style.css\") ?? \"\";\n const hash = crypto\n .createHash(\"sha256\")\n .update(viewFile)\n .update(\"\\0\")\n .update(styleFile)\n .digest(\"hex\")\n .slice(0, 8);\n return `?v=${hash}`;\n } catch {\n return \"\";\n }\n }\n\n private lookupViewFile(viewName: string) {\n const manifest = this.readManifest();\n for (const entry of Object.values(manifest)) {\n if (entry?.isEntry && entry.name === viewName && entry.file) {\n return entry.file;\n }\n }\n throw new Error(\n `View \"${viewName}\" not found in Vite manifest. Did the build complete successfully? Look for an entry with name \"${viewName}\" in dist/assets/.vite/manifest.json.`,\n );\n }\n\n private lookupDistFile(key: string) {\n const manifest = this.readManifest();\n return manifest[key]?.file;\n }\n\n /**\n * Inject the Vite manifest as a value rather than letting `readManifest()`\n * load it from disk. Required for runtimes without a usable filesystem\n * (Cloudflare Workers, etc.) — the user's `skybridge build` emits the\n * manifest as a JS module which the entry imports and passes here.\n */\n setViteManifest(manifest: Record<string, { file: string }>): this {\n this.viteManifest = manifest as Record<string, ViteManifestEntry>;\n return this;\n }\n\n private readManifest(): Record<string, ViteManifestEntry> {\n if (this.viteManifest) {\n return this.viteManifest;\n }\n return JSON.parse(\n readFileSync(\n path.join(process.cwd(), \"dist\", \"assets\", \".vite\", \"manifest.json\"),\n \"utf-8\",\n ),\n );\n }\n\n registerTool<\n TName extends string,\n InputArgs extends ZodRawShapeCompat,\n TReturn extends { content?: HandlerContent },\n >(\n config: ToolConfig<InputArgs> & { name: TName },\n cb: ToolHandler<InputArgs, TReturn>,\n ): AddTool<\n TTools,\n TName,\n InputArgs,\n ExtractStructuredContent<TReturn>,\n ExtractMeta<TReturn>\n >;\n registerTool<InputArgs extends ZodRawShapeCompat>(\n config: ToolConfig<InputArgs>,\n cb: ToolHandler<InputArgs>,\n ): this;\n registerTool(...args: unknown[]): unknown {\n const baseFn = McpServerBase.prototype.registerTool as (\n ...args: unknown[]\n ) => unknown;\n\n if (typeof args[0] === \"string\") {\n baseFn.call(this, args[0], args[1], args[2]);\n return this;\n }\n\n const config = args[0] as ToolConfig<ZodRawShapeCompat>;\n const cb = args[1] as ToolHandler<ZodRawShapeCompat>;\n\n const { name, view, _meta: userToolMeta, ...toolFields } = config;\n\n const toolMeta: InternalToolMeta = { ...userToolMeta };\n\n if (view) {\n this.enforceOneToolPerView(view.component, name);\n this.registerViewResources(name, view, toolMeta);\n }\n\n const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });\n\n baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);\n\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EACL,MAAM,IAAI,SAAS,GAEpB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAgBrF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,OAAO,EAAE,EAIf,MAAM,SAAS,CAAC;AAC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AC;IACd,CAAC;CACF","sourcesContent":["import crypto from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport http from \"node:http\";\nimport path from \"node:path\";\nimport type {\n McpUiResourceMeta,\n McpUiToolMeta,\n} from \"@modelcontextprotocol/ext-apps\";\nimport {\n Server as SdkServer,\n type ServerOptions,\n} from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { McpServer as McpServerBase } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type {\n AnySchema,\n SchemaOutput,\n ZodRawShapeCompat,\n} from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n ContentBlock,\n Implementation,\n RequestMeta,\n ServerNotification,\n ServerRequest,\n ServerResult,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { mergeWith, union } from \"es-toolkit\";\nimport express, {\n type ErrorRequestHandler,\n type Express,\n type RequestHandler,\n} from \"express\";\nimport { createApp } from \"./express.js\";\nimport { createMiddlewareEntry } from \"./metric.js\";\nimport type {\n McpExtra,\n McpExtraFor,\n McpMethodString,\n McpMiddlewareEntry,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nimport { buildMiddlewareChain, getHandlerMaps } from \"./middleware.js\";\nimport { templateHelper } from \"./templateHelper.js\";\n\nconst mergeWithUnion = <T extends object, S extends object>(\n target: T,\n source: S,\n): T & S => {\n return mergeWith(target, source, (targetVal, sourceVal) => {\n if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {\n return union(targetVal, sourceVal);\n }\n });\n};\n\nexport type ToolDef<\n TInput = unknown,\n TOutput = unknown,\n TResponseMetadata = unknown,\n> = {\n input: TInput;\n output: TOutput;\n responseMetadata: TResponseMetadata;\n};\n\nexport type ViewHostType = \"apps-sdk\" | \"mcp-app\";\n\nexport interface ViewCsp {\n /** Origins for static assets (images, fonts, scripts, styles). */\n resourceDomains?: string[];\n /** Origins the view may contact via fetch/XHR. */\n connectDomains?: string[];\n /** Origins allowed for iframe embeds (opts into stricter app review). */\n frameDomains?: string[];\n /** Origins that can receive openExternal redirects without the safe-link modal. */\n redirectDomains?: string[];\n /** Origins allowed in `<base href>` tags (mcp-apps only). */\n baseUriDomains?: string[];\n}\n\n// Must be exported: TS module augmentation only merges with exported\n// declarations. Without `export`, `.skybridge/views.d.ts` augmentation\n// would create a separate interface and `ViewName` would stay `string`.\n// biome-ignore lint/suspicious/noEmptyInterface: register pattern — augmented by `.skybridge/views.d.ts` to narrow ViewName\nexport interface ViewNameRegistry {}\n\nexport type ViewName = keyof ViewNameRegistry & string;\n\nexport interface ViewConfig {\n component: ViewName;\n description?: string;\n hosts?: ViewHostType[];\n prefersBorder?: boolean;\n domain?: string;\n csp?: ViewCsp;\n _meta?: Record<string, unknown>;\n}\n\nexport type SecurityScheme =\n | { type: \"noauth\" }\n | { type: \"oauth2\"; scopes?: string[] };\n\nexport interface KnownToolMeta {\n \"openai/widgetAccessible\"?: boolean;\n \"openai/toolInvocation/invoking\"?: string;\n \"openai/toolInvocation/invoked\"?: string;\n \"openai/fileParams\"?: string[];\n ui?: Pick<McpUiToolMeta, \"visibility\">;\n securitySchemes?: SecurityScheme[];\n}\n\nexport type ToolMeta = KnownToolMeta & Record<string, unknown>;\n\nexport type HandlerContent = string | ContentBlock | ContentBlock[];\n\n/** @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters */\ntype ViteManifestEntry = {\n file: string;\n name?: string;\n src?: string;\n isEntry?: boolean;\n isDynamicEntry?: boolean;\n css?: string[];\n assets?: string[];\n imports?: string[];\n dynamicImports?: string[];\n};\n\ntype OpenaiToolMeta = {\n \"openai/outputTemplate\": string;\n \"openai/widgetAccessible\"?: boolean;\n \"openai/toolInvocation/invoking\"?: string;\n \"openai/toolInvocation/invoked\"?: string;\n \"openai/fileParams\"?: string[];\n};\n\n/** @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#resource-discovery */\ntype McpAppsToolMeta = {\n ui: McpUiToolMeta;\n};\n\ntype SecuritySchemesToolMeta = {\n securitySchemes: SecurityScheme[];\n};\n\ntype InternalToolMeta = Partial<\n OpenaiToolMeta & McpAppsToolMeta & SecuritySchemesToolMeta\n>;\n\n/** @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields */\ntype OpenaiViewCSP = {\n connect_domains: string[];\n resource_domains: string[];\n frame_domains?: string[];\n redirect_domains?: string[];\n};\n\ntype OpenaiResourceMeta = {\n \"openai/widgetDescription\"?: string;\n \"openai/widgetPrefersBorder\"?: boolean;\n \"openai/widgetCSP\"?: OpenaiViewCSP;\n \"openai/widgetDomain\"?: string;\n};\n\n/**\n * MCP Apps CSP extended with upcoming / Skybridge-specific fields.\n * @see https://github.com/modelcontextprotocol/ext-apps/pull/158\n */\ntype ExtendedMcpUiResourceCsp = McpUiResourceMeta[\"csp\"] & {\n /**\n * Origins that can receive openExternal redirects without the safe-link modal.\n * OpenAI-specific; mirrored into the mcp-apps CSP for cross-host parity.\n * @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields\n */\n redirectDomains?: string[];\n};\n\ntype ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, \"csp\"> & {\n csp?: ExtendedMcpUiResourceCsp;\n};\n\ntype McpAppsResourceMeta = {\n ui?: ExtendedMcpUiResourceMeta;\n};\n\ntype ResourceMeta = OpenaiResourceMeta | McpAppsResourceMeta;\n\ntype ViewResourceConfig<T extends ResourceMeta = ResourceMeta> = {\n hostType: ViewHostType;\n uri: string;\n mimeType: string;\n buildContentMeta: (\n defaults: {\n resourceDomains: string[];\n connectDomains: string[];\n domain: string;\n baseUriDomains: string[];\n },\n overrides: { domain?: string },\n ) => T;\n};\n\n/**\n * Type-level marker interface for cross-package type inference.\n *\n * Consumers infer tool types via the structural `$types` property rather than\n * the `McpServer` class generic, because class-generic inference breaks when\n * `McpServer` comes from different package installations (e.g. a consumer\n * with its own `skybridge` dep vs. the in-tree workspace version).\n *\n * Inspired by tRPC's `_def` pattern and Hono's type markers.\n */\nexport interface McpServerTypes<TTools extends Record<string, ToolDef>> {\n readonly tools: TTools;\n}\n\ntype Simplify<T> = { [K in keyof T]: T[K] };\n\ntype ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<\n {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? never\n : K]: SchemaOutput<Shape[K]>;\n } & {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? K\n : never]?: SchemaOutput<Shape[K]>;\n }\n>;\n\ntype ExtractStructuredContent<T> = T extends { structuredContent: infer SC }\n ? Simplify<SC>\n : never;\n\ntype ExtractMeta<T> = [Extract<T, { _meta: unknown }>] extends [never]\n ? unknown\n : Extract<T, { _meta: unknown }> extends { _meta: infer M }\n ? Simplify<M>\n : unknown;\n\ntype AddTool<\n TTools,\n TName extends string,\n TInput extends ZodRawShapeCompat,\n TOutput,\n TResponseMetadata = unknown,\n> = McpServer<\n TTools & {\n [K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;\n }\n>;\n\ninterface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {\n name: string;\n title?: string;\n description?: string;\n inputSchema?: TInput;\n outputSchema?: ZodRawShapeCompat | AnySchema;\n annotations?: ToolAnnotations;\n view?: ViewConfig;\n /**\n * Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).\n * Lets clients label tools that require sign-in before calling, and pass\n * the right scopes through the OAuth flow. Listing both `noauth` and\n * `oauth2` signals that the tool works for anonymous callers and gives\n * enhanced behavior to authenticated ones.\n */\n securitySchemes?: SecurityScheme[];\n _meta?: ToolMeta;\n}\n\n/**\n * Optional client-supplied hints attached to `params._meta` on every tool call\n * by the Apps SDK host. Hints only: never use for authorization, and tolerate\n * absence.\n * @see https://developers.openai.com/apps-sdk/reference#_meta-fields-the-client-provides\n */\nexport interface ClientHintsMeta {\n /** Requested locale (BCP-47, e.g. `\"en-US\"`). */\n \"openai/locale\"?: string;\n /** Browser user-agent */\n \"openai/userAgent\"?: string;\n /** Coarse user location. May be partially populated. */\n \"openai/userLocation\"?: {\n city?: string;\n region?: string;\n country?: string;\n timezone?: string;\n longitude?: number;\n latitude?: number;\n };\n /** Anonymized user id. */\n \"openai/subject\"?: string;\n /** Anonymized conversation id, stable within a ChatGPT session. */\n \"openai/session\"?: string;\n /** Anonymized organization id, when the user account is part of an organization. */\n \"openai/organization\"?: string;\n /** Stable id for the currently mounted widget instance. */\n \"openai/widgetSessionId\"?: string;\n}\n\ntype ToolHandlerExtra = Omit<\n RequestHandlerExtra<ServerRequest, ServerNotification>,\n \"_meta\"\n> & {\n _meta?: RequestMeta & ClientHintsMeta;\n};\n\ntype ToolHandler<\n TInput extends ZodRawShapeCompat,\n TReturn extends { content?: HandlerContent } = { content?: HandlerContent },\n> = (\n args: ShapeOutput<TInput>,\n extra: ToolHandlerExtra,\n) => TReturn | Promise<TReturn>;\n\ntype ErrorMiddlewareConfig = {\n path?: string;\n handlers: ErrorRequestHandler[];\n};\n\nexport function normalizeContent(\n content: HandlerContent | undefined,\n): ContentBlock[] {\n if (content === undefined) {\n return [];\n }\n if (typeof content === \"string\") {\n return [{ type: \"text\", text: content }];\n }\n if (Array.isArray(content)) {\n return content;\n }\n return [content];\n}\n\n// We Omit `registerTool` from the base class at the type level so our\n// unified 2-arg signature can replace the SDK's 3-arg one without an\n// incompatible override. The runtime prototype chain is unaffected.\ninterface McpServerBaseOmitted\n extends Omit<McpServerBase, \"registerTool\" | \"connect\"> {}\nconst McpServerBaseOmitted = McpServerBase as unknown as new (\n ...args: ConstructorParameters<typeof McpServerBase>\n) => McpServerBaseOmitted;\n\nexport class McpServer<\n TTools extends Record<string, ToolDef> = Record<never, ToolDef>,\n> extends McpServerBaseOmitted {\n declare readonly $types: McpServerTypes<TTools>;\n /**\n * The underlying Express app. Use this to extend the HTTP server with\n * custom routes, middleware, or settings — e.g.\n * `server.express.get(\"/health\", ...)`.\n *\n * `express.json()` is pre-applied. Register your handlers before `run()`;\n * after `run()`, dev-mode middleware, the `/mcp` route, and the default\n * error handler are appended in that order.\n *\n * Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work\n * locally and on self-hosted deployments.\n */\n readonly express: Express;\n private customErrorMiddleware: ErrorMiddlewareConfig[] = [];\n private mcpMiddlewareEntries: McpMiddlewareEntry[] = [];\n private mcpMiddlewareApplied = false;\n private claimedViews = new Map<string, string>();\n private viteManifest: Record<string, ViteManifestEntry> | null = null;\n private readonly serverInfo: Implementation;\n private readonly serverOptions?: ServerOptions;\n\n constructor(serverInfo: Implementation, options?: ServerOptions) {\n super(serverInfo, options);\n this.serverInfo = serverInfo;\n this.serverOptions = options;\n this.express = express();\n this.express.use(express.json());\n }\n\n use(...handlers: RequestHandler[]): this;\n use(path: string, ...handlers: RequestHandler[]): this;\n use(\n pathOrHandler: string | RequestHandler,\n ...handlers: RequestHandler[]\n ): this {\n // Branching is load-bearing: Express's `app.use` overloads can't be\n // resolved against a `string | RequestHandler` union, so we narrow.\n if (typeof pathOrHandler === \"string\") {\n this.express.use(pathOrHandler, ...handlers);\n } else {\n this.express.use(pathOrHandler, ...handlers);\n }\n return this;\n }\n\n useOnError(...handlers: ErrorRequestHandler[]): this;\n useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;\n useOnError(\n pathOrHandler: string | ErrorRequestHandler,\n ...handlers: ErrorRequestHandler[]\n ): this {\n if (typeof pathOrHandler === \"string\") {\n this.customErrorMiddleware.push({ path: pathOrHandler, handlers });\n } else {\n this.customErrorMiddleware.push({\n handlers: [pathOrHandler, ...handlers],\n });\n }\n return this;\n }\n\n /** Register MCP protocol-level middleware (catch-all). */\n mcpMiddleware(handler: McpMiddlewareFn): this;\n /** Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`). */\n mcpMiddleware(\n filter: \"request\",\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtra,\n next: () => Promise<ServerResult>,\n ) => Promise<unknown> | unknown,\n ): this;\n /** Register MCP protocol-level middleware for all notifications (`extra` is `undefined`). */\n mcpMiddleware(\n filter: \"notification\",\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: undefined,\n next: () => Promise<undefined>,\n ) => Promise<unknown> | unknown,\n ): this;\n /**\n * Register MCP protocol-level middleware for an exact method.\n * Narrows `params`, `extra`, and `next()` result based on the method string.\n */\n mcpMiddleware<M extends McpMethodString>(\n filter: M,\n handler: McpTypedMiddlewareFn<M>,\n ): this;\n /**\n * Register MCP protocol-level middleware for a wildcard pattern (e.g. `\"tools/*\"`).\n * `next()` returns the union of result types for matching methods.\n */\n mcpMiddleware<W extends McpWildcard>(\n filter: W,\n handler: (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtraFor<W>,\n next: () => Promise<McpResultFor<W>>,\n ) => Promise<unknown> | unknown,\n ): this;\n /**\n * Register MCP protocol-level middleware with a method filter.\n * Filter can be an exact method (`\"tools/call\"`), wildcard (`\"tools/*\"`),\n * category (`\"request\"` | `\"notification\"`), or an array of those.\n */\n mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;\n mcpMiddleware(\n filterOrHandler: McpMiddlewareFilter | McpMiddlewareFn,\n // biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants\n maybeHandler?: any,\n ): this {\n if (this.mcpMiddlewareApplied) {\n throw new Error(\n \"Cannot register MCP middleware after run() or connect() has been called\",\n );\n }\n\n const handler = maybeHandler as McpMiddlewareFn | undefined;\n\n if (typeof filterOrHandler === \"function\") {\n this.mcpMiddlewareEntries.push({\n filter: null,\n handler: filterOrHandler,\n });\n } else if (handler) {\n this.mcpMiddlewareEntries.push({\n filter: filterOrHandler,\n handler,\n });\n } else {\n throw new Error(\n \"mcpMiddleware requires a handler function when a filter is provided\",\n );\n }\n\n return this;\n }\n\n private applyMcpMiddleware(): void {\n if (this.mcpMiddlewareApplied) {\n return;\n }\n this.mcpMiddlewareApplied = true;\n\n const monitoringEntry = createMiddlewareEntry();\n const entries = monitoringEntry\n ? [monitoringEntry, ...this.mcpMiddlewareEntries]\n : this.mcpMiddlewareEntries;\n\n if (entries.length === 0) {\n return;\n }\n\n const { requestHandlers, notificationHandlers } = getHandlerMaps(\n this.server,\n );\n\n const instrumentMap = (\n map: Map<string, (...args: unknown[]) => Promise<unknown>>,\n isNotification: boolean,\n ) => {\n for (const [method, handler] of map) {\n map.set(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n }\n const originalSet = map.set.bind(map);\n map.set = (\n method: string,\n handler: (...args: unknown[]) => Promise<unknown>,\n ) =>\n originalSet(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n };\n\n instrumentMap(requestHandlers, false);\n instrumentMap(notificationHandlers, true);\n }\n\n async connect(\n transport: Parameters<typeof McpServerBase.prototype.connect>[0],\n ): Promise<void> {\n this.applyMcpMiddleware();\n return McpServerBase.prototype.connect.call(this, transport);\n }\n\n /**\n * Per-request stateless connect. The SDK's `Protocol` only allows one\n * transport per instance, so we can't reuse this `McpServer` across\n * concurrent requests. The SDK's idiomatic fix is a `() => McpServer`\n * factory, but that would break Skybridge's singleton API — so instead\n * we build a fresh underlying `Server` per request and share the main\n * server's handler maps by reference. The cast is unavoidable: there's\n * no public API to inject handler maps. `getHandlerMaps` validates the\n * read side and fails fast on SDK field renames.\n */\n async connectStatelessTransport(\n transport: Parameters<typeof McpServerBase.prototype.connect>[0],\n ): Promise<void> {\n this.applyMcpMiddleware();\n\n const { requestHandlers, notificationHandlers } = getHandlerMaps(\n this.server,\n );\n const fresh = new SdkServer(this.serverInfo, this.serverOptions);\n const target = fresh as unknown as {\n _requestHandlers: unknown;\n _notificationHandlers: unknown;\n };\n target._requestHandlers = requestHandlers;\n target._notificationHandlers = notificationHandlers;\n\n await fresh.connect(transport);\n }\n\n async run(): Promise<{ fetch: (...args: unknown[]) => unknown } | undefined> {\n this.applyMcpMiddleware();\n const httpServer = http.createServer();\n\n await createApp({\n mcpServer: this,\n httpServer,\n errorMiddleware: this.customErrorMiddleware,\n });\n\n httpServer.on(\"request\", this.express);\n const port = parseInt(process.env.__PORT ?? \"3000\", 10);\n await new Promise<void>((resolve, reject) => {\n httpServer.on(\"error\", (error: Error) => {\n console.error(\"Failed to start server:\", error);\n reject(error);\n });\n httpServer.listen(port, () => {\n resolve();\n });\n });\n\n // On workerd, bridge the Node http server to a Workers fetch handler.\n // The specifier is held in a variable to sidestep tsc's module resolution\n // (`cloudflare:node` only exists under wrangler/workerd).\n if (\n typeof navigator !== \"undefined\" &&\n navigator.userAgent === \"Cloudflare-Workers\"\n ) {\n const cloudflareNode = \"cloudflare:node\";\n const { httpServerHandler } = await import(cloudflareNode);\n return httpServerHandler({ port });\n }\n\n const shutdown = () => {\n // Drop both handlers so a second signal falls through to Node's default\n // (force-quit on a second Ctrl+C while drain is hanging).\n process.off(\"SIGTERM\", shutdown);\n process.off(\"SIGINT\", shutdown);\n httpServer.close(() => process.exit(0));\n // Force exit if connections don't drain in time so the port is still\n // released promptly (e.g. for nodemon restarts).\n setTimeout(() => process.exit(0), 3000).unref();\n };\n process.on(\"SIGTERM\", shutdown);\n process.on(\"SIGINT\", shutdown);\n return undefined;\n }\n\n private enforceOneToolPerView(component: string, toolName: string): void {\n const existingTool = this.claimedViews.get(component);\n if (existingTool) {\n throw new Error(\n `skybridge: view \"${component}\" is already used by tool \"${existingTool}\". Tool \"${toolName}\" cannot also reference it — each view backs exactly one tool.`,\n );\n }\n this.claimedViews.set(component, toolName);\n }\n\n private registerViewResources(\n toolName: string,\n view: ViewConfig,\n toolMeta: InternalToolMeta,\n ): void {\n const hosts = view.hosts ?? ([\"apps-sdk\", \"mcp-app\"] as const);\n\n // Append a content-derived version param so hosts (e.g. ChatGPT) bust\n // their cache when the bundle changes, but keep the URI stable across\n // `tools/list` calls when the bundle hasn't changed.\n const versionParam = this.computeViewVersionParam(view.component);\n\n if (hosts.includes(\"apps-sdk\")) {\n const viewResource: ViewResourceConfig<OpenaiResourceMeta> = {\n hostType: \"apps-sdk\",\n uri: `ui://views/apps-sdk/${view.component}.html${versionParam}`,\n mimeType: \"text/html+skybridge\",\n buildContentMeta: (\n { resourceDomains, connectDomains, domain },\n overrides,\n ) => {\n const defaults: OpenaiResourceMeta = {\n \"openai/widgetCSP\": {\n resource_domains: resourceDomains,\n connect_domains: connectDomains,\n },\n \"openai/widgetDomain\": domain,\n \"openai/widgetDescription\": view.description,\n };\n\n const fromView: Partial<\n Omit<\n OpenaiResourceMeta,\n \"openai/widgetCSP\" | \"openai/widgetDescription\"\n > & {\n \"openai/widgetCSP\": Partial<OpenaiViewCSP>;\n }\n > = {\n \"openai/widgetCSP\": {\n resource_domains: view.csp?.resourceDomains,\n connect_domains: view.csp?.connectDomains,\n frame_domains: view.csp?.frameDomains,\n redirect_domains: view.csp?.redirectDomains,\n },\n \"openai/widgetDomain\": view.domain,\n \"openai/widgetPrefersBorder\": view.prefersBorder,\n };\n\n const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {\n \"openai/widgetDomain\": overrides.domain,\n });\n\n if (view._meta) {\n return { ...base, ...view._meta } as OpenaiResourceMeta;\n }\n return base;\n },\n };\n this.registerViewResource({\n name: toolName,\n viewResource,\n view,\n });\n toolMeta[\"openai/outputTemplate\"] = viewResource.uri;\n }\n\n if (hosts.includes(\"mcp-app\")) {\n const viewResource: ViewResourceConfig<McpAppsResourceMeta> = {\n hostType: \"mcp-app\",\n uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,\n mimeType: \"text/html;profile=mcp-app\",\n buildContentMeta: (\n { resourceDomains, connectDomains, domain, baseUriDomains },\n overrides,\n ) => {\n const defaults: McpAppsResourceMeta = {\n ui: {\n csp: {\n resourceDomains,\n connectDomains,\n baseUriDomains,\n },\n domain,\n },\n };\n\n const fromView: McpAppsResourceMeta = {\n ui: {\n ...(view.description && { description: view.description }),\n ...(view.prefersBorder !== undefined && {\n prefersBorder: view.prefersBorder,\n }),\n ...(view.domain && { domain: view.domain }),\n csp: {\n ...(view.csp?.resourceDomains && {\n resourceDomains: view.csp.resourceDomains,\n }),\n ...(view.csp?.connectDomains && {\n connectDomains: view.csp.connectDomains,\n }),\n ...(view.csp?.frameDomains && {\n frameDomains: view.csp.frameDomains,\n }),\n ...(view.csp?.baseUriDomains && {\n baseUriDomains: view.csp.baseUriDomains,\n }),\n ...(view.csp?.redirectDomains && {\n redirectDomains: view.csp.redirectDomains,\n }),\n },\n },\n };\n\n const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {\n ui: overrides,\n });\n\n if (view._meta) {\n return { ...base, ...view._meta } as McpAppsResourceMeta;\n }\n return base;\n },\n };\n this.registerViewResource({\n name: toolName,\n viewResource,\n view,\n });\n // @ts-expect-error - For backwards compatibility with Claude current implementation of the specs\n toolMeta[\"ui/resourceUri\"] = viewResource.uri;\n\n toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };\n }\n }\n\n private registerViewResource({\n name,\n viewResource,\n view,\n }: {\n name: string;\n viewResource: ViewResourceConfig;\n view: ViewConfig;\n }): void {\n const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;\n\n this.registerResource(\n name,\n viewUri,\n { description: view.description },\n async (uri, extra) => {\n const isProduction = process.env.NODE_ENV === \"production\";\n const isClaude =\n extra?.requestInfo?.headers?.[\"user-agent\"] === \"Claude-User\";\n\n const headers = extra?.requestInfo?.headers || {};\n const header = (key: string) => {\n const val = headers[key];\n return Array.isArray(val) ? val[0] : val;\n };\n\n let serverUrl: string;\n\n const forwardedHost = header(\"x-forwarded-host\");\n const origin = header(\"origin\");\n const host = header(\"host\");\n\n if (forwardedHost) {\n const proto = header(\"x-forwarded-proto\") || \"https\";\n serverUrl = `${proto}://${forwardedHost}`;\n } else if (origin) {\n serverUrl = origin;\n } else if (host) {\n const proto = [\"127.0.0.1:\", \"localhost:\"].some((p) =>\n host.startsWith(p),\n )\n ? \"http\"\n : \"https\";\n serverUrl = `${proto}://${host}`;\n } else {\n const devPort = process.env.__PORT || \"3000\";\n serverUrl = `http://localhost:${devPort}`;\n }\n\n const html = isProduction\n ? templateHelper.renderProduction({\n hostType,\n serverUrl,\n viewFile: this.lookupViewFile(view.component),\n styleFile: this.lookupDistFile(\"style.css\") ?? \"\",\n })\n : templateHelper.renderDevelopment({\n hostType,\n serverUrl,\n viewName: view.component,\n });\n\n const connectDomains = [serverUrl];\n if (!isProduction) {\n const wsUrl = new URL(serverUrl);\n wsUrl.protocol = wsUrl.protocol === \"https:\" ? \"wss:\" : \"ws:\";\n connectDomains.push(wsUrl.origin);\n }\n\n let contentMetaOverrides: { domain?: string } = {};\n if (isClaude) {\n const pathname = extra?.requestInfo?.url?.pathname ?? \"\";\n const rawUrl =\n header(\"x-alpic-forwarded-url\") ?? `${serverUrl}${pathname}`;\n // Strip a lone trailing slash so the hash matches the connector URL\n // as registered with Claude (which has no trailing slash on bare origins).\n const url = rawUrl.endsWith(\"/\") ? rawUrl.slice(0, -1) : rawUrl;\n const hash = crypto\n .createHash(\"sha256\")\n .update(url)\n .digest(\"hex\")\n .slice(0, 32);\n contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };\n }\n\n const contentMeta = buildContentMeta(\n {\n resourceDomains: [serverUrl],\n connectDomains,\n domain: serverUrl,\n baseUriDomains: [serverUrl],\n },\n contentMetaOverrides,\n );\n\n return {\n contents: [\n { uri: uri.href, mimeType, text: html, _meta: contentMeta },\n ],\n };\n },\n );\n }\n\n private wrapHandler<InputArgs extends ZodRawShapeCompat>(\n cb: ToolHandler<InputArgs>,\n { attachViewUUID }: { attachViewUUID: boolean },\n ): ToolHandler<InputArgs> {\n return async (args, extra) => {\n const result = await cb(args, extra);\n return {\n ...result,\n content: normalizeContent(result.content),\n ...(attachViewUUID && {\n _meta: {\n ...(result as { _meta?: Record<string, unknown> })._meta,\n viewUUID: crypto.randomUUID(),\n },\n }),\n };\n };\n }\n\n private computeViewVersionParam(viewName: string): string {\n if (process.env.NODE_ENV !== \"production\") {\n return \"\";\n }\n try {\n const viewFile = this.lookupViewFile(viewName);\n const styleFile = this.lookupDistFile(\"style.css\") ?? \"\";\n const hash = crypto\n .createHash(\"sha256\")\n .update(viewFile)\n .update(\"\\0\")\n .update(styleFile)\n .digest(\"hex\")\n .slice(0, 8);\n return `?v=${hash}`;\n } catch {\n return \"\";\n }\n }\n\n private lookupViewFile(viewName: string) {\n const manifest = this.readManifest();\n for (const entry of Object.values(manifest)) {\n if (entry?.isEntry && entry.name === viewName && entry.file) {\n return entry.file;\n }\n }\n throw new Error(\n `View \"${viewName}\" not found in Vite manifest. Did the build complete successfully? Look for an entry with name \"${viewName}\" in dist/assets/.vite/manifest.json.`,\n );\n }\n\n private lookupDistFile(key: string) {\n const manifest = this.readManifest();\n return manifest[key]?.file;\n }\n\n /**\n * Inject the Vite manifest as a value rather than letting `readManifest()`\n * load it from disk. Required for runtimes without a usable filesystem\n * (Cloudflare Workers, etc.) — the user's `skybridge build` emits the\n * manifest as a JS module which the entry imports and passes here.\n */\n setViteManifest(manifest: Record<string, { file: string }>): this {\n this.viteManifest = manifest as Record<string, ViteManifestEntry>;\n return this;\n }\n\n private readManifest(): Record<string, ViteManifestEntry> {\n if (this.viteManifest) {\n return this.viteManifest;\n }\n return JSON.parse(\n readFileSync(\n path.join(process.cwd(), \"dist\", \"assets\", \".vite\", \"manifest.json\"),\n \"utf-8\",\n ),\n );\n }\n\n registerTool<\n TName extends string,\n InputArgs extends ZodRawShapeCompat,\n TReturn extends { content?: HandlerContent },\n >(\n config: ToolConfig<InputArgs> & { name: TName },\n cb: ToolHandler<InputArgs, TReturn>,\n ): AddTool<\n TTools,\n TName,\n InputArgs,\n ExtractStructuredContent<TReturn>,\n ExtractMeta<TReturn>\n >;\n registerTool<InputArgs extends ZodRawShapeCompat>(\n config: ToolConfig<InputArgs>,\n cb: ToolHandler<InputArgs>,\n ): this;\n registerTool(...args: unknown[]): unknown {\n const baseFn = McpServerBase.prototype.registerTool as (\n ...args: unknown[]\n ) => unknown;\n\n if (typeof args[0] === \"string\") {\n baseFn.call(this, args[0], args[1], args[2]);\n return this;\n }\n\n const config = args[0] as ToolConfig<ZodRawShapeCompat>;\n const cb = args[1] as ToolHandler<ZodRawShapeCompat>;\n\n const {\n name,\n view,\n securitySchemes,\n _meta: userToolMeta,\n ...toolFields\n } = config;\n\n const toolMeta: InternalToolMeta = { ...userToolMeta };\n\n if (securitySchemes) {\n // SEP-1488 puts `securitySchemes` at the top level of the tool\n // descriptor, but the SDK's `registerTool` drops unknown top-level\n // fields, so the canonical spot isn't reachable without intercepting\n // `tools/list`. Use the `_meta` back-compat mirror documented in the\n // Apps SDK reference until SEP-1488 lands in the spec.\n toolMeta.securitySchemes = securitySchemes;\n }\n\n if (view) {\n this.enforceOneToolPerView(view.component, name);\n this.registerViewResources(name, view, toolMeta);\n }\n\n const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });\n\n baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);\n\n return this;\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Adaptor, CallToolResponse, FileMetadata, HostContext, HostContextStore, OpenExternalOptions, RequestDisplayMode, RequestModalOptions, RequestSizeOptions, SendFollowUpMessageOptions, SetViewStateAction, UploadFileOptions } from "../types.js";
|
|
1
|
+
import type { Adaptor, CallToolResponse, DownloadParams, DownloadResult, FileMetadata, HostContext, HostContextStore, OpenExternalOptions, RequestDisplayMode, RequestModalOptions, RequestSizeOptions, SendFollowUpMessageOptions, SetViewStateAction, UploadFileOptions } from "../types.js";
|
|
2
2
|
export declare class AppsSdkAdaptor implements Adaptor {
|
|
3
3
|
private static instance;
|
|
4
4
|
static getInstance(): AppsSdkAdaptor;
|
|
@@ -11,6 +11,7 @@ export declare class AppsSdkAdaptor implements Adaptor {
|
|
|
11
11
|
requestClose: () => Promise<void>;
|
|
12
12
|
requestSize: (_size: RequestSizeOptions) => Promise<void>;
|
|
13
13
|
sendFollowUpMessage: (prompt: string, options?: SendFollowUpMessageOptions) => Promise<void>;
|
|
14
|
+
download: (_params: DownloadParams) => Promise<DownloadResult>;
|
|
14
15
|
openExternal(href: string, options?: OpenExternalOptions): void;
|
|
15
16
|
setViewState: (stateOrUpdater: SetViewStateAction) => Promise<void>;
|
|
16
17
|
uploadFile: (file: File, options?: UploadFileOptions) => Promise<FileMetadata>;
|
|
@@ -53,6 +53,10 @@ export class AppsSdkAdaptor {
|
|
|
53
53
|
scrollToBottom: options?.scrollToBottom,
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
+
download = async (_params) => {
|
|
57
|
+
console.error("[skybridge] download: not supported on Apps SDK");
|
|
58
|
+
return { isError: true };
|
|
59
|
+
};
|
|
56
60
|
openExternal(href, options = {}) {
|
|
57
61
|
window.openai.openExternal({ href, ...options });
|
|
58
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/adaptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/adaptor.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,OAAO,cAAc;IACjB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAE/C,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;IACjC,CAAC;IAEM,mBAAmB,CACxB,GAAM;QAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;QA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AY,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC","sourcesContent":["import type {\n Adaptor,\n CallToolResponse,\n DownloadParams,\n DownloadResult,\n FileMetadata,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n UploadFileOptions,\n} from \"../types.js\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkWidgetState } from \"./types.js\";\n\nexport class AppsSdkAdaptor implements Adaptor {\n private static instance: AppsSdkAdaptor | null = null;\n\n public static getInstance(): AppsSdkAdaptor {\n if (!AppsSdkAdaptor.instance) {\n AppsSdkAdaptor.instance = new AppsSdkAdaptor();\n }\n return AppsSdkAdaptor.instance;\n }\n\n public static resetInstance(): void {\n AppsSdkAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n const bridge = AppsSdkBridge.getInstance();\n\n if (key === \"viewState\") {\n return {\n subscribe: bridge.subscribe(\"widgetState\"),\n getSnapshot: () =>\n bridge.getSnapshot(\"widgetState\")?.modelContent ?? null,\n } as HostContextStore<K>;\n }\n\n if (key === \"display\") {\n return {\n subscribe: bridge.subscribe(\"view\"),\n getSnapshot: () => bridge.getSnapshot(\"view\"),\n } as HostContextStore<K>;\n }\n\n return {\n subscribe: bridge.subscribe(key),\n getSnapshot: () => bridge.getSnapshot(key),\n } as HostContextStore<K>;\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const response = await (window.openai.callTool(name, args) as Promise<\n CallToolResponse & { _meta?: CallToolResponse[\"meta\"] }\n >);\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? response.meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = (\n mode: RequestDisplayMode,\n ): Promise<{ mode: RequestDisplayMode }> => {\n return window.openai.requestDisplayMode({ mode });\n };\n\n public requestClose = (): Promise<void> => {\n return window.openai.requestClose();\n };\n\n public requestSize = async (_size: RequestSizeOptions): Promise<void> => {\n console.warn(\"[skybridge] requestSize: not supported on Apps SDK\");\n };\n\n public sendFollowUpMessage = (\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void> => {\n return window.openai.sendFollowUpMessage({\n prompt,\n scrollToBottom: options?.scrollToBottom,\n });\n };\n\n public download = async (\n _params: DownloadParams,\n ): Promise<DownloadResult> => {\n console.error(\"[skybridge] download: not supported on Apps SDK\");\n return { isError: true };\n };\n\n public openExternal(href: string, options: OpenExternalOptions = {}): void {\n window.openai.openExternal({ href, ...options });\n }\n\n public setViewState = (stateOrUpdater: SetViewStateAction): Promise<void> => {\n const modelContent =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(window.openai.widgetState?.modelContent ?? null)\n : stateOrUpdater;\n\n return window.openai.setWidgetState({\n privateContent: {},\n ...window.openai.widgetState,\n modelContent,\n });\n };\n\n public uploadFile = async (file: File, options?: UploadFileOptions) => {\n const metadata = await window.openai.uploadFile(file, options);\n await this.trackFileIds(metadata.fileId);\n return metadata;\n };\n\n public getFileDownloadUrl = (file: { fileId: string }) => {\n return window.openai.getFileDownloadUrl(file);\n };\n\n public selectFiles = async (): Promise<FileMetadata[]> => {\n if (!window.openai.selectFiles) {\n throw new Error(\n \"selectFiles is not supported by the current host version.\",\n );\n }\n const files = await window.openai.selectFiles();\n if (files.length > 0) {\n await this.trackFileIds(...files.map((f) => f.fileId));\n }\n return files;\n };\n\n private async trackFileIds(...fileIds: string[]): Promise<void> {\n const state: AppsSdkWidgetState = window.openai.widgetState\n ? { ...window.openai.widgetState }\n : { modelContent: {}, privateContent: {} };\n if (!state.imageIds) {\n state.imageIds = [];\n }\n state.imageIds.push(...fileIds);\n await window.openai.setWidgetState(state);\n }\n\n public openModal(options: RequestModalOptions) {\n return window.openai.requestModal(options);\n }\n\n public setOpenInAppUrl(href: string): Promise<void> {\n href = href.trim();\n\n if (!href) {\n throw new Error(\"The href parameter is required.\");\n }\n\n return window.openai.setOpenInAppUrl({ href });\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Adaptor, CallToolResponse, HostContext, HostContextStore, OpenExternalOptions, RequestDisplayMode, RequestModalOptions, RequestSizeOptions, SendFollowUpMessageOptions, SetViewStateAction } from "../types.js";
|
|
1
|
+
import type { Adaptor, CallToolResponse, DownloadParams, DownloadResult, HostContext, HostContextStore, OpenExternalOptions, RequestDisplayMode, RequestModalOptions, RequestSizeOptions, SendFollowUpMessageOptions, SetViewStateAction } from "../types.js";
|
|
2
2
|
export declare class McpAppAdaptor implements Adaptor {
|
|
3
3
|
private static instance;
|
|
4
4
|
private stores;
|
|
@@ -19,6 +19,7 @@ export declare class McpAppAdaptor implements Adaptor {
|
|
|
19
19
|
requestClose: () => Promise<void>;
|
|
20
20
|
requestSize: (size: RequestSizeOptions) => Promise<void>;
|
|
21
21
|
sendFollowUpMessage: (prompt: string, _options?: SendFollowUpMessageOptions) => Promise<void>;
|
|
22
|
+
download: (params: DownloadParams) => Promise<DownloadResult>;
|
|
22
23
|
openExternal(href: string, options?: OpenExternalOptions): void;
|
|
23
24
|
private initializeStores;
|
|
24
25
|
setViewState: (stateOrUpdater: SetViewStateAction) => Promise<void>;
|
|
@@ -75,6 +75,14 @@ export class McpAppAdaptor {
|
|
|
75
75
|
],
|
|
76
76
|
});
|
|
77
77
|
};
|
|
78
|
+
download = async (params) => {
|
|
79
|
+
const app = await McpAppBridge.getInstance().getApp();
|
|
80
|
+
if (!app.getHostCapabilities()?.downloadFile) {
|
|
81
|
+
console.error("[skybridge] download: host does not support ui/download-file");
|
|
82
|
+
return { isError: true };
|
|
83
|
+
}
|
|
84
|
+
return app.downloadFile(params);
|
|
85
|
+
};
|
|
78
86
|
openExternal(href, options) {
|
|
79
87
|
if (options?.redirectUrl === false) {
|
|
80
88
|
console.warn("[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAarC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,GAAG,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5D,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACM,UAAU,GAA6B,IAAI,CAAC;IAC5C,kBAAkB,GAAG,IAAI,GAAG,EAAc,CAAC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Z,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC;YAClE,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;gBAC3B,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAEO,sBAAsB,CAG5B,IAAU,EAAE,eAAkD;QAC9D,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,WAA0B,CAAC;QAE/B,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACjC,WAAW,EAAE,GAAG,EAAE;gBAChB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CAAC;gBACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;gBAE1C,IAAI,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAC/D,OAAO,WAAW,CAAC;gBACrB,CAAC;gBAED,WAAW,GAAG,QAAQ,CAAC;gBACvB,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type {\n Adaptor,\n CallToolResponse,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n} from \"../types.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nconst STORAGE_PREFIX = \"sb:\";\nconst MAX_STORAGE_ENTRIES = 200;\n\nfunction findStorageKey(viewUUID: string): string | undefined {\n const suffix = `:${viewUUID}`;\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX) && key.endsWith(suffix)) {\n return key;\n }\n }\n return undefined;\n}\n\nexport class McpAppAdaptor implements Adaptor {\n private static instance: McpAppAdaptor | null = null;\n private stores: {\n [K in keyof HostContext]: HostContextStore<K>;\n };\n private _viewState: HostContext[\"viewState\"] = null;\n private viewStateListeners = new Set<() => void>();\n private _viewUUID: string | null = null;\n\n private _displayState: HostContext[\"display\"] = {\n mode: \"inline\",\n };\n private displayListeners = new Set<() => void>();\n\n private constructor() {\n this.stores = this.initializeStores();\n this.subscribeToViewUUID();\n }\n\n public static getInstance(): McpAppAdaptor {\n if (!McpAppAdaptor.instance) {\n McpAppAdaptor.instance = new McpAppAdaptor();\n }\n return McpAppAdaptor.instance;\n }\n\n public static resetInstance(): void {\n McpAppAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n return this.stores[key];\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const app = await McpAppBridge.getInstance().getApp();\n const response = await app.callServerTool({\n name,\n arguments: args ?? undefined,\n });\n\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = async (mode: RequestDisplayMode) => {\n const app = await McpAppBridge.getInstance().getApp();\n return app.requestDisplayMode({ mode });\n };\n\n public requestClose = async (): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.requestTeardown();\n };\n\n public requestSize = async (size: RequestSizeOptions): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendSizeChanged(size);\n };\n\n public sendFollowUpMessage = async (\n prompt: string,\n _options?: SendFollowUpMessageOptions,\n ) => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendMessage({\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: prompt,\n },\n ],\n });\n };\n\n public openExternal(href: string, options?: OpenExternalOptions): void {\n if (options?.redirectUrl === false) {\n console.warn(\n \"[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.\",\n );\n }\n\n McpAppBridge.getInstance()\n .getApp()\n .then((app) => app.openLink({ url: href }))\n .catch((err) => {\n console.error(\"Failed to open external link:\", err);\n });\n }\n\n private initializeStores(): {\n [K in keyof HostContext]: HostContextStore<K>;\n } {\n return {\n theme: this.createHostContextStore(\n [\"theme\"],\n ({ theme }) => theme ?? \"light\",\n ),\n locale: this.createHostContextStore(\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: this.createHostContextStore(\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: this.createHostContextStore(\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: this.createHostContextStore(\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n\n return undefined;\n },\n ),\n userAgent: this.createHostContextStore(\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: this.createHostContextStore(\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n display: {\n subscribe: (onChange: () => void) => {\n this.displayListeners.add(onChange);\n return () => {\n this.displayListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._displayState,\n },\n viewState: {\n subscribe: (onChange: () => void) => {\n this.viewStateListeners.add(onChange);\n return () => {\n this.viewStateListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._viewState,\n },\n };\n }\n\n public setViewState = async (\n stateOrUpdater: SetViewStateAction,\n ): Promise<void> => {\n const newState =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(this._viewState)\n : stateOrUpdater;\n\n // must happen before the async bridge call to ensure the state is updated immediately for the UI,\n // otherwise successive calls to setViewState may have stale state\n this._viewState = newState;\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n\n this.persistToLocalStorage(newState);\n\n try {\n const app = await McpAppBridge.getInstance().getApp();\n await app.updateModelContext({\n structuredContent: newState,\n content: [{ type: \"text\", text: JSON.stringify(newState) }],\n });\n } catch (error) {\n console.error(\"Failed to update view state in MCP App.\", error);\n }\n };\n\n /**\n * @throws File upload is not supported in MCP App.\n */\n public uploadFile(): Promise<{ fileId: string }> {\n throw new Error(\"File upload is not supported in MCP App.\");\n }\n\n /**\n * @throws File download is not supported in MCP App.\n */\n public getFileDownloadUrl(): Promise<{ downloadUrl: string }> {\n throw new Error(\"File download is not supported in MCP App.\");\n }\n\n /**\n * @throws File selection is not supported in MCP App.\n */\n public selectFiles(): Promise<{ fileId: string }[]> {\n throw new Error(\"File selection is not supported in MCP App.\");\n }\n\n public openModal(options: RequestModalOptions) {\n this._displayState = { mode: \"modal\", params: options.params };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public closeModal() {\n this._displayState = { mode: \"inline\" };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public setOpenInAppUrl(_href: string): Promise<void> {\n throw new Error(\"setOpenInAppUrl is not implemented in MCP App.\");\n }\n\n private subscribeToViewUUID(): void {\n const bridge = McpAppBridge.getInstance();\n bridge.subscribe(\"toolResult\")(() => {\n const toolResult = bridge.getSnapshot(\"toolResult\");\n const viewUUID = (\n toolResult?._meta as Record<string, unknown> | undefined\n )?.viewUUID as string | undefined;\n\n if (viewUUID && viewUUID !== this._viewUUID) {\n this._viewUUID = viewUUID;\n this.restoreFromLocalStorage(viewUUID);\n }\n });\n }\n\n // localStorage keys: sb:{unix_ms}:{viewUUID}\n // Timestamp is updated on every write (LRU); eviction drops the least recently used entries.\n private restoreFromLocalStorage(viewUUID: string): void {\n try {\n const existingKey = findStorageKey(viewUUID);\n if (existingKey) {\n const stored = localStorage.getItem(existingKey);\n if (stored !== null) {\n this._viewState = JSON.parse(stored);\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n }\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private persistToLocalStorage(state: Record<string, unknown> | null): void {\n if (!this._viewUUID || state === null) {\n return;\n }\n try {\n // Remove old key for this view, write with fresh timestamp (LRU)\n const oldKey = findStorageKey(this._viewUUID);\n if (oldKey) {\n localStorage.removeItem(oldKey);\n }\n const newKey = `${STORAGE_PREFIX}${Date.now()}:${this._viewUUID}`;\n localStorage.setItem(newKey, JSON.stringify(state));\n\n // lru cleanup\n const keys: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX)) {\n keys.push(key);\n }\n }\n if (keys.length <= MAX_STORAGE_ENTRIES) {\n return;\n }\n keys.sort();\n const toRemove = keys.slice(0, keys.length - MAX_STORAGE_ENTRIES);\n for (const key of toRemove) {\n localStorage.removeItem(key);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private createHostContextStore<\n const Keys extends readonly McpAppContextKey[],\n R,\n >(keys: Keys, computeSnapshot: (context: PickContext<Keys>) => R) {\n const bridge = McpAppBridge.getInstance();\n let cachedValue: R | undefined;\n\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n\n cachedValue = newValue;\n return newValue;\n },\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAerC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,GAAG,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5D,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACM,UAAU,GAA6B,IAAI,CAAC;IAC5C,kBAAkB,GAAG,IAAI,GAAG,EAAc,CAAC;IAC3C,SAAS,GAAkB,IAAI,CAAC;IAEhC,aAAa,GAA2B;QAC9C,IAAI,EAAE,Q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GAAG,QAAQ,CAAC;gBACvB,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type {\n Adaptor,\n CallToolResponse,\n DownloadParams,\n DownloadResult,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n} from \"../types.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nconst STORAGE_PREFIX = \"sb:\";\nconst MAX_STORAGE_ENTRIES = 200;\n\nfunction findStorageKey(viewUUID: string): string | undefined {\n const suffix = `:${viewUUID}`;\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX) && key.endsWith(suffix)) {\n return key;\n }\n }\n return undefined;\n}\n\nexport class McpAppAdaptor implements Adaptor {\n private static instance: McpAppAdaptor | null = null;\n private stores: {\n [K in keyof HostContext]: HostContextStore<K>;\n };\n private _viewState: HostContext[\"viewState\"] = null;\n private viewStateListeners = new Set<() => void>();\n private _viewUUID: string | null = null;\n\n private _displayState: HostContext[\"display\"] = {\n mode: \"inline\",\n };\n private displayListeners = new Set<() => void>();\n\n private constructor() {\n this.stores = this.initializeStores();\n this.subscribeToViewUUID();\n }\n\n public static getInstance(): McpAppAdaptor {\n if (!McpAppAdaptor.instance) {\n McpAppAdaptor.instance = new McpAppAdaptor();\n }\n return McpAppAdaptor.instance;\n }\n\n public static resetInstance(): void {\n McpAppAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n return this.stores[key];\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const app = await McpAppBridge.getInstance().getApp();\n const response = await app.callServerTool({\n name,\n arguments: args ?? undefined,\n });\n\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = async (mode: RequestDisplayMode) => {\n const app = await McpAppBridge.getInstance().getApp();\n return app.requestDisplayMode({ mode });\n };\n\n public requestClose = async (): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.requestTeardown();\n };\n\n public requestSize = async (size: RequestSizeOptions): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendSizeChanged(size);\n };\n\n public sendFollowUpMessage = async (\n prompt: string,\n _options?: SendFollowUpMessageOptions,\n ) => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendMessage({\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: prompt,\n },\n ],\n });\n };\n\n public download = async (params: DownloadParams): Promise<DownloadResult> => {\n const app = await McpAppBridge.getInstance().getApp();\n if (!app.getHostCapabilities()?.downloadFile) {\n console.error(\n \"[skybridge] download: host does not support ui/download-file\",\n );\n return { isError: true };\n }\n return app.downloadFile(params);\n };\n\n public openExternal(href: string, options?: OpenExternalOptions): void {\n if (options?.redirectUrl === false) {\n console.warn(\n \"[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.\",\n );\n }\n\n McpAppBridge.getInstance()\n .getApp()\n .then((app) => app.openLink({ url: href }))\n .catch((err) => {\n console.error(\"Failed to open external link:\", err);\n });\n }\n\n private initializeStores(): {\n [K in keyof HostContext]: HostContextStore<K>;\n } {\n return {\n theme: this.createHostContextStore(\n [\"theme\"],\n ({ theme }) => theme ?? \"light\",\n ),\n locale: this.createHostContextStore(\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: this.createHostContextStore(\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: this.createHostContextStore(\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: this.createHostContextStore(\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n\n return undefined;\n },\n ),\n userAgent: this.createHostContextStore(\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: this.createHostContextStore(\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n display: {\n subscribe: (onChange: () => void) => {\n this.displayListeners.add(onChange);\n return () => {\n this.displayListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._displayState,\n },\n viewState: {\n subscribe: (onChange: () => void) => {\n this.viewStateListeners.add(onChange);\n return () => {\n this.viewStateListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._viewState,\n },\n };\n }\n\n public setViewState = async (\n stateOrUpdater: SetViewStateAction,\n ): Promise<void> => {\n const newState =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(this._viewState)\n : stateOrUpdater;\n\n // must happen before the async bridge call to ensure the state is updated immediately for the UI,\n // otherwise successive calls to setViewState may have stale state\n this._viewState = newState;\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n\n this.persistToLocalStorage(newState);\n\n try {\n const app = await McpAppBridge.getInstance().getApp();\n await app.updateModelContext({\n structuredContent: newState,\n content: [{ type: \"text\", text: JSON.stringify(newState) }],\n });\n } catch (error) {\n console.error(\"Failed to update view state in MCP App.\", error);\n }\n };\n\n /**\n * @throws File upload is not supported in MCP App.\n */\n public uploadFile(): Promise<{ fileId: string }> {\n throw new Error(\"File upload is not supported in MCP App.\");\n }\n\n /**\n * @throws File download is not supported in MCP App.\n */\n public getFileDownloadUrl(): Promise<{ downloadUrl: string }> {\n throw new Error(\"File download is not supported in MCP App.\");\n }\n\n /**\n * @throws File selection is not supported in MCP App.\n */\n public selectFiles(): Promise<{ fileId: string }[]> {\n throw new Error(\"File selection is not supported in MCP App.\");\n }\n\n public openModal(options: RequestModalOptions) {\n this._displayState = { mode: \"modal\", params: options.params };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public closeModal() {\n this._displayState = { mode: \"inline\" };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public setOpenInAppUrl(_href: string): Promise<void> {\n throw new Error(\"setOpenInAppUrl is not implemented in MCP App.\");\n }\n\n private subscribeToViewUUID(): void {\n const bridge = McpAppBridge.getInstance();\n bridge.subscribe(\"toolResult\")(() => {\n const toolResult = bridge.getSnapshot(\"toolResult\");\n const viewUUID = (\n toolResult?._meta as Record<string, unknown> | undefined\n )?.viewUUID as string | undefined;\n\n if (viewUUID && viewUUID !== this._viewUUID) {\n this._viewUUID = viewUUID;\n this.restoreFromLocalStorage(viewUUID);\n }\n });\n }\n\n // localStorage keys: sb:{unix_ms}:{viewUUID}\n // Timestamp is updated on every write (LRU); eviction drops the least recently used entries.\n private restoreFromLocalStorage(viewUUID: string): void {\n try {\n const existingKey = findStorageKey(viewUUID);\n if (existingKey) {\n const stored = localStorage.getItem(existingKey);\n if (stored !== null) {\n this._viewState = JSON.parse(stored);\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n }\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private persistToLocalStorage(state: Record<string, unknown> | null): void {\n if (!this._viewUUID || state === null) {\n return;\n }\n try {\n // Remove old key for this view, write with fresh timestamp (LRU)\n const oldKey = findStorageKey(this._viewUUID);\n if (oldKey) {\n localStorage.removeItem(oldKey);\n }\n const newKey = `${STORAGE_PREFIX}${Date.now()}:${this._viewUUID}`;\n localStorage.setItem(newKey, JSON.stringify(state));\n\n // lru cleanup\n const keys: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX)) {\n keys.push(key);\n }\n }\n if (keys.length <= MAX_STORAGE_ENTRIES) {\n return;\n }\n keys.sort();\n const toRemove = keys.slice(0, keys.length - MAX_STORAGE_ENTRIES);\n for (const key of toRemove) {\n localStorage.removeItem(key);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private createHostContextStore<\n const Keys extends readonly McpAppContextKey[],\n R,\n >(keys: Keys, computeSnapshot: (context: PickContext<Keys>) => R) {\n const bridge = McpAppBridge.getInstance();\n let cachedValue: R | undefined;\n\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n\n cachedValue = newValue;\n return newValue;\n },\n };\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
1
|
+
import type { CallToolResult, EmbeddedResource, ResourceLink } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import type { useSyncExternalStore } from "react";
|
|
3
3
|
import type { ViewHostType } from "../../server/index.js";
|
|
4
4
|
export type SkybridgeProperties = {
|
|
@@ -96,6 +96,12 @@ export type RequestSizeOptions = {
|
|
|
96
96
|
width?: number;
|
|
97
97
|
height?: number;
|
|
98
98
|
};
|
|
99
|
+
export type DownloadParams = {
|
|
100
|
+
contents: (EmbeddedResource | ResourceLink)[];
|
|
101
|
+
};
|
|
102
|
+
export type DownloadResult = {
|
|
103
|
+
isError?: boolean;
|
|
104
|
+
};
|
|
99
105
|
export interface Adaptor {
|
|
100
106
|
getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
|
|
101
107
|
callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
|
|
@@ -106,6 +112,7 @@ export interface Adaptor {
|
|
|
106
112
|
requestSize(size: RequestSizeOptions): Promise<void>;
|
|
107
113
|
sendFollowUpMessage(prompt: string, options?: SendFollowUpMessageOptions): Promise<void>;
|
|
108
114
|
openExternal(href: string, options?: OpenExternalOptions): void;
|
|
115
|
+
download(params: DownloadParams): Promise<DownloadResult>;
|
|
109
116
|
setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;
|
|
110
117
|
uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;
|
|
111
118
|
getFileDownloadUrl(file: FileMetadata): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\nexport type CallToolArgs = Record<string, unknown> | null;\n\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\nexport type Theme = \"light\" | \"dark\";\n\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\nexport type ViewState = Record<string, unknown>;\n\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\nexport type UploadFileOptions = { library?: boolean };\n\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { type DownloadFn, useDownload } from "./use-download.js";
|
|
3
4
|
export { useFiles } from "./use-files.js";
|
|
4
5
|
export { type LayoutState, useLayout } from "./use-layout.js";
|
|
5
6
|
export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
|
package/dist/web/hooks/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useDownload } from "./use-download.js";
|
|
3
4
|
export { useFiles } from "./use-files.js";
|
|
4
5
|
export { useLayout } from "./use-layout.js";
|
|
5
6
|
export { useOpenExternal } from "./use-open-external.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type LayoutState, useLayout } from \"./use-layout.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type LayoutState, useLayout } from \"./use-layout.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\n"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
1
|
+
import type { McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
2
|
export declare class MockResizeObserver {
|
|
3
3
|
observe(): void;
|
|
4
4
|
unobserve(): void;
|
|
5
5
|
disconnect(): void;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type McpAppHostMockOptions = {
|
|
8
|
+
hostCapabilities?: McpUiHostCapabilities;
|
|
9
|
+
downloadFileResult?: McpUiDownloadFileResult;
|
|
10
|
+
};
|
|
11
|
+
export declare const getMcpAppHostPostMessageMock: (initialContext?: McpUiHostContext, options?: McpAppHostMockOptions) => import("vitest").Mock<(message: {
|
|
8
12
|
method: string;
|
|
9
13
|
id: number;
|
|
10
14
|
}) => void>;
|
|
@@ -7,13 +7,13 @@ export class MockResizeObserver {
|
|
|
7
7
|
disconnect() { }
|
|
8
8
|
}
|
|
9
9
|
const DEFAULT_CONTEXT = {};
|
|
10
|
-
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) => vi.fn((message) => {
|
|
10
|
+
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT, options = {}) => vi.fn((message) => {
|
|
11
11
|
switch (message.method) {
|
|
12
12
|
case "ui/initialize": {
|
|
13
13
|
const result = {
|
|
14
14
|
protocolVersion: "2025-06-18",
|
|
15
15
|
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
16
|
-
hostCapabilities: {},
|
|
16
|
+
hostCapabilities: options.hostCapabilities ?? {},
|
|
17
17
|
hostContext: initialContext,
|
|
18
18
|
};
|
|
19
19
|
act(() => fireEvent(window, new MessageEvent("message", {
|
|
@@ -37,6 +37,17 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
|
|
|
37
37
|
})));
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
|
+
case "ui/download-file": {
|
|
41
|
+
act(() => fireEvent(window, new MessageEvent("message", {
|
|
42
|
+
source: window.parent,
|
|
43
|
+
data: {
|
|
44
|
+
jsonrpc: "2.0",
|
|
45
|
+
id: message.id,
|
|
46
|
+
result: options.downloadFileResult ?? {},
|
|
47
|
+
},
|
|
48
|
+
})));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
52
|
});
|
|
42
53
|
export const fireToolInputNotification = (args) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,OAAO,kBAAkB;IAC7B,OAAO,KAAU,CAAC;IAClB,SAAS,KAAU,CAAC;IACpB,UAAU,KAAU,CAAC;CACtB;AAED,MAAM,eAAe,GAAqB,EAAE,CAAC;AAO7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,iBAAmC,eAAe,EAClD,UAAiC,EAAE,EACnC,EAAE,CACF,EAAE,CAAC,EAAE,CAAC,CAAC,OAAuC,EAAE,EAAE;IAChD,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,MAAM,M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AAE;IACzE,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,6BAA6B;YACrC,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAI1C,EAAE,EAAE;IACH,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,8BAA8B;YACtC,MAAM;SACP;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n McpUiDownloadFileResult,\n McpUiHostCapabilities,\n McpUiHostContext,\n McpUiInitializeResult,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\nimport { fireEvent } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { vi } from \"vitest\";\n\nexport class MockResizeObserver {\n observe(): void {}\n unobserve(): void {}\n disconnect(): void {}\n}\n\nconst DEFAULT_CONTEXT: McpUiHostContext = {};\n\nexport type McpAppHostMockOptions = {\n hostCapabilities?: McpUiHostCapabilities;\n downloadFileResult?: McpUiDownloadFileResult;\n};\n\nexport const getMcpAppHostPostMessageMock = (\n initialContext: McpUiHostContext = DEFAULT_CONTEXT,\n options: McpAppHostMockOptions = {},\n) =>\n vi.fn((message: { method: string; id: number }) => {\n switch (message.method) {\n case \"ui/initialize\": {\n const result: McpUiInitializeResult = {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: options.hostCapabilities ?? {},\n hostContext: initialContext,\n };\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiInitializeResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result,\n },\n }),\n ),\n );\n break;\n }\n case \"ui/update-model-context\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{ jsonrpc: \"2.0\"; id: number; result: unknown }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {},\n },\n },\n ),\n ),\n );\n break;\n }\n case \"ui/download-file\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiDownloadFileResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: options.downloadFileResult ?? {},\n },\n }),\n ),\n );\n break;\n }\n }\n });\n\nexport const fireToolInputNotification = (args: Record<string, unknown>) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolInputNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-input\",\n params: {\n arguments: args,\n },\n },\n },\n ),\n );\n};\n\nexport const fireToolResultNotification = (params: {\n content: McpUiToolResultNotification[\"params\"][\"content\"];\n structuredContent: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n}) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolResultNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-result\",\n params,\n },\n },\n ),\n );\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
export function useDownload() {
|
|
4
|
+
const adaptor = getAdaptor();
|
|
5
|
+
const download = useCallback((params) => adaptor.download(params), [adaptor]);
|
|
6
|
+
return { download };
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=use-download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-download.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EACpC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { DownloadParams, DownloadResult } from \"../bridges/types.js\";\n\nexport type DownloadFn = (params: DownloadParams) => Promise<DownloadResult>;\n\nexport function useDownload(): { download: DownloadFn } {\n const adaptor = getAdaptor();\n const download = useCallback<DownloadFn>(\n (params) => adaptor.download(params),\n [adaptor],\n );\n\n return { download };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { AppsSdkAdaptor } from "../bridges/apps-sdk/adaptor.js";
|
|
4
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
5
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
+
import { useDownload } from "./use-download.js";
|
|
7
|
+
const params = {
|
|
8
|
+
contents: [
|
|
9
|
+
{
|
|
10
|
+
type: "resource",
|
|
11
|
+
resource: {
|
|
12
|
+
uri: "file:///export.json",
|
|
13
|
+
mimeType: "application/json",
|
|
14
|
+
text: '{"hello":"world"}',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
describe("useDownload", () => {
|
|
20
|
+
describe("apps-sdk host", () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.stubGlobal("openai", {});
|
|
23
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
vi.unstubAllGlobals();
|
|
27
|
+
vi.resetAllMocks();
|
|
28
|
+
AppsSdkAdaptor.resetInstance();
|
|
29
|
+
});
|
|
30
|
+
it("returns { isError: true } and logs an error", async () => {
|
|
31
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
32
|
+
const { result } = renderHook(() => useDownload());
|
|
33
|
+
const res = await result.current.download(params);
|
|
34
|
+
expect(res).toEqual({ isError: true });
|
|
35
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("not supported on Apps SDK"));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("mcp-app host without downloadFile capability", () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
41
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
42
|
+
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
43
|
+
});
|
|
44
|
+
afterEach(async () => {
|
|
45
|
+
vi.unstubAllGlobals();
|
|
46
|
+
vi.resetAllMocks();
|
|
47
|
+
McpAppBridge.resetInstance();
|
|
48
|
+
});
|
|
49
|
+
it("returns { isError: true } and logs an error", async () => {
|
|
50
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
51
|
+
const { result } = renderHook(() => useDownload());
|
|
52
|
+
const res = await result.current.download(params);
|
|
53
|
+
expect(res).toEqual({ isError: true });
|
|
54
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("does not support ui/download-file"));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe("mcp-app host with downloadFile capability", () => {
|
|
58
|
+
let postMessageMock;
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
61
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
62
|
+
postMessageMock = getMcpAppHostPostMessageMock({}, { hostCapabilities: { downloadFile: {} } });
|
|
63
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
64
|
+
});
|
|
65
|
+
afterEach(async () => {
|
|
66
|
+
vi.unstubAllGlobals();
|
|
67
|
+
vi.resetAllMocks();
|
|
68
|
+
McpAppBridge.resetInstance();
|
|
69
|
+
});
|
|
70
|
+
it("sends ui/download-file with the provided contents", async () => {
|
|
71
|
+
const { result } = renderHook(() => useDownload());
|
|
72
|
+
const res = await result.current.download(params);
|
|
73
|
+
expect(res).toEqual({});
|
|
74
|
+
await waitFor(() => {
|
|
75
|
+
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
76
|
+
jsonrpc: "2.0",
|
|
77
|
+
method: "ui/download-file",
|
|
78
|
+
params,
|
|
79
|
+
}), "*");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it("returns { isError: true } when the host denies the request", async () => {
|
|
83
|
+
McpAppBridge.resetInstance();
|
|
84
|
+
postMessageMock = getMcpAppHostPostMessageMock({}, {
|
|
85
|
+
hostCapabilities: { downloadFile: {} },
|
|
86
|
+
downloadFileResult: { isError: true },
|
|
87
|
+
});
|
|
88
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
89
|
+
const { result } = renderHook(() => useDownload());
|
|
90
|
+
const res = await result.current.download(params);
|
|
91
|
+
expect(res).toEqual({ isError: true });
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=use-download.test.js.map
|
|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AAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAElD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACxB,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,kBAAkB;oBAC1B,MAAM;iBACP,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4DAA4D,EAAE,KAAK,IAAI,EAAE;YAC1E,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,eAAe,GAAG,4BAA4B,CAC5C,EAAE,EACF;gBACE,gBAAgB,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;gBACtC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aACtC,CACF,CAAC;YACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;YAE1D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAEnD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAElD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { AppsSdkAdaptor } from \"../bridges/apps-sdk/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { DownloadParams } from \"../bridges/types.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDownload } from \"./use-download.js\";\n\nconst params: DownloadParams = {\n contents: [\n {\n type: \"resource\",\n resource: {\n uri: \"file:///export.json\",\n mimeType: \"application/json\",\n text: '{\"hello\":\"world\"}',\n },\n },\n ],\n};\n\ndescribe(\"useDownload\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", {});\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n AppsSdkAdaptor.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"not supported on Apps SDK\"),\n );\n });\n });\n\n describe(\"mcp-app host without downloadFile capability\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host with downloadFile capability\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n { hostCapabilities: { downloadFile: {} } },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends ui/download-file with the provided contents\", async () => {\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({});\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/download-file\",\n params,\n }),\n \"*\",\n );\n });\n });\n\n it(\"returns { isError: true } when the host denies the request\", async () => {\n McpAppBridge.resetInstance();\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n {\n hostCapabilities: { downloadFile: {} },\n downloadFileResult: { isError: true },\n },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n });\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skybridge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Skybridge is a framework for building ChatGPT and MCP Apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -95,6 +95,10 @@
|
|
|
95
95
|
"commands": "./dist/commands",
|
|
96
96
|
"dirname": "skybridge",
|
|
97
97
|
"topicSeparator": " ",
|
|
98
|
+
"helpClass": {
|
|
99
|
+
"target": "./dist/commands/create",
|
|
100
|
+
"identifier": "SkybridgeHelp"
|
|
101
|
+
},
|
|
98
102
|
"hooks": {
|
|
99
103
|
"finally": "./dist/cli/telemetry"
|
|
100
104
|
}
|