skybridge 0.0.0-dev.e9705ff → 0.0.0-dev.e9d034c
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/LICENSE +21 -674
- package/dist/src/server/index.d.ts +2 -2
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/inferUtilityTypes.d.ts +10 -0
- package/dist/src/server/server.d.ts +71 -18
- package/dist/src/server/server.js +94 -36
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +3 -0
- package/dist/src/server/templateHelper.js +5 -4
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/development.hbs +57 -3
- package/dist/src/server/templates/production.hbs +1 -0
- package/dist/src/server/widgetsDevServer.d.ts +2 -2
- package/dist/src/server/widgetsDevServer.js +13 -5
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/utils.d.ts +54 -8
- package/dist/src/test/utils.js +86 -8
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/test/widget.test.js +178 -31
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +13 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +33 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +1 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +16 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +115 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +10 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js +46 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-adaptor.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js +8 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-bridge.js +8 -0
- package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +5 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +41 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -0
- package/dist/src/web/bridges/index.d.ts +4 -0
- package/dist/src/web/bridges/index.js +5 -0
- package/dist/src/web/bridges/index.js.map +1 -0
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +38 -0
- package/dist/src/web/bridges/mcp-app-bridge.js +162 -0
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/types.d.ts +57 -0
- package/dist/src/web/bridges/types.js +2 -0
- package/dist/src/web/bridges/types.js.map +1 -0
- package/dist/src/web/create-store.js +1 -1
- package/dist/src/web/create-store.js.map +1 -1
- package/dist/src/web/create-store.test.js +1 -1
- package/dist/src/web/create-store.test.js.map +1 -1
- package/dist/src/web/data-llm.js +6 -4
- package/dist/src/web/data-llm.js.map +1 -1
- package/dist/src/web/data-llm.test.js.map +1 -1
- package/dist/src/web/generate-helpers.d.ts +9 -7
- package/dist/src/web/generate-helpers.js +4 -2
- package/dist/src/web/generate-helpers.js.map +1 -1
- package/dist/src/web/generate-helpers.test-d.js +59 -3
- package/dist/src/web/generate-helpers.test-d.js.map +1 -1
- package/dist/src/web/generate-helpers.test.js +1 -1
- package/dist/src/web/generate-helpers.test.js.map +1 -1
- package/dist/src/web/helpers/state.js +1 -1
- package/dist/src/web/helpers/state.js.map +1 -1
- package/dist/src/web/helpers/state.test.js +19 -12
- package/dist/src/web/helpers/state.test.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +4 -5
- package/dist/src/web/hooks/index.js +3 -4
- package/dist/src/web/hooks/index.js.map +1 -1
- package/dist/src/web/hooks/test/utils.d.ts +10 -0
- package/dist/src/web/hooks/test/utils.js +40 -0
- package/dist/src/web/hooks/test/utils.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +2 -2
- package/dist/src/web/hooks/use-call-tool.js +12 -4
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js +2 -2
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test.js +37 -18
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/src/web/hooks/use-display-mode.js +6 -3
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.test.js +3 -2
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/src/web/hooks/use-files.test.js +1 -1
- package/dist/src/web/hooks/use-files.test.js.map +1 -1
- package/dist/src/web/hooks/use-layout.d.ts +22 -0
- package/dist/src/web/hooks/use-layout.js +23 -0
- package/dist/src/web/hooks/use-layout.js.map +1 -0
- package/dist/src/web/hooks/use-layout.test.js +95 -0
- package/dist/src/web/hooks/use-layout.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.js +5 -3
- package/dist/src/web/hooks/use-open-external.js.map +1 -1
- package/dist/src/web/hooks/use-open-external.test.js +43 -17
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +3 -2
- package/dist/src/web/hooks/use-openai-global.js +3 -20
- package/dist/src/web/hooks/use-openai-global.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +6 -3
- package/dist/src/web/hooks/use-request-modal.js +6 -1
- package/dist/src/web/hooks/use-request-modal.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.test.js +37 -4
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +3 -6
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +13 -2
- package/dist/src/web/hooks/use-tool-info.js +15 -11
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js +40 -5
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test.js +119 -48
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user.d.ts +18 -0
- package/dist/src/web/hooks/use-user.js +19 -0
- package/dist/src/web/hooks/use-user.js.map +1 -0
- package/dist/src/web/hooks/use-user.test.js +93 -0
- package/dist/src/web/hooks/use-user.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.js +3 -3
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js +3 -2
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/src/web/index.d.ts +5 -4
- package/dist/src/web/index.js +5 -4
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin/plugin.js +10 -4
- package/dist/src/web/plugin/plugin.js.map +1 -1
- package/dist/src/web/plugin/transform-data-llm.js +6 -3
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/src/web/proxy.js +6 -1
- package/dist/src/web/proxy.js.map +1 -1
- package/dist/src/web/types.d.ts +31 -15
- package/dist/src/web/types.js.map +1 -1
- package/package.json +31 -26
- package/README.md +0 -415
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- /package/dist/src/web/{hooks/use-locale.test.d.ts → bridges/hooks/use-mcp-app-bridge.test.d.ts} +0 -0
- /package/dist/src/web/hooks/{use-theme.test.d.ts → use-layout.test.d.ts} +0 -0
- /package/dist/src/web/hooks/{use-user-agent.test.d.ts → use-user.test.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
|
|
2
|
+
export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
|
|
1
3
|
export { McpServer } from "./server.js";
|
|
2
4
|
export { widgetsDevServer } from "./widgetsDevServer.js";
|
|
3
|
-
export type { ToolDef, McpServerTypes } from "./server.js";
|
|
4
|
-
export type { InferTools, AnyToolRegistry, ToolNames, ToolInput, ToolOutput, } from "./inferUtilityTypes.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -51,4 +51,14 @@ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = Extr
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
|
|
54
|
+
/**
|
|
55
|
+
* Get the responseMetadata type for a specific tool (widget or regular tool).
|
|
56
|
+
* This is inferred from the `_meta` property of the tool callback's return value.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* type SearchMeta = ToolResponseMetadata<MyServer, "search">;
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export type ToolResponseMetadata<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["responseMetadata"];
|
|
54
64
|
export {};
|
|
@@ -1,16 +1,55 @@
|
|
|
1
|
+
import type { McpUiResourceMeta } from "@modelcontextprotocol/ext-apps";
|
|
1
2
|
import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import type {
|
|
3
|
+
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
3
4
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
-
import type {
|
|
5
|
-
export type ToolDef<TInput = unknown, TOutput = unknown> = {
|
|
5
|
+
import type { CallToolResult, Resource, ServerNotification, ServerRequest, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
6
7
|
input: TInput;
|
|
7
8
|
output: TOutput;
|
|
9
|
+
responseMetadata: TResponseMetadata;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Extended MCP Apps CSP with upcoming fields from ext-apps PR #158
|
|
13
|
+
* and Skybridge-specific fields for OpenAI compatibility
|
|
14
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/pull/158
|
|
15
|
+
*/
|
|
16
|
+
type ExtendedMcpUiResourceCsp = McpUiResourceMeta["csp"] & {
|
|
17
|
+
/** Origins allowed for nested iframe embeds */
|
|
18
|
+
frameDomains?: string[];
|
|
19
|
+
/** Origins permitted for the <base> tag URI directive */
|
|
20
|
+
baseUriDomains?: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Origins that can receive openExternal redirects without safe-link modal (OpenAI-specific)
|
|
23
|
+
* @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields
|
|
24
|
+
*/
|
|
25
|
+
redirectDomains?: string[];
|
|
26
|
+
};
|
|
27
|
+
/** Extended MCP Apps resource metadata with upcoming CSP fields */
|
|
28
|
+
type ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, "csp"> & {
|
|
29
|
+
csp?: ExtendedMcpUiResourceCsp;
|
|
30
|
+
};
|
|
31
|
+
/** User-provided resource configuration with optional CSP override */
|
|
32
|
+
export type WidgetResourceMeta = {
|
|
33
|
+
ui?: ExtendedMcpUiResourceMeta;
|
|
34
|
+
} & Resource["_meta"];
|
|
35
|
+
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
36
|
+
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType" | "_meta"> & {
|
|
37
|
+
_meta?: WidgetResourceMeta;
|
|
38
|
+
};
|
|
39
|
+
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
40
|
+
type Simplify<T> = {
|
|
41
|
+
[K in keyof T]: T[K];
|
|
8
42
|
};
|
|
9
|
-
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
|
|
10
|
-
type McpServerOriginalToolConfig = Omit<Parameters<McpServerBase["registerTool"]>[1], "inputSchema" | "outputSchema">;
|
|
11
43
|
type ExtractStructuredContent<T> = T extends {
|
|
12
44
|
structuredContent: infer SC;
|
|
13
|
-
} ? SC : never;
|
|
45
|
+
} ? Simplify<SC> : never;
|
|
46
|
+
type ExtractMeta<T> = [Extract<T, {
|
|
47
|
+
_meta: unknown;
|
|
48
|
+
}>] extends [never] ? unknown : Extract<T, {
|
|
49
|
+
_meta: unknown;
|
|
50
|
+
}> extends {
|
|
51
|
+
_meta: infer M;
|
|
52
|
+
} ? Simplify<M> : unknown;
|
|
14
53
|
/**
|
|
15
54
|
* Type-level marker interface for cross-package type inference.
|
|
16
55
|
* This enables TypeScript to infer tool types across package boundaries
|
|
@@ -20,29 +59,43 @@ type ExtractStructuredContent<T> = T extends {
|
|
|
20
59
|
*
|
|
21
60
|
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
22
61
|
*/
|
|
23
|
-
export interface McpServerTypes<TTools extends Record<string, ToolDef
|
|
62
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
24
63
|
readonly tools: TTools;
|
|
25
64
|
}
|
|
26
|
-
type
|
|
27
|
-
[K in
|
|
65
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
66
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
67
|
+
} & {
|
|
68
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
69
|
+
}>;
|
|
70
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
71
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
28
72
|
}>;
|
|
29
|
-
type ToolConfig<TInput extends
|
|
73
|
+
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
30
74
|
title?: string;
|
|
31
75
|
description?: string;
|
|
32
76
|
inputSchema?: TInput;
|
|
33
|
-
outputSchema?:
|
|
77
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
34
78
|
annotations?: ToolAnnotations;
|
|
35
79
|
_meta?: Record<string, unknown>;
|
|
36
80
|
};
|
|
37
|
-
type ToolHandler<TInput extends
|
|
38
|
-
|
|
81
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
82
|
+
content: CallToolResult["content"];
|
|
83
|
+
} = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
84
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
|
|
39
85
|
readonly $types: McpServerTypes<TTools>;
|
|
40
|
-
|
|
86
|
+
registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends {
|
|
87
|
+
content: CallToolResult["content"];
|
|
88
|
+
}>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
41
89
|
inputSchema?: TInput;
|
|
42
|
-
outputSchema?:
|
|
43
|
-
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>>;
|
|
44
|
-
registerTool<TName extends string, InputArgs extends
|
|
45
|
-
|
|
90
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
91
|
+
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
92
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
93
|
+
content: CallToolResult["content"];
|
|
94
|
+
}>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
95
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
96
|
+
private registerWidgetResource;
|
|
46
97
|
private lookupDistFile;
|
|
98
|
+
private lookupDistFileWithIndexFallback;
|
|
99
|
+
private readManifest;
|
|
47
100
|
}
|
|
48
101
|
export {};
|
|
@@ -1,62 +1,120 @@
|
|
|
1
|
-
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { templateHelper } from "./templateHelper.js";
|
|
3
1
|
import { readFileSync } from "node:fs";
|
|
4
2
|
import path from "node:path";
|
|
3
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { toMerged } from "es-toolkit";
|
|
5
|
+
import { templateHelper } from "./templateHelper.js";
|
|
5
6
|
export class McpServer extends McpServerBase {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
7
|
+
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
8
|
+
const userMeta = resourceConfig._meta;
|
|
9
|
+
const appsSdkResourceConfig = {
|
|
10
|
+
hostType: "apps-sdk",
|
|
11
|
+
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
12
|
+
mimeType: "text/html+skybridge",
|
|
13
|
+
buildContentMeta: ({ serverUrl, wsServerUrl }) => {
|
|
14
|
+
const userUi = userMeta?.ui;
|
|
15
|
+
const defaults = {
|
|
16
|
+
"openai/widgetCSP": {
|
|
17
|
+
resource_domains: [serverUrl],
|
|
18
|
+
connect_domains: [serverUrl, wsServerUrl],
|
|
19
|
+
},
|
|
20
|
+
"openai/widgetDomain": serverUrl,
|
|
21
|
+
"openai/widgetDescription": toolConfig.description,
|
|
22
|
+
};
|
|
23
|
+
const userCsp = userUi?.csp;
|
|
24
|
+
const fromUi = {
|
|
25
|
+
"openai/widgetCSP": {
|
|
26
|
+
resource_domains: userCsp?.resourceDomains,
|
|
27
|
+
connect_domains: userCsp?.connectDomains,
|
|
28
|
+
frame_domains: userCsp?.frameDomains,
|
|
29
|
+
redirect_domains: userCsp?.redirectDomains,
|
|
30
|
+
},
|
|
31
|
+
"openai/widgetDomain": userUi?.domain,
|
|
32
|
+
"openai/widgetPrefersBorder": userUi?.prefersBorder,
|
|
33
|
+
};
|
|
34
|
+
const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
|
|
35
|
+
return toMerged(toMerged(defaults, fromUi), directOpenaiKeys);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const extAppsResourceConfig = {
|
|
39
|
+
hostType: "mcp-app",
|
|
40
|
+
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
41
|
+
mimeType: "text/html;profile=mcp-app",
|
|
42
|
+
buildContentMeta: ({ serverUrl, wsServerUrl }) => {
|
|
43
|
+
const defaults = {
|
|
44
|
+
ui: {
|
|
45
|
+
csp: {
|
|
46
|
+
resourceDomains: [serverUrl],
|
|
47
|
+
connectDomains: [serverUrl, wsServerUrl],
|
|
48
|
+
},
|
|
49
|
+
domain: serverUrl,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return toMerged(defaults, { ui: userMeta?.ui });
|
|
53
|
+
},
|
|
10
54
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
55
|
+
[appsSdkResourceConfig, extAppsResourceConfig].forEach((widgetConfig) => {
|
|
56
|
+
this.registerWidgetResource({
|
|
57
|
+
name,
|
|
58
|
+
widgetConfig,
|
|
59
|
+
resourceConfig,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
const toolMeta = {
|
|
63
|
+
...toolConfig._meta,
|
|
64
|
+
"openai/outputTemplate": appsSdkResourceConfig.uri,
|
|
65
|
+
ui: {
|
|
66
|
+
resourceUri: extAppsResourceConfig.uri,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
this.registerTool(name, {
|
|
70
|
+
...toolConfig,
|
|
71
|
+
_meta: toolMeta,
|
|
72
|
+
}, toolCallback);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
registerTool(name, config, cb) {
|
|
76
|
+
super.registerTool(name, config, cb);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
registerWidgetResource({ name, widgetConfig, resourceConfig, }) {
|
|
80
|
+
const { hostType, uri: widgetUri, mimeType, buildContentMeta, } = widgetConfig;
|
|
81
|
+
this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceConfig._meta }, async (uri, extra) => {
|
|
18
82
|
const serverUrl = process.env.NODE_ENV === "production"
|
|
19
|
-
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
20
|
-
extra?.requestInfo?.headers?.host}`
|
|
83
|
+
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ?? extra?.requestInfo?.headers?.host}`
|
|
21
84
|
: `http://localhost:3000`;
|
|
85
|
+
const wsServerUrl = serverUrl.replace(/^http/, "ws");
|
|
22
86
|
const html = process.env.NODE_ENV === "production"
|
|
23
87
|
? templateHelper.renderProduction({
|
|
88
|
+
hostType,
|
|
24
89
|
serverUrl,
|
|
25
|
-
widgetFile: this.
|
|
90
|
+
widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
|
|
26
91
|
styleFile: this.lookupDistFile("style.css"),
|
|
27
92
|
})
|
|
28
93
|
: templateHelper.renderDevelopment({
|
|
94
|
+
hostType,
|
|
29
95
|
serverUrl,
|
|
30
96
|
widgetName: name,
|
|
31
97
|
});
|
|
98
|
+
const contentMeta = buildContentMeta({ serverUrl, wsServerUrl });
|
|
32
99
|
return {
|
|
33
100
|
contents: [
|
|
34
|
-
{
|
|
35
|
-
uri,
|
|
36
|
-
mimeType: "text/html+skybridge",
|
|
37
|
-
text: html,
|
|
38
|
-
},
|
|
101
|
+
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|
|
39
102
|
],
|
|
40
103
|
};
|
|
41
104
|
});
|
|
42
|
-
const toolMeta = {
|
|
43
|
-
...toolConfig._meta,
|
|
44
|
-
"openai/outputTemplate": uri,
|
|
45
|
-
"ui/resourceUri": uri,
|
|
46
|
-
};
|
|
47
|
-
this.registerTool(name, {
|
|
48
|
-
...toolConfig,
|
|
49
|
-
_meta: toolMeta,
|
|
50
|
-
}, toolCallback);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
registerTool(name, config, cb) {
|
|
54
|
-
super.registerTool(name, config, cb);
|
|
55
|
-
return this;
|
|
56
105
|
}
|
|
57
106
|
lookupDistFile(key) {
|
|
58
|
-
const manifest =
|
|
107
|
+
const manifest = this.readManifest();
|
|
59
108
|
return manifest[key]?.file;
|
|
60
109
|
}
|
|
110
|
+
lookupDistFileWithIndexFallback(basePath) {
|
|
111
|
+
const manifest = this.readManifest();
|
|
112
|
+
const flatFileKey = `${basePath}.tsx`;
|
|
113
|
+
const indexFileKey = `${basePath}/index.tsx`;
|
|
114
|
+
return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
|
|
115
|
+
}
|
|
116
|
+
readManifest() {
|
|
117
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
118
|
+
}
|
|
61
119
|
}
|
|
62
120
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EACL,SAAS,IAAI,aAAa,GAG3B,MAAM,yCAAyC,CAAC;AAcjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OA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,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;iBAC5D;aACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;IAEO,+BAA+B,CAAC,QAAgB;QACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAErC,MAAM,WAAW,GAAG,GAAG,QAAQ,MAAM,CAAC;QACtC,MAAM,YAAY,GAAG,GAAG,QAAQ,YAAY,CAAC;QAC7C,OAAO,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,IAAI,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;IACrE,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,CAAC,KAAK,CACf,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { WidgetHostType } from "./server.js";
|
|
1
2
|
declare class TemplateHelper {
|
|
2
3
|
private templateCache;
|
|
3
4
|
private loadTemplate;
|
|
4
5
|
renderProduction(data: {
|
|
6
|
+
hostType: WidgetHostType;
|
|
5
7
|
serverUrl: string;
|
|
6
8
|
widgetFile: string;
|
|
7
9
|
styleFile: string;
|
|
8
10
|
}): string;
|
|
9
11
|
renderDevelopment(data: {
|
|
12
|
+
hostType: WidgetHostType;
|
|
10
13
|
serverUrl: string;
|
|
11
14
|
widgetName: string;
|
|
12
15
|
}): string;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import Handlebars from "handlebars";
|
|
2
1
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
+
import Handlebars from "handlebars";
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
class TemplateHelper {
|
|
8
8
|
templateCache = new Map();
|
|
9
9
|
loadTemplate(templateName) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const cached = this.templateCache.get(templateName);
|
|
11
|
+
if (cached) {
|
|
12
|
+
return cached;
|
|
12
13
|
}
|
|
13
14
|
const templatePath = join(__dirname, "templates", `${templateName}.hbs`);
|
|
14
15
|
const templateSource = readFileSync(templatePath, "utf-8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,cAAc;IACV,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE9D,YAAY,CAAC,YAAoB;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACpD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QACzE,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,IAKhB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,iBAAiB,CAAC,IAIjB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QAClD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -1,12 +1,66 @@
|
|
|
1
1
|
<base href="{{serverUrl}}" />
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
2
3
|
<script type="module">
|
|
3
|
-
import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
|
|
4
|
+
import { injectIntoGlobalHook } from "{{serverUrl}}/assets/@react-refresh";
|
|
4
5
|
injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
|
|
5
6
|
window.$RefreshSig$ = () => (type) => type;
|
|
6
7
|
window.__vite_plugin_react_preamble_installed__ = true;
|
|
7
8
|
</script>
|
|
8
9
|
<script type="module" src="{{serverUrl}}/@vite/client"></script>
|
|
9
|
-
<div id="root"></div>
|
|
10
10
|
<script type="module">
|
|
11
|
-
|
|
11
|
+
// Checks for browser support and shows error if local network access is denied
|
|
12
|
+
(async () => {
|
|
13
|
+
if (!navigator.permissions?.query) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Skip for non-http(s) protocols (file://, custom protocols in Electron, etc.)
|
|
18
|
+
const protocol = window.location.protocol;
|
|
19
|
+
const isNonHttpProtocol = protocol !== 'http:' && protocol !== 'https:'
|
|
20
|
+
if (isNonHttpProtocol) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const host = window.location.hostname;
|
|
25
|
+
const isLoopback = host === 'localhost'
|
|
26
|
+
|| /^127\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.test(host)
|
|
27
|
+
|| host === '::1';
|
|
28
|
+
if (isLoopback) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const status = await navigator.permissions.query({ name: "local-network-access" });
|
|
34
|
+
if (status.state === "denied") {
|
|
35
|
+
const errorDiv = document.createElement("div");
|
|
36
|
+
errorDiv.style.cssText = "background: #fef2f2; border: 2px solid #ef4444; border-radius: 8px; padding: 16px; text-align: center; z-index: 10000; font-family: system-ui, sans-serif;";
|
|
37
|
+
|
|
38
|
+
const errorTitle = document.createElement("div");
|
|
39
|
+
errorTitle.style.cssText = "color: #ef4444; font-size: 18px; font-weight: 600; margin-bottom: 8px;";
|
|
40
|
+
errorTitle.textContent = "Error: Local network access permission is denied.";
|
|
41
|
+
|
|
42
|
+
const errorMessage = document.createElement("div");
|
|
43
|
+
errorMessage.style.cssText = "color: #ef4444; font-size: 14px;";
|
|
44
|
+
errorMessage.textContent = "Local network access is required for your widget to connect to the local dev server. Please enable it in your browser settings. ";
|
|
45
|
+
|
|
46
|
+
const link = document.createElement("a");
|
|
47
|
+
link.href = "https://developer.chrome.com/blog/local-network-access";
|
|
48
|
+
link.target = "_blank";
|
|
49
|
+
link.rel = "noopener noreferrer";
|
|
50
|
+
link.style.cssText = "color: #ef4444; text-decoration: underline;";
|
|
51
|
+
link.textContent = "Learn more";
|
|
52
|
+
errorMessage.appendChild(link);
|
|
53
|
+
|
|
54
|
+
errorDiv.appendChild(errorTitle);
|
|
55
|
+
errorDiv.appendChild(errorMessage);
|
|
56
|
+
document.body.appendChild(errorDiv);
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Permission API doesn't support local-network-access, ignore silently
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
</script>
|
|
63
|
+
<div id="root"></div>
|
|
64
|
+
<script type="module" id="dev-widget-entry">
|
|
65
|
+
import('{{serverUrl}}/src/widgets/{{widgetName}}');
|
|
12
66
|
</script>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Router } from "express";
|
|
2
2
|
/**
|
|
3
3
|
* Install Vite dev server
|
|
4
4
|
* This router MUST be installed at the application root, like so:
|
|
@@ -9,4 +9,4 @@ import { type RequestHandler } from "express";
|
|
|
9
9
|
* app.use(await widgetsRouter());
|
|
10
10
|
* }
|
|
11
11
|
*/
|
|
12
|
-
export declare const widgetsDevServer: () => Promise<
|
|
12
|
+
export declare const widgetsDevServer: () => Promise<Router>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import cors from "cors";
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import cors from "cors";
|
|
4
|
+
import express, {} from "express";
|
|
4
5
|
/**
|
|
5
6
|
* Install Vite dev server
|
|
6
7
|
* This router MUST be installed at the application root, like so:
|
|
@@ -14,10 +15,17 @@ import path from "node:path";
|
|
|
14
15
|
export const widgetsDevServer = async () => {
|
|
15
16
|
const router = express.Router();
|
|
16
17
|
const { createServer, searchForWorkspaceRoot, loadConfigFromFile } = await import("vite");
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
// Since 0.16.0, the template is a single package that does not rely on workspace.
|
|
19
|
+
// It means that, when starting the server, the working dir is the template root
|
|
20
|
+
// hence we don't need to walk up the tree to find the workspace, which does not exist anymore.
|
|
21
|
+
let webAppRoot = path.join(process.cwd(), "web");
|
|
22
|
+
// fallback to the old behavior for backward compatibility
|
|
23
|
+
const hasWebAppRoot = existsSync(webAppRoot);
|
|
24
|
+
if (!hasWebAppRoot) {
|
|
25
|
+
const workspaceRoot = searchForWorkspaceRoot(process.cwd());
|
|
26
|
+
webAppRoot = path.join(workspaceRoot, "web");
|
|
27
|
+
}
|
|
19
28
|
const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, path.join(webAppRoot, "vite.config.ts"), webAppRoot);
|
|
20
|
-
// Remove build-specific options that don't apply to dev server
|
|
21
29
|
const { build, preview, ...devConfig } = configResult?.config || {};
|
|
22
30
|
const vite = await createServer({
|
|
23
31
|
...devConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,EAAE,EAAe,MAAM,SAAS,CAAC;AAC/C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAAqB,EAAE;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,MAAM,EAAE,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,GAChE,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAEvB,kFAAkF;IAClF,gFAAgF;IAChF,+FAA+F;IAC/F,IAAI,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;IAEjD,0DAA0D;IAC1D,MAAM,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IAC7C,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,aAAa,GAAG,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5D,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAC3C,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,EACzC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,EACvC,UAAU,CACX,CAAC;IAEF,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,EAAE,MAAM,IAAI,EAAE,CAAC;IAEpE,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC;QAC9B,GAAG,SAAS;QACZ,UAAU,EAAE,KAAK,EAAE,kFAAkF;QACrG,OAAO,EAAE,QAAQ;QACjB,MAAM,EAAE;YACN,YAAY,EAAE,IAAI;YAClB,cAAc,EAAE,IAAI;SACrB;QACD,IAAI,EAAE,UAAU;QAChB,YAAY,EAAE;YACZ,OAAO,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC;SACvC;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/src/test/utils.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { McpServer } from "../server/server.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function createMockMcpServer(): {
|
|
7
7
|
server: McpServer;
|
|
8
|
-
|
|
8
|
+
mockRegisterResource: MockInstance<McpServer["registerResource"]>;
|
|
9
9
|
mockRegisterTool: MockInstance<McpServer["registerTool"]>;
|
|
10
10
|
};
|
|
11
|
-
export declare function createTestServer(): McpServer<{
|
|
11
|
+
export declare function createTestServer(): McpServer<Record<never, import("../server/server.js").ToolDef<unknown, unknown, unknown>> & {
|
|
12
12
|
"search-voyage": import("../server/server.js").ToolDef<{
|
|
13
13
|
destination: string;
|
|
14
14
|
departureDate?: string | undefined;
|
|
@@ -20,7 +20,7 @@ export declare function createTestServer(): McpServer<{
|
|
|
20
20
|
price: number;
|
|
21
21
|
}[];
|
|
22
22
|
totalCount: number;
|
|
23
|
-
}>;
|
|
23
|
+
}, unknown>;
|
|
24
24
|
} & {
|
|
25
25
|
"get-trip-details": import("../server/server.js").ToolDef<{
|
|
26
26
|
tripId: string;
|
|
@@ -28,9 +28,9 @@ export declare function createTestServer(): McpServer<{
|
|
|
28
28
|
name: string;
|
|
29
29
|
description: string;
|
|
30
30
|
images: string[];
|
|
31
|
-
}>;
|
|
31
|
+
}, unknown>;
|
|
32
32
|
} & {
|
|
33
|
-
"no-input-widget": import("../server/server.js").ToolDef<{}, {}>;
|
|
33
|
+
"no-input-widget": import("../server/server.js").ToolDef<{}, {}, unknown>;
|
|
34
34
|
} & {
|
|
35
35
|
"inferred-output-widget": import("../server/server.js").ToolDef<{
|
|
36
36
|
query: string;
|
|
@@ -40,7 +40,7 @@ export declare function createTestServer(): McpServer<{
|
|
|
40
40
|
score: number;
|
|
41
41
|
}[];
|
|
42
42
|
inferredCount: number;
|
|
43
|
-
}>;
|
|
43
|
+
}, unknown>;
|
|
44
44
|
} & {
|
|
45
45
|
"calculate-price": import("../server/server.js").ToolDef<{
|
|
46
46
|
tripId: string;
|
|
@@ -48,7 +48,7 @@ export declare function createTestServer(): McpServer<{
|
|
|
48
48
|
}, {
|
|
49
49
|
totalPrice: number;
|
|
50
50
|
currency: string;
|
|
51
|
-
}>;
|
|
51
|
+
}, unknown>;
|
|
52
52
|
} & {
|
|
53
53
|
"inferred-tool": import("../server/server.js").ToolDef<{
|
|
54
54
|
itemId: string;
|
|
@@ -58,15 +58,61 @@ export declare function createTestServer(): McpServer<{
|
|
|
58
58
|
available: boolean;
|
|
59
59
|
};
|
|
60
60
|
fetchedAt: string;
|
|
61
|
+
}, unknown>;
|
|
62
|
+
} & {
|
|
63
|
+
"widget-with-metadata": import("../server/server.js").ToolDef<{
|
|
64
|
+
resourceId: string;
|
|
65
|
+
}, {
|
|
66
|
+
data: {
|
|
67
|
+
id: string;
|
|
68
|
+
loaded: boolean;
|
|
69
|
+
};
|
|
70
|
+
}, {
|
|
71
|
+
requestId: string;
|
|
72
|
+
timestamp: number;
|
|
73
|
+
cached: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
} & {
|
|
76
|
+
"tool-with-metadata": import("../server/server.js").ToolDef<{
|
|
77
|
+
query: string;
|
|
78
|
+
}, {
|
|
79
|
+
results: string[];
|
|
80
|
+
}, {
|
|
81
|
+
executionTime: number;
|
|
82
|
+
source: string;
|
|
83
|
+
}>;
|
|
84
|
+
} & {
|
|
85
|
+
"widget-with-mixed-returns": import("../server/server.js").ToolDef<{
|
|
86
|
+
shouldSucceed: boolean;
|
|
87
|
+
}, {
|
|
88
|
+
error: string;
|
|
89
|
+
data?: undefined;
|
|
90
|
+
} | {
|
|
91
|
+
data: string;
|
|
92
|
+
error?: undefined;
|
|
93
|
+
}, {
|
|
94
|
+
processedAt: number;
|
|
95
|
+
region: string;
|
|
61
96
|
}>;
|
|
62
97
|
}>;
|
|
63
|
-
export declare function createMinimalTestServer(): McpServer<{
|
|
98
|
+
export declare function createMinimalTestServer(): McpServer<Record<never, import("../server/server.js").ToolDef<unknown, unknown, unknown>> & {
|
|
64
99
|
"search-voyage": import("../server/server.js").ToolDef<{
|
|
65
100
|
destination: string;
|
|
66
101
|
}, {
|
|
67
102
|
results: {
|
|
68
103
|
id: string;
|
|
69
104
|
}[];
|
|
105
|
+
}, unknown>;
|
|
106
|
+
}>;
|
|
107
|
+
export declare function createInterfaceTestServer(): McpServer<Record<never, import("../server/server.js").ToolDef<unknown, unknown, unknown>> & {
|
|
108
|
+
"interface-widget": import("../server/server.js").ToolDef<{
|
|
109
|
+
id: string;
|
|
110
|
+
}, {
|
|
111
|
+
itemName: string;
|
|
112
|
+
quantity: number;
|
|
113
|
+
}, {
|
|
114
|
+
processedBy: string;
|
|
115
|
+
version: number;
|
|
70
116
|
}>;
|
|
71
117
|
}>;
|
|
72
118
|
/**
|