@mcp-web/react 0.1.2 → 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/mcp-web-context.d.ts +2 -0
- package/dist/mcp-web-context.d.ts.map +1 -1
- package/dist/mcp-web-context.js.map +1 -1
- package/dist/use-connected-mcp-web.d.ts +3 -0
- package/dist/use-connected-mcp-web.d.ts.map +1 -1
- package/dist/use-connected-mcp-web.js +19 -10
- package/dist/use-connected-mcp-web.js.map +1 -1
- package/package.json +4 -4
- package/src/mcp-web-context.ts +2 -0
- package/src/use-connected-mcp-web.ts +20 -9
|
@@ -5,6 +5,8 @@ import type { MCPWeb } from "@mcp-web/core";
|
|
|
5
5
|
export interface MCPWebContextValue {
|
|
6
6
|
/** The MCPWeb instance for registering tools and making queries. */
|
|
7
7
|
mcpWeb: MCPWeb;
|
|
8
|
+
/** Whether the MCPWeb instance is currently attempting to connect. */
|
|
9
|
+
isConnecting: boolean;
|
|
8
10
|
/** Whether the MCPWeb instance is connected to the bridge server. */
|
|
9
11
|
isConnected: boolean;
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-web-context.d.ts","sourceRoot":"","sources":["../src/mcp-web-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,oDAAiD,CAAC"}
|
|
1
|
+
{"version":3,"file":"mcp-web-context.d.ts","sourceRoot":"","sources":["../src/mcp-web-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,YAAY,EAAE,OAAO,CAAC;IACtB,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,oDAAiD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-web-context.js","sourceRoot":"","sources":["../src/mcp-web-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-web-context.js","sourceRoot":"","sources":["../src/mcp-web-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AActC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC"}
|
|
@@ -5,6 +5,9 @@ import type { MCPWebContextValue } from "./mcp-web-context";
|
|
|
5
5
|
* Connects on mount and disconnects on unmount.
|
|
6
6
|
* Returns reactive connection state for triggering re-renders.
|
|
7
7
|
*
|
|
8
|
+
* Subscribes to MCPWeb's connection state changes so that reconnection
|
|
9
|
+
* attempts (e.g. after a WebSocket drop) are reflected in React state.
|
|
10
|
+
*
|
|
8
11
|
* Handles React StrictMode's double-mount behavior by using a ref to track
|
|
9
12
|
* whether we should actually disconnect on cleanup.
|
|
10
13
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-connected-mcp-web.d.ts","sourceRoot":"","sources":["../src/use-connected-mcp-web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D
|
|
1
|
+
{"version":3,"file":"use-connected-mcp-web.d.ts","sourceRoot":"","sources":["../src/use-connected-mcp-web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,CA0C1E"}
|
|
@@ -4,29 +4,38 @@ import { useEffect, useRef, useState } from "react";
|
|
|
4
4
|
* Connects on mount and disconnects on unmount.
|
|
5
5
|
* Returns reactive connection state for triggering re-renders.
|
|
6
6
|
*
|
|
7
|
+
* Subscribes to MCPWeb's connection state changes so that reconnection
|
|
8
|
+
* attempts (e.g. after a WebSocket drop) are reflected in React state.
|
|
9
|
+
*
|
|
7
10
|
* Handles React StrictMode's double-mount behavior by using a ref to track
|
|
8
11
|
* whether we should actually disconnect on cleanup.
|
|
9
12
|
*
|
|
10
13
|
* @internal
|
|
11
14
|
*/
|
|
12
15
|
export function useConnectedMCPWeb(mcpInstance) {
|
|
16
|
+
const [isConnecting, setIsConnecting] = useState(mcpInstance.connecting);
|
|
13
17
|
const [isConnected, setIsConnected] = useState(mcpInstance.connected);
|
|
14
18
|
// Track if the effect has been cleaned up to handle StrictMode double-mount
|
|
15
19
|
const cleanedUpRef = useRef(false);
|
|
20
|
+
// Subscribe to connection state changes from the MCPWeb instance.
|
|
21
|
+
// This is the single source of truth — all state updates flow through here
|
|
22
|
+
// (and the initial connect effect below for the first mount).
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const unsubscribe = mcpInstance.onConnectionStateChange(() => {
|
|
25
|
+
setIsConnecting(mcpInstance.connecting);
|
|
26
|
+
setIsConnected(mcpInstance.connected);
|
|
27
|
+
});
|
|
28
|
+
return unsubscribe;
|
|
29
|
+
}, [mcpInstance]);
|
|
16
30
|
useEffect(() => {
|
|
17
31
|
// Reset the cleanup flag on mount
|
|
18
32
|
cleanedUpRef.current = false;
|
|
19
|
-
if (!mcpInstance.connected) {
|
|
20
|
-
mcpInstance.connect().
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
setIsConnected(true);
|
|
24
|
-
}
|
|
33
|
+
if (!mcpInstance.connected && !mcpInstance.connecting) {
|
|
34
|
+
mcpInstance.connect().catch(() => {
|
|
35
|
+
// Connection failed — state listener already handles updates.
|
|
36
|
+
// Nothing to do here.
|
|
25
37
|
});
|
|
26
38
|
}
|
|
27
|
-
else {
|
|
28
|
-
setIsConnected(true);
|
|
29
|
-
}
|
|
30
39
|
return () => {
|
|
31
40
|
cleanedUpRef.current = true;
|
|
32
41
|
// Use setTimeout to defer disconnect, allowing StrictMode's remount to cancel it
|
|
@@ -39,6 +48,6 @@ export function useConnectedMCPWeb(mcpInstance) {
|
|
|
39
48
|
}, 0);
|
|
40
49
|
};
|
|
41
50
|
}, [mcpInstance]);
|
|
42
|
-
return { mcpWeb: mcpInstance, isConnected };
|
|
51
|
+
return { mcpWeb: mcpInstance, isConnecting, isConnected };
|
|
43
52
|
}
|
|
44
53
|
//# sourceMappingURL=use-connected-mcp-web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-connected-mcp-web.js","sourceRoot":"","sources":["../src/use-connected-mcp-web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGpD
|
|
1
|
+
{"version":3,"file":"use-connected-mcp-web.js","sourceRoot":"","sources":["../src/use-connected-mcp-web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGpD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACzE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACtE,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": "0.1.3",
|
|
4
4
|
"description": "MCP Web integration for React state management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"zod": "~4.1.12",
|
|
16
|
-
"@mcp-web/
|
|
17
|
-
"@mcp-web/
|
|
18
|
-
"@mcp-web/
|
|
16
|
+
"@mcp-web/types": "0.1.3",
|
|
17
|
+
"@mcp-web/core": "0.1.3",
|
|
18
|
+
"@mcp-web/decompose-zod-schema": "0.1.3"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/react": "^18.3.0",
|
package/src/mcp-web-context.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { createContext } from "react";
|
|
|
7
7
|
export interface MCPWebContextValue {
|
|
8
8
|
/** The MCPWeb instance for registering tools and making queries. */
|
|
9
9
|
mcpWeb: MCPWeb;
|
|
10
|
+
/** Whether the MCPWeb instance is currently attempting to connect. */
|
|
11
|
+
isConnecting: boolean;
|
|
10
12
|
/** Whether the MCPWeb instance is connected to the bridge server. */
|
|
11
13
|
isConnected: boolean;
|
|
12
14
|
}
|
|
@@ -7,29 +7,40 @@ import type { MCPWebContextValue } from "./mcp-web-context";
|
|
|
7
7
|
* Connects on mount and disconnects on unmount.
|
|
8
8
|
* Returns reactive connection state for triggering re-renders.
|
|
9
9
|
*
|
|
10
|
+
* Subscribes to MCPWeb's connection state changes so that reconnection
|
|
11
|
+
* attempts (e.g. after a WebSocket drop) are reflected in React state.
|
|
12
|
+
*
|
|
10
13
|
* Handles React StrictMode's double-mount behavior by using a ref to track
|
|
11
14
|
* whether we should actually disconnect on cleanup.
|
|
12
15
|
*
|
|
13
16
|
* @internal
|
|
14
17
|
*/
|
|
15
18
|
export function useConnectedMCPWeb(mcpInstance: MCPWeb): MCPWebContextValue {
|
|
19
|
+
const [isConnecting, setIsConnecting] = useState(mcpInstance.connecting);
|
|
16
20
|
const [isConnected, setIsConnected] = useState(mcpInstance.connected);
|
|
17
21
|
// Track if the effect has been cleaned up to handle StrictMode double-mount
|
|
18
22
|
const cleanedUpRef = useRef(false);
|
|
19
23
|
|
|
24
|
+
// Subscribe to connection state changes from the MCPWeb instance.
|
|
25
|
+
// This is the single source of truth — all state updates flow through here
|
|
26
|
+
// (and the initial connect effect below for the first mount).
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const unsubscribe = mcpInstance.onConnectionStateChange(() => {
|
|
29
|
+
setIsConnecting(mcpInstance.connecting);
|
|
30
|
+
setIsConnected(mcpInstance.connected);
|
|
31
|
+
});
|
|
32
|
+
return unsubscribe;
|
|
33
|
+
}, [mcpInstance]);
|
|
34
|
+
|
|
20
35
|
useEffect(() => {
|
|
21
36
|
// Reset the cleanup flag on mount
|
|
22
37
|
cleanedUpRef.current = false;
|
|
23
38
|
|
|
24
|
-
if (!mcpInstance.connected) {
|
|
25
|
-
mcpInstance.connect().
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
setIsConnected(true);
|
|
29
|
-
}
|
|
39
|
+
if (!mcpInstance.connected && !mcpInstance.connecting) {
|
|
40
|
+
mcpInstance.connect().catch(() => {
|
|
41
|
+
// Connection failed — state listener already handles updates.
|
|
42
|
+
// Nothing to do here.
|
|
30
43
|
});
|
|
31
|
-
} else {
|
|
32
|
-
setIsConnected(true);
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
return () => {
|
|
@@ -45,5 +56,5 @@ export function useConnectedMCPWeb(mcpInstance: MCPWeb): MCPWebContextValue {
|
|
|
45
56
|
};
|
|
46
57
|
}, [mcpInstance]);
|
|
47
58
|
|
|
48
|
-
return { mcpWeb: mcpInstance, isConnected };
|
|
59
|
+
return { mcpWeb: mcpInstance, isConnecting, isConnected };
|
|
49
60
|
}
|