@nyx-intelligence/val-mcp 0.5.1 → 0.5.5

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/dist/index.js CHANGED
@@ -38,8 +38,20 @@ async function runCli(args) {
38
38
  console.log(` ERROR: ${e.el} — ${e.error}`);
39
39
  await session.close();
40
40
  }
41
+ else if (cmd === "exercise-forms" && url) {
42
+ console.log(fmtAction(await session.open(url, arg2 || undefined)));
43
+ const res = await session.exerciseForms();
44
+ console.log(`\nexercised ${res.tested} form(s): ${res.dead.length} dead, ${res.errored.length} errored, ${res.submitted.length} submitted`);
45
+ for (const d of res.dead)
46
+ console.log(` DEAD: ${d.form} — ${d.reason}`);
47
+ for (const e of res.errored)
48
+ console.log(` ERROR: ${e.form} — ${e.error}`);
49
+ for (const s of res.submitted)
50
+ console.log(` OK: ${s.form}${s.navigatedTo ? ` → ${s.navigatedTo}` : ""}`);
51
+ await session.close();
52
+ }
41
53
  else {
42
- console.error("Usage:\n val-mcp scan <url> [maxPages] [device]\n val-mcp exercise <url> [device]\n val-mcp (start MCP server on stdio)");
54
+ console.error("Usage:\n val-mcp scan <url> [maxPages] [device]\n val-mcp exercise <url> [device]\n val-mcp exercise-forms <url> [device]\n val-mcp (start MCP server on stdio)");
43
55
  process.exit(1);
44
56
  }
45
57
  process.exit(0);
@@ -66,7 +78,7 @@ async function runServer() {
66
78
  const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
67
79
  const { chromium } = await import("playwright");
68
80
  const { z } = await import("zod");
69
- const server = new McpServer({ name: "val", version: "0.5.0" });
81
+ const server = new McpServer({ name: "val", version: "0.5.5" });
70
82
  const text = (t) => ({ content: [{ type: "text", text: t }] });
71
83
  // ── Passive crawl ──
72
84
  server.registerTool("val_scan", {
@@ -125,6 +137,23 @@ async function runServer() {
125
137
  lines.push(`ERROR: ${e.el} — ${e.error}`);
126
138
  return text(lines.join("\n"));
127
139
  });
140
+ server.registerTool("val_exercise_forms", {
141
+ title: "Submit every form on the current page",
142
+ description: "Find every visible <form>, fill its inputs with plausible test data (email, password, text, etc.), submit it, and report which forms are DEAD (submit produced no effect, no API call, no DOM change), which threw a JS error, and which submitted successfully. Complements val_exercise — buttons-only sweeps miss broken signup/checkout/contact forms.",
143
+ inputSchema: {},
144
+ }, async () => {
145
+ const r = await session.exerciseForms();
146
+ const lines = [
147
+ `Exercised ${r.tested} form(s): ${r.dead.length} dead, ${r.errored.length} errored, ${r.submitted.length} submitted.`,
148
+ ];
149
+ for (const d of r.dead)
150
+ lines.push(`DEAD: ${d.form} — ${d.reason}`);
151
+ for (const e of r.errored)
152
+ lines.push(`ERROR: ${e.form} — ${e.error}`);
153
+ for (const s of r.submitted)
154
+ lines.push(`OK: ${s.form}${s.navigatedTo ? ` → ${s.navigatedTo}` : ""}`);
155
+ return text(lines.join("\n"));
156
+ });
128
157
  server.registerTool("val_state", {
129
158
  title: "Current page state + new errors",
130
159
  description: "Return the current URL/title and any console/JS/network errors captured since the last action. Use to verify a step did not break anything.",
@@ -151,7 +180,7 @@ async function runServer() {
151
180
  console.error("val-mcp server running on stdio");
152
181
  }
153
182
  const args = process.argv.slice(2);
154
- if (args[0] === "scan" || args[0] === "exercise") {
183
+ if (args[0] === "scan" || args[0] === "exercise" || args[0] === "exercise-forms") {
155
184
  runCli(args).catch((e) => {
156
185
  console.error(e);
157
186
  process.exit(1);
package/dist/session.js CHANGED
@@ -195,13 +195,41 @@ class ValSession {
195
195
  const startUrl = page.url();
196
196
  for (const b of buttons) {
197
197
  this.drain();
198
- const before = await this.sig();
199
198
  try {
199
+ const before = await this.sig();
200
200
  const loc = page.locator(`[data-val-ex="${b.ref}"]`);
201
201
  if ((await loc.count()) === 0)
202
202
  continue;
203
+ // Install mutation watcher BEFORE the click. The handler can mutate
204
+ // the DOM synchronously and finish before we start observing — we'd
205
+ // then wait 800ms for nothing and falsely flag the button dead.
206
+ // Watch ANY mutation: node added/removed (modal, dropdown), attribute
207
+ // changed (`value=`, `style`, `aria-*` — React preset buttons), or
208
+ // text changed (counters, totals). Anything = the click did something.
209
+ await page.evaluate(() => {
210
+ const w = window;
211
+ w.__valMut = false;
212
+ const obs = new MutationObserver(() => {
213
+ w.__valMut = true;
214
+ });
215
+ obs.observe(document.body, {
216
+ childList: true,
217
+ subtree: true,
218
+ attributes: true,
219
+ characterData: true,
220
+ });
221
+ w.__valObs = obs;
222
+ });
203
223
  await loc.click({ timeout: 4000 });
204
- await page.waitForTimeout(400);
224
+ await page.waitForTimeout(800);
225
+ const mutated = await page
226
+ .evaluate(() => {
227
+ const w = window;
228
+ const m = !!w.__valMut;
229
+ w.__valObs?.disconnect();
230
+ return m;
231
+ })
232
+ .catch(() => false);
205
233
  if (page.url() !== startUrl) {
206
234
  await page.goBack({ waitUntil: "load" }).catch(() => { });
207
235
  await page.waitForTimeout(300);
@@ -211,18 +239,185 @@ class ValSession {
211
239
  const after = await this.sig();
212
240
  const errs = this.drain();
213
241
  const label = b.text || b.ref;
214
- const moved = after.nodes !== before.nodes || Math.abs(after.text - before.text) > 3;
242
+ const sigChanged = after.nodes !== before.nodes || Math.abs(after.text - before.text) > 3;
243
+ const moved = mutated || sigChanged;
215
244
  if (errs.newPageErrors.length)
216
245
  errored.push({ el: label, error: errs.newPageErrors[0] });
217
246
  else if (!moved && errs.newConsoleErrors.length === 0 && errs.newNetworkErrors.length === 0)
218
247
  dead.push(label);
219
248
  }
220
249
  catch (e) {
221
- errored.push({ el: b.text || b.ref, error: e instanceof Error ? e.message : String(e) });
250
+ const msg = e instanceof Error ? e.message : String(e);
251
+ // SPA navigations can destroy our eval context mid-probe — recover silently,
252
+ // don't flag the click as an error of the page under test.
253
+ if (/Execution context was destroyed|Target closed|frame got detached|Navigation/i.test(msg)) {
254
+ try {
255
+ if (page.url() !== startUrl) {
256
+ await page.goBack({ waitUntil: "load" }).catch(() => { });
257
+ await page.waitForTimeout(300);
258
+ }
259
+ else {
260
+ await page.waitForLoadState("load", { timeout: 2000 }).catch(() => { });
261
+ }
262
+ await tag();
263
+ }
264
+ catch {
265
+ /* nothing more we can do */
266
+ }
267
+ }
268
+ else {
269
+ errored.push({ el: b.text || b.ref, error: msg });
270
+ }
222
271
  }
223
272
  }
224
273
  return { tested: buttons.length, dead, errored };
225
274
  }
275
+ /**
276
+ * Find every visible <form>, fill its inputs with plausible test data,
277
+ * submit it, and classify the outcome. Catches a class of bugs the button
278
+ * sweep cannot see: signup/checkout/contact forms with no handler, broken
279
+ * endpoints, validation that silently rejects everything.
280
+ */
281
+ async exerciseForms() {
282
+ const page = await this.ensure();
283
+ const forms = await page.evaluate(() => {
284
+ const isVisible = (el) => {
285
+ const r = el.getBoundingClientRect();
286
+ return r.width > 0 && r.height > 0;
287
+ };
288
+ const fs = Array.from(document.querySelectorAll("form")).filter(isVisible);
289
+ fs.forEach((f, i) => f.setAttribute("data-val-fx", `f${i}`));
290
+ return fs.map((f, i) => {
291
+ const submit = f.querySelector("button[type=submit], input[type=submit], button:not([type])");
292
+ const label = (submit?.innerText || "").trim().slice(0, 40) ||
293
+ f.getAttribute("aria-label") ||
294
+ f.id ||
295
+ `form-${i}`;
296
+ return { ref: `f${i}`, label };
297
+ });
298
+ });
299
+ const dead = [];
300
+ const errored = [];
301
+ const submitted = [];
302
+ const startUrl = page.url();
303
+ for (const fx of forms) {
304
+ this.drain();
305
+ try {
306
+ const form = page.locator(`[data-val-fx="${fx.ref}"]`);
307
+ if ((await form.count()) === 0)
308
+ continue;
309
+ // Fill every fillable input. Skip hidden/disabled/submit/checkbox/radio/file
310
+ // so we don't accidentally check legal-agreement boxes or upload anything.
311
+ const filled = await page.evaluate((ref) => {
312
+ const f = document.querySelector(`[data-val-fx="${ref}"]`);
313
+ if (!f)
314
+ return 0;
315
+ const inputs = Array.from(f.querySelectorAll("input, textarea"));
316
+ let n = 0;
317
+ for (const input of inputs) {
318
+ const i = input;
319
+ if (i.disabled)
320
+ continue;
321
+ const t = i.type || "text";
322
+ if (["hidden", "submit", "reset", "button", "checkbox", "radio", "file", "image"].indexOf(t) >= 0)
323
+ continue;
324
+ const value = t === "email" ? "test+val@example.com"
325
+ : t === "password" ? "ValTestPass123!"
326
+ : t === "tel" ? "+15551234567"
327
+ : t === "number" ? "1"
328
+ : t === "url" ? "https://example.com"
329
+ : t === "date" ? "2026-01-01"
330
+ : t === "search" ? "test"
331
+ : input.tagName === "TEXTAREA" ? "Test message from Val."
332
+ : "Test";
333
+ input.focus?.();
334
+ input.value = value;
335
+ input.dispatchEvent(new Event("input", { bubbles: true }));
336
+ input.dispatchEvent(new Event("change", { bubbles: true }));
337
+ n++;
338
+ }
339
+ return n;
340
+ }, fx.ref);
341
+ // Install mutation watcher BEFORE submit (same rationale as val_exercise).
342
+ await page.evaluate(() => {
343
+ const w = window;
344
+ w.__valMut = false;
345
+ const obs = new MutationObserver(() => {
346
+ w.__valMut = true;
347
+ });
348
+ obs.observe(document.body, { childList: true, subtree: true, attributes: true, characterData: true });
349
+ w.__valObs = obs;
350
+ });
351
+ // Prefer clicking the submit control (lets React onClick handlers fire).
352
+ // Fall back to form.requestSubmit() then form.submit().
353
+ const submitOk = await page.evaluate((ref) => {
354
+ const f = document.querySelector(`[data-val-fx="${ref}"]`);
355
+ if (!f)
356
+ return false;
357
+ const btn = f.querySelector("button[type=submit], input[type=submit]") ||
358
+ f.querySelector("button:not([type])");
359
+ if (btn) {
360
+ btn.click();
361
+ return true;
362
+ }
363
+ if (typeof f.requestSubmit === "function") {
364
+ f.requestSubmit();
365
+ return true;
366
+ }
367
+ f.submit();
368
+ return true;
369
+ }, fx.ref);
370
+ if (!submitOk) {
371
+ dead.push({ form: fx.label, reason: "no submit control found" });
372
+ continue;
373
+ }
374
+ await page.waitForTimeout(900);
375
+ const mutated = await page
376
+ .evaluate(() => {
377
+ const w = window;
378
+ const m = !!w.__valMut;
379
+ w.__valObs?.disconnect();
380
+ return m;
381
+ })
382
+ .catch(() => false);
383
+ const errs = this.drain();
384
+ const navigated = page.url() !== startUrl;
385
+ const has5xx = errs.newNetworkErrors.some((n) => n.status >= 500);
386
+ const networkFired = errs.newNetworkErrors.length > 0;
387
+ if (errs.newPageErrors.length) {
388
+ errored.push({ form: fx.label, error: errs.newPageErrors[0] });
389
+ }
390
+ else if (has5xx) {
391
+ errored.push({ form: fx.label, error: `server ${errs.newNetworkErrors.find((n) => n.status >= 500).status} on submit` });
392
+ }
393
+ else if (navigated || mutated || networkFired) {
394
+ submitted.push({ form: fx.label, navigatedTo: navigated ? page.url() : undefined });
395
+ }
396
+ else {
397
+ dead.push({ form: fx.label, reason: filled === 0 ? "no fillable inputs and submit had no effect" : "submit had no observable effect" });
398
+ }
399
+ if (navigated) {
400
+ await page.goBack({ waitUntil: "load" }).catch(() => { });
401
+ await page.waitForTimeout(300);
402
+ }
403
+ }
404
+ catch (e) {
405
+ const msg = e instanceof Error ? e.message : String(e);
406
+ // SPA navigations destroy our eval context. That means submit DID work.
407
+ if (/Execution context was destroyed|Target closed|frame got detached|Navigation/i.test(msg)) {
408
+ submitted.push({ form: fx.label, navigatedTo: page.url() !== startUrl ? page.url() : undefined });
409
+ if (page.url() !== startUrl) {
410
+ await page.goBack({ waitUntil: "load" }).catch(() => { });
411
+ await page.waitForTimeout(300);
412
+ }
413
+ }
414
+ else {
415
+ errored.push({ form: fx.label, error: msg });
416
+ }
417
+ }
418
+ }
419
+ return { tested: forms.length, dead, errored, submitted };
420
+ }
226
421
  async state() {
227
422
  const page = await this.ensure();
228
423
  return { ok: true, url: page.url(), title: await safeTitle(page), changed: false, ...this.drain() };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyx-intelligence/val-mcp",
3
- "version": "0.5.1",
3
+ "version": "0.5.5",
4
4
  "description": "Val — a 100% MCP QA agent for vibecoders. Drives a real browser to catch UX bugs (broken links, 404s, console errors, broken images) so your coding agent can fix them.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",