@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/README.md +129 -0
- package/dist/index.d.ts +539 -430
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { JSONRPCMessage } from
|
|
2
|
-
import { Transport, TransportSendOptions } from
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
99
|
+
mcp?: MCPBrowserInterface;
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
102
|
* Message types for internal MCP communication
|
|
102
103
|
*/
|
|
103
104
|
interface MCPServerInfoMessage {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
type: 'mcp-server-info';
|
|
106
|
+
serverInstanceId: string;
|
|
107
|
+
serverSessionId?: string;
|
|
108
|
+
hasEventStore: boolean;
|
|
109
|
+
streamId: StreamId;
|
|
109
110
|
}
|
|
110
111
|
interface MCPEventMessage {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
type: 'mcp-event';
|
|
113
|
+
eventId: EventId;
|
|
114
|
+
message: JSONRPCMessage;
|
|
114
115
|
}
|
|
115
116
|
interface MCPReplayEventMessage {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
eventId: EventId;
|
|
126
|
+
streamId: StreamId;
|
|
127
|
+
message: JSONRPCMessage;
|
|
128
|
+
timestamp: number;
|
|
129
|
+
clientId: string;
|
|
129
130
|
}
|
|
130
131
|
declare enum NativeMessageType {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
156
|
-
|
|
156
|
+
readonly NAME: "com.chromemcp.nativehost";
|
|
157
|
+
readonly DEFAULT_PORT: 12306;
|
|
157
158
|
};
|
|
158
159
|
declare const ERROR_MESSAGES: {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
173
|
+
readonly SERVER_STATUS: "serverStatus";
|
|
173
174
|
};
|
|
174
175
|
declare const BACKGROUND_MESSAGE_TYPES: {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
360
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
382
|
-
|
|
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
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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,
|
|
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
|