@mcp-web/core 0.1.1 → 0.1.3
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/web.d.ts +29 -3
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +77 -14
- package/package.json +4 -4
package/dist/web.d.ts
CHANGED
|
@@ -62,8 +62,6 @@ export declare class MCPWeb {
|
|
|
62
62
|
* const mcp = new MCPWeb({
|
|
63
63
|
* name: 'My Todo App',
|
|
64
64
|
* description: 'A todo application that AI agents can control',
|
|
65
|
-
* bridgeUrl: 'localhost:3001',
|
|
66
|
-
* autoConnect: true,
|
|
67
65
|
* });
|
|
68
66
|
* ```
|
|
69
67
|
*/
|
|
@@ -120,7 +118,7 @@ export declare class MCPWeb {
|
|
|
120
118
|
get config(): {
|
|
121
119
|
name: string;
|
|
122
120
|
description: string;
|
|
123
|
-
bridgeUrl: string;
|
|
121
|
+
bridgeUrl: string | undefined;
|
|
124
122
|
agentUrl: string | undefined;
|
|
125
123
|
persistAuthToken: boolean;
|
|
126
124
|
autoConnect: boolean;
|
|
@@ -595,6 +593,34 @@ export declare class MCPWeb {
|
|
|
595
593
|
* ```
|
|
596
594
|
*/
|
|
597
595
|
get connected(): boolean;
|
|
596
|
+
/**
|
|
597
|
+
* Whether the instance is currently attempting to connect to the bridge.
|
|
598
|
+
*
|
|
599
|
+
* Returns `true` during the connection/authentication handshake,
|
|
600
|
+
* before `connected` becomes `true` or the connection fails.
|
|
601
|
+
*
|
|
602
|
+
* @returns `true` if a connection attempt is in progress
|
|
603
|
+
*/
|
|
604
|
+
get connecting(): boolean;
|
|
605
|
+
/**
|
|
606
|
+
* Subscribe to connection state changes.
|
|
607
|
+
*
|
|
608
|
+
* The listener is called whenever `connected` or `connecting` changes.
|
|
609
|
+
* Returns an unsubscribe function.
|
|
610
|
+
*
|
|
611
|
+
* @param listener - Callback invoked on state change
|
|
612
|
+
* @returns Unsubscribe function
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* const unsubscribe = mcp.onConnectionStateChange(() => {
|
|
617
|
+
* console.log('connected:', mcp.connected, 'connecting:', mcp.connecting);
|
|
618
|
+
* });
|
|
619
|
+
* // Later:
|
|
620
|
+
* unsubscribe();
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
onConnectionStateChange(listener: () => void): () => void;
|
|
598
624
|
/**
|
|
599
625
|
* Disconnects from the bridge server.
|
|
600
626
|
*
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAEjF,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,YAAY,EAEZ,sBAAsB,EAEtB,uBAAuB,EAEvB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAYxB,OAAO,EAAa,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAAa,MAAM;;
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAEjF,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,YAAY,EAEZ,sBAAsB,EAEtB,uBAAuB,EAEvB,kBAAkB,EAClB,cA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Token;
|
|
55
|
+
#bridgeUrl;
|
|
55
56
|
#tools = new Map();
|
|
56
57
|
#resources = new Map();
|
|
57
58
|
#apps = new Map();
|
|
58
59
|
#connected = false;
|
|
59
60
|
#isConnecting = false;
|
|
60
61
|
#authError = null;
|
|
62
|
+
#connectionStateListeners = new Set();
|
|
63
|
+
/** Update connected state and notify listeners on change */
|
|
64
|
+
#setConnected(value) {
|
|
65
|
+
if (this.#connected !== value) {
|
|
66
|
+
this.#connected = value;
|
|
67
|
+
this.#notifyConnectionStateChange();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Update connecting state and notify listeners on change */
|
|
71
|
+
#setIsConnecting(value) {
|
|
72
|
+
if (this.#isConnecting !== value) {
|
|
73
|
+
this.#isConnecting = value;
|
|
74
|
+
this.#notifyConnectionStateChange();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
61
77
|
#config;
|
|
62
78
|
#toolRegistrationErrorCallbacks = new Map();
|
|
63
79
|
#mcpConfig;
|
|
@@ -75,13 +91,14 @@ export class MCPWeb {
|
|
|
75
91
|
* const mcp = new MCPWeb({
|
|
76
92
|
* name: 'My Todo App',
|
|
77
93
|
* description: 'A todo application that AI agents can control',
|
|
78
|
-
* bridgeUrl: 'localhost:3001',
|
|
79
|
-
* autoConnect: true,
|
|
80
94
|
* });
|
|
81
95
|
* ```
|
|
82
96
|
*/
|
|
83
97
|
constructor(config) {
|
|
84
98
|
this.#config = McpWebConfigSchema.parse(config);
|
|
99
|
+
this.#bridgeUrl = this.#config.bridgeUrl
|
|
100
|
+
?? globalThis.window?.location?.host
|
|
101
|
+
?? 'localhost:3001';
|
|
85
102
|
this.#sessionId = this.#generateSessionId();
|
|
86
103
|
this.#authToken = this.#resolveAuthToken(this.#config);
|
|
87
104
|
this.#mcpConfig = {
|
|
@@ -89,7 +106,7 @@ export class MCPWeb {
|
|
|
89
106
|
command: 'npx',
|
|
90
107
|
args: ['@mcp-web/client'],
|
|
91
108
|
env: {
|
|
92
|
-
MCP_SERVER_URL: `${this.#getHttpProtocol()}//${this.#
|
|
109
|
+
MCP_SERVER_URL: `${this.#getHttpProtocol()}//${this.#bridgeUrl}`,
|
|
93
110
|
AUTH_TOKEN: this.#authToken
|
|
94
111
|
}
|
|
95
112
|
}
|
|
@@ -206,12 +223,12 @@ export class MCPWeb {
|
|
|
206
223
|
get remoteMcpConfig() {
|
|
207
224
|
return {
|
|
208
225
|
[this.#config.name]: {
|
|
209
|
-
url: `${this.#getHttpProtocol()}//${this.#
|
|
226
|
+
url: `${this.#getHttpProtocol()}//${this.#bridgeUrl}?token=${this.#authToken}`,
|
|
210
227
|
},
|
|
211
228
|
};
|
|
212
229
|
}
|
|
213
230
|
#getBridgeWsUrl() {
|
|
214
|
-
return `${this.#getWsProtocol()}//${this.#
|
|
231
|
+
return `${this.#getWsProtocol()}//${this.#bridgeUrl}`;
|
|
215
232
|
}
|
|
216
233
|
#getWsProtocol() {
|
|
217
234
|
return globalThis.window?.location?.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
@@ -322,7 +339,7 @@ export class MCPWeb {
|
|
|
322
339
|
checkConnection();
|
|
323
340
|
});
|
|
324
341
|
}
|
|
325
|
-
this.#
|
|
342
|
+
this.#setIsConnecting(true);
|
|
326
343
|
this.#authError = null;
|
|
327
344
|
return new Promise((resolve, reject) => {
|
|
328
345
|
try {
|
|
@@ -342,8 +359,8 @@ export class MCPWeb {
|
|
|
342
359
|
}
|
|
343
360
|
};
|
|
344
361
|
this.#ws.onclose = () => {
|
|
345
|
-
this.#
|
|
346
|
-
this.#
|
|
362
|
+
this.#setConnected(false);
|
|
363
|
+
this.#setIsConnecting(false);
|
|
347
364
|
// Don't reconnect if authentication was rejected
|
|
348
365
|
if (!this.#authError) {
|
|
349
366
|
this.scheduleReconnect();
|
|
@@ -351,17 +368,17 @@ export class MCPWeb {
|
|
|
351
368
|
};
|
|
352
369
|
this.#ws.onerror = (error) => {
|
|
353
370
|
console.error('WebSocket error:', error);
|
|
354
|
-
this.#
|
|
371
|
+
this.#setIsConnecting(false);
|
|
355
372
|
reject(error);
|
|
356
373
|
};
|
|
357
374
|
// Resolve when authenticated, reject on auth failure
|
|
358
375
|
const checkConnection = () => {
|
|
359
376
|
if (this.#connected) {
|
|
360
|
-
this.#
|
|
377
|
+
this.#setIsConnecting(false);
|
|
361
378
|
resolve(true);
|
|
362
379
|
}
|
|
363
380
|
else if (this.#authError) {
|
|
364
|
-
this.#
|
|
381
|
+
this.#setIsConnecting(false);
|
|
365
382
|
reject(new Error(this.#authError.error));
|
|
366
383
|
}
|
|
367
384
|
else {
|
|
@@ -371,7 +388,7 @@ export class MCPWeb {
|
|
|
371
388
|
setTimeout(checkConnection, 100);
|
|
372
389
|
}
|
|
373
390
|
catch (error) {
|
|
374
|
-
this.#
|
|
391
|
+
this.#setIsConnecting(false);
|
|
375
392
|
reject(error);
|
|
376
393
|
}
|
|
377
394
|
});
|
|
@@ -394,7 +411,7 @@ export class MCPWeb {
|
|
|
394
411
|
handleMessage(message) {
|
|
395
412
|
switch (message.type) {
|
|
396
413
|
case 'authenticated':
|
|
397
|
-
this.#
|
|
414
|
+
this.#setConnected(true);
|
|
398
415
|
this.registerAllTools();
|
|
399
416
|
this.registerAllResources();
|
|
400
417
|
break;
|
|
@@ -580,10 +597,16 @@ export class MCPWeb {
|
|
|
580
597
|
scheduleReconnect() {
|
|
581
598
|
if (!this.#ws)
|
|
582
599
|
return;
|
|
600
|
+
// Signal that we intend to reconnect so consumers (e.g. React hooks)
|
|
601
|
+
// can show a "connecting" state instead of "disconnected".
|
|
602
|
+
this.#setIsConnecting(true);
|
|
583
603
|
setTimeout(() => {
|
|
584
604
|
if (!this.#connected && this.#ws) {
|
|
585
605
|
this.connect().catch(console.error);
|
|
586
606
|
}
|
|
607
|
+
else {
|
|
608
|
+
this.#setIsConnecting(false);
|
|
609
|
+
}
|
|
587
610
|
}, 5000);
|
|
588
611
|
}
|
|
589
612
|
setupActivityTracking() {
|
|
@@ -1039,6 +1062,46 @@ export class MCPWeb {
|
|
|
1039
1062
|
get connected() {
|
|
1040
1063
|
return this.#connected;
|
|
1041
1064
|
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Whether the instance is currently attempting to connect to the bridge.
|
|
1067
|
+
*
|
|
1068
|
+
* Returns `true` during the connection/authentication handshake,
|
|
1069
|
+
* before `connected` becomes `true` or the connection fails.
|
|
1070
|
+
*
|
|
1071
|
+
* @returns `true` if a connection attempt is in progress
|
|
1072
|
+
*/
|
|
1073
|
+
get connecting() {
|
|
1074
|
+
return this.#isConnecting;
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Subscribe to connection state changes.
|
|
1078
|
+
*
|
|
1079
|
+
* The listener is called whenever `connected` or `connecting` changes.
|
|
1080
|
+
* Returns an unsubscribe function.
|
|
1081
|
+
*
|
|
1082
|
+
* @param listener - Callback invoked on state change
|
|
1083
|
+
* @returns Unsubscribe function
|
|
1084
|
+
*
|
|
1085
|
+
* @example
|
|
1086
|
+
* ```typescript
|
|
1087
|
+
* const unsubscribe = mcp.onConnectionStateChange(() => {
|
|
1088
|
+
* console.log('connected:', mcp.connected, 'connecting:', mcp.connecting);
|
|
1089
|
+
* });
|
|
1090
|
+
* // Later:
|
|
1091
|
+
* unsubscribe();
|
|
1092
|
+
* ```
|
|
1093
|
+
*/
|
|
1094
|
+
onConnectionStateChange(listener) {
|
|
1095
|
+
this.#connectionStateListeners.add(listener);
|
|
1096
|
+
return () => {
|
|
1097
|
+
this.#connectionStateListeners.delete(listener);
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
#notifyConnectionStateChange() {
|
|
1101
|
+
for (const listener of this.#connectionStateListeners) {
|
|
1102
|
+
listener();
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1042
1105
|
/**
|
|
1043
1106
|
* Disconnects from the bridge server.
|
|
1044
1107
|
*
|
|
@@ -1062,7 +1125,7 @@ export class MCPWeb {
|
|
|
1062
1125
|
this.#ws.close();
|
|
1063
1126
|
this.#ws = null;
|
|
1064
1127
|
}
|
|
1065
|
-
this.#
|
|
1128
|
+
this.#setConnected(false);
|
|
1066
1129
|
}
|
|
1067
1130
|
/**
|
|
1068
1131
|
* Gets list of all registered tool names.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-web/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"ajv": "^8.17.1",
|
|
39
39
|
"zod": "~4.1.12",
|
|
40
|
-
"@mcp-web/
|
|
41
|
-
"@mcp-web/
|
|
42
|
-
"@mcp-web/
|
|
40
|
+
"@mcp-web/types": "0.1.3",
|
|
41
|
+
"@mcp-web/bridge": "0.1.3",
|
|
42
|
+
"@mcp-web/decompose-zod-schema": "0.1.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/json-schema": "^7.0.15",
|