fastqa-mcp 0.0.0-stage โ†’ 0.3.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 VnKk8
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,216 @@
1
- # Temporary Holding Version
1
+ # FastQA
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
+ **An MCP server with a QA mindset that lets an LLM drive and test web UI applications.**
4
+
5
+ FastQA connects any MCP client (Claude Code, OpenCode and others) to a real browser. The LLM clicks, types and reads the page the way a tester would, and FastQA checks every step: it asserts on text, URLs, field values and accessibility. It also **records every network call with its method, URL and status code**, so a `500 POST /api/orders` is caught even when the UI hides it.
6
+
7
+ When a test passes, FastQA saves it as a flow. Saved flows replay in about a second with no LLM calls, from the MCP client or from the command line in CI.
8
+
9
+ ---
10
+
11
+ ## How it fits together
12
+
13
+ | Part | Role | Who does it |
14
+ |---|---|---|
15
+ | ๐Ÿง  The brain | Decides what to test and what to do next | The LLM (Claude, or whatever model OpenCode uses) |
16
+ | โœ‹ The hands and eyes | Clicks, types, reads the page, checks results | **FastQA** (the MCP server) |
17
+ | ๐Ÿ“ก The network log | Records each call: method, URL, status code | **FastQA** |
18
+ | ๐Ÿ’ป The browser | Runs the web app under test | Chrome, headless by default |
19
+
20
+ **Why it's fast:** Most browser MCP servers make the LLM do one click, stop and look, then do the next click and look again. Each "look" costs the LLM about 3 seconds of thinking.
21
+
22
+ FastQA lets the LLM send a **batch of steps** instead: *type the email, type the password, click Log in, check the welcome message, check that `POST /api/login` returned 200*. The whole batch runs in one go. The LLM only hears back **what changed** on the page, plus any failed calls or errors, not the whole page again.
23
+
24
+ The result is that the same test takes **about 8 seconds instead of about 33**. Once it's saved, it takes **about 1.5 seconds**.
25
+
26
+ ---
27
+
28
+ ## What it can check for you
29
+
30
+ | Check | What it means in plain words |
31
+ |---|---|
32
+ | **Text** | "The page must say *Thank you for your order*." |
33
+ | **Page address** | "After login, we must be on the dashboard." |
34
+ | **Field values** | "The quantity box must show 2." |
35
+ | **Buttons** | "*Place order* must be greyed out until I tick the terms box." |
36
+ | **Background calls** | "When I click *Place order*, the server must answer 201." This catches bugs the screen hides, like an error the page swallows. |
37
+ | **No hidden errors** | "Nothing broke behind the scenes." It catches crashes in the page's code and server errors. |
38
+ | **Accessibility** | "People using screen readers or the keyboard can use this page," following the WCAG rules. |
39
+ | **Phone view** | "Does it still work on an iPhone 13 screen?" |
40
+ | **Many users at once** | Runs the same test with a list of users from a simple spreadsheet (CSV) and shows which ones fail. |
41
+
42
+ It also handles the tricky parts of modern sites: **pop-in payment frames** (iframes, including a 3-D Secure frame inside a payment frame) and **self-contained widgets** (shadow DOM). You don't need to do anything special for these.
43
+
44
+ ---
45
+
46
+ ## What you get when something fails
47
+
48
+ - โŒ **Which step failed and why**, written in plain language. For example: `expected "Thank you for your order", but the page says "Payment could not be processed"`.
49
+ - ๐Ÿ“ธ **A screenshot** of the screen at the moment it failed.
50
+ - ๐Ÿ”Ž **Evidence**: server errors (like `500 POST /api/orders`) and errors from the page's own code. You can paste these straight into a bug report.
51
+ - ๐Ÿ“„ **A report page** you can open in any browser: green and red bars, each step and the screenshots.
52
+ - ๐Ÿงพ **A Jenkins file** (JUnit XML), so the results show up in your pipeline like any other tests.
53
+
54
+ ---
55
+
56
+ ## Setting it up (about 2 minutes, once)
57
+
58
+ **You need:** Node.js 20 or newer, plus Google Chrome. If you don't have Chrome, run `npx playwright install chromium`.
59
+
60
+ There is nothing to download or build. `npx` fetches FastQA from npm the first time your AI tool starts it.
61
+
62
+ **Step 1: connect it to your AI tool**
63
+
64
+ *If you use Claude Code*, run this once:
65
+ ```bash
66
+ claude mcp add fastqa -- npx -y fastqa-mcp
67
+ ```
68
+
69
+ *If you use OpenCode*, add this to your `opencode.json`:
70
+ ```json
71
+ {
72
+ "$schema": "https://opencode.ai/config.json",
73
+ "mcp": {
74
+ "fastqa": {
75
+ "type": "local",
76
+ "command": ["npx", "-y", "fastqa-mcp"],
77
+ "enabled": true
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ *If you use another MCP client* (Cursor, Claude Desktop, VS Code and others), add this to its MCP config:
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "fastqa": { "command": "npx", "args": ["-y", "fastqa-mcp"] }
88
+ }
89
+ }
90
+ ```
91
+
92
+ **Step 2: restart your AI tool.** You should now see `fastqa` in its list of tools.
93
+
94
+ To update later, restart your AI tool: `npx -y fastqa-mcp` uses the newest published version. If an old version keeps running, use `fastqa-mcp@latest` in the command once.
95
+
96
+ <details>
97
+ <summary>Running from source instead</summary>
98
+
99
+ ```bash
100
+ git clone https://github.com/VnKk8/FastQA-MCP.git
101
+ cd FastQA-MCP
102
+ npm install
103
+ npm run build
104
+ claude mcp add fastqa -- node /full/path/to/FastQA-MCP/dist/index.js
105
+ ```
106
+ </details>
107
+
108
+ ---
109
+
110
+ ## Your first test
111
+
112
+ Type this to your AI, in normal words:
113
+
114
+ > Open https://staging.example.com/login with FastQA. Log in as qa.user@example.com with password {{password}}. Add the "Blue T-shirt" to the cart, go to checkout and place the order. Check that it says "Thank you for your order" and that POST /api/orders returned 201. Make sure no server errors happened. If it passes, save it as "checkout".
115
+
116
+ That's it. The AI works out the steps and runs them in one go. It then tells you PASS or FAIL, with the reasons.
117
+
118
+ ### About passwords ๐Ÿ”’
119
+ Never type a real password into the chat. Write `{{password}}` instead, and set the real value on your computer before starting your AI tool:
120
+
121
+ ```bash
122
+ export FASTQA_VAR_password='the-real-password' # Mac / Linux
123
+ setx FASTQA_VAR_password "the-real-password" # Windows (then open a new terminal)
124
+ ```
125
+
126
+ FastQA fills it in at the last moment, so the AI never sees it. Password fields always show as `โ€ขโ€ขโ€ข`.
127
+
128
+ ---
129
+
130
+ ## Rerunning tests without the AI
131
+
132
+ Once a test is saved, you can rerun it in either of these ways.
133
+
134
+ **From the chat:**
135
+ > Run all saved FastQA flows.
136
+
137
+ **From a terminal or Jenkins** (no AI involved, free and fast):
138
+ ```bash
139
+ npx fastqa-mcp run '*' # run every saved test
140
+ npx fastqa-mcp run checkout # run just one
141
+ ```
142
+
143
+ It finishes with a โœ… or โŒ for each test and tells you where the report was saved.
144
+
145
+ ### Testing with many users
146
+ Make a file `.fastqa/data/users.csv`:
147
+ ```
148
+ email,password
149
+ john@example.com,secret123
150
+ emma@example.com,secret123
151
+ locked@example.com,wrong
152
+ ```
153
+ Then run:
154
+ ```bash
155
+ npx fastqa-mcp run login --data=users
156
+ ```
157
+ The test runs once per line. The report shows each user's result, and password columns are never printed.
158
+
159
+ ### Turning a test into real code
160
+ > Export the checkout flow.
161
+
162
+ This creates a normal Playwright test file in `.fastqa/tests/`. You can add it to your automation repo like any other test.
163
+
164
+ ---
165
+
166
+ ## Where things are saved
167
+
168
+ Everything goes in a `.fastqa` folder inside the project you're working in:
169
+
170
+ ```
171
+ .fastqa/
172
+ โ”œโ”€โ”€ flows/ โ† saved tests (simple JSON you can read)
173
+ โ”œโ”€โ”€ data/ โ† your CSV files with test users or values
174
+ โ”œโ”€โ”€ reports/ โ† report pages (open latest.html) + Jenkins files
175
+ โ”œโ”€โ”€ artifacts/ โ† screenshots of failures
176
+ โ””โ”€โ”€ tests/ โ† exported Playwright test files
177
+ ```
178
+
179
+ ---
180
+
181
+ ## Handy phrases for the AI
182
+
183
+ | You want to... | Say something like... |
184
+ |---|---|
185
+ | Watch the browser while it works | Set `FASTQA_HEADED=true` before starting the AI tool |
186
+ | Test on a phone screen | "Open the login page in FastQA as an **iPhone 13**." |
187
+ | Check accessibility | "Run a FastQA **audit** on this page." |
188
+ | See what went wrong behind the scenes | "Show me the FastQA **evidence**." |
189
+ | Get a picture | "Take a FastQA **screenshot**." |
190
+ | List saved tests | "List my FastQA flows." |
191
+
192
+ ---
193
+
194
+ ## When something doesn't work
195
+
196
+ | What you see | What to do |
197
+ |---|---|
198
+ | "Could not launch a browser" | Install Chrome, or run `npx playwright install chromium`. |
199
+ | "No visible element matches 'X'" | The button or field is named differently on screen. Ask the AI to "take a snapshot" and use the exact name it shows. |
200
+ | Two things have the same name (e.g. three "I accept" boxes) | Ask the AI to use the **ref** from the snapshot (like `e15`) instead of the name. |
201
+ | A widget can't be seen at all | It may use a "closed" component that no testing tool can look inside. Ask the developers to add a `data-testid` to it. |
202
+ | Test passes in chat but fails when rerun | The page probably needs a moment to load. Ask the AI to add a check (like "expect the text *Welcome*") before the next click. |
203
+
204
+ ---
205
+
206
+ ## Good habits
207
+
208
+ 1. **Always end with a check.** "Click Place order" isn't a test. "Click Place order, then check it says *Thank you for your order*" is.
209
+ 2. **Add "no hidden errors"** to important journeys like sign-up, checkout and payments.
210
+ 3. **Save every test that passes.** A saved test is a free regression test forever.
211
+ 4. **Use test users and `{{password}}`.** Never use real customer data.
212
+ 5. **Run all saved tests every night in Jenkins** and look at `reports/latest.html` in the morning.
213
+
214
+ ---
215
+
216
+ Technical details (every option, setting and step type) are in [docs/REFERENCE.md](docs/REFERENCE.md).
package/dist/a11y.js ADDED
@@ -0,0 +1,41 @@
1
+ import { createRequire } from 'node:module';
2
+ import { readFileSync } from 'node:fs';
3
+ const require = createRequire(import.meta.url);
4
+ let AXE_SRC;
5
+ const axeSource = () => (AXE_SRC ??= readFileSync(require.resolve('axe-core/axe.min.js'), 'utf8'));
6
+ const ORDER = { critical: 0, serious: 1, moderate: 2, minor: 3 };
7
+ /** Runs axe-core (WCAG 2.1 A/AA rules) in the page and every iframe. */
8
+ export async function auditA11y(page, frameLabel) {
9
+ const issues = [];
10
+ for (const f of page.frames()) {
11
+ if (f.isDetached())
12
+ continue;
13
+ try {
14
+ const has = await f.evaluate(() => typeof window.axe !== 'undefined');
15
+ if (!has)
16
+ await f.evaluate(axeSource());
17
+ const res = await f.evaluate(async () => {
18
+ const r = await window.axe.run(document, {
19
+ runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'] },
20
+ resultTypes: ['violations'],
21
+ });
22
+ return r.violations.map((v) => ({
23
+ impact: v.impact || 'minor', id: v.id, help: v.help, count: v.nodes.length,
24
+ examples: v.nodes.slice(0, 3).map((n) => String(n.target?.join(' ') ?? '').slice(0, 80)),
25
+ }));
26
+ });
27
+ const label = f === page.mainFrame() ? undefined : frameLabel(f);
28
+ for (const v of res)
29
+ issues.push({ ...v, frame: label });
30
+ }
31
+ catch { /* frame navigated away or blocked script injection (CSP) */ }
32
+ }
33
+ return issues.sort((a, b) => (ORDER[a.impact] ?? 9) - (ORDER[b.impact] ?? 9) || b.count - a.count);
34
+ }
35
+ export function renderA11y(issues) {
36
+ if (!issues.length)
37
+ return 'No WCAG 2.1 A/AA violations found by automated checks (manual checks still needed).';
38
+ const by = (i) => issues.filter((x) => x.impact === i).length;
39
+ return `${issues.length} rule(s) violated โ€” critical ${by('critical')}, serious ${by('serious')}, moderate ${by('moderate')}, minor ${by('minor')}\n` +
40
+ issues.map((i) => `[${i.impact}] ${i.id}: ${i.help} ร—${i.count}${i.frame ? ` (frame "${i.frame}")` : ''}\n e.g. ${i.examples.join(' | ')}`).join('\n');
41
+ }
package/dist/flows.js ADDED
@@ -0,0 +1,146 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { Session } from './session.js';
4
+ import { runStep, bind } from './runner.js';
5
+ export const FLOW_DIR = () => path.resolve(process.env.FASTQA_DIR || path.join(process.cwd(), '.fastqa'));
6
+ const flowPath = (name) => path.join(FLOW_DIR(), 'flows', `${safe(name)}.json`);
7
+ const safe = (n) => n.replace(/[^\w.-]+/g, '-').slice(0, 80);
8
+ export async function saveFlow(name, steps) {
9
+ const p = flowPath(name);
10
+ await fs.mkdir(path.dirname(p), { recursive: true });
11
+ const flow = { name, created: new Date().toISOString(), steps };
12
+ await fs.writeFile(p, JSON.stringify(flow, null, 2));
13
+ return p;
14
+ }
15
+ export async function loadFlow(name) {
16
+ return JSON.parse(await fs.readFile(flowPath(name), 'utf8'));
17
+ }
18
+ export async function listFlows() {
19
+ try {
20
+ return (await fs.readdir(path.join(FLOW_DIR(), 'flows'))).filter((f) => f.endsWith('.json')).map((f) => f.slice(0, -5)).sort();
21
+ }
22
+ catch {
23
+ return [];
24
+ }
25
+ }
26
+ /** Replays a flow in its own isolated browser context. No model involved. */
27
+ export async function runFlow(name, vars = {}, shared) {
28
+ const flow = await loadFlow(name);
29
+ const s = new Session();
30
+ if (shared?.browser)
31
+ s.browser = shared.browser; // reuse the running browser process, new context
32
+ const t0 = Date.now();
33
+ const started = new Date().toISOString();
34
+ const lines = [];
35
+ let ok = true;
36
+ let failedAt;
37
+ let screenshot;
38
+ let shotFile;
39
+ let url;
40
+ try {
41
+ await s.ensure();
42
+ s.mark = Date.now();
43
+ for (let i = 0; i < flow.steps.length; i++) {
44
+ const step = flow.steps[i];
45
+ const r = await runStep(s, bind(step, vars), step);
46
+ lines.push(`${String(i + 1).padStart(2)}. ${r.line}`);
47
+ if (!r.ok) {
48
+ ok = false;
49
+ failedAt = i + 1;
50
+ break;
51
+ }
52
+ if (/^(goto|click|dblclick|press|select|check|uncheck)$/.test(step.do))
53
+ await s.settle(1500);
54
+ }
55
+ }
56
+ catch (e) {
57
+ ok = false;
58
+ lines.push(`โœ— ${String(e?.message || e).split('\n')[0]}`);
59
+ }
60
+ if (!ok && s.page && !s.page.isClosed()) {
61
+ try {
62
+ url = s.page.url();
63
+ const buf = await s.page.screenshot({ type: 'jpeg', quality: 60 });
64
+ screenshot = buf.toString('base64');
65
+ shotFile = path.join(FLOW_DIR(), 'artifacts', `${safe(name)}-${Date.now()}.jpg`);
66
+ await fs.mkdir(path.dirname(shotFile), { recursive: true });
67
+ await fs.writeFile(shotFile, buf);
68
+ }
69
+ catch { /* page gone */ }
70
+ }
71
+ const ev = s.takeEvidence();
72
+ const evidence = [...ev.pageErrors.map((x) => 'pageerror: ' + x), ...ev.console.filter((x) => x.startsWith('[error]')), ...ev.failedRequests];
73
+ if (shared?.browser)
74
+ await s.closeContext();
75
+ else
76
+ await s.close();
77
+ return { name, ok, ms: Date.now() - t0, lines, failedAt, evidence, screenshot, shotFile, url, started };
78
+ }
79
+ /** Exports a flow as a Playwright Test spec. */
80
+ export async function exportFlow(name) {
81
+ const flow = await loadFlow(name);
82
+ const body = flow.steps.map((s) => ' ' + (s.code ?? `// ${s.do} ${s.target ?? ''} ${s.value ?? ''}`)).join('\n');
83
+ const code = `import { test, expect } from '@playwright/test';
84
+
85
+ // Generated by fastqa-mcp from flow "${flow.name}" (${flow.created})
86
+ // Templated values read FASTQA_VAR_<name> environment variables.
87
+ test(${JSON.stringify(flow.name)}, async ({ page }) => {
88
+ ${body}
89
+ });
90
+ `;
91
+ const file = path.join(FLOW_DIR(), 'tests', `${safe(name)}.spec.ts`);
92
+ await fs.mkdir(path.dirname(file), { recursive: true });
93
+ await fs.writeFile(file, code);
94
+ return { file, code };
95
+ }
96
+ /** Reads a CSV data file (header row = variable names). Looks in .fastqa/data/<name>.csv when given a bare name. */
97
+ export async function loadDataset(nameOrPath) {
98
+ const p = /[\\/]|\.csv$/i.test(nameOrPath) ? path.resolve(nameOrPath) : path.join(FLOW_DIR(), 'data', `${safe(nameOrPath)}.csv`);
99
+ const rows = (await fs.readFile(p, 'utf8')).split(/\r?\n/).filter((l) => l.trim()).map(splitCsv);
100
+ const [head, ...data] = rows;
101
+ return data.map((r) => Object.fromEntries(head.map((h, i) => [h.trim(), (r[i] ?? '').trim()])));
102
+ }
103
+ function splitCsv(line) {
104
+ const out = [];
105
+ let cur = '';
106
+ let inQ = false;
107
+ for (let i = 0; i < line.length; i++) {
108
+ const c = line[i];
109
+ if (inQ) {
110
+ if (c === '"' && line[i + 1] === '"') {
111
+ cur += '"';
112
+ i++;
113
+ }
114
+ else if (c === '"')
115
+ inQ = false;
116
+ else
117
+ cur += c;
118
+ }
119
+ else if (c === '"')
120
+ inQ = true;
121
+ else if (c === ',') {
122
+ out.push(cur);
123
+ cur = '';
124
+ }
125
+ else
126
+ cur += c;
127
+ }
128
+ out.push(cur);
129
+ return out;
130
+ }
131
+ /** Runs flows, optionally once per dataset row, then writes an HTML report and a JUnit XML file. */
132
+ export async function runSuite(names, vars, dataset, shared) {
133
+ const rows = dataset ? await loadDataset(dataset) : [{}];
134
+ const runs = [];
135
+ for (const n of names) {
136
+ for (let i = 0; i < rows.length; i++) {
137
+ const r = await runFlow(n, { ...vars, ...rows[i] }, shared);
138
+ if (dataset)
139
+ r.name = `${n} [row ${i + 1}: ${Object.entries(rows[i]).filter(([k]) => !/pass|pwd|secret|token|key|card|cc/i.test(k)).map(([, v]) => v).join(', ').slice(0, 40)}]`;
140
+ runs.push(r);
141
+ }
142
+ }
143
+ const { writeReports } = await import('./report.js');
144
+ const files = await writeReports(runs, FLOW_DIR());
145
+ return { runs, ...files };
146
+ }