@modelcontextprotocol/ext-apps 0.4.0 → 0.4.1
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 +196 -1
- package/README.md +21 -10
- package/dist/src/app-bridge.d.ts +84 -71
- package/dist/src/app-bridge.js +2 -2
- package/dist/src/app-with-deps.js +2 -2
- package/dist/src/app.d.ts +33 -23
- package/dist/src/app.js +2 -2
- package/dist/src/generated/schema.d.ts +9 -9
- package/dist/src/message-transport.d.ts +20 -22
- package/dist/src/react/index.js +8 -8
- package/dist/src/react/react-with-deps.js +8 -8
- package/dist/src/react/useApp.d.ts +22 -17
- package/dist/src/react/useAutoResize.d.ts +5 -3
- package/dist/src/react/useDocumentTheme.d.ts +3 -1
- package/dist/src/react/useHostStyles.d.ts +19 -18
- package/dist/src/server/index.d.ts +106 -13
- package/dist/src/server/index.js +9 -9
- package/dist/src/spec.types.d.ts +15 -15
- package/dist/src/styles.d.ts +5 -5
- package/dist/src/types.d.ts +7 -6
- package/package.json +5 -3
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
import { JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
3
|
/**
|
|
4
|
-
* JSON-RPC transport using window.postMessage for iframe↔parent communication.
|
|
4
|
+
* JSON-RPC transport using `window.postMessage` for iframe↔parent communication.
|
|
5
5
|
*
|
|
6
6
|
* This transport enables bidirectional communication between MCP Apps running in
|
|
7
|
-
* iframes and their host applications using the browser's postMessage API. It
|
|
8
|
-
* implements the MCP SDK's Transport interface.
|
|
7
|
+
* iframes and their host applications using the browser's `postMessage` API. It
|
|
8
|
+
* implements the MCP SDK's `Transport` interface.
|
|
9
9
|
*
|
|
10
10
|
* ## Security
|
|
11
11
|
*
|
|
12
|
-
* The `eventSource` parameter
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* security.
|
|
12
|
+
* The `eventSource` parameter is required and validates the message source window
|
|
13
|
+
* by checking `event.source`. For guest UIs, pass `window.parent`.
|
|
14
|
+
* For hosts, pass `iframe.contentWindow` to validate the iframe source.
|
|
16
15
|
*
|
|
17
16
|
* ## Usage
|
|
18
17
|
*
|
|
19
|
-
* **Guest UI
|
|
18
|
+
* **Guest UI**:
|
|
20
19
|
* ```typescript
|
|
21
|
-
* const transport = new PostMessageTransport(window.parent);
|
|
20
|
+
* const transport = new PostMessageTransport(window.parent, window.parent);
|
|
22
21
|
* await app.connect(transport);
|
|
23
22
|
* ```
|
|
24
23
|
*
|
|
25
|
-
* **Host
|
|
24
|
+
* **Host**:
|
|
26
25
|
* ```typescript
|
|
27
26
|
* const iframe = document.getElementById('app-iframe') as HTMLIFrameElement;
|
|
28
27
|
* const transport = new PostMessageTransport(
|
|
29
28
|
* iframe.contentWindow!,
|
|
30
|
-
* iframe.contentWindow
|
|
29
|
+
* iframe.contentWindow!
|
|
31
30
|
* );
|
|
32
31
|
* await bridge.connect(transport);
|
|
33
32
|
* ```
|
|
34
33
|
*
|
|
35
|
-
* @see {@link app
|
|
36
|
-
* @see {@link app-bridge
|
|
34
|
+
* @see {@link app!App.connect} for Guest UI usage
|
|
35
|
+
* @see {@link app-bridge!AppBridge.connect} for Host usage
|
|
37
36
|
*/
|
|
38
37
|
export declare class PostMessageTransport implements Transport {
|
|
39
38
|
private eventTarget;
|
|
@@ -42,22 +41,21 @@ export declare class PostMessageTransport implements Transport {
|
|
|
42
41
|
/**
|
|
43
42
|
* Create a new PostMessageTransport.
|
|
44
43
|
*
|
|
45
|
-
* @param eventTarget - Target window to send messages to (default: window.parent)
|
|
46
|
-
* @param eventSource -
|
|
47
|
-
*
|
|
48
|
-
* receive from parent), but hosts should validate the iframe source.
|
|
44
|
+
* @param eventTarget - Target window to send messages to (default: `window.parent`)
|
|
45
|
+
* @param eventSource - Source window for message validation. For guests, pass
|
|
46
|
+
* `window.parent`. For hosts, pass `iframe.contentWindow`.
|
|
49
47
|
*
|
|
50
48
|
* @example Guest UI connecting to parent
|
|
51
49
|
* ```typescript
|
|
52
|
-
* const transport = new PostMessageTransport(window.parent);
|
|
50
|
+
* const transport = new PostMessageTransport(window.parent, window.parent);
|
|
53
51
|
* ```
|
|
54
52
|
*
|
|
55
|
-
* @example Host connecting to iframe
|
|
53
|
+
* @example Host connecting to iframe
|
|
56
54
|
* ```typescript
|
|
57
55
|
* const iframe = document.getElementById('app') as HTMLIFrameElement;
|
|
58
56
|
* const transport = new PostMessageTransport(
|
|
59
57
|
* iframe.contentWindow!,
|
|
60
|
-
* iframe.contentWindow
|
|
58
|
+
* iframe.contentWindow!
|
|
61
59
|
* );
|
|
62
60
|
* ```
|
|
63
61
|
*/
|
|
@@ -72,7 +70,7 @@ export declare class PostMessageTransport implements Transport {
|
|
|
72
70
|
/**
|
|
73
71
|
* Send a JSON-RPC message to the target window.
|
|
74
72
|
*
|
|
75
|
-
* Messages are sent using postMessage with "*" origin, meaning they are visible
|
|
73
|
+
* Messages are sent using `postMessage` with `"*"` origin, meaning they are visible
|
|
76
74
|
* to all frames. The receiver should validate the message source for security.
|
|
77
75
|
*
|
|
78
76
|
* @param message - JSON-RPC message to send
|
|
@@ -114,7 +112,7 @@ export declare class PostMessageTransport implements Transport {
|
|
|
114
112
|
* Optional session identifier for this transport connection.
|
|
115
113
|
*
|
|
116
114
|
* Set by the MCP SDK to track the connection session. Not required for
|
|
117
|
-
* PostMessageTransport functionality.
|
|
115
|
+
* `PostMessageTransport` functionality.
|
|
118
116
|
*/
|
|
119
117
|
sessionId?: string;
|
|
120
118
|
/**
|