@mcp-native/webview 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -20
- package/dist/apps.d.ts +82 -0
- package/dist/apps.d.ts.map +1 -0
- package/dist/apps.js +381 -0
- package/dist/apps.js.map +1 -0
- package/dist/bridge.d.ts +69 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +754 -0
- package/dist/bridge.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +107 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +308 -0
- package/dist/sandbox.js.map +1 -0
- package/package.json +2 -2
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { JsonObject, McpReadResourceResult, McpTool, McpToolCallResult } from "@mcp-native/core";
|
|
2
|
+
import { McpAppsError } from "./apps.js";
|
|
3
|
+
import type { McpAppsResource } from "./apps.js";
|
|
4
|
+
import type { McpAppsNativeSandboxConfiguration } from "./sandbox.js";
|
|
5
|
+
export declare const MCP_APPS_MAX_BRIDGE_MESSAGE_LENGTH = 1048576;
|
|
6
|
+
export declare const MCP_APPS_MAX_PENDING_REQUESTS = 128;
|
|
7
|
+
export type McpAppsDisplayMode = "fullscreen" | "inline" | "pip";
|
|
8
|
+
export type McpAppsBridgeState = "awaiting-initialize" | "awaiting-initialized" | "ready" | "closing" | "closed";
|
|
9
|
+
export type McpAppsContentModality = "audio" | "image" | "resource" | "resourceLink" | "structuredContent" | "text";
|
|
10
|
+
export interface McpAppsBridgeHandlers {
|
|
11
|
+
readonly callTool?: (name: string, arguments_: JsonObject, requestMeta?: JsonObject) => McpToolCallResult | Promise<McpToolCallResult>;
|
|
12
|
+
readonly readResource?: (uri: string, requestMeta?: JsonObject) => McpReadResourceResult | Promise<McpReadResourceResult>;
|
|
13
|
+
readonly openLink?: (url: string) => boolean | Promise<boolean>;
|
|
14
|
+
readonly downloadFile?: (contents: readonly JsonObject[]) => void | Promise<void>;
|
|
15
|
+
readonly sendMessage?: (message: JsonObject) => void | Promise<void>;
|
|
16
|
+
readonly updateModelContext?: (context: JsonObject) => void | Promise<void>;
|
|
17
|
+
readonly requestDisplayMode?: (mode: McpAppsDisplayMode) => McpAppsDisplayMode | Promise<McpAppsDisplayMode>;
|
|
18
|
+
readonly log?: (message: JsonObject) => void | Promise<void>;
|
|
19
|
+
readonly sizeChanged?: (size: {
|
|
20
|
+
readonly width?: number;
|
|
21
|
+
readonly height?: number;
|
|
22
|
+
}) => void;
|
|
23
|
+
readonly requestTeardown?: () => void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface McpAppsBridgeOptions {
|
|
26
|
+
readonly postMessage: (serializedMessage: string) => void | Promise<void>;
|
|
27
|
+
readonly hostInfo: {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly version: string;
|
|
30
|
+
readonly title?: string;
|
|
31
|
+
readonly websiteUrl?: string;
|
|
32
|
+
};
|
|
33
|
+
readonly hostContext?: unknown;
|
|
34
|
+
readonly tools?: readonly McpTool[];
|
|
35
|
+
readonly resource: McpAppsResource;
|
|
36
|
+
readonly sandbox: McpAppsNativeSandboxConfiguration;
|
|
37
|
+
readonly handlers?: McpAppsBridgeHandlers;
|
|
38
|
+
readonly messageModalities?: readonly McpAppsContentModality[];
|
|
39
|
+
readonly updateModelContextModalities?: readonly McpAppsContentModality[];
|
|
40
|
+
readonly onProtocolError?: (error: McpAppsBridgeError) => void;
|
|
41
|
+
readonly onTeardownComplete?: (result: "error" | "success") => void;
|
|
42
|
+
}
|
|
43
|
+
export declare class McpAppsBridgeError extends McpAppsError {
|
|
44
|
+
readonly code: number;
|
|
45
|
+
constructor(message: string, code?: number, options?: ErrorOptions);
|
|
46
|
+
}
|
|
47
|
+
type RequestId = number | string;
|
|
48
|
+
/**
|
|
49
|
+
* Stable MCP Apps host lifecycle for a single native WebView. Incoming data is
|
|
50
|
+
* schema-shaped and bounded before any host callback runs.
|
|
51
|
+
*/
|
|
52
|
+
export declare class McpAppsBridge {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(options: McpAppsBridgeOptions);
|
|
55
|
+
get state(): McpAppsBridgeState;
|
|
56
|
+
get hostCapabilities(): JsonObject;
|
|
57
|
+
/** Receives a serialized native WebView message or an already-decoded test value. */
|
|
58
|
+
receive(value: unknown): Promise<void>;
|
|
59
|
+
sendToolInput(arguments_?: unknown): Promise<void>;
|
|
60
|
+
sendPartialToolInput(arguments_?: unknown): Promise<void>;
|
|
61
|
+
sendToolResult(result: McpToolCallResult): Promise<void>;
|
|
62
|
+
sendToolCancelled(reason?: string): Promise<void>;
|
|
63
|
+
sendHostContextChanged(context: unknown): Promise<void>;
|
|
64
|
+
/** Begins graceful teardown. The View's matching response closes the bridge. */
|
|
65
|
+
requestResourceTeardown(): Promise<RequestId>;
|
|
66
|
+
close(): void;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAEV,qBAAqB,EACrB,OAAO,EACP,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAGL,YAAY,EAGb,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAEtE,eAAO,MAAM,kCAAkC,UAAY,CAAC;AAC5D,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAEjD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,QAAQ,GAAG,KAAK,CAAC;AACjE,MAAM,MAAM,kBAA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