@react-webmcp-kit/react-hook-form 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 react-webmcp-kit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # @react-webmcp-kit/react-hook-form
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Expose **[React Hook Form](https://react-hook-form.com/)** fields and submit handlers as **[WebMCP](https://developer.chrome.com/docs/ai/webmcp)** tools so agents can fill and submit forms safely.
4
+
5
+ Requires [`@react-webmcp-kit/core`](https://www.npmjs.com/package/@react-webmcp-kit/core).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @react-webmcp-kit/react-hook-form @react-webmcp-kit/core react-hook-form use-webmcp-tool zod
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Render inside `McpProvider`. Hoist field defs at module scope when possible.
16
+
17
+ ```tsx
18
+ 'use client';
19
+
20
+ import { useForm } from 'react-hook-form';
21
+ import { z } from 'zod';
22
+ import { zodResolver } from '@hookform/resolvers/zod';
23
+ import { McpFormTools, useMcpSubmitTool } from '@react-webmcp-kit/react-hook-form';
24
+
25
+ const schema = z.object({
26
+ email: z.string().email(),
27
+ fullName: z.string().min(1),
28
+ });
29
+
30
+ type FormValues = z.infer<typeof schema>;
31
+
32
+ const fields = [
33
+ { name: 'email' as const, description: 'Set checkout email' },
34
+ { name: 'fullName' as const, description: 'Set full name' },
35
+ ];
36
+
37
+ export function CheckoutForm() {
38
+ const form = useForm<FormValues>({
39
+ resolver: zodResolver(schema),
40
+ defaultValues: { email: '', fullName: '' },
41
+ });
42
+
43
+ useMcpSubmitTool({
44
+ name: 'submit_checkout',
45
+ description: 'Submit the checkout form',
46
+ form,
47
+ enabled: form.formState.isValid,
48
+ onSubmit: async (values) => {
49
+ // persist / navigate
50
+ return { success: true, values };
51
+ },
52
+ });
53
+
54
+ return (
55
+ <>
56
+ <McpFormTools form={form} fields={fields} />
57
+ <form onSubmit={form.handleSubmit((v) => console.log(v))}>{/* inputs */}</form>
58
+ </>
59
+ );
60
+ }
61
+ ```
62
+
63
+ ## API
64
+
65
+ | Export | Purpose |
66
+ |--------|---------|
67
+ | `McpFormTools` | One `fill_*` tool per field (`toolName` optional; default `fill_<path>`) |
68
+ | `useMcpSubmitTool` | Registers a submit tool that runs validation then your `onSubmit` |
69
+ | `McpFormFieldDef` | `{ name, description, toolName?, schema? }` |
70
+
71
+ Default field schema is `z.object({ value: z.string() })`. Pass a custom Zod schema when the agent should send structured values.
72
+
73
+ Gate tools with `enabled` (e.g. disable submit until the cart is non-empty).
74
+
75
+ ## Demo
76
+
77
+ See `apps/demo-checkout` in [webmcp-kit-react](https://github.com/stubbies/webmcp-kit-react).
78
+
79
+ ## License
80
+
81
+ MIT
@@ -0,0 +1,34 @@
1
+ import * as react from 'react';
2
+ import { FieldValues, FieldPath, UseFormReturn } from 'react-hook-form';
3
+ import { z } from 'zod';
4
+
5
+ type McpFormFieldDef<T extends FieldValues> = {
6
+ name: FieldPath<T>;
7
+ description: string;
8
+ toolName?: string;
9
+ schema?: z.ZodTypeAny;
10
+ };
11
+ type McpFormToolsProps<T extends FieldValues> = {
12
+ form: UseFormReturn<T>;
13
+ fields: McpFormFieldDef<T>[];
14
+ enabled?: boolean;
15
+ };
16
+ /** Register one WebMCP tool per form field (render inside McpProvider). */
17
+ declare function McpFormTools<T extends FieldValues>({ form, fields, enabled, }: McpFormToolsProps<T>): react.JSX.Element;
18
+ type UseMcpSubmitToolOptions<T extends FieldValues> = {
19
+ form: UseFormReturn<T>;
20
+ name: string;
21
+ description: string;
22
+ enabled?: boolean;
23
+ onValidSubmit?: (values: T) => unknown | Promise<unknown>;
24
+ };
25
+ declare function useMcpSubmitTool<T extends FieldValues>({ form, name, description, enabled, onValidSubmit, }: UseMcpSubmitToolOptions<T>): {
26
+ supported: boolean;
27
+ registered: boolean;
28
+ error: Error | null;
29
+ };
30
+ /** @deprecated Use McpFormTools component instead (hooks cannot run in a loop). */
31
+ declare function useMcpFormTools<T extends FieldValues>(_options: UseMcpFormToolsOptions<T>): void;
32
+ type UseMcpFormToolsOptions<T extends FieldValues> = McpFormToolsProps<T>;
33
+
34
+ export { type McpFormFieldDef, McpFormTools, type McpFormToolsProps, type UseMcpFormToolsOptions, type UseMcpSubmitToolOptions, useMcpFormTools, useMcpSubmitTool };
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ 'use client';
2
+
3
+ // src/index.tsx
4
+ import { z } from "zod";
5
+ import { useMcpTool } from "@react-webmcp-kit/core";
6
+ import { Fragment, jsx } from "react/jsx-runtime";
7
+ var DEFAULT_FIELD_SCHEMA = z.object({ value: z.string().describe("Field value") });
8
+ function McpFormFieldTool({
9
+ form,
10
+ field,
11
+ enabled
12
+ }) {
13
+ const toolName = field.toolName ?? `fill_${String(field.name).replace(/\./g, "_")}`;
14
+ const schema = field.schema ?? DEFAULT_FIELD_SCHEMA;
15
+ useMcpTool({
16
+ name: toolName,
17
+ description: field.description,
18
+ schema,
19
+ enabled,
20
+ execute: ({ value }) => {
21
+ form.setValue(field.name, value, { shouldValidate: true, shouldDirty: true });
22
+ return { success: true, field: field.name, value };
23
+ }
24
+ });
25
+ return null;
26
+ }
27
+ function McpFormTools({
28
+ form,
29
+ fields,
30
+ enabled = true
31
+ }) {
32
+ return /* @__PURE__ */ jsx(Fragment, { children: fields.map((field) => /* @__PURE__ */ jsx(McpFormFieldTool, { form, field, enabled }, String(field.name))) });
33
+ }
34
+ function useMcpSubmitTool({
35
+ form,
36
+ name,
37
+ description,
38
+ enabled = true,
39
+ onValidSubmit
40
+ }) {
41
+ return useMcpTool({
42
+ name,
43
+ description,
44
+ schema: z.object({}),
45
+ enabled,
46
+ execute: () => new Promise((resolve) => {
47
+ void form.handleSubmit(
48
+ async (values) => {
49
+ const result = onValidSubmit ? await onValidSubmit(values) : { success: true, values };
50
+ resolve(result);
51
+ },
52
+ (errors) => {
53
+ resolve({ success: false, errors });
54
+ }
55
+ )();
56
+ })
57
+ });
58
+ }
59
+ function useMcpFormTools(_options) {
60
+ throw new Error("useMcpFormTools is removed; render <McpFormTools /> instead.");
61
+ }
62
+ export {
63
+ McpFormTools,
64
+ useMcpFormTools,
65
+ useMcpSubmitTool
66
+ };
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"sourcesContent":["import type { FieldPath, FieldValues, UseFormReturn } from 'react-hook-form';\nimport { z } from 'zod';\nimport { useMcpTool } from '@react-webmcp-kit/core';\n\nexport type McpFormFieldDef<T extends FieldValues> = {\n name: FieldPath<T>;\n description: string;\n toolName?: string;\n schema?: z.ZodTypeAny;\n};\n\nexport type McpFormToolsProps<T extends FieldValues> = {\n form: UseFormReturn<T>;\n fields: McpFormFieldDef<T>[];\n enabled?: boolean;\n};\n\nconst DEFAULT_FIELD_SCHEMA = z.object({ value: z.string().describe('Field value') });\n\nfunction McpFormFieldTool<T extends FieldValues>({\n form,\n field,\n enabled,\n}: {\n form: UseFormReturn<T>;\n field: McpFormFieldDef<T>;\n enabled: boolean;\n}) {\n const toolName = field.toolName ?? `fill_${String(field.name).replace(/\\./g, '_')}`;\n const schema = field.schema ?? DEFAULT_FIELD_SCHEMA;\n\n useMcpTool({\n name: toolName,\n description: field.description,\n schema,\n enabled,\n execute: ({ value }: { value: string }) => {\n form.setValue(field.name, value as never, { shouldValidate: true, shouldDirty: true });\n return { success: true, field: field.name, value };\n },\n });\n\n return null;\n}\n\n/** Register one WebMCP tool per form field (render inside McpProvider). */\nexport function McpFormTools<T extends FieldValues>({\n form,\n fields,\n enabled = true,\n}: McpFormToolsProps<T>) {\n return (\n <>\n {fields.map((field) => (\n <McpFormFieldTool key={String(field.name)} form={form} field={field} enabled={enabled} />\n ))}\n </>\n );\n}\n\nexport type UseMcpSubmitToolOptions<T extends FieldValues> = {\n form: UseFormReturn<T>;\n name: string;\n description: string;\n enabled?: boolean;\n onValidSubmit?: (values: T) => unknown | Promise<unknown>;\n};\n\nexport function useMcpSubmitTool<T extends FieldValues>({\n form,\n name,\n description,\n enabled = true,\n onValidSubmit,\n}: UseMcpSubmitToolOptions<T>) {\n return useMcpTool({\n name,\n description,\n schema: z.object({}),\n enabled,\n execute: () =>\n new Promise((resolve) => {\n void form.handleSubmit(\n async (values) => {\n const result = onValidSubmit ? await onValidSubmit(values) : { success: true, values };\n resolve(result);\n },\n (errors) => {\n resolve({ success: false, errors });\n },\n )();\n }),\n });\n}\n\n/** @deprecated Use McpFormTools component instead (hooks cannot run in a loop). */\nexport function useMcpFormTools<T extends FieldValues>(_options: UseMcpFormToolsOptions<T>): void {\n throw new Error('useMcpFormTools is removed; render <McpFormTools /> instead.');\n}\n\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;AACrF,kBAAQ,MAAM;AAAA,QAChB;AAAA,QACA,CAAC,WAAW;AACV,kBAAQ,EAAE,SAAS,OAAO,OAAO,CAAC;AAAA,QACpC;AAAA,MACF,EAAE;AAAA,IACJ,CAAC;AAAA,EACL,CAAC;AACH;AAGO,SAAS,gBAAuC,UAA2C;AAChG,QAAM,IAAI,MAAM,8DAA8D;AAChF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@react-webmcp-kit/react-hook-form",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "React Hook Form adapters that expose fill and submit fields as WebMCP tools for AI agents",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/stubbies/webmcp-kit-react.git",
11
+ "directory": "packages/rhf"
12
+ },
13
+ "homepage": "https://github.com/stubbies/webmcp-kit-react/tree/main/packages/rhf#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/stubbies/webmcp-kit-react/issues"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "LICENSE",
29
+ "README.md"
30
+ ],
31
+ "peerDependencies": {
32
+ "@react-webmcp-kit/core": "^0.1.0",
33
+ "react": ">=18",
34
+ "react-hook-form": ">=7",
35
+ "zod": ">=3"
36
+ },
37
+ "devDependencies": {
38
+ "@testing-library/react": "^16.3.0",
39
+ "@types/react": "^19.0.0",
40
+ "jsdom": "^26.0.0",
41
+ "react": "^19.0.0",
42
+ "react-dom": "^19.0.0",
43
+ "react-hook-form": "^7.54.0",
44
+ "tsup": "^8.3.5",
45
+ "typescript": "^5.7.2",
46
+ "use-webmcp-tool": "^0.3.0",
47
+ "vitest": "^3.0.0",
48
+ "zod": "^3.24.1",
49
+ "@react-webmcp-kit/core": "0.1.0"
50
+ },
51
+ "keywords": [
52
+ "webmcp",
53
+ "mcp",
54
+ "react",
55
+ "react-hook-form",
56
+ "forms",
57
+ "ai-agents"
58
+ ],
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "test": "vitest run",
62
+ "typecheck": "tsc --noEmit",
63
+ "lint": "tsc --noEmit"
64
+ }
6
65
  }