Skip to main content
Glama
qa-triage-mcp
by mnawaz6935
README.md
# qa-triage-mcp

[![tests](https://github.com/mnawaz6935/qa-triage-mcp/actions/workflows/tests.yml/badge.svg)](https://github.com/mnawaz6935/qa-triage-mcp/actions/workflows/tests.yml)
![python](https://img.shields.io/badge/python-3.11%2B-blue)
![mcp](https://img.shields.io/badge/MCP%20Python%20SDK-v2.3-purple)
![license](https://img.shields.io/badge/license-MIT-green)

An MCP server that helps an AI assistant triage failed test runs. You give it JUnit XML from your CI, and Claude, Cursor or your own agent can tell you why the build went red, which tests are flaky, when a test started failing, and draft the bug report.

I'm Muhammad Nawaz. I built this around a problem anyone in QA automation knows: the slow part is rarely writing tests. It's the morning after a nightly run with 30 red tests, working out that 28 of them are one dead service, 2 are a real bug and 1 is that checkout test that always times out. Most AI tools for testing help you *run* tests (Playwright MCP, for example, drives a browser). I wanted one that reads the results history and does the triage.

It works with pretty much any framework, because nearly all of them can write JUnit XML:

| Framework | How to get JUnit XML |
|---|---|
| pytest | `pytest --junitxml=reports/run.xml` |
| Playwright | `reporter: [['junit', { outputFile: 'reports/run.xml' }]]` |
| Cypress | `--reporter junit` |
| Jest | `jest-junit` reporter |
| JUnit / TestNG (Maven, Gradle) | Surefire / Gradle test reports, already JUnit XML |
| Robot Framework | `robot --xunit reports/run.xml` |

## What it looks like

This is a real run of the included OpenAI agent (`gpt-5.4-mini`) against the demo data, trimmed to fit. The latest nightly run has 31 failures:

```text
> Last night's CI run has a lot of red tests. Why did it fail, and what should I do about each problem?
  -> list_runs({})
  -> get_run_failures({'run_id': 30, 'limit': 200})
  -> cluster_failures({'run_id': 30})
  -> compare_runs({'head_run_id': 30, 'base_run_id': 29})

Last night's CI failed for three distinct reasons...

1) Main failure: inventory-service was unreachable
   28 errors with the same signature: ConnectionRefusedError: ... inventory-service:8443
   earlier_runs_with_same_error: 0, so this looks new, not a long-standing flaky issue.

2) Two pricing unit tests are failing consistently
   price mismatch: expected 107.99, got 108.00 / expected 15.00, got 20.00
   earlier_runs_with_same_error: 6, still failing from run 29 to 30.

3) One end-to-end checkout test timed out waiting for a pay button
   TimeoutError waiting for locator('#pay-now'). The same error has appeared before,
   so this is likely a known UI timing/locator fragility.
```

So 31 red tests became 3 causes, each with evidence attached. The full answer also had a next step for each one. Asking "which tests are flaky?" or "when did test_discount_stacking start failing?" gets you `find_flaky_tests` and `test_history`. The second one comes back with run 24 and the commit it started on.

## Tools, resources, prompts

| Kind | Name | What it's for |
|---|---|---|
| Tool | `list_report_files` | JUnit files in the reports folder, and which ones are already loaded |
| Tool | `ingest_junit_report` | Load a report. Branch, commit and CI job come from the report's `<properties>` or can be passed in. Loading the same file twice does nothing |
| Tool | `list_runs` | Recent runs with pass/fail counts |
| Tool | `get_run_failures` | Every failed or errored test in a run |
| Tool | `cluster_failures` | Groups failures by root cause, with a category hint and how many earlier runs had the same error |
| Tool | `find_flaky_tests` | Tests that flip between pass and fail. Failing and passing on the same commit is flagged, since that's the clearest sign |
| Tool | `compare_runs` | New failures, fixed, still failing, added and removed tests |
| Tool | `test_history` | One test over time: pass rate, current streak, and the run and commit where it started failing |
| Tool | `quarantine_test` | Mark a flaky test as quarantined. Dry run by default |
| Tool | `run_readonly_query` | Ad-hoc SQL over the results, read-only |
| Resource | `qa://schema`, `qa://runs/latest`, `qa://quarantine` | Schema, latest run summary, quarantined tests |
| Prompt | `triage_failed_run` | Walks through clusters, history and flakiness, and ends with a table of causes and next actions |
| Prompt | `flaky_test_report` | Ranked flaky tests with a suggested fix for each |
| Prompt | `draft_bug_report` | A ticket-ready bug for one failing test, built from its history. If the test turns out to be flaky, it says so instead |

## How failures get grouped

Two failures belong together if they have the same normalised error. The server takes the first line of the message and replaces the parts that change from run to run (numbers, UUIDs, hex ids, timestamps, temp paths) with placeholders:

```text
ConnectionRefusedError: [Errno 111] Connection refused: inventory-service:8443 (attempt 2/3)
ConnectionRefusedError: [Errno 111] Connection refused: inventory-service:8443 (attempt 1/3)
  -> ConnectionRefusedError: [Errno <n>] Connection refused: inventory-service:<n> (attempt <n>/<n>)
```

Hostnames, selectors and words stay, because that's where the meaning is. `locator('#pay-now')` and `locator('#login')` are different problems.

I kept this simple on purpose. It's a handful of regexes, not machine learning, so when two failures end up in the same cluster you can see exactly why. It won't catch every case, and that's fine for a first pass the model then checks against history.

A test counts as flaky if it has both passed and failed recently, and it either flipped at least twice or failed and passed on the same commit. A test that broke once and stayed broken is left out on purpose. That's a regression, and it's what `test_history` is for.

## Safety

Test reports come from CI artifacts, so the server doesn't trust them. And it's an LLM calling the tools, so I assume it'll eventually call one with something wrong.

- The server won't read reports from anywhere except one configured folder. Paths are resolved (following `..` and symlinks) and anything that ends up outside the folder is refused. Only `.xml`, max 20 MB.
- XML is parsed with `defusedxml` and DTDs are forbidden. That blocks XXE (a report that tries to read a local file through an entity) and entity-expansion bombs. There are tests for both.
- The model can't write SQL that changes anything. The only way data gets in is `ingest_junit_report`, which runs my own parameterised inserts in one transaction.
- `run_readonly_query` goes through five checks: a read-only connection (`mode=ro`), `PRAGMA query_only`, an authorizer callback that only allows reads, single `SELECT`/`WITH` statements only, and a 200-row cap with a 2 second timeout.
- `quarantine_test` is a dry run unless the model passes `dry_run=false`, and the agents' system prompts say to only do that after the user confirms. Even then it only appends to `quarantine.jsonl`. It doesn't touch test results.
- Every argument is typed with Pydantic (ranges, enums, regex patterns for branch names and commit SHAs), so bad input is rejected before any tool code runs. Expected problems come back as `ToolError`, which the model sees as `isError: true` and can recover from.
- Logs are JSON lines on stderr (stdout is the protocol channel in stdio mode). Each tool call is logged with an id, its arguments, how long it took and whether it worked.

## Running it

You need [uv](https://docs.astral.sh/uv/) and Python 3.11+.

```bash
uv sync
uv run python -m qa_triage.demo     # builds data/qa.db from the 30 demo reports in examples/reports
uv run pytest -q                    # 39 tests, about 6 seconds
```

Start the server:

```bash
uv run python -m qa_triage                                   # stdio
uv run python -m qa_triage --transport http --port 8000      # Streamable HTTP on /mcp
uv run python -m qa_triage --reports-dir /path/to/your/ci/reports   # your own results
```

Try an agent:

```bash
export OPENAI_API_KEY=...       # or ANTHROPIC_API_KEY for agent/agent.py
uv run python agent/agent_openai.py "Why did last night's run fail?"
uv run python agent/agent.py "Which tests are flaky?"
uv run python agent/agent.py --list-tools      # checks the connection only, no API call
```

`agent.py` uses the Anthropic SDK's tool runner. In `agent_openai.py` I wrote the loop by hand: turn each MCP tool into an OpenAI function, call the model, run the tools it asks for, send the results back, and give up after 12 rounds.

## Using it with your own test results

1. Have CI write JUnit XML into a folder. Add branch and commit as properties if your runner supports it, or pass them to `ingest_junit_report`.
2. Start the server with `--reports-dir` pointing at that folder.
3. Ask your assistant to load the new reports and triage the latest run.

## Connecting a client

Put your clone's path in place of `C:/path/to/qa-triage-mcp` in `configs/*.json`, then:

- Claude Desktop: merge `configs/claude_desktop_config.json` into your `claude_desktop_config.json` and restart.
- Claude Code: copy `configs/claude_code.mcp.json` to `.mcp.json`, or run `claude mcp add qa-triage -- uv --directory /path/to/qa-triage-mcp run python -m qa_triage`.
- Cursor: copy `configs/cursor.mcp.json` to `.cursor/mcp.json`.

In Claude Code the three prompts show up in the `/` menu, so you can start a triage without typing out the steps.

## The demo data

`examples/reports/` has 30 nightly runs of a made-up web shop's suite (75 tests across e2e, API and unit). It's generated by `qa_triage/demo.py` with a fixed seed, and four things are planted in it:

- 3 flaky tests. Runs 12 and 13 are a CI retry on the same commit, and two of them flip between those.
- A real regression: two pricing tests start failing at run 24 and stay failed.
- An outage in run 30: all 28 tests that call inventory-service fail with "connection refused".
- One test that's always skipped.

The tests check that the server finds all four, so if I break the clustering I'll know.

## Layout

```text
qa_triage/
  server.py          tools, resources, prompts
  junit.py           safe JUnit parsing, error signatures, category hints
  store.py           the only code that writes to the database
  db.py              read-only SQLite access with the five checks
  demo.py            demo report generator
  logging_setup.py   JSON logs, @audited decorator, redaction
  __main__.py        CLI: --transport, --host, --port, --db, --reports-dir
agent/               Claude agent and OpenAI agent
examples/reports/    30 demo JUnit reports
tests/               39 tests
configs/             Claude Desktop, Claude Code, Cursor
```

## Tests

The server tests connect the SDK's `Client` straight to the server object in the same process. That's the real protocol, without spawning anything. They cover:

- clustering, flaky detection, history and run comparison against the planted demo data
- ingesting a Playwright-style report on a feature branch
- path escapes (`../`, absolute paths, wrong extension) and XXE / entity-bomb reports
- input validation on every kind of argument
- seven write attempts against the SQL tool, each followed by a check that nothing changed
- the quarantine dry-run behaviour

CI runs them on Ubuntu and Windows with Python 3.11, 3.12 and 3.13.

## SDK notes

It's on v2 of the official [`mcp` Python SDK](https://github.com/modelcontextprotocol/python-sdk), where `FastMCP` was renamed `MCPServer`. The separate `fastmcp` package on PyPI is a different, third-party project. In-protocol logging (`ctx.info()`) was deprecated in the 2026-07-28 spec, so the server logs to stderr instead.

## What I'd add next

- Read reports straight from GitHub Actions / GitLab CI artifacts instead of a local folder
- Link a failing streak to the commits in that range (`git log base..head`) to point at the likely change
- Allure and TRX (.NET) report formats
- Slowest and slowing-down tests (the durations are already stored)
- Write quarantine decisions to a pytest/Playwright skip list CI can read
- Postgres for teams with a lot of history

## Author

Built by **Muhammad Nawaz**.

## License

MIT. See [LICENSE](LICENSE).

TDQS

A3.7/5.0

Scored across 10 tools

Disambiguation5/5

Each tool has a clearly distinct job: file listing, ingestion, run listing, raw failures, clustered failures, flakiness, diffs, per-test history, quarantine, and a constrained SQL escape hatch. The closest pairs (get_run_failures vs cluster_failures, find_flaky_tests vs test_history) are explicitly differentiated in their descriptions. run_readonly_query is the only potentially overlapping tool, and it is explicitly gated as a last resort.

Naming Consistency4/5

Nearly all tools follow a verb_noun convention (list_report_files, ingest_junit_report, cluster_failures, compare_runs, quarantine_test). The one deviation is test_history, which is noun-only rather than get_test_history, but it remains readable and predictable.

Tool Count5/5

Ten tools is well within the sweet spot and each one covers a distinct step of the triage workflow. Nothing feels padded or redundant; the escape hatch is justified given the domain.

Completeness4/5

The surface covers the full triage lifecycle: ingest, list, inspect, cluster, diff, history, and quarantine. The main gap is no explicit un-quarantine/release tool, so removing a test from quarantine.jsonl has no dedicated path (only the raw query tool).

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues