@frontmcp/react 1.8.6 → 1.8.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.
- package/ai/index.js +39 -12
- package/api/index.js +29 -9
- package/components/ToolForm.d.ts +1 -1
- package/components/ToolForm.d.ts.map +1 -1
- package/esm/ai/index.mjs +42 -15
- package/esm/api/index.mjs +29 -9
- package/esm/index.mjs +95 -30
- package/esm/package.json +6 -6
- package/esm/router/index.mjs +22 -4
- package/esm/state/index.mjs +29 -9
- package/hooks/useDynamicTool.d.ts.map +1 -1
- package/hooks/useServer.d.ts +2 -2
- package/hooks/useServer.d.ts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +91 -26
- package/package.json +6 -6
- package/provider/FrontMcpContext.d.ts +2 -1
- package/provider/FrontMcpContext.d.ts.map +1 -1
- package/registry/DynamicRegistry.d.ts +4 -1
- package/registry/DynamicRegistry.d.ts.map +1 -1
- package/registry/ServerRegistry.d.ts +3 -3
- package/registry/ServerRegistry.d.ts.map +1 -1
- package/registry/createWrappedServer.d.ts.map +1 -1
- package/router/index.js +22 -4
- package/router/router.entries.d.ts +9 -5
- package/router/router.entries.d.ts.map +1 -1
- package/state/index.js +29 -9
package/ai/index.js
CHANGED
|
@@ -90,6 +90,7 @@ var DynamicRegistry = class {
|
|
|
90
90
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
91
91
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
92
92
|
listeners = /* @__PURE__ */ new Set();
|
|
93
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
93
94
|
version = 0;
|
|
94
95
|
/**
|
|
95
96
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -168,8 +169,18 @@ var DynamicRegistry = class {
|
|
|
168
169
|
if (existing) {
|
|
169
170
|
existing.read = read;
|
|
170
171
|
this.notify();
|
|
172
|
+
this.resourceListeners.forEach((l) => {
|
|
173
|
+
l(uri);
|
|
174
|
+
});
|
|
171
175
|
}
|
|
172
176
|
}
|
|
177
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
178
|
+
onResourceUpdated(listener) {
|
|
179
|
+
this.resourceListeners.add(listener);
|
|
180
|
+
return () => {
|
|
181
|
+
this.resourceListeners.delete(listener);
|
|
182
|
+
};
|
|
183
|
+
}
|
|
173
184
|
getTools() {
|
|
174
185
|
return [...this.tools.values()];
|
|
175
186
|
}
|
|
@@ -214,15 +225,24 @@ var DynamicRegistry = class {
|
|
|
214
225
|
};
|
|
215
226
|
|
|
216
227
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
228
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
229
|
+
function getOrCreateContext() {
|
|
230
|
+
const host = globalThis;
|
|
231
|
+
const existing = host[CONTEXT_KEY];
|
|
232
|
+
if (existing) return existing;
|
|
233
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
234
|
+
const created = (0, import_react.createContext)({
|
|
235
|
+
name: "default",
|
|
236
|
+
registry: new ComponentRegistry(),
|
|
237
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
238
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
239
|
+
connect: async () => {
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
host[CONTEXT_KEY] = created;
|
|
243
|
+
return created;
|
|
244
|
+
}
|
|
245
|
+
var FrontMcpContext = getOrCreateContext();
|
|
226
246
|
|
|
227
247
|
// libs/react/src/hooks/useServer.ts
|
|
228
248
|
var import_react2 = require("react");
|
|
@@ -320,14 +340,21 @@ var ServerRegistry = class {
|
|
|
320
340
|
this.listeners.forEach((l) => l());
|
|
321
341
|
}
|
|
322
342
|
};
|
|
323
|
-
var
|
|
343
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/serverRegistry");
|
|
344
|
+
function getOrCreateRegistry() {
|
|
345
|
+
const host = globalThis;
|
|
346
|
+
return host[REGISTRY_KEY] ??= new ServerRegistry();
|
|
347
|
+
}
|
|
348
|
+
var serverRegistry = getOrCreateRegistry();
|
|
324
349
|
|
|
325
350
|
// libs/react/src/hooks/useServer.ts
|
|
326
351
|
function useServer(name) {
|
|
352
|
+
const ctx = (0, import_react2.useContext)(FrontMcpContext);
|
|
353
|
+
const serverName = name ?? ctx.name;
|
|
327
354
|
const subscribe = (0, import_react2.useCallback)((cb) => serverRegistry.subscribe(cb), []);
|
|
328
355
|
const getSnapshot = (0, import_react2.useCallback)(() => {
|
|
329
|
-
return serverRegistry.get(
|
|
330
|
-
}, [
|
|
356
|
+
return serverRegistry.get(serverName);
|
|
357
|
+
}, [serverName]);
|
|
331
358
|
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
332
359
|
}
|
|
333
360
|
|
package/api/index.js
CHANGED
|
@@ -86,6 +86,7 @@ var DynamicRegistry = class {
|
|
|
86
86
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
87
87
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
88
88
|
listeners = /* @__PURE__ */ new Set();
|
|
89
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
89
90
|
version = 0;
|
|
90
91
|
/**
|
|
91
92
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -164,8 +165,18 @@ var DynamicRegistry = class {
|
|
|
164
165
|
if (existing) {
|
|
165
166
|
existing.read = read;
|
|
166
167
|
this.notify();
|
|
168
|
+
this.resourceListeners.forEach((l) => {
|
|
169
|
+
l(uri);
|
|
170
|
+
});
|
|
167
171
|
}
|
|
168
172
|
}
|
|
173
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
174
|
+
onResourceUpdated(listener) {
|
|
175
|
+
this.resourceListeners.add(listener);
|
|
176
|
+
return () => {
|
|
177
|
+
this.resourceListeners.delete(listener);
|
|
178
|
+
};
|
|
179
|
+
}
|
|
169
180
|
getTools() {
|
|
170
181
|
return [...this.tools.values()];
|
|
171
182
|
}
|
|
@@ -210,15 +221,24 @@ var DynamicRegistry = class {
|
|
|
210
221
|
};
|
|
211
222
|
|
|
212
223
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
224
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
225
|
+
function getOrCreateContext() {
|
|
226
|
+
const host = globalThis;
|
|
227
|
+
const existing = host[CONTEXT_KEY];
|
|
228
|
+
if (existing) return existing;
|
|
229
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
230
|
+
const created = (0, import_react.createContext)({
|
|
231
|
+
name: "default",
|
|
232
|
+
registry: new ComponentRegistry(),
|
|
233
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
234
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
235
|
+
connect: async () => {
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
host[CONTEXT_KEY] = created;
|
|
239
|
+
return created;
|
|
240
|
+
}
|
|
241
|
+
var FrontMcpContext = getOrCreateContext();
|
|
222
242
|
|
|
223
243
|
// libs/react/src/api/createFetchClient.ts
|
|
224
244
|
function createFetchClient(fetchFn) {
|
package/components/ToolForm.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Otherwise uses basic unstyled `<input>` / `<select>` / `<textarea>`.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import type {
|
|
8
|
+
import type { FieldRenderProps, ToolInfo } from '../types';
|
|
9
9
|
export interface ToolFormProps {
|
|
10
10
|
tool: ToolInfo;
|
|
11
11
|
onSubmit: (args: Record<string, unknown>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolForm.d.ts","sourceRoot":"","sources":["../../src/components/ToolForm.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAgC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ToolForm.d.ts","sourceRoot":"","sources":["../../src/components/ToolForm.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAgC,MAAM,OAAO,CAAC;AAErD,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,KAAK,CAAC,SAAS,CAAC;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,WAAyB,GAC1B,EAAE,aAAa,GAAG,KAAK,CAAC,YAAY,CAgGpC"}
|
package/esm/ai/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { useState, useCallback as useCallback2, useEffect } from "react";
|
|
|
3
3
|
import { formatToolsForPlatform, formatResultForPlatform } from "@frontmcp/sdk";
|
|
4
4
|
|
|
5
5
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
6
|
-
import { useContext } from "react";
|
|
6
|
+
import { useContext as useContext2 } from "react";
|
|
7
7
|
|
|
8
8
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
9
9
|
import { createContext } from "react";
|
|
@@ -62,6 +62,7 @@ var DynamicRegistry = class {
|
|
|
62
62
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
63
63
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
64
64
|
listeners = /* @__PURE__ */ new Set();
|
|
65
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
65
66
|
version = 0;
|
|
66
67
|
/**
|
|
67
68
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -140,8 +141,18 @@ var DynamicRegistry = class {
|
|
|
140
141
|
if (existing) {
|
|
141
142
|
existing.read = read;
|
|
142
143
|
this.notify();
|
|
144
|
+
this.resourceListeners.forEach((l) => {
|
|
145
|
+
l(uri);
|
|
146
|
+
});
|
|
143
147
|
}
|
|
144
148
|
}
|
|
149
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
150
|
+
onResourceUpdated(listener) {
|
|
151
|
+
this.resourceListeners.add(listener);
|
|
152
|
+
return () => {
|
|
153
|
+
this.resourceListeners.delete(listener);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
145
156
|
getTools() {
|
|
146
157
|
return [...this.tools.values()];
|
|
147
158
|
}
|
|
@@ -186,18 +197,27 @@ var DynamicRegistry = class {
|
|
|
186
197
|
};
|
|
187
198
|
|
|
188
199
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
201
|
+
function getOrCreateContext() {
|
|
202
|
+
const host = globalThis;
|
|
203
|
+
const existing = host[CONTEXT_KEY];
|
|
204
|
+
if (existing) return existing;
|
|
205
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
206
|
+
const created = createContext({
|
|
207
|
+
name: "default",
|
|
208
|
+
registry: new ComponentRegistry(),
|
|
209
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
210
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
211
|
+
connect: async () => {
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
host[CONTEXT_KEY] = created;
|
|
215
|
+
return created;
|
|
216
|
+
}
|
|
217
|
+
var FrontMcpContext = getOrCreateContext();
|
|
198
218
|
|
|
199
219
|
// libs/react/src/hooks/useServer.ts
|
|
200
|
-
import {
|
|
220
|
+
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
201
221
|
|
|
202
222
|
// libs/react/src/registry/ServerRegistry.ts
|
|
203
223
|
var ServerRegistry = class {
|
|
@@ -292,20 +312,27 @@ var ServerRegistry = class {
|
|
|
292
312
|
this.listeners.forEach((l) => l());
|
|
293
313
|
}
|
|
294
314
|
};
|
|
295
|
-
var
|
|
315
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/serverRegistry");
|
|
316
|
+
function getOrCreateRegistry() {
|
|
317
|
+
const host = globalThis;
|
|
318
|
+
return host[REGISTRY_KEY] ??= new ServerRegistry();
|
|
319
|
+
}
|
|
320
|
+
var serverRegistry = getOrCreateRegistry();
|
|
296
321
|
|
|
297
322
|
// libs/react/src/hooks/useServer.ts
|
|
298
323
|
function useServer(name) {
|
|
324
|
+
const ctx = useContext(FrontMcpContext);
|
|
325
|
+
const serverName = name ?? ctx.name;
|
|
299
326
|
const subscribe = useCallback((cb) => serverRegistry.subscribe(cb), []);
|
|
300
327
|
const getSnapshot = useCallback(() => {
|
|
301
|
-
return serverRegistry.get(
|
|
302
|
-
}, [
|
|
328
|
+
return serverRegistry.get(serverName);
|
|
329
|
+
}, [serverName]);
|
|
303
330
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
304
331
|
}
|
|
305
332
|
|
|
306
333
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
307
334
|
function useResolvedServer(serverName) {
|
|
308
|
-
const ctx =
|
|
335
|
+
const ctx = useContext2(FrontMcpContext);
|
|
309
336
|
const resolvedName = serverName ?? ctx.name;
|
|
310
337
|
const entry = useServer(resolvedName);
|
|
311
338
|
return { entry, name: resolvedName, registry: ctx.registry, connect: ctx.connect };
|
package/esm/api/index.mjs
CHANGED
|
@@ -58,6 +58,7 @@ var DynamicRegistry = class {
|
|
|
58
58
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
59
59
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
60
60
|
listeners = /* @__PURE__ */ new Set();
|
|
61
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
61
62
|
version = 0;
|
|
62
63
|
/**
|
|
63
64
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -136,8 +137,18 @@ var DynamicRegistry = class {
|
|
|
136
137
|
if (existing) {
|
|
137
138
|
existing.read = read;
|
|
138
139
|
this.notify();
|
|
140
|
+
this.resourceListeners.forEach((l) => {
|
|
141
|
+
l(uri);
|
|
142
|
+
});
|
|
139
143
|
}
|
|
140
144
|
}
|
|
145
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
146
|
+
onResourceUpdated(listener) {
|
|
147
|
+
this.resourceListeners.add(listener);
|
|
148
|
+
return () => {
|
|
149
|
+
this.resourceListeners.delete(listener);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
141
152
|
getTools() {
|
|
142
153
|
return [...this.tools.values()];
|
|
143
154
|
}
|
|
@@ -182,15 +193,24 @@ var DynamicRegistry = class {
|
|
|
182
193
|
};
|
|
183
194
|
|
|
184
195
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
197
|
+
function getOrCreateContext() {
|
|
198
|
+
const host = globalThis;
|
|
199
|
+
const existing = host[CONTEXT_KEY];
|
|
200
|
+
if (existing) return existing;
|
|
201
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
202
|
+
const created = createContext({
|
|
203
|
+
name: "default",
|
|
204
|
+
registry: new ComponentRegistry(),
|
|
205
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
206
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
207
|
+
connect: async () => {
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
host[CONTEXT_KEY] = created;
|
|
211
|
+
return created;
|
|
212
|
+
}
|
|
213
|
+
var FrontMcpContext = getOrCreateContext();
|
|
194
214
|
|
|
195
215
|
// libs/react/src/api/createFetchClient.ts
|
|
196
216
|
function createFetchClient(fetchFn) {
|
package/esm/index.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
Plugin,
|
|
27
27
|
FrontMcpPlugin
|
|
28
28
|
} from "@frontmcp/sdk";
|
|
29
|
+
import { z as z2 } from "@frontmcp/sdk";
|
|
29
30
|
import { ToolContext, ResourceContext, PromptContext, ExecutionContextBase } from "@frontmcp/sdk";
|
|
30
31
|
|
|
31
32
|
// libs/react/src/registry/ServerRegistry.ts
|
|
@@ -121,7 +122,12 @@ var ServerRegistry = class {
|
|
|
121
122
|
this.listeners.forEach((l) => l());
|
|
122
123
|
}
|
|
123
124
|
};
|
|
124
|
-
var
|
|
125
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/serverRegistry");
|
|
126
|
+
function getOrCreateRegistry() {
|
|
127
|
+
const host = globalThis;
|
|
128
|
+
return host[REGISTRY_KEY] ??= new ServerRegistry();
|
|
129
|
+
}
|
|
130
|
+
var serverRegistry = getOrCreateRegistry();
|
|
125
131
|
|
|
126
132
|
// libs/react/src/registry/DynamicRegistry.ts
|
|
127
133
|
var DynamicRegistry = class {
|
|
@@ -130,6 +136,7 @@ var DynamicRegistry = class {
|
|
|
130
136
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
131
137
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
132
138
|
listeners = /* @__PURE__ */ new Set();
|
|
139
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
133
140
|
version = 0;
|
|
134
141
|
/**
|
|
135
142
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -208,8 +215,18 @@ var DynamicRegistry = class {
|
|
|
208
215
|
if (existing) {
|
|
209
216
|
existing.read = read;
|
|
210
217
|
this.notify();
|
|
218
|
+
this.resourceListeners.forEach((l) => {
|
|
219
|
+
l(uri);
|
|
220
|
+
});
|
|
211
221
|
}
|
|
212
222
|
}
|
|
223
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
224
|
+
onResourceUpdated(listener) {
|
|
225
|
+
this.resourceListeners.add(listener);
|
|
226
|
+
return () => {
|
|
227
|
+
this.resourceListeners.delete(listener);
|
|
228
|
+
};
|
|
229
|
+
}
|
|
213
230
|
getTools() {
|
|
214
231
|
return [...this.tools.values()];
|
|
215
232
|
}
|
|
@@ -275,6 +292,31 @@ function patchClientWithDynamic(client, dynamicRegistry) {
|
|
|
275
292
|
return originalReadResource(uri);
|
|
276
293
|
};
|
|
277
294
|
}
|
|
295
|
+
if (typeof client.subscribeResource === "function") {
|
|
296
|
+
const originalSubscribe = client.subscribeResource.bind(client);
|
|
297
|
+
client.subscribeResource = async (uri) => {
|
|
298
|
+
if (dynamicRegistry.hasResource(uri)) return;
|
|
299
|
+
return originalSubscribe(uri);
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
if (typeof client.unsubscribeResource === "function") {
|
|
303
|
+
const originalUnsubscribe = client.unsubscribeResource.bind(client);
|
|
304
|
+
client.unsubscribeResource = async (uri) => {
|
|
305
|
+
if (dynamicRegistry.hasResource(uri)) return;
|
|
306
|
+
return originalUnsubscribe(uri);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
if (typeof client.onResourceUpdated === "function") {
|
|
310
|
+
const originalOnUpdated = client.onResourceUpdated.bind(client);
|
|
311
|
+
client.onResourceUpdated = (handler) => {
|
|
312
|
+
const offServer = originalOnUpdated(handler);
|
|
313
|
+
const offDynamic = dynamicRegistry.onResourceUpdated(handler);
|
|
314
|
+
return () => {
|
|
315
|
+
offServer();
|
|
316
|
+
offDynamic();
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
}
|
|
278
320
|
return client;
|
|
279
321
|
}
|
|
280
322
|
function createWrappedServer(base, dynamicRegistry) {
|
|
@@ -419,15 +461,24 @@ function extractName(uri) {
|
|
|
419
461
|
}
|
|
420
462
|
|
|
421
463
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
422
|
-
var
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
464
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
465
|
+
function getOrCreateContext() {
|
|
466
|
+
const host = globalThis;
|
|
467
|
+
const existing = host[CONTEXT_KEY];
|
|
468
|
+
if (existing) return existing;
|
|
469
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
470
|
+
const created = createContext({
|
|
471
|
+
name: "default",
|
|
472
|
+
registry: new ComponentRegistry(),
|
|
473
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
474
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
475
|
+
connect: async () => {
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
host[CONTEXT_KEY] = created;
|
|
479
|
+
return created;
|
|
480
|
+
}
|
|
481
|
+
var FrontMcpContext = getOrCreateContext();
|
|
431
482
|
|
|
432
483
|
// libs/react/src/provider/FrontMcpProvider.tsx
|
|
433
484
|
import React, { useCallback, useEffect as useEffect2, useRef, useMemo } from "react";
|
|
@@ -718,21 +769,23 @@ function FrontMcpProvider({
|
|
|
718
769
|
}
|
|
719
770
|
|
|
720
771
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
721
|
-
import { useContext } from "react";
|
|
772
|
+
import { useContext as useContext2 } from "react";
|
|
722
773
|
|
|
723
774
|
// libs/react/src/hooks/useServer.ts
|
|
724
|
-
import {
|
|
775
|
+
import { useCallback as useCallback2, useContext, useSyncExternalStore } from "react";
|
|
725
776
|
function useServer(name) {
|
|
777
|
+
const ctx = useContext(FrontMcpContext);
|
|
778
|
+
const serverName = name ?? ctx.name;
|
|
726
779
|
const subscribe = useCallback2((cb) => serverRegistry.subscribe(cb), []);
|
|
727
780
|
const getSnapshot = useCallback2(() => {
|
|
728
|
-
return serverRegistry.get(
|
|
729
|
-
}, [
|
|
781
|
+
return serverRegistry.get(serverName);
|
|
782
|
+
}, [serverName]);
|
|
730
783
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
731
784
|
}
|
|
732
785
|
|
|
733
786
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
734
787
|
function useResolvedServer(serverName) {
|
|
735
|
-
const ctx =
|
|
788
|
+
const ctx = useContext2(FrontMcpContext);
|
|
736
789
|
const resolvedName = serverName ?? ctx.name;
|
|
737
790
|
const entry = useServer(resolvedName);
|
|
738
791
|
return { entry, name: resolvedName, registry: ctx.registry, connect: ctx.connect };
|
|
@@ -980,7 +1033,7 @@ function useStoreResource(uri, options) {
|
|
|
980
1033
|
}
|
|
981
1034
|
|
|
982
1035
|
// libs/react/src/hooks/useDynamicTool.ts
|
|
983
|
-
import { useContext as
|
|
1036
|
+
import { useContext as useContext3, useEffect as useEffect6, useMemo as useMemo2, useRef as useRef3 } from "react";
|
|
984
1037
|
|
|
985
1038
|
// libs/react/src/utils/zodToJsonSchema.ts
|
|
986
1039
|
import { forceMaterialize, toJSONSchema } from "@frontmcp/lazy-zod";
|
|
@@ -989,16 +1042,20 @@ function zodToJsonSchema(schema) {
|
|
|
989
1042
|
}
|
|
990
1043
|
|
|
991
1044
|
// libs/react/src/hooks/useDynamicTool.ts
|
|
1045
|
+
function stableKey(value) {
|
|
1046
|
+
try {
|
|
1047
|
+
return JSON.stringify(value) ?? "";
|
|
1048
|
+
} catch {
|
|
1049
|
+
return String(Math.random());
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
992
1052
|
function useDynamicTool(options) {
|
|
993
1053
|
const { name, description, enabled = true } = options;
|
|
994
|
-
const { getDynamicRegistry } =
|
|
1054
|
+
const { getDynamicRegistry } = useContext3(FrontMcpContext);
|
|
995
1055
|
const dynamicRegistry = getDynamicRegistry(options.server);
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
}
|
|
1000
|
-
return options.inputSchema;
|
|
1001
|
-
}, ["schema" in options ? options.schema : void 0, "inputSchema" in options ? options.inputSchema : void 0]);
|
|
1056
|
+
const computedInputSchema = "schema" in options && options.schema ? zodToJsonSchema(options.schema) : options.inputSchema;
|
|
1057
|
+
const inputSchemaKey = stableKey(computedInputSchema);
|
|
1058
|
+
const resolvedInputSchema = useMemo2(() => computedInputSchema, [inputSchemaKey]);
|
|
1002
1059
|
const executeRef = useRef3(options.execute);
|
|
1003
1060
|
executeRef.current = options.execute;
|
|
1004
1061
|
const schemaRef = useRef3("schema" in options && options.schema ? options.schema : null);
|
|
@@ -1041,10 +1098,10 @@ function useDynamicTool(options) {
|
|
|
1041
1098
|
}
|
|
1042
1099
|
|
|
1043
1100
|
// libs/react/src/hooks/useDynamicResource.ts
|
|
1044
|
-
import { useContext as
|
|
1101
|
+
import { useContext as useContext4, useEffect as useEffect7, useRef as useRef4 } from "react";
|
|
1045
1102
|
function useDynamicResource(options) {
|
|
1046
1103
|
const { uri, name, description, mimeType, read, enabled = true } = options;
|
|
1047
|
-
const { getDynamicRegistry } =
|
|
1104
|
+
const { getDynamicRegistry } = useContext4(FrontMcpContext);
|
|
1048
1105
|
const dynamicRegistry = getDynamicRegistry(options.server);
|
|
1049
1106
|
const readRef = useRef4(read);
|
|
1050
1107
|
readRef.current = read;
|
|
@@ -1240,7 +1297,7 @@ function readDomBySelector(selector) {
|
|
|
1240
1297
|
}
|
|
1241
1298
|
|
|
1242
1299
|
// libs/react/src/components/ToolForm.tsx
|
|
1243
|
-
import React3, {
|
|
1300
|
+
import React3, { useCallback as useCallback8, useState as useState5 } from "react";
|
|
1244
1301
|
function ToolForm({
|
|
1245
1302
|
tool: tool2,
|
|
1246
1303
|
onSubmit,
|
|
@@ -1251,12 +1308,19 @@ function ToolForm({
|
|
|
1251
1308
|
const properties = schema["properties"] ?? {};
|
|
1252
1309
|
const required = schema["required"] ?? [];
|
|
1253
1310
|
const [values, setValues] = useState5({});
|
|
1311
|
+
const initialValue = (prop) => {
|
|
1312
|
+
const options = prop["enum"];
|
|
1313
|
+
if (!options) return "";
|
|
1314
|
+
const fallback = prop["default"];
|
|
1315
|
+
return typeof fallback === "string" && options.includes(fallback) ? fallback : options[0] ?? "";
|
|
1316
|
+
};
|
|
1254
1317
|
const handleSubmit = useCallback8(
|
|
1255
1318
|
(e) => {
|
|
1256
1319
|
e.preventDefault();
|
|
1257
1320
|
const args = {};
|
|
1258
1321
|
for (const [key, prop] of Object.entries(properties)) {
|
|
1259
|
-
const
|
|
1322
|
+
const seeded = required.includes(key) || prop["default"] !== void 0;
|
|
1323
|
+
const raw = values[key] ?? (seeded ? initialValue(prop) : "");
|
|
1260
1324
|
if (!required.includes(key) && raw === "") continue;
|
|
1261
1325
|
if (prop["type"] === "number" || prop["type"] === "integer") {
|
|
1262
1326
|
args[key] = Number(raw);
|
|
@@ -1280,7 +1344,7 @@ function ToolForm({
|
|
|
1280
1344
|
const isRequired = required.includes(key);
|
|
1281
1345
|
const enumValues = prop["enum"];
|
|
1282
1346
|
const fieldType = getFieldType(prop);
|
|
1283
|
-
const value = values[key] ??
|
|
1347
|
+
const value = values[key] ?? initialValue(prop);
|
|
1284
1348
|
if (renderField) {
|
|
1285
1349
|
return React3.createElement(
|
|
1286
1350
|
React3.Fragment,
|
|
@@ -1308,7 +1372,7 @@ function ToolForm({
|
|
|
1308
1372
|
"select",
|
|
1309
1373
|
{
|
|
1310
1374
|
id: `field-${key}`,
|
|
1311
|
-
value
|
|
1375
|
+
value,
|
|
1312
1376
|
onChange: (e) => handleChange(key, e.target.value)
|
|
1313
1377
|
},
|
|
1314
1378
|
...enumValues.map((v) => React3.createElement("option", { key: v, value: v }, v))
|
|
@@ -1810,5 +1874,6 @@ export {
|
|
|
1810
1874
|
useResolvedServer,
|
|
1811
1875
|
useServer,
|
|
1812
1876
|
useStoreResource,
|
|
1813
|
-
valtioStore
|
|
1877
|
+
valtioStore,
|
|
1878
|
+
z2 as z
|
|
1814
1879
|
};
|
package/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/react",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
4
4
|
"description": "React hooks, components, and AI SDK integration for FrontMCP",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://docs.agentfront.dev",
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"node": ">=24.0.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@frontmcp/lazy-zod": "1.8.
|
|
90
|
-
"@frontmcp/sdk": "1.8.
|
|
91
|
-
"@frontmcp/utils": "1.8.
|
|
89
|
+
"@frontmcp/lazy-zod": "1.8.7",
|
|
90
|
+
"@frontmcp/sdk": "1.8.7",
|
|
91
|
+
"@frontmcp/utils": "1.8.7",
|
|
92
92
|
"react": "^18.0.0 || ^19.0.0",
|
|
93
93
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
94
94
|
"react-router-dom": "^7.0.0"
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@frontmcp/sdk": "1.8.
|
|
106
|
-
"@frontmcp/utils": "1.8.
|
|
105
|
+
"@frontmcp/sdk": "1.8.7",
|
|
106
|
+
"@frontmcp/utils": "1.8.7"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
109
|
"typescript": "^5.9.3"
|
package/esm/router/index.mjs
CHANGED
|
@@ -137,11 +137,29 @@ var CurrentRouteResource = class _CurrentRouteResource {
|
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
// libs/react/src/router/router.entries.ts
|
|
140
|
+
import { z } from "@frontmcp/lazy-zod";
|
|
141
|
+
import { resource, tool } from "@frontmcp/sdk";
|
|
140
142
|
function createRouterEntries() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
const navigate = tool({
|
|
144
|
+
name: NavigateTool.toolName,
|
|
145
|
+
description: NavigateTool.description,
|
|
146
|
+
inputSchema: {
|
|
147
|
+
path: z.string().describe("The URL path to navigate to"),
|
|
148
|
+
replace: z.boolean().optional().describe("Replace current history entry instead of pushing")
|
|
149
|
+
}
|
|
150
|
+
})((input) => NavigateTool.execute(input));
|
|
151
|
+
const goBack = tool({
|
|
152
|
+
name: GoBackTool.toolName,
|
|
153
|
+
description: GoBackTool.description,
|
|
154
|
+
inputSchema: {}
|
|
155
|
+
})(() => GoBackTool.execute());
|
|
156
|
+
const currentRoute = resource({
|
|
157
|
+
name: CurrentRouteResource.resourceName,
|
|
158
|
+
uri: CurrentRouteResource.uri,
|
|
159
|
+
description: CurrentRouteResource.description,
|
|
160
|
+
mimeType: "application/json"
|
|
161
|
+
})(() => CurrentRouteResource.read());
|
|
162
|
+
return { tools: [navigate, goBack], resources: [currentRoute] };
|
|
145
163
|
}
|
|
146
164
|
export {
|
|
147
165
|
CurrentRouteResource,
|
package/esm/state/index.mjs
CHANGED
|
@@ -58,6 +58,7 @@ var DynamicRegistry = class {
|
|
|
58
58
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
59
59
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
60
60
|
listeners = /* @__PURE__ */ new Set();
|
|
61
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
61
62
|
version = 0;
|
|
62
63
|
/**
|
|
63
64
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -136,8 +137,18 @@ var DynamicRegistry = class {
|
|
|
136
137
|
if (existing) {
|
|
137
138
|
existing.read = read;
|
|
138
139
|
this.notify();
|
|
140
|
+
this.resourceListeners.forEach((l) => {
|
|
141
|
+
l(uri);
|
|
142
|
+
});
|
|
139
143
|
}
|
|
140
144
|
}
|
|
145
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
146
|
+
onResourceUpdated(listener) {
|
|
147
|
+
this.resourceListeners.add(listener);
|
|
148
|
+
return () => {
|
|
149
|
+
this.resourceListeners.delete(listener);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
141
152
|
getTools() {
|
|
142
153
|
return [...this.tools.values()];
|
|
143
154
|
}
|
|
@@ -182,15 +193,24 @@ var DynamicRegistry = class {
|
|
|
182
193
|
};
|
|
183
194
|
|
|
184
195
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
197
|
+
function getOrCreateContext() {
|
|
198
|
+
const host = globalThis;
|
|
199
|
+
const existing = host[CONTEXT_KEY];
|
|
200
|
+
if (existing) return existing;
|
|
201
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
202
|
+
const created = createContext({
|
|
203
|
+
name: "default",
|
|
204
|
+
registry: new ComponentRegistry(),
|
|
205
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
206
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
207
|
+
connect: async () => {
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
host[CONTEXT_KEY] = created;
|
|
211
|
+
return created;
|
|
212
|
+
}
|
|
213
|
+
var FrontMcpContext = getOrCreateContext();
|
|
194
214
|
|
|
195
215
|
// libs/react/src/state/useStoreResource.ts
|
|
196
216
|
var VALID_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDynamicTool.d.ts","sourceRoot":"","sources":["../../src/hooks/useDynamicTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAOpD,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,MAAM,EAAE,CAAC,CAAC;IACV,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,wEAAwE;IACxE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACvD,sEAAsE;IACtE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,WAAW,+BAA+B;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACpE,sEAAsE;IACtE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC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MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,IAC/F,2BAA2B,CAAC,CAAC,CAAC,GAC9B,+BAA+B,CAAC;AAUpC,wBAAgB,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,IAAI,CA+D5G"}
|
package/hooks/useServer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* useServer — access a named server from the shared ServerRegistry singleton.
|
|
3
3
|
*
|
|
4
4
|
* Uses useSyncExternalStore for tear-free reads. When no name is given,
|
|
5
|
-
* returns the 'default'
|
|
5
|
+
* returns the entry of the nearest FrontMcpProvider (`'default'` outside one).
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
* }
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
import type
|
|
15
|
+
import { type ServerEntry } from '../registry/ServerRegistry';
|
|
16
16
|
export declare function useServer(name?: string): ServerEntry | undefined;
|
|
17
17
|
//# sourceMappingURL=useServer.d.ts.map
|
package/hooks/useServer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useServer.d.ts","sourceRoot":"","sources":["../../src/hooks/useServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"useServer.d.ts","sourceRoot":"","sources":["../../src/hooks/useServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9E,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAUhE"}
|
package/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { connect, connectOpenAI, connectClaude, connectLangChain, connectVercelA
|
|
|
15
15
|
export type { CreateConfig, DirectMcpServer, DirectClient, DirectCallOptions, DirectAuthContext } from '@frontmcp/sdk';
|
|
16
16
|
export type { ConnectOptions, LLMPlatform } from '@frontmcp/sdk';
|
|
17
17
|
export { Tool, FrontMcpTool, tool, frontMcpTool, Resource, FrontMcpResource, resource, frontMcpResource, ResourceTemplate, FrontMcpResourceTemplate, resourceTemplate, frontMcpResourceTemplate, Prompt, FrontMcpPrompt, prompt, frontMcpPrompt, App, FrontMcpApp, FrontMcp, Adapter, FrontMcpAdapter, Plugin, FrontMcpPlugin, } from '@frontmcp/sdk';
|
|
18
|
+
export { z } from '@frontmcp/sdk';
|
|
18
19
|
export { ToolContext, ResourceContext, PromptContext, ExecutionContextBase } from '@frontmcp/sdk';
|
|
19
20
|
export type { GetPromptResult, ReadResourceResult, CallToolResult, ListToolsResult, ListResourcesResult, ListResourceTemplatesResult, ListPromptsResult, TextContent, ImageContent, PromptMessage, } from '@frontmcp/sdk';
|
|
20
21
|
export type { FrontMcpContextValue, ResolvedServer, FrontMcpStatus, ToolInfo, ResourceInfo, ResourceTemplateInfo, PromptInfo, ToolState, ResourceState, PromptState, UseCallToolOptions, UseCallToolReturn, ComponentNode, FieldRenderProps, DynamicToolDef, DynamicResourceDef, StoreAdapter, McpColumnDef, } from './types';
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EA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e,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGxD,OAAO,EACL,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACvH,YAAY,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,+BAA+B,EAC/B,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGxE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/index.js
CHANGED
|
@@ -37,7 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
ComponentRegistry: () => ComponentRegistry,
|
|
38
38
|
DynamicRegistry: () => DynamicRegistry,
|
|
39
39
|
DynamicRenderer: () => DynamicRenderer,
|
|
40
|
-
ExecutionContextBase: () =>
|
|
40
|
+
ExecutionContextBase: () => import_sdk5.ExecutionContextBase,
|
|
41
41
|
FrontMcp: () => import_sdk3.FrontMcp,
|
|
42
42
|
FrontMcpAdapter: () => import_sdk3.FrontMcpAdapter,
|
|
43
43
|
FrontMcpApp: () => import_sdk3.FrontMcpApp,
|
|
@@ -51,15 +51,15 @@ __export(index_exports, {
|
|
|
51
51
|
OutputDisplay: () => OutputDisplay,
|
|
52
52
|
Plugin: () => import_sdk3.Plugin,
|
|
53
53
|
Prompt: () => import_sdk3.Prompt,
|
|
54
|
-
PromptContext: () =>
|
|
54
|
+
PromptContext: () => import_sdk5.PromptContext,
|
|
55
55
|
PromptForm: () => PromptForm,
|
|
56
56
|
Resource: () => import_sdk3.Resource,
|
|
57
|
-
ResourceContext: () =>
|
|
57
|
+
ResourceContext: () => import_sdk5.ResourceContext,
|
|
58
58
|
ResourceTemplate: () => import_sdk3.ResourceTemplate,
|
|
59
59
|
ResourceViewer: () => ResourceViewer,
|
|
60
60
|
ServerRegistry: () => ServerRegistry,
|
|
61
61
|
Tool: () => import_sdk3.Tool,
|
|
62
|
-
ToolContext: () =>
|
|
62
|
+
ToolContext: () => import_sdk5.ToolContext,
|
|
63
63
|
ToolForm: () => ToolForm,
|
|
64
64
|
clearCreateCache: () => import_sdk.clearCreateCache,
|
|
65
65
|
connect: () => import_sdk2.connect,
|
|
@@ -96,13 +96,15 @@ __export(index_exports, {
|
|
|
96
96
|
useResolvedServer: () => useResolvedServer,
|
|
97
97
|
useServer: () => useServer,
|
|
98
98
|
useStoreResource: () => useStoreResource,
|
|
99
|
-
valtioStore: () => valtioStore
|
|
99
|
+
valtioStore: () => valtioStore,
|
|
100
|
+
z: () => import_sdk4.z
|
|
100
101
|
});
|
|
101
102
|
module.exports = __toCommonJS(index_exports);
|
|
102
103
|
var import_sdk = require("@frontmcp/sdk");
|
|
103
104
|
var import_sdk2 = require("@frontmcp/sdk");
|
|
104
105
|
var import_sdk3 = require("@frontmcp/sdk");
|
|
105
106
|
var import_sdk4 = require("@frontmcp/sdk");
|
|
107
|
+
var import_sdk5 = require("@frontmcp/sdk");
|
|
106
108
|
|
|
107
109
|
// libs/react/src/registry/ServerRegistry.ts
|
|
108
110
|
var ServerRegistry = class {
|
|
@@ -197,7 +199,12 @@ var ServerRegistry = class {
|
|
|
197
199
|
this.listeners.forEach((l) => l());
|
|
198
200
|
}
|
|
199
201
|
};
|
|
200
|
-
var
|
|
202
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/serverRegistry");
|
|
203
|
+
function getOrCreateRegistry() {
|
|
204
|
+
const host = globalThis;
|
|
205
|
+
return host[REGISTRY_KEY] ??= new ServerRegistry();
|
|
206
|
+
}
|
|
207
|
+
var serverRegistry = getOrCreateRegistry();
|
|
201
208
|
|
|
202
209
|
// libs/react/src/registry/DynamicRegistry.ts
|
|
203
210
|
var DynamicRegistry = class {
|
|
@@ -206,6 +213,7 @@ var DynamicRegistry = class {
|
|
|
206
213
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
207
214
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
208
215
|
listeners = /* @__PURE__ */ new Set();
|
|
216
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
209
217
|
version = 0;
|
|
210
218
|
/**
|
|
211
219
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -284,8 +292,18 @@ var DynamicRegistry = class {
|
|
|
284
292
|
if (existing) {
|
|
285
293
|
existing.read = read;
|
|
286
294
|
this.notify();
|
|
295
|
+
this.resourceListeners.forEach((l) => {
|
|
296
|
+
l(uri);
|
|
297
|
+
});
|
|
287
298
|
}
|
|
288
299
|
}
|
|
300
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
301
|
+
onResourceUpdated(listener) {
|
|
302
|
+
this.resourceListeners.add(listener);
|
|
303
|
+
return () => {
|
|
304
|
+
this.resourceListeners.delete(listener);
|
|
305
|
+
};
|
|
306
|
+
}
|
|
289
307
|
getTools() {
|
|
290
308
|
return [...this.tools.values()];
|
|
291
309
|
}
|
|
@@ -351,6 +369,31 @@ function patchClientWithDynamic(client, dynamicRegistry) {
|
|
|
351
369
|
return originalReadResource(uri);
|
|
352
370
|
};
|
|
353
371
|
}
|
|
372
|
+
if (typeof client.subscribeResource === "function") {
|
|
373
|
+
const originalSubscribe = client.subscribeResource.bind(client);
|
|
374
|
+
client.subscribeResource = async (uri) => {
|
|
375
|
+
if (dynamicRegistry.hasResource(uri)) return;
|
|
376
|
+
return originalSubscribe(uri);
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if (typeof client.unsubscribeResource === "function") {
|
|
380
|
+
const originalUnsubscribe = client.unsubscribeResource.bind(client);
|
|
381
|
+
client.unsubscribeResource = async (uri) => {
|
|
382
|
+
if (dynamicRegistry.hasResource(uri)) return;
|
|
383
|
+
return originalUnsubscribe(uri);
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if (typeof client.onResourceUpdated === "function") {
|
|
387
|
+
const originalOnUpdated = client.onResourceUpdated.bind(client);
|
|
388
|
+
client.onResourceUpdated = (handler) => {
|
|
389
|
+
const offServer = originalOnUpdated(handler);
|
|
390
|
+
const offDynamic = dynamicRegistry.onResourceUpdated(handler);
|
|
391
|
+
return () => {
|
|
392
|
+
offServer();
|
|
393
|
+
offDynamic();
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
}
|
|
354
397
|
return client;
|
|
355
398
|
}
|
|
356
399
|
function createWrappedServer(base, dynamicRegistry) {
|
|
@@ -495,15 +538,24 @@ function extractName(uri) {
|
|
|
495
538
|
}
|
|
496
539
|
|
|
497
540
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
498
|
-
var
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
541
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
542
|
+
function getOrCreateContext() {
|
|
543
|
+
const host = globalThis;
|
|
544
|
+
const existing = host[CONTEXT_KEY];
|
|
545
|
+
if (existing) return existing;
|
|
546
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
547
|
+
const created = (0, import_react.createContext)({
|
|
548
|
+
name: "default",
|
|
549
|
+
registry: new ComponentRegistry(),
|
|
550
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
551
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
552
|
+
connect: async () => {
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
host[CONTEXT_KEY] = created;
|
|
556
|
+
return created;
|
|
557
|
+
}
|
|
558
|
+
var FrontMcpContext = getOrCreateContext();
|
|
507
559
|
|
|
508
560
|
// libs/react/src/provider/FrontMcpProvider.tsx
|
|
509
561
|
var import_react3 = __toESM(require("react"));
|
|
@@ -799,10 +851,12 @@ var import_react5 = require("react");
|
|
|
799
851
|
// libs/react/src/hooks/useServer.ts
|
|
800
852
|
var import_react4 = require("react");
|
|
801
853
|
function useServer(name) {
|
|
854
|
+
const ctx = (0, import_react4.useContext)(FrontMcpContext);
|
|
855
|
+
const serverName = name ?? ctx.name;
|
|
802
856
|
const subscribe = (0, import_react4.useCallback)((cb) => serverRegistry.subscribe(cb), []);
|
|
803
857
|
const getSnapshot = (0, import_react4.useCallback)(() => {
|
|
804
|
-
return serverRegistry.get(
|
|
805
|
-
}, [
|
|
858
|
+
return serverRegistry.get(serverName);
|
|
859
|
+
}, [serverName]);
|
|
806
860
|
return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
807
861
|
}
|
|
808
862
|
|
|
@@ -1065,16 +1119,20 @@ function zodToJsonSchema(schema) {
|
|
|
1065
1119
|
}
|
|
1066
1120
|
|
|
1067
1121
|
// libs/react/src/hooks/useDynamicTool.ts
|
|
1122
|
+
function stableKey(value) {
|
|
1123
|
+
try {
|
|
1124
|
+
return JSON.stringify(value) ?? "";
|
|
1125
|
+
} catch {
|
|
1126
|
+
return String(Math.random());
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1068
1129
|
function useDynamicTool(options) {
|
|
1069
1130
|
const { name, description, enabled = true } = options;
|
|
1070
1131
|
const { getDynamicRegistry } = (0, import_react10.useContext)(FrontMcpContext);
|
|
1071
1132
|
const dynamicRegistry = getDynamicRegistry(options.server);
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1076
|
-
return options.inputSchema;
|
|
1077
|
-
}, ["schema" in options ? options.schema : void 0, "inputSchema" in options ? options.inputSchema : void 0]);
|
|
1133
|
+
const computedInputSchema = "schema" in options && options.schema ? zodToJsonSchema(options.schema) : options.inputSchema;
|
|
1134
|
+
const inputSchemaKey = stableKey(computedInputSchema);
|
|
1135
|
+
const resolvedInputSchema = (0, import_react10.useMemo)(() => computedInputSchema, [inputSchemaKey]);
|
|
1078
1136
|
const executeRef = (0, import_react10.useRef)(options.execute);
|
|
1079
1137
|
executeRef.current = options.execute;
|
|
1080
1138
|
const schemaRef = (0, import_react10.useRef)("schema" in options && options.schema ? options.schema : null);
|
|
@@ -1327,12 +1385,19 @@ function ToolForm({
|
|
|
1327
1385
|
const properties = schema["properties"] ?? {};
|
|
1328
1386
|
const required = schema["required"] ?? [];
|
|
1329
1387
|
const [values, setValues] = (0, import_react14.useState)({});
|
|
1388
|
+
const initialValue = (prop) => {
|
|
1389
|
+
const options = prop["enum"];
|
|
1390
|
+
if (!options) return "";
|
|
1391
|
+
const fallback = prop["default"];
|
|
1392
|
+
return typeof fallback === "string" && options.includes(fallback) ? fallback : options[0] ?? "";
|
|
1393
|
+
};
|
|
1330
1394
|
const handleSubmit = (0, import_react14.useCallback)(
|
|
1331
1395
|
(e) => {
|
|
1332
1396
|
e.preventDefault();
|
|
1333
1397
|
const args = {};
|
|
1334
1398
|
for (const [key, prop] of Object.entries(properties)) {
|
|
1335
|
-
const
|
|
1399
|
+
const seeded = required.includes(key) || prop["default"] !== void 0;
|
|
1400
|
+
const raw = values[key] ?? (seeded ? initialValue(prop) : "");
|
|
1336
1401
|
if (!required.includes(key) && raw === "") continue;
|
|
1337
1402
|
if (prop["type"] === "number" || prop["type"] === "integer") {
|
|
1338
1403
|
args[key] = Number(raw);
|
|
@@ -1356,7 +1421,7 @@ function ToolForm({
|
|
|
1356
1421
|
const isRequired = required.includes(key);
|
|
1357
1422
|
const enumValues = prop["enum"];
|
|
1358
1423
|
const fieldType = getFieldType(prop);
|
|
1359
|
-
const value = values[key] ??
|
|
1424
|
+
const value = values[key] ?? initialValue(prop);
|
|
1360
1425
|
if (renderField) {
|
|
1361
1426
|
return import_react14.default.createElement(
|
|
1362
1427
|
import_react14.default.Fragment,
|
|
@@ -1384,7 +1449,7 @@ function ToolForm({
|
|
|
1384
1449
|
"select",
|
|
1385
1450
|
{
|
|
1386
1451
|
id: `field-${key}`,
|
|
1387
|
-
value
|
|
1452
|
+
value,
|
|
1388
1453
|
onChange: (e) => handleChange(key, e.target.value)
|
|
1389
1454
|
},
|
|
1390
1455
|
...enumValues.map((v) => import_react14.default.createElement("option", { key: v, value: v }, v))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/react",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
4
4
|
"description": "React hooks, components, and AI SDK integration for FrontMCP",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://docs.agentfront.dev",
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"node": ">=24.0.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@frontmcp/lazy-zod": "1.8.
|
|
90
|
-
"@frontmcp/sdk": "1.8.
|
|
91
|
-
"@frontmcp/utils": "1.8.
|
|
89
|
+
"@frontmcp/lazy-zod": "1.8.7",
|
|
90
|
+
"@frontmcp/sdk": "1.8.7",
|
|
91
|
+
"@frontmcp/utils": "1.8.7",
|
|
92
92
|
"react": "^18.0.0 || ^19.0.0",
|
|
93
93
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
94
94
|
"react-router-dom": "^7.0.0"
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@frontmcp/sdk": "1.8.
|
|
106
|
-
"@frontmcp/utils": "1.8.
|
|
105
|
+
"@frontmcp/sdk": "1.8.7",
|
|
106
|
+
"@frontmcp/utils": "1.8.7"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
109
|
"typescript": "^5.9.3"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React context for FrontMCP.
|
|
3
3
|
*/
|
|
4
|
+
import { type Context } from 'react';
|
|
4
5
|
import type { FrontMcpContextValue } from '../types';
|
|
5
|
-
export declare const FrontMcpContext:
|
|
6
|
+
export declare const FrontMcpContext: Context<FrontMcpContextValue>;
|
|
6
7
|
//# sourceMappingURL=FrontMcpContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontMcpContext.d.ts","sourceRoot":"","sources":["../../src/provider/FrontMcpContext.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"FrontMcpContext.d.ts","sourceRoot":"","sources":["../../src/provider/FrontMcpContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,OAAO,CAAC;AAIpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AA2BrD,eAAO,MAAM,eAAe,+BAAuB,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Uses the same listener/version pattern as ServerRegistry for
|
|
10
10
|
* useSyncExternalStore compatibility.
|
|
11
11
|
*/
|
|
12
|
-
import type {
|
|
12
|
+
import type { DynamicResourceDef, DynamicToolDef } from '../types';
|
|
13
13
|
type Listener = () => void;
|
|
14
14
|
export declare class DynamicRegistry {
|
|
15
15
|
private tools;
|
|
@@ -17,6 +17,7 @@ export declare class DynamicRegistry {
|
|
|
17
17
|
private toolRefCounts;
|
|
18
18
|
private resourceRefCounts;
|
|
19
19
|
private listeners;
|
|
20
|
+
private resourceListeners;
|
|
20
21
|
private version;
|
|
21
22
|
/**
|
|
22
23
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -40,6 +41,8 @@ export declare class DynamicRegistry {
|
|
|
40
41
|
updateToolExecute(name: string, execute: DynamicToolDef['execute']): void;
|
|
41
42
|
/** Update the read function for an existing resource and notify subscribers. */
|
|
42
43
|
updateResourceRead(uri: string, read: DynamicResourceDef['read']): void;
|
|
44
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
45
|
+
onResourceUpdated(listener: (uri: string) => void): () => void;
|
|
43
46
|
getTools(): DynamicToolDef[];
|
|
44
47
|
getResources(): DynamicResourceDef[];
|
|
45
48
|
findTool(name: string): DynamicToolDef | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/DynamicRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"DynamicRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/DynamicRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEnE,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,SAAS,CAAyC;IAC1D,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,iBAAiB,CAA6B;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FrontMcpStatus,
|
|
10
|
+
import type { DirectClient, DirectMcpServer } from '@frontmcp/sdk';
|
|
11
|
+
import type { FrontMcpStatus, PromptInfo, ResourceInfo, ResourceTemplateInfo, ToolInfo } from '../types';
|
|
12
12
|
type Listener = () => void;
|
|
13
13
|
export interface ServerEntry {
|
|
14
14
|
server: DirectMcpServer;
|
|
@@ -37,7 +37,7 @@ export declare class ServerRegistry {
|
|
|
37
37
|
getVersion(): number;
|
|
38
38
|
private notify;
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
40
|
+
/** Page-wide singleton — shared across all components and all entry points. */
|
|
41
41
|
export declare const serverRegistry: ServerRegistry;
|
|
42
42
|
export {};
|
|
43
43
|
//# sourceMappingURL=ServerRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/ServerRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ServerRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/ServerRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzG,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;IAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,OAAO,CAAK;IAEpB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI;IAcrD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAI1C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,IAAI,IAAI,MAAM,EAAE;IAIV,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAuC5C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAQzD,KAAK,IAAI,IAAI;IAKb,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI;IAOzC,UAAU,IAAI,MAAM;IAIpB,OAAO,CAAC,MAAM;CAIf;AAYD,+EAA+E;AAC/E,eAAO,MAAM,cAAc,gBAAwB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWrappedServer.d.ts","sourceRoot":"","sources":["../../src/registry/createWrappedServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createWrappedServer.d.ts","sourceRoot":"","sources":["../../src/registry/createWrappedServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAGV,eAAe,EAGhB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AA8DzD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,eAAe,CA4H5G"}
|
package/router/index.js
CHANGED
|
@@ -172,9 +172,27 @@ var CurrentRouteResource = class _CurrentRouteResource {
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
// libs/react/src/router/router.entries.ts
|
|
175
|
+
var import_lazy_zod = require("@frontmcp/lazy-zod");
|
|
176
|
+
var import_sdk = require("@frontmcp/sdk");
|
|
175
177
|
function createRouterEntries() {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
const navigate = (0, import_sdk.tool)({
|
|
179
|
+
name: NavigateTool.toolName,
|
|
180
|
+
description: NavigateTool.description,
|
|
181
|
+
inputSchema: {
|
|
182
|
+
path: import_lazy_zod.z.string().describe("The URL path to navigate to"),
|
|
183
|
+
replace: import_lazy_zod.z.boolean().optional().describe("Replace current history entry instead of pushing")
|
|
184
|
+
}
|
|
185
|
+
})((input) => NavigateTool.execute(input));
|
|
186
|
+
const goBack = (0, import_sdk.tool)({
|
|
187
|
+
name: GoBackTool.toolName,
|
|
188
|
+
description: GoBackTool.description,
|
|
189
|
+
inputSchema: {}
|
|
190
|
+
})(() => GoBackTool.execute());
|
|
191
|
+
const currentRoute = (0, import_sdk.resource)({
|
|
192
|
+
name: CurrentRouteResource.resourceName,
|
|
193
|
+
uri: CurrentRouteResource.uri,
|
|
194
|
+
description: CurrentRouteResource.description,
|
|
195
|
+
mimeType: "application/json"
|
|
196
|
+
})(() => CurrentRouteResource.read());
|
|
197
|
+
return { tools: [navigate, goBack], resources: [currentRoute] };
|
|
180
198
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* createRouterEntries — factory that returns tool/resource entries for easy
|
|
3
3
|
* spreading into `create()` config.
|
|
4
4
|
*
|
|
5
|
+
* The entries are SDK function-style tools/resources, so `create()` accepts
|
|
6
|
+
* them directly.
|
|
7
|
+
*
|
|
5
8
|
* @example
|
|
6
9
|
* ```ts
|
|
7
10
|
* const { tools, resources } = createRouterEntries();
|
|
@@ -12,12 +15,13 @@
|
|
|
12
15
|
* });
|
|
13
16
|
* ```
|
|
14
17
|
*/
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
import { resource, tool } from '@frontmcp/sdk';
|
|
19
|
+
type ToolEntry = ReturnType<ReturnType<typeof tool>>;
|
|
20
|
+
type ResourceEntry = ReturnType<ReturnType<typeof resource>>;
|
|
18
21
|
export interface RouterEntries {
|
|
19
|
-
tools: [
|
|
20
|
-
resources: [
|
|
22
|
+
tools: [ToolEntry, ToolEntry];
|
|
23
|
+
resources: [ResourceEntry];
|
|
21
24
|
}
|
|
22
25
|
export declare function createRouterEntries(): RouterEntries;
|
|
26
|
+
export {};
|
|
23
27
|
//# sourceMappingURL=router.entries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.entries.d.ts","sourceRoot":"","sources":["../../src/router/router.entries.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"router.entries.d.ts","sourceRoot":"","sources":["../../src/router/router.entries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM/C,KAAK,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;AACrD,KAAK,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC;AAE7D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9B,SAAS,EAAE,CAAC,aAAa,CAAC,CAAC;CAC5B;AAED,wBAAgB,mBAAmB,IAAI,aAAa,CAwBnD"}
|
package/state/index.js
CHANGED
|
@@ -89,6 +89,7 @@ var DynamicRegistry = class {
|
|
|
89
89
|
toolRefCounts = /* @__PURE__ */ new Map();
|
|
90
90
|
resourceRefCounts = /* @__PURE__ */ new Map();
|
|
91
91
|
listeners = /* @__PURE__ */ new Set();
|
|
92
|
+
resourceListeners = /* @__PURE__ */ new Set();
|
|
92
93
|
version = 0;
|
|
93
94
|
/**
|
|
94
95
|
* Register a dynamic tool. Returns an unregister function
|
|
@@ -167,8 +168,18 @@ var DynamicRegistry = class {
|
|
|
167
168
|
if (existing) {
|
|
168
169
|
existing.read = read;
|
|
169
170
|
this.notify();
|
|
171
|
+
this.resourceListeners.forEach((l) => {
|
|
172
|
+
l(uri);
|
|
173
|
+
});
|
|
170
174
|
}
|
|
171
175
|
}
|
|
176
|
+
/** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
|
|
177
|
+
onResourceUpdated(listener) {
|
|
178
|
+
this.resourceListeners.add(listener);
|
|
179
|
+
return () => {
|
|
180
|
+
this.resourceListeners.delete(listener);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
172
183
|
getTools() {
|
|
173
184
|
return [...this.tools.values()];
|
|
174
185
|
}
|
|
@@ -213,15 +224,24 @@ var DynamicRegistry = class {
|
|
|
213
224
|
};
|
|
214
225
|
|
|
215
226
|
// libs/react/src/provider/FrontMcpContext.ts
|
|
216
|
-
var
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
227
|
+
var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("@frontmcp/react/FrontMcpContext");
|
|
228
|
+
function getOrCreateContext() {
|
|
229
|
+
const host = globalThis;
|
|
230
|
+
const existing = host[CONTEXT_KEY];
|
|
231
|
+
if (existing) return existing;
|
|
232
|
+
const defaultDynamicRegistry = new DynamicRegistry();
|
|
233
|
+
const created = (0, import_react.createContext)({
|
|
234
|
+
name: "default",
|
|
235
|
+
registry: new ComponentRegistry(),
|
|
236
|
+
dynamicRegistry: defaultDynamicRegistry,
|
|
237
|
+
getDynamicRegistry: () => defaultDynamicRegistry,
|
|
238
|
+
connect: async () => {
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
host[CONTEXT_KEY] = created;
|
|
242
|
+
return created;
|
|
243
|
+
}
|
|
244
|
+
var FrontMcpContext = getOrCreateContext();
|
|
225
245
|
|
|
226
246
|
// libs/react/src/state/useStoreResource.ts
|
|
227
247
|
var VALID_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|