@askqa/mcp 1.1.2 → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askqa",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "AskQA skills — set up notifications and monitoring for your websites",
5
5
  "mcpServers": {
6
6
  "askqa": {
package/README.md CHANGED
@@ -41,6 +41,7 @@ Get your API key from [askqa.ai](https://askqa.ai) after signing in.
41
41
  | `delete_test` | Delete a test (with confirmation) |
42
42
  | `run_test` | Run a test and wait for results |
43
43
  | `get_test_results` | Get recent test run results with step details |
44
+ | `heal_test` | Diagnose a layout-change regression and help fix selectors |
44
45
  | `get_test_screenshots` | Get screenshots from a test run |
45
46
  | `list_templates` | List available test templates |
46
47
  | `screenshot_url` | Screenshot a URL and extract page structure |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askqa/mcp",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "MCP server for AskQA — monitor websites with automated tests by chatting with AI",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/server.js CHANGED
@@ -498,9 +498,11 @@ server.registerTool(
498
498
  secrets: z.record(z.string()).nullable().optional().describe("Updated secrets (pass null to clear). Encrypted at rest, never returned in API responses — must be provided again when updating a test that uses secrets."),
499
499
  headers: z.record(z.string()).nullable().optional().describe("Updated HTTP headers (pass null to clear)"),
500
500
  enable_test_mode: z.boolean().optional().describe("Send X-AskQA-Secret header to the target site, enabling test mode on sites that support it (default: true)"),
501
+ healing_disabled: z.boolean().optional().describe("Set true to stop AskQA from suggesting fixes for this test (e.g. a failing test that's acceptable as-is, or one you'd rather fix yourself). Auto-clears once the test passes again. Set false to re-enable."),
502
+ healing_note: z.string().nullable().optional().describe("Optional note explaining why healing was disabled (pass null to clear)."),
501
503
  },
502
504
  },
503
- async ({ test_id, name, url, code, template_id, params, secrets, headers, enable_test_mode }) => {
505
+ async ({ test_id, name, url, code, template_id, params, secrets, headers, enable_test_mode, healing_disabled, healing_note }) => {
504
506
  try {
505
507
  const body = {};
506
508
  if (name !== undefined) body.name = name;
@@ -511,6 +513,8 @@ server.registerTool(
511
513
  if (secrets !== undefined) body.secrets = secrets;
512
514
  if (headers !== undefined) body.headers = headers;
513
515
  if (enable_test_mode !== undefined) body.enable_test_mode = enable_test_mode;
516
+ if (healing_disabled !== undefined) body.healing_disabled = healing_disabled;
517
+ if (healing_note !== undefined) body.healing_note = healing_note;
514
518
  const test = await apiPatch(`/api/tests/${test_id}`, body);
515
519
  return { content: [{ type: "text", text: JSON.stringify(test, null, 2) }] };
516
520
  } catch (err) {
@@ -762,6 +766,150 @@ server.registerTool(
762
766
  }
763
767
  );
764
768
 
769
+ const REASON_EXPLANATIONS = {
770
+ "healing-disabled": "Healing is turned off for this test. Re-enable with update_test healing_disabled=false, or pass force=true to heal anyway.",
771
+ "not-custom-code": "This is a template-based test with no custom selectors to heal. Layout-change healing only applies to custom-code tests.",
772
+ "currently-passing": "The test's most recent run passed — there's nothing to heal.",
773
+ "not-enough-failures": "The test hasn't failed enough consecutive times yet to confirm a regression (a single/transient failure isn't healed). Wait for the confirmation threshold.",
774
+ "never-passed": "This test has no prior passing run, so a failure isn't a regression — it likely needs to be authored/fixed from scratch rather than healed.",
775
+ "transient-recovered": "On a fresh re-run the test passed, so the earlier failure was transient — no layout fix needed.",
776
+ };
777
+
778
+ function renderPageStructure(pageInfo) {
779
+ if (!pageInfo) return "";
780
+ const lines = ["", "Current page structure (selectors that exist NOW — map old selectors to these):"];
781
+ if (pageInfo.buttons?.length) {
782
+ lines.push(" Buttons:");
783
+ for (const b of pageInfo.buttons) lines.push(` "${b.text}" → ${b.selector}`);
784
+ }
785
+ if (pageInfo.inputs?.length) {
786
+ lines.push(" Inputs:");
787
+ for (const inp of pageInfo.inputs) {
788
+ const desc = inp.placeholder || inp.name || inp.type || inp.tag;
789
+ lines.push(` [${desc}] → ${inp.selector}`);
790
+ }
791
+ }
792
+ if (pageInfo.links?.length) {
793
+ lines.push(" Links:");
794
+ for (const l of pageInfo.links) lines.push(` "${l.text}" → ${l.selector}`);
795
+ }
796
+ return lines.join("\n");
797
+ }
798
+
799
+ server.registerTool(
800
+ "heal_test",
801
+ {
802
+ description: "Diagnose and help heal a test that recently started failing because the website's layout changed (e.g. an input id or button selector changed). Accepts a test_id or name. Checks run history to confirm a real regression (was passing, now consistently failing) and that the failure is selector/layout-related — NOT a site outage, network error, or genuine feature breakage. When healable, it re-runs the test live, captures the CURRENT page structure + screenshots, and returns a brief for you to write new selectors. IMPORTANT: only fix the selectors — never change the test's logic, step order, assertions, or navigation, and never skip steps. After proposing new code, verify it with validate_test, and only then apply with update_test. If the failing test is actually acceptable, or the user wants to fix it themselves, call update_test healing_disabled=true to stop future suggestions.",
803
+ readOnlyHint: true,
804
+ inputSchema: {
805
+ test_id: z.coerce.number().optional().describe("The test ID to heal (from list_tests). Provide this or name."),
806
+ name: z.string().optional().describe("Test name (case-insensitive substring match) if you don't have the ID."),
807
+ reproduce: z.boolean().optional().describe("Re-run the test live to confirm the failure and capture current layout (default: true)."),
808
+ force: z.boolean().optional().describe("Heal even if healing_disabled is set on the test (default: false)."),
809
+ },
810
+ },
811
+ async ({ test_id, name, reproduce, force }) => {
812
+ try {
813
+ // Resolve test by id or name.
814
+ let resolvedId = test_id;
815
+ if (!resolvedId) {
816
+ if (!name) {
817
+ return { content: [{ type: "text", text: "Provide a test_id or name." }], isError: true };
818
+ }
819
+ const data = await apiGet("/api/tests/list");
820
+ const needle = name.toLowerCase();
821
+ const matches = data.tests.filter((t) => t.name && t.name.toLowerCase().includes(needle));
822
+ if (matches.length === 0) {
823
+ return { content: [{ type: "text", text: `No test found matching "${name}". Use list_tests to see available tests.` }], isError: true };
824
+ }
825
+ if (matches.length > 1) {
826
+ const list = matches.map((t) => ` #${t.id} — ${t.name} (${t.url})`).join("\n");
827
+ return { content: [{ type: "text", text: `Multiple tests match "${name}":\n${list}\n\nRe-run heal_test with a specific test_id.` }] };
828
+ }
829
+ resolvedId = matches[0].id;
830
+ }
831
+
832
+ const result = await apiPost(`/api/tests/${resolvedId}/heal`, { mode: "diagnose", reproduce: reproduce !== false });
833
+ const { test, diagnosis, reproduction } = result;
834
+ const content = [];
835
+ const lines = [`Healing diagnosis for "${test.name}" (#${test.id})`, ` URL: ${test.url}`, ""];
836
+
837
+ // Healing disabled — respect unless forced.
838
+ if (diagnosis.reason === "healing-disabled" && !force) {
839
+ lines.push("⚠ " + REASON_EXPLANATIONS["healing-disabled"]);
840
+ if (diagnosis.healing_note) lines.push(` Note: ${diagnosis.healing_note}`);
841
+ return { content: [{ type: "text", text: lines.join("\n") }] };
842
+ }
843
+
844
+ // Not healable — explain and stop.
845
+ if (!diagnosis.healable && diagnosis.reason !== "healing-disabled") {
846
+ lines.push(`Not healable (${diagnosis.reason}).`);
847
+ if (REASON_EXPLANATIONS[diagnosis.reason]) lines.push(` ${REASON_EXPLANATIONS[diagnosis.reason]}`);
848
+ if (diagnosis.reason === "regression" && diagnosis.failure_class && diagnosis.failure_class !== "selector") {
849
+ lines.push(` The failure looks like a "${diagnosis.failure_class}" issue, not a layout/selector change, so healing won't help.`);
850
+ if (diagnosis.failing_step) lines.push(` Failing step: ${diagnosis.failing_step.name} — ${diagnosis.failing_step.error || ""}`);
851
+ }
852
+ return { content: [{ type: "text", text: lines.join("\n") }] };
853
+ }
854
+
855
+ // Healable (or forced past a disabled flag). Build the brief.
856
+ const reg = diagnosis.regression;
857
+ if (reg) {
858
+ lines.push("✓ Confirmed regression (layout change suspected):");
859
+ lines.push(` Last passed: run #${reg.lastPassRunId} at ${reg.lastPassAt}`);
860
+ lines.push(` Started failing: run #${reg.firstFailRunId} at ${reg.firstFailAt}`);
861
+ lines.push(` Consecutive failures: ${reg.failureStreak}`);
862
+ }
863
+ if (diagnosis.failing_step) {
864
+ lines.push("", `Failing step: ${diagnosis.failing_step.name}`);
865
+ if (diagnosis.failing_step.error) lines.push(` Error: ${diagnosis.failing_step.error}`);
866
+ }
867
+
868
+ if (reproduction && !reproduction.still_failing) {
869
+ lines.push("", "On a fresh re-run the test PASSED — the failure was transient. No fix needed right now.");
870
+ return { content: [{ type: "text", text: lines.join("\n") }] };
871
+ }
872
+
873
+ // Current test code
874
+ const fullTest = await apiGet(`/api/tests/${test.id}`);
875
+ lines.push("", "Current test code:", "```javascript", fullTest.code || "(no code)", "```");
876
+
877
+ // Current page structure
878
+ if (reproduction?.page_info) lines.push(renderPageStructure(reproduction.page_info));
879
+
880
+ // Guardrails + instructions for the calling agent
881
+ lines.push(
882
+ "",
883
+ "── How to heal this test ──",
884
+ "1. Propose updated code that changes ONLY the broken selector(s) to match the current page structure above.",
885
+ " • Do NOT change the test's logic, step order, assertions, waits, or navigation.",
886
+ " • Do NOT skip/remove steps or add workarounds (no JS .click(), no waitForTimeout).",
887
+ "2. Verify your new code with validate_test (code + url). Iterate until it passes.",
888
+ "3. Only after it passes, apply it with update_test (confirm with the user first).",
889
+ "",
890
+ "If this failing test is actually acceptable, or the user wants to fix it themselves, call",
891
+ "update_test healing_disabled=true (optionally with healing_note) to stop future suggestions.",
892
+ );
893
+
894
+ content.push({ type: "text", text: lines.join("\n") });
895
+
896
+ // Reproduction screenshots
897
+ if (reproduction?.screenshots) {
898
+ for (const [stepName, base64] of Object.entries(reproduction.screenshots)) {
899
+ if (base64) {
900
+ content.push({ type: "text", text: `Screenshot: ${stepName}` });
901
+ content.push({ type: "image", data: base64, mimeType: "image/png" });
902
+ }
903
+ }
904
+ }
905
+
906
+ return { content };
907
+ } catch (err) {
908
+ return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
909
+ }
910
+ }
911
+ );
912
+
765
913
  // --- Notification channel tools ---
766
914
 
767
915
  server.registerTool(