@frontmcp/react 1.8.7 → 1.9.1-rc.1

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/README.md CHANGED
@@ -169,6 +169,8 @@ useDynamicTool({
169
169
 
170
170
  Also supports raw JSON Schema via `inputSchema` for backward compatibility.
171
171
 
172
+ The provider registers each dynamic tool with the server as a real tool (`server.registerTool()`), so it runs through the server's flows (plugin hooks, authorities, `availableWhen`) and every client sees it — including in-browser agents through `@frontmcp/plugin-webmcp`. A name a server tool already has is reported through the provider's `onError` instead of shadowing that tool. On a server with several apps, say which app dynamic tools join with the provider's `dynamicToolApps` (by server name) or a tool's own `app` option.
173
+
172
174
  ## State Management
173
175
 
174
176
  `@frontmcp/react/state` exposes your application state as MCP resources and actions as tools.
package/ai/index.js CHANGED
@@ -97,16 +97,16 @@ var DynamicRegistry = class {
97
97
  * suitable for useEffect cleanup.
98
98
  *
99
99
  * Multiple registrations of the same name are ref-counted:
100
- * subsequent registrations update the definition but the tool
101
- * is only removed when every registrant has unregistered.
100
+ * subsequent registrations replace the definition (and notify, so
101
+ * the server registration follows the new description, schema or
102
+ * availability) but the tool is only removed when every registrant
103
+ * has unregistered.
102
104
  */
103
105
  registerTool(def) {
104
106
  const existing = this.toolRefCounts.get(def.name) ?? 0;
105
107
  this.toolRefCounts.set(def.name, existing + 1);
106
108
  this.tools.set(def.name, def);
107
- if (existing === 0) {
108
- this.notify();
109
- }
109
+ this.notify();
110
110
  let called = false;
111
111
  return () => {
112
112
  if (called) return;
@@ -248,11 +248,22 @@ var FrontMcpContext = getOrCreateContext();
248
248
  var import_react2 = require("react");
249
249
 
250
250
  // libs/react/src/registry/ServerRegistry.ts
251
+ function sameListing(a, b) {
252
+ if (a === b) return true;
253
+ if (a.length !== b.length) return false;
254
+ try {
255
+ return JSON.stringify(a) === JSON.stringify(b);
256
+ } catch {
257
+ return false;
258
+ }
259
+ }
251
260
  var ServerRegistry = class {
252
261
  entries = /* @__PURE__ */ new Map();
253
262
  listeners = /* @__PURE__ */ new Set();
263
+ toolListWatches = /* @__PURE__ */ new Map();
254
264
  version = 0;
255
265
  register(name, server) {
266
+ this.stopToolListWatch(name);
256
267
  this.entries.set(name, {
257
268
  server,
258
269
  client: null,
@@ -266,6 +277,7 @@ var ServerRegistry = class {
266
277
  this.notify();
267
278
  }
268
279
  unregister(name) {
280
+ this.stopToolListWatch(name);
269
281
  this.entries.delete(name);
270
282
  this.notify();
271
283
  }
@@ -304,6 +316,7 @@ var ServerRegistry = class {
304
316
  };
305
317
  this.entries.set(name, connected);
306
318
  this.notify();
319
+ this.watchToolList(name, client);
307
320
  return client;
308
321
  } catch (err) {
309
322
  const error = err instanceof Error ? err : new Error(String(err));
@@ -315,6 +328,32 @@ var ServerRegistry = class {
315
328
  async connectAll() {
316
329
  await Promise.all(this.list().map((name) => this.connect(name)));
317
330
  }
331
+ /**
332
+ * Keep `name`'s tool list current: re-list through `client` now, and whenever the server
333
+ * announces `notifications/tools/list_changed` (a dynamic tool registered or removed, say). The
334
+ * first listing catches a change made before the watch began. Only the newest listing is applied,
335
+ * and only while `client` is still the entry's client.
336
+ */
337
+ watchToolList(name, client) {
338
+ this.stopToolListWatch(name);
339
+ if (typeof client.onNotification !== "function") return;
340
+ let latest = 0;
341
+ const relist = () => {
342
+ const listing = ++latest;
343
+ client.listTools().then((tools) => {
344
+ const entry = this.entries.get(name);
345
+ if (listing !== latest || !entry || entry.client !== client) return;
346
+ if (sameListing(entry.tools, tools)) return;
347
+ this.update(name, { tools });
348
+ }).catch(() => {
349
+ });
350
+ };
351
+ const stop = client.onNotification((notification) => {
352
+ if (notification.method === "notifications/tools/list_changed") relist();
353
+ });
354
+ this.toolListWatches.set(name, stop);
355
+ relist();
356
+ }
318
357
  update(name, partial) {
319
358
  const entry = this.entries.get(name);
320
359
  if (entry) {
@@ -323,6 +362,7 @@ var ServerRegistry = class {
323
362
  }
324
363
  }
325
364
  clear() {
365
+ for (const name of [...this.toolListWatches.keys()]) this.stopToolListWatch(name);
326
366
  this.entries.clear();
327
367
  this.notify();
328
368
  }
@@ -335,6 +375,12 @@ var ServerRegistry = class {
335
375
  getVersion() {
336
376
  return this.version;
337
377
  }
378
+ stopToolListWatch(name) {
379
+ const stop = this.toolListWatches.get(name);
380
+ if (!stop) return;
381
+ this.toolListWatches.delete(name);
382
+ stop();
383
+ }
338
384
  notify() {
339
385
  this.version++;
340
386
  this.listeners.forEach((l) => l());
@@ -1,6 +1,30 @@
1
1
  /**
2
2
  * Types for API client integration.
3
3
  */
4
+ /** Where an operation parameter goes in the request (the OpenAPI `in` field). */
5
+ export type ApiParameterLocation = 'path' | 'query' | 'header' | 'cookie';
6
+ /** How an array or object argument is written into the request (the OpenAPI `style` field). */
7
+ export type ApiParameterStyle = 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject' | 'simple';
8
+ /** An operation parameter: the argument `name`, where the request carries it, and how. */
9
+ export interface ApiParameter {
10
+ /** Argument name, as it appears in `inputSchema.properties`. */
11
+ name: string;
12
+ /**
13
+ * `'query'` arguments are sent in the query string and `'header'` arguments as request headers.
14
+ * `'path'` arguments fill the `{name}` placeholders of `path` (as every placeholder is filled);
15
+ * `'cookie'` arguments are not sent.
16
+ */
17
+ in: ApiParameterLocation;
18
+ /**
19
+ * How an array or object value is serialized, as in OpenAPI. A query argument defaults to
20
+ * `'form'` (an array repeats the name, an object sends each property as its own parameter) and
21
+ * may be `'spaceDelimited'`, `'pipeDelimited'` or `'deepObject'` (`name[key]=value`). A header
22
+ * argument is always `'simple'`: its items joined with commas.
23
+ */
24
+ style?: ApiParameterStyle;
25
+ /** The OpenAPI `explode` flag: `true` by default for `'form'`, `false` for the other styles. */
26
+ explode?: boolean;
27
+ }
4
28
  export interface ApiOperation {
5
29
  /** Unique operation identifier (becomes part of the tool name). */
6
30
  operationId: string;
@@ -12,6 +36,11 @@ export interface ApiOperation {
12
36
  path: string;
13
37
  /** JSON Schema for the operation's input. */
14
38
  inputSchema: Record<string, unknown>;
39
+ /**
40
+ * Where each argument goes. `parseOpenApiSpec` fills this from the spec's `parameters`. An
41
+ * argument without an entry here is sent only when it is a `{param}` of `path` or the `body`.
42
+ */
43
+ parameters?: ApiParameter[];
15
44
  }
16
45
  /** Configuration for a single HTTP request. */
17
46
  export interface HttpRequestConfig {
@@ -1 +1 @@
1
- {"version":3,"file":"api.types.d.ts","sourceRoot":"","sources":["../../src/api/api.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,uDAAuD;IACvD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClE,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"api.types.d.ts","sourceRoot":"","sources":["../../src/api/api.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,iFAAiF;AACjF,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1E,+FAA+F;AAC/F,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,GAAG,eAAe,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEtG,0FAA0F;AAC1F,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,EAAE,EAAE,oBAAoB,CAAC;IACzB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,gGAAgG;IAChG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;CAC7B;AAED,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,uDAAuD;IACvD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClE,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/api/index.d.ts CHANGED
@@ -8,5 +8,5 @@
8
8
  export { useApiClient } from './useApiClient';
9
9
  export { parseOpenApiSpec } from './parseOpenApiSpec';
10
10
  export { createFetchClient } from './createFetchClient';
11
- export type { ApiOperation, ApiClientOptions, HttpClient, HttpRequestConfig, HttpResponse } from './api.types';
11
+ export type { ApiOperation, ApiParameter, ApiParameterLocation, ApiParameterStyle, ApiClientOptions, HttpClient, HttpRequestConfig, HttpResponse, } from './api.types';
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC"}
package/api/index.js CHANGED
@@ -93,16 +93,16 @@ var DynamicRegistry = class {
93
93
  * suitable for useEffect cleanup.
94
94
  *
95
95
  * Multiple registrations of the same name are ref-counted:
96
- * subsequent registrations update the definition but the tool
97
- * is only removed when every registrant has unregistered.
96
+ * subsequent registrations replace the definition (and notify, so
97
+ * the server registration follows the new description, schema or
98
+ * availability) but the tool is only removed when every registrant
99
+ * has unregistered.
98
100
  */
99
101
  registerTool(def) {
100
102
  const existing = this.toolRefCounts.get(def.name) ?? 0;
101
103
  this.toolRefCounts.set(def.name, existing + 1);
102
104
  this.tools.set(def.name, def);
103
- if (existing === 0) {
104
- this.notify();
105
- }
105
+ this.notify();
106
106
  let called = false;
107
107
  return () => {
108
108
  if (called) return;
@@ -280,29 +280,91 @@ function interpolatePath(path, params) {
280
280
  return value != null ? encodeURIComponent(String(value)) : `{${key}}`;
281
281
  });
282
282
  }
283
+ function paramText(value) {
284
+ return typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
285
+ }
286
+ function isRecord(value) {
287
+ return typeof value === "object" && value !== null && !Array.isArray(value);
288
+ }
289
+ var QUERY_DELIMITERS = { spaceDelimited: "%20", pipeDelimited: "%7C" };
290
+ function serializedItems(value, explode, encode) {
291
+ if (Array.isArray(value)) return value.map((item) => encode(paramText(item)));
292
+ return Object.entries(value).flatMap(
293
+ ([key, item]) => explode ? [`${encode(key)}=${encode(paramText(item))}`] : [encode(key), encode(paramText(item))]
294
+ );
295
+ }
296
+ function queryPairs(param, value) {
297
+ const style = param.style ?? "form";
298
+ const explode = param.explode ?? style === "form";
299
+ const name = encodeURIComponent(param.name);
300
+ if (style === "deepObject" && isRecord(value)) {
301
+ return Object.entries(value).map(
302
+ ([key, item]) => `${encodeURIComponent(`${param.name}[${key}]`)}=${encodeURIComponent(paramText(item))}`
303
+ );
304
+ }
305
+ if (!Array.isArray(value) && !isRecord(value)) return [`${name}=${encodeURIComponent(paramText(value))}`];
306
+ const items = serializedItems(value, explode, encodeURIComponent);
307
+ if (!explode) return [`${name}=${items.join(QUERY_DELIMITERS[style] ?? ",")}`];
308
+ return Array.isArray(value) ? items.map((item) => `${name}=${item}`) : items;
309
+ }
310
+ function buildRequestUrl(baseUrl, op, args) {
311
+ const pairs = [];
312
+ for (const param of op.parameters ?? []) {
313
+ if (param.in !== "query") continue;
314
+ const value = args[param.name];
315
+ if (value === void 0 || value === null) continue;
316
+ pairs.push(...queryPairs(param, value));
317
+ }
318
+ const url = baseUrl + interpolatePath(op.path, args);
319
+ return pairs.length > 0 ? `${url}${url.includes("?") ? "&" : "?"}${pairs.join("&")}` : url;
320
+ }
321
+ function headerText(param, value) {
322
+ if (!Array.isArray(value) && !isRecord(value)) return paramText(value);
323
+ return serializedItems(value, param.explode ?? false, (text) => text).join(",");
324
+ }
325
+ function headerParams(op, args) {
326
+ const headers = {};
327
+ for (const param of op.parameters ?? []) {
328
+ if (param.in !== "header") continue;
329
+ const value = args[param.name];
330
+ if (value !== void 0 && value !== null) headers[param.name] = headerText(param, value);
331
+ }
332
+ return headers;
333
+ }
334
+ function registrationKey(operations) {
335
+ return JSON.stringify(
336
+ operations.map((op) => [op.operationId, op.description, op.method, op.path, op.inputSchema, op.parameters ?? null])
337
+ );
338
+ }
283
339
  function useApiClient(options) {
284
340
  const { baseUrl, operations, headers, prefix = "api", client, fetch: customFetch } = options;
285
341
  const { getDynamicRegistry } = (0, import_react2.useContext)(FrontMcpContext);
286
342
  const dynamicRegistry = getDynamicRegistry(options.server);
343
+ const baseUrlRef = (0, import_react2.useRef)(baseUrl);
287
344
  const headersRef = (0, import_react2.useRef)(headers);
288
- headersRef.current = headers;
345
+ const operationsRef = (0, import_react2.useRef)(operations);
289
346
  const clientRef = (0, import_react2.useRef)(client ?? createFetchClient(customFetch));
290
- clientRef.current = client ?? createFetchClient(customFetch);
291
347
  (0, import_react2.useEffect)(() => {
292
- const cleanups = [];
293
- for (const op of operations) {
294
- const toolName = `${prefix}_${op.operationId}`;
348
+ baseUrlRef.current = baseUrl;
349
+ headersRef.current = headers;
350
+ operationsRef.current = operations;
351
+ clientRef.current = client ?? createFetchClient(customFetch);
352
+ }, [baseUrl, headers, operations, client, customFetch]);
353
+ const key = registrationKey(operations);
354
+ (0, import_react2.useEffect)(() => {
355
+ const cleanups = operationsRef.current.map((registered) => {
295
356
  const execute = async (args) => {
357
+ const op = operationsRef.current.find((o) => o.operationId === registered.operationId) ?? registered;
296
358
  const resolvedHeaders = {
297
359
  "Content-Type": "application/json",
298
- ...typeof headersRef.current === "function" ? headersRef.current() : headersRef.current ?? {}
360
+ ...typeof headersRef.current === "function" ? headersRef.current() : headersRef.current ?? {},
361
+ ...headerParams(op, args)
299
362
  };
300
- const url = baseUrl + interpolatePath(op.path, args);
301
363
  const body = args["body"];
302
364
  const method = op.method;
303
365
  const requestConfig = {
304
366
  method,
305
- url,
367
+ url: buildRequestUrl(baseUrlRef.current, op, args),
306
368
  headers: resolvedHeaders
307
369
  };
308
370
  if (body !== void 0 && method !== "GET" && method !== "HEAD") {
@@ -323,25 +385,37 @@ function useApiClient(options) {
323
385
  isError: response.status >= 400
324
386
  };
325
387
  };
326
- cleanups.push(
327
- dynamicRegistry.registerTool({
328
- name: toolName,
329
- description: op.description,
330
- inputSchema: op.inputSchema,
331
- execute
332
- })
333
- );
334
- }
388
+ return dynamicRegistry.registerTool({
389
+ name: `${prefix}_${registered.operationId}`,
390
+ description: registered.description,
391
+ inputSchema: registered.inputSchema,
392
+ execute
393
+ });
394
+ });
335
395
  return () => {
336
396
  cleanups.forEach((fn) => {
337
397
  fn();
338
398
  });
339
399
  };
340
- }, [dynamicRegistry, baseUrl, operations, prefix, client, customFetch]);
400
+ }, [dynamicRegistry, prefix, key]);
341
401
  }
342
402
 
343
403
  // libs/react/src/api/parseOpenApiSpec.ts
344
404
  var HTTP_METHODS = ["get", "post", "put", "delete", "patch", "options", "head"];
405
+ var PARAMETER_LOCATIONS = ["path", "query", "header", "cookie"];
406
+ var PARAMETER_STYLES = [
407
+ "form",
408
+ "spaceDelimited",
409
+ "pipeDelimited",
410
+ "deepObject",
411
+ "simple"
412
+ ];
413
+ function toApiParameter(param) {
414
+ const parameter = { name: param.name, in: param.in };
415
+ if (PARAMETER_STYLES.includes(param.style)) parameter.style = param.style;
416
+ if (typeof param.explode === "boolean") parameter.explode = param.explode;
417
+ return parameter;
418
+ }
345
419
  function parseOpenApiSpec(spec) {
346
420
  const paths = spec["paths"];
347
421
  if (!paths) return [];
@@ -381,6 +455,7 @@ function parseOpenApiSpec(spec) {
381
455
  }
382
456
  }
383
457
  const propertyLocations = /* @__PURE__ */ new Map();
458
+ const parameters = [];
384
459
  for (const param of paramMap.values()) {
385
460
  if (param.name === "__proto__" || param.name === "constructor" || param.name === "prototype") continue;
386
461
  const existingIn = propertyLocations.get(param.name);
@@ -395,6 +470,7 @@ function parseOpenApiSpec(spec) {
395
470
  description: param.description
396
471
  };
397
472
  if (param.required) required.push(param.name);
473
+ if (PARAMETER_LOCATIONS.includes(param.in)) parameters.push(toApiParameter(param));
398
474
  }
399
475
  const requestBody = operation["requestBody"];
400
476
  if (requestBody) {
@@ -415,7 +491,14 @@ function parseOpenApiSpec(spec) {
415
491
  if (required.length > 0) {
416
492
  inputSchema["required"] = required;
417
493
  }
418
- operations.push({ operationId, description, method: method.toUpperCase(), path, inputSchema });
494
+ operations.push({
495
+ operationId,
496
+ description,
497
+ method: method.toUpperCase(),
498
+ path,
499
+ inputSchema,
500
+ ...parameters.length > 0 ? { parameters } : {}
501
+ });
419
502
  }
420
503
  }
421
504
  return operations;
@@ -1 +1 @@
1
- {"version":3,"file":"parseOpenApiSpec.d.ts","sourceRoot":"","sources":["../../src/api/parseOpenApiSpec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,EAAE,CAmG9E"}
1
+ {"version":3,"file":"parseOpenApiSpec.d.ts","sourceRoot":"","sources":["../../src/api/parseOpenApiSpec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAyD,MAAM,aAAa,CAAC;AA8BvG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,EAAE,CA4G9E"}
@@ -3,6 +3,11 @@
3
3
  *
4
4
  * Each operation becomes a dynamic tool that makes an HTTP request
5
5
  * using an injected HttpClient, a custom fetch, or globalThis.fetch.
6
+ *
7
+ * Options may be written inline: the tools are registered again only when the
8
+ * `prefix`, the target server, or what an operation declares (its id, description,
9
+ * method, path, input schema or parameters) changes. `baseUrl`, `headers`,
10
+ * `client` and `fetch` are read when a tool runs, from the latest committed render.
6
11
  */
7
12
  import type { ApiClientOptions } from './api.types';
8
13
  export declare function useApiClient(options: ApiClientOptions): void;
@@ -1 +1 @@
1
- {"version":3,"file":"useApiClient.d.ts","sourceRoot":"","sources":["../../src/api/useApiClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAiC,MAAM,aAAa,CAAC;AAUnF,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAuE5D"}
1
+ {"version":3,"file":"useApiClient.d.ts","sourceRoot":"","sources":["../../src/api/useApiClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,KAAK,EACV,gBAAgB,EAMjB,MAAM,aAAa,CAAC;AAyFrB,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CA0E5D"}
@@ -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;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"}
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,CAoGpC"}
package/esm/ai/index.mjs CHANGED
@@ -69,16 +69,16 @@ var DynamicRegistry = class {
69
69
  * suitable for useEffect cleanup.
70
70
  *
71
71
  * Multiple registrations of the same name are ref-counted:
72
- * subsequent registrations update the definition but the tool
73
- * is only removed when every registrant has unregistered.
72
+ * subsequent registrations replace the definition (and notify, so
73
+ * the server registration follows the new description, schema or
74
+ * availability) but the tool is only removed when every registrant
75
+ * has unregistered.
74
76
  */
75
77
  registerTool(def) {
76
78
  const existing = this.toolRefCounts.get(def.name) ?? 0;
77
79
  this.toolRefCounts.set(def.name, existing + 1);
78
80
  this.tools.set(def.name, def);
79
- if (existing === 0) {
80
- this.notify();
81
- }
81
+ this.notify();
82
82
  let called = false;
83
83
  return () => {
84
84
  if (called) return;
@@ -220,11 +220,22 @@ var FrontMcpContext = getOrCreateContext();
220
220
  import { useCallback, useContext, useSyncExternalStore } from "react";
221
221
 
222
222
  // libs/react/src/registry/ServerRegistry.ts
223
+ function sameListing(a, b) {
224
+ if (a === b) return true;
225
+ if (a.length !== b.length) return false;
226
+ try {
227
+ return JSON.stringify(a) === JSON.stringify(b);
228
+ } catch {
229
+ return false;
230
+ }
231
+ }
223
232
  var ServerRegistry = class {
224
233
  entries = /* @__PURE__ */ new Map();
225
234
  listeners = /* @__PURE__ */ new Set();
235
+ toolListWatches = /* @__PURE__ */ new Map();
226
236
  version = 0;
227
237
  register(name, server) {
238
+ this.stopToolListWatch(name);
228
239
  this.entries.set(name, {
229
240
  server,
230
241
  client: null,
@@ -238,6 +249,7 @@ var ServerRegistry = class {
238
249
  this.notify();
239
250
  }
240
251
  unregister(name) {
252
+ this.stopToolListWatch(name);
241
253
  this.entries.delete(name);
242
254
  this.notify();
243
255
  }
@@ -276,6 +288,7 @@ var ServerRegistry = class {
276
288
  };
277
289
  this.entries.set(name, connected);
278
290
  this.notify();
291
+ this.watchToolList(name, client);
279
292
  return client;
280
293
  } catch (err) {
281
294
  const error = err instanceof Error ? err : new Error(String(err));
@@ -287,6 +300,32 @@ var ServerRegistry = class {
287
300
  async connectAll() {
288
301
  await Promise.all(this.list().map((name) => this.connect(name)));
289
302
  }
303
+ /**
304
+ * Keep `name`'s tool list current: re-list through `client` now, and whenever the server
305
+ * announces `notifications/tools/list_changed` (a dynamic tool registered or removed, say). The
306
+ * first listing catches a change made before the watch began. Only the newest listing is applied,
307
+ * and only while `client` is still the entry's client.
308
+ */
309
+ watchToolList(name, client) {
310
+ this.stopToolListWatch(name);
311
+ if (typeof client.onNotification !== "function") return;
312
+ let latest = 0;
313
+ const relist = () => {
314
+ const listing = ++latest;
315
+ client.listTools().then((tools) => {
316
+ const entry = this.entries.get(name);
317
+ if (listing !== latest || !entry || entry.client !== client) return;
318
+ if (sameListing(entry.tools, tools)) return;
319
+ this.update(name, { tools });
320
+ }).catch(() => {
321
+ });
322
+ };
323
+ const stop = client.onNotification((notification) => {
324
+ if (notification.method === "notifications/tools/list_changed") relist();
325
+ });
326
+ this.toolListWatches.set(name, stop);
327
+ relist();
328
+ }
290
329
  update(name, partial) {
291
330
  const entry = this.entries.get(name);
292
331
  if (entry) {
@@ -295,6 +334,7 @@ var ServerRegistry = class {
295
334
  }
296
335
  }
297
336
  clear() {
337
+ for (const name of [...this.toolListWatches.keys()]) this.stopToolListWatch(name);
298
338
  this.entries.clear();
299
339
  this.notify();
300
340
  }
@@ -307,6 +347,12 @@ var ServerRegistry = class {
307
347
  getVersion() {
308
348
  return this.version;
309
349
  }
350
+ stopToolListWatch(name) {
351
+ const stop = this.toolListWatches.get(name);
352
+ if (!stop) return;
353
+ this.toolListWatches.delete(name);
354
+ stop();
355
+ }
310
356
  notify() {
311
357
  this.version++;
312
358
  this.listeners.forEach((l) => l());