@mcp-b/transports 1.0.3 → 1.1.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/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
2
- import { Transport, TransportSendOptions } from '@modelcontextprotocol/sdk/shared/transport.js';
1
+ import { JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
2
+ import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
3
3
 
4
+ //#region src/browser-types.d.ts
4
5
  /**
5
6
  * Unique identifier for an event in the event store
6
7
  */
@@ -13,217 +14,218 @@ type StreamId = string;
13
14
  * Options for connecting to an MCP server
14
15
  */
15
16
  interface MCPConnectOptions {
16
- /**
17
- * The event ID to resume from if reconnecting
18
- */
19
- resumeFrom?: EventId;
17
+ /**
18
+ * The event ID to resume from if reconnecting
19
+ */
20
+ resumeFrom?: EventId;
20
21
  }
21
22
  /**
22
23
  * Information about the MCP server
23
24
  */
24
25
  interface MCPServerInfo {
25
- /**
26
- * Unique identifier for this server instance
27
- */
28
- instanceId: string;
29
- /**
30
- * Whether the server maintains session state
31
- */
32
- stateful: boolean;
33
- /**
34
- * Whether the server has event storage enabled
35
- */
36
- hasEventStore: boolean;
26
+ /**
27
+ * Unique identifier for this server instance
28
+ */
29
+ instanceId: string;
30
+ /**
31
+ * Whether the server maintains session state
32
+ */
33
+ stateful: boolean;
34
+ /**
35
+ * Whether the server has event storage enabled
36
+ */
37
+ hasEventStore: boolean;
37
38
  }
38
39
  /**
39
40
  * Event storage interface for accessing stored events
40
41
  */
41
42
  interface MCPEventStore {
42
- /**
43
- * Get stored events, optionally filtered by client and/or after a specific event
44
- * @param clientId - Optional client ID to filter events
45
- * @param afterEventId - Optional event ID to get events after
46
- * @param limit - Maximum number of events to return (default: 100)
47
- */
48
- getEvents(clientId?: string, afterEventId?: EventId, limit?: number): StoredEvent[];
49
- /**
50
- * Get the ID of the last event, optionally for a specific client
51
- * @param clientId - Optional client ID to filter by
52
- */
53
- getLastEventId(clientId?: string): EventId | null;
54
- /**
55
- * Clear stored events, optionally for a specific client
56
- * @param clientId - Optional client ID to clear events for
57
- */
58
- clearEvents(clientId?: string): void;
43
+ /**
44
+ * Get stored events, optionally filtered by client and/or after a specific event
45
+ * @param clientId - Optional client ID to filter events
46
+ * @param afterEventId - Optional event ID to get events after
47
+ * @param limit - Maximum number of events to return (default: 100)
48
+ */
49
+ getEvents(clientId?: string, afterEventId?: EventId, limit?: number): StoredEvent[];
50
+ /**
51
+ * Get the ID of the last event, optionally for a specific client
52
+ * @param clientId - Optional client ID to filter by
53
+ */
54
+ getLastEventId(clientId?: string): EventId | null;
55
+ /**
56
+ * Clear stored events, optionally for a specific client
57
+ * @param clientId - Optional client ID to clear events for
58
+ */
59
+ clearEvents(clientId?: string): void;
59
60
  }
60
61
  /**
61
62
  * The MCP interface exposed on window for browser environments
62
63
  */
63
64
  interface MCPBrowserInterface {
64
- /**
65
- * Connect a client to the MCP server
66
- * @param clientId - Unique identifier for the client
67
- * @param options - Optional connection options
68
- * @returns MessagePort for communication or null if connection fails
69
- */
70
- connect(clientId: string, options?: MCPConnectOptions): MessagePort | null;
71
- /**
72
- * Disconnect a client from the MCP server
73
- * @param clientId - The client ID to disconnect
74
- */
75
- disconnect(clientId: string): void;
76
- /**
77
- * Terminate a client's session and clean up all associated resources
78
- * @param clientId - The client ID to terminate
79
- */
80
- terminateSession?(clientId: string): void;
81
- /**
82
- * Check if the MCP server is available and running
83
- */
84
- isServerAvailable(): boolean;
85
- /**
86
- * Get information about the MCP server
87
- */
88
- getServerInfo(): MCPServerInfo;
89
- /**
90
- * Event storage access (only available in stateful mode with event store)
91
- */
92
- events?: MCPEventStore;
65
+ /**
66
+ * Connect a client to the MCP server
67
+ * @param clientId - Unique identifier for the client
68
+ * @param options - Optional connection options
69
+ * @returns MessagePort for communication or null if connection fails
70
+ */
71
+ connect(clientId: string, options?: MCPConnectOptions): MessagePort | null;
72
+ /**
73
+ * Disconnect a client from the MCP server
74
+ * @param clientId - The client ID to disconnect
75
+ */
76
+ disconnect(clientId: string): void;
77
+ /**
78
+ * Terminate a client's session and clean up all associated resources
79
+ * @param clientId - The client ID to terminate
80
+ */
81
+ terminateSession?(clientId: string): void;
82
+ /**
83
+ * Check if the MCP server is available and running
84
+ */
85
+ isServerAvailable(): boolean;
86
+ /**
87
+ * Get information about the MCP server
88
+ */
89
+ getServerInfo(): MCPServerInfo;
90
+ /**
91
+ * Event storage access (only available in stateful mode with event store)
92
+ */
93
+ events?: MCPEventStore;
93
94
  }
94
95
  /**
95
96
  * Extended Window interface with MCP support
96
97
  */
97
98
  interface MCPWindow extends Window {
98
- mcp?: MCPBrowserInterface;
99
+ mcp?: MCPBrowserInterface;
99
100
  }
100
101
  /**
101
102
  * Message types for internal MCP communication
102
103
  */
103
104
  interface MCPServerInfoMessage {
104
- type: 'mcp-server-info';
105
- serverInstanceId: string;
106
- serverSessionId?: string;
107
- hasEventStore: boolean;
108
- streamId: StreamId;
105
+ type: 'mcp-server-info';
106
+ serverInstanceId: string;
107
+ serverSessionId?: string;
108
+ hasEventStore: boolean;
109
+ streamId: StreamId;
109
110
  }
110
111
  interface MCPEventMessage {
111
- type: 'mcp-event';
112
- eventId: EventId;
113
- message: JSONRPCMessage;
112
+ type: 'mcp-event';
113
+ eventId: EventId;
114
+ message: JSONRPCMessage;
114
115
  }
115
116
  interface MCPReplayEventMessage {
116
- type: 'mcp-replay-event';
117
- eventId: EventId;
118
- message: JSONRPCMessage;
117
+ type: 'mcp-replay-event';
118
+ eventId: EventId;
119
+ message: JSONRPCMessage;
119
120
  }
120
121
  /**
121
122
  * Stored event with metadata for event sourcing
122
123
  */
123
124
  interface StoredEvent {
124
- eventId: EventId;
125
- streamId: StreamId;
126
- message: JSONRPCMessage;
127
- timestamp: number;
128
- clientId: string;
125
+ eventId: EventId;
126
+ streamId: StreamId;
127
+ message: JSONRPCMessage;
128
+ timestamp: number;
129
+ clientId: string;
129
130
  }
130
131
  declare enum NativeMessageType {
131
- START = "start",
132
- STARTED = "started",
133
- STOP = "stop",
134
- STOPPED = "stopped",
135
- PING = "ping",
136
- PONG = "pong",
137
- ERROR = "error",
138
- LIST_TOOLS = "list_tools",
139
- CALL_TOOL = "call_tool",
140
- TOOL_LIST_UPDATED = "tool_list_updated",
141
- TOOL_LIST_UPDATED_ACK = "tool_list_updated_ack",
142
- PROCESS_DATA = "process_data",
143
- SERVER_STARTED = "server_started",
144
- SERVER_STOPPED = "server_stopped",
145
- ERROR_FROM_NATIVE_HOST = "error_from_native_host",
146
- CONNECT_NATIVE = "connectNative",
147
- PING_NATIVE = "ping_native",
148
- DISCONNECT_NATIVE = "disconnect_native"
132
+ START = "start",
133
+ STARTED = "started",
134
+ STOP = "stop",
135
+ STOPPED = "stopped",
136
+ PING = "ping",
137
+ PONG = "pong",
138
+ ERROR = "error",
139
+ LIST_TOOLS = "list_tools",
140
+ CALL_TOOL = "call_tool",
141
+ TOOL_LIST_UPDATED = "tool_list_updated",
142
+ TOOL_LIST_UPDATED_ACK = "tool_list_updated_ack",
143
+ PROCESS_DATA = "process_data",
144
+ SERVER_STARTED = "server_started",
145
+ SERVER_STOPPED = "server_stopped",
146
+ ERROR_FROM_NATIVE_HOST = "error_from_native_host",
147
+ CONNECT_NATIVE = "connectNative",
148
+ PING_NATIVE = "ping_native",
149
+ DISCONNECT_NATIVE = "disconnect_native",
149
150
  }
150
151
  /**
151
152
  * Chrome Extension Constants
152
153
  * Centralized configuration values and magic constants
153
154
  */
154
155
  declare const NATIVE_HOST: {
155
- readonly NAME: "com.chromemcp.nativehost";
156
- readonly DEFAULT_PORT: 12306;
156
+ readonly NAME: "com.chromemcp.nativehost";
157
+ readonly DEFAULT_PORT: 12306;
157
158
  };
158
159
  declare const ERROR_MESSAGES: {
159
- readonly NATIVE_CONNECTION_FAILED: "Failed to connect to native host";
160
- readonly NATIVE_DISCONNECTED: "Native connection disconnected";
161
- readonly SERVER_STATUS_LOAD_FAILED: "Failed to load server status";
162
- readonly TOOL_EXECUTION_FAILED: "Tool execution failed";
163
- readonly SERVER_STATUS_SAVE_FAILED: "Failed to save server status";
160
+ readonly NATIVE_CONNECTION_FAILED: "Failed to connect to native host";
161
+ readonly NATIVE_DISCONNECTED: "Native connection disconnected";
162
+ readonly SERVER_STATUS_LOAD_FAILED: "Failed to load server status";
163
+ readonly TOOL_EXECUTION_FAILED: "Tool execution failed";
164
+ readonly SERVER_STATUS_SAVE_FAILED: "Failed to save server status";
164
165
  };
165
166
  declare const SUCCESS_MESSAGES: {
166
- readonly TOOL_EXECUTED: "Tool executed successfully";
167
- readonly CONNECTION_ESTABLISHED: "Connection established";
168
- readonly SERVER_STARTED: "Server started successfully";
169
- readonly SERVER_STOPPED: "Server stopped successfully";
167
+ readonly TOOL_EXECUTED: "Tool executed successfully";
168
+ readonly CONNECTION_ESTABLISHED: "Connection established";
169
+ readonly SERVER_STARTED: "Server started successfully";
170
+ readonly SERVER_STOPPED: "Server stopped successfully";
170
171
  };
171
172
  declare const STORAGE_KEYS: {
172
- readonly SERVER_STATUS: "serverStatus";
173
+ readonly SERVER_STATUS: "serverStatus";
173
174
  };
174
175
  declare const BACKGROUND_MESSAGE_TYPES: {
175
- readonly GET_SERVER_STATUS: "get_server_status";
176
- readonly REFRESH_SERVER_STATUS: "refresh_server_status";
177
- readonly SERVER_STATUS_CHANGED: "server_status_changed";
176
+ readonly GET_SERVER_STATUS: "get_server_status";
177
+ readonly REFRESH_SERVER_STATUS: "refresh_server_status";
178
+ readonly SERVER_STATUS_CHANGED: "server_status_changed";
178
179
  };
179
180
  declare const HOST_NAME: "com.chromemcp.nativehost";
180
181
  /**
181
182
  * Server status management interface
182
183
  */
183
184
  interface ServerStatus {
184
- isRunning: boolean;
185
- port?: number;
186
- lastUpdated: number;
185
+ isRunning: boolean;
186
+ port?: number;
187
+ lastUpdated: number;
187
188
  }
188
-
189
+ //#endregion
190
+ //#region src/ExtensionClientTransport.d.ts
189
191
  /**
190
192
  * Configuration options for ExtensionClientTransport
191
193
  */
192
194
  interface ExtensionClientTransportOptions {
193
- /**
194
- * The extension ID to connect to (optional for same-extension connections)
195
- */
196
- extensionId?: string;
197
- /**
198
- * Port name for the connection
199
- * Default: 'mcp'
200
- */
201
- portName?: string;
202
- /**
203
- * Enable automatic reconnection on disconnect
204
- * Default: true
205
- */
206
- autoReconnect?: boolean;
207
- /**
208
- * Maximum number of reconnection attempts
209
- * Default: 10
210
- */
211
- maxReconnectAttempts?: number;
212
- /**
213
- * Initial reconnection delay in milliseconds
214
- * Default: 1000
215
- */
216
- reconnectDelay?: number;
217
- /**
218
- * Maximum reconnection delay in milliseconds
219
- * Default: 30000
220
- */
221
- maxReconnectDelay?: number;
222
- /**
223
- * Reconnection backoff multiplier
224
- * Default: 1.5
225
- */
226
- reconnectBackoffMultiplier?: number;
195
+ /**
196
+ * The extension ID to connect to (optional for same-extension connections)
197
+ */
198
+ extensionId?: string;
199
+ /**
200
+ * Port name for the connection
201
+ * Default: 'mcp'
202
+ */
203
+ portName?: string;
204
+ /**
205
+ * Enable automatic reconnection on disconnect
206
+ * Default: true
207
+ */
208
+ autoReconnect?: boolean;
209
+ /**
210
+ * Maximum number of reconnection attempts
211
+ * Default: 10
212
+ */
213
+ maxReconnectAttempts?: number;
214
+ /**
215
+ * Initial reconnection delay in milliseconds
216
+ * Default: 1000
217
+ */
218
+ reconnectDelay?: number;
219
+ /**
220
+ * Maximum reconnection delay in milliseconds
221
+ * Default: 30000
222
+ */
223
+ maxReconnectDelay?: number;
224
+ /**
225
+ * Reconnection backoff multiplier
226
+ * Default: 1.5
227
+ */
228
+ reconnectBackoffMultiplier?: number;
227
229
  }
228
230
  /**
229
231
  * Client transport for Chrome extensions using Port-based messaging.
@@ -233,70 +235,71 @@ interface ExtensionClientTransportOptions {
233
235
  * Features automatic reconnection to handle background service worker lifecycle.
234
236
  */
235
237
  declare class ExtensionClientTransport implements Transport {
236
- private _port?;
237
- private _extensionId?;
238
- private _portName;
239
- private _messageHandler?;
240
- private _disconnectHandler?;
241
- private _isReconnecting;
242
- private _reconnectAttempts;
243
- private _reconnectTimer?;
244
- private _currentReconnectDelay;
245
- private _isStarted;
246
- private _isClosed;
247
- private _autoReconnect;
248
- private _maxReconnectAttempts;
249
- private _reconnectDelay;
250
- private _maxReconnectDelay;
251
- private _reconnectBackoffMultiplier;
252
- onclose?: () => void;
253
- onerror?: (error: Error) => void;
254
- onmessage?: (message: JSONRPCMessage) => void;
255
- constructor(options?: ExtensionClientTransportOptions);
256
- /**
257
- * Starts the transport by connecting to the extension port
258
- */
259
- start(): Promise<void>;
260
- /**
261
- * Connects to the extension port
262
- */
263
- private _connect;
264
- /**
265
- * Sends a message to the server
266
- */
267
- send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
268
- /**
269
- * Closes the transport
270
- */
271
- close(): Promise<void>;
272
- /**
273
- * Cleans up event listeners and references
274
- */
275
- private _cleanup;
276
- /**
277
- * Schedules a reconnection attempt
278
- */
279
- private _scheduleReconnect;
280
- /**
281
- * Attempts to reconnect to the extension
282
- */
283
- private _attemptReconnect;
238
+ private _port;
239
+ private _extensionId;
240
+ private _portName;
241
+ private _messageHandler;
242
+ private _disconnectHandler;
243
+ private _isReconnecting;
244
+ private _reconnectAttempts;
245
+ private _reconnectTimer;
246
+ private _currentReconnectDelay;
247
+ private _isStarted;
248
+ private _isClosed;
249
+ private _autoReconnect;
250
+ private _maxReconnectAttempts;
251
+ private _reconnectDelay;
252
+ private _maxReconnectDelay;
253
+ private _reconnectBackoffMultiplier;
254
+ onclose?: () => void;
255
+ onerror?: (error: Error) => void;
256
+ onmessage?: (message: JSONRPCMessage) => void;
257
+ constructor(options?: ExtensionClientTransportOptions);
258
+ /**
259
+ * Starts the transport by connecting to the extension port
260
+ */
261
+ start(): Promise<void>;
262
+ /**
263
+ * Connects to the extension port
264
+ */
265
+ private _connect;
266
+ /**
267
+ * Sends a message to the server
268
+ */
269
+ send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
270
+ /**
271
+ * Closes the transport
272
+ */
273
+ close(): Promise<void>;
274
+ /**
275
+ * Cleans up event listeners and references
276
+ */
277
+ private _cleanup;
278
+ /**
279
+ * Schedules a reconnection attempt
280
+ */
281
+ private _scheduleReconnect;
282
+ /**
283
+ * Attempts to reconnect to the extension
284
+ */
285
+ private _attemptReconnect;
284
286
  }
285
-
287
+ //#endregion
288
+ //#region src/ExtensionServerTransport.d.ts
286
289
  /**
287
290
  * Configuration options for ExtensionServerTransport
288
291
  */
289
292
  type ExtensionServerTransportOptions = {
290
- /**
291
- * Enable keep-alive mechanism to prevent service worker shutdown
292
- * Default: true
293
- */
294
- keepAlive?: boolean;
295
- /**
296
- * Keep-alive interval in milliseconds
297
- * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)
298
- */
299
- keepAliveInterval?: number;
293
+ /**
294
+ * Enable keep-alive mechanism to prevent service worker shutdown
295
+ * Default: true
296
+ */
297
+ keepAlive?: boolean;
298
+ /**
299
+ * Keep-alive interval in milliseconds
300
+ * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)
301
+ */
302
+ keepAliveInterval?: number;
300
303
  };
301
304
  /**
302
305
  * Server transport for Chrome extensions using Port-based messaging.
@@ -308,132 +311,236 @@ type ExtensionServerTransportOptions = {
308
311
  * - Graceful connection state management
309
312
  */
310
313
  declare class ExtensionServerTransport implements Transport {
311
- private _port;
312
- private _started;
313
- private _messageHandler?;
314
- private _disconnectHandler?;
315
- private _keepAliveTimer?;
316
- private _options;
317
- private _connectionInfo;
318
- onclose?: () => void;
319
- onerror?: (error: Error) => void;
320
- onmessage?: (message: JSONRPCMessage) => void;
321
- constructor(port: chrome.runtime.Port, options?: ExtensionServerTransportOptions);
322
- /**
323
- * Starts the transport and begins handling messages
324
- */
325
- start(): Promise<void>;
326
- /**
327
- * Sends a message to the client
328
- */
329
- send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
330
- /**
331
- * Closes the transport
332
- */
333
- close(): Promise<void>;
334
- /**
335
- * Cleans up event listeners and references
336
- */
337
- private _cleanup;
338
- /**
339
- * Starts the keep-alive mechanism
340
- */
341
- private _startKeepAlive;
342
- /**
343
- * Stops the keep-alive mechanism
344
- */
345
- private _stopKeepAlive;
346
- /**
347
- * Gets connection information
348
- */
349
- getConnectionInfo(): {
350
- uptime: number;
351
- isConnected: boolean;
352
- connectedAt: number;
353
- lastMessageAt: number;
354
- messageCount: number;
355
- };
314
+ private _port;
315
+ private _started;
316
+ private _messageHandler;
317
+ private _disconnectHandler;
318
+ private _keepAliveTimer;
319
+ private _options;
320
+ private _connectionInfo;
321
+ onclose?: () => void;
322
+ onerror?: (error: Error) => void;
323
+ onmessage?: (message: JSONRPCMessage) => void;
324
+ constructor(port: chrome.runtime.Port, options?: ExtensionServerTransportOptions);
325
+ /**
326
+ * Starts the transport and begins handling messages
327
+ */
328
+ start(): Promise<void>;
329
+ /**
330
+ * Sends a message to the client
331
+ */
332
+ send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
333
+ /**
334
+ * Closes the transport
335
+ */
336
+ close(): Promise<void>;
337
+ /**
338
+ * Cleans up event listeners and references
339
+ */
340
+ private _cleanup;
341
+ /**
342
+ * Starts the keep-alive mechanism
343
+ */
344
+ private _startKeepAlive;
345
+ /**
346
+ * Stops the keep-alive mechanism
347
+ */
348
+ private _stopKeepAlive;
349
+ /**
350
+ * Gets connection information
351
+ */
352
+ getConnectionInfo(): {
353
+ uptime: number;
354
+ isConnected: boolean;
355
+ connectedAt: number;
356
+ lastMessageAt: number;
357
+ messageCount: number;
358
+ };
356
359
  }
357
-
360
+ //#endregion
361
+ //#region src/IframeChildTransport.d.ts
362
+ interface IframeChildTransportOptions {
363
+ /** Whitelist of parent origins allowed to connect (for security) */
364
+ allowedOrigins: string[];
365
+ /** Optional channel name (default: 'mcp-iframe') */
366
+ channelId?: string;
367
+ /** Retry interval for broadcasting ready signal in milliseconds (default: 250) */
368
+ serverReadyRetryMs?: number;
369
+ }
370
+ /**
371
+ * IframeChildTransport - Server transport for iframe
372
+ *
373
+ * Use this transport when an iframe wants to expose an MCP server to its parent page.
374
+ * Supports cross-origin communication.
375
+ *
376
+ * @example
377
+ * ```typescript
378
+ * const transport = new IframeChildTransport({
379
+ * allowedOrigins: ['https://parent-app.com'],
380
+ * });
381
+ *
382
+ * const server = new Server({ name: 'IframeApp', version: '1.0.0' });
383
+ * await server.connect(transport);
384
+ * ```
385
+ */
386
+ declare class IframeChildTransport implements Transport {
387
+ private _started;
388
+ private _allowedOrigins;
389
+ private _channelId;
390
+ private _messageHandler?;
391
+ private _clientOrigin?;
392
+ private _serverReadyTimeout;
393
+ private readonly _serverReadyRetryMs;
394
+ onclose?: () => void;
395
+ onerror?: (error: Error) => void;
396
+ onmessage?: (message: JSONRPCMessage) => void;
397
+ constructor(options: IframeChildTransportOptions);
398
+ start(): Promise<void>;
399
+ private broadcastServerReady;
400
+ private scheduleServerReadyRetry;
401
+ private clearServerReadyRetry;
402
+ send(message: JSONRPCMessage): Promise<void>;
403
+ close(): Promise<void>;
404
+ }
405
+ //#endregion
406
+ //#region src/IframeParentTransport.d.ts
407
+ interface IframeParentTransportOptions {
408
+ /** Reference to the iframe element */
409
+ iframe: HTMLIFrameElement;
410
+ /** Expected origin of the iframe (for security) */
411
+ targetOrigin: string;
412
+ /** Optional channel name (default: 'mcp-iframe') */
413
+ channelId?: string;
414
+ /** Retry interval for ready handshake in milliseconds (default: 250) */
415
+ checkReadyRetryMs?: number;
416
+ }
417
+ /**
418
+ * IframeParentTransport - Client transport for parent page
419
+ *
420
+ * Use this transport when the parent page wants to connect to an MCP server
421
+ * running inside an iframe. Supports cross-origin communication.
422
+ *
423
+ * @example
424
+ * ```typescript
425
+ * const iframe = document.querySelector('iframe');
426
+ * const transport = new IframeParentTransport({
427
+ * iframe,
428
+ * targetOrigin: 'https://iframe-app.com',
429
+ * });
430
+ *
431
+ * const client = new Client({ name: 'Parent', version: '1.0.0' });
432
+ * await client.connect(transport);
433
+ * ```
434
+ */
435
+ declare class IframeParentTransport implements Transport {
436
+ private _started;
437
+ private _iframe;
438
+ private _targetOrigin;
439
+ private _channelId;
440
+ private _messageHandler?;
441
+ private _checkReadyTimeout;
442
+ private readonly _checkReadyRetryMs;
443
+ readonly serverReadyPromise: Promise<void>;
444
+ private _serverReadyResolve;
445
+ private _serverReadyReject;
446
+ onclose?: () => void;
447
+ onerror?: (error: Error) => void;
448
+ onmessage?: (message: JSONRPCMessage) => void;
449
+ constructor(options: IframeParentTransportOptions);
450
+ start(): Promise<void>;
451
+ private sendCheckReady;
452
+ private scheduleCheckReadyRetry;
453
+ private clearCheckReadyRetry;
454
+ send(message: JSONRPCMessage): Promise<void>;
455
+ close(): Promise<void>;
456
+ }
457
+ //#endregion
458
+ //#region src/TabClientTransport.d.ts
358
459
  interface TabClientTransportOptions {
359
- targetOrigin: string;
360
- channelId?: string;
460
+ /** Origin expected from the server window (for security) */
461
+ targetOrigin: string;
462
+ /** Optional channel name (default: 'mcp-default') */
463
+ channelId?: string;
361
464
  }
362
465
  declare class TabClientTransport implements Transport {
363
- private _started;
364
- private _targetOrigin;
365
- private _channelId;
366
- private _messageHandler?;
367
- readonly serverReadyPromise: Promise<void>;
368
- private _serverReadyResolve;
369
- private _serverReadyReject;
370
- onclose?: () => void;
371
- onerror?: (error: Error) => void;
372
- onmessage?: (message: JSONRPCMessage) => void;
373
- constructor(options: TabClientTransportOptions);
374
- start(): Promise<void>;
375
- private sendCheckReady;
376
- send(message: JSONRPCMessage): Promise<void>;
377
- close(): Promise<void>;
466
+ private _started;
467
+ private _targetOrigin;
468
+ private _channelId;
469
+ private _messageHandler?;
470
+ readonly serverReadyPromise: Promise<void>;
471
+ private _serverReadyResolve;
472
+ private _serverReadyReject;
473
+ onclose?: () => void;
474
+ onerror?: (error: Error) => void;
475
+ onmessage?: (message: JSONRPCMessage) => void;
476
+ constructor(options: TabClientTransportOptions);
477
+ start(): Promise<void>;
478
+ private sendCheckReady;
479
+ send(message: JSONRPCMessage): Promise<void>;
480
+ close(): Promise<void>;
378
481
  }
379
-
482
+ //#endregion
483
+ //#region src/TabServerTransport.d.ts
380
484
  interface TabServerTransportOptions {
381
- allowedOrigins: string[];
382
- channelId?: string;
485
+ /** Whitelist of origins allowed to connect (for security) */
486
+ allowedOrigins: string[];
487
+ /** Optional channel name (default: 'mcp-default') */
488
+ channelId?: string;
383
489
  }
384
490
  declare class TabServerTransport implements Transport {
385
- private _started;
386
- private _allowedOrigins;
387
- private _channelId;
388
- private _messageHandler?;
389
- private _clientOrigin?;
390
- onclose?: () => void;
391
- onerror?: (error: Error) => void;
392
- onmessage?: (message: JSONRPCMessage) => void;
393
- constructor(options: TabServerTransportOptions);
394
- start(): Promise<void>;
395
- send(message: JSONRPCMessage): Promise<void>;
396
- close(): Promise<void>;
491
+ private _started;
492
+ private _allowedOrigins;
493
+ private _channelId;
494
+ private _messageHandler?;
495
+ private _clientOrigin?;
496
+ onclose?: () => void;
497
+ onerror?: (error: Error) => void;
498
+ onmessage?: (message: JSONRPCMessage) => void;
499
+ constructor(options: TabServerTransportOptions);
500
+ start(): Promise<void>;
501
+ send(message: JSONRPCMessage): Promise<void>;
502
+ close(): Promise<void>;
397
503
  }
398
-
504
+ //#endregion
505
+ //#region src/UserScriptClientTransport.d.ts
399
506
  /**
400
507
  * Configuration options for UserScriptClientTransport
401
508
  */
402
509
  interface UserScriptClientTransportOptions {
403
- /**
404
- * The extension ID to connect to (optional for same-extension connections)
405
- */
406
- extensionId?: string;
407
- /**
408
- * Port name for the connection
409
- * Default: 'mcp'
410
- */
411
- portName?: string;
412
- /**
413
- * Enable automatic reconnection on disconnect
414
- * Default: true
415
- */
416
- autoReconnect?: boolean;
417
- /**
418
- * Maximum number of reconnection attempts
419
- * Default: 10
420
- */
421
- maxReconnectAttempts?: number;
422
- /**
423
- * Initial reconnection delay in milliseconds
424
- * Default: 1000
425
- */
426
- reconnectDelay?: number;
427
- /**
428
- * Maximum reconnection delay in milliseconds
429
- * Default: 30000
430
- */
431
- maxReconnectDelay?: number;
432
- /**
433
- * Reconnection backoff multiplier
434
- * Default: 1.5
435
- */
436
- reconnectBackoffMultiplier?: number;
510
+ /**
511
+ * The extension ID to connect to (optional for same-extension connections)
512
+ */
513
+ extensionId?: string;
514
+ /**
515
+ * Port name for the connection
516
+ * Default: 'mcp'
517
+ */
518
+ portName?: string;
519
+ /**
520
+ * Enable automatic reconnection on disconnect
521
+ * Default: true
522
+ */
523
+ autoReconnect?: boolean;
524
+ /**
525
+ * Maximum number of reconnection attempts
526
+ * Default: 10
527
+ */
528
+ maxReconnectAttempts?: number;
529
+ /**
530
+ * Initial reconnection delay in milliseconds
531
+ * Default: 1000
532
+ */
533
+ reconnectDelay?: number;
534
+ /**
535
+ * Maximum reconnection delay in milliseconds
536
+ * Default: 30000
537
+ */
538
+ maxReconnectDelay?: number;
539
+ /**
540
+ * Reconnection backoff multiplier
541
+ * Default: 1.5
542
+ */
543
+ reconnectBackoffMultiplier?: number;
437
544
  }
438
545
  /**
439
546
  * Client transport for Chrome MV3 User Scripts using Port-based messaging.
@@ -444,70 +551,71 @@ interface UserScriptClientTransportOptions {
444
551
  * Features automatic reconnection to handle background service worker lifecycle.
445
552
  */
446
553
  declare class UserScriptClientTransport implements Transport {
447
- private _port?;
448
- private _extensionId?;
449
- private _portName;
450
- private _messageHandler?;
451
- private _disconnectHandler?;
452
- private _isReconnecting;
453
- private _reconnectAttempts;
454
- private _reconnectTimer?;
455
- private _currentReconnectDelay;
456
- private _isStarted;
457
- private _isClosed;
458
- private _autoReconnect;
459
- private _maxReconnectAttempts;
460
- private _reconnectDelay;
461
- private _maxReconnectDelay;
462
- private _reconnectBackoffMultiplier;
463
- onclose?: () => void;
464
- onerror?: (error: Error) => void;
465
- onmessage?: (message: JSONRPCMessage) => void;
466
- constructor(options?: UserScriptClientTransportOptions);
467
- /**
468
- * Starts the transport by connecting to the extension port
469
- */
470
- start(): Promise<void>;
471
- /**
472
- * Connects to the extension port
473
- */
474
- private _connect;
475
- /**
476
- * Sends a message to the server
477
- */
478
- send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
479
- /**
480
- * Closes the transport
481
- */
482
- close(): Promise<void>;
483
- /**
484
- * Cleans up event listeners and references
485
- */
486
- private _cleanup;
487
- /**
488
- * Schedules a reconnection attempt
489
- */
490
- private _scheduleReconnect;
491
- /**
492
- * Attempts to reconnect to the extension
493
- */
494
- private _attemptReconnect;
554
+ private _port;
555
+ private _extensionId;
556
+ private _portName;
557
+ private _messageHandler;
558
+ private _disconnectHandler;
559
+ private _isReconnecting;
560
+ private _reconnectAttempts;
561
+ private _reconnectTimer;
562
+ private _currentReconnectDelay;
563
+ private _isStarted;
564
+ private _isClosed;
565
+ private _autoReconnect;
566
+ private _maxReconnectAttempts;
567
+ private _reconnectDelay;
568
+ private _maxReconnectDelay;
569
+ private _reconnectBackoffMultiplier;
570
+ onclose?: () => void;
571
+ onerror?: (error: Error) => void;
572
+ onmessage?: (message: JSONRPCMessage) => void;
573
+ constructor(options?: UserScriptClientTransportOptions);
574
+ /**
575
+ * Starts the transport by connecting to the extension port
576
+ */
577
+ start(): Promise<void>;
578
+ /**
579
+ * Connects to the extension port
580
+ */
581
+ private _connect;
582
+ /**
583
+ * Sends a message to the server
584
+ */
585
+ send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
586
+ /**
587
+ * Closes the transport
588
+ */
589
+ close(): Promise<void>;
590
+ /**
591
+ * Cleans up event listeners and references
592
+ */
593
+ private _cleanup;
594
+ /**
595
+ * Schedules a reconnection attempt
596
+ */
597
+ private _scheduleReconnect;
598
+ /**
599
+ * Attempts to reconnect to the extension
600
+ */
601
+ private _attemptReconnect;
495
602
  }
496
-
603
+ //#endregion
604
+ //#region src/UserScriptServerTransport.d.ts
497
605
  /**
498
606
  * Configuration options for UserScriptServerTransport
499
607
  */
500
608
  type UserScriptServerTransportOptions = {
501
- /**
502
- * Enable keep-alive mechanism to prevent service worker shutdown
503
- * Default: true
504
- */
505
- keepAlive?: boolean;
506
- /**
507
- * Keep-alive interval in milliseconds
508
- * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)
509
- */
510
- keepAliveInterval?: number;
609
+ /**
610
+ * Enable keep-alive mechanism to prevent service worker shutdown
611
+ * Default: true
612
+ */
613
+ keepAlive?: boolean;
614
+ /**
615
+ * Keep-alive interval in milliseconds
616
+ * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)
617
+ */
618
+ keepAliveInterval?: number;
511
619
  };
512
620
  /**
513
621
  * Server transport for Chrome MV3 User Scripts using Port-based messaging.
@@ -521,51 +629,52 @@ type UserScriptServerTransportOptions = {
521
629
  * - Graceful connection state management
522
630
  */
523
631
  declare class UserScriptServerTransport implements Transport {
524
- private _port;
525
- private _started;
526
- private _messageHandler?;
527
- private _disconnectHandler?;
528
- private _keepAliveTimer?;
529
- private _options;
530
- private _connectionInfo;
531
- onclose?: () => void;
532
- onerror?: (error: Error) => void;
533
- onmessage?: (message: JSONRPCMessage) => void;
534
- constructor(port: chrome.runtime.Port, options?: UserScriptServerTransportOptions);
535
- /**
536
- * Starts the transport and begins handling messages
537
- */
538
- start(): Promise<void>;
539
- /**
540
- * Sends a message to the client
541
- */
542
- send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
543
- /**
544
- * Closes the transport
545
- */
546
- close(): Promise<void>;
547
- /**
548
- * Cleans up event listeners and references
549
- */
550
- private _cleanup;
551
- /**
552
- * Starts the keep-alive mechanism
553
- */
554
- private _startKeepAlive;
555
- /**
556
- * Stops the keep-alive mechanism
557
- */
558
- private _stopKeepAlive;
559
- /**
560
- * Gets connection information
561
- */
562
- getConnectionInfo(): {
563
- uptime: number;
564
- isConnected: boolean;
565
- connectedAt: number;
566
- lastMessageAt: number;
567
- messageCount: number;
568
- };
632
+ private _port;
633
+ private _started;
634
+ private _messageHandler;
635
+ private _disconnectHandler;
636
+ private _keepAliveTimer;
637
+ private _options;
638
+ private _connectionInfo;
639
+ onclose?: () => void;
640
+ onerror?: (error: Error) => void;
641
+ onmessage?: (message: JSONRPCMessage) => void;
642
+ constructor(port: chrome.runtime.Port, options?: UserScriptServerTransportOptions);
643
+ /**
644
+ * Starts the transport and begins handling messages
645
+ */
646
+ start(): Promise<void>;
647
+ /**
648
+ * Sends a message to the client
649
+ */
650
+ send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
651
+ /**
652
+ * Closes the transport
653
+ */
654
+ close(): Promise<void>;
655
+ /**
656
+ * Cleans up event listeners and references
657
+ */
658
+ private _cleanup;
659
+ /**
660
+ * Starts the keep-alive mechanism
661
+ */
662
+ private _startKeepAlive;
663
+ /**
664
+ * Stops the keep-alive mechanism
665
+ */
666
+ private _stopKeepAlive;
667
+ /**
668
+ * Gets connection information
669
+ */
670
+ getConnectionInfo(): {
671
+ uptime: number;
672
+ isConnected: boolean;
673
+ connectedAt: number;
674
+ lastMessageAt: number;
675
+ messageCount: number;
676
+ };
569
677
  }
570
-
571
- export { BACKGROUND_MESSAGE_TYPES, ERROR_MESSAGES, type EventId, ExtensionClientTransport, type ExtensionClientTransportOptions, ExtensionServerTransport, type ExtensionServerTransportOptions, HOST_NAME, type MCPBrowserInterface, type MCPConnectOptions, type MCPEventMessage, type MCPEventStore, type MCPReplayEventMessage, type MCPServerInfo, type MCPServerInfoMessage, type MCPWindow, NATIVE_HOST, NativeMessageType, STORAGE_KEYS, SUCCESS_MESSAGES, type ServerStatus, type StoredEvent, type StreamId, TabClientTransport, type TabClientTransportOptions, TabServerTransport, type TabServerTransportOptions, UserScriptClientTransport, type UserScriptClientTransportOptions, UserScriptServerTransport, type UserScriptServerTransportOptions };
678
+ //#endregion
679
+ export { BACKGROUND_MESSAGE_TYPES, ERROR_MESSAGES, EventId, ExtensionClientTransport, ExtensionClientTransportOptions, ExtensionServerTransport, ExtensionServerTransportOptions, HOST_NAME, IframeChildTransport, IframeChildTransportOptions, IframeParentTransport, IframeParentTransportOptions, MCPBrowserInterface, MCPConnectOptions, MCPEventMessage, MCPEventStore, MCPReplayEventMessage, MCPServerInfo, MCPServerInfoMessage, MCPWindow, NATIVE_HOST, NativeMessageType, STORAGE_KEYS, SUCCESS_MESSAGES, ServerStatus, StoredEvent, StreamId, TabClientTransport, TabClientTransportOptions, TabServerTransport, TabServerTransportOptions, UserScriptClientTransport, UserScriptClientTransportOptions, UserScriptServerTransport, UserScriptServerTransportOptions };
680
+ //# sourceMappingURL=index.d.ts.map