@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.
@@ -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 provides origin validation by filtering messages
13
- * from specific sources. Guest UIs typically don't need to specify this (they only
14
- * communicate with their parent), but hosts should validate the iframe source for
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 (default)**:
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 (with source validation)**:
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 // Validate messages from this iframe only
29
+ * iframe.contentWindow!
31
30
  * );
32
31
  * await bridge.connect(transport);
33
32
  * ```
34
33
  *
35
- * @see {@link app.App.connect} for Guest UI usage
36
- * @see {@link app-bridge.AppBridge.connect} for Host usage
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 - Optional source validation. If specified, only messages from
47
- * this source will be accepted. Guest UIs typically don't need this (they only
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 with validation
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 // Only accept messages from this iframe
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
  /**