@frontmcp/react 1.8.6 → 1.9.0

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.
Files changed (47) hide show
  1. package/README.md +2 -0
  2. package/ai/index.js +90 -17
  3. package/api/api.types.d.ts +29 -0
  4. package/api/api.types.d.ts.map +1 -1
  5. package/api/index.d.ts +1 -1
  6. package/api/index.d.ts.map +1 -1
  7. package/api/index.js +136 -33
  8. package/api/parseOpenApiSpec.d.ts.map +1 -1
  9. package/api/useApiClient.d.ts +5 -0
  10. package/api/useApiClient.d.ts.map +1 -1
  11. package/components/ToolForm.d.ts +1 -1
  12. package/components/ToolForm.d.ts.map +1 -1
  13. package/esm/ai/index.mjs +93 -20
  14. package/esm/api/index.mjs +136 -33
  15. package/esm/index.mjs +298 -85
  16. package/esm/package.json +6 -6
  17. package/esm/router/index.mjs +22 -4
  18. package/esm/state/index.mjs +113 -98
  19. package/hooks/useDynamicTool.d.ts +19 -3
  20. package/hooks/useDynamicTool.d.ts.map +1 -1
  21. package/hooks/useServer.d.ts +2 -2
  22. package/hooks/useServer.d.ts.map +1 -1
  23. package/index.d.ts +1 -0
  24. package/index.d.ts.map +1 -1
  25. package/index.js +293 -80
  26. package/package.json +6 -6
  27. package/provider/FrontMcpContext.d.ts +2 -1
  28. package/provider/FrontMcpContext.d.ts.map +1 -1
  29. package/provider/FrontMcpProvider.d.ts +12 -6
  30. package/provider/FrontMcpProvider.d.ts.map +1 -1
  31. package/registry/DynamicRegistry.d.ts +12 -6
  32. package/registry/DynamicRegistry.d.ts.map +1 -1
  33. package/registry/ServerRegistry.d.ts +14 -3
  34. package/registry/ServerRegistry.d.ts.map +1 -1
  35. package/registry/bindDynamicTools.d.ts +29 -0
  36. package/registry/bindDynamicTools.d.ts.map +1 -0
  37. package/registry/createWrappedServer.d.ts +6 -5
  38. package/registry/createWrappedServer.d.ts.map +1 -1
  39. package/router/index.js +22 -4
  40. package/router/router.entries.d.ts +9 -5
  41. package/router/router.entries.d.ts.map +1 -1
  42. package/state/index.js +112 -97
  43. package/state/useReduxResource.d.ts.map +1 -1
  44. package/state/useStoreResource.d.ts +6 -0
  45. package/state/useStoreResource.d.ts.map +1 -1
  46. package/types.d.ts +10 -1
  47. package/types.d.ts.map +1 -1
@@ -7,13 +7,14 @@
7
7
  * 4. Optionally auto-connects a client on mount (default: true)
8
8
  * 5. Registers all servers into the shared ServerRegistry singleton
9
9
  * 6. Creates a DynamicRegistry for dynamic tool/resource registration
10
- * 7. Wraps the server to overlay dynamic entries on list/call operations
11
- * 8. All state (status, tools, etc.) lives in the ServerRegistry — context
10
+ * 7. Mirrors dynamic tools into each server as real tools (bindDynamicTools), and keeps the
11
+ * listed tools current from the server's `notifications/tools/list_changed`
12
+ * 8. Wraps the server to overlay dynamic resources on list/read operations
13
+ * 9. All state (status, tools, etc.) lives in the ServerRegistry — context
12
14
  * carries only `name`, `registry`, `dynamicRegistry`, and `connect`.
13
15
  */
14
- import React from 'react';
15
- import type { ComponentType } from 'react';
16
- import type { DirectMcpServer, DirectClient } from '@frontmcp/sdk';
16
+ import React, { type ComponentType } from 'react';
17
+ import type { DirectClient, DirectMcpServer } from '@frontmcp/sdk';
17
18
  import type { StoreAdapter } from '../types';
18
19
  export interface FrontMcpProviderProps {
19
20
  /** Logical name for the primary server (defaults to 'default') */
@@ -25,10 +26,15 @@ export interface FrontMcpProviderProps {
25
26
  components?: Record<string, ComponentType<Record<string, unknown>>>;
26
27
  /** Store adapters to register at the provider level (reduxStore, valtioStore, createStore). */
27
28
  stores?: StoreAdapter[];
29
+ /**
30
+ * Server app that dynamic tools join, by server name (the primary server goes by `name`). Needed
31
+ * only for a server with more than one local app; a tool's own `app` option takes precedence.
32
+ */
33
+ dynamicToolApps?: Record<string, string>;
28
34
  autoConnect?: boolean;
29
35
  children: React.ReactNode;
30
36
  onConnected?: (client: DirectClient) => void;
31
37
  onError?: (error: Error) => void;
32
38
  }
33
- export declare function FrontMcpProvider({ name: nameProp, server, servers, components, stores, autoConnect, children, onConnected, onError, }: FrontMcpProviderProps): React.ReactElement;
39
+ export declare function FrontMcpProvider({ name: nameProp, server, servers, components, stores, dynamicToolApps, autoConnect, children, onConnected, onError, }: FrontMcpProviderProps): React.ReactElement;
34
40
  //# sourceMappingURL=FrontMcpProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrontMcpProvider.d.ts","sourceRoot":"","sources":["../../src/provider/FrontMcpProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAKnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAK7C,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,MAAM,EAAE,eAAe,CAAC;IACxB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpE,+FAA+F;IAC/F,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC7C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EAAE,QAAQ,EACd,MAAM,EACN,OAAO,EACP,UAAU,EACV,MA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W,EACX,OAAO,GACR,EAAE,qBAAqB,GAAG,KAAK,CAAC,YAAY,CA8O5C"}
@@ -2,14 +2,15 @@
2
2
  * DynamicRegistry — React-side registry for tools and resources that
3
3
  * components register on mount and unregister on unmount.
4
4
  *
5
- * Operates as an overlay on the base DirectMcpServer: dynamic entries
6
- * are merged into listTools/listResources and checked first on
7
- * callTool/readResource.
5
+ * Tools are mirrored into the server as real tools by `bindDynamicTools`
6
+ * (the provider binds each server's registry), so they run through the
7
+ * server's flows. Resources stay an overlay on the base DirectMcpServer:
8
+ * they are merged into listResources and checked first on readResource.
8
9
  *
9
10
  * Uses the same listener/version pattern as ServerRegistry for
10
11
  * useSyncExternalStore compatibility.
11
12
  */
12
- import type { DynamicToolDef, DynamicResourceDef } from '../types';
13
+ import type { DynamicResourceDef, DynamicToolDef } from '../types';
13
14
  type Listener = () => void;
14
15
  export declare class DynamicRegistry {
15
16
  private tools;
@@ -17,14 +18,17 @@ export declare class DynamicRegistry {
17
18
  private toolRefCounts;
18
19
  private resourceRefCounts;
19
20
  private listeners;
21
+ private resourceListeners;
20
22
  private version;
21
23
  /**
22
24
  * Register a dynamic tool. Returns an unregister function
23
25
  * suitable for useEffect cleanup.
24
26
  *
25
27
  * Multiple registrations of the same name are ref-counted:
26
- * subsequent registrations update the definition but the tool
27
- * is only removed when every registrant has unregistered.
28
+ * subsequent registrations replace the definition (and notify, so
29
+ * the server registration follows the new description, schema or
30
+ * availability) but the tool is only removed when every registrant
31
+ * has unregistered.
28
32
  */
29
33
  registerTool(def: DynamicToolDef): () => void;
30
34
  unregisterTool(name: string): void;
@@ -40,6 +44,8 @@ export declare class DynamicRegistry {
40
44
  updateToolExecute(name: string, execute: DynamicToolDef['execute']): void;
41
45
  /** Update the read function for an existing resource and notify subscribers. */
42
46
  updateResourceRead(uri: string, read: DynamicResourceDef['read']): void;
47
+ /** Listen for changes to a dynamic resource's content (the in-page `resources/updated`). */
48
+ onResourceUpdated(listener: (uri: string) => void): () => void;
43
49
  getTools(): DynamicToolDef[];
44
50
  getResources(): DynamicResourceDef[];
45
51
  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,cAAc,EAAE,kBAAkB,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;IACtD,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,OAAO,CAAK;IAEpB;;;;;;;OAOG;IACH,YAAY,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,IAAI;IAe7C,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAYlC;;;;;OAKG;IACH,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,IAAI;IAerD,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAYrC,uFAAuF;IACvF,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,IAAI;IAOzE,gFAAgF;IAChF,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAAG,IAAI;IAQvE,QAAQ,IAAI,cAAc,EAAE;IAI5B,YAAY,IAAI,kBAAkB,EAAE;IAIpC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIlD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIzD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAA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AI;IAO9D,QAAQ,IAAI,cAAc,EAAE;IAI5B,YAAY,IAAI,kBAAkB,EAAE;IAIpC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIlD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIzD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI;IAOzC,UAAU,IAAI,MAAM;IAIpB,KAAK,IAAI,IAAI;IASb,OAAO,CAAC,MAAM;CAMf"}
@@ -7,9 +7,11 @@
7
7
  *
8
8
  * Integrates with React via useSyncExternalStore for tear-free reads.
9
9
  */
10
- import type { DirectMcpServer, DirectClient } from '@frontmcp/sdk';
11
- import type { FrontMcpStatus, ToolInfo, ResourceInfo, ResourceTemplateInfo, PromptInfo } from '../types';
10
+ import type { DirectClient, DirectMcpServer } from '@frontmcp/sdk';
11
+ import type { FrontMcpStatus, PromptInfo, ResourceInfo, ResourceTemplateInfo, ToolInfo } from '../types';
12
12
  type Listener = () => void;
13
+ /** Whether two tool / resource listings are the same, entry for entry. */
14
+ export declare function sameListing(a: readonly unknown[], b: readonly unknown[]): boolean;
13
15
  export interface ServerEntry {
14
16
  server: DirectMcpServer;
15
17
  client: DirectClient | null;
@@ -23,6 +25,7 @@ export interface ServerEntry {
23
25
  export declare class ServerRegistry {
24
26
  private entries;
25
27
  private listeners;
28
+ private toolListWatches;
26
29
  private version;
27
30
  register(name: string, server: DirectMcpServer): void;
28
31
  unregister(name: string): void;
@@ -31,13 +34,21 @@ export declare class ServerRegistry {
31
34
  list(): string[];
32
35
  connect(name: string): Promise<DirectClient>;
33
36
  connectAll(): Promise<void>;
37
+ /**
38
+ * Keep `name`'s tool list current: re-list through `client` now, and whenever the server
39
+ * announces `notifications/tools/list_changed` (a dynamic tool registered or removed, say). The
40
+ * first listing catches a change made before the watch began. Only the newest listing is applied,
41
+ * and only while `client` is still the entry's client.
42
+ */
43
+ watchToolList(name: string, client: DirectClient): void;
34
44
  update(name: string, partial: Partial<ServerEntry>): void;
35
45
  clear(): void;
36
46
  subscribe(listener: Listener): () => void;
37
47
  getVersion(): number;
48
+ private stopToolListWatch;
38
49
  private notify;
39
50
  }
40
- /** Module-scoped singleton — shared across all components. */
51
+ /** Page-wide singleton — shared across all components and all entry points. */
41
52
  export declare const serverRegistry: ServerRegistry;
42
53
  export {};
43
54
  //# 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,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,oBAAoB,EAAE,UAAU,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;IAcr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E,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,eAAe,CAAiC;IACxD,OAAO,CAAC,OAAO,CAAK;IAEpB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI;IAerD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM9B,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;IAwC5C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI;IA0BvD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAQzD,KAAK,IAAI,IAAI;IAMb,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI;IAOzC,UAAU,IAAI,MAAM;IAIpB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,MAAM;CAIf;AAYD,+EAA+E;AAC/E,eAAO,MAAM,cAAc,gBAAwB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * bindDynamicTools — mirrors a DynamicRegistry's tools into a DirectMcpServer as real server tools.
3
+ *
4
+ * Components register tools in the DynamicRegistry (ref-counted, latest `execute` kept in the
5
+ * registry). This binder registers each one with `server.registerTool()`, so the tool is listed by
6
+ * the server, runs through its `tools:call-tool` flow (hooks, authorities, quota, `availableWhen`),
7
+ * reaches every client (including WebMCP) and is announced with `notifications/tools/list_changed`.
8
+ *
9
+ * Changes are reconciled on a microtask, so the register → unregister → register churn of React
10
+ * StrictMode settles into a single change on the server.
11
+ */
12
+ import type { DirectMcpServer } from '@frontmcp/sdk';
13
+ import type { DynamicRegistry } from './DynamicRegistry';
14
+ export interface BindDynamicToolsOptions {
15
+ /** Called when the server refuses a tool (a name conflict, a name over 64 characters, ...). */
16
+ onError?: (error: Error, toolName: string) => void;
17
+ /**
18
+ * Id of the server app that tools join when they don't name one (`DynamicToolDef.app`). Needed
19
+ * only for a server with more than one local app.
20
+ */
21
+ app?: string;
22
+ }
23
+ /**
24
+ * Keep `server`'s runtime tools in step with `registry`'s tools.
25
+ *
26
+ * @returns A function that stops mirroring and unregisters every mirrored tool
27
+ */
28
+ export declare function bindDynamicTools(registry: DynamicRegistry, server: DirectMcpServer, options?: BindDynamicToolsOptions): () => void;
29
+ //# sourceMappingURL=bindDynamicTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindDynamicTools.d.ts","sourceRoot":"","sources":["../../src/registry/bindDynamicTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAkB,eAAe,EAAyB,MAAM,eAAe,CAAC;AAG5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,uBAAuB;IACtC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA2BD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,uBAA4B,GACpC,MAAM,IAAI,CAsGZ"}
@@ -1,14 +1,15 @@
1
1
  /**
2
- * createWrappedServer — wraps a DirectMcpServer with a DynamicRegistry overlay.
2
+ * createWrappedServer — wraps a DirectMcpServer with a DynamicRegistry resource overlay.
3
3
  *
4
- * Intercepts listTools/callTool/listResources/readResource to merge
5
- * dynamically registered entries. All other methods delegate directly.
4
+ * Intercepts listResources/readResource to merge dynamically registered resources. Dynamic tools
5
+ * are not overlaid: `bindDynamicTools` registers them with the server as real tools, so tool
6
+ * listing and calls go straight to the server's flows. All other methods delegate directly.
6
7
  */
7
8
  import type { DirectMcpServer } from '@frontmcp/sdk';
8
9
  import type { DynamicRegistry } from './DynamicRegistry';
9
10
  /**
10
- * Create a wrapped DirectMcpServer that overlays dynamic tools and resources.
11
- * Dynamic entries take precedence over base server entries with the same name/uri.
11
+ * Create a wrapped DirectMcpServer that overlays dynamic resources.
12
+ * Dynamic resources take precedence over base server resources with the same uri.
12
13
  */
13
14
  export declare function createWrappedServer(base: DirectMcpServer, dynamicRegistry: DynamicRegistry): DirectMcpServer;
14
15
  //# sourceMappingURL=createWrappedServer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createWrappedServer.d.ts","sourceRoot":"","sources":["../../src/registry/createWrappedServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,eAAe,EAKhB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAiCzD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,eAAe,CA4H5G"}
1
+ {"version":3,"file":"createWrappedServer.d.ts","sourceRoot":"","sources":["../../src/registry/createWrappedServer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAIV,eAAe,EAEhB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAmDzD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,eAAe,CAyG5G"}
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
- return {
177
- tools: [NavigateTool, GoBackTool],
178
- resources: [CurrentRouteResource]
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 { NavigateTool } from './navigate.tool';
16
- import { GoBackTool } from './go-back.tool';
17
- import { CurrentRouteResource } from './current-route.resource';
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: [typeof NavigateTool, typeof GoBackTool];
20
- resources: [typeof CurrentRouteResource];
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;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,CAAC,OAAO,YAAY,EAAE,OAAO,UAAU,CAAC,CAAC;IAChD,SAAS,EAAE,CAAC,OAAO,oBAAoB,CAAC,CAAC;CAC1C;AAED,wBAAgB,mBAAmB,IAAI,aAAa,CAKnD"}
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,22 +89,23 @@ 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
95
96
  * suitable for useEffect cleanup.
96
97
  *
97
98
  * Multiple registrations of the same name are ref-counted:
98
- * subsequent registrations update the definition but the tool
99
- * is only removed when every registrant has unregistered.
99
+ * subsequent registrations replace the definition (and notify, so
100
+ * the server registration follows the new description, schema or
101
+ * availability) but the tool is only removed when every registrant
102
+ * has unregistered.
100
103
  */
101
104
  registerTool(def) {
102
105
  const existing = this.toolRefCounts.get(def.name) ?? 0;
103
106
  this.toolRefCounts.set(def.name, existing + 1);
104
107
  this.tools.set(def.name, def);
105
- if (existing === 0) {
106
- this.notify();
107
- }
108
+ this.notify();
108
109
  let called = false;
109
110
  return () => {
110
111
  if (called) return;
@@ -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,129 +224,131 @@ var DynamicRegistry = class {
213
224
  };
214
225
 
215
226
  // libs/react/src/provider/FrontMcpContext.ts
216
- var defaultDynamicRegistry = new DynamicRegistry();
217
- var FrontMcpContext = (0, import_react.createContext)({
218
- name: "default",
219
- registry: new ComponentRegistry(),
220
- dynamicRegistry: defaultDynamicRegistry,
221
- getDynamicRegistry: () => defaultDynamicRegistry,
222
- connect: async () => {
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_-]+$/;
248
+ function keysOf(map, kind) {
249
+ if (!map) return "[]";
250
+ const keys = Object.keys(map);
251
+ if (kind === "selector") {
252
+ for (const key of keys) {
253
+ if (!key || !VALID_NAME_RE.test(key)) {
254
+ throw new Error(`useStoreResource: invalid selector key "${key}". Keys must match ${VALID_NAME_RE}.`);
255
+ }
256
+ }
257
+ }
258
+ return JSON.stringify(keys.sort());
259
+ }
260
+ function parseKeys(keys) {
261
+ return JSON.parse(keys);
262
+ }
263
+ function jsonResource(uri, value) {
264
+ return { contents: [{ uri, mimeType: "application/json", text: JSON.stringify(value ?? null) }] };
265
+ }
228
266
  function useStoreResource(options) {
229
- const { name, getState, subscribe, selectors, actions } = options;
267
+ const { name, subscribe } = options;
230
268
  const { getDynamicRegistry } = (0, import_react2.useContext)(FrontMcpContext);
231
269
  const dynamicRegistry = getDynamicRegistry(options.server);
232
270
  if (!name || !VALID_NAME_RE.test(name)) {
233
271
  throw new Error(`useStoreResource: invalid store name "${name}". Names must match ${VALID_NAME_RE}.`);
234
272
  }
235
- const getStateRef = (0, import_react2.useRef)(getState);
236
- getStateRef.current = getState;
237
- const readState = (0, import_react2.useCallback)(
238
- async () => ({
239
- contents: [
240
- {
241
- uri: `state://${name}`,
242
- mimeType: "application/json",
243
- text: JSON.stringify(getStateRef.current() ?? null)
244
- }
245
- ]
246
- }),
247
- [name]
248
- );
249
- (0, import_react2.useEffect)(() => {
250
- const unregister = dynamicRegistry.registerResource({
251
- uri: `state://${name}`,
273
+ const selectorKeys = keysOf(options.selectors, "selector");
274
+ const actionKeys = keysOf(options.actions, "action");
275
+ const getStateRef = (0, import_react2.useRef)(options.getState);
276
+ getStateRef.current = options.getState;
277
+ const selectorsRef = (0, import_react2.useRef)(options.selectors);
278
+ selectorsRef.current = options.selectors;
279
+ const actionsRef = (0, import_react2.useRef)(options.actions);
280
+ actionsRef.current = options.actions;
281
+ const stateUri = `state://${name}`;
282
+ (0, import_react2.useEffect)(
283
+ () => dynamicRegistry.registerResource({
284
+ uri: stateUri,
252
285
  name: `${name}-state`,
253
286
  description: `Full state of ${name} store`,
254
287
  mimeType: "application/json",
255
- read: readState
256
- });
257
- const unsubscribe = subscribe(() => {
258
- dynamicRegistry.updateResourceRead(`state://${name}`, readState);
259
- });
260
- return () => {
261
- unregister();
262
- unsubscribe();
263
- };
264
- }, [dynamicRegistry, name, subscribe, readState]);
288
+ read: async () => jsonResource(stateUri, getStateRef.current())
289
+ }),
290
+ [dynamicRegistry, name, stateUri]
291
+ );
265
292
  (0, import_react2.useEffect)(() => {
266
- if (!selectors) return;
267
- const cleanups = [];
268
- const selectorUris = [];
269
- for (const [key, selector] of Object.entries(selectors)) {
270
- if (!key || !VALID_NAME_RE.test(key)) {
271
- throw new Error(`useStoreResource: invalid selector key "${key}". Keys must match ${VALID_NAME_RE}.`);
272
- }
273
- const uri = `state://${name}/${key}`;
274
- const selectorRef = { current: selector };
275
- const readSelector = async () => ({
276
- contents: [
277
- {
278
- uri,
279
- mimeType: "application/json",
280
- text: JSON.stringify(selectorRef.current(getStateRef.current()) ?? null)
281
- }
282
- ]
293
+ const cleanups = parseKeys(selectorKeys).map((key) => {
294
+ const uri = `${stateUri}/${key}`;
295
+ return dynamicRegistry.registerResource({
296
+ uri,
297
+ name: `${name}-${key}`,
298
+ description: `Selector "${key}" from ${name} store`,
299
+ mimeType: "application/json",
300
+ read: async () => {
301
+ const selector = selectorsRef.current?.[key];
302
+ return jsonResource(uri, selector ? selector(getStateRef.current()) : void 0);
303
+ }
283
304
  });
284
- selectorUris.push({ uri, readSelector });
285
- cleanups.push(
286
- dynamicRegistry.registerResource({
287
- uri,
288
- name: `${name}-${key}`,
289
- description: `Selector "${key}" from ${name} store`,
290
- mimeType: "application/json",
291
- read: readSelector
292
- })
293
- );
294
- }
295
- const unsubscribe = subscribe(() => {
296
- for (const { uri, readSelector } of selectorUris) {
297
- dynamicRegistry.updateResourceRead(uri, readSelector);
298
- }
299
305
  });
300
- cleanups.push(unsubscribe);
301
306
  return () => {
302
307
  cleanups.forEach((fn) => {
303
308
  fn();
304
309
  });
305
310
  };
306
- }, [dynamicRegistry, name, selectors, subscribe]);
311
+ }, [dynamicRegistry, name, stateUri, selectorKeys]);
307
312
  (0, import_react2.useEffect)(() => {
308
- if (!actions) return;
309
- const cleanups = [];
310
- for (const [key, action] of Object.entries(actions)) {
311
- const toolName = `${name}_${key}`;
313
+ const uris = [stateUri, ...parseKeys(selectorKeys).map((key) => `${stateUri}/${key}`)];
314
+ return subscribe(() => {
315
+ for (const uri of uris) {
316
+ const resource = dynamicRegistry.findResource(uri);
317
+ if (resource) dynamicRegistry.updateResourceRead(uri, resource.read);
318
+ }
319
+ });
320
+ }, [dynamicRegistry, stateUri, selectorKeys, subscribe]);
321
+ (0, import_react2.useEffect)(() => {
322
+ const cleanups = parseKeys(actionKeys).map((key) => {
312
323
  const execute = async (args) => {
324
+ const action = actionsRef.current?.[key];
325
+ if (!action) {
326
+ return { isError: true, content: [{ type: "text", text: `Action "${key}" is no longer available` }] };
327
+ }
313
328
  const argsArray = args["args"];
314
329
  const result = await (Array.isArray(argsArray) ? action(...argsArray) : action(args));
315
330
  return {
316
331
  content: [{ type: "text", text: JSON.stringify({ success: true, result }) }]
317
332
  };
318
333
  };
319
- cleanups.push(
320
- dynamicRegistry.registerTool({
321
- name: toolName,
322
- description: `Action "${key}" on ${name} store`,
323
- inputSchema: {
324
- type: "object",
325
- properties: {
326
- args: { type: "array", description: "Arguments to pass to the action" }
327
- }
328
- },
329
- execute
330
- })
331
- );
332
- }
334
+ return dynamicRegistry.registerTool({
335
+ name: `${name}_${key}`,
336
+ description: `Action "${key}" on ${name} store`,
337
+ inputSchema: {
338
+ type: "object",
339
+ properties: {
340
+ args: { type: "array", description: "Arguments to pass to the action" }
341
+ }
342
+ },
343
+ execute
344
+ });
345
+ });
333
346
  return () => {
334
347
  cleanups.forEach((fn) => {
335
348
  fn();
336
349
  });
337
350
  };
338
- }, [dynamicRegistry, name, actions]);
351
+ }, [dynamicRegistry, name, actionKeys]);
339
352
  }
340
353
 
341
354
  // libs/react/src/state/useReduxResource.ts
@@ -353,10 +366,12 @@ function useReduxResource(options) {
353
366
  }
354
367
  return wrapped;
355
368
  }, [actions, store]);
369
+ const getState = (0, import_react3.useMemo)(() => store.getState.bind(store), [store]);
370
+ const subscribe = (0, import_react3.useMemo)(() => store.subscribe.bind(store), [store]);
356
371
  useStoreResource({
357
372
  name,
358
- getState: store.getState.bind(store),
359
- subscribe: store.subscribe.bind(store),
373
+ getState,
374
+ subscribe,
360
375
  selectors,
361
376
  actions: wrappedActions,
362
377
  server
@@ -1 +1 @@
1
- {"version":3,"file":"useReduxResource.d.ts","sourceRoot":"","sources":["../../src/state/useReduxResource.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAwBpE"}
1
+ {"version":3,"file":"useReduxResource.d.ts","sourceRoot":"","sources":["../../src/state/useReduxResource.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CA4BpE"}
@@ -4,6 +4,12 @@
4
4
  *
5
5
  * This is the core hook; useReduxResource and useValtioResource are
6
6
  * thin wrappers around it.
7
+ *
8
+ * Options may be written inline: `getState`, `selectors` and `actions` are read
9
+ * through refs, so a new function or object on every render does not register the
10
+ * resources and tools again. They are registered again only when the store `name`,
11
+ * the target server, or the set of selector / action names changes. A new
12
+ * `subscribe` function re-subscribes to the store, which touches no registry.
7
13
  */
8
14
  import type { StoreResourceOptions } from './state.types';
9
15
  export declare function useStoreResource(options: StoreResourceOptions): void;
@@ -1 +1 @@
1
- {"version":3,"file":"useStoreResource.d.ts","sourceRoot":"","sources":["../../src/state/useStoreResource.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAI1D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CA0IpE"}
1
+ {"version":3,"file":"useStoreResource.d.ts","sourceRoot":"","sources":["../../src/state/useStoreResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AA0B1D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAqGpE"}
package/types.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Core types for @frontmcp/react
3
3
  */
4
4
  import type React from 'react';
5
- import type { DirectMcpServer, DirectClient, CallToolResult, ReadResourceResult } from '@frontmcp/sdk';
5
+ import type { CallToolResult, DirectClient, DirectMcpServer, ReadResourceResult, RuntimeToolDefinition } from '@frontmcp/sdk';
6
6
  import type { ComponentRegistry } from './components/ComponentRegistry';
7
7
  import type { DynamicRegistry } from './registry/DynamicRegistry';
8
8
  export interface ToolInfo {
@@ -44,6 +44,15 @@ export interface DynamicToolDef {
44
44
  description: string;
45
45
  inputSchema: Record<string, unknown>;
46
46
  execute: (args: Record<string, unknown>) => Promise<CallToolResult>;
47
+ /** MCP behavioral hints (`readOnlyHint`, `destructiveHint`, ...). */
48
+ annotations?: RuntimeToolDefinition['annotations'];
49
+ /** Where the tool is offered, e.g. `{ surface: ['webmcp'] }` for in-browser agents only. */
50
+ availableWhen?: RuntimeToolDefinition['availableWhen'];
51
+ /**
52
+ * Id of the server app the tool joins (its plugins' hooks apply to the tool). Needed only for a
53
+ * server with more than one local app; defaults to the provider's `dynamicToolApps` entry.
54
+ */
55
+ app?: RuntimeToolDefinition['app'];
47
56
  }
48
57
  export interface DynamicResourceDef {
49
58
  uri: string;