@mcp-fe/react-tools 0.1.5 → 0.1.7

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.
@@ -1,4 +1,4 @@
1
- import { ToolHandler } from '@mcp-fe/mcp-worker';
1
+ import { ToolHandler, Icon, ToolAnnotations, ToolExecution } from '@mcp-fe/mcp-worker';
2
2
  export interface UseMCPToolOptions {
3
3
  /**
4
4
  * Tool name (must be unique)
@@ -7,15 +7,45 @@ export interface UseMCPToolOptions {
7
7
  /**
8
8
  * Tool description for AI
9
9
  */
10
- description: string;
10
+ description?: string;
11
11
  /**
12
12
  * JSON Schema for tool inputs
13
13
  */
14
14
  inputSchema: Record<string, unknown>;
15
+ /**
16
+ * JSON Schema for tool outputs (optional)
17
+ */
18
+ outputSchema?: Record<string, unknown>;
15
19
  /**
16
20
  * Handler function (runs in main thread with full browser access)
17
21
  */
18
22
  handler: ToolHandler;
23
+ /**
24
+ * Tool annotations (hints for AI about tool behavior)
25
+ * - title: Human-readable title for the tool
26
+ * - readOnlyHint: Indicates the tool only reads data
27
+ * - destructiveHint: Warns that the tool performs destructive actions
28
+ * - idempotentHint: Indicates multiple calls have the same effect
29
+ * - openWorldHint: Suggests the tool may access external systems
30
+ */
31
+ annotations?: ToolAnnotations;
32
+ /**
33
+ * Tool execution metadata
34
+ * - taskSupport: Whether the tool supports task-based execution
35
+ */
36
+ execution?: ToolExecution;
37
+ /**
38
+ * Optional metadata for extensibility
39
+ */
40
+ _meta?: Record<string, unknown>;
41
+ /**
42
+ * Optional icons for the tool
43
+ */
44
+ icons?: Icon[];
45
+ /**
46
+ * Optional display title
47
+ */
48
+ title?: string;
19
49
  /**
20
50
  * Whether to register immediately on mount (default: true)
21
51
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useMCPTool.d.ts","sourceRoot":"","sources":["../../../../libs/react-tools/src/hooks/useMCPTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAg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G,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,GACX;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAEpD"}
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),l=require("@mcp-fe/mcp-worker"),x=require("react/jsx-runtime");function k(r){const{name:t,description:i,inputSchema:c,handler:n,autoRegister:f=!0,autoUnregister:a=!0}=r,[C,h]=e.useState(null),d=e.useRef(n),P=e.useRef(t),g=e.useRef(i),M=e.useRef(c),y=e.useRef(!0),s=e.useRef(!1);e.useEffect(()=>{d.current=n,P.current=t,g.current=i,M.current=c},[n,t,i,c]);const u=e.useCallback(async o=>d.current(o),[]),w=e.useCallback(async()=>{const o=P.current,T=g.current,b=M.current;try{await l.workerClient.registerTool(o,T,b,u),s.current=!0,console.log(`[useMCPTool] Registered tool '${o}'`)}catch(v){throw console.error(`[useMCPTool] Failed to register tool '${o}':`,v),v}},[u]),R=e.useCallback(async()=>{const o=P.current;try{await l.workerClient.unregisterTool(o),s.current=!1,console.log(`[useMCPTool] Unregistered tool '${o}'`)}catch(T){console.error(`[useMCPTool] Failed to unregister tool '${o}':`,T)}},[]);return e.useEffect(()=>l.workerClient.onToolChange(t,T=>{h(T)}),[t]),e.useEffect(()=>(f&&w().catch(o=>{console.error(`[useMCPTool] Auto-register failed for '${t}':`,o)}),()=>{y.current=!1,a&&s.current&&R().catch(o=>{console.error(`[useMCPTool] Auto-unregister failed for '${t}':`,o)})}),[t]),{isRegistered:C?.isRegistered??!1,refCount:C?.refCount??0,register:w,unregister:R}}function p(r){return l.workerClient.isToolRegistered(r)}function m(){return l.workerClient.getRegisteredTools()}function I(r){return l.workerClient.getToolInfo(r)}function E(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 k({name:r,description:t,inputSchema:{type:"object",properties:{}},handler:n,...c})}function z(r,t,i,c,n){const f=e.useCallback(async a=>{const C=await c(a);return{content:[{type:"text",text:JSON.stringify(C,null,2)}]}},[c]);return k({name:r,description:t,inputSchema:{type:"object",properties:i,...n?.required&&{required:n.required}},handler:f,autoRegister:n?.autoRegister,autoUnregister:n?.autoUnregister})}const S=e.createContext(null);function q({children:r,autoInit:t=!0,backendWsUrl:i="ws://localhost:3001",initOptions:c,onInitialized:n,onInitError:f}){const[a,C]=e.useState(!1),[h,d]=e.useState(!1),[P]=e.useState([]),g=e.useCallback(async s=>{if(a){console.log("[MCPToolsProvider] Already initialized");return}try{const u=s||c||{backendWsUrl:i};console.log("[MCPToolsProvider] Initializing worker client...",u),await l.workerClient.init(u),C(!0);const w=await l.workerClient.getConnectionStatus();d(w),l.workerClient.onConnectionStatus(R=>{d(R)}),console.log("[MCPToolsProvider] Worker client initialized"),n?.()}catch(u){throw console.error("[MCPToolsProvider] Initialization failed:",u),f?.(u instanceof Error?u:new Error(String(u))),u}},[a,c,i,n,f]),M=e.useCallback(async()=>{const s=await l.workerClient.getConnectionStatus();return d(s),s},[]);e.useEffect(()=>{t&&g().catch(s=>{console.error("[MCPToolsProvider] Auto-init failed:",s)})},[t,g]),e.useEffect(()=>{if(!a)return;const s=setInterval(()=>{},5e3);return()=>clearInterval(s)},[a]);const y={isInitialized:a,isConnected:h,registeredTools:P,initialize:g,getConnectionStatus:M};return x.jsx(S.Provider,{value:y,children:r})}function A(r=!1){const t=e.useContext(S);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 $(){return e.useContext(S)!==null}exports.MCPToolsProvider=q;exports.getRegisteredTools=m;exports.getToolInfo=I;exports.isToolRegistered=p;exports.useHasMCPProvider=$;exports.useMCPAction=z;exports.useMCPGetter=E;exports.useMCPTool=k;exports.useMCPToolsContext=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),f=require("@mcp-fe/mcp-worker"),D=require("react/jsx-runtime");function m(r){const{name:t,description:s,inputSchema:c,outputSchema:n,handler:l,annotations:u,execution:C,_meta:g,icons:d,title:P,autoRegister:T=!0,autoUnregister:S=!0}=r,[h,a]=e.useState(null),i=e.useRef(l),R=e.useRef(t),w=e.useRef(s),k=e.useRef(c),p=e.useRef(n),v=e.useRef(u),b=e.useRef(C),I=e.useRef(g),E=e.useRef(d),z=e.useRef(P),N=e.useRef(!0),y=e.useRef(!1);e.useEffect(()=>{i.current=l,R.current=t,w.current=s,k.current=c,p.current=n,v.current=u,b.current=C,I.current=g,E.current=d,z.current=P},[l,t,s,c,n,u,C,g,d,P]);const A=e.useCallback(async o=>i.current(o),[]),q=e.useCallback(async()=>{const o=R.current,M=w.current,H=k.current,O=p.current,U=v.current,F=b.current,G=I.current,J=E.current,_=z.current;try{await f.workerClient.registerTool(o,M,H,A,{outputSchema:O,annotations:U,execution:F,_meta:G,icons:J,title:_}),y.current=!0,console.log(`[useMCPTool] Registered tool '${o}'`)}catch(j){throw console.error(`[useMCPTool] Failed to register tool '${o}':`,j),j}},[A]),$=e.useCallback(async()=>{const o=R.current;try{await f.workerClient.unregisterTool(o),y.current=!1,console.log(`[useMCPTool] Unregistered tool '${o}'`)}catch(M){console.error(`[useMCPTool] Failed to unregister tool '${o}':`,M)}},[]);return e.useEffect(()=>f.workerClient.onToolChange(t,M=>{a(M)}),[t]),e.useEffect(()=>(T&&q().catch(o=>{console.error(`[useMCPTool] Auto-register failed for '${t}':`,o)}),()=>{N.current=!1,S&&y.current&&$().catch(o=>{console.error(`[useMCPTool] Auto-unregister failed for '${t}':`,o)})}),[t]),{isRegistered:h?.isRegistered??!1,refCount:h?.refCount??0,register:q,unregister:$}}function W(r){return f.workerClient.isToolRegistered(r)}function B(){return f.workerClient.getRegisteredTools()}function K(r){return f.workerClient.getToolInfo(r)}function L(r,t,s,c){const n=e.useCallback(async()=>{const l=await s();return{content:[{type:"text",text:JSON.stringify(l,null,2)}]}},[s]);return m({name:r,description:t,inputSchema:{type:"object",properties:{}},handler:n,...c})}function Q(r,t,s,c,n){const l=e.useCallback(async u=>{const C=await c(u);return{content:[{type:"text",text:JSON.stringify(C,null,2)}]}},[c]);return m({name:r,description:t,inputSchema:{type:"object",properties:s,...n?.required&&{required:n.required}},handler:l,autoRegister:n?.autoRegister,autoUnregister:n?.autoUnregister})}const x=e.createContext(null);function V({children:r,autoInit:t=!0,backendWsUrl:s="ws://localhost:3001",initOptions:c,onInitialized:n,onInitError:l}){const[u,C]=e.useState(!1),[g,d]=e.useState(!1),[P]=e.useState([]),T=e.useCallback(async a=>{if(u){console.log("[MCPToolsProvider] Already initialized");return}try{const i=a||c||{backendWsUrl:s};console.log("[MCPToolsProvider] Initializing worker client...",i),await f.workerClient.init(i),C(!0);const R=await f.workerClient.getConnectionStatus();d(R),f.workerClient.onConnectionStatus(w=>{d(w)}),console.log("[MCPToolsProvider] Worker client initialized"),n?.()}catch(i){throw console.error("[MCPToolsProvider] Initialization failed:",i),l?.(i instanceof Error?i:new Error(String(i))),i}},[u,c,s,n,l]),S=e.useCallback(async()=>{const a=await f.workerClient.getConnectionStatus();return d(a),a},[]);e.useEffect(()=>{t&&T().catch(a=>{console.error("[MCPToolsProvider] Auto-init failed:",a)})},[t,T]),e.useEffect(()=>{if(!u)return;const a=setInterval(()=>{},5e3);return()=>clearInterval(a)},[u]);const h={isInitialized:u,isConnected:g,registeredTools:P,initialize:T,getConnectionStatus:S};return D.jsx(x.Provider,{value:h,children:r})}function X(r=!1){const t=e.useContext(x);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 Y(){return e.useContext(x)!==null}exports.MCPToolsProvider=V;exports.getRegisteredTools=B;exports.getToolInfo=K;exports.isToolRegistered=W;exports.useHasMCPProvider=Y;exports.useMCPAction=Q;exports.useMCPGetter=L;exports.useMCPTool=m;exports.useMCPToolsContext=X;
package/index.mjs CHANGED
@@ -1,76 +1,101 @@
1
- import { useState as m, useRef as P, useEffect as M, useCallback as f, createContext as $, useContext as I } from "react";
2
- import { workerClient as u } from "@mcp-fe/mcp-worker";
3
- import { jsx as A } from "react/jsx-runtime";
4
- function b(t) {
1
+ import { useState as y, useRef as n, useEffect as R, useCallback as C, createContext as Q, useContext as F } from "react";
2
+ import { workerClient as f } from "@mcp-fe/mcp-worker";
3
+ import { jsx as V } from "react/jsx-runtime";
4
+ function H(t) {
5
5
  const {
6
6
  name: e,
7
7
  description: s,
8
- inputSchema: i,
9
- handler: r,
10
- autoRegister: a = !0,
11
- autoUnregister: l = !0
12
- } = t, [d, p] = m(null), g = P(r), T = P(e), C = P(s), w = P(i), v = P(!0), n = P(!1);
13
- M(() => {
14
- g.current = r, T.current = e, C.current = s, w.current = i;
15
- }, [r, e, s, i]);
16
- const c = f(async (o) => g.current(o), []), y = f(async () => {
17
- const o = T.current, h = C.current, z = w.current;
8
+ inputSchema: c,
9
+ outputSchema: o,
10
+ handler: a,
11
+ annotations: i,
12
+ execution: d,
13
+ _meta: P,
14
+ icons: g,
15
+ title: T,
16
+ autoRegister: h = !0,
17
+ autoUnregister: x = !0
18
+ } = t, [p, l] = y(null), u = n(a), m = n(e), w = n(s), I = n(c), b = n(o), z = n(i), A = n(d), E = n(P), $ = n(g), N = n(T), J = n(!0), S = n(!1);
19
+ R(() => {
20
+ u.current = a, m.current = e, w.current = s, I.current = c, b.current = o, z.current = i, A.current = d, E.current = P, $.current = g, N.current = T;
21
+ }, [
22
+ a,
23
+ e,
24
+ s,
25
+ c,
26
+ o,
27
+ i,
28
+ d,
29
+ P,
30
+ g,
31
+ T
32
+ ]);
33
+ const j = C(async (r) => u.current(r), []), k = C(async () => {
34
+ const r = m.current, M = w.current, O = I.current, _ = b.current, D = z.current, G = A.current, B = E.current, K = $.current, L = N.current;
18
35
  try {
19
- await u.registerTool(
20
- o,
21
- h,
22
- z,
23
- c
24
- ), n.current = !0, console.log(`[useMCPTool] Registered tool '${o}'`);
25
- } catch (S) {
36
+ await f.registerTool(
37
+ r,
38
+ M,
39
+ O,
40
+ j,
41
+ {
42
+ outputSchema: _,
43
+ annotations: D,
44
+ execution: G,
45
+ _meta: B,
46
+ icons: K,
47
+ title: L
48
+ }
49
+ ), S.current = !0, console.log(`[useMCPTool] Registered tool '${r}'`);
50
+ } catch (U) {
26
51
  throw console.error(
27
- `[useMCPTool] Failed to register tool '${o}':`,
28
- S
29
- ), S;
52
+ `[useMCPTool] Failed to register tool '${r}':`,
53
+ U
54
+ ), U;
30
55
  }
31
- }, [c]), R = f(async () => {
32
- const o = T.current;
56
+ }, [j]), q = C(async () => {
57
+ const r = m.current;
33
58
  try {
34
- await u.unregisterTool(o), n.current = !1, console.log(`[useMCPTool] Unregistered tool '${o}'`);
35
- } catch (h) {
59
+ await f.unregisterTool(r), S.current = !1, console.log(`[useMCPTool] Unregistered tool '${r}'`);
60
+ } catch (M) {
36
61
  console.error(
37
- `[useMCPTool] Failed to unregister tool '${o}':`,
38
- h
62
+ `[useMCPTool] Failed to unregister tool '${r}':`,
63
+ M
39
64
  );
40
65
  }
41
66
  }, []);
42
- return M(() => u.onToolChange(e, (h) => {
43
- p(h);
44
- }), [e]), M(() => (a && y().catch((o) => {
67
+ return R(() => f.onToolChange(e, (M) => {
68
+ l(M);
69
+ }), [e]), R(() => (h && k().catch((r) => {
45
70
  console.error(
46
71
  `[useMCPTool] Auto-register failed for '${e}':`,
47
- o
72
+ r
48
73
  );
49
74
  }), () => {
50
- v.current = !1, l && n.current && R().catch((o) => {
75
+ J.current = !1, x && S.current && q().catch((r) => {
51
76
  console.error(
52
77
  `[useMCPTool] Auto-unregister failed for '${e}':`,
53
- o
78
+ r
54
79
  );
55
80
  });
56
81
  }), [e]), {
57
- isRegistered: d?.isRegistered ?? !1,
58
- refCount: d?.refCount ?? 0,
59
- register: y,
60
- unregister: R
82
+ isRegistered: p?.isRegistered ?? !1,
83
+ refCount: p?.refCount ?? 0,
84
+ register: k,
85
+ unregister: q
61
86
  };
62
87
  }
63
- function k(t) {
64
- return u.isToolRegistered(t);
88
+ function Z(t) {
89
+ return f.isToolRegistered(t);
65
90
  }
66
- function q() {
67
- return u.getRegisteredTools();
91
+ function ee() {
92
+ return f.getRegisteredTools();
68
93
  }
69
- function U(t) {
70
- return u.getToolInfo(t);
94
+ function te(t) {
95
+ return f.getToolInfo(t);
71
96
  }
72
- function F(t, e, s, i) {
73
- const r = f(async () => {
97
+ function re(t, e, s, c) {
98
+ const o = C(async () => {
74
99
  const a = await s();
75
100
  return {
76
101
  content: [
@@ -81,21 +106,21 @@ function F(t, e, s, i) {
81
106
  ]
82
107
  };
83
108
  }, [s]);
84
- return b({
109
+ return H({
85
110
  name: t,
86
111
  description: e,
87
112
  inputSchema: {
88
113
  type: "object",
89
114
  properties: {}
90
115
  },
91
- handler: r,
92
- ...i
116
+ handler: o,
117
+ ...c
93
118
  });
94
119
  }
95
- function H(t, e, s, i, r) {
96
- const a = f(
97
- async (l) => {
98
- const d = await i(l);
120
+ function oe(t, e, s, c, o) {
121
+ const a = C(
122
+ async (i) => {
123
+ const d = await c(i);
99
124
  return {
100
125
  content: [
101
126
  {
@@ -105,75 +130,75 @@ function H(t, e, s, i, r) {
105
130
  ]
106
131
  };
107
132
  },
108
- [i]
133
+ [c]
109
134
  );
110
- return b({
135
+ return H({
111
136
  name: t,
112
137
  description: e,
113
138
  inputSchema: {
114
139
  type: "object",
115
140
  properties: s,
116
- ...r?.required && { required: r.required }
141
+ ...o?.required && { required: o.required }
117
142
  },
118
143
  handler: a,
119
- autoRegister: r?.autoRegister,
120
- autoUnregister: r?.autoUnregister
144
+ autoRegister: o?.autoRegister,
145
+ autoUnregister: o?.autoUnregister
121
146
  });
122
147
  }
123
- const x = $(null);
124
- function J({
148
+ const v = Q(null);
149
+ function ne({
125
150
  children: t,
126
151
  autoInit: e = !0,
127
152
  backendWsUrl: s = "ws://localhost:3001",
128
- initOptions: i,
129
- onInitialized: r,
153
+ initOptions: c,
154
+ onInitialized: o,
130
155
  onInitError: a
131
156
  }) {
132
- const [l, d] = m(!1), [p, g] = m(!1), [T] = m([]), C = f(
133
- async (n) => {
134
- if (l) {
157
+ const [i, d] = y(!1), [P, g] = y(!1), [T] = y([]), h = C(
158
+ async (l) => {
159
+ if (i) {
135
160
  console.log("[MCPToolsProvider] Already initialized");
136
161
  return;
137
162
  }
138
163
  try {
139
- const c = n || i || { backendWsUrl: s };
140
- console.log("[MCPToolsProvider] Initializing worker client...", c), await u.init(c), d(!0);
141
- const y = await u.getConnectionStatus();
142
- g(y), u.onConnectionStatus((R) => {
143
- g(R);
144
- }), console.log("[MCPToolsProvider] Worker client initialized"), r?.();
145
- } catch (c) {
146
- throw console.error("[MCPToolsProvider] Initialization failed:", c), a?.(
147
- c instanceof Error ? c : new Error(String(c))
148
- ), c;
164
+ const u = l || c || { backendWsUrl: s };
165
+ console.log("[MCPToolsProvider] Initializing worker client...", u), await f.init(u), d(!0);
166
+ const m = await f.getConnectionStatus();
167
+ g(m), f.onConnectionStatus((w) => {
168
+ g(w);
169
+ }), console.log("[MCPToolsProvider] Worker client initialized"), o?.();
170
+ } catch (u) {
171
+ throw console.error("[MCPToolsProvider] Initialization failed:", u), a?.(
172
+ u instanceof Error ? u : new Error(String(u))
173
+ ), u;
149
174
  }
150
175
  },
151
- [l, i, s, r, a]
152
- ), w = f(async () => {
153
- const n = await u.getConnectionStatus();
154
- return g(n), n;
176
+ [i, c, s, o, a]
177
+ ), x = C(async () => {
178
+ const l = await f.getConnectionStatus();
179
+ return g(l), l;
155
180
  }, []);
156
- M(() => {
157
- e && C().catch((n) => {
158
- console.error("[MCPToolsProvider] Auto-init failed:", n);
181
+ R(() => {
182
+ e && h().catch((l) => {
183
+ console.error("[MCPToolsProvider] Auto-init failed:", l);
159
184
  });
160
- }, [e, C]), M(() => {
161
- if (!l) return;
162
- const n = setInterval(() => {
185
+ }, [e, h]), R(() => {
186
+ if (!i) return;
187
+ const l = setInterval(() => {
163
188
  }, 5e3);
164
- return () => clearInterval(n);
165
- }, [l]);
166
- const v = {
167
- isInitialized: l,
168
- isConnected: p,
189
+ return () => clearInterval(l);
190
+ }, [i]);
191
+ const p = {
192
+ isInitialized: i,
193
+ isConnected: P,
169
194
  registeredTools: T,
170
- initialize: C,
171
- getConnectionStatus: w
195
+ initialize: h,
196
+ getConnectionStatus: x
172
197
  };
173
- return /* @__PURE__ */ A(x.Provider, { value: v, children: t });
198
+ return /* @__PURE__ */ V(v.Provider, { value: p, children: t });
174
199
  }
175
- function D(t = !1) {
176
- const e = I(x);
200
+ function se(t = !1) {
201
+ const e = F(v);
177
202
  if (!e && t)
178
203
  throw new Error(
179
204
  "useMCPToolsContext must be used within MCPToolsProvider. Either wrap your component tree with <MCPToolsProvider> or set strict=false."
@@ -188,17 +213,17 @@ function D(t = !1) {
188
213
  getConnectionStatus: async () => !1
189
214
  };
190
215
  }
191
- function G() {
192
- return I(x) !== null;
216
+ function ce() {
217
+ return F(v) !== null;
193
218
  }
194
219
  export {
195
- J as MCPToolsProvider,
196
- q as getRegisteredTools,
197
- U as getToolInfo,
198
- k as isToolRegistered,
199
- G as useHasMCPProvider,
200
- H as useMCPAction,
201
- F as useMCPGetter,
202
- b as useMCPTool,
203
- D as useMCPToolsContext
220
+ ne as MCPToolsProvider,
221
+ ee as getRegisteredTools,
222
+ te as getToolInfo,
223
+ Z as isToolRegistered,
224
+ ce as useHasMCPProvider,
225
+ oe as useMCPAction,
226
+ re as useMCPGetter,
227
+ H as useMCPTool,
228
+ se as useMCPToolsContext
204
229
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-fe/react-tools",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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.1.5",
22
+ "@mcp-fe/mcp-worker": "^0.1.7",
23
23
  "react": "^19.0.0",
24
24
  "react-dom": "^19.0.0"
25
25
  },