mcp-test-runner
v0.4.3[DEPRECATED — renamed to mk-qa-master] MCP server for running tests across pytest / Jest / Cypress / Go test / Maestro.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
get_runner_info
回傳目前由 QA_RUNNER 環境變數選定的測試 runner(pytest / jest / cypress / go / maestro 五選一)加上 server 編譯時內建的全部 runner 清單。建議每個 session 第一個呼叫——AI 用它判斷後續該產 Playwright .py 還是 Maestro .yaml、要不要 headed browser,避免後面拿錯模板。也用來確認專案環境設定正確:QA_PROJECT_ROOT 指對地方、QA_RUNNER 沒拼錯。回傳 shape:{active: 'pytest', available: ['pytest', 'jest', ...]}。
list_tests
用 runner 的原生 collection 機制列出受測專案內所有可執行測試:pytest 走 `pytest --collect-only`、Jest 走 `npx jest --listTests`、Cypress 走 `cypress/e2e/*.cy.*` glob、Go 走 `go test -list .*`、Maestro 走 `*.yaml` 遞迴掃。回傳一份逐行 nodeid / 檔名清單。用法:run_tests 前確認 collection 沒漏、generate_test 前避免跟既有 case 重複。
run_tests
Execute the test suite under the active QA_RUNNER and produce a structured report. The single most-called tool — invoke whenever a user says 「跑/run/test/check/驗證/執行」, after generate_test (verify new test), or after a fix (confirm bug gone). Behavior: - Invokes the runner's native CLI under QA_PROJECT_ROOT — pytest with --screenshot=on / --tracing=on / --video=retain-on-failure, or `npx jest --json`, `npx cypress run --reporter json`, `go test -json`, `maestro test --format junit` - Optional `filter` narrows the scope: pytest -k expr, jest -t pattern, cypress --spec g…
| Parameter | Type | Description |
|---|---|---|
browser | string | 選填,僅對 pytest-playwright 有效,指定 Playwright 啟用的 browser engine。需事先 `playwright install <browser>` 過。 |
filter | string | 選填,測試名稱關鍵字。pytest 走 -k 表達式(支援 and/or/not)、Jest 走 -t、Cypress 走 --spec '**/*<filter>*'、Go 走 -run regex、Maestro 在 flow 檔名作子字串比對。 |
headed | boolean | 選填,僅對 pytest-playwright 有效。True 時瀏覽器有 UI 模式跑(適合 debug、看 flake 視覺現象);預設 headless 跑、CI / 大量套件用這個。 |
run_failed
只重跑上次失敗的測試——比跑整套套件快很多,適合修完一個 bug 後驗證迭代。pytest 走 `--lf`(last-failed)、Jest 走 `--onlyFailures`、Cypress 解析上次 report.json 的 failures[] 反查 spec 重跑、Go 撈失敗的 Test 名組成 regex 餵 -run、Maestro 反查 nodeid 對應 .yaml 重跑。需要先有過一次 run_tests(不然 report.json 不存在)。回傳 shape 跟 run_tests 一樣,接 get_test_report / get_failure_details 同樣方式檢視。
get_test_report
讀上一次 run_tests 留下的 report.json,回傳一個輕量摘要:total / passed / failed / skipped / flaky_in_run(auto-retry 救回的數量)/ duration(秒)。比再跑一次 suite 便宜得多——適合在連續操作中間反覆查狀態。未跑過時回 {error: 找不到報告,請先執行 run_tests}。拿到摘要後若 failed > 0,接 get_failure_details 拿錯誤細節。
get_failure_details
Extract full root-cause-analysis materials for every failed test in the most recent run. Behavior: - Reads report.json, filters tests where outcome == 「failed」 - pytest: parses Playwright trace.zip → extracts real API call sequence (Frame.*, Page.*, Locator.*, ElementHandle.* events) as steps[] - Maestro: parses flow YAML for `takeScreenshot:` directives → resolves <name>.png at PROJECT_ROOT root - Best-effort resolves screenshot / trace.zip / video / recording paths from --output / --debug-output artifact directories Returns: list[{nodeid, title, message, duration, steps[], scr…
| Parameter | Type | Description |
|---|---|---|
test_id | string | 選填,僅回傳 nodeid 含此關鍵字的 case(substring match,不分大小寫)。省略則回傳全部失敗 case。常用模式:先全部抓→看到特定模式後再用 test_id 收斂々 |
generate_test
產生 pytest-playwright 測試骨架。推薦流程:先呼叫 analyze_url 拿 candidate_tcs,再對每條想覆蓋的 TC 呼叫一次 generate_test、把該 candidate_tc 整段字串當 description 傳入 — 這段會自動寫成 test 函式的 docstring,HTML 報告會把它當作 case 名稱顯示。若提供 url+module(來自 analyze_url 的 modules[]),會用 selectors 預填可執行版本。若想一次處理整個 URL、不想自己編排,請改用 auto_generate_tests。
| Parameter | Type | Description |
|---|---|---|
description * | string | test 的描述文字。會直接寫成產出 test 函式的 docstring(pytest)或 YAML 開頭註解(Maestro),HTML 報告會用這段當 case 名稱顯示。建議直接傳 analyze_url / analy… |
filename * | string | 輸出檔名,相對於 PROJECT_ROOT。pytest 用 .py、Maestro 用 .yaml、Jest 用 .test.js、Cypress 用 .cy.js、Go 用 _test.go。不可絕對路徑、不可含 `..`(會被 security guardrail… |
business_context | string | 選填,業務規則 / 歷史 Bug / 標準斷言文字 等領域知識。提供後會以 `# Business context:` 註解區塊印進 test 函式內,讓人類 reviewer 與後續 AI 都能看到設計ä¾… |
module | object | 選填,analyze_url 結果 modules[] 中的一個項目;提供後會用 selectors 預填 |
url | string | 選填,受測 URL;提供後 page.goto 會預填 |
codegen
Launch interactive test recording for the active runner. Useful as a baseline-builder before refining with generate_test. Behavior: - pytest-playwright: spawns `playwright codegen -o <output> <url>` — a real Chromium window opens, you click / type / navigate, Playwright transcribes every action into runnable pytest code, output is saved to PROJECT_ROOT/<output> on browser close - Maestro: returns a human-readable hint string pointing at `maestro studio` (no shell-able codegen exists for it) - jest / cypress / go runners: same Maestro-style fallback hint Returns: a string with the sa…
| Parameter | Type | Description |
|---|---|---|
url * | string | 受測 URL。Playwright codegen 會開瀏覽器 navigate 到此網址、從這頁開始錄製你的互動。 |
output | string | 選填,輸出檔名(相對於 PROJECT_ROOT,不可絕對路徑、不可含 `..`)。預設 `recorded_test.py`。 |
generate_html_report
把最近一次 run_tests 的結果渲染成單檔自包含 HTML——base64 內嵌截圖、嵌入式 step list、history sparkline 走勢、折疊的 Passed 區塊、展開的 Failed cards。沒外部 CSS/JS 依賴,可以直接寄信、丟靜態 host、貼到 Slack。預設輸出 PROJECT_ROOT/report.html。實作位於 reporters/html.py,走 sample_report.html 同款設計。
| Parameter | Type | Description |
|---|---|---|
output | string | 選填,輸出檔名(相對於 QA_PROJECT_ROOT)。預設 `report.html`。 |
get_test_history
遍歷 test-results/history/*.json 快照(每次 run_tests 完會自動歸檔),回傳逐次摘要:timestamp / total / passed / failed / skipped / duration / pass_rate(0-100)。用於 flake 分析(『這條測試上週一直 fail 嗎』)、速度退化分析(『duration 是不是越來越長』)、覆蓋趨勢圖。預設回最近 10 次,limit 可調 1-100。想要可執行行動建議的話接 get_optimization_plan,它已綜合 history + telemetry。
| Parameter | Type | Description |
|---|---|---|
limit | integer | 選填,回最近 N 次 run 的摘要。1-100,預設 10。長期 flake 分析建議 30+。 |
get_optimization_plan
綜合 history/ 快照、telemetry tool-usage、analyze_url 偵測過的 modules,產出三層自我強化分析:(1) 測試套件品質:每條 test 算 outcomes 字串(PFPFP 那種)→ flake_score、再對失敗 error signature 做指紋比對,連 3 次相同 signature 升級為 broken,duration 退化超 1.5x 標記 slow_regression,否則 stable_passing;(2) MCP 使用模式:top tool、重複 args、錯誤率、常見呼叫鏈(A→B 共現);(3) AI 產測效益:generate_test 寫的 test 有沒有出現在下一次 run、analyze_url 偵測到的 module 對不對得到 t…
| Parameter | Type | Description |
|---|---|---|
history_limit | integer | 選填,套件品質分析會看最近 N 次 history 快照。1-100,預設 10。flake score 至少要 5 次以上才穩,深度分析建議 30+。 |
telemetry_limit | integer | 選填,MCP 使用模式分析會看 telemetry 最近 N 筆 tool-call。10-5000,預設 500。長期使用模式分析拉到 2000+,近期問題排查 100-200 就夠。 |
analyze_url
Probe a live web page in headless Chromium and return a structured map of testable modules plus the API endpoints the page actually called. The web counterpart of analyze_screen. Behavior: - page.goto(url) with DOMContentLoaded + 5s networkidle wait - DOM probe extracts five module kinds: form (with fields[] + required flags), nav (link lists), dialog (modal containers), section (labeled regions), cta (action buttons matching action keywords like 登入/送出/ Login/Submit) - Each module gets a candidate_tcs[] — domain-aware test case strings ready to paste into generate_test - Reco…
| Parameter | Type | Description |
|---|---|---|
url * | string | 要分析的網頁 URL,需含 protocol(http:// 或 https://)。 |
auth_cookie | string | 選填,預先注入登入 cookie,格式:`name1=value1; name2=value2`(一行 cookie header)。用法:先在瀏覽器 DevTools / Application / Cookies 複製值再貼進來。用於分析需… |
timeout_ms | integer | 選填,page.goto 等待 DOMContentLoaded 的逾時毫秒數。之後額外 wait 5 秒讓 networkidle(XHR 載入)穩定。預設 15000。慢站 / 需要 SSR / 重 JS hydration 的網站可拉到… |
analyze_screen
Mobile 版的 analyze_url:透過 `maestro hierarchy` dump 當前 iOS Simulator / Android Emulator / 實體機 / BlueStacks(透過 QA_ANDROID_HOST)前景 app 的 view tree,再分類成 form(具 hint_text 的輸入欄位)、cta(enabled + 有文字的可點元件)、tab_bar(selected 狀態 + 同 y 對齊的 2+ 個 tab)三種 modules 並附 candidate_tcs。內建 noise filter 自動排除 iOS 狀態列 + asset 命名標籤(bg_* / *_filled / 純數字 / 單一 ASCII 字元等)讓結果信號集中。需 Maestro CLI 已裝、裝置 booted、app 已在前景。若給 app_id +…
| Parameter | Type | Description |
|---|---|---|
app_id | string | 選填,bundle id (iOS) / package name (Android),格式如 `com.example.app`。搭配 launch_app=true 使用,或為了在輸出標註是分析哪個 app。 |
launch_app | boolean | 搭配 app_id:True 時在 hierarchy dump 前用 maestro launchApp 啟動 app。用 clearState: false(保留 app 狀態),確保看到「真實」起始畫面。省略則假設裝置上 app 已æ… |
timeout_ms | integer | 選填,hierarchy 命令超時毫秒。預設 30000;BlueStacks / 遠端 ADB 較慢,QA_ANDROID_HOST 有設時會自動拉到 60000 起跳。 |
init_qa_knowledge
在受測專案根 (PROJECT_ROOT) 建立 qa-knowledge.md 起手範本,含業務規則 / 歷史 Bug / 標準斷言文字 / User Journeys / 技術約束 5 個 H2 區段,每段都有 TODO 提示。Idempotent:檔已存在不會覆蓋(除非 overwrite=true)。新用戶建議第一次跑 MCP 就先 call 一次。這份檔案後續會被 get_qa_context 讀、做為 business_context 傳進 generate_test,讓 AI 寫出有業務邏輯的測試(而不是泛例 monkey testing)。
| Parameter | Type | Description |
|---|---|---|
overwrite | boolean | 強制覆蓋既存檔案(會丟失你已填的內容、請先備份) |
get_qa_context
讀取受測專案的 qa-knowledge.md(業務規則 / 歷史 Bug / 標準斷言文字 / User Journeys 等領域知識),用 ## H2 區段拆分。用法:先 call 拿到整份或指定 section,再把相關段落以 business_context 傳給 generate_test,產出的 test 就會自帶業務知識註解 — 跳脫 monkey testing。若檔案不存在會 fallback 到內建的 ISTQB 七大原則 + 等價分割 + 邊界值 + 決策表 + 狀態轉換 + Mobile checklist 通用知識,先用著也可以;之後跑 init_qa_knowledge 建立專案專屬版本。
| Parameter | Type | Description |
|---|---|---|
section | string | 選填,只取單一 H2 section(不區分大小寫、支援部分匹配)。省略則回整份檔 + 所有 section 名稱清單。 |
auto_generate_tests
一鍵交付:在內部依序做 analyze_url → 為每個偵測到的 module 用 candidate_tcs 內容各跑一次 generate_test,把整套 pytest 測試骨架寫進 PROJECT_ROOT/tests/。等同於『analyze_url 後對每個 module 手動跑 N 次 generate_test』的自動化版本,適合「給我一個 URL、其他你看著辦」這種快速覆蓋場景。每條 candidate_tc 變成對應 test 函式的 docstring,run_tests 跑完 HTML 報告會用 docstring 當 case 名稱顯示。回傳產生的檔案路徑列表 + 每個 module 對應幾個 test。預設每個 module 1 條,想要更å…
| Parameter | Type | Description |
|---|---|---|
url * | string | 要分析並批次產測的 URL,需含 protocol(http:// 或 https://)。 |
auth_cookie | string | 選填,登入後分析所需 cookie,格式:`name1=value1; name2=value2`。從 DevTools / Application / Cookies 抓現成值貼進來。 |
tests_per_module | integer | 選填,每個 module 從 candidate_tcs 取前 N 條各產一條 test。1-10,預設 1(最少噪音)。想要更密的覆蓋拉 3-5;拉到 10 通常會產 garbage tests,因為 candidate_tcs… |
timeout_ms | integer | 選填,analyze_url 內部 page.goto 等 DOMContentLoaded 的逾時毫秒。預設 15000,慢站可拉到 30000+。 |