auto-webmcp 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) 2025 Prasanna Vaidya (prasanna@gyde.ai)
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 ADDED
@@ -0,0 +1,193 @@
1
+ # auto-webmcp
2
+
3
+ **Automatically make any HTML form WebMCP-ready — zero explicit coding required.**
4
+
5
+ Drop in one script tag (or one `import`) and every `<form>` on your page is
6
+ instantly registered as a structured tool that in-browser AI agents can
7
+ discover and use via Google Chrome's
8
+ [WebMCP](https://github.com/nicktindall/mcp-browser) proposal.
9
+
10
+ ---
11
+
12
+ ## Quick start
13
+
14
+ ### Script tag (CDN / zero-config)
15
+
16
+ ```html
17
+ <script src="https://cdn.jsdelivr.net/npm/auto-webmcp/dist/auto-webmcp.iife.js"></script>
18
+ ```
19
+
20
+ All forms on the page are discovered and registered automatically.
21
+
22
+ ### npm / ESM
23
+
24
+ ```bash
25
+ npm install auto-webmcp
26
+ ```
27
+
28
+ ```js
29
+ import { autoWebMCP } from 'auto-webmcp';
30
+ await autoWebMCP();
31
+ ```
32
+
33
+ ---
34
+
35
+ ## What it does
36
+
37
+ 1. Scans the page for all `<form>` elements (on load + dynamically via `MutationObserver`)
38
+ 2. Infers a meaningful **tool name**, **description**, and **JSON Schema** from the form's DOM
39
+ 3. Registers each form as a WebMCP tool via `navigator.modelContext.registerTool()`
40
+ 4. Intercepts submissions to return structured results back to the agent
41
+ 5. Degrades silently in browsers without WebMCP
42
+
43
+ ---
44
+
45
+ ## Configuration
46
+
47
+ ```js
48
+ import { autoWebMCP } from 'auto-webmcp';
49
+
50
+ await autoWebMCP({
51
+ // Skip specific forms
52
+ exclude: ['#login-form', '[data-no-webmcp]'],
53
+
54
+ // Auto-submit when agent invokes (default: false — human must click submit)
55
+ autoSubmit: false,
56
+
57
+ // Optional AI enrichment for richer descriptions
58
+ enhance: { provider: 'claude', apiKey: 'sk-...' },
59
+
60
+ // Per-form name / description overrides
61
+ overrides: {
62
+ '#checkout-form': {
63
+ name: 'checkout',
64
+ description: 'Complete a purchase'
65
+ }
66
+ },
67
+
68
+ // Log registered tools to console
69
+ debug: true,
70
+ });
71
+ ```
72
+
73
+ ### Per-form HTML overrides
74
+
75
+ Override individual forms without JavaScript:
76
+
77
+ ```html
78
+ <form
79
+ data-webmcp-name="book_appointment"
80
+ data-webmcp-description="Book a doctor appointment"
81
+ data-webmcp-autosubmit
82
+ >
83
+ <input
84
+ name="date"
85
+ type="date"
86
+ data-webmcp-title="Appointment Date"
87
+ data-webmcp-description="Preferred appointment date"
88
+ >
89
+
90
+ </form>
91
+ ```
92
+
93
+ ### Skip a form entirely
94
+
95
+ ```html
96
+ <form data-no-webmcp>…</form>
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Tool name inference (priority order)
102
+
103
+ 1. `data-webmcp-name` attribute on `<form>`
104
+ 2. Submit button text (e.g. "Search Flights" → `search_flights`)
105
+ 3. Nearest `<h1>`–`<h3>` heading above the form
106
+ 4. Form `id` or `name` attribute
107
+ 5. Last segment of form `action` URL
108
+ 6. Fallback: `form_N`
109
+
110
+ ## Tool description inference (priority order)
111
+
112
+ 1. `data-webmcp-description` attribute on `<form>`
113
+ 2. `<legend>` text inside the form
114
+ 3. `aria-label` on the form
115
+ 4. `aria-describedby` target
116
+ 5. Nearest heading + page `<title>`
117
+
118
+ ## HTML → JSON Schema mapping
119
+
120
+ | HTML type | JSON Schema |
121
+ |------------------------|-------------------------|
122
+ | `text`, `search`, `tel`| `string` |
123
+ | `email` | `string` + format:email |
124
+ | `url` | `string` + format:uri |
125
+ | `number`, `range` | `number` (+ min/max) |
126
+ | `date` | `string` + format:date |
127
+ | `datetime-local` | `string` + format:date-time |
128
+ | `checkbox` | `boolean` |
129
+ | `radio` | `string` + enum |
130
+ | `select` | `string` + enum |
131
+ | `textarea` | `string` |
132
+ | `file`, `hidden`, `password` | _skipped_ |
133
+
134
+ ---
135
+
136
+ ## API
137
+
138
+ ```ts
139
+ const handle = await autoWebMCP(config?);
140
+
141
+ handle.isSupported // boolean — true if navigator.modelContext exists
142
+ handle.getTools() // Array<{ form: HTMLFormElement; name: string }>
143
+ handle.destroy() // Promise<void> — unregister all tools & stop observing
144
+ ```
145
+
146
+ ### Events
147
+
148
+ ```js
149
+ window.addEventListener('form:registered', (e) => {
150
+ console.log('Registered:', e.detail.toolName, e.detail.form);
151
+ });
152
+ window.addEventListener('form:unregistered', (e) => {
153
+ console.log('Removed:', e.detail.toolName);
154
+ });
155
+ ```
156
+
157
+ ### Prevent auto-init (IIFE build)
158
+
159
+ Set this before the script loads:
160
+
161
+ ```html
162
+ <script>window.__AUTO_WEBMCP_NO_AUTOINIT = true;</script>
163
+ <script src="auto-webmcp.iife.js"></script>
164
+ <script>
165
+ AutoWebMCP.autoWebMCP({ debug: true });
166
+ </script>
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Development
172
+
173
+ ```bash
174
+ npm install
175
+ npm run build # compile to dist/
176
+ npm run build:watch # rebuild on change
177
+ npm run typecheck # TypeScript type check only
178
+ npm test # Playwright integration tests
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Browser support
184
+
185
+ - Chrome 146+ with `#enable-webmcp-testing` flag (or WebMCP GA) for full functionality
186
+ - All other browsers: forms are analyzed and the library loads without error —
187
+ `navigator.modelContext` calls are silently no-opped (progressive enhancement)
188
+
189
+ ---
190
+
191
+ ## License
192
+
193
+ MIT
@@ -0,0 +1,15 @@
1
+ /**
2
+ * analyzer.ts — Infer tool name, description, and JSON Schema from form DOM
3
+ */
4
+ import { JsonSchema } from './schema.js';
5
+ import { FormOverride } from './config.js';
6
+ export interface ToolMetadata {
7
+ name: string;
8
+ description: string;
9
+ inputSchema: JsonSchema;
10
+ }
11
+ /** Reset form index counter (useful in tests) */
12
+ export declare function resetFormIndex(): void;
13
+ /** Derive ToolMetadata from a <form> element */
14
+ export declare function analyzeForm(form: HTMLFormElement, override?: FormOverride): ToolMetadata;
15
+ //# sourceMappingURL=analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAA2D,MAAM,aAAa,CAAC;AAClG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,UAAU,CAAC;CACzB;AAKD,iDAAiD;AACjD,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,YAAY,CAMxF"}