@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 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 granting the License.
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
- (which shall not include communications that are solely about
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 upon (or derived from) the Work and for which the
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 derivative works thereof.
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
- systems, and issue tracking systems that are managed by, or on behalf
58
- of, the Licensor for the purpose of discussing and improving the Work,
59
- but excluding communication that is conspicuously marked or otherwise
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 use, reproduce, modify, merge, publish,
70
- distribute, sublicense, and/or sell copies of the Work, and to
71
- permit persons to whom the Work is furnished to do so, subject to
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 notice to Your modifications and
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 Support. You may choose to offer, and to
170
- charge a fee for, warranty, support, indemnity or other liability
171
- obligations and/or rights consistent with this License. However, in
172
- accepting such obligations, You may act only on Your own behalf and on
173
- Your sole responsibility, not on behalf of any other Contributor, and
174
- only if You agree to indemnify, defend, and hold each Contributor
175
- harmless for any liability incurred by, or claims asserted against,
176
- such Contributor by reason of your accepting any such warranty or support.
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 identification within
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,KAMN,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"}
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"),c=require("@mcp-fe/mcp-worker"),W=require("react/jsx-runtime");function m(r){const{name:t,description:l,inputSchema:n,outputSchema:s,handler:f,annotations:C,execution:i,_meta:d,icons:P,title:g,autoRegister:p=!0,autoUnregister:T=!0}=r,[w,y]=e.useState(null),a=e.useRef(f),u=e.useRef(t),h=e.useRef(l),S=e.useRef(n),x=e.useRef(s),b=e.useRef(C),I=e.useRef(i),E=e.useRef(d),A=e.useRef(P),z=e.useRef(g),N=e.useRef(!0),k=e.useRef(!1),R=e.useRef(!1);e.useEffect(()=>{a.current=f,u.current=t,h.current=l,S.current=n,x.current=s,b.current=C,I.current=i,E.current=d,A.current=P,z.current=g},[f,t,l,n,s,C,i,d,P,g]);const $=e.useCallback(async o=>a.current(o),[]),q=e.useCallback(async()=>{const o=u.current;if(k.current||R.current){console.log(`[useMCPTool] Skipping registration for '${o}' (already registered or in progress)`);return}k.current=!0;const M=h.current,H=S.current,O=x.current,U=b.current,F=I.current,G=E.current,J=A.current,_=z.current;try{await c.workerClient.registerTool(o,M,H,$,{outputSchema:O,annotations:U,execution:F,_meta:G,icons:J,title:_}),R.current=!0,console.log(`[useMCPTool] Registered tool '${o}'`)}catch(D){throw console.error(`[useMCPTool] Failed to register tool '${o}':`,D),D}finally{k.current=!1}},[$]),j=e.useCallback(async()=>{const o=u.current;if(!R.current){console.log(`[useMCPTool] Skipping unregistration for '${o}' (not registered)`);return}try{await c.workerClient.unregisterTool(o),R.current=!1,console.log(`[useMCPTool] Unregistered tool '${o}'`)}catch(M){console.error(`[useMCPTool] Failed to unregister tool '${o}':`,M)}},[]);return e.useEffect(()=>c.workerClient.onToolChange(t,M=>{y(M)}),[t]),e.useEffect(()=>(p&&q().catch(o=>{console.error(`[useMCPTool] Auto-register failed for '${t}':`,o)}),()=>{N.current=!1,T&&R.current&&j().catch(o=>{console.error(`[useMCPTool] Auto-unregister failed for '${t}':`,o)})}),[t]),{isRegistered:w?.isRegistered??!1,refCount:w?.refCount??0,register:q,unregister:j}}function B(r){return c.workerClient.isToolRegistered(r)}function K(){return c.workerClient.getRegisteredTools()}function L(r){return c.workerClient.getToolInfo(r)}function Q(r){return c.workerClient.getToolDetails(r)}function V(r,t,l,n){const s=e.useCallback(async()=>{const f=await l();return{content:[{type:"text",text:JSON.stringify(f,null,2)}]}},[l]);return m({name:r,description:t,inputSchema:{type:"object",properties:{}},handler:s,...n})}function X(r,t,l,n,s){const f=e.useCallback(async C=>{const i=await n(C);return{content:[{type:"text",text:JSON.stringify(i,null,2)}]}},[n]);return m({name:r,description:t,inputSchema:{type:"object",properties:l,...s?.required&&{required:s.required}},handler:f,autoRegister:s?.autoRegister,autoUnregister:s?.autoUnregister})}const v=e.createContext(null);function Y({children:r,autoInit:t=!0,backendWsUrl:l="ws://localhost:3001",authToken:n,initOptions:s,onInitialized:f,onInitError:C}){const[i,d]=e.useState(!1),[P,g]=e.useState(!1),[p]=e.useState([]),T=e.useCallback(async a=>{if(i){console.log("[MCPToolsProvider] Already initialized");return}try{const u=a||s||{backendWsUrl:l};console.log("[MCPToolsProvider] Initializing worker client...",u),await c.workerClient.init(u),n&&(console.log("[MCPToolsProvider] Setting auth token..."),c.workerClient.setAuthToken(n)),d(!0);const h=await c.workerClient.getConnectionStatus();g(h),c.workerClient.onConnectionStatus(S=>{g(S)}),console.log("[MCPToolsProvider] Worker client initialized"),f?.()}catch(u){throw console.error("[MCPToolsProvider] Initialization failed:",u),C?.(u instanceof Error?u:new Error(String(u))),u}},[i,s,l,n,f,C]),w=e.useCallback(async()=>{const a=await c.workerClient.getConnectionStatus();return g(a),a},[]);e.useEffect(()=>{t&&T().catch(a=>{console.error("[MCPToolsProvider] Auto-init failed:",a)})},[t,T]),e.useEffect(()=>{i&&n&&(console.log("[MCPToolsProvider] Auth token changed, updating..."),c.workerClient.setAuthToken(n))},[n,i]),e.useEffect(()=>{if(!i)return;const a=setInterval(()=>{},5e3);return()=>clearInterval(a)},[i]);const y={isInitialized:i,isConnected:P,registeredTools:p,initialize:T,getConnectionStatus:w};return W.jsx(v.Provider,{value:y,children:r})}function Z(r=!1){const t=e.useContext(v);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(v)!==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=m;exports.useMCPToolsContext=Z;
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 w, useRef as c, useEffect as P, useCallback as C, createContext as V, useContext as F } from "react";
2
- import { workerClient as i } from "@mcp-fe/mcp-worker";
3
- import { jsx as W } from "react/jsx-runtime";
4
- function H(t) {
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: l,
8
- inputSchema: o,
7
+ description: i,
8
+ inputSchema: c,
9
9
  outputSchema: n,
10
10
  handler: f,
11
- annotations: g,
12
- execution: s,
13
- _meta: T,
14
- icons: h,
15
- title: d,
16
- autoRegister: x = !0,
17
- autoUnregister: M = !0
18
- } = t, [m, v] = w(null), a = c(f), u = c(e), y = c(l), S = c(o), b = c(n), z = c(g), $ = c(s), E = c(T), k = c(h), N = c(d), J = c(!0), I = c(!1), p = c(!1);
19
- P(() => {
20
- a.current = f, u.current = e, y.current = l, S.current = o, b.current = n, z.current = g, $.current = s, E.current = T, k.current = h, N.current = d;
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
- l,
25
- o,
24
+ i,
25
+ c,
26
26
  n,
27
- g,
28
- s,
29
- T,
27
+ d,
28
+ u,
30
29
  h,
31
- d
30
+ R,
31
+ g
32
32
  ]);
33
- const j = C(async (r) => a.current(r), []), q = C(async () => {
34
- const r = u.current;
35
- if (I.current || p.current) {
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 '${r}' (already registered or in progress)`
37
+ `[useMCPTool] Skipping registration for '${o}' (already registered or in progress)`
38
38
  );
39
39
  return;
40
40
  }
41
- I.current = !0;
42
- const R = y.current, O = S.current, _ = b.current, G = z.current, B = $.current, K = E.current, L = k.current, Q = N.current;
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 i.registerTool(
45
- r,
46
- R,
47
- O,
48
- j,
44
+ await s.registerTool(
45
+ o,
46
+ y,
47
+ J,
48
+ N,
49
49
  {
50
- outputSchema: _,
51
- annotations: G,
52
- execution: B,
53
- _meta: K,
54
- icons: L,
55
- title: Q
50
+ outputSchema: W,
51
+ annotations: _,
52
+ execution: G,
53
+ _meta: B,
54
+ icons: K,
55
+ title: L
56
56
  }
57
- ), p.current = !0, console.log(`[useMCPTool] Registered tool '${r}'`);
58
- } catch (U) {
57
+ ), m.current = !0, console.log(`[useMCPTool] Registered tool '${o}'`);
58
+ } catch (D) {
59
59
  throw console.error(
60
- `[useMCPTool] Failed to register tool '${r}':`,
61
- U
62
- ), U;
60
+ `[useMCPTool] Failed to register tool '${o}':`,
61
+ D
62
+ ), D;
63
63
  } finally {
64
- I.current = !1;
64
+ $.current = !1;
65
65
  }
66
- }, [j]), D = C(async () => {
67
- const r = u.current;
68
- if (!p.current) {
66
+ }, [N]), q = P(async () => {
67
+ const o = C.current;
68
+ if (!m.current) {
69
69
  console.log(
70
- `[useMCPTool] Skipping unregistration for '${r}' (not registered)`
70
+ `[useMCPTool] Skipping unregistration for '${o}' (not registered)`
71
71
  );
72
72
  return;
73
73
  }
74
74
  try {
75
- await i.unregisterTool(r), p.current = !1, console.log(`[useMCPTool] Unregistered tool '${r}'`);
76
- } catch (R) {
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 '${r}':`,
79
- R
78
+ `[useMCPTool] Failed to unregister tool '${o}':`,
79
+ y
80
80
  );
81
81
  }
82
82
  }, []);
83
- return P(() => i.onToolChange(e, (R) => {
84
- v(R);
85
- }), [e]), P(() => (x && q().catch((r) => {
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
- r
88
+ o
89
89
  );
90
90
  }), () => {
91
- J.current = !1, M && p.current && D().catch((r) => {
91
+ H.current = !1, w && m.current && q().catch((o) => {
92
92
  console.error(
93
93
  `[useMCPTool] Auto-unregister failed for '${e}':`,
94
- r
94
+ o
95
95
  );
96
96
  });
97
97
  }), [e]), {
98
- isRegistered: m?.isRegistered ?? !1,
99
- refCount: m?.refCount ?? 0,
100
- register: q,
101
- unregister: D
98
+ isRegistered: p?.isRegistered ?? !1,
99
+ refCount: p?.refCount ?? 0,
100
+ register: j,
101
+ unregister: q
102
102
  };
103
103
  }
104
- function ee(t) {
105
- return i.isToolRegistered(t);
104
+ function ee(r) {
105
+ return s.isToolRegistered(r);
106
106
  }
107
107
  function te() {
108
- return i.getRegisteredTools();
108
+ return s.getRegisteredTools();
109
109
  }
110
- function re(t) {
111
- return i.getToolInfo(t);
110
+ function re(r) {
111
+ return s.getToolInfo(r);
112
112
  }
113
- function oe(t) {
114
- return i.getToolDetails(t);
113
+ function oe(r) {
114
+ return s.getToolDetails(r);
115
115
  }
116
- function ne(t, e, l, o) {
117
- const n = C(async () => {
118
- const f = await l();
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
- }, [l]);
128
- return H({
129
- name: t,
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
- ...o
136
+ ...c
137
137
  });
138
138
  }
139
- function se(t, e, l, o, n) {
140
- const f = C(
141
- async (g) => {
142
- const s = await o(g);
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(s, null, 2)
147
+ text: JSON.stringify(u, null, 2)
148
148
  }
149
149
  ]
150
150
  };
151
151
  },
152
- [o]
152
+ [c]
153
153
  );
154
- return H({
155
- name: t,
154
+ return F({
155
+ name: r,
156
156
  description: e,
157
157
  inputSchema: {
158
158
  type: "object",
159
- properties: l,
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 A = V(null);
167
+ const k = Q(null);
168
168
  function ce({
169
- children: t,
169
+ children: r,
170
170
  autoInit: e = !0,
171
- backendWsUrl: l = "ws://localhost:3001",
172
- authToken: o,
171
+ backendWsUrl: i = "ws://localhost:3001",
172
+ authToken: c,
173
173
  initOptions: n,
174
174
  onInitialized: f,
175
- onInitError: g
175
+ onInitError: d
176
176
  }) {
177
- const [s, T] = w(!1), [h, d] = w(!1), [x] = w([]), M = C(
178
- async (a) => {
179
- if (s) {
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 u = a || n || { backendWsUrl: l };
185
- console.log("[MCPToolsProvider] Initializing worker client...", u), await i.init(u), o && (console.log("[MCPToolsProvider] Setting auth token..."), i.setAuthToken(o)), T(!0);
186
- const y = await i.getConnectionStatus();
187
- d(y), i.onConnectionStatus((S) => {
188
- d(S);
189
- }), console.log("[MCPToolsProvider] Worker client initialized"), f?.();
190
- } catch (u) {
191
- throw console.error("[MCPToolsProvider] Initialization failed:", u), g?.(
192
- u instanceof Error ? u : new Error(String(u))
193
- ), u;
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
- s,
198
- n,
199
- l,
200
- o,
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
- P(() => {
209
- e && M().catch((a) => {
210
- console.error("[MCPToolsProvider] Auto-init failed:", a);
204
+ T(() => {
205
+ e && C().catch((l) => {
206
+ console.error("[MCPToolsProvider] Auto-init failed:", l);
211
207
  });
212
- }, [e, M]), P(() => {
213
- s && o && (console.log("[MCPToolsProvider] Auth token changed, updating..."), i.setAuthToken(o));
214
- }, [o, s]), P(() => {
215
- if (!s) return;
216
- const a = setInterval(() => {
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(a);
219
- }, [s]);
214
+ return () => clearInterval(l);
215
+ }, [u]);
220
216
  const v = {
221
- isInitialized: s,
222
- isConnected: h,
223
- registeredTools: x,
224
- initialize: M,
225
- getConnectionStatus: m
217
+ isInitialized: u,
218
+ isConnected: R,
219
+ registeredTools: A,
220
+ initialize: C,
221
+ getConnectionStatus: x
226
222
  };
227
- return /* @__PURE__ */ W(A.Provider, { value: v, children: t });
223
+ return /* @__PURE__ */ V(k.Provider, { value: v, children: r });
228
224
  }
229
- function ie(t = !1) {
230
- const e = F(A);
231
- if (!e && t)
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 F(A) !== null;
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
- H as useMCPTool,
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.0",
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.0",
22
+ "@mcp-fe/mcp-worker": "^0.2.2",
23
23
  "react": "^19.0.0",
24
24
  "react-dom": "^19.0.0"
25
25
  },