digital-ai-testing-mcp 1.2.2

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.
Files changed (333) hide show
  1. package/LICENSE +197 -0
  2. package/README.md +984 -0
  3. package/dist/api/agents.d.ts +5 -0
  4. package/dist/api/agents.d.ts.map +1 -0
  5. package/dist/api/agents.js +33 -0
  6. package/dist/api/agents.js.map +1 -0
  7. package/dist/api/applications.d.ts +35 -0
  8. package/dist/api/applications.d.ts.map +1 -0
  9. package/dist/api/applications.js +162 -0
  10. package/dist/api/applications.js.map +1 -0
  11. package/dist/api/backup.d.ts +4 -0
  12. package/dist/api/backup.d.ts.map +1 -0
  13. package/dist/api/backup.js +13 -0
  14. package/dist/api/backup.js.map +1 -0
  15. package/dist/api/browser-inspection.d.ts +33 -0
  16. package/dist/api/browser-inspection.d.ts.map +1 -0
  17. package/dist/api/browser-inspection.js +273 -0
  18. package/dist/api/browser-inspection.js.map +1 -0
  19. package/dist/api/browsers.d.ts +20 -0
  20. package/dist/api/browsers.d.ts.map +1 -0
  21. package/dist/api/browsers.js +31 -0
  22. package/dist/api/browsers.js.map +1 -0
  23. package/dist/api/client.d.ts +33 -0
  24. package/dist/api/client.d.ts.map +1 -0
  25. package/dist/api/client.js +200 -0
  26. package/dist/api/client.js.map +1 -0
  27. package/dist/api/device-groups.d.ts +15 -0
  28. package/dist/api/device-groups.d.ts.map +1 -0
  29. package/dist/api/device-groups.js +106 -0
  30. package/dist/api/device-groups.js.map +1 -0
  31. package/dist/api/devices.d.ts +32 -0
  32. package/dist/api/devices.d.ts.map +1 -0
  33. package/dist/api/devices.js +192 -0
  34. package/dist/api/devices.js.map +1 -0
  35. package/dist/api/license.d.ts +3 -0
  36. package/dist/api/license.d.ts.map +1 -0
  37. package/dist/api/license.js +11 -0
  38. package/dist/api/license.js.map +1 -0
  39. package/dist/api/nv-servers.d.ts +4 -0
  40. package/dist/api/nv-servers.d.ts.map +1 -0
  41. package/dist/api/nv-servers.js +20 -0
  42. package/dist/api/nv-servers.js.map +1 -0
  43. package/dist/api/projects.d.ts +36 -0
  44. package/dist/api/projects.d.ts.map +1 -0
  45. package/dist/api/projects.js +246 -0
  46. package/dist/api/projects.js.map +1 -0
  47. package/dist/api/provisioning-profiles.d.ts +7 -0
  48. package/dist/api/provisioning-profiles.d.ts.map +1 -0
  49. package/dist/api/provisioning-profiles.js +54 -0
  50. package/dist/api/provisioning-profiles.js.map +1 -0
  51. package/dist/api/regions.d.ts +4 -0
  52. package/dist/api/regions.d.ts.map +1 -0
  53. package/dist/api/regions.js +20 -0
  54. package/dist/api/regions.js.map +1 -0
  55. package/dist/api/reporter-projects.d.ts +3 -0
  56. package/dist/api/reporter-projects.d.ts.map +1 -0
  57. package/dist/api/reporter-projects.js +13 -0
  58. package/dist/api/reporter-projects.js.map +1 -0
  59. package/dist/api/reporting.d.ts +28 -0
  60. package/dist/api/reporting.d.ts.map +1 -0
  61. package/dist/api/reporting.js +340 -0
  62. package/dist/api/reporting.js.map +1 -0
  63. package/dist/api/repository.d.ts +17 -0
  64. package/dist/api/repository.d.ts.map +1 -0
  65. package/dist/api/repository.js +81 -0
  66. package/dist/api/repository.js.map +1 -0
  67. package/dist/api/reservations.d.ts +9 -0
  68. package/dist/api/reservations.d.ts.map +1 -0
  69. package/dist/api/reservations.js +72 -0
  70. package/dist/api/reservations.js.map +1 -0
  71. package/dist/api/sessions.d.ts +3 -0
  72. package/dist/api/sessions.d.ts.map +1 -0
  73. package/dist/api/sessions.js +12 -0
  74. package/dist/api/sessions.js.map +1 -0
  75. package/dist/api/test-views.d.ts +9 -0
  76. package/dist/api/test-views.d.ts.map +1 -0
  77. package/dist/api/test-views.js +77 -0
  78. package/dist/api/test-views.js.map +1 -0
  79. package/dist/api/transactions.d.ts +4 -0
  80. package/dist/api/transactions.d.ts.map +1 -0
  81. package/dist/api/transactions.js +28 -0
  82. package/dist/api/transactions.js.map +1 -0
  83. package/dist/api/usage-reports.d.ts +24 -0
  84. package/dist/api/usage-reports.d.ts.map +1 -0
  85. package/dist/api/usage-reports.js +47 -0
  86. package/dist/api/usage-reports.js.map +1 -0
  87. package/dist/api/users.d.ts +14 -0
  88. package/dist/api/users.d.ts.map +1 -0
  89. package/dist/api/users.js +77 -0
  90. package/dist/api/users.js.map +1 -0
  91. package/dist/api/webdriver.d.ts +97 -0
  92. package/dist/api/webdriver.d.ts.map +1 -0
  93. package/dist/api/webdriver.js +1183 -0
  94. package/dist/api/webdriver.js.map +1 -0
  95. package/dist/index.d.ts +3 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +130 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/tools/agent-tools.d.ts +3 -0
  100. package/dist/tools/agent-tools.d.ts.map +1 -0
  101. package/dist/tools/agent-tools.js +74 -0
  102. package/dist/tools/agent-tools.js.map +1 -0
  103. package/dist/tools/application-tools.d.ts +3 -0
  104. package/dist/tools/application-tools.d.ts.map +1 -0
  105. package/dist/tools/application-tools.js +816 -0
  106. package/dist/tools/application-tools.js.map +1 -0
  107. package/dist/tools/backup-tools.d.ts +3 -0
  108. package/dist/tools/backup-tools.d.ts.map +1 -0
  109. package/dist/tools/backup-tools.js +33 -0
  110. package/dist/tools/backup-tools.js.map +1 -0
  111. package/dist/tools/boilerplate-tools.d.ts +9 -0
  112. package/dist/tools/boilerplate-tools.d.ts.map +1 -0
  113. package/dist/tools/boilerplate-tools.js +1365 -0
  114. package/dist/tools/boilerplate-tools.js.map +1 -0
  115. package/dist/tools/browser-tools.d.ts +3 -0
  116. package/dist/tools/browser-tools.d.ts.map +1 -0
  117. package/dist/tools/browser-tools.js +108 -0
  118. package/dist/tools/browser-tools.js.map +1 -0
  119. package/dist/tools/coverage-tools.d.ts +3 -0
  120. package/dist/tools/coverage-tools.d.ts.map +1 -0
  121. package/dist/tools/coverage-tools.js +148 -0
  122. package/dist/tools/coverage-tools.js.map +1 -0
  123. package/dist/tools/debug-tools.d.ts +3 -0
  124. package/dist/tools/debug-tools.d.ts.map +1 -0
  125. package/dist/tools/debug-tools.js +315 -0
  126. package/dist/tools/debug-tools.js.map +1 -0
  127. package/dist/tools/device-group-tools.d.ts +3 -0
  128. package/dist/tools/device-group-tools.d.ts.map +1 -0
  129. package/dist/tools/device-group-tools.js +284 -0
  130. package/dist/tools/device-group-tools.js.map +1 -0
  131. package/dist/tools/device-tools.d.ts +3 -0
  132. package/dist/tools/device-tools.d.ts.map +1 -0
  133. package/dist/tools/device-tools.js +757 -0
  134. package/dist/tools/device-tools.js.map +1 -0
  135. package/dist/tools/health-tools.d.ts +3 -0
  136. package/dist/tools/health-tools.d.ts.map +1 -0
  137. package/dist/tools/health-tools.js +368 -0
  138. package/dist/tools/health-tools.js.map +1 -0
  139. package/dist/tools/inspection-tools.d.ts +3 -0
  140. package/dist/tools/inspection-tools.d.ts.map +1 -0
  141. package/dist/tools/inspection-tools.js +1170 -0
  142. package/dist/tools/inspection-tools.js.map +1 -0
  143. package/dist/tools/meta-tools.d.ts +4 -0
  144. package/dist/tools/meta-tools.d.ts.map +1 -0
  145. package/dist/tools/meta-tools.js +412 -0
  146. package/dist/tools/meta-tools.js.map +1 -0
  147. package/dist/tools/nv-server-tools.d.ts +3 -0
  148. package/dist/tools/nv-server-tools.d.ts.map +1 -0
  149. package/dist/tools/nv-server-tools.js +67 -0
  150. package/dist/tools/nv-server-tools.js.map +1 -0
  151. package/dist/tools/performance-tools.d.ts +3 -0
  152. package/dist/tools/performance-tools.d.ts.map +1 -0
  153. package/dist/tools/performance-tools.js +295 -0
  154. package/dist/tools/performance-tools.js.map +1 -0
  155. package/dist/tools/project-tools.d.ts +3 -0
  156. package/dist/tools/project-tools.d.ts.map +1 -0
  157. package/dist/tools/project-tools.js +577 -0
  158. package/dist/tools/project-tools.js.map +1 -0
  159. package/dist/tools/prompt-tools.d.ts +3 -0
  160. package/dist/tools/prompt-tools.d.ts.map +1 -0
  161. package/dist/tools/prompt-tools.js +570 -0
  162. package/dist/tools/prompt-tools.js.map +1 -0
  163. package/dist/tools/provisioning-profile-tools.d.ts +3 -0
  164. package/dist/tools/provisioning-profile-tools.d.ts.map +1 -0
  165. package/dist/tools/provisioning-profile-tools.js +169 -0
  166. package/dist/tools/provisioning-profile-tools.js.map +1 -0
  167. package/dist/tools/region-tools.d.ts +3 -0
  168. package/dist/tools/region-tools.d.ts.map +1 -0
  169. package/dist/tools/region-tools.js +46 -0
  170. package/dist/tools/region-tools.js.map +1 -0
  171. package/dist/tools/reporting-tools.d.ts +3 -0
  172. package/dist/tools/reporting-tools.d.ts.map +1 -0
  173. package/dist/tools/reporting-tools.js +1105 -0
  174. package/dist/tools/reporting-tools.js.map +1 -0
  175. package/dist/tools/repository-tools.d.ts +3 -0
  176. package/dist/tools/repository-tools.d.ts.map +1 -0
  177. package/dist/tools/repository-tools.js +208 -0
  178. package/dist/tools/repository-tools.js.map +1 -0
  179. package/dist/tools/reservation-tools.d.ts +3 -0
  180. package/dist/tools/reservation-tools.d.ts.map +1 -0
  181. package/dist/tools/reservation-tools.js +199 -0
  182. package/dist/tools/reservation-tools.js.map +1 -0
  183. package/dist/tools/resources.d.ts +3 -0
  184. package/dist/tools/resources.d.ts.map +1 -0
  185. package/dist/tools/resources.js +91 -0
  186. package/dist/tools/resources.js.map +1 -0
  187. package/dist/tools/test-view-tools.d.ts +3 -0
  188. package/dist/tools/test-view-tools.d.ts.map +1 -0
  189. package/dist/tools/test-view-tools.js +242 -0
  190. package/dist/tools/test-view-tools.js.map +1 -0
  191. package/dist/tools/transaction-tools.d.ts +3 -0
  192. package/dist/tools/transaction-tools.d.ts.map +1 -0
  193. package/dist/tools/transaction-tools.js +391 -0
  194. package/dist/tools/transaction-tools.js.map +1 -0
  195. package/dist/tools/usage-report-tools.d.ts +3 -0
  196. package/dist/tools/usage-report-tools.d.ts.map +1 -0
  197. package/dist/tools/usage-report-tools.js +160 -0
  198. package/dist/tools/usage-report-tools.js.map +1 -0
  199. package/dist/tools/user-tools.d.ts +3 -0
  200. package/dist/tools/user-tools.d.ts.map +1 -0
  201. package/dist/tools/user-tools.js +279 -0
  202. package/dist/tools/user-tools.js.map +1 -0
  203. package/dist/tools/web-inspection-tools.d.ts +3 -0
  204. package/dist/tools/web-inspection-tools.d.ts.map +1 -0
  205. package/dist/tools/web-inspection-tools.js +416 -0
  206. package/dist/tools/web-inspection-tools.js.map +1 -0
  207. package/dist/tools/workflow-tools.d.ts +3 -0
  208. package/dist/tools/workflow-tools.d.ts.map +1 -0
  209. package/dist/tools/workflow-tools.js +1136 -0
  210. package/dist/tools/workflow-tools.js.map +1 -0
  211. package/dist/types/digital-ai.d.ts +691 -0
  212. package/dist/types/digital-ai.d.ts.map +1 -0
  213. package/dist/types/digital-ai.js +3 -0
  214. package/dist/types/digital-ai.js.map +1 -0
  215. package/dist/utils/csv.d.ts +6 -0
  216. package/dist/utils/csv.d.ts.map +1 -0
  217. package/dist/utils/csv.js +77 -0
  218. package/dist/utils/csv.js.map +1 -0
  219. package/dist/utils/destructive-guard.d.ts +2 -0
  220. package/dist/utils/destructive-guard.d.ts.map +1 -0
  221. package/dist/utils/destructive-guard.js +13 -0
  222. package/dist/utils/destructive-guard.js.map +1 -0
  223. package/dist/utils/device-resolver.d.ts +22 -0
  224. package/dist/utils/device-resolver.d.ts.map +1 -0
  225. package/dist/utils/device-resolver.js +69 -0
  226. package/dist/utils/device-resolver.js.map +1 -0
  227. package/dist/utils/download-command.d.ts +18 -0
  228. package/dist/utils/download-command.d.ts.map +1 -0
  229. package/dist/utils/download-command.js +54 -0
  230. package/dist/utils/download-command.js.map +1 -0
  231. package/dist/utils/locality.d.ts +9 -0
  232. package/dist/utils/locality.d.ts.map +1 -0
  233. package/dist/utils/locality.js +22 -0
  234. package/dist/utils/locality.js.map +1 -0
  235. package/dist/utils/output-format.d.ts +13 -0
  236. package/dist/utils/output-format.d.ts.map +1 -0
  237. package/dist/utils/output-format.js +13 -0
  238. package/dist/utils/output-format.js.map +1 -0
  239. package/dist/utils/pagination.d.ts +12 -0
  240. package/dist/utils/pagination.d.ts.map +1 -0
  241. package/dist/utils/pagination.js +24 -0
  242. package/dist/utils/pagination.js.map +1 -0
  243. package/dist/utils/path-guard.d.ts +17 -0
  244. package/dist/utils/path-guard.d.ts.map +1 -0
  245. package/dist/utils/path-guard.js +41 -0
  246. package/dist/utils/path-guard.js.map +1 -0
  247. package/dist/utils/performance-comparison.d.ts +53 -0
  248. package/dist/utils/performance-comparison.d.ts.map +1 -0
  249. package/dist/utils/performance-comparison.js +286 -0
  250. package/dist/utils/performance-comparison.js.map +1 -0
  251. package/dist/utils/performance-stats.d.ts +72 -0
  252. package/dist/utils/performance-stats.d.ts.map +1 -0
  253. package/dist/utils/performance-stats.js +124 -0
  254. package/dist/utils/performance-stats.js.map +1 -0
  255. package/dist/utils/profile-loader.d.ts +37 -0
  256. package/dist/utils/profile-loader.d.ts.map +1 -0
  257. package/dist/utils/profile-loader.js +80 -0
  258. package/dist/utils/profile-loader.js.map +1 -0
  259. package/dist/utils/response-formatter.d.ts +27 -0
  260. package/dist/utils/response-formatter.d.ts.map +1 -0
  261. package/dist/utils/response-formatter.js +493 -0
  262. package/dist/utils/response-formatter.js.map +1 -0
  263. package/dist/utils/timestamp.d.ts +12 -0
  264. package/dist/utils/timestamp.d.ts.map +1 -0
  265. package/dist/utils/timestamp.js +22 -0
  266. package/dist/utils/timestamp.js.map +1 -0
  267. package/dist/utils/tool-registry.d.ts +21 -0
  268. package/dist/utils/tool-registry.d.ts.map +1 -0
  269. package/dist/utils/tool-registry.js +137 -0
  270. package/dist/utils/tool-registry.js.map +1 -0
  271. package/dist/utils/upload-command.d.ts +20 -0
  272. package/dist/utils/upload-command.d.ts.map +1 -0
  273. package/dist/utils/upload-command.js +64 -0
  274. package/dist/utils/upload-command.js.map +1 -0
  275. package/dist/utils/usage-report-guard.d.ts +48 -0
  276. package/dist/utils/usage-report-guard.d.ts.map +1 -0
  277. package/dist/utils/usage-report-guard.js +88 -0
  278. package/dist/utils/usage-report-guard.js.map +1 -0
  279. package/dist/utils/usage-report-summary.d.ts +20 -0
  280. package/dist/utils/usage-report-summary.d.ts.map +1 -0
  281. package/dist/utils/usage-report-summary.js +48 -0
  282. package/dist/utils/usage-report-summary.js.map +1 -0
  283. package/dist/utils/version.d.ts +2 -0
  284. package/dist/utils/version.d.ts.map +1 -0
  285. package/dist/utils/version.js +24 -0
  286. package/dist/utils/version.js.map +1 -0
  287. package/package.json +73 -0
  288. package/resources/boilerplate/Android-Native/Java JUnit5/AndroidNative-oss.java +58 -0
  289. package/resources/boilerplate/Android-Native/Java JUnit5/AndroidNative.java +67 -0
  290. package/resources/boilerplate/Android-Native/Java JUnit5/gradle +10 -0
  291. package/resources/boilerplate/Android-Native/Java JUnit5/gradle-oss +10 -0
  292. package/resources/boilerplate/Android-Native/Java JUnit5/maven +42 -0
  293. package/resources/boilerplate/Android-Native/Java JUnit5/maven-oss +42 -0
  294. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/AndroidNative.js +30 -0
  295. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/Shell +19 -0
  296. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/Shell-oss +19 -0
  297. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/package-oss.json +12 -0
  298. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/package.json +12 -0
  299. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/wdio-oss.conf.js +40 -0
  300. package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/wdio.conf.js +44 -0
  301. package/resources/boilerplate/Android-Native/Python/AndroidNative-oss.py +49 -0
  302. package/resources/boilerplate/Android-Native/Python/AndroidNative.py +69 -0
  303. package/resources/boilerplate/Android-Native/Python/pip +2 -0
  304. package/resources/boilerplate/Android-Native/Python/pip-oss +1 -0
  305. package/resources/boilerplate/Android-Native/java TestNG/AndroidNative-oss.java +58 -0
  306. package/resources/boilerplate/Android-Native/java TestNG/AndroidNative.java +67 -0
  307. package/resources/boilerplate/Android-Native/java TestNG/gradle +13 -0
  308. package/resources/boilerplate/Android-Native/java TestNG/gradle-oss +13 -0
  309. package/resources/boilerplate/Android-Native/java TestNG/maven +42 -0
  310. package/resources/boilerplate/Android-Native/java TestNG/maven-oss +42 -0
  311. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/Shell-oss.txt +19 -0
  312. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/Shell.txt +19 -0
  313. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/iOSNative.js +30 -0
  314. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/package-oss.json +12 -0
  315. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/package.json +12 -0
  316. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/wdio-oss.conf.js +35 -0
  317. package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/wdio.conf.js +39 -0
  318. package/resources/boilerplate/iOS-Native/Python/iOSNative-oss.py +44 -0
  319. package/resources/boilerplate/iOS-Native/Python/iOSNative.py +62 -0
  320. package/resources/boilerplate/iOS-Native/Python/pip-oss.txt +1 -0
  321. package/resources/boilerplate/iOS-Native/Python/pip.txt +2 -0
  322. package/resources/boilerplate/iOS-Native/java-JUnit5/gradle +10 -0
  323. package/resources/boilerplate/iOS-Native/java-JUnit5/gradle-oss +10 -0
  324. package/resources/boilerplate/iOS-Native/java-JUnit5/iOSNative-oss.java +52 -0
  325. package/resources/boilerplate/iOS-Native/java-JUnit5/iOSNative.java +59 -0
  326. package/resources/boilerplate/iOS-Native/java-JUnit5/maven +42 -0
  327. package/resources/boilerplate/iOS-Native/java-JUnit5/maven-oss +42 -0
  328. package/resources/boilerplate/iOS-Native/java-TestNG/gradle +13 -0
  329. package/resources/boilerplate/iOS-Native/java-TestNG/gradle-oss +13 -0
  330. package/resources/boilerplate/iOS-Native/java-TestNG/iOSNative-oss.java +52 -0
  331. package/resources/boilerplate/iOS-Native/java-TestNG/iOSNative.java +59 -0
  332. package/resources/boilerplate/iOS-Native/java-TestNG/maven +42 -0
  333. package/resources/boilerplate/iOS-Native/java-TestNG/maven-oss +42 -0
@@ -0,0 +1,1105 @@
1
+ import { z } from 'zod';
2
+ import { getTestById, getTestByReportApiId, listTests, listTestsSortedDesc, getGroupedTests, getDistinctKeyValues, deleteTests, downloadTestAttachments, extractAttachmentLog, summarizeTestFailures, } from '../api/reporting.js';
3
+ import { getActiveKeyType } from '../api/client.js';
4
+ import { checkDestructiveGuard } from '../utils/destructive-guard.js';
5
+ import { validateOutputPath } from '../utils/path-guard.js';
6
+ import { buildDownloadCommand } from '../utils/download-command.js';
7
+ import { formatTestReport, formatTestReportList, formatFailureSummary, formatTestAttachments, formatGroupedTestReports, formatProjectTestSummary, } from '../utils/response-formatter.js';
8
+ import { outputFormatParam, respond } from '../utils/output-format.js';
9
+ export function registerReportingTools(server) {
10
+ // ─── get_test_report ───────────────────────────────────────────────────────
11
+ server.tool('get_test_report', 'Retrieve a full test execution report by its numeric test ID or by the report URL printed in tearDown (digitalai:reportUrl capability). ' +
12
+ 'Provide either testId OR reportUrl — reportUrl is parsed to extract the numeric test ID automatically. ' +
13
+ 'The test ID (test_id field) is also returned by list_test_reports and find_latest_test_for_name. ' +
14
+ 'NOTE: Step-level detail is not available via numeric test ID — the backend API does not support it on this endpoint. ' +
15
+ 'To get steps, use get_test_by_report_id with the report_api_id from a live session. ' +
16
+ 'For failure diagnosis use the cause/errorCategory/errorDetail fields in this response, or get_test_log for the full Appium log.', {
17
+ testId: z.number().int().optional().describe('The numeric test ID (test_id field from list results, e.g. 377918). Provide this OR reportUrl.'),
18
+ reportUrl: z.string().optional().describe('The report URL printed by tearDown (digitalai:reportUrl capability value). The numeric test ID is extracted automatically.'),
19
+ outputFormat: outputFormatParam,
20
+ }, async ({ testId, reportUrl, outputFormat }) => {
21
+ let resolvedId = testId;
22
+ if (!resolvedId && reportUrl) {
23
+ const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
24
+ const numericMatch = reportUrl.match(/\/(\d+)\/?(?:\?.*)?$/);
25
+ if (numericMatch) {
26
+ resolvedId = parseInt(numericMatch[1], 10);
27
+ }
28
+ else if (UUID_RE.test(reportUrl)) {
29
+ return {
30
+ content: [{
31
+ type: 'text',
32
+ text: `The report URL contains a UUID, not a numeric test ID. The Digital.ai reporter API does not support UUID-based lookup.\n\n` +
33
+ `Use the numeric test ID from the "Report Test ID" line printed in tearDown (digitalai:reportTestId capability):\n` +
34
+ ` get_test_report(testId: <the number from "Report Test ID">)\n\n` +
35
+ `Or find it via: list_test_reports or find_latest_test_for_name.`,
36
+ }],
37
+ isError: true,
38
+ };
39
+ }
40
+ else {
41
+ return {
42
+ content: [{ type: 'text', text: `Could not extract a numeric test ID from the report URL: ${reportUrl}. Provide testId directly instead.` }],
43
+ isError: true,
44
+ };
45
+ }
46
+ }
47
+ if (!resolvedId) {
48
+ return {
49
+ content: [{ type: 'text', text: 'Provide either testId or reportUrl.' }],
50
+ isError: true,
51
+ };
52
+ }
53
+ try {
54
+ const report = await getTestById(resolvedId);
55
+ return respond(outputFormat, report, formatTestReport(report));
56
+ }
57
+ catch (e) {
58
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
59
+ }
60
+ });
61
+ // ─── get_test_by_report_id ─────────────────────────────────────────────────
62
+ server.tool('get_test_by_report_id', 'Retrieve a test execution report using the report_api_id returned when starting a manual or web-control test session. CRITICAL: report_api_id is NOT the same as test_id (integer) or uuid (hex UUID). It is a separate opaque string returned only by create_mobile_manual_test, start_manual_test_session, or start_device_web_control. This only works AFTER the session has fully ended AND a tester actually executed it — allow up to 60 seconds after session close. A session that was created but never opened/executed produces NO report and its report_api_id stays 404 permanently. ' +
63
+ 'Unlike get_test_report (numeric ID), THIS endpoint supports includeSteps — but the steps array is only populated for tests that logged steps (manual sessions a tester ran, or scripted tests calling the reporter step API). An empty/absent steps array means the test logged no steps, NOT that the tool is broken.', {
64
+ reportApiId: z
65
+ .string()
66
+ .describe('The report_api_id string returned by the session-start API (create_mobile_manual_test, start_manual_test_session, or start_device_web_control). NOT the numeric test_id or UUID.'),
67
+ includeSteps: z
68
+ .boolean()
69
+ .optional()
70
+ .describe('If true, steps and sub-steps are included in the response. Default: false.'),
71
+ outputFormat: outputFormatParam,
72
+ }, async ({ reportApiId, includeSteps, outputFormat }) => {
73
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
74
+ if (/^\d+$/.test(reportApiId)) {
75
+ return {
76
+ content: [{ type: 'text', text: `Error: "${reportApiId}" is a numeric test_id, not a report_api_id. Use get_test_report(testId: ${reportApiId}) instead. The report_api_id is a separate identifier returned only when starting a session via create_mobile_manual_test or start_manual_test_session.` }],
77
+ isError: true,
78
+ };
79
+ }
80
+ if (UUID_RE.test(reportApiId)) {
81
+ return {
82
+ content: [{ type: 'text', text: `Error: "${reportApiId}" is a test UUID, not a report_api_id. There is no API endpoint to look up a test by UUID — use get_test_report(testId: <numeric_id>) instead. Find the numeric test_id via list_test_reports or find_latest_test_for_name. The report_api_id is a different identifier returned only when starting a manual or web-control session.` }],
83
+ isError: true,
84
+ };
85
+ }
86
+ try {
87
+ const report = await getTestByReportApiId(reportApiId, includeSteps ?? false);
88
+ return respond(outputFormat, report, formatTestReport(report));
89
+ }
90
+ catch (e) {
91
+ const msg = e.message;
92
+ if (msg.includes('404') || msg.toLowerCase().includes('not found')) {
93
+ return {
94
+ content: [{ type: 'text', text: `Error: No test found for report_api_id "${reportApiId}". Possible reasons:\n1. The session is still active — the reporter record is created only after the session ends (allow up to 60 seconds).\n2. This is not a valid report_api_id. The report_api_id is returned by create_mobile_manual_test, start_manual_test_session, or start_device_web_control — it is NOT the numeric test_id or UUID.` }],
95
+ isError: true,
96
+ };
97
+ }
98
+ return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
99
+ }
100
+ });
101
+ // ─── list_test_reports ─────────────────────────────────────────────────────
102
+ server.tool('list_test_reports', 'Search and list test execution reports. Supports filtering, sorting, and pagination. ' +
103
+ 'For date-range filtering use startDate/endDate — server-side start_time filtering is CSRF-blocked. ' +
104
+ 'When the user asks for "my reports" / "reports linked to my account", filter by user immediately: ' +
105
+ '[{"property":"user","operator":"=","value":"<email from get_my_account_info>"}] — do not return a global count first. ' +
106
+ 'Scoped to a project if projectId or projectName is provided. ' +
107
+ 'NOTE: the list response does NOT include failure diagnostics — the cause, errorCategory, and errorDetail fields are only returned by get_test_report (single-record). ' +
108
+ 'To diagnose why a listed test failed, call get_test_report with its test_id, or get_test_log for the full Appium log. ' +
109
+ 'For "why are my tests failing?" across many failures, use summarize_test_failures — it buckets failures by error classification in one call.', {
110
+ limit: z
111
+ .number()
112
+ .int()
113
+ .min(1)
114
+ .max(500)
115
+ .optional()
116
+ .describe('Number of results to return (default: 50, max: 500).'),
117
+ page: z
118
+ .number()
119
+ .int()
120
+ .min(1)
121
+ .optional()
122
+ .describe('Page number, starting at 1. Default: 1. Ignored when startDate/endDate are provided.'),
123
+ searchValue: z
124
+ .string()
125
+ .optional()
126
+ .describe('Case-insensitive substring search across test names (separate from filter[]).'),
127
+ filter: z
128
+ .array(z.object({
129
+ property: z.string().describe('Field to filter on. Confirmed working: ' +
130
+ '"status" (Passed/Failed/Incomplete/Skipped/Error/Healed), ' +
131
+ '"name", ' +
132
+ '"user" (email, exact match — for "my reports" use the email from get_my_account_info), ' +
133
+ '"has_attachment" ("Y"/"N"), ' +
134
+ '"success" (boolean true/false), ' +
135
+ '"test_id" (number), ' +
136
+ '"project_id" (number), ' +
137
+ '"device.os" ("Android"/"iOS" — case-sensitive), ' +
138
+ '"duration" (milliseconds), ' +
139
+ '"attachment_count", ' +
140
+ '"attachments_size" (bytes), ' +
141
+ '"status_code". ' +
142
+ 'CSRF-blocked (use startDate/endDate instead): "start_time", "create_time", "uuid".'),
143
+ operator: z.string().describe('Comparison operator. Supported: "=" (equality), ">" ">=" "<" "<=" (numeric/date), "contains" (substring for name). ' +
144
+ 'CSRF-blocked operators: "!=", "like", "startsWith", "in". ' +
145
+ 'Note: "success" must use boolean value with "="; string "true" is CSRF-blocked.'),
146
+ value: z.union([z.string(), z.number(), z.boolean()]).describe('Filter value. Use boolean true/false for "success", numbers for numeric fields, strings for text fields.'),
147
+ }))
148
+ .optional()
149
+ .describe('Server-side filters. Multiple filters are ANDed. ' +
150
+ 'Example: [{"property":"status","operator":"=","value":"Failed"},{"property":"device.os","operator":"=","value":"Android"}]'),
151
+ sort: z
152
+ .array(z.object({
153
+ property: z.string().describe('Field to sort by, e.g. "start_time".'),
154
+ descending: z.boolean().describe('True for descending order.'),
155
+ }))
156
+ .optional()
157
+ .describe('Sort order. Example: [{"property":"start_time","descending":true}].'),
158
+ keys: z
159
+ .array(z.string())
160
+ .optional()
161
+ .describe('Key names to include in the response, e.g. ["device.os", "browser"]. Omit to return all keys.'),
162
+ returnTotalCount: z
163
+ .boolean()
164
+ .optional()
165
+ .describe('If true, the response includes the total matching count. Works with startDate/endDate too: the scan continues past limit to count all in-range records (up to 5000 scanned; totalCapped: true indicates the count was truncated). For a count-only query, combine with limit: 1.'),
166
+ startDate: z
167
+ .string()
168
+ .optional()
169
+ .describe('ISO 8601 start of date range, e.g. "2025-01-01T00:00:00Z". Applied client-side — do NOT also add start_time to filter[].'),
170
+ endDate: z
171
+ .string()
172
+ .optional()
173
+ .describe('ISO 8601 end of date range, e.g. "2025-06-01T00:00:00Z". Defaults to now when startDate is provided.'),
174
+ projectId: z.number().int().optional().describe('Scope results to this project ID.'),
175
+ projectName: z.string().optional().describe('Scope results to this project name.'),
176
+ outputFormat: outputFormatParam,
177
+ }, async ({ limit, page, searchValue, filter, sort, keys, returnTotalCount, startDate, endDate, projectId, projectName, outputFormat }) => {
178
+ try {
179
+ const targetLimit = limit ?? 50;
180
+ if (startDate || endDate) {
181
+ // Client-side date filtering — server-side start_time filter is CSRF-blocked for all key types.
182
+ // JWT keys: fetch sorted descending so we can stop as soon as we pass the startDate cutoff.
183
+ // Project keys: sort is CSRF-blocked, so fetch unsorted and scan all pages (slower).
184
+ const isSortedFetch = getActiveKeyType() === 'jwt';
185
+ const startTs = startDate ? new Date(startDate).getTime() : 0;
186
+ const endTs = endDate ? new Date(endDate).getTime() : Date.now();
187
+ // When a total is requested, keep scanning past targetLimit to count
188
+ // all in-range records (up to maxScan) instead of stopping at the limit.
189
+ const wantTotal = returnTotalCount ?? false;
190
+ const maxScan = 5000;
191
+ const matched = [];
192
+ let matchedCount = 0;
193
+ let scanned = 0;
194
+ let countCapped = false;
195
+ let fetchPage = 1;
196
+ let done = false;
197
+ while (!done && (wantTotal || matched.length < targetLimit)) {
198
+ const batch = await listTests({
199
+ limit: 500,
200
+ page: fetchPage,
201
+ returnTotalCount: false,
202
+ ...(isSortedFetch && { sort: [{ property: 'start_time', descending: true }] }),
203
+ ...(searchValue && { searchValue }),
204
+ ...(filter && { filter }),
205
+ ...(keys && { keys }),
206
+ }, projectId, projectName);
207
+ const records = batch.data ?? [];
208
+ if (records.length === 0)
209
+ break;
210
+ scanned += records.length;
211
+ for (const r of records) {
212
+ const t = new Date(r.start_time).getTime();
213
+ // Early-exit is only valid when results are sorted descending by start_time.
214
+ if (isSortedFetch && t < startTs) {
215
+ done = true;
216
+ break;
217
+ }
218
+ if (t >= startTs && t <= endTs) {
219
+ matchedCount++;
220
+ if (matched.length < targetLimit)
221
+ matched.push(r);
222
+ if (!wantTotal && matched.length >= targetLimit) {
223
+ done = true;
224
+ break;
225
+ }
226
+ }
227
+ }
228
+ if (records.length < 500)
229
+ done = true;
230
+ if (!done && scanned >= maxScan) {
231
+ countCapped = true;
232
+ done = true;
233
+ }
234
+ fetchPage++;
235
+ }
236
+ const rangeLabel = `${startDate ?? 'beginning'} → ${endDate ?? 'now'}`;
237
+ const totalLine = wantTotal
238
+ ? `Total matching: ${matchedCount}${countCapped ? `+ (count capped after scanning ${maxScan} records — narrow the range for an exact total)` : ''}\n`
239
+ : '';
240
+ const header = matched.length === 0
241
+ ? `${totalLine}No tests found in range ${rangeLabel} (date filter applied client-side).`
242
+ : `${totalLine}${matched.length} test(s) shown for range ${rangeLabel} (date filter applied client-side):\n`;
243
+ return respond(outputFormat, {
244
+ reports: matched,
245
+ ...(wantTotal && { total: matchedCount, totalCapped: countCapped }),
246
+ }, header + (matched.length > 0 ? '\n' + formatTestReportList(matched) : ''));
247
+ }
248
+ const request = {
249
+ limit: targetLimit,
250
+ page: page ?? 1,
251
+ returnTotalCount: returnTotalCount ?? true,
252
+ ...(searchValue && { searchValue }),
253
+ ...(filter && { filter }),
254
+ ...(sort && { sort }),
255
+ ...(keys && { keys }),
256
+ };
257
+ const result = await listTests(request, projectId, projectName);
258
+ const reports = result.data ?? [];
259
+ const countLine = result.count !== undefined ? `Total matching: ${result.count}\n\n` : '';
260
+ return respond(outputFormat, { reports, total: result.count }, countLine + formatTestReportList(reports));
261
+ }
262
+ catch (e) {
263
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
264
+ }
265
+ });
266
+ // ─── get_grouped_test_reports ──────────────────────────────────────────────
267
+ server.tool('get_grouped_test_reports', 'Get test report counts grouped by field values. Returns one row per unique value combination. ' +
268
+ 'Use groupBy to specify which fields to group on — e.g. ["device.os"] returns one row per OS. ' +
269
+ 'Use pivotBy to add per-status columns (passedCount, failedCount, etc.) instead of separate rows. ' +
270
+ 'Useful for dashboards: pass/fail by OS, by test name, by environment, etc. ' +
271
+ 'Note: null OS values represent browser/Selenium sessions. ' +
272
+ 'When groupBy includes "device.os", the MCP normalises case variants ("ANDROID"/"IOS") to ' +
273
+ '"Android"/"iOS" and merges their counts, so you always receive at most 3 rows: Android, iOS, null.', {
274
+ groupBy: z
275
+ .array(z.string())
276
+ .optional()
277
+ .describe('Fields to group results by, e.g. ["device.os"], ["status"], or ["device.os","status"] for multi-dimensional grouping. ' +
278
+ 'Each unique value combination becomes one row. Omit to get a single aggregate row for the entire dataset.'),
279
+ pivotBy: z
280
+ .array(z.enum(['success', 'status']))
281
+ .optional()
282
+ .describe('Add per-status count columns to each group row: "status" adds passedCount/failedCount/etc., "success" adds true/false split.'),
283
+ filter: z
284
+ .array(z.object({
285
+ property: z.string(),
286
+ operator: z.string(),
287
+ value: z.union([z.string(), z.number(), z.boolean()]),
288
+ }))
289
+ .optional()
290
+ .describe('Scope the aggregation to matching records. Same filter syntax as list_test_reports.'),
291
+ returnTotalCount: z
292
+ .boolean()
293
+ .optional()
294
+ .describe('If true, includes total record count across all groups.'),
295
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
296
+ projectName: z.string().optional().describe('Scope to this project name.'),
297
+ outputFormat: outputFormatParam,
298
+ }, async ({ groupBy, pivotBy, filter, returnTotalCount, projectId, projectName, outputFormat }) => {
299
+ try {
300
+ const request = {
301
+ ...(groupBy && { groupBy }),
302
+ ...(pivotBy && { pivotBy }),
303
+ ...(filter && { filter }),
304
+ returnTotalCount: returnTotalCount ?? true,
305
+ };
306
+ let result = await getGroupedTests(request, projectId, projectName);
307
+ // Normalise device.os case variants ("ANDROID"/"IOS") to canonical form and
308
+ // merge their counts so consumers see at most 3 rows: Android, iOS, null.
309
+ if (groupBy?.includes('device.os') && Array.isArray(result?.data)) {
310
+ const OS_NORM = { android: 'Android', ios: 'iOS' };
311
+ const merged = {};
312
+ for (const row of result.data) {
313
+ const rawOs = row['device.os'];
314
+ const normOs = rawOs == null ? null : (OS_NORM[(String(rawOs)).toLowerCase()] ?? String(rawOs));
315
+ const key = normOs ?? '__null__';
316
+ if (!merged[key]) {
317
+ merged[key] = { ...row, 'device.os': normOs };
318
+ }
319
+ else {
320
+ // Sum all numeric count fields
321
+ for (const [k, v] of Object.entries(row)) {
322
+ if (typeof v === 'number' && k !== 'device.os') {
323
+ merged[key][k] = (merged[key][k] ?? 0) + v;
324
+ }
325
+ }
326
+ }
327
+ }
328
+ result = { ...result, data: Object.values(merged) };
329
+ }
330
+ return respond(outputFormat, result, formatGroupedTestReports(result));
331
+ }
332
+ catch (e) {
333
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
334
+ }
335
+ });
336
+ // ─── get_distinct_test_key_values ──────────────────────────────────────────
337
+ server.tool('get_distinct_test_key_values', 'Return every distinct value recorded for one or more test report keys. Useful for discovering what devices, browsers, environments, or other dimensions appear in test history. NOTE: this tool requires browser session authentication on some platforms — if you receive a CSRF/401 error, the endpoint is not accessible via API key on your deployment. Use get_grouped_test_reports with a keys array as an alternative.', {
338
+ keys: z
339
+ .array(z.string())
340
+ .min(1)
341
+ .describe('One or more key names, e.g. ["device.os", "browser", "environment"].'),
342
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
343
+ projectName: z.string().optional().describe('Scope to this project name.'),
344
+ outputFormat: outputFormatParam,
345
+ }, async ({ keys, projectId, projectName, outputFormat }) => {
346
+ try {
347
+ const result = await getDistinctKeyValues(keys, projectId, projectName);
348
+ const lines = [];
349
+ for (const [key, rawValues] of Object.entries(result)) {
350
+ lines.push(`${key}:`);
351
+ const values = Array.isArray(rawValues)
352
+ ? rawValues
353
+ : rawValues != null
354
+ ? [String(rawValues)]
355
+ : [];
356
+ if (values.length === 0) {
357
+ lines.push(' (no values recorded)');
358
+ }
359
+ else {
360
+ for (const v of values)
361
+ lines.push(` • ${v}`);
362
+ }
363
+ }
364
+ return respond(outputFormat, result, lines.join('\n') || 'No values found.');
365
+ }
366
+ catch (e) {
367
+ const msg = e.message;
368
+ if (msg.startsWith('PLATFORM_LIMITATION:')) {
369
+ return {
370
+ content: [{ type: 'text', text: `⚠️ Platform limitation: This endpoint requires browser session authentication and is not available via API key on this deployment.\n\nAlternative: use get_grouped_test_reports with a keys array to enumerate value combinations for the same keys.` }],
371
+ isError: true,
372
+ };
373
+ }
374
+ return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
375
+ }
376
+ });
377
+ // ─── delete_test_reports ───────────────────────────────────────────────────
378
+ server.tool('delete_test_reports', 'Permanently delete one or more test execution records by their numeric IDs. This cannot be undone. Requires confirmDeletion: true. Cloud Admin only (project keys CSRF-blocked on reporter delete). PREFERRED cleanup method whenever the IDs are already known (e.g. from a filtered list_test_reports call) — more precise than name or date matching.', {
379
+ ids: z
380
+ .array(z.number().int())
381
+ .min(1)
382
+ .describe('Array of numeric test IDs to delete, e.g. [5, 67, 100].'),
383
+ confirmDeletion: z
384
+ .boolean()
385
+ .optional()
386
+ .describe('Must be true to confirm the permanent deletion.'),
387
+ projectId: z.number().int().optional().describe('Ignored — reporter API CSRF-blocks numeric projectId. Use projectName instead.'),
388
+ projectName: z.string().optional().describe('Exact project name (from list_projects) to scope the delete to a specific reporter instance.'),
389
+ }, async ({ ids, confirmDeletion, projectId, projectName }) => {
390
+ if (getActiveKeyType() !== 'jwt') {
391
+ return { content: [{ type: 'text', text: 'Error: Cloud Admin access required. The reporter delete endpoint is CSRF-blocked for project-level keys (Project Admin and Project User). Use switch_environment() to switch to a Cloud Admin profile.' }], isError: true };
392
+ }
393
+ if (confirmDeletion !== true) {
394
+ if (ids.length <= 50) {
395
+ // Fetch details for all IDs so the guard shows a human-readable preview.
396
+ // If any ID cannot be resolved, block the deletion entirely rather than
397
+ // silently deleting records the caller cannot verify.
398
+ const results = await Promise.allSettled(ids.map(id => getTestById(id)));
399
+ const failedIndices = results.reduce((acc, r, i) => (r.status === 'rejected' ? [...acc, i] : acc), []);
400
+ if (failedIndices.length > 0) {
401
+ const failedIds = failedIndices.map(i => ids[i]).join(', ');
402
+ return {
403
+ content: [{
404
+ type: 'text',
405
+ text: `⛔ Cannot preview deletion: ${failedIndices.length} of the requested ID(s) could not be resolved ` +
406
+ `in the current reporter scope: [${failedIds}].\n\n` +
407
+ `Verify these IDs exist and are accessible with the active credentials. ` +
408
+ `If they belong to a different project, switch to that project's profile ` +
409
+ `with switch_environment() and retry.\n\nNo changes were made.`,
410
+ }],
411
+ isError: true,
412
+ };
413
+ }
414
+ const rows = results.map((r) => {
415
+ const t = r.value;
416
+ const date = t.start_time ? t.start_time.substring(0, 19).replace('T', ' ') : '—';
417
+ return ` ${String(t.test_id).padEnd(10)} ${(t.status ?? '').padEnd(12)} ${date.padEnd(20)} ${t.name ?? ''}`;
418
+ });
419
+ const header = ` ${'ID'.padEnd(10)} ${'Status'.padEnd(12)} ${'Start (UTC)'.padEnd(20)} Name`;
420
+ const sep = ` ${'-'.repeat(9)} ${'-'.repeat(11)} ${'-'.repeat(19)} ${'-'.repeat(30)}`;
421
+ const table = [header, sep, ...rows].join('\n');
422
+ const guard = checkDestructiveGuard(confirmDeletion, `Delete ${ids.length} test report(s)`);
423
+ return { content: [{ type: 'text', text: `${guard}\n\nRecords that would be deleted:\n${table}` }] };
424
+ }
425
+ // >50 IDs — skip detail fetch, return guard with ID list
426
+ const guard = checkDestructiveGuard(confirmDeletion, `Delete ${ids.length} test report(s): [${ids.join(', ')}]`);
427
+ return { content: [{ type: 'text', text: guard }] };
428
+ }
429
+ try {
430
+ await deleteTests(ids, projectId, projectName);
431
+ return {
432
+ content: [{ type: 'text', text: `✅ Successfully deleted ${ids.length} test report(s).` }],
433
+ };
434
+ }
435
+ catch (e) {
436
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
437
+ }
438
+ });
439
+ // ─── delete_test_reports_by_name ──────────────────────────────────────────
440
+ server.tool('delete_test_reports_by_name', 'Find and permanently delete test execution records matching a name. Accepts exact match (name) or substring match (nameContains). Searches across all pages. Show a preview first via confirmDeletion: false, then re-call with confirmDeletion: true to execute. If you already have the numeric IDs (e.g. from a filtered list_test_reports call), use delete_test_reports instead — no name-matching ambiguity. Cloud Admin only — project-level keys (Project Admin and Project User) are CSRF-blocked on the reporter delete endpoint. IMPORTANT: always pass projectName (exact project name from list_projects) when using Cloud Admin access — without it the search spans the default reporter scope and tests from separate project reporter instances will not appear. The numeric projectId param is CSRF-blocked on reporter endpoints and is silently ignored.', {
441
+ name: z
442
+ .string()
443
+ .optional()
444
+ .describe('Exact test name to match. Use this or nameContains, not both.'),
445
+ nameContains: z
446
+ .string()
447
+ .optional()
448
+ .describe('Case-insensitive substring to match against test names. Use this or name, not both.'),
449
+ confirmDeletion: z
450
+ .boolean()
451
+ .optional()
452
+ .describe('Set true to execute the deletion. Omit or false to preview matching records without deleting.'),
453
+ maxPreviewResults: z
454
+ .number()
455
+ .int()
456
+ .optional()
457
+ .describe('Maximum records to show in preview (confirmDeletion: false). Defaults to 50. The deletion itself (confirmDeletion: true) always processes all matching records regardless of this limit.'),
458
+ projectId: z.number().int().optional().describe('Ignored — the reporter API CSRF-blocks numeric projectId. Use projectName instead.'),
459
+ projectName: z.string().optional().describe('Exact project name (from list_projects) to scope the search. Required when the target project has its own reporter instance separate from the default scope.'),
460
+ }, async ({ name, nameContains, confirmDeletion, maxPreviewResults, projectId, projectName }) => {
461
+ if (getActiveKeyType() !== 'jwt') {
462
+ return { content: [{ type: 'text', text: 'Error: Cloud Admin access required. The reporter delete endpoint is CSRF-blocked for project-level keys (Project Admin and Project User). Use switch_environment() to switch to a Cloud Admin profile.' }], isError: true };
463
+ }
464
+ try {
465
+ if (!name && !nameContains) {
466
+ return { content: [{ type: 'text', text: 'Error: provide either name (exact) or nameContains (substring).' }], isError: true };
467
+ }
468
+ if (name && nameContains) {
469
+ return { content: [{ type: 'text', text: 'Error: provide either name or nameContains, not both.' }], isError: true };
470
+ }
471
+ const filter = name
472
+ ? [{ property: 'name', operator: '=', value: name }]
473
+ : [{ property: 'name', operator: 'contains', value: nameContains }];
474
+ // In preview mode cap scanning to avoid timeout on high-cardinality matches
475
+ const isPreview = !confirmDeletion;
476
+ const previewCap = maxPreviewResults ?? 50;
477
+ const allIds = [];
478
+ const previewNames = [];
479
+ let truncated = false;
480
+ let page = 1;
481
+ outer: while (true) {
482
+ const batch = await listTests({ limit: 500, page, returnTotalCount: false, filter }, projectId, projectName);
483
+ const records = batch.data ?? [];
484
+ for (const r of records) {
485
+ allIds.push(r.test_id);
486
+ previewNames.push(` ${r.test_id}: ${r.name} (${r.start_time?.slice(0, 10) ?? '?'})`);
487
+ if (isPreview && allIds.length >= previewCap) {
488
+ truncated = true;
489
+ break outer;
490
+ }
491
+ }
492
+ if (records.length < 500)
493
+ break;
494
+ page++;
495
+ }
496
+ if (allIds.length === 0) {
497
+ const criterion = name ? `name = "${name}"` : `name contains "${nameContains}"`;
498
+ return { content: [{ type: 'text', text: `No test reports found matching ${criterion}.` }] };
499
+ }
500
+ const countDesc = truncated ? `${previewCap}+ (preview capped at ${previewCap})` : `${allIds.length}`;
501
+ const guard = checkDestructiveGuard(confirmDeletion, `Delete ${countDesc} test report(s) matching "${name ?? nameContains}"`);
502
+ if (guard) {
503
+ const truncationNote = truncated
504
+ ? `\n\n⚠️ Showing first ${previewCap} of ${previewCap}+ matches. Re-run with confirmDeletion: true to delete all matches, or use a more specific nameContains value to narrow the search.`
505
+ : '';
506
+ return {
507
+ content: [{
508
+ type: 'text',
509
+ text: `${guard}\n\nMatching records (${truncated ? `first ${previewCap} shown` : allIds.length}):\n${previewNames.join('\n')}${truncationNote}`,
510
+ }],
511
+ };
512
+ }
513
+ await deleteTests(allIds, projectId, projectName);
514
+ return {
515
+ content: [{ type: 'text', text: `✅ Deleted ${allIds.length} test report(s) matching "${name ?? nameContains}".` }],
516
+ };
517
+ }
518
+ catch (e) {
519
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
520
+ }
521
+ });
522
+ // ─── download_test_attachments ─────────────────────────────────────────────
523
+ server.tool('download_test_attachments', 'Download all attachments for a test execution as a ZIP file, saved to the MCP server\'s own filesystem. ' +
524
+ 'WARNING: the file is written to the MCP server process filesystem — if the server runs in Docker or a remote container, ' +
525
+ 'the path must be valid on that container and the file will NOT be accessible from your local machine or bash tools. ' +
526
+ 'Use get_test_log instead to retrieve log content directly without a file download.', {
527
+ uuid: z.string().describe('The test execution UUID.'),
528
+ localPath: z
529
+ .string()
530
+ .describe('Absolute path on the MCP server\'s own filesystem where the ZIP will be saved (e.g. "/tmp/test.zip" for Linux/Docker deployment).'),
531
+ }, async ({ uuid, localPath }) => {
532
+ const pathErr = validateOutputPath(localPath);
533
+ if (pathErr)
534
+ return { content: [{ type: 'text', text: `Error: ${pathErr}` }], isError: true };
535
+ try {
536
+ await downloadTestAttachments(uuid, localPath);
537
+ return {
538
+ content: [{ type: 'text', text: `✅ Attachments downloaded to: ${localPath}` }],
539
+ };
540
+ }
541
+ catch (e) {
542
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
543
+ }
544
+ });
545
+ // ─── get_test_attachments_download_command ─────────────────────────────────
546
+ server.tool('get_test_attachments_download_command', 'Generates a ready-to-run curl or PowerShell command for downloading a test execution\'s full attachment ZIP (session video .mp4, Appium/device logs) directly to the user\'s local machine. ' +
547
+ 'Use this instead of download_test_attachments when the MCP server runs in Docker/remote: download_test_attachments writes to the SERVER\'s filesystem (invisible to the user), whereas this command runs on the user\'s machine so the binary lands locally. ' +
548
+ 'For text logs only, get_test_log is simpler (returns log text inline, no command). This is the path for the BINARY artifacts (video).\n\n' +
549
+ 'WARNING: The generated command embeds the active access key in plaintext. Instruct the user to run it immediately and not save or share the output.', {
550
+ uuid: z.string().describe('Test execution UUID (uuid field from get_test_report or list_test_reports).'),
551
+ localPath: z.string().optional().default('test-attachments.zip').describe('Path on the user\'s local machine to save the ZIP. Default: "test-attachments.zip" in the current directory.'),
552
+ localPlatform: z.enum(['windows', 'macos', 'linux']).describe('Platform of the machine that will run the command. "windows" emits both Git Bash curl and PowerShell. Cannot be inferred — the MCP runs in Docker.'),
553
+ outputFormat: outputFormatParam,
554
+ }, async ({ uuid, localPath, localPlatform, outputFormat }) => {
555
+ const result = buildDownloadCommand({
556
+ path: `/reporter/api/reports/${uuid}/attachments`,
557
+ localPath: localPath ?? 'test-attachments.zip',
558
+ localPlatform,
559
+ notes: ['The downloaded file is a ZIP — unzip it to access the .mp4 video and the appium/device/ws logs.'],
560
+ });
561
+ return respond(outputFormat, { endpoint: result.endpoint, curlCommand: result.curlCommand, psCommand: result.psCommand }, result.humanText);
562
+ });
563
+ // ─── get_test_log ──────────────────────────────────────────────────────────
564
+ server.tool('get_test_log', 'Retrieve log content from a test execution directly as text — no file download required. ' +
565
+ 'Fetches the attachment ZIP and extracts the requested log in memory, returning the tail. ' +
566
+ 'Use this to diagnose test failures when get_test_report shows cause/errorDetail but you need the full Appium trace. ' +
567
+ 'Requires the test execution UUID (uuid field from get_test_report or list_test_reports).', {
568
+ uuid: z.string().describe('Test execution UUID (uuid field from get_test_report or list_test_reports).'),
569
+ logType: z
570
+ .enum(['appium', 'device', 'ws'])
571
+ .optional()
572
+ .default('appium')
573
+ .describe("Which log file to extract: 'appium' (default) — Appium server log with test steps and errors; 'device' — on-device logcat; 'ws' — WebSocket/network bridge log."),
574
+ maxLines: z
575
+ .number()
576
+ .int()
577
+ .optional()
578
+ .default(200)
579
+ .describe('Number of lines to return from the END of the log. Default: 200.'),
580
+ }, async ({ uuid, logType, maxLines }) => {
581
+ try {
582
+ const { filename, content, totalLines } = await extractAttachmentLog(uuid, logType ?? 'appium');
583
+ const tail = content.split('\n').slice(-(maxLines ?? 200));
584
+ const truncated = totalLines > (maxLines ?? 200);
585
+ const header = truncated
586
+ ? `[${filename} — showing last ${maxLines ?? 200} of ${totalLines} lines]\n\n`
587
+ : `[${filename} — ${totalLines} lines]\n\n`;
588
+ return { content: [{ type: 'text', text: header + tail.join('\n') }] };
589
+ }
590
+ catch (e) {
591
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
592
+ }
593
+ });
594
+ // ─── summarize_test_failures ───────────────────────────────────────────────
595
+ server.tool('summarize_test_failures', 'Answer "why are my tests failing?" in one call: buckets failed tests by error classification and returns the breakdown (e.g. "44 failures: 38 element_not_found, 6 timeout"). ' +
596
+ 'Use this instead of fanning out get_test_report manually across many failures. ' +
597
+ 'SLOW: the reporter list endpoint does not carry error classification, so this fetches the single-record report for each failed test (N+1) — bounded by maxReports. ' +
598
+ 'groupBy "name" needs no per-test fetch (name is on the list record) and is fast. ' +
599
+ 'Scope with startDate/endDate (client-side window), projectName/projectId, and nameFilter (substring on test name).', {
600
+ startDate: z.string().optional().describe('ISO 8601 start of window, e.g. "2026-06-01T00:00:00Z". Omit for all-time (bounded by maxReports).'),
601
+ endDate: z.string().optional().describe('ISO 8601 end of window. Defaults to now.'),
602
+ groupBy: z
603
+ .enum(['errorClassification', 'errorCategory', 'name'])
604
+ .optional()
605
+ .default('errorClassification')
606
+ .describe("Dimension to bucket by. 'errorClassification' (default, e.g. element_not_found) and 'errorCategory' (e.g. assertion) require per-test fetches; 'name' is fast (no fetch)."),
607
+ nameFilter: z.string().optional().describe('Only include failures whose test name contains this substring (e.g. "Login").'),
608
+ maxReports: z.number().int().min(1).max(1000).optional().default(200).describe('Cap on failures analyzed (fan-out bound). Default 200. capped:true in the result means more failures exist beyond this.'),
609
+ projectId: z.number().int().optional().describe('Scope to a project by numeric ID.'),
610
+ projectName: z.string().optional().describe('Scope to a project by name.'),
611
+ outputFormat: outputFormatParam,
612
+ }, async ({ startDate, endDate, groupBy, nameFilter, maxReports, projectId, projectName, outputFormat }) => {
613
+ try {
614
+ const summary = await summarizeTestFailures({
615
+ startDate, endDate, groupBy, nameFilter, maxReports, projectId, projectName,
616
+ });
617
+ return respond(outputFormat, summary, formatFailureSummary(summary));
618
+ }
619
+ catch (e) {
620
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
621
+ }
622
+ });
623
+ // ─── list_test_attachments ─────────────────────────────────────────────────
624
+ server.tool('list_test_attachments', 'Show attachment metadata (file names, types, sizes) for a test execution. Takes the numeric testId (integer), NOT the uuid string. Call this before download_test_attachments to confirm attachments exist — download_test_attachments then takes the uuid shown in the output.', {
625
+ testId: z.number().int().describe('Numeric test ID (the test_id integer from list_test_reports or find_latest_test_for_name — NOT the uuid string).'),
626
+ outputFormat: outputFormatParam,
627
+ }, async ({ testId, outputFormat }) => {
628
+ try {
629
+ const report = await getTestById(testId);
630
+ const structured = {
631
+ testId: report.test_id,
632
+ uuid: report.uuid,
633
+ hasAttachments: report.has_attachment === 'Y',
634
+ count: report.attachment_count,
635
+ sizeBytes: report.attachments_size,
636
+ attachments: report.testAttachments ?? [],
637
+ };
638
+ return respond(outputFormat, structured, formatTestAttachments(report));
639
+ }
640
+ catch (e) {
641
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
642
+ }
643
+ });
644
+ // ─── find_latest_test_for_name ─────────────────────────────────────────────
645
+ server.tool('find_latest_test_for_name', 'Return the most recent execution record for a test by name. Answers "did the last run of X pass?" without requiring a full list_test_reports query.', {
646
+ name: z.string().describe('Exact or partial test name to search for.'),
647
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
648
+ projectName: z.string().optional().describe('Scope to this project name.'),
649
+ outputFormat: outputFormatParam,
650
+ }, async ({ name, projectId, projectName, outputFormat }) => {
651
+ try {
652
+ // listTestsSortedDesc guarantees newest-first for both key types — project
653
+ // keys CSRF-block sort, so a plain sorted listTests call would silently
654
+ // return an arbitrary record instead of the latest.
655
+ const result = await listTestsSortedDesc({ limit: 1, page: 1, searchValue: name }, projectId, projectName);
656
+ if (!result.data || result.data.length === 0) {
657
+ return respond(outputFormat, { found: false }, `No test found matching "${name}".`);
658
+ }
659
+ return respond(outputFormat, result.data[0], formatTestReport(result.data[0]));
660
+ }
661
+ catch (e) {
662
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
663
+ }
664
+ });
665
+ // ─── get_project_test_summary ──────────────────────────────────────────────
666
+ server.tool('get_project_test_summary', 'Return a human-readable pass/fail summary for a project. Overall status counts (Passed/Failed/Incomplete) are all-time totals — the reporter API does not support date-range filtering for aggregate counts. Top failing test names are filtered to the requested time window client-side from the most recent 200 failures.', {
667
+ startDate: z
668
+ .string()
669
+ .optional()
670
+ .describe('ISO 8601 start of the window for top-failure names, e.g. "2025-01-01T00:00:00Z". Defaults to 48 hours ago if omitted.'),
671
+ endDate: z
672
+ .string()
673
+ .optional()
674
+ .describe('ISO 8601 end of the window. Defaults to now if omitted.'),
675
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
676
+ projectName: z.string().optional().describe('Scope to this project name.'),
677
+ outputFormat: outputFormatParam,
678
+ }, async ({ startDate, endDate, projectId, projectName, outputFormat }) => {
679
+ try {
680
+ const defaultStart = new Date(Date.now() - 48 * 60 * 60 * 1000).toISOString();
681
+ const resolvedStart = startDate ?? defaultStart;
682
+ // Fetch per-status counts + recent failures in parallel.
683
+ // The grouped endpoint returns empty data[] without grouping keys, so we
684
+ // use per-status listTests calls with returnTotalCount which reliably works.
685
+ const [passedResult, failedResult, incompleteResult] = await Promise.all([
686
+ listTests({ limit: 1, page: 1, returnTotalCount: true, filter: [{ property: 'status', operator: '=', value: 'Passed' }] }, projectId, projectName),
687
+ listTestsSortedDesc({ limit: 200, page: 1, returnTotalCount: true, filter: [{ property: 'status', operator: '=', value: 'Failed' }] }, projectId, projectName),
688
+ listTests({ limit: 1, page: 1, returnTotalCount: true, filter: [{ property: 'status', operator: '=', value: 'Incomplete' }] }, projectId, projectName),
689
+ ]);
690
+ const passed = passedResult.count ?? 0;
691
+ const failed = failedResult.count ?? 0;
692
+ const incomplete = incompleteResult.count ?? 0;
693
+ const total = passed + failed + incomplete;
694
+ // Apply date window client-side on the most recent 200 failures
695
+ // (start_time filter via API key triggers CSRF — filter locally instead).
696
+ const endTs = endDate ? new Date(endDate).getTime() : Date.now();
697
+ const startTs = new Date(resolvedStart).getTime();
698
+ const windowedFailures = (failedResult.data ?? []).filter((r) => {
699
+ const t = new Date(r.start_time).getTime();
700
+ return t >= startTs && t <= endTs;
701
+ });
702
+ const nameCounts = {};
703
+ for (const r of windowedFailures) {
704
+ nameCounts[r.name] = (nameCounts[r.name] ?? 0) + 1;
705
+ }
706
+ const topFailures = Object.entries(nameCounts)
707
+ .sort((a, b) => b[1] - a[1])
708
+ .slice(0, 5)
709
+ .map(([name, count]) => `${name} (${count}x)`);
710
+ const statusCounts = { Passed: passed, Failed: failed, Incomplete: incomplete };
711
+ const windowLabel = endDate
712
+ ? `${resolvedStart} → ${endDate}`
713
+ : startDate
714
+ ? `${resolvedStart} → now`
715
+ : `last 48 hours`;
716
+ const passRate = total > 0 ? ((passed / total) * 100).toFixed(1) : '0.0';
717
+ const structured = {
718
+ total,
719
+ passed,
720
+ failed,
721
+ incomplete,
722
+ passRate: parseFloat(passRate),
723
+ topFailures,
724
+ window: windowLabel,
725
+ };
726
+ return respond(outputFormat, structured, formatProjectTestSummary(statusCounts, total, windowLabel, topFailures));
727
+ }
728
+ catch (e) {
729
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
730
+ }
731
+ });
732
+ // ─── delete_test_reports_before_date ──────────────────────────────────────
733
+ server.tool('delete_test_reports_before_date', 'Permanently delete all test execution records started before a given date. Fetches matching IDs automatically then deletes them. Requires confirmDeletion: true. This cannot be undone. Cloud Admin only (project keys CSRF-blocked on reporter delete).', {
734
+ beforeDate: z
735
+ .string()
736
+ .describe('ISO 8601 cutoff date. All tests with start_time before this date will be deleted, e.g. "2024-01-01T00:00:00Z".'),
737
+ confirmDeletion: z
738
+ .boolean()
739
+ .optional()
740
+ .describe('Must be true to confirm the permanent deletion. Omit or set false to preview what would be deleted.'),
741
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
742
+ projectName: z.string().optional().describe('Scope to this project name.'),
743
+ }, async ({ beforeDate, confirmDeletion, projectId, projectName }) => {
744
+ if (getActiveKeyType() !== 'jwt') {
745
+ return { content: [{ type: 'text', text: 'Error: Cloud Admin access required. The reporter delete endpoint is CSRF-blocked for project-level keys (Project Admin and Project User). Use switch_environment() to switch to a Cloud Admin profile.' }], isError: true };
746
+ }
747
+ try {
748
+ // The reporter API does not support start_time filter via API key (CSRF restriction).
749
+ // Fetch all records page by page and apply the date filter client-side.
750
+ const cutoff = new Date(beforeDate).getTime();
751
+ const allIds = [];
752
+ let page = 1;
753
+ while (true) {
754
+ const batch = await listTests({ limit: 500, page, returnTotalCount: false }, projectId, projectName);
755
+ for (const r of batch.data ?? []) {
756
+ if (new Date(r.start_time).getTime() < cutoff)
757
+ allIds.push(r.test_id);
758
+ }
759
+ if ((batch.data ?? []).length < 500)
760
+ break;
761
+ page++;
762
+ }
763
+ if (allIds.length === 0) {
764
+ return { content: [{ type: 'text', text: `No test reports found before ${beforeDate}.` }] };
765
+ }
766
+ const guard = checkDestructiveGuard(confirmDeletion, `Delete ${allIds.length} test report(s) started before ${beforeDate}`);
767
+ if (guard) {
768
+ return {
769
+ content: [{ type: 'text', text: `${guard}\n\nPreview: ${allIds.length} record(s) would be deleted (IDs ${allIds[0]}…${allIds[allIds.length - 1]}).` }],
770
+ };
771
+ }
772
+ await deleteTests(allIds, projectId, projectName);
773
+ return {
774
+ content: [{ type: 'text', text: `✅ Deleted ${allIds.length} test report(s) started before ${beforeDate}.` }],
775
+ };
776
+ }
777
+ catch (e) {
778
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
779
+ }
780
+ });
781
+ // ─── list_active_test_executions ──────────────────────────────────────────
782
+ server.tool('list_active_test_executions', 'Returns currently-running test executions. Active tests appear in the reporter as Incomplete status with no duration value. This tool encapsulates that heuristic so you don\'t need to compose list_test_reports filters manually. Useful for answering "what is running right now?"', {
783
+ limit: z
784
+ .number()
785
+ .int()
786
+ .min(1)
787
+ .max(200)
788
+ .optional()
789
+ .default(50)
790
+ .describe('Maximum number of active executions to return (default: 50).'),
791
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
792
+ projectName: z.string().optional().describe('Scope to this project name.'),
793
+ outputFormat: outputFormatParam,
794
+ }, async ({ limit, projectId, projectName, outputFormat }) => {
795
+ try {
796
+ // Active executions are Incomplete records with null duration.
797
+ // We fetch more than needed since not all Incomplete records are still running.
798
+ const result = await listTestsSortedDesc({
799
+ limit: Math.min((limit ?? 50) * 4, 500),
800
+ page: 1,
801
+ returnTotalCount: false,
802
+ filter: [{ property: 'status', operator: '=', value: 'Incomplete' }],
803
+ }, projectId, projectName);
804
+ const active = (result.data ?? []).filter(r => r.duration === null).slice(0, limit ?? 50);
805
+ if (active.length === 0) {
806
+ return respond(outputFormat, { count: 0, executions: [] }, 'No active test executions found. All Incomplete records have finished reporting.');
807
+ }
808
+ const structured = {
809
+ count: active.length,
810
+ executions: active.map(r => ({
811
+ testId: r.test_id,
812
+ uuid: r.uuid,
813
+ name: r.name,
814
+ startTime: r.start_time,
815
+ projectId: r.project_id,
816
+ })),
817
+ };
818
+ const now = Date.now();
819
+ const lines = [`🔴 Active test executions (${active.length}):\n`];
820
+ for (const r of active) {
821
+ const elapsedMs = now - new Date(r.start_time).getTime();
822
+ const elapsedMin = Math.floor(elapsedMs / 60000);
823
+ const elapsedSec = Math.floor((elapsedMs % 60000) / 1000);
824
+ lines.push(` • ${r.name}`, ` Test ID: ${r.test_id} UUID: ${r.uuid}`, ` Started: ${r.start_time} Elapsed: ${elapsedMin}m ${elapsedSec}s`, ` Project: ${r.project_id}`, '');
825
+ }
826
+ lines.push('Note: "active" is inferred from Incomplete status + null duration. A test that finished very recently may appear here until the reporter updates.');
827
+ return respond(outputFormat, structured, lines.join('\n'));
828
+ }
829
+ catch (e) {
830
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
831
+ }
832
+ });
833
+ // ─── get_failure_rate_by_app_version ──────────────────────────────────────
834
+ server.tool('get_failure_rate_by_app_version', 'Show pass/fail breakdown grouped by app version key. Requires that test runs record an app version in their key-value metadata. The versionKey parameter should match whatever key your test framework writes (e.g. "appVersion", "buildNumber", "releaseVersion").', {
835
+ versionKey: z
836
+ .string()
837
+ .default('appVersion')
838
+ .describe('The test report metadata key that holds the app version, e.g. "appVersion" or "buildNumber".'),
839
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
840
+ projectName: z.string().optional().describe('Scope to this project name.'),
841
+ outputFormat: outputFormatParam,
842
+ }, async ({ versionKey, projectId, projectName, outputFormat }) => {
843
+ try {
844
+ const result = await getGroupedTests({ groupBy: [versionKey], pivotBy: ['status'], returnTotalCount: true }, projectId, projectName);
845
+ return respond(outputFormat, result, formatGroupedTestReports(result));
846
+ }
847
+ catch (e) {
848
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
849
+ }
850
+ });
851
+ // ─── get_test_stability_report ────────────────────────────────────────────
852
+ server.tool('get_test_stability_report', 'Show the execution history of a named test: last N runs in chronological order, ' +
853
+ 'individual pass/fail, overall pass rate, and a sparkline trend. ' +
854
+ 'Use this to decide whether a failing test is a new regression or a recurring unstable test.', {
855
+ testName: z.string().describe('Exact or partial test name to look up.'),
856
+ maxRuns: z.number().int().min(1).max(200).optional().default(20)
857
+ .describe('Number of most-recent runs to retrieve (default: 20, max: 200).'),
858
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
859
+ projectName: z.string().optional().describe('Scope to this project name.'),
860
+ outputFormat: outputFormatParam,
861
+ }, async ({ testName, maxRuns, projectId, projectName, outputFormat }) => {
862
+ try {
863
+ const result = await listTestsSortedDesc({
864
+ limit: maxRuns,
865
+ page: 1,
866
+ filter: [{ property: 'name', operator: 'contains', value: testName }],
867
+ returnTotalCount: false,
868
+ }, projectId, projectName);
869
+ const runs = result.data ?? [];
870
+ if (runs.length === 0) {
871
+ return respond(outputFormat, { found: false }, `No executions found for test name containing "${testName}".`);
872
+ }
873
+ const passed = runs.filter(r => r.status === 'Passed' || r.success).length;
874
+ const failed = runs.filter(r => r.status === 'Failed').length;
875
+ const other = runs.length - passed - failed;
876
+ const passRate = runs.length > 0 ? ((passed / runs.length) * 100).toFixed(1) : '0.0';
877
+ // Sparkline: ✅ = Passed, ❌ = Failed, ⚠️ = other — newest last
878
+ const spark = [...runs].reverse().map(r => {
879
+ if (r.status === 'Passed' || r.success)
880
+ return '✅';
881
+ if (r.status === 'Failed')
882
+ return '❌';
883
+ return '⚠️';
884
+ }).join(' ');
885
+ // Consecutive streak from the most recent run
886
+ const latestStatus = runs[0].status;
887
+ let streak = 0;
888
+ for (const r of runs) {
889
+ if (r.status === latestStatus)
890
+ streak++;
891
+ else
892
+ break;
893
+ }
894
+ const streakLabel = streak > 1 ? ` (${streak} in a row)` : '';
895
+ const structured = {
896
+ testName: runs[0].name,
897
+ runs: runs.length,
898
+ passed, failed, other,
899
+ passRate: parseFloat(passRate),
900
+ latestStatus: runs[0].status,
901
+ latestRun: runs[0].start_time,
902
+ streak,
903
+ history: runs.map(r => ({
904
+ testId: r.test_id,
905
+ status: r.status,
906
+ startTime: r.start_time,
907
+ durationMs: r.duration,
908
+ })),
909
+ };
910
+ const lines = [
911
+ `📋 Stability report: "${runs[0].name}"`,
912
+ ` Runs examined: ${runs.length} | Pass rate: ${passRate}% | Latest: ${runs[0].status}${streakLabel}`,
913
+ ` ${passed} passed · ${failed} failed · ${other} other`,
914
+ ``,
915
+ ` Trend (oldest → newest):`,
916
+ ` ${spark}`,
917
+ ``,
918
+ ` Most recent ${Math.min(5, runs.length)} runs:`,
919
+ ...runs.slice(0, 5).map(r => {
920
+ const dur = r.duration != null ? `${(r.duration / 1000).toFixed(1)}s` : 'n/a';
921
+ const icon = r.status === 'Passed' ? '✅' : r.status === 'Failed' ? '❌' : '⚠️';
922
+ return ` ${icon} ${r.status} — ${r.start_time} (${dur})`;
923
+ }),
924
+ ];
925
+ return respond(outputFormat, structured, lines.join('\n'));
926
+ }
927
+ catch (e) {
928
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
929
+ }
930
+ });
931
+ // ─── get_cross_platform_divergence ────────────────────────────────────────
932
+ server.tool('get_cross_platform_divergence', 'Find tests that behave differently on Android vs iOS — passing consistently on one platform ' +
933
+ 'while failing on the other. Use this to detect platform-conditional bugs, ' +
934
+ 'missing device-specific handling, or OS API differences affecting test stability. ' +
935
+ 'Results sorted by divergence magnitude (largest gap first).', {
936
+ minRunsPerPlatform: z.number().int().min(1).optional().default(3)
937
+ .describe('Minimum runs on each platform to include a test in the comparison (default: 3). Filters out tests barely run on one OS.'),
938
+ minDivergencePct: z.number().min(0).max(100).optional().default(20)
939
+ .describe('Minimum pass-rate gap (percentage points) to flag as divergent (default: 20).'),
940
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
941
+ projectName: z.string().optional().describe('Scope to this project name.'),
942
+ outputFormat: outputFormatParam,
943
+ }, async ({ minRunsPerPlatform, minDivergencePct, projectId, projectName, outputFormat }) => {
944
+ try {
945
+ const raw = await getGroupedTests({ groupBy: ['name', 'device.os'], pivotBy: ['status'], returnTotalCount: false }, projectId, projectName);
946
+ const rows = Array.isArray(raw) ? raw : (raw.data ?? []);
947
+ const map = {};
948
+ for (const row of rows) {
949
+ const name = String(row['name'] ?? '');
950
+ const os = String(row['device.os'] ?? '');
951
+ if (!name || (os !== 'Android' && os !== 'iOS'))
952
+ continue;
953
+ const passed = Number(row['passedCount'] ?? 0);
954
+ const total = Number(row['_count_'] ?? (Number(row['passedCount'] ?? 0) + Number(row['failedCount'] ?? 0) + Number(row['incompleteCount'] ?? 0) + Number(row['errorCount'] ?? 0)));
955
+ if (!map[name])
956
+ map[name] = {};
957
+ map[name][os] = { passed, total };
958
+ }
959
+ // Find divergent tests
960
+ const divergent = Object.entries(map)
961
+ .filter(([, platforms]) => {
962
+ const a = platforms.Android;
963
+ const i = platforms.iOS;
964
+ return a && i && a.total >= minRunsPerPlatform && i.total >= minRunsPerPlatform;
965
+ })
966
+ .map(([name, platforms]) => {
967
+ const a = platforms.Android;
968
+ const i = platforms.iOS;
969
+ const androidPct = a.total > 0 ? (a.passed / a.total) * 100 : 0;
970
+ const iosPct = i.total > 0 ? (i.passed / i.total) * 100 : 0;
971
+ return {
972
+ name,
973
+ androidPassRate: parseFloat(androidPct.toFixed(1)),
974
+ androidRuns: a.total,
975
+ iosPassRate: parseFloat(iosPct.toFixed(1)),
976
+ iosRuns: i.total,
977
+ divergencePct: parseFloat(Math.abs(androidPct - iosPct).toFixed(1)),
978
+ failingOn: androidPct < iosPct ? 'Android' : 'iOS',
979
+ };
980
+ })
981
+ .filter(t => t.divergencePct >= minDivergencePct)
982
+ .sort((a, b) => b.divergencePct - a.divergencePct);
983
+ const structured = { found: divergent.length, minRunsPerPlatform, minDivergencePct, divergentTests: divergent };
984
+ if (divergent.length === 0) {
985
+ return respond(outputFormat, structured, `No tests found with ≥${minDivergencePct}pp divergence between Android and iOS (min ${minRunsPerPlatform} runs each platform).`);
986
+ }
987
+ const lines = [
988
+ `🔀 Cross-platform divergence (${divergent.length} tests with ≥${minDivergencePct}pp gap):\n`,
989
+ ...divergent.slice(0, 20).map(t => ` ❗ "${t.name}"\n` +
990
+ ` Android: ${t.androidPassRate}% pass (${t.androidRuns} runs) ` +
991
+ `iOS: ${t.iosPassRate}% pass (${t.iosRuns} runs) ` +
992
+ `Gap: ${t.divergencePct}pp — failing more on ${t.failingOn}`),
993
+ divergent.length > 20 ? `\n … and ${divergent.length - 20} more` : '',
994
+ ].filter(Boolean);
995
+ return respond(outputFormat, structured, lines.join('\n'));
996
+ }
997
+ catch (e) {
998
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
999
+ }
1000
+ });
1001
+ // ─── get_daily_execution_trend ────────────────────────────────────────────
1002
+ server.tool('get_daily_execution_trend', 'Show test execution counts and pass rates bucketed by day or week. ' +
1003
+ 'Use this to detect volume drops (CI stopped running tests), quality degradation over a sprint, ' +
1004
+ 'or spikes in failures following a deployment. ' +
1005
+ 'Fetches records sorted newest-first and stops at maxRecords OR lookbackDays, whichever comes first.', {
1006
+ lookbackDays: z.number().int().min(1).max(365).optional().default(30)
1007
+ .describe('How many days back to analyse (default: 30). Scanning stops as soon as this boundary is crossed.'),
1008
+ maxRecords: z.number().int().min(100).max(25000).optional().default(5000)
1009
+ .describe('Hard cap on records fetched to protect against very large datasets (default: 5 000, max: 25 000). Increase if your project runs >165 tests/day and lookbackDays > 30.'),
1010
+ bucketBy: z.enum(['day', 'week']).optional().default('day')
1011
+ .describe('"day" (default) or "week". Weekly buckets are cleaner for 90-day views.'),
1012
+ projectId: z.number().int().optional().describe('Scope to this project ID.'),
1013
+ projectName: z.string().optional().describe('Scope to this project name.'),
1014
+ outputFormat: outputFormatParam,
1015
+ }, async ({ lookbackDays, maxRecords, bucketBy, projectId, projectName, outputFormat }) => {
1016
+ try {
1017
+ const cutoffTs = Date.now() - lookbackDays * 86400000;
1018
+ const records = [];
1019
+ let fetchPage = 1;
1020
+ let done = false;
1021
+ while (!done && records.length < maxRecords) {
1022
+ const batch = await listTests({ limit: 500, page: fetchPage, returnTotalCount: false,
1023
+ sort: [{ property: 'start_time', descending: true }] }, projectId, projectName);
1024
+ const rows = batch.data ?? [];
1025
+ if (rows.length === 0)
1026
+ break;
1027
+ for (const r of rows) {
1028
+ const ts = new Date(r.start_time).getTime();
1029
+ if (ts < cutoffTs) {
1030
+ done = true;
1031
+ break;
1032
+ }
1033
+ records.push({ status: r.status, start_time: r.start_time });
1034
+ if (records.length >= maxRecords) {
1035
+ done = true;
1036
+ break;
1037
+ }
1038
+ }
1039
+ if (rows.length < 500)
1040
+ done = true;
1041
+ fetchPage++;
1042
+ }
1043
+ if (records.length === 0) {
1044
+ return respond(outputFormat, { buckets: [] }, `No test executions found in the last ${lookbackDays} days.`);
1045
+ }
1046
+ // Bucket by day or week
1047
+ const bucketKey = (isoDate) => {
1048
+ const d = new Date(isoDate);
1049
+ if (bucketBy === 'week') {
1050
+ // ISO week start (Monday)
1051
+ const day = d.getUTCDay() || 7;
1052
+ const monday = new Date(d);
1053
+ monday.setUTCDate(d.getUTCDate() - (day - 1));
1054
+ return monday.toISOString().slice(0, 10);
1055
+ }
1056
+ return d.toISOString().slice(0, 10);
1057
+ };
1058
+ const buckets = {};
1059
+ for (const r of records) {
1060
+ const key = bucketKey(r.start_time);
1061
+ if (!buckets[key])
1062
+ buckets[key] = { total: 0, passed: 0, failed: 0, other: 0 };
1063
+ buckets[key].total++;
1064
+ if (r.status === 'Passed')
1065
+ buckets[key].passed++;
1066
+ else if (r.status === 'Failed')
1067
+ buckets[key].failed++;
1068
+ else
1069
+ buckets[key].other++;
1070
+ }
1071
+ const sorted = Object.entries(buckets).sort(([a], [b]) => a.localeCompare(b));
1072
+ const structured = {
1073
+ bucketBy,
1074
+ lookbackDays,
1075
+ recordsScanned: records.length,
1076
+ cappedAt: records.length >= maxRecords ? maxRecords : null,
1077
+ buckets: sorted.map(([date, b]) => ({
1078
+ date,
1079
+ total: b.total,
1080
+ passed: b.passed,
1081
+ failed: b.failed,
1082
+ other: b.other,
1083
+ passRate: b.total > 0 ? parseFloat(((b.passed / b.total) * 100).toFixed(1)) : null,
1084
+ })),
1085
+ };
1086
+ const lines = [
1087
+ `📅 Test execution trend (${bucketBy === 'week' ? 'weekly' : 'daily'}, last ${lookbackDays} days — ${records.length} records scanned)\n`,
1088
+ ` ${'Date'.padEnd(12)} ${'Total'.padStart(6)} ${'Passed'.padStart(7)} ${'Failed'.padStart(7)} ${'Pass%'.padStart(7)}`,
1089
+ ` ${'─'.repeat(44)}`,
1090
+ ...sorted.map(([date, b]) => {
1091
+ const pct = b.total > 0 ? ((b.passed / b.total) * 100).toFixed(1) : '—';
1092
+ return ` ${date.padEnd(12)} ${String(b.total).padStart(6)} ${String(b.passed).padStart(7)} ${String(b.failed).padStart(7)} ${pct.padStart(7)}`;
1093
+ }),
1094
+ ];
1095
+ if (records.length >= maxRecords) {
1096
+ lines.push(`\n ⚠️ Capped at ${maxRecords} records — increase maxRecords or reduce lookbackDays for a complete picture.`);
1097
+ }
1098
+ return respond(outputFormat, structured, lines.join('\n'));
1099
+ }
1100
+ catch (e) {
1101
+ return { content: [{ type: 'text', text: `Error: ${e.message}` }], isError: true };
1102
+ }
1103
+ });
1104
+ }
1105
+ //# sourceMappingURL=reporting-tools.js.map