@mcp-web/react 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-web/react",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MCP Web integration for React state management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,9 +13,9 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "zod": "~4.1.12",
16
- "@mcp-web/decompose-zod-schema": "0.1.0",
17
- "@mcp-web/types": "0.1.0",
18
- "@mcp-web/core": "0.1.0"
16
+ "@mcp-web/decompose-zod-schema": "0.1.1",
17
+ "@mcp-web/types": "0.1.1",
18
+ "@mcp-web/core": "0.1.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/react": "^18.3.0",
@@ -24,6 +24,11 @@
24
24
  "peerDependencies": {
25
25
  "react": ">=17.0.0"
26
26
  },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/flekschas/mcp-web",
30
+ "directory": "packages/integrations/react"
31
+ },
27
32
  "scripts": {
28
33
  "build": "tsc",
29
34
  "clean": "rm -rf dist"
@@ -1,63 +0,0 @@
1
- import type { MCPWeb } from '@mcp-web/core';
2
- import type { AppDefinition, CreatedApp } from '@mcp-web/types';
3
- /**
4
- * An app that can be registered with useApps.
5
- * Can be a CreatedApp or a raw AppDefinition.
6
- */
7
- export type RegisterableApp = CreatedApp | AppDefinition;
8
- /**
9
- * Hook for registering MCP Apps with automatic cleanup on unmount.
10
- *
11
- * This is the recommended way to register MCP Apps in React applications.
12
- * Apps are registered when the component mounts and automatically
13
- * unregistered when the component unmounts.
14
- *
15
- * MCP Apps are visual UI components that AI can render inline in chat
16
- * interfaces like Claude Desktop.
17
- *
18
- * @example Basic usage with createApp
19
- * ```tsx
20
- * // apps.ts
21
- * import { createApp } from '@mcp-web/app';
22
- *
23
- * export const statisticsApp = createApp({
24
- * name: 'show_statistics',
25
- * description: 'Display statistics visualization',
26
- * handler: () => ({
27
- * totalTasks: todos.length,
28
- * completedTasks: completedTodos.length,
29
- * }),
30
- * });
31
- *
32
- * // App.tsx
33
- * import { useApps } from '@mcp-web/react';
34
- * import { statisticsApp } from './apps';
35
- *
36
- * function App() {
37
- * useApps(statisticsApp);
38
- * return <div>...</div>;
39
- * }
40
- * ```
41
- *
42
- * @example Multiple apps
43
- * ```tsx
44
- * function App() {
45
- * useApps(statisticsApp, chartApp, dashboardApp);
46
- * return <div>...</div>;
47
- * }
48
- * ```
49
- *
50
- * @example Conditional app registration
51
- * ```tsx
52
- * function Analytics() {
53
- * // This app only exists while Analytics is mounted
54
- * useApps(analyticsApp);
55
- * return <div>Analytics enabled</div>;
56
- * }
57
- * ```
58
- *
59
- * @param apps - Apps to register (variadic or array)
60
- */
61
- export declare function useApps(...apps: (RegisterableApp | RegisterableApp[])[]): void;
62
- export declare function useApps(mcpWeb: MCPWeb, ...apps: (RegisterableApp | RegisterableApp[])[]): void;
63
- //# sourceMappingURL=use-apps.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-apps.d.ts","sourceRoot":"","sources":["../src/use-apps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKhE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,aAAa,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;AAEhF,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,GAAG,IAAI,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GAC/C,IAAI,CAAC"}
package/dist/use-apps.js DELETED
@@ -1,58 +0,0 @@
1
- import { isCreatedApp } from '@mcp-web/types';
2
- import { useContext, useEffect, useRef } from 'react';
3
- import { MCPWebContext } from './mcp-web-context';
4
- export function useApps(firstArg, ...rest) {
5
- // Determine if first arg is MCPWeb instance or an app
6
- const isMCPWebInstance = (value) => typeof value === 'object' &&
7
- value !== null &&
8
- 'addApp' in value &&
9
- 'removeApp' in value &&
10
- typeof value.addApp === 'function';
11
- let mcpWebProp;
12
- let appsToRegister;
13
- if (isMCPWebInstance(firstArg)) {
14
- mcpWebProp = firstArg;
15
- appsToRegister = rest.flat();
16
- }
17
- else {
18
- mcpWebProp = undefined;
19
- appsToRegister = [firstArg, ...rest].flat();
20
- }
21
- // Try to get from context if not provided
22
- const context = useContext(MCPWebContext);
23
- const mcpWeb = mcpWebProp ?? context?.mcpWeb;
24
- if (!mcpWeb) {
25
- throw new Error('useApps requires either mcpWeb as first argument or MCPWebProvider in component tree');
26
- }
27
- // Keep a stable reference to the apps array
28
- const appsRef = useRef(appsToRegister);
29
- appsRef.current = appsToRegister;
30
- // Keep a stable reference to mcpWeb
31
- const mcpWebRef = useRef(mcpWeb);
32
- mcpWebRef.current = mcpWeb;
33
- useEffect(() => {
34
- const cleanupFns = [];
35
- const mcp = mcpWebRef.current;
36
- for (const app of appsRef.current) {
37
- if (isCreatedApp(app)) {
38
- // Register CreatedApp
39
- mcp.addApp(app);
40
- cleanupFns.push(() => mcp.removeApp(app.definition.name));
41
- }
42
- else {
43
- // Register raw AppDefinition
44
- mcp.addApp(app);
45
- cleanupFns.push(() => mcp.removeApp(app.name));
46
- }
47
- }
48
- return () => {
49
- for (const cleanup of cleanupFns) {
50
- cleanup();
51
- }
52
- };
53
- }, []);
54
- // Note: Empty deps because we use refs - apps are registered once on mount
55
- // and cleaned up on unmount. If you need to re-register on app change,
56
- // use a key prop on the component.
57
- }
58
- //# sourceMappingURL=use-apps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IACpC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,UAAU,GAAmB,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC;QAE9B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,sBAAsB;gBACtB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACN,6BAA6B;gBAC7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QAED,OAAO,GAAG,EAAE;YACV,KAAK,MAAM,OAAO,IAAI,UAAU,EAAE,CAAC;gBACjC,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,2EAA2E;IAC3E,uEAAuE;IACvE,mCAAmC;AACrC,CAAC"}
@@ -1,78 +0,0 @@
1
- import type { CreatedStateTools, CreatedTool, MCPWeb } from '@mcp-web/core';
2
- import type { ToolDefinition } from '@mcp-web/types';
3
- /**
4
- * A tool that can be registered with useTools.
5
- * Can be a CreatedTool, CreatedStateTools, or a raw ToolDefinition.
6
- */
7
- export type RegisterableTool = CreatedTool | CreatedStateTools<any> | ToolDefinition;
8
- /**
9
- * Hook for registering pre-created tools with automatic cleanup on unmount.
10
- *
11
- * This is the recommended way to register tools in React applications.
12
- * Tools are registered when the component mounts and automatically
13
- * unregistered when the component unmounts.
14
- *
15
- * @example Basic usage with created tools
16
- * ```tsx
17
- * // tools.ts
18
- * import { createTool, createStateTools } from '@mcp-web/core';
19
- *
20
- * export const timeTool = createTool({
21
- * name: 'get_time',
22
- * description: 'Get current time',
23
- * handler: () => new Date().toISOString(),
24
- * });
25
- *
26
- * export const todoTools = createStateTools({
27
- * name: 'todos',
28
- * description: 'Todo list',
29
- * get: () => store.get(todosAtom),
30
- * set: (value) => store.set(todosAtom, value),
31
- * schema: TodosSchema,
32
- * expand: true,
33
- * });
34
- *
35
- * // App.tsx
36
- * import { useTools } from '@mcp-web/react';
37
- * import { timeTool, todoTools } from './tools';
38
- *
39
- * function App() {
40
- * useTools(timeTool, todoTools);
41
- * return <div>...</div>;
42
- * }
43
- * ```
44
- *
45
- * @example Conditional tool registration
46
- * ```tsx
47
- * function AdminPanel() {
48
- * // These tools only exist while AdminPanel is mounted
49
- * useTools(adminTools);
50
- * return <div>Admin controls</div>;
51
- * }
52
- *
53
- * function App() {
54
- * const [isAdmin, setIsAdmin] = useState(false);
55
- * return (
56
- * <div>
57
- * {isAdmin && <AdminPanel />}
58
- * </div>
59
- * );
60
- * }
61
- * ```
62
- *
63
- * @example With array of tools
64
- * ```tsx
65
- * const allTools = [todoTools, projectTools, settingsTools];
66
- *
67
- * function App() {
68
- * useTools(allTools);
69
- * // or: useTools(...allTools);
70
- * return <div>...</div>;
71
- * }
72
- * ```
73
- *
74
- * @param tools - Tools to register (variadic or array)
75
- */
76
- export declare function useTools(...tools: (RegisterableTool | RegisterableTool[])[]): void;
77
- export declare function useTools(mcpWeb: MCPWeb, ...tools: (RegisterableTool | RegisterableTool[])[]): void;
78
- //# sourceMappingURL=use-tools.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-tools.d.ts","sourceRoot":"","sources":["../src/use-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIrD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACxB,WAAW,GAEX,iBAAiB,CAAC,GAAG,CAAC,GACtB,cAAc,CAAC;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,wBAAgB,QAAQ,CACtB,GAAG,KAAK,EAAE,CAAC,gBAAgB,GAAG,gBAAgB,EAAE,CAAC,EAAE,GAClD,IAAI,CAAC;AAER,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,GAAG,KAAK,EAAE,CAAC,gBAAgB,GAAG,gBAAgB,EAAE,CAAC,EAAE,GAClD,IAAI,CAAC"}
package/dist/use-tools.js DELETED
@@ -1,64 +0,0 @@
1
- import { isCreatedStateTools, isCreatedTool } from '@mcp-web/core';
2
- import { useContext, useEffect, useRef } from 'react';
3
- import { MCPWebContext } from './mcp-web-context';
4
- export function useTools(firstArg, ...rest) {
5
- // Determine if first arg is MCPWeb instance or a tool
6
- const isMCPWebInstance = (value) => typeof value === 'object' &&
7
- value !== null &&
8
- 'addTool' in value &&
9
- 'addStateTools' in value &&
10
- typeof value.addTool === 'function';
11
- let mcpWebProp;
12
- let toolsToRegister;
13
- if (isMCPWebInstance(firstArg)) {
14
- mcpWebProp = firstArg;
15
- toolsToRegister = rest.flat();
16
- }
17
- else {
18
- mcpWebProp = undefined;
19
- toolsToRegister = [firstArg, ...rest].flat();
20
- }
21
- // Try to get from context if not provided
22
- const context = useContext(MCPWebContext);
23
- const mcpWeb = mcpWebProp ?? context?.mcpWeb;
24
- if (!mcpWeb) {
25
- throw new Error('useTools requires either mcpWeb as first argument or MCPWebProvider in component tree');
26
- }
27
- // Keep a stable reference to the tools array
28
- const toolsRef = useRef(toolsToRegister);
29
- toolsRef.current = toolsToRegister;
30
- // Keep a stable reference to mcpWeb
31
- const mcpWebRef = useRef(mcpWeb);
32
- mcpWebRef.current = mcpWeb;
33
- useEffect(() => {
34
- const cleanupFns = [];
35
- const mcp = mcpWebRef.current;
36
- for (const tool of toolsRef.current) {
37
- if (isCreatedTool(tool)) {
38
- // Register CreatedTool
39
- mcp.addTool(tool);
40
- cleanupFns.push(() => mcp.removeTool(tool.definition.name));
41
- }
42
- else if (isCreatedStateTools(tool)) {
43
- // Register CreatedStateTools
44
- const [, , cleanup] = mcp.addStateTools(tool);
45
- cleanupFns.push(cleanup);
46
- }
47
- else {
48
- // Register raw ToolDefinition
49
- // biome-ignore lint/suspicious/noExplicitAny: Internal addTool accepts ToolDefinition, but overloads are stricter
50
- mcp.addTool(tool);
51
- cleanupFns.push(() => mcp.removeTool(tool.name));
52
- }
53
- }
54
- return () => {
55
- for (const cleanup of cleanupFns) {
56
- cleanup();
57
- }
58
- };
59
- }, []);
60
- // Note: Empty deps because we use refs - tools are registered once on mount
61
- // and cleaned up on unmount. If you need to re-register on tool change,
62
- // use a key prop on the component.
63
- }
64
- //# sourceMappingURL=use-tools.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-tools.js","sourceRoot":"","sources":["../src/use-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAyFlD,MAAM,UAAU,QAAQ,CACtB,QAAwD,EACxD,GAAG,IAA+C;IAElD,sDAAsD;IACtD,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC3D,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,eAAe,IAAI,KAAK;QACxB,OAAQ,KAAgB,C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