@mcp-fe/react-tools 0.2.0 → 0.2.2
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/LICENSE +27 -29
- package/context/MCPToolsContext.d.ts.map +1 -1
- package/index.js +1 -1
- package/index.mjs +132 -136
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
10
|
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
11
|
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
13
14
|
|
|
14
15
|
"Legal Entity" shall mean the union of the acting entity and all
|
|
15
16
|
other entities that control, are controlled by, or are under common
|
|
@@ -22,11 +23,11 @@
|
|
|
22
23
|
"You" (or "Your") shall mean an individual or Legal Entity
|
|
23
24
|
exercising permissions granted by this License.
|
|
24
25
|
|
|
25
|
-
"Source" shall mean the preferred form for making modifications,
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
26
27
|
including but not limited to software source code, documentation
|
|
27
28
|
source, and configuration files.
|
|
28
29
|
|
|
29
|
-
"Object" shall mean any form resulting from mechanical
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
30
31
|
transformation or translation of a Source form, including but
|
|
31
32
|
not limited to compiled object code, generated documentation,
|
|
32
33
|
and conversions to other media types.
|
|
@@ -34,16 +35,15 @@
|
|
|
34
35
|
"Work" shall mean the work of authorship, whether in Source or
|
|
35
36
|
Object form, made available under the License, as indicated by a
|
|
36
37
|
copyright notice that is included in or attached to the work
|
|
37
|
-
(
|
|
38
|
-
and bear an appropriate legal notice).
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
39
|
|
|
40
40
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
42
|
editorial revisions, annotations, elaborations, or other modifications
|
|
43
43
|
represent, as a whole, an original work of authorship. For the purposes
|
|
44
44
|
of this License, Derivative Works shall not include works that remain
|
|
45
45
|
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
47
|
|
|
48
48
|
"Contribution" shall mean any work of authorship, including
|
|
49
49
|
the original version of the Work and any modifications or additions
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
54
|
means any form of electronic, verbal, or written communication sent
|
|
55
55
|
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
60
|
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
61
|
|
|
62
62
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
@@ -66,13 +66,9 @@
|
|
|
66
66
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
67
|
this License, each Contributor hereby grants to You a perpetual,
|
|
68
68
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
the following conditions:
|
|
73
|
-
|
|
74
|
-
The above copyright notice and this permission notice shall be
|
|
75
|
-
included in all copies or substantial portions of the Work.
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
76
72
|
|
|
77
73
|
3. Grant of Patent License. Subject to the terms and conditions of
|
|
78
74
|
this License, each Contributor hereby grants to You a perpetual,
|
|
@@ -124,7 +120,7 @@
|
|
|
124
120
|
that such additional attribution notices cannot be construed
|
|
125
121
|
as modifying the License.
|
|
126
122
|
|
|
127
|
-
You may add Your own copyright
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
128
124
|
may provide additional or different license terms and conditions
|
|
129
125
|
for use, reproduction, or distribution of Your modifications, or
|
|
130
126
|
for any such Derivative Works as a whole, provided Your use,
|
|
@@ -166,14 +162,16 @@
|
|
|
166
162
|
other commercial damages or losses), even if such Contributor
|
|
167
163
|
has been advised of the possibility of such damages.
|
|
168
164
|
|
|
169
|
-
9. Accepting Warranty or
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
177
175
|
|
|
178
176
|
END OF TERMS AND CONDITIONS
|
|
179
177
|
|
|
@@ -185,8 +183,8 @@
|
|
|
185
183
|
the brackets!) The text should be enclosed in the appropriate
|
|
186
184
|
comment syntax for the file format. We also recommend that a
|
|
187
185
|
file or class name and description of purpose be included on the
|
|
188
|
-
same page as the copyright notice for easier
|
|
189
|
-
third-party archives.
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
190
188
|
|
|
191
189
|
Copyright 2026 Michal Kopecky
|
|
192
190
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MCPToolsContext.d.ts","sourceRoot":"","sources":["../../../../libs/react-tools/src/context/MCPToolsContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"MCPToolsContext.d.ts","sourceRoot":"","sources":["../../../../libs/react-tools/src/context/MCPToolsContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,EAAgB,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,UAAU,oBAAoB;IAC5B;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;OAEG;IACH,mBAAmB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C;AAID,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B;;OAEG;IACH,WAAW,CAAC,EAAE,uBAAuB,CAAC;IAEtC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAE3B;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,QAAe,EACf,YAAoC,EACpC,SAAS,EACT,WAAW,EACX,aAAa,EACb,WAAW,GACZ,EAAE,qBAAqB,2CAsGvB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,UAAQ,GAAG,oBAAoB,CAsBvE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAG3C"}
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),s=require("@mcp-fe/mcp-worker"),_=require("react/jsx-runtime");function I(r){const{name:t,description:i,inputSchema:c,outputSchema:n,handler:f,annotations:C,execution:u,_meta:R,icons:P,title:d,autoRegister:v=!0,autoUnregister:k=!0}=r,[T,p]=e.useState(null),M=e.useRef(f),g=e.useRef(t),S=e.useRef(i),y=e.useRef(c),l=e.useRef(n),a=e.useRef(C),m=e.useRef(u),x=e.useRef(R),z=e.useRef(P),A=e.useRef(d),D=e.useRef(!0),b=e.useRef(!1),w=e.useRef(!1);e.useEffect(()=>{M.current=f,g.current=t,S.current=i,y.current=c,l.current=n,a.current=C,m.current=u,x.current=R,z.current=P,A.current=d},[f,t,i,c,n,C,u,R,P,d]);const $=e.useCallback(async o=>M.current(o),[]),q=e.useCallback(async()=>{const o=g.current;if(b.current||w.current){console.log(`[useMCPTool] Skipping registration for '${o}' (already registered or in progress)`);return}b.current=!0;const h=S.current,N=y.current,O=l.current,H=a.current,W=m.current,F=x.current,G=z.current,J=A.current;try{await s.workerClient.registerTool(o,h,N,$,{outputSchema:O,annotations:H,execution:W,_meta:F,icons:G,title:J}),w.current=!0,console.log(`[useMCPTool] Registered tool '${o}'`)}catch(U){throw console.error(`[useMCPTool] Failed to register tool '${o}':`,U),U}finally{b.current=!1}},[$]),j=e.useCallback(async()=>{const o=g.current;if(!w.current){console.log(`[useMCPTool] Skipping unregistration for '${o}' (not registered)`);return}try{await s.workerClient.unregisterTool(o),w.current=!1,console.log(`[useMCPTool] Unregistered tool '${o}'`)}catch(h){console.error(`[useMCPTool] Failed to unregister tool '${o}':`,h)}},[]);return e.useEffect(()=>s.workerClient.onToolChange(t,h=>{p(h)}),[t]),e.useEffect(()=>(v&&q().catch(o=>{console.error(`[useMCPTool] Auto-register failed for '${t}':`,o)}),()=>{D.current=!1,k&&w.current&&j().catch(o=>{console.error(`[useMCPTool] Auto-unregister failed for '${t}':`,o)})}),[t]),{isRegistered:T?.isRegistered??!1,refCount:T?.refCount??0,register:q,unregister:j}}function B(r){return s.workerClient.isToolRegistered(r)}function K(){return s.workerClient.getRegisteredTools()}function L(r){return s.workerClient.getToolInfo(r)}function Q(r){return s.workerClient.getToolDetails(r)}function V(r,t,i,c){const n=e.useCallback(async()=>{const f=await i();return{content:[{type:"text",text:JSON.stringify(f,null,2)}]}},[i]);return I({name:r,description:t,inputSchema:{type:"object",properties:{}},handler:n,...c})}function X(r,t,i,c,n){const f=e.useCallback(async C=>{const u=await c(C);return{content:[{type:"text",text:JSON.stringify(u,null,2)}]}},[c]);return I({name:r,description:t,inputSchema:{type:"object",properties:i,...n?.required&&{required:n.required}},handler:f,autoRegister:n?.autoRegister,autoUnregister:n?.autoUnregister})}const E=e.createContext(null);function Y({children:r,autoInit:t=!0,backendWsUrl:i="ws://localhost:3001",authToken:c,initOptions:n,onInitialized:f,onInitError:C}){const[u,R]=e.useState(!1),[P,d]=e.useState(!1),[v]=e.useState([]),k=e.useRef(n),T=e.useRef(i),p=e.useRef(f),M=e.useRef(C);k.current=n,T.current=i,p.current=f,M.current=C;const g=e.useCallback(async l=>{if(s.workerClient.initialized){console.log("[MCPToolsProvider] Already initialized");return}try{const a=l||k.current||{backendWsUrl:T.current};console.log("[MCPToolsProvider] Initializing worker client...",a),await s.workerClient.init(a),R(!0);const m=await s.workerClient.getConnectionStatus();d(m),s.workerClient.onConnectionStatus(x=>{d(x)}),console.log("[MCPToolsProvider] Worker client initialized"),p.current?.()}catch(a){throw console.error("[MCPToolsProvider] Initialization failed:",a),M.current?.(a instanceof Error?a:new Error(String(a))),a}},[]),S=e.useCallback(async()=>{const l=await s.workerClient.getConnectionStatus();return d(l),l},[]);e.useEffect(()=>{t&&g().catch(l=>{console.error("[MCPToolsProvider] Auto-init failed:",l)})},[t,g]),e.useEffect(()=>{u&&c&&(console.log("[MCPToolsProvider] Auth token changed, updating..."),s.workerClient.setAuthToken(c))},[c,u]),e.useEffect(()=>{if(!u)return;const l=setInterval(()=>{},5e3);return()=>clearInterval(l)},[u]);const y={isInitialized:u,isConnected:P,registeredTools:v,initialize:g,getConnectionStatus:S};return _.jsx(E.Provider,{value:y,children:r})}function Z(r=!1){const t=e.useContext(E);if(!t&&r)throw new Error("useMCPToolsContext must be used within MCPToolsProvider. Either wrap your component tree with <MCPToolsProvider> or set strict=false.");return t||{isInitialized:!1,isConnected:!1,registeredTools:[],initialize:async()=>{throw new Error("MCPToolsProvider not found")},getConnectionStatus:async()=>!1}}function ee(){return e.useContext(E)!==null}exports.MCPToolsProvider=Y;exports.getRegisteredTools=K;exports.getToolDetails=Q;exports.getToolInfo=L;exports.isToolRegistered=B;exports.useHasMCPProvider=ee;exports.useMCPAction=X;exports.useMCPGetter=V;exports.useMCPTool=I;exports.useMCPToolsContext=Z;
|
package/index.mjs
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { workerClient as
|
|
3
|
-
import { jsx as
|
|
4
|
-
function
|
|
1
|
+
import { useState as z, useRef as t, useEffect as T, useCallback as P, createContext as Q, useContext as O } from "react";
|
|
2
|
+
import { workerClient as s } from "@mcp-fe/mcp-worker";
|
|
3
|
+
import { jsx as V } from "react/jsx-runtime";
|
|
4
|
+
function F(r) {
|
|
5
5
|
const {
|
|
6
6
|
name: e,
|
|
7
|
-
description:
|
|
8
|
-
inputSchema:
|
|
7
|
+
description: i,
|
|
8
|
+
inputSchema: c,
|
|
9
9
|
outputSchema: n,
|
|
10
10
|
handler: f,
|
|
11
|
-
annotations:
|
|
12
|
-
execution:
|
|
13
|
-
_meta:
|
|
14
|
-
icons:
|
|
15
|
-
title:
|
|
16
|
-
autoRegister:
|
|
17
|
-
autoUnregister:
|
|
18
|
-
} =
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
annotations: d,
|
|
12
|
+
execution: u,
|
|
13
|
+
_meta: h,
|
|
14
|
+
icons: R,
|
|
15
|
+
title: g,
|
|
16
|
+
autoRegister: A = !0,
|
|
17
|
+
autoUnregister: w = !0
|
|
18
|
+
} = r, [p, S] = z(null), M = t(f), C = t(e), x = t(i), v = t(c), l = t(n), a = t(d), I = t(u), b = t(h), E = t(R), U = t(g), H = t(!0), $ = t(!1), m = t(!1);
|
|
19
|
+
T(() => {
|
|
20
|
+
M.current = f, C.current = e, x.current = i, v.current = c, l.current = n, a.current = d, I.current = u, b.current = h, E.current = R, U.current = g;
|
|
21
21
|
}, [
|
|
22
22
|
f,
|
|
23
23
|
e,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
i,
|
|
25
|
+
c,
|
|
26
26
|
n,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
T,
|
|
27
|
+
d,
|
|
28
|
+
u,
|
|
30
29
|
h,
|
|
31
|
-
|
|
30
|
+
R,
|
|
31
|
+
g
|
|
32
32
|
]);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
33
|
+
const N = P(async (o) => M.current(o), []), j = P(async () => {
|
|
34
|
+
const o = C.current;
|
|
35
|
+
if ($.current || m.current) {
|
|
36
36
|
console.log(
|
|
37
|
-
`[useMCPTool] Skipping registration for '${
|
|
37
|
+
`[useMCPTool] Skipping registration for '${o}' (already registered or in progress)`
|
|
38
38
|
);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
const
|
|
41
|
+
$.current = !0;
|
|
42
|
+
const y = x.current, J = v.current, W = l.current, _ = a.current, G = I.current, B = b.current, K = E.current, L = U.current;
|
|
43
43
|
try {
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
await s.registerTool(
|
|
45
|
+
o,
|
|
46
|
+
y,
|
|
47
|
+
J,
|
|
48
|
+
N,
|
|
49
49
|
{
|
|
50
|
-
outputSchema:
|
|
51
|
-
annotations:
|
|
52
|
-
execution:
|
|
53
|
-
_meta:
|
|
54
|
-
icons:
|
|
55
|
-
title:
|
|
50
|
+
outputSchema: W,
|
|
51
|
+
annotations: _,
|
|
52
|
+
execution: G,
|
|
53
|
+
_meta: B,
|
|
54
|
+
icons: K,
|
|
55
|
+
title: L
|
|
56
56
|
}
|
|
57
|
-
),
|
|
58
|
-
} catch (
|
|
57
|
+
), m.current = !0, console.log(`[useMCPTool] Registered tool '${o}'`);
|
|
58
|
+
} catch (D) {
|
|
59
59
|
throw console.error(
|
|
60
|
-
`[useMCPTool] Failed to register tool '${
|
|
61
|
-
|
|
62
|
-
),
|
|
60
|
+
`[useMCPTool] Failed to register tool '${o}':`,
|
|
61
|
+
D
|
|
62
|
+
), D;
|
|
63
63
|
} finally {
|
|
64
|
-
|
|
64
|
+
$.current = !1;
|
|
65
65
|
}
|
|
66
|
-
}, [
|
|
67
|
-
const
|
|
68
|
-
if (!
|
|
66
|
+
}, [N]), q = P(async () => {
|
|
67
|
+
const o = C.current;
|
|
68
|
+
if (!m.current) {
|
|
69
69
|
console.log(
|
|
70
|
-
`[useMCPTool] Skipping unregistration for '${
|
|
70
|
+
`[useMCPTool] Skipping unregistration for '${o}' (not registered)`
|
|
71
71
|
);
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
try {
|
|
75
|
-
await
|
|
76
|
-
} catch (
|
|
75
|
+
await s.unregisterTool(o), m.current = !1, console.log(`[useMCPTool] Unregistered tool '${o}'`);
|
|
76
|
+
} catch (y) {
|
|
77
77
|
console.error(
|
|
78
|
-
`[useMCPTool] Failed to unregister tool '${
|
|
79
|
-
|
|
78
|
+
`[useMCPTool] Failed to unregister tool '${o}':`,
|
|
79
|
+
y
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
}, []);
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
}), [e]),
|
|
83
|
+
return T(() => s.onToolChange(e, (y) => {
|
|
84
|
+
S(y);
|
|
85
|
+
}), [e]), T(() => (A && j().catch((o) => {
|
|
86
86
|
console.error(
|
|
87
87
|
`[useMCPTool] Auto-register failed for '${e}':`,
|
|
88
|
-
|
|
88
|
+
o
|
|
89
89
|
);
|
|
90
90
|
}), () => {
|
|
91
|
-
|
|
91
|
+
H.current = !1, w && m.current && q().catch((o) => {
|
|
92
92
|
console.error(
|
|
93
93
|
`[useMCPTool] Auto-unregister failed for '${e}':`,
|
|
94
|
-
|
|
94
|
+
o
|
|
95
95
|
);
|
|
96
96
|
});
|
|
97
97
|
}), [e]), {
|
|
98
|
-
isRegistered:
|
|
99
|
-
refCount:
|
|
100
|
-
register:
|
|
101
|
-
unregister:
|
|
98
|
+
isRegistered: p?.isRegistered ?? !1,
|
|
99
|
+
refCount: p?.refCount ?? 0,
|
|
100
|
+
register: j,
|
|
101
|
+
unregister: q
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
function ee(
|
|
105
|
-
return
|
|
104
|
+
function ee(r) {
|
|
105
|
+
return s.isToolRegistered(r);
|
|
106
106
|
}
|
|
107
107
|
function te() {
|
|
108
|
-
return
|
|
108
|
+
return s.getRegisteredTools();
|
|
109
109
|
}
|
|
110
|
-
function re(
|
|
111
|
-
return
|
|
110
|
+
function re(r) {
|
|
111
|
+
return s.getToolInfo(r);
|
|
112
112
|
}
|
|
113
|
-
function oe(
|
|
114
|
-
return
|
|
113
|
+
function oe(r) {
|
|
114
|
+
return s.getToolDetails(r);
|
|
115
115
|
}
|
|
116
|
-
function ne(
|
|
117
|
-
const n =
|
|
118
|
-
const f = await
|
|
116
|
+
function ne(r, e, i, c) {
|
|
117
|
+
const n = P(async () => {
|
|
118
|
+
const f = await i();
|
|
119
119
|
return {
|
|
120
120
|
content: [
|
|
121
121
|
{
|
|
@@ -124,39 +124,39 @@ function ne(t, e, l, o) {
|
|
|
124
124
|
}
|
|
125
125
|
]
|
|
126
126
|
};
|
|
127
|
-
}, [
|
|
128
|
-
return
|
|
129
|
-
name:
|
|
127
|
+
}, [i]);
|
|
128
|
+
return F({
|
|
129
|
+
name: r,
|
|
130
130
|
description: e,
|
|
131
131
|
inputSchema: {
|
|
132
132
|
type: "object",
|
|
133
133
|
properties: {}
|
|
134
134
|
},
|
|
135
135
|
handler: n,
|
|
136
|
-
...
|
|
136
|
+
...c
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
function se(
|
|
140
|
-
const f =
|
|
141
|
-
async (
|
|
142
|
-
const
|
|
139
|
+
function se(r, e, i, c, n) {
|
|
140
|
+
const f = P(
|
|
141
|
+
async (d) => {
|
|
142
|
+
const u = await c(d);
|
|
143
143
|
return {
|
|
144
144
|
content: [
|
|
145
145
|
{
|
|
146
146
|
type: "text",
|
|
147
|
-
text: JSON.stringify(
|
|
147
|
+
text: JSON.stringify(u, null, 2)
|
|
148
148
|
}
|
|
149
149
|
]
|
|
150
150
|
};
|
|
151
151
|
},
|
|
152
|
-
[
|
|
152
|
+
[c]
|
|
153
153
|
);
|
|
154
|
-
return
|
|
155
|
-
name:
|
|
154
|
+
return F({
|
|
155
|
+
name: r,
|
|
156
156
|
description: e,
|
|
157
157
|
inputSchema: {
|
|
158
158
|
type: "object",
|
|
159
|
-
properties:
|
|
159
|
+
properties: i,
|
|
160
160
|
...n?.required && { required: n.required }
|
|
161
161
|
},
|
|
162
162
|
handler: f,
|
|
@@ -164,71 +164,67 @@ function se(t, e, l, o, n) {
|
|
|
164
164
|
autoUnregister: n?.autoUnregister
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
-
const
|
|
167
|
+
const k = Q(null);
|
|
168
168
|
function ce({
|
|
169
|
-
children:
|
|
169
|
+
children: r,
|
|
170
170
|
autoInit: e = !0,
|
|
171
|
-
backendWsUrl:
|
|
172
|
-
authToken:
|
|
171
|
+
backendWsUrl: i = "ws://localhost:3001",
|
|
172
|
+
authToken: c,
|
|
173
173
|
initOptions: n,
|
|
174
174
|
onInitialized: f,
|
|
175
|
-
onInitError:
|
|
175
|
+
onInitError: d
|
|
176
176
|
}) {
|
|
177
|
-
const [
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
const [u, h] = z(!1), [R, g] = z(!1), [A] = z([]), w = t(n), p = t(i), S = t(f), M = t(d);
|
|
178
|
+
w.current = n, p.current = i, S.current = f, M.current = d;
|
|
179
|
+
const C = P(
|
|
180
|
+
async (l) => {
|
|
181
|
+
if (s.initialized) {
|
|
180
182
|
console.log("[MCPToolsProvider] Already initialized");
|
|
181
183
|
return;
|
|
182
184
|
}
|
|
183
185
|
try {
|
|
184
|
-
const
|
|
185
|
-
console.log("[MCPToolsProvider] Initializing worker client...",
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}), console.log("[MCPToolsProvider] Worker client initialized"),
|
|
190
|
-
} catch (
|
|
191
|
-
throw console.error("[MCPToolsProvider] Initialization failed:",
|
|
192
|
-
|
|
193
|
-
),
|
|
186
|
+
const a = l || w.current || { backendWsUrl: p.current };
|
|
187
|
+
console.log("[MCPToolsProvider] Initializing worker client...", a), await s.init(a), h(!0);
|
|
188
|
+
const I = await s.getConnectionStatus();
|
|
189
|
+
g(I), s.onConnectionStatus((b) => {
|
|
190
|
+
g(b);
|
|
191
|
+
}), console.log("[MCPToolsProvider] Worker client initialized"), S.current?.();
|
|
192
|
+
} catch (a) {
|
|
193
|
+
throw console.error("[MCPToolsProvider] Initialization failed:", a), M.current?.(
|
|
194
|
+
a instanceof Error ? a : new Error(String(a))
|
|
195
|
+
), a;
|
|
194
196
|
}
|
|
195
197
|
},
|
|
196
|
-
[
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
f,
|
|
202
|
-
g
|
|
203
|
-
]
|
|
204
|
-
), m = C(async () => {
|
|
205
|
-
const a = await i.getConnectionStatus();
|
|
206
|
-
return d(a), a;
|
|
198
|
+
[]
|
|
199
|
+
// stable — all dependencies accessed via refs
|
|
200
|
+
), x = P(async () => {
|
|
201
|
+
const l = await s.getConnectionStatus();
|
|
202
|
+
return g(l), l;
|
|
207
203
|
}, []);
|
|
208
|
-
|
|
209
|
-
e &&
|
|
210
|
-
console.error("[MCPToolsProvider] Auto-init failed:",
|
|
204
|
+
T(() => {
|
|
205
|
+
e && C().catch((l) => {
|
|
206
|
+
console.error("[MCPToolsProvider] Auto-init failed:", l);
|
|
211
207
|
});
|
|
212
|
-
}, [e,
|
|
213
|
-
|
|
214
|
-
}, [
|
|
215
|
-
if (!
|
|
216
|
-
const
|
|
208
|
+
}, [e, C]), T(() => {
|
|
209
|
+
u && c && (console.log("[MCPToolsProvider] Auth token changed, updating..."), s.setAuthToken(c));
|
|
210
|
+
}, [c, u]), T(() => {
|
|
211
|
+
if (!u) return;
|
|
212
|
+
const l = setInterval(() => {
|
|
217
213
|
}, 5e3);
|
|
218
|
-
return () => clearInterval(
|
|
219
|
-
}, [
|
|
214
|
+
return () => clearInterval(l);
|
|
215
|
+
}, [u]);
|
|
220
216
|
const v = {
|
|
221
|
-
isInitialized:
|
|
222
|
-
isConnected:
|
|
223
|
-
registeredTools:
|
|
224
|
-
initialize:
|
|
225
|
-
getConnectionStatus:
|
|
217
|
+
isInitialized: u,
|
|
218
|
+
isConnected: R,
|
|
219
|
+
registeredTools: A,
|
|
220
|
+
initialize: C,
|
|
221
|
+
getConnectionStatus: x
|
|
226
222
|
};
|
|
227
|
-
return /* @__PURE__ */
|
|
223
|
+
return /* @__PURE__ */ V(k.Provider, { value: v, children: r });
|
|
228
224
|
}
|
|
229
|
-
function ie(
|
|
230
|
-
const e =
|
|
231
|
-
if (!e &&
|
|
225
|
+
function ie(r = !1) {
|
|
226
|
+
const e = O(k);
|
|
227
|
+
if (!e && r)
|
|
232
228
|
throw new Error(
|
|
233
229
|
"useMCPToolsContext must be used within MCPToolsProvider. Either wrap your component tree with <MCPToolsProvider> or set strict=false."
|
|
234
230
|
);
|
|
@@ -243,7 +239,7 @@ function ie(t = !1) {
|
|
|
243
239
|
};
|
|
244
240
|
}
|
|
245
241
|
function ue() {
|
|
246
|
-
return
|
|
242
|
+
return O(k) !== null;
|
|
247
243
|
}
|
|
248
244
|
export {
|
|
249
245
|
ce as MCPToolsProvider,
|
|
@@ -254,6 +250,6 @@ export {
|
|
|
254
250
|
ue as useHasMCPProvider,
|
|
255
251
|
se as useMCPAction,
|
|
256
252
|
ne as useMCPGetter,
|
|
257
|
-
|
|
253
|
+
F as useMCPTool,
|
|
258
254
|
ie as useMCPToolsContext
|
|
259
255
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-fe/react-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://mcp-fe.ai",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@mcp-fe/mcp-worker": "^0.2.
|
|
22
|
+
"@mcp-fe/mcp-worker": "^0.2.2",
|
|
23
23
|
"react": "^19.0.0",
|
|
24
24
|
"react-dom": "^19.0.0"
|
|
25
25
|
},
|