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.
- package/LICENSE +197 -0
- package/README.md +984 -0
- package/dist/api/agents.d.ts +5 -0
- package/dist/api/agents.d.ts.map +1 -0
- package/dist/api/agents.js +33 -0
- package/dist/api/agents.js.map +1 -0
- package/dist/api/applications.d.ts +35 -0
- package/dist/api/applications.d.ts.map +1 -0
- package/dist/api/applications.js +162 -0
- package/dist/api/applications.js.map +1 -0
- package/dist/api/backup.d.ts +4 -0
- package/dist/api/backup.d.ts.map +1 -0
- package/dist/api/backup.js +13 -0
- package/dist/api/backup.js.map +1 -0
- package/dist/api/browser-inspection.d.ts +33 -0
- package/dist/api/browser-inspection.d.ts.map +1 -0
- package/dist/api/browser-inspection.js +273 -0
- package/dist/api/browser-inspection.js.map +1 -0
- package/dist/api/browsers.d.ts +20 -0
- package/dist/api/browsers.d.ts.map +1 -0
- package/dist/api/browsers.js +31 -0
- package/dist/api/browsers.js.map +1 -0
- package/dist/api/client.d.ts +33 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +200 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/device-groups.d.ts +15 -0
- package/dist/api/device-groups.d.ts.map +1 -0
- package/dist/api/device-groups.js +106 -0
- package/dist/api/device-groups.js.map +1 -0
- package/dist/api/devices.d.ts +32 -0
- package/dist/api/devices.d.ts.map +1 -0
- package/dist/api/devices.js +192 -0
- package/dist/api/devices.js.map +1 -0
- package/dist/api/license.d.ts +3 -0
- package/dist/api/license.d.ts.map +1 -0
- package/dist/api/license.js +11 -0
- package/dist/api/license.js.map +1 -0
- package/dist/api/nv-servers.d.ts +4 -0
- package/dist/api/nv-servers.d.ts.map +1 -0
- package/dist/api/nv-servers.js +20 -0
- package/dist/api/nv-servers.js.map +1 -0
- package/dist/api/projects.d.ts +36 -0
- package/dist/api/projects.d.ts.map +1 -0
- package/dist/api/projects.js +246 -0
- package/dist/api/projects.js.map +1 -0
- package/dist/api/provisioning-profiles.d.ts +7 -0
- package/dist/api/provisioning-profiles.d.ts.map +1 -0
- package/dist/api/provisioning-profiles.js +54 -0
- package/dist/api/provisioning-profiles.js.map +1 -0
- package/dist/api/regions.d.ts +4 -0
- package/dist/api/regions.d.ts.map +1 -0
- package/dist/api/regions.js +20 -0
- package/dist/api/regions.js.map +1 -0
- package/dist/api/reporter-projects.d.ts +3 -0
- package/dist/api/reporter-projects.d.ts.map +1 -0
- package/dist/api/reporter-projects.js +13 -0
- package/dist/api/reporter-projects.js.map +1 -0
- package/dist/api/reporting.d.ts +28 -0
- package/dist/api/reporting.d.ts.map +1 -0
- package/dist/api/reporting.js +340 -0
- package/dist/api/reporting.js.map +1 -0
- package/dist/api/repository.d.ts +17 -0
- package/dist/api/repository.d.ts.map +1 -0
- package/dist/api/repository.js +81 -0
- package/dist/api/repository.js.map +1 -0
- package/dist/api/reservations.d.ts +9 -0
- package/dist/api/reservations.d.ts.map +1 -0
- package/dist/api/reservations.js +72 -0
- package/dist/api/reservations.js.map +1 -0
- package/dist/api/sessions.d.ts +3 -0
- package/dist/api/sessions.d.ts.map +1 -0
- package/dist/api/sessions.js +12 -0
- package/dist/api/sessions.js.map +1 -0
- package/dist/api/test-views.d.ts +9 -0
- package/dist/api/test-views.d.ts.map +1 -0
- package/dist/api/test-views.js +77 -0
- package/dist/api/test-views.js.map +1 -0
- package/dist/api/transactions.d.ts +4 -0
- package/dist/api/transactions.d.ts.map +1 -0
- package/dist/api/transactions.js +28 -0
- package/dist/api/transactions.js.map +1 -0
- package/dist/api/usage-reports.d.ts +24 -0
- package/dist/api/usage-reports.d.ts.map +1 -0
- package/dist/api/usage-reports.js +47 -0
- package/dist/api/usage-reports.js.map +1 -0
- package/dist/api/users.d.ts +14 -0
- package/dist/api/users.d.ts.map +1 -0
- package/dist/api/users.js +77 -0
- package/dist/api/users.js.map +1 -0
- package/dist/api/webdriver.d.ts +97 -0
- package/dist/api/webdriver.d.ts.map +1 -0
- package/dist/api/webdriver.js +1183 -0
- package/dist/api/webdriver.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +130 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/agent-tools.d.ts +3 -0
- package/dist/tools/agent-tools.d.ts.map +1 -0
- package/dist/tools/agent-tools.js +74 -0
- package/dist/tools/agent-tools.js.map +1 -0
- package/dist/tools/application-tools.d.ts +3 -0
- package/dist/tools/application-tools.d.ts.map +1 -0
- package/dist/tools/application-tools.js +816 -0
- package/dist/tools/application-tools.js.map +1 -0
- package/dist/tools/backup-tools.d.ts +3 -0
- package/dist/tools/backup-tools.d.ts.map +1 -0
- package/dist/tools/backup-tools.js +33 -0
- package/dist/tools/backup-tools.js.map +1 -0
- package/dist/tools/boilerplate-tools.d.ts +9 -0
- package/dist/tools/boilerplate-tools.d.ts.map +1 -0
- package/dist/tools/boilerplate-tools.js +1365 -0
- package/dist/tools/boilerplate-tools.js.map +1 -0
- package/dist/tools/browser-tools.d.ts +3 -0
- package/dist/tools/browser-tools.d.ts.map +1 -0
- package/dist/tools/browser-tools.js +108 -0
- package/dist/tools/browser-tools.js.map +1 -0
- package/dist/tools/coverage-tools.d.ts +3 -0
- package/dist/tools/coverage-tools.d.ts.map +1 -0
- package/dist/tools/coverage-tools.js +148 -0
- package/dist/tools/coverage-tools.js.map +1 -0
- package/dist/tools/debug-tools.d.ts +3 -0
- package/dist/tools/debug-tools.d.ts.map +1 -0
- package/dist/tools/debug-tools.js +315 -0
- package/dist/tools/debug-tools.js.map +1 -0
- package/dist/tools/device-group-tools.d.ts +3 -0
- package/dist/tools/device-group-tools.d.ts.map +1 -0
- package/dist/tools/device-group-tools.js +284 -0
- package/dist/tools/device-group-tools.js.map +1 -0
- package/dist/tools/device-tools.d.ts +3 -0
- package/dist/tools/device-tools.d.ts.map +1 -0
- package/dist/tools/device-tools.js +757 -0
- package/dist/tools/device-tools.js.map +1 -0
- package/dist/tools/health-tools.d.ts +3 -0
- package/dist/tools/health-tools.d.ts.map +1 -0
- package/dist/tools/health-tools.js +368 -0
- package/dist/tools/health-tools.js.map +1 -0
- package/dist/tools/inspection-tools.d.ts +3 -0
- package/dist/tools/inspection-tools.d.ts.map +1 -0
- package/dist/tools/inspection-tools.js +1170 -0
- package/dist/tools/inspection-tools.js.map +1 -0
- package/dist/tools/meta-tools.d.ts +4 -0
- package/dist/tools/meta-tools.d.ts.map +1 -0
- package/dist/tools/meta-tools.js +412 -0
- package/dist/tools/meta-tools.js.map +1 -0
- package/dist/tools/nv-server-tools.d.ts +3 -0
- package/dist/tools/nv-server-tools.d.ts.map +1 -0
- package/dist/tools/nv-server-tools.js +67 -0
- package/dist/tools/nv-server-tools.js.map +1 -0
- package/dist/tools/performance-tools.d.ts +3 -0
- package/dist/tools/performance-tools.d.ts.map +1 -0
- package/dist/tools/performance-tools.js +295 -0
- package/dist/tools/performance-tools.js.map +1 -0
- package/dist/tools/project-tools.d.ts +3 -0
- package/dist/tools/project-tools.d.ts.map +1 -0
- package/dist/tools/project-tools.js +577 -0
- package/dist/tools/project-tools.js.map +1 -0
- package/dist/tools/prompt-tools.d.ts +3 -0
- package/dist/tools/prompt-tools.d.ts.map +1 -0
- package/dist/tools/prompt-tools.js +570 -0
- package/dist/tools/prompt-tools.js.map +1 -0
- package/dist/tools/provisioning-profile-tools.d.ts +3 -0
- package/dist/tools/provisioning-profile-tools.d.ts.map +1 -0
- package/dist/tools/provisioning-profile-tools.js +169 -0
- package/dist/tools/provisioning-profile-tools.js.map +1 -0
- package/dist/tools/region-tools.d.ts +3 -0
- package/dist/tools/region-tools.d.ts.map +1 -0
- package/dist/tools/region-tools.js +46 -0
- package/dist/tools/region-tools.js.map +1 -0
- package/dist/tools/reporting-tools.d.ts +3 -0
- package/dist/tools/reporting-tools.d.ts.map +1 -0
- package/dist/tools/reporting-tools.js +1105 -0
- package/dist/tools/reporting-tools.js.map +1 -0
- package/dist/tools/repository-tools.d.ts +3 -0
- package/dist/tools/repository-tools.d.ts.map +1 -0
- package/dist/tools/repository-tools.js +208 -0
- package/dist/tools/repository-tools.js.map +1 -0
- package/dist/tools/reservation-tools.d.ts +3 -0
- package/dist/tools/reservation-tools.d.ts.map +1 -0
- package/dist/tools/reservation-tools.js +199 -0
- package/dist/tools/reservation-tools.js.map +1 -0
- package/dist/tools/resources.d.ts +3 -0
- package/dist/tools/resources.d.ts.map +1 -0
- package/dist/tools/resources.js +91 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/test-view-tools.d.ts +3 -0
- package/dist/tools/test-view-tools.d.ts.map +1 -0
- package/dist/tools/test-view-tools.js +242 -0
- package/dist/tools/test-view-tools.js.map +1 -0
- package/dist/tools/transaction-tools.d.ts +3 -0
- package/dist/tools/transaction-tools.d.ts.map +1 -0
- package/dist/tools/transaction-tools.js +391 -0
- package/dist/tools/transaction-tools.js.map +1 -0
- package/dist/tools/usage-report-tools.d.ts +3 -0
- package/dist/tools/usage-report-tools.d.ts.map +1 -0
- package/dist/tools/usage-report-tools.js +160 -0
- package/dist/tools/usage-report-tools.js.map +1 -0
- package/dist/tools/user-tools.d.ts +3 -0
- package/dist/tools/user-tools.d.ts.map +1 -0
- package/dist/tools/user-tools.js +279 -0
- package/dist/tools/user-tools.js.map +1 -0
- package/dist/tools/web-inspection-tools.d.ts +3 -0
- package/dist/tools/web-inspection-tools.d.ts.map +1 -0
- package/dist/tools/web-inspection-tools.js +416 -0
- package/dist/tools/web-inspection-tools.js.map +1 -0
- package/dist/tools/workflow-tools.d.ts +3 -0
- package/dist/tools/workflow-tools.d.ts.map +1 -0
- package/dist/tools/workflow-tools.js +1136 -0
- package/dist/tools/workflow-tools.js.map +1 -0
- package/dist/types/digital-ai.d.ts +691 -0
- package/dist/types/digital-ai.d.ts.map +1 -0
- package/dist/types/digital-ai.js +3 -0
- package/dist/types/digital-ai.js.map +1 -0
- package/dist/utils/csv.d.ts +6 -0
- package/dist/utils/csv.d.ts.map +1 -0
- package/dist/utils/csv.js +77 -0
- package/dist/utils/csv.js.map +1 -0
- package/dist/utils/destructive-guard.d.ts +2 -0
- package/dist/utils/destructive-guard.d.ts.map +1 -0
- package/dist/utils/destructive-guard.js +13 -0
- package/dist/utils/destructive-guard.js.map +1 -0
- package/dist/utils/device-resolver.d.ts +22 -0
- package/dist/utils/device-resolver.d.ts.map +1 -0
- package/dist/utils/device-resolver.js +69 -0
- package/dist/utils/device-resolver.js.map +1 -0
- package/dist/utils/download-command.d.ts +18 -0
- package/dist/utils/download-command.d.ts.map +1 -0
- package/dist/utils/download-command.js +54 -0
- package/dist/utils/download-command.js.map +1 -0
- package/dist/utils/locality.d.ts +9 -0
- package/dist/utils/locality.d.ts.map +1 -0
- package/dist/utils/locality.js +22 -0
- package/dist/utils/locality.js.map +1 -0
- package/dist/utils/output-format.d.ts +13 -0
- package/dist/utils/output-format.d.ts.map +1 -0
- package/dist/utils/output-format.js +13 -0
- package/dist/utils/output-format.js.map +1 -0
- package/dist/utils/pagination.d.ts +12 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +24 -0
- package/dist/utils/pagination.js.map +1 -0
- package/dist/utils/path-guard.d.ts +17 -0
- package/dist/utils/path-guard.d.ts.map +1 -0
- package/dist/utils/path-guard.js +41 -0
- package/dist/utils/path-guard.js.map +1 -0
- package/dist/utils/performance-comparison.d.ts +53 -0
- package/dist/utils/performance-comparison.d.ts.map +1 -0
- package/dist/utils/performance-comparison.js +286 -0
- package/dist/utils/performance-comparison.js.map +1 -0
- package/dist/utils/performance-stats.d.ts +72 -0
- package/dist/utils/performance-stats.d.ts.map +1 -0
- package/dist/utils/performance-stats.js +124 -0
- package/dist/utils/performance-stats.js.map +1 -0
- package/dist/utils/profile-loader.d.ts +37 -0
- package/dist/utils/profile-loader.d.ts.map +1 -0
- package/dist/utils/profile-loader.js +80 -0
- package/dist/utils/profile-loader.js.map +1 -0
- package/dist/utils/response-formatter.d.ts +27 -0
- package/dist/utils/response-formatter.d.ts.map +1 -0
- package/dist/utils/response-formatter.js +493 -0
- package/dist/utils/response-formatter.js.map +1 -0
- package/dist/utils/timestamp.d.ts +12 -0
- package/dist/utils/timestamp.d.ts.map +1 -0
- package/dist/utils/timestamp.js +22 -0
- package/dist/utils/timestamp.js.map +1 -0
- package/dist/utils/tool-registry.d.ts +21 -0
- package/dist/utils/tool-registry.d.ts.map +1 -0
- package/dist/utils/tool-registry.js +137 -0
- package/dist/utils/tool-registry.js.map +1 -0
- package/dist/utils/upload-command.d.ts +20 -0
- package/dist/utils/upload-command.d.ts.map +1 -0
- package/dist/utils/upload-command.js +64 -0
- package/dist/utils/upload-command.js.map +1 -0
- package/dist/utils/usage-report-guard.d.ts +48 -0
- package/dist/utils/usage-report-guard.d.ts.map +1 -0
- package/dist/utils/usage-report-guard.js +88 -0
- package/dist/utils/usage-report-guard.js.map +1 -0
- package/dist/utils/usage-report-summary.d.ts +20 -0
- package/dist/utils/usage-report-summary.d.ts.map +1 -0
- package/dist/utils/usage-report-summary.js +48 -0
- package/dist/utils/usage-report-summary.js.map +1 -0
- package/dist/utils/version.d.ts +2 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +24 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +73 -0
- package/resources/boilerplate/Android-Native/Java JUnit5/AndroidNative-oss.java +58 -0
- package/resources/boilerplate/Android-Native/Java JUnit5/AndroidNative.java +67 -0
- package/resources/boilerplate/Android-Native/Java JUnit5/gradle +10 -0
- package/resources/boilerplate/Android-Native/Java JUnit5/gradle-oss +10 -0
- package/resources/boilerplate/Android-Native/Java JUnit5/maven +42 -0
- package/resources/boilerplate/Android-Native/Java JUnit5/maven-oss +42 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/AndroidNative.js +30 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/Shell +19 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/Shell-oss +19 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/package-oss.json +12 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/package.json +12 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/wdio-oss.conf.js +40 -0
- package/resources/boilerplate/Android-Native/NodeJS (WebDriver)/wdio.conf.js +44 -0
- package/resources/boilerplate/Android-Native/Python/AndroidNative-oss.py +49 -0
- package/resources/boilerplate/Android-Native/Python/AndroidNative.py +69 -0
- package/resources/boilerplate/Android-Native/Python/pip +2 -0
- package/resources/boilerplate/Android-Native/Python/pip-oss +1 -0
- package/resources/boilerplate/Android-Native/java TestNG/AndroidNative-oss.java +58 -0
- package/resources/boilerplate/Android-Native/java TestNG/AndroidNative.java +67 -0
- package/resources/boilerplate/Android-Native/java TestNG/gradle +13 -0
- package/resources/boilerplate/Android-Native/java TestNG/gradle-oss +13 -0
- package/resources/boilerplate/Android-Native/java TestNG/maven +42 -0
- package/resources/boilerplate/Android-Native/java TestNG/maven-oss +42 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/Shell-oss.txt +19 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/Shell.txt +19 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/iOSNative.js +30 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/package-oss.json +12 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/package.json +12 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/wdio-oss.conf.js +35 -0
- package/resources/boilerplate/iOS-Native/NodeJS (WebDriver)/wdio.conf.js +39 -0
- package/resources/boilerplate/iOS-Native/Python/iOSNative-oss.py +44 -0
- package/resources/boilerplate/iOS-Native/Python/iOSNative.py +62 -0
- package/resources/boilerplate/iOS-Native/Python/pip-oss.txt +1 -0
- package/resources/boilerplate/iOS-Native/Python/pip.txt +2 -0
- package/resources/boilerplate/iOS-Native/java-JUnit5/gradle +10 -0
- package/resources/boilerplate/iOS-Native/java-JUnit5/gradle-oss +10 -0
- package/resources/boilerplate/iOS-Native/java-JUnit5/iOSNative-oss.java +52 -0
- package/resources/boilerplate/iOS-Native/java-JUnit5/iOSNative.java +59 -0
- package/resources/boilerplate/iOS-Native/java-JUnit5/maven +42 -0
- package/resources/boilerplate/iOS-Native/java-JUnit5/maven-oss +42 -0
- package/resources/boilerplate/iOS-Native/java-TestNG/gradle +13 -0
- package/resources/boilerplate/iOS-Native/java-TestNG/gradle-oss +13 -0
- package/resources/boilerplate/iOS-Native/java-TestNG/iOSNative-oss.java +52 -0
- package/resources/boilerplate/iOS-Native/java-TestNG/iOSNative.java +59 -0
- package/resources/boilerplate/iOS-Native/java-TestNG/maven +42 -0
- package/resources/boilerplate/iOS-Native/java-TestNG/maven-oss +42 -0
|
@@ -0,0 +1,1170 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createInspectionSession, quitInspectionSession, captureScreenshot, getPageSource, findElements, tapElement, typeIntoElement, clearElement, swipeScreen, getWindowSize, launchApp, pressBack, longPress, doubleTap, dragAndDrop, pinchZoom, scrollToElement, pressKey, isKeyboardShown, hideKeyboard, appControl, getOrientation, setOrientation, getClipboard, setClipboard, setGeolocation, resetGeolocation, handleAlert, pushFileToDevice, pullFileFromDevice, mockAuthentication, requireSession, findFirstElementId, listActiveSessions, getPendingReportIds, deleteAllTrackedReports, } from '../api/webdriver.js';
|
|
3
|
+
import { checkDestructiveGuard } from '../utils/destructive-guard.js';
|
|
4
|
+
import { getActiveKeyType, getActiveUrl } from '../api/client.js';
|
|
5
|
+
import { resolveDevice } from '../utils/device-resolver.js';
|
|
6
|
+
import { getAllDevices } from '../api/devices.js';
|
|
7
|
+
import { validateInputPath, validateOutputPath } from '../utils/path-guard.js';
|
|
8
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
9
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
10
|
+
// Returns an error result if the session is a browser (web) session — used to
|
|
11
|
+
// guard mobile-only tools so they produce a clear message instead of a protocol error.
|
|
12
|
+
function requireMobileSession(handle, toolName) {
|
|
13
|
+
try {
|
|
14
|
+
const session = requireSession(handle);
|
|
15
|
+
if (session.platform === 'web') {
|
|
16
|
+
return {
|
|
17
|
+
content: [{
|
|
18
|
+
type: 'text',
|
|
19
|
+
text: `"${toolName}" is for mobile sessions only (Android/iOS). ` +
|
|
20
|
+
`For browser sessions use: navigate_to (instead of launch_app), ` +
|
|
21
|
+
`browser_action("back") (instead of press_back/app_control), ` +
|
|
22
|
+
`find_web_elements + tap_element/type_into_element for interactions. ` +
|
|
23
|
+
`Gestures (pinch_zoom, press_key, hide_keyboard) and device_control are not available in browser sessions.`,
|
|
24
|
+
}],
|
|
25
|
+
isError: true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// requireSession will throw a "no active session" error — let the tool itself handle it
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function sessionSummary(s) {
|
|
35
|
+
const age = Math.round((Date.now() - s.startedAt) / 1000);
|
|
36
|
+
const idle = Math.round((Date.now() - s.lastUsedAt) / 1000);
|
|
37
|
+
const idleWarning = idle > 180 ? ' ⚠️ likely expired (Grid idle timeout ~4 min)' : '';
|
|
38
|
+
return (`Handle: ${s.handle}\n` +
|
|
39
|
+
`Device: ${s.deviceName} (${s.deviceOs} ${s.deviceVersion})\n` +
|
|
40
|
+
`App: ${s.appPackage || '(none)'}\n` +
|
|
41
|
+
`Age: ${age}s | Idle: ${idle}s${idleWarning}\n` +
|
|
42
|
+
(s.cloudViewLink ? `Studio: ${s.cloudViewLink}\n` : ''));
|
|
43
|
+
}
|
|
44
|
+
// Extract a named attribute value from an XML attribute string.
|
|
45
|
+
function extractAttr(attrs, name) {
|
|
46
|
+
const re = new RegExp(`${name}="([^"]*)"`, 'i');
|
|
47
|
+
const m = re.exec(attrs);
|
|
48
|
+
return m ? m[1] : null;
|
|
49
|
+
}
|
|
50
|
+
// Shorten a class name to just the leaf component (e.g. android.widget.EditText → EditText).
|
|
51
|
+
function shortClass(cls) {
|
|
52
|
+
const parts = cls.split('.');
|
|
53
|
+
return parts[parts.length - 1] ?? cls;
|
|
54
|
+
}
|
|
55
|
+
// Strip the package prefix from a resource-id (e.g. com.example:id/foo → foo).
|
|
56
|
+
function shortId(id) {
|
|
57
|
+
const colonIdx = id.indexOf(':id/');
|
|
58
|
+
return colonIdx >= 0 ? id.slice(colonIdx + 4) : id;
|
|
59
|
+
}
|
|
60
|
+
function parseElementTree(xml, platform) {
|
|
61
|
+
const elements = [];
|
|
62
|
+
let totalNodes = 0;
|
|
63
|
+
// Match opening or self-closing tags (not closing tags, not processing instructions)
|
|
64
|
+
const tagRe = /<([\w.]+)(\s[^>]*?)?(?:\s*\/?>)/g;
|
|
65
|
+
let m;
|
|
66
|
+
while ((m = tagRe.exec(xml)) !== null) {
|
|
67
|
+
const cls = m[1];
|
|
68
|
+
if (cls === 'hierarchy' || cls === 'AppiumAUT' || cls === 'node')
|
|
69
|
+
continue;
|
|
70
|
+
const attrs = m[2] ?? '';
|
|
71
|
+
totalNodes++;
|
|
72
|
+
if (platform === 'ios') {
|
|
73
|
+
// XCUI XML: locators live in name/label/value; geometry in x/y/width/height.
|
|
74
|
+
const name = extractAttr(attrs, 'name');
|
|
75
|
+
const label = extractAttr(attrs, 'label');
|
|
76
|
+
const value = extractAttr(attrs, 'value');
|
|
77
|
+
const visible = extractAttr(attrs, 'visible') !== 'false';
|
|
78
|
+
const enabled = extractAttr(attrs, 'enabled') !== 'false';
|
|
79
|
+
const x = extractAttr(attrs, 'x');
|
|
80
|
+
const y = extractAttr(attrs, 'y');
|
|
81
|
+
const w = extractAttr(attrs, 'width');
|
|
82
|
+
const h = extractAttr(attrs, 'height');
|
|
83
|
+
const bounds = x != null && y != null && w != null && h != null
|
|
84
|
+
? `[${x},${y}][${Number(x) + Number(w)},${Number(y) + Number(h)}]`
|
|
85
|
+
: null;
|
|
86
|
+
elements.push({
|
|
87
|
+
className: cls,
|
|
88
|
+
resourceId: null,
|
|
89
|
+
contentDesc: null,
|
|
90
|
+
text: null,
|
|
91
|
+
bounds,
|
|
92
|
+
clickable: visible,
|
|
93
|
+
enabled,
|
|
94
|
+
fullResourceId: null,
|
|
95
|
+
name: name || null,
|
|
96
|
+
label: label || null,
|
|
97
|
+
value: value || null,
|
|
98
|
+
});
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const resourceId = extractAttr(attrs, 'resource-id');
|
|
102
|
+
const contentDesc = extractAttr(attrs, 'content-desc');
|
|
103
|
+
const text = extractAttr(attrs, 'text');
|
|
104
|
+
const bounds = extractAttr(attrs, 'bounds');
|
|
105
|
+
const clickable = extractAttr(attrs, 'clickable') === 'true';
|
|
106
|
+
const enabled = extractAttr(attrs, 'enabled') !== 'false';
|
|
107
|
+
elements.push({
|
|
108
|
+
className: cls,
|
|
109
|
+
resourceId,
|
|
110
|
+
contentDesc: contentDesc || null,
|
|
111
|
+
text: text || null,
|
|
112
|
+
bounds,
|
|
113
|
+
clickable,
|
|
114
|
+
enabled,
|
|
115
|
+
fullResourceId: resourceId,
|
|
116
|
+
name: null,
|
|
117
|
+
label: null,
|
|
118
|
+
value: null,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return { elements, totalNodes };
|
|
122
|
+
}
|
|
123
|
+
function formatElementTable(elements, totalNodes, platform) {
|
|
124
|
+
if (platform === 'ios') {
|
|
125
|
+
const interesting = elements.filter((e) => e.name || e.label || e.value);
|
|
126
|
+
const lines = [
|
|
127
|
+
`Screen hierarchy: ${totalNodes} nodes total, ${interesting.length} with locators`,
|
|
128
|
+
'',
|
|
129
|
+
`${'Type'.padEnd(22)} ${'name'.padEnd(26)} ${'label'.padEnd(26)} ${'value'.padEnd(18)} Vis`,
|
|
130
|
+
'─'.repeat(98),
|
|
131
|
+
];
|
|
132
|
+
for (const e of interesting) {
|
|
133
|
+
const t = shortClass(e.className).replace(/^XCUIElementType/, '').padEnd(22);
|
|
134
|
+
const n = (e.name ?? '-').slice(0, 24).padEnd(26);
|
|
135
|
+
const l = (e.label ?? '-').slice(0, 24).padEnd(26);
|
|
136
|
+
const v = (e.value ?? '-').slice(0, 16).padEnd(18);
|
|
137
|
+
const vis = e.clickable ? '✓' : ' ';
|
|
138
|
+
lines.push(`${t} ${n} ${l} ${v} ${vis}`);
|
|
139
|
+
}
|
|
140
|
+
if (interesting.length === 0) {
|
|
141
|
+
lines.push(' (no elements with name, label, or value found on this screen)');
|
|
142
|
+
}
|
|
143
|
+
lines.push('', "Locate iOS elements with: strategy 'accessibility id' or 'name' (matches name), or xpath like //*[@label='...'] or //XCUIElementTypeButton.");
|
|
144
|
+
return lines.join('\n');
|
|
145
|
+
}
|
|
146
|
+
// Only show elements with at least one useful locator attribute
|
|
147
|
+
const interesting = elements.filter((e) => e.resourceId || e.contentDesc || e.text);
|
|
148
|
+
const lines = [
|
|
149
|
+
`Screen hierarchy: ${totalNodes} nodes total, ${interesting.length} with locators`,
|
|
150
|
+
'',
|
|
151
|
+
`${'Type'.padEnd(18)} ${'resource-id'.padEnd(28)} ${'content-desc'.padEnd(22)} ${'text'.padEnd(22)} Clk`,
|
|
152
|
+
'─'.repeat(96),
|
|
153
|
+
];
|
|
154
|
+
for (const e of interesting) {
|
|
155
|
+
const t = shortClass(e.className).padEnd(18);
|
|
156
|
+
const rid = (e.resourceId ? shortId(e.resourceId) : '-').padEnd(28);
|
|
157
|
+
const desc = (e.contentDesc ?? '-').slice(0, 20).padEnd(22);
|
|
158
|
+
const txt = (e.text ?? '-').slice(0, 20).padEnd(22);
|
|
159
|
+
const clk = e.clickable ? '✓' : ' ';
|
|
160
|
+
lines.push(`${t} ${rid} ${desc} ${txt} ${clk}`);
|
|
161
|
+
}
|
|
162
|
+
if (interesting.length === 0) {
|
|
163
|
+
lines.push(' (no elements with resource-id, content-desc, or text found on this screen)');
|
|
164
|
+
}
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
// ─── Tool registration ────────────────────────────────────────────────────────
|
|
168
|
+
export function registerInspectionTools(server) {
|
|
169
|
+
// ── start_inspection_session ──────────────────────────────────────────────
|
|
170
|
+
server.tool('start_inspection_session', 'Start a live WebDriver session on a real Android or iOS device for interactive test building. ' +
|
|
171
|
+
'Returns a session handle used by all other inspection tools, plus a viewUrl — ' +
|
|
172
|
+
'SHARE THE VIEW URL WITH THE USER IMMEDIATELY so they can watch the session live (read-only). ' +
|
|
173
|
+
'Do NOT share the cloudViewLink — a second connection to the same device will conflict and error. ' +
|
|
174
|
+
'Session creation takes 20-90 s while a device is allocated.\n\n' +
|
|
175
|
+
'MODE: Use INTERACTIVE (this tool + collaborative_test_creation prompt) when the request is vague, ' +
|
|
176
|
+
'the user wants to watch/drive, or exploration signals appear ("let\'s see what\'s there"). ' +
|
|
177
|
+
'Use AUTONOMOUS (silent session to capture element IDs → get_test_boilerplate) when intent is specific and selectors are needed. ' +
|
|
178
|
+
'NEVER fabricate selectors — get them from a live session or workspace source. ' +
|
|
179
|
+
'If unsure: ask "Build it for you, or work through it together?"\n\n' +
|
|
180
|
+
'WORKFLOW: list_applications (confirm version) → find_available_device (note region) → ' +
|
|
181
|
+
'install_application (MUST be before session — fails while device is reserved) → ' +
|
|
182
|
+
'start_inspection_session(device=<id>) → launch_app → get_element_tree/find_elements → interact → stop_inspection_session.\n\n' +
|
|
183
|
+
'iOS NOTES: elements located by name/label/value (not resource-id); ' +
|
|
184
|
+
'press_back performs left-edge swipe; clipboard and clear_data unavailable on Grid iOS.\n\n' +
|
|
185
|
+
'KNOWN LIMITATIONS: app/appPackage/appActivity params may return HTTP 500 — start a generic session and use launch_app instead. ' +
|
|
186
|
+
'Use the device param (not hand-written deviceQuery) to target a specific device reliably.\n\n' +
|
|
187
|
+
'Always call stop_inspection_session when done — open sessions consume a reserved device and create a reporter record. ' +
|
|
188
|
+
'Use cleanup_inspection_sessions for abandoned sessions.', {
|
|
189
|
+
platform: z
|
|
190
|
+
.enum(['android', 'ios'])
|
|
191
|
+
.optional()
|
|
192
|
+
.default('android')
|
|
193
|
+
.describe("Target platform. Default 'android'. Sets platformName and the default deviceQuery @os."),
|
|
194
|
+
device: z
|
|
195
|
+
.string()
|
|
196
|
+
.optional()
|
|
197
|
+
.describe('PIN the session to a specific device — numeric platform ID, serial/UDID, or unambiguous device name. ' +
|
|
198
|
+
'Use this to get the SAME device you selected with find_available_device and installed the app on ' +
|
|
199
|
+
'(without it, the Grid picks any matching device and your install may land elsewhere). ' +
|
|
200
|
+
'Confirmed working — resolves to an @serialNumber query. Overrides deviceQuery and region.'),
|
|
201
|
+
deviceQuery: z
|
|
202
|
+
.string()
|
|
203
|
+
.optional()
|
|
204
|
+
.describe("Server-side device query. Default: \"@os='android' and @category='PHONE'\" (or @os='iOS' when platform is ios). " +
|
|
205
|
+
"Add @region, @model, @version as needed. Example: \"@os='android' and @category='PHONE' and @model='Pixel 7'\". " +
|
|
206
|
+
'Ignored when device is provided.'),
|
|
207
|
+
region: z
|
|
208
|
+
.string()
|
|
209
|
+
.optional()
|
|
210
|
+
.describe("Region shortcode (e.g. 'US2', 'SG1'). Appended to deviceQuery as \"and @region='X'\". " +
|
|
211
|
+
'Use find_available_device first to identify a healthy region.'),
|
|
212
|
+
app: z
|
|
213
|
+
.string()
|
|
214
|
+
.optional()
|
|
215
|
+
.describe("Full app capability string. For cloud-hosted apps: 'cloud:com.example.app/.MainActivity'. " +
|
|
216
|
+
"Triggers install+launch. Omit to attach to an already-running app."),
|
|
217
|
+
appPackage: z
|
|
218
|
+
.string()
|
|
219
|
+
.optional()
|
|
220
|
+
.describe("Android package name, e.g. 'com.experitest.ExperiBank'. Required when app is provided."),
|
|
221
|
+
appActivity: z
|
|
222
|
+
.string()
|
|
223
|
+
.optional()
|
|
224
|
+
.describe("Launch activity, e.g. '.LoginActivity'. Required when app is provided."),
|
|
225
|
+
noReset: z
|
|
226
|
+
.boolean()
|
|
227
|
+
.optional()
|
|
228
|
+
.default(true)
|
|
229
|
+
.describe('If false, clears app data before launching. Default true.'),
|
|
230
|
+
testName: z
|
|
231
|
+
.string()
|
|
232
|
+
.optional()
|
|
233
|
+
.describe("Name shown in the Digital.ai reporter for this inspection session. Default: '[MCP Inspection]'."),
|
|
234
|
+
}, async (args) => {
|
|
235
|
+
try {
|
|
236
|
+
// Device pinning: resolve to the serial and use an exact @serialNumber query
|
|
237
|
+
// (confirmed live — routes to the requested device). Fail fast when the
|
|
238
|
+
// device is not Available instead of burning a 120 s allocation timeout.
|
|
239
|
+
let pinnedQuery;
|
|
240
|
+
if (args.device) {
|
|
241
|
+
let resolved = await resolveDevice(args.device);
|
|
242
|
+
if (!resolved.udid) {
|
|
243
|
+
// Numeric-ID passthrough skips the lookup — fetch the record for serial + status.
|
|
244
|
+
const match = (await getAllDevices()).find((d) => d.id === resolved.id);
|
|
245
|
+
if (!match) {
|
|
246
|
+
return {
|
|
247
|
+
content: [{ type: 'text', text: `Error: no device found with ID ${resolved.id}. Use list_devices to browse.` }],
|
|
248
|
+
isError: true,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
resolved = { ...resolved, udid: match.udid, deviceName: match.deviceName, displayStatus: match.displayStatus };
|
|
252
|
+
}
|
|
253
|
+
if (resolved.displayStatus.toLowerCase() !== 'available' && resolved.displayStatus !== 'unknown') {
|
|
254
|
+
return {
|
|
255
|
+
content: [{
|
|
256
|
+
type: 'text',
|
|
257
|
+
text: `Error: device ${resolved.deviceName} is "${resolved.displayStatus}", not Available — the session would time out waiting for it. Pick another device with find_available_device, or wait for it to free up.`,
|
|
258
|
+
}],
|
|
259
|
+
isError: true,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
pinnedQuery = `@serialNumber='${resolved.udid}'`;
|
|
263
|
+
}
|
|
264
|
+
const session = await createInspectionSession({
|
|
265
|
+
platform: args.platform ?? 'android',
|
|
266
|
+
deviceQuery: pinnedQuery ?? args.deviceQuery,
|
|
267
|
+
region: pinnedQuery ? undefined : args.region,
|
|
268
|
+
app: args.app,
|
|
269
|
+
appPackage: args.appPackage,
|
|
270
|
+
appActivity: args.appActivity,
|
|
271
|
+
noReset: args.noReset ?? true,
|
|
272
|
+
testName: args.testName,
|
|
273
|
+
});
|
|
274
|
+
// Resolve the numeric platform device ID from the UDID so the user-facing
|
|
275
|
+
// view URL can be emitted without a follow-up list_devices call.
|
|
276
|
+
// Note: the debug URL (/3) is intentionally NOT generated — the device is
|
|
277
|
+
// already reserved by this WebDriver session, and opening a second interactive
|
|
278
|
+
// connection causes a conflict error.
|
|
279
|
+
let deviceId = null;
|
|
280
|
+
let viewUrl = null;
|
|
281
|
+
if (session.deviceUDID) {
|
|
282
|
+
try {
|
|
283
|
+
const resolved = await resolveDevice(session.deviceUDID);
|
|
284
|
+
deviceId = resolved.id;
|
|
285
|
+
const base = getActiveUrl().replace(/\/+$/, '');
|
|
286
|
+
viewUrl = `${base}/#/open/device/${deviceId}/1`;
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Non-fatal — session is usable without the URL
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const structured = {
|
|
293
|
+
handle: session.handle,
|
|
294
|
+
platform: session.platform,
|
|
295
|
+
device: {
|
|
296
|
+
id: deviceId,
|
|
297
|
+
name: session.deviceName,
|
|
298
|
+
model: session.deviceModel,
|
|
299
|
+
os: session.deviceOs,
|
|
300
|
+
version: session.deviceVersion,
|
|
301
|
+
udid: session.deviceUDID,
|
|
302
|
+
},
|
|
303
|
+
appPackage: session.appPackage,
|
|
304
|
+
viewUrl,
|
|
305
|
+
cloudViewLink: session.cloudViewLink,
|
|
306
|
+
reportUrl: session.reportUrl,
|
|
307
|
+
idleTimeoutNote: 'Grid sessions expire after ~4 minutes without a command. Before pausing to ask the user something, ' +
|
|
308
|
+
'call take_inspection_screenshot — it resets the idle clock AND captures the state you are asking about. ' +
|
|
309
|
+
'If the user takes longer than ~4 minutes, expect a 404 on your next call: stop_inspection_session to clean up, ' +
|
|
310
|
+
'start a fresh session, and re-find elements (your noted selectors stay valid; raw elementIds do not survive sessions).',
|
|
311
|
+
shareWithUser: viewUrl
|
|
312
|
+
? `Share this URL with the user immediately so they can watch the session live (read-only): ${viewUrl}`
|
|
313
|
+
: null,
|
|
314
|
+
};
|
|
315
|
+
if (!session.canDeleteReport) {
|
|
316
|
+
structured.authWarning =
|
|
317
|
+
'Project-level key detected (Project Admin or Project User). The reporter delete endpoint (POST /reporter/api/tests/delete) ' +
|
|
318
|
+
'is CSRF-blocked for project-level keys — inspection session reports will NOT be automatically ' +
|
|
319
|
+
'deleted. Delete them manually from the Digital.ai reporter UI, or switch to a Cloud Admin ' +
|
|
320
|
+
'profile before using inspection sessions: switch_environment("default").';
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
content: [{ type: 'text', text: JSON.stringify(structured) }],
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
return {
|
|
328
|
+
content: [{ type: 'text', text: `Error starting inspection session: ${e.message}` }],
|
|
329
|
+
isError: true,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
// ── stop_inspection_session ───────────────────────────────────────────────
|
|
334
|
+
server.tool('stop_inspection_session', 'Stop a live inspection session and release the device. ' +
|
|
335
|
+
'By default deletes the test report created by this session from the Digital.ai reporter. ' +
|
|
336
|
+
'Pass keepReport: true to preserve it — the platform records video of every session, and the kept ' +
|
|
337
|
+
"report's video is retrievable via download_test_attachments (useful for documenting a verified flow). " +
|
|
338
|
+
'Always call this when done inspecting — open sessions hold a reserved device.\n\n' +
|
|
339
|
+
'STEP CONFIRMATION GATE — when building a test interactively, NEVER call this tool (and NEVER call ' +
|
|
340
|
+
'get_test_boilerplate) until the user explicitly confirms all test steps are captured. A single completed ' +
|
|
341
|
+
'scenario does NOT mean the test is done. After each scenario, surface what was captured and ask: ' +
|
|
342
|
+
'"I\'ve captured [description of step]. Want to add another step — for example a success path, a failure ' +
|
|
343
|
+
'path, navigation to another screen, or a different scenario — or are you ready to generate the script?" ' +
|
|
344
|
+
'WAIT for the answer before proceeding. Language like "let\'s start with...", "first...", or "begin by..." ' +
|
|
345
|
+
'is an explicit signal that more steps are planned — NEVER finalize after only the first step when these ' +
|
|
346
|
+
'phrases were used. Keep the session alive between steps: call take_inspection_screenshot periodically ' +
|
|
347
|
+
'if the user is thinking (resets the idle clock without moving to the next phase).', {
|
|
348
|
+
handle: z
|
|
349
|
+
.string()
|
|
350
|
+
.describe("Session handle returned by start_inspection_session, e.g. 'A1B2C3D4'."),
|
|
351
|
+
keepReport: z
|
|
352
|
+
.boolean()
|
|
353
|
+
.optional()
|
|
354
|
+
.default(false)
|
|
355
|
+
.describe('Preserve the session report (and its platform-recorded video) instead of deleting it. Default false.'),
|
|
356
|
+
}, async (args) => {
|
|
357
|
+
try {
|
|
358
|
+
const { reportDeleted, reportKept, canDeleteReport, reportTestId, reportUrl } = await quitInspectionSession(args.handle, args.keepReport ?? false);
|
|
359
|
+
let text;
|
|
360
|
+
if (reportKept) {
|
|
361
|
+
text =
|
|
362
|
+
`✅ Session ${args.handle} stopped. Device released. Report KEPT (test_id=${reportTestId}).\n` +
|
|
363
|
+
`Report: ${reportUrl}\n` +
|
|
364
|
+
`The platform-recorded session video is attached to this report — retrieve it with ` +
|
|
365
|
+
`download_test_attachments once processing completes (usually within a minute).`;
|
|
366
|
+
}
|
|
367
|
+
else if (reportDeleted) {
|
|
368
|
+
text = `✅ Session ${args.handle} stopped. Device released. Probe report deleted.`;
|
|
369
|
+
}
|
|
370
|
+
else if (!canDeleteReport && reportTestId > 0) {
|
|
371
|
+
text =
|
|
372
|
+
`✅ Session ${args.handle} stopped. Device released.\n\n` +
|
|
373
|
+
`⚠️ Report NOT deleted (test_id=${reportTestId}): the reporter delete endpoint is CSRF-blocked ` +
|
|
374
|
+
`for project-level keys (Project Admin and Project User). Delete it manually from the Digital.ai reporter UI, or switch to a ` +
|
|
375
|
+
`Cloud Admin profile before running inspection sessions: switch_environment("default").`;
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
text = `✅ Session ${args.handle} stopped. Device released.`;
|
|
379
|
+
}
|
|
380
|
+
text +=
|
|
381
|
+
'\n\n📌 If you have the View URL open in a browser, please close that tab now — ' +
|
|
382
|
+
'the device has been released but the browser session may still appear connected.';
|
|
383
|
+
return { content: [{ type: 'text', text }] };
|
|
384
|
+
}
|
|
385
|
+
catch (e) {
|
|
386
|
+
return {
|
|
387
|
+
content: [{ type: 'text', text: `Error stopping session: ${e.message}` }],
|
|
388
|
+
isError: true,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
// ── take_inspection_screenshot ────────────────────────────────────────────
|
|
393
|
+
server.tool('take_inspection_screenshot', 'Capture a screenshot from the device in the active inspection session. ' +
|
|
394
|
+
'Returns the image directly so you can see what is currently displayed on the device screen. ' +
|
|
395
|
+
'Use this after navigation or interactions to verify the UI state.', {
|
|
396
|
+
handle: z
|
|
397
|
+
.string()
|
|
398
|
+
.describe("Session handle from start_inspection_session."),
|
|
399
|
+
}, async (args) => {
|
|
400
|
+
try {
|
|
401
|
+
const { data, mimeType } = await captureScreenshot(args.handle);
|
|
402
|
+
return {
|
|
403
|
+
content: [
|
|
404
|
+
{ type: 'image', data, mimeType },
|
|
405
|
+
{ type: 'text', text: `Screenshot captured (session ${args.handle}, ${mimeType}).` },
|
|
406
|
+
],
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
catch (e) {
|
|
410
|
+
return {
|
|
411
|
+
content: [{ type: 'text', text: `Error capturing screenshot: ${e.message}` }],
|
|
412
|
+
isError: true,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
// ── get_element_tree ──────────────────────────────────────────────────────
|
|
417
|
+
server.tool('get_element_tree', 'Get the UI element hierarchy from the current screen. ' +
|
|
418
|
+
'Returns a formatted table of all elements that have locator attributes (resource-id, ' +
|
|
419
|
+
'content-desc, or visible text), plus the raw XML source for detailed inspection. ' +
|
|
420
|
+
'Use this to discover element IDs for use with find_elements, tap_element, and type_into_element.', {
|
|
421
|
+
handle: z
|
|
422
|
+
.string()
|
|
423
|
+
.describe("Session handle from start_inspection_session."),
|
|
424
|
+
includeRawXml: z
|
|
425
|
+
.boolean()
|
|
426
|
+
.optional()
|
|
427
|
+
.default(false)
|
|
428
|
+
.describe('Include the raw XML page source in the response. Default false (summary only).'),
|
|
429
|
+
}, async (args) => {
|
|
430
|
+
const mobileErr = requireMobileSession(args.handle, 'get_element_tree');
|
|
431
|
+
if (mobileErr)
|
|
432
|
+
return { ...mobileErr, content: [{ type: 'text', text: `"get_element_tree" is for mobile sessions only. For browser sessions use get_page_dom to inspect the rendered DOM.` }] };
|
|
433
|
+
try {
|
|
434
|
+
const platform = requireSession(args.handle).platform;
|
|
435
|
+
const xml = await getPageSource(args.handle);
|
|
436
|
+
const { elements, totalNodes } = parseElementTree(xml, platform);
|
|
437
|
+
const table = formatElementTable(elements, totalNodes, platform);
|
|
438
|
+
let text = table;
|
|
439
|
+
if (args.includeRawXml) {
|
|
440
|
+
const truncated = xml.length > 8000 ? xml.slice(0, 8000) + '\n... (truncated)' : xml;
|
|
441
|
+
text += `\n\nRaw XML:\n${truncated}`;
|
|
442
|
+
}
|
|
443
|
+
return { content: [{ type: 'text', text }] };
|
|
444
|
+
}
|
|
445
|
+
catch (e) {
|
|
446
|
+
return {
|
|
447
|
+
content: [{ type: 'text', text: `Error getting element tree: ${e.message}` }],
|
|
448
|
+
isError: true,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
// ── find_elements ─────────────────────────────────────────────────────────
|
|
453
|
+
server.tool('find_elements', 'Find elements on the current screen using a locator strategy and return their IDs and attributes. ' +
|
|
454
|
+
'The returned elementId values are used with tap_element, type_into_element, and clear_element. ' +
|
|
455
|
+
'Strategies: "xpath" (most flexible), "id" (resource-id, fastest), "accessibility id" (content-desc), ' +
|
|
456
|
+
'"class name" (by widget type, often returns many).', {
|
|
457
|
+
handle: z
|
|
458
|
+
.string()
|
|
459
|
+
.describe("Session handle from start_inspection_session."),
|
|
460
|
+
strategy: z
|
|
461
|
+
.enum(['xpath', 'id', 'accessibility id', 'class name'])
|
|
462
|
+
.describe("Locator strategy. 'id' matches resource-id (e.g. 'com.example:id/login'). " +
|
|
463
|
+
"'accessibility id' matches content-desc. " +
|
|
464
|
+
"'xpath' supports complex expressions like '//android.widget.EditText[@text=\"Username\"]'."),
|
|
465
|
+
selector: z
|
|
466
|
+
.string()
|
|
467
|
+
.describe("The locator value. Examples: 'com.example:id/login', '//android.widget.Button[@text=\"Submit\"]'."),
|
|
468
|
+
}, async (args) => {
|
|
469
|
+
try {
|
|
470
|
+
const elements = await findElements(args.handle, args.strategy, args.selector);
|
|
471
|
+
if (elements.length === 0) {
|
|
472
|
+
return {
|
|
473
|
+
content: [
|
|
474
|
+
{
|
|
475
|
+
type: 'text',
|
|
476
|
+
text: `No elements found matching ${args.strategy}: "${args.selector}"\n\nCheck the selector with get_element_tree to confirm available locators.`,
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
const lines = [
|
|
482
|
+
`Found ${elements.length} element${elements.length !== 1 ? 's' : ''} matching ${args.strategy}: "${args.selector}"\n`,
|
|
483
|
+
];
|
|
484
|
+
for (let i = 0; i < elements.length; i++) {
|
|
485
|
+
const e = elements[i];
|
|
486
|
+
lines.push(`Element ${i + 1}:`);
|
|
487
|
+
lines.push(` elementId: ${e.elementId}`);
|
|
488
|
+
if (e.className)
|
|
489
|
+
lines.push(` type: ${shortClass(e.className)}`);
|
|
490
|
+
if (e.resourceId)
|
|
491
|
+
lines.push(` resource-id: ${e.resourceId}`);
|
|
492
|
+
if (e.contentDesc)
|
|
493
|
+
lines.push(` content-desc: ${e.contentDesc}`);
|
|
494
|
+
if (e.name)
|
|
495
|
+
lines.push(` name: ${e.name}`);
|
|
496
|
+
if (e.label)
|
|
497
|
+
lines.push(` label: ${e.label}`);
|
|
498
|
+
if (e.value)
|
|
499
|
+
lines.push(` value: ${e.value}`);
|
|
500
|
+
if (e.text != null || (!e.name && !e.label))
|
|
501
|
+
lines.push(` text: ${e.text ?? '(empty)'}`);
|
|
502
|
+
if (e.bounds)
|
|
503
|
+
lines.push(` bounds: ${e.bounds}`);
|
|
504
|
+
lines.push(` clickable: ${e.clickable ?? 'unknown'}`);
|
|
505
|
+
lines.push(` enabled: ${e.enabled ?? 'unknown'}`);
|
|
506
|
+
lines.push('');
|
|
507
|
+
}
|
|
508
|
+
if (elements.length === 1) {
|
|
509
|
+
const e = elements[0];
|
|
510
|
+
lines.push(`To interact:\n` +
|
|
511
|
+
` tap_element(handle="${args.handle}", elementId="${e.elementId}")\n` +
|
|
512
|
+
` type_into_element(handle="${args.handle}", elementId="${e.elementId}", text="...")`);
|
|
513
|
+
}
|
|
514
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
515
|
+
}
|
|
516
|
+
catch (e) {
|
|
517
|
+
return {
|
|
518
|
+
content: [{ type: 'text', text: `Error finding elements: ${e.message}` }],
|
|
519
|
+
isError: true,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
// ── Resolve elementId-or-selector args shared by tap/type/clear ──────────
|
|
524
|
+
const resolveTargetElement = async (args) => {
|
|
525
|
+
if (args.elementId)
|
|
526
|
+
return { elementId: args.elementId };
|
|
527
|
+
if (args.strategy && args.selector) {
|
|
528
|
+
const found = await findFirstElementId(args.handle, args.strategy, args.selector);
|
|
529
|
+
if (!found) {
|
|
530
|
+
return { error: `No element found matching ${args.strategy}: "${args.selector}". Check the locator with get_element_tree.` };
|
|
531
|
+
}
|
|
532
|
+
return { elementId: found };
|
|
533
|
+
}
|
|
534
|
+
return { error: 'Provide either elementId (from find_elements) or strategy + selector to locate the element directly.' };
|
|
535
|
+
};
|
|
536
|
+
const targetParams = {
|
|
537
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
538
|
+
elementId: z
|
|
539
|
+
.string()
|
|
540
|
+
.optional()
|
|
541
|
+
.describe('Element ID from a previous find_elements call. Provide this OR strategy+selector.'),
|
|
542
|
+
strategy: z
|
|
543
|
+
.enum(['xpath', 'id', 'accessibility id', 'class name'])
|
|
544
|
+
.optional()
|
|
545
|
+
.describe('Locator strategy for direct one-call targeting (the find happens internally — no separate find_elements round trip needed).'),
|
|
546
|
+
selector: z
|
|
547
|
+
.string()
|
|
548
|
+
.optional()
|
|
549
|
+
.describe("Locator value for direct targeting, e.g. 'com.example:id/login' or '//XCUIElementTypeButton[@label=\"Sign In\"]'. First match is used."),
|
|
550
|
+
};
|
|
551
|
+
// ── tap_element ───────────────────────────────────────────────────────────
|
|
552
|
+
server.tool('tap_element', 'Tap (click) an element on the device screen. ' +
|
|
553
|
+
'Target it directly with strategy + selector (one call — the find happens internally), ' +
|
|
554
|
+
'or pass an elementId from a previous find_elements call. ' +
|
|
555
|
+
'After tapping, call take_inspection_screenshot to verify the result.', { ...targetParams }, async (args) => {
|
|
556
|
+
try {
|
|
557
|
+
const target = await resolveTargetElement(args);
|
|
558
|
+
if ('error' in target) {
|
|
559
|
+
return { content: [{ type: 'text', text: `Error: ${target.error}` }], isError: true };
|
|
560
|
+
}
|
|
561
|
+
await tapElement(args.handle, target.elementId);
|
|
562
|
+
const via = args.elementId ? `element ${args.elementId}` : `${args.strategy}: "${args.selector}"`;
|
|
563
|
+
return {
|
|
564
|
+
content: [
|
|
565
|
+
{
|
|
566
|
+
type: 'text',
|
|
567
|
+
text: `✅ Tapped ${via}.\n\nCall take_inspection_screenshot to verify the result.`,
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
catch (e) {
|
|
573
|
+
return {
|
|
574
|
+
content: [{ type: 'text', text: `Error tapping element: ${e.message}` }],
|
|
575
|
+
isError: true,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
// ── type_into_element ─────────────────────────────────────────────────────
|
|
580
|
+
server.tool('type_into_element', 'Type text into an input field on the device screen. ' +
|
|
581
|
+
'Target the field directly with strategy + selector (one call — the find happens internally), ' +
|
|
582
|
+
'or pass an elementId from a previous find_elements call. ' +
|
|
583
|
+
'For fields that need clearing first, call clear_element before typing.', {
|
|
584
|
+
...targetParams,
|
|
585
|
+
text: z
|
|
586
|
+
.string()
|
|
587
|
+
.describe("Text to type into the field."),
|
|
588
|
+
}, async (args) => {
|
|
589
|
+
try {
|
|
590
|
+
const target = await resolveTargetElement(args);
|
|
591
|
+
if ('error' in target) {
|
|
592
|
+
return { content: [{ type: 'text', text: `Error: ${target.error}` }], isError: true };
|
|
593
|
+
}
|
|
594
|
+
await typeIntoElement(args.handle, target.elementId, args.text);
|
|
595
|
+
const via = args.elementId ? `element ${args.elementId}` : `${args.strategy}: "${args.selector}"`;
|
|
596
|
+
return {
|
|
597
|
+
content: [
|
|
598
|
+
{
|
|
599
|
+
type: 'text',
|
|
600
|
+
text: `✅ Typed "${args.text}" into ${via}.`,
|
|
601
|
+
},
|
|
602
|
+
],
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
catch (e) {
|
|
606
|
+
return {
|
|
607
|
+
content: [{ type: 'text', text: `Error typing into element: ${e.message}` }],
|
|
608
|
+
isError: true,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
// ── clear_element ─────────────────────────────────────────────────────────
|
|
613
|
+
server.tool('clear_element', 'Clear the text content of an input field. Use before type_into_element when the field already has content. ' +
|
|
614
|
+
'Target it directly with strategy + selector, or pass an elementId from find_elements.', { ...targetParams }, async (args) => {
|
|
615
|
+
try {
|
|
616
|
+
const target = await resolveTargetElement(args);
|
|
617
|
+
if ('error' in target) {
|
|
618
|
+
return { content: [{ type: 'text', text: `Error: ${target.error}` }], isError: true };
|
|
619
|
+
}
|
|
620
|
+
await clearElement(args.handle, target.elementId);
|
|
621
|
+
const via = args.elementId ? `element ${args.elementId}` : `${args.strategy}: "${args.selector}"`;
|
|
622
|
+
return {
|
|
623
|
+
content: [{ type: 'text', text: `✅ Cleared ${via}.` }],
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
catch (e) {
|
|
627
|
+
return {
|
|
628
|
+
content: [{ type: 'text', text: `Error clearing element: ${e.message}` }],
|
|
629
|
+
isError: true,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
// ── swipe_screen ──────────────────────────────────────────────────────────
|
|
634
|
+
server.tool('swipe_screen', 'Swipe/scroll on the device screen. Use a named direction for common gestures ' +
|
|
635
|
+
'(scrolling lists, opening the app drawer, dismissing overlays), or explicit coordinates for precision. ' +
|
|
636
|
+
'Direction is the FINGER movement: "up" moves the finger up, which scrolls content DOWN/forward ' +
|
|
637
|
+
'(and opens the app drawer from the home screen). ' +
|
|
638
|
+
'Works on both Appium 1.x (JWP touch actions) and Appium 2/3 (W3C actions) agents automatically.', {
|
|
639
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
640
|
+
direction: z
|
|
641
|
+
.enum(['up', 'down', 'left', 'right'])
|
|
642
|
+
.optional()
|
|
643
|
+
.describe('Finger movement direction. Swipes from 80% to 20% of the screen along the axis, centered on the other axis. Provide this OR explicit coordinates.'),
|
|
644
|
+
startX: z.number().int().optional().describe('Explicit start X (pixels). All four coordinates required together.'),
|
|
645
|
+
startY: z.number().int().optional().describe('Explicit start Y (pixels).'),
|
|
646
|
+
endX: z.number().int().optional().describe('Explicit end X (pixels).'),
|
|
647
|
+
endY: z.number().int().optional().describe('Explicit end Y (pixels).'),
|
|
648
|
+
durationMs: z
|
|
649
|
+
.number()
|
|
650
|
+
.int()
|
|
651
|
+
.optional()
|
|
652
|
+
.default(300)
|
|
653
|
+
.describe('Gesture duration in ms. 300 = normal swipe, 100 = fast fling, 600+ = slow drag. Default 300.'),
|
|
654
|
+
}, async (args) => {
|
|
655
|
+
try {
|
|
656
|
+
let { startX, startY, endX, endY } = args;
|
|
657
|
+
const hasCoords = [startX, startY, endX, endY].every((v) => v != null);
|
|
658
|
+
if (!args.direction && !hasCoords) {
|
|
659
|
+
return {
|
|
660
|
+
content: [{ type: 'text', text: 'Error: provide either direction or all four of startX/startY/endX/endY.' }],
|
|
661
|
+
isError: true,
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
if (args.direction && !hasCoords) {
|
|
665
|
+
const { width, height } = await getWindowSize(args.handle);
|
|
666
|
+
const midX = Math.round(width / 2);
|
|
667
|
+
const midY = Math.round(height / 2);
|
|
668
|
+
switch (args.direction) {
|
|
669
|
+
case 'up':
|
|
670
|
+
startX = midX;
|
|
671
|
+
endX = midX;
|
|
672
|
+
startY = Math.round(height * 0.8);
|
|
673
|
+
endY = Math.round(height * 0.2);
|
|
674
|
+
break;
|
|
675
|
+
case 'down':
|
|
676
|
+
startX = midX;
|
|
677
|
+
endX = midX;
|
|
678
|
+
startY = Math.round(height * 0.2);
|
|
679
|
+
endY = Math.round(height * 0.8);
|
|
680
|
+
break;
|
|
681
|
+
case 'left':
|
|
682
|
+
startY = midY;
|
|
683
|
+
endY = midY;
|
|
684
|
+
startX = Math.round(width * 0.8);
|
|
685
|
+
endX = Math.round(width * 0.2);
|
|
686
|
+
break;
|
|
687
|
+
case 'right':
|
|
688
|
+
startY = midY;
|
|
689
|
+
endY = midY;
|
|
690
|
+
startX = Math.round(width * 0.2);
|
|
691
|
+
endX = Math.round(width * 0.8);
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const mechanism = await swipeScreen(args.handle, startX, startY, endX, endY, args.durationMs ?? 300);
|
|
696
|
+
return {
|
|
697
|
+
content: [{
|
|
698
|
+
type: 'text',
|
|
699
|
+
text: `✅ Swiped ${args.direction ?? ''} (${startX},${startY}) → (${endX},${endY}) over ${args.durationMs ?? 300}ms [${mechanism}].\n\n` +
|
|
700
|
+
`Call take_inspection_screenshot to verify the result.`,
|
|
701
|
+
}],
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
catch (e) {
|
|
705
|
+
return {
|
|
706
|
+
content: [{ type: 'text', text: `Error swiping: ${e.message}` }],
|
|
707
|
+
isError: true,
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
// ── launch_app ────────────────────────────────────────────────────────────
|
|
712
|
+
server.tool('launch_app', 'Launch an installed app on the device in an inspection session — the equivalent of tapping its icon. ' +
|
|
713
|
+
'Android: ALWAYS pass the activity (get mainActivity from get_application_info(appId); guessing ".MainActivity" often fails, ' +
|
|
714
|
+
'and Grid sessions cannot launch by package name alone). ' +
|
|
715
|
+
'iOS: pass the bundleIdentifier as packageName — no activity exists or is needed. ' +
|
|
716
|
+
'Use this instead of navigating to the app via home screen / app drawer / search.', {
|
|
717
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
718
|
+
packageName: z.string().describe("Android package name (e.g. 'com.digitalai.sampleapp') or iOS bundle identifier (e.g. 'com.digitalai.sample')."),
|
|
719
|
+
activity: z
|
|
720
|
+
.string()
|
|
721
|
+
.optional()
|
|
722
|
+
.describe("Android launch activity, e.g. '.LoginActivity' — from get_application_info mainActivity; effectively required on Android Grid sessions. Ignored on iOS."),
|
|
723
|
+
}, async (args) => {
|
|
724
|
+
const mobileErr = requireMobileSession(args.handle, 'launch_app');
|
|
725
|
+
if (mobileErr)
|
|
726
|
+
return mobileErr;
|
|
727
|
+
try {
|
|
728
|
+
const result = await launchApp(args.handle, args.packageName, args.activity);
|
|
729
|
+
return {
|
|
730
|
+
content: [{
|
|
731
|
+
type: 'text',
|
|
732
|
+
text: `✅ ${result}.\n\nCall take_inspection_screenshot to verify the app is in the foreground.`,
|
|
733
|
+
}],
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
catch (e) {
|
|
737
|
+
return {
|
|
738
|
+
content: [{
|
|
739
|
+
type: 'text',
|
|
740
|
+
text: `Error launching app: ${e.message}\n\n` +
|
|
741
|
+
`If the app is not installed, install it first (install_application requires the device to be ` +
|
|
742
|
+
`unreserved — stop this session, install, then start a new session). ` +
|
|
743
|
+
`If the activity is wrong, get the correct one from get_application_info(appId).`,
|
|
744
|
+
}],
|
|
745
|
+
isError: true,
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
// ── press_back ────────────────────────────────────────────────────────────
|
|
750
|
+
server.tool('press_back', 'Navigate back one screen. Android: presses the Back button (also dismisses keyboards and dialogs). ' +
|
|
751
|
+
'iOS: performs the left-edge back swipe (the platform convention — iOS has no Back button).', {
|
|
752
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
753
|
+
}, async (args) => {
|
|
754
|
+
const mobileErr = requireMobileSession(args.handle, 'press_back');
|
|
755
|
+
if (mobileErr)
|
|
756
|
+
return mobileErr;
|
|
757
|
+
try {
|
|
758
|
+
const result = await pressBack(args.handle);
|
|
759
|
+
return {
|
|
760
|
+
content: [{
|
|
761
|
+
type: 'text',
|
|
762
|
+
text: `✅ ${result}.\n\nCall take_inspection_screenshot to verify the result.`,
|
|
763
|
+
}],
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
catch (e) {
|
|
767
|
+
return {
|
|
768
|
+
content: [{ type: 'text', text: `Error pressing back: ${e.message}` }],
|
|
769
|
+
isError: true,
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
// ── long_press ────────────────────────────────────────────────────────────
|
|
774
|
+
server.tool('long_press', 'Long-press an element or screen coordinate — opens context menus, triggers press-and-hold actions. ' +
|
|
775
|
+
'Provide elementId (from find_elements) or explicit x/y coordinates.', {
|
|
776
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
777
|
+
elementId: z.string().optional().describe('Element ID from find_elements. Provide this OR x/y.'),
|
|
778
|
+
x: z.number().int().optional().describe('X coordinate (pixels).'),
|
|
779
|
+
y: z.number().int().optional().describe('Y coordinate (pixels).'),
|
|
780
|
+
durationMs: z.number().int().optional().default(1500).describe('Hold duration in ms. Default 1500.'),
|
|
781
|
+
}, async (args) => {
|
|
782
|
+
try {
|
|
783
|
+
await longPress(args.handle, { elementId: args.elementId, x: args.x, y: args.y }, args.durationMs ?? 1500);
|
|
784
|
+
return {
|
|
785
|
+
content: [{ type: 'text', text: `✅ Long-pressed for ${args.durationMs ?? 1500}ms.\n\nCall take_inspection_screenshot to verify the result.` }],
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
catch (e) {
|
|
789
|
+
return { content: [{ type: 'text', text: `Error long-pressing: ${e.message}` }], isError: true };
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
// ── double_tap ────────────────────────────────────────────────────────────
|
|
793
|
+
server.tool('double_tap', 'Double-tap an element or screen coordinate — zoom into images/maps, trigger double-tap actions. ' +
|
|
794
|
+
'Provide elementId (from find_elements) or explicit x/y coordinates.', {
|
|
795
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
796
|
+
elementId: z.string().optional().describe('Element ID from find_elements. Provide this OR x/y.'),
|
|
797
|
+
x: z.number().int().optional().describe('X coordinate (pixels).'),
|
|
798
|
+
y: z.number().int().optional().describe('Y coordinate (pixels).'),
|
|
799
|
+
}, async (args) => {
|
|
800
|
+
try {
|
|
801
|
+
await doubleTap(args.handle, { elementId: args.elementId, x: args.x, y: args.y });
|
|
802
|
+
return {
|
|
803
|
+
content: [{ type: 'text', text: `✅ Double-tapped.\n\nCall take_inspection_screenshot to verify the result.` }],
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
catch (e) {
|
|
807
|
+
return { content: [{ type: 'text', text: `Error double-tapping: ${e.message}` }], isError: true };
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
// ── drag_and_drop ─────────────────────────────────────────────────────────
|
|
811
|
+
server.tool('drag_and_drop', 'Press and hold at a start point, drag to an end point, and release — reorder lists, move sliders, drag items between containers. ' +
|
|
812
|
+
'Use find_elements bounds to compute coordinates.', {
|
|
813
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
814
|
+
startX: z.number().int().describe('Drag start X (pixels).'),
|
|
815
|
+
startY: z.number().int().describe('Drag start Y (pixels).'),
|
|
816
|
+
endX: z.number().int().describe('Drop X (pixels).'),
|
|
817
|
+
endY: z.number().int().describe('Drop Y (pixels).'),
|
|
818
|
+
holdMs: z.number().int().optional().default(600).describe('Initial hold before moving (ms). Default 600.'),
|
|
819
|
+
moveMs: z.number().int().optional().default(1200).describe('Movement duration (ms). Default 1200.'),
|
|
820
|
+
}, async (args) => {
|
|
821
|
+
try {
|
|
822
|
+
await dragAndDrop(args.handle, args.startX, args.startY, args.endX, args.endY, args.holdMs ?? 600, args.moveMs ?? 1200);
|
|
823
|
+
return {
|
|
824
|
+
content: [{ type: 'text', text: `✅ Dragged (${args.startX},${args.startY}) → (${args.endX},${args.endY}).\n\nCall take_inspection_screenshot to verify the result.` }],
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
catch (e) {
|
|
828
|
+
return { content: [{ type: 'text', text: `Error dragging: ${e.message}` }], isError: true };
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
// ── pinch_zoom ────────────────────────────────────────────────────────────
|
|
832
|
+
server.tool('pinch_zoom', 'Two-finger pinch gesture — zoom in (fingers diverge) or out (fingers converge) on maps and images. ' +
|
|
833
|
+
'Defaults to the screen center. NOTE: Appium Server (OSS) project sessions only — the Appium Grid rejects multi-touch.', {
|
|
834
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
835
|
+
direction: z.enum(['in', 'out']).describe("'in' = zoom in (fingers spread apart), 'out' = zoom out (fingers converge)."),
|
|
836
|
+
centerX: z.number().int().optional().describe('Gesture center X. Default: screen center.'),
|
|
837
|
+
centerY: z.number().int().optional().describe('Gesture center Y. Default: screen center.'),
|
|
838
|
+
distance: z.number().int().optional().default(300).describe('Distance each finger travels (pixels). Default 300.'),
|
|
839
|
+
}, async (args) => {
|
|
840
|
+
const mobileErr = requireMobileSession(args.handle, 'pinch_zoom');
|
|
841
|
+
if (mobileErr)
|
|
842
|
+
return mobileErr;
|
|
843
|
+
try {
|
|
844
|
+
await pinchZoom(args.handle, args.direction, args.centerX, args.centerY, args.distance ?? 300);
|
|
845
|
+
return {
|
|
846
|
+
content: [{ type: 'text', text: `✅ Pinch-zoomed ${args.direction}.\n\nCall take_inspection_screenshot to verify the result.` }],
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
catch (e) {
|
|
850
|
+
return { content: [{ type: 'text', text: `Error pinch-zooming: ${e.message}` }], isError: true };
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
// ── scroll_to_element ─────────────────────────────────────────────────────
|
|
854
|
+
server.tool('scroll_to_element', 'Scroll until an element becomes visible, swiping repeatedly and stopping when found or when the end of the ' +
|
|
855
|
+
'scrollable content is reached (screen stops changing). Returns the element ID ready for tap/type. ' +
|
|
856
|
+
'Much faster than manual swipe + screenshot loops for finding content below the fold.', {
|
|
857
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
858
|
+
strategy: z
|
|
859
|
+
.enum(['xpath', 'id', 'accessibility id', 'class name'])
|
|
860
|
+
.describe('Locator strategy (same as find_elements).'),
|
|
861
|
+
selector: z.string().describe('The locator value to search for while scrolling.'),
|
|
862
|
+
direction: z
|
|
863
|
+
.enum(['up', 'down'])
|
|
864
|
+
.optional()
|
|
865
|
+
.default('up')
|
|
866
|
+
.describe("Finger movement per swipe. 'up' (default) scrolls content forward/down; 'down' scrolls back toward the top."),
|
|
867
|
+
maxSwipes: z.number().int().optional().default(8).describe('Maximum swipes before giving up. Default 8.'),
|
|
868
|
+
}, async (args) => {
|
|
869
|
+
try {
|
|
870
|
+
const result = await scrollToElement(args.handle, args.strategy, args.selector, args.direction ?? 'up', args.maxSwipes ?? 8);
|
|
871
|
+
if (result.found && result.element) {
|
|
872
|
+
const e = result.element;
|
|
873
|
+
const lines = [
|
|
874
|
+
`✅ Found after ${result.swipesUsed} swipe${result.swipesUsed !== 1 ? 's' : ''}:`,
|
|
875
|
+
` elementId: ${e.elementId}`,
|
|
876
|
+
e.resourceId ? ` resource-id: ${e.resourceId}` : '',
|
|
877
|
+
e.text ? ` text: ${e.text}` : '',
|
|
878
|
+
e.bounds ? ` bounds: ${e.bounds}` : '',
|
|
879
|
+
'',
|
|
880
|
+
`To interact: tap_element(handle="${args.handle}", elementId="${e.elementId}")`,
|
|
881
|
+
].filter(Boolean);
|
|
882
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
883
|
+
}
|
|
884
|
+
const reason = result.reachedEnd
|
|
885
|
+
? `reached the end of the scrollable content after ${result.swipesUsed} swipes`
|
|
886
|
+
: `gave up after ${result.swipesUsed} swipes (maxSwipes)`;
|
|
887
|
+
return {
|
|
888
|
+
content: [{ type: 'text', text: `Element not found — ${reason}.\n\nVerify the selector with get_element_tree, or try direction="${(args.direction ?? 'up') === 'up' ? 'down' : 'up'}".` }],
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
catch (e) {
|
|
892
|
+
return { content: [{ type: 'text', text: `Error scrolling to element: ${e.message}` }], isError: true };
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
// ── press_key ─────────────────────────────────────────────────────────────
|
|
896
|
+
server.tool('press_key', 'Press a device key. Android: ENTER to submit forms/search, HOME, APP_SWITCH, volume, or any raw keycode. ' +
|
|
897
|
+
'iOS: HOME, VOLUME_UP, VOLUME_DOWN, POWER (physical buttons only — for ENTER type "\\n" via type_into_element). ' +
|
|
898
|
+
'Complements press_back (which has its own tool).', {
|
|
899
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
900
|
+
key: z
|
|
901
|
+
.enum(['HOME', 'BACK', 'ENTER', 'TAB', 'DELETE', 'APP_SWITCH', 'SEARCH', 'MENU', 'VOLUME_UP', 'VOLUME_DOWN', 'POWER'])
|
|
902
|
+
.optional()
|
|
903
|
+
.describe('Named key. Provide this OR keycode. iOS supports HOME, VOLUME_UP, VOLUME_DOWN, POWER.'),
|
|
904
|
+
keycode: z.number().int().optional().describe('Raw Android keycode (e.g. 66 = ENTER). Android only. Provide this OR key.'),
|
|
905
|
+
}, async (args) => {
|
|
906
|
+
const mobileErr = requireMobileSession(args.handle, 'press_key');
|
|
907
|
+
if (mobileErr)
|
|
908
|
+
return mobileErr;
|
|
909
|
+
try {
|
|
910
|
+
if (!args.key && args.keycode == null) {
|
|
911
|
+
return { content: [{ type: 'text', text: 'Error: provide either key (named) or keycode (number).' }], isError: true };
|
|
912
|
+
}
|
|
913
|
+
const pressed = await pressKey(args.handle, args.key, args.keycode);
|
|
914
|
+
return {
|
|
915
|
+
content: [{ type: 'text', text: `✅ Pressed ${pressed}.\n\nCall take_inspection_screenshot to verify the result.` }],
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
catch (e) {
|
|
919
|
+
return { content: [{ type: 'text', text: `Error pressing key: ${e.message}` }], isError: true };
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
// ── hide_keyboard ─────────────────────────────────────────────────────────
|
|
923
|
+
server.tool('hide_keyboard', 'Hide the on-screen keyboard if it is open. Safer than press_back (which navigates when no keyboard is shown). ' +
|
|
924
|
+
'Use when the keyboard covers an element you need to tap.', {
|
|
925
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
926
|
+
}, async (args) => {
|
|
927
|
+
const mobileErr = requireMobileSession(args.handle, 'hide_keyboard');
|
|
928
|
+
if (mobileErr)
|
|
929
|
+
return mobileErr;
|
|
930
|
+
try {
|
|
931
|
+
const shown = await isKeyboardShown(args.handle);
|
|
932
|
+
if (!shown) {
|
|
933
|
+
return { content: [{ type: 'text', text: 'Keyboard is not shown — nothing to hide.' }] };
|
|
934
|
+
}
|
|
935
|
+
await hideKeyboard(args.handle);
|
|
936
|
+
return { content: [{ type: 'text', text: '✅ Keyboard hidden.' }] };
|
|
937
|
+
}
|
|
938
|
+
catch (e) {
|
|
939
|
+
return { content: [{ type: 'text', text: `Error hiding keyboard: ${e.message}` }], isError: true };
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
// ── app_control ───────────────────────────────────────────────────────────
|
|
943
|
+
server.tool('app_control', 'Control app lifecycle in an inspection session: terminate (force-stop), clear_data (reset to first-launch state — Android only; ' +
|
|
944
|
+
'iOS requires uninstall/reinstall), query_state (installed/background/foreground), ' +
|
|
945
|
+
'deep_link (open a URL/URI directly — skip navigation to the screen under test). ' +
|
|
946
|
+
'NOTE on Grid sessions: query_state reports only the foreground activity (Android) or is unavailable (iOS); deep_link is best-effort. ' +
|
|
947
|
+
'To relaunch after terminate, use launch_app.', {
|
|
948
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
949
|
+
action: z
|
|
950
|
+
.enum(['terminate', 'clear_data', 'query_state', 'deep_link'])
|
|
951
|
+
.describe('Lifecycle action to perform.'),
|
|
952
|
+
packageName: z
|
|
953
|
+
.string()
|
|
954
|
+
.optional()
|
|
955
|
+
.describe('Android package name or iOS bundle identifier. Required for terminate, clear_data, query_state; optional Android handler hint for deep_link.'),
|
|
956
|
+
url: z.string().optional().describe('URL or URI scheme for deep_link, e.g. "myapp://orders/42" or "https://...".'),
|
|
957
|
+
}, async (args) => {
|
|
958
|
+
const mobileErr = requireMobileSession(args.handle, 'app_control');
|
|
959
|
+
if (mobileErr)
|
|
960
|
+
return mobileErr;
|
|
961
|
+
try {
|
|
962
|
+
const result = await appControl(args.handle, args.action, args.packageName, args.url);
|
|
963
|
+
return { content: [{ type: 'text', text: `✅ ${result}` }] };
|
|
964
|
+
}
|
|
965
|
+
catch (e) {
|
|
966
|
+
return { content: [{ type: 'text', text: `Error (${args.action}): ${e.message}` }], isError: true };
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
// ── device_control ────────────────────────────────────────────────────────
|
|
970
|
+
server.tool('device_control', 'Device-level controls for an inspection session: orientation (get/set — rotation testing), clipboard (get/set — paste flows), ' +
|
|
971
|
+
'geolocation (set/reset — location-based features), alerts (accept/dismiss — system dialogs, Appium Server only), ' +
|
|
972
|
+
'and file transfer (push_file/pull_file — test fixtures like images for upload flows). ' +
|
|
973
|
+
'Grid session limits: alerts and reset_geolocation are not supported, and iOS Grid devices reject clipboard ops ' +
|
|
974
|
+
'(clear errors explain alternatives). iOS file paths may require the @bundleId:container syntax.', {
|
|
975
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
976
|
+
action: z
|
|
977
|
+
.enum(['get_orientation', 'set_orientation', 'get_clipboard', 'set_clipboard', 'set_geolocation', 'reset_geolocation', 'accept_alert', 'dismiss_alert', 'push_file', 'pull_file'])
|
|
978
|
+
.describe('Device action to perform.'),
|
|
979
|
+
orientation: z.enum(['PORTRAIT', 'LANDSCAPE']).optional().describe('For set_orientation.'),
|
|
980
|
+
text: z.string().optional().describe('For set_clipboard: the text to place on the clipboard.'),
|
|
981
|
+
latitude: z.number().optional().describe('For set_geolocation.'),
|
|
982
|
+
longitude: z.number().optional().describe('For set_geolocation.'),
|
|
983
|
+
remotePath: z.string().optional().describe('For push_file/pull_file: absolute device path, e.g. "/sdcard/Download/fixture.png".'),
|
|
984
|
+
localPath: z.string().optional().describe('For push_file (source) / pull_file (destination): absolute path on the MCP SERVER\'s own filesystem, NOT your local machine. If the server runs in Docker/remote, push_file needs the file already present there (volume-mount), and pull_file writes to a location your local bash/file tools cannot see.'),
|
|
985
|
+
}, async (args) => {
|
|
986
|
+
const mobileErr = requireMobileSession(args.handle, 'device_control');
|
|
987
|
+
if (mobileErr)
|
|
988
|
+
return mobileErr;
|
|
989
|
+
try {
|
|
990
|
+
switch (args.action) {
|
|
991
|
+
case 'get_orientation': {
|
|
992
|
+
const o = await getOrientation(args.handle);
|
|
993
|
+
return { content: [{ type: 'text', text: `Orientation: ${o}` }] };
|
|
994
|
+
}
|
|
995
|
+
case 'set_orientation': {
|
|
996
|
+
if (!args.orientation)
|
|
997
|
+
return { content: [{ type: 'text', text: 'Error: set_orientation requires orientation.' }], isError: true };
|
|
998
|
+
await setOrientation(args.handle, args.orientation);
|
|
999
|
+
return { content: [{ type: 'text', text: `✅ Orientation set to ${args.orientation}.\n\nCall take_inspection_screenshot to verify the layout.` }] };
|
|
1000
|
+
}
|
|
1001
|
+
case 'get_clipboard': {
|
|
1002
|
+
const text = await getClipboard(args.handle);
|
|
1003
|
+
return { content: [{ type: 'text', text: text ? `Clipboard: "${text}"` : 'Clipboard is empty.' }] };
|
|
1004
|
+
}
|
|
1005
|
+
case 'set_clipboard': {
|
|
1006
|
+
if (args.text == null)
|
|
1007
|
+
return { content: [{ type: 'text', text: 'Error: set_clipboard requires text.' }], isError: true };
|
|
1008
|
+
await setClipboard(args.handle, args.text);
|
|
1009
|
+
return { content: [{ type: 'text', text: `✅ Clipboard set (${args.text.length} chars). Long-press an input field to paste.` }] };
|
|
1010
|
+
}
|
|
1011
|
+
case 'set_geolocation': {
|
|
1012
|
+
if (args.latitude == null || args.longitude == null) {
|
|
1013
|
+
return { content: [{ type: 'text', text: 'Error: set_geolocation requires latitude and longitude.' }], isError: true };
|
|
1014
|
+
}
|
|
1015
|
+
await setGeolocation(args.handle, args.latitude, args.longitude);
|
|
1016
|
+
return { content: [{ type: 'text', text: `✅ Location set to ${args.latitude}, ${args.longitude}.` }] };
|
|
1017
|
+
}
|
|
1018
|
+
case 'reset_geolocation': {
|
|
1019
|
+
await resetGeolocation(args.handle);
|
|
1020
|
+
return { content: [{ type: 'text', text: '✅ Simulated location cleared — device uses its real location again.' }] };
|
|
1021
|
+
}
|
|
1022
|
+
case 'accept_alert':
|
|
1023
|
+
case 'dismiss_alert': {
|
|
1024
|
+
await handleAlert(args.handle, args.action === 'accept_alert' ? 'accept' : 'dismiss');
|
|
1025
|
+
return { content: [{ type: 'text', text: `✅ Alert ${args.action === 'accept_alert' ? 'accepted' : 'dismissed'}.` }] };
|
|
1026
|
+
}
|
|
1027
|
+
case 'push_file': {
|
|
1028
|
+
if (!args.remotePath || !args.localPath) {
|
|
1029
|
+
return { content: [{ type: 'text', text: 'Error: push_file requires remotePath and localPath.' }], isError: true };
|
|
1030
|
+
}
|
|
1031
|
+
const inputError = validateInputPath(args.localPath);
|
|
1032
|
+
if (inputError)
|
|
1033
|
+
return { content: [{ type: 'text', text: inputError }], isError: true };
|
|
1034
|
+
const data = readFileSync(args.localPath).toString('base64');
|
|
1035
|
+
await pushFileToDevice(args.handle, args.remotePath, data);
|
|
1036
|
+
return { content: [{ type: 'text', text: `✅ Pushed ${args.localPath} → ${args.remotePath} (${Math.round(data.length * 0.75)} bytes).` }] };
|
|
1037
|
+
}
|
|
1038
|
+
case 'pull_file': {
|
|
1039
|
+
if (!args.remotePath || !args.localPath) {
|
|
1040
|
+
return { content: [{ type: 'text', text: 'Error: pull_file requires remotePath and localPath.' }], isError: true };
|
|
1041
|
+
}
|
|
1042
|
+
const outputError = validateOutputPath(args.localPath);
|
|
1043
|
+
if (outputError)
|
|
1044
|
+
return { content: [{ type: 'text', text: outputError }], isError: true };
|
|
1045
|
+
const b64 = await pullFileFromDevice(args.handle, args.remotePath);
|
|
1046
|
+
const buf = Buffer.from(b64, 'base64');
|
|
1047
|
+
writeFileSync(args.localPath, buf);
|
|
1048
|
+
return { content: [{ type: 'text', text: `✅ Pulled ${args.remotePath} → ${args.localPath} (${buf.length} bytes).` }] };
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
catch (e) {
|
|
1053
|
+
return { content: [{ type: 'text', text: `Error (${args.action}): ${e.message}` }], isError: true };
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
// ── list_inspection_sessions ──────────────────────────────────────────────
|
|
1057
|
+
server.tool('list_inspection_sessions', 'List all active inspection sessions in the current MCP server process. ' +
|
|
1058
|
+
'Use this to find session handles when continuing after a previous interaction, ' +
|
|
1059
|
+
'or to identify sessions that should be stopped.', {}, async () => {
|
|
1060
|
+
const sessions = listActiveSessions();
|
|
1061
|
+
if (sessions.length === 0) {
|
|
1062
|
+
return {
|
|
1063
|
+
content: [
|
|
1064
|
+
{
|
|
1065
|
+
type: 'text',
|
|
1066
|
+
text: 'No active inspection sessions. Use start_inspection_session to begin.',
|
|
1067
|
+
},
|
|
1068
|
+
],
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
const lines = [`${sessions.length} active inspection session${sessions.length !== 1 ? 's' : ''}:\n`];
|
|
1072
|
+
for (const s of sessions) {
|
|
1073
|
+
lines.push(sessionSummary(s));
|
|
1074
|
+
}
|
|
1075
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
1076
|
+
});
|
|
1077
|
+
// ── cleanup_inspection_sessions ───────────────────────────────────────────
|
|
1078
|
+
server.tool('cleanup_inspection_sessions', 'Delete all test reports created by inspection sessions during this MCP server process. ' +
|
|
1079
|
+
'Includes reports from sessions that were stopped without a clean shutdown. ' +
|
|
1080
|
+
'stop_inspection_session deletes its own report automatically; this tool handles orphans. ' +
|
|
1081
|
+
'Requires confirmDeletion: true.', {
|
|
1082
|
+
confirmDeletion: z
|
|
1083
|
+
.boolean()
|
|
1084
|
+
.optional()
|
|
1085
|
+
.describe('Must be true to proceed. Safety guard prevents accidental deletion.'),
|
|
1086
|
+
}, async (args) => {
|
|
1087
|
+
const pending = getPendingReportIds();
|
|
1088
|
+
if (pending.length === 0) {
|
|
1089
|
+
return {
|
|
1090
|
+
content: [
|
|
1091
|
+
{
|
|
1092
|
+
type: 'text',
|
|
1093
|
+
text: 'No tracked inspection reports to clean up.',
|
|
1094
|
+
},
|
|
1095
|
+
],
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
if (getActiveKeyType() !== 'jwt') {
|
|
1099
|
+
return {
|
|
1100
|
+
content: [{
|
|
1101
|
+
type: 'text',
|
|
1102
|
+
text: `Error: Cloud Admin access required. The reporter delete endpoint is CSRF-blocked for project-level keys (Project Admin and Project User). ` +
|
|
1103
|
+
`The ${pending.length} tracked report ID(s) are preserved — use switch_environment() to switch to a ` +
|
|
1104
|
+
`Cloud Admin profile, then re-run cleanup_inspection_sessions.`,
|
|
1105
|
+
}],
|
|
1106
|
+
isError: true,
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
const guard = checkDestructiveGuard(args.confirmDeletion, `Delete ${pending.length} inspection session report${pending.length !== 1 ? 's' : ''} (IDs: ${pending.join(', ')})`);
|
|
1110
|
+
if (guard)
|
|
1111
|
+
return { content: [{ type: 'text', text: guard }] };
|
|
1112
|
+
try {
|
|
1113
|
+
const { deleted, failed } = await deleteAllTrackedReports();
|
|
1114
|
+
const failNote = failed.length > 0
|
|
1115
|
+
? ` ⚠️ ${failed.length} could not be deleted and remain tracked (IDs: ${failed.join(', ')}) — run cleanup again to retry.`
|
|
1116
|
+
: '';
|
|
1117
|
+
return {
|
|
1118
|
+
content: [
|
|
1119
|
+
{
|
|
1120
|
+
type: 'text',
|
|
1121
|
+
text: `✅ Deleted ${deleted.length} inspection report${deleted.length !== 1 ? 's' : ''} (IDs: ${deleted.join(', ')}).${failNote}`,
|
|
1122
|
+
},
|
|
1123
|
+
],
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
catch (e) {
|
|
1127
|
+
return {
|
|
1128
|
+
content: [{ type: 'text', text: `Error during cleanup: ${e.message}` }],
|
|
1129
|
+
isError: true,
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
// ── mock_authentication ────────────────────────────────────────────────────
|
|
1134
|
+
server.tool('mock_authentication', 'Pre-stage a mock biometric authentication response (Touch ID, Face ID, or fingerprint) ' +
|
|
1135
|
+
'for the next auth dialog in an instrumented app. ' +
|
|
1136
|
+
'Call this BEFORE the action that triggers the biometric prompt — the platform intercepts ' +
|
|
1137
|
+
'the LocalAuthentication / BiometricPrompt request and answers it automatically without user interaction. ' +
|
|
1138
|
+
'REQUIRES an instrumented app (uploaded with instrument=true, or manually instrumented for iOS). ' +
|
|
1139
|
+
'Does NOT work for system apps (App Store, Play Store) or third-party auth libraries. ' +
|
|
1140
|
+
'Use reply "clear" to remove the mock after the test so subsequent auth dialogs behave normally.', {
|
|
1141
|
+
handle: z.string().describe('Session handle from start_inspection_session.'),
|
|
1142
|
+
reply: z
|
|
1143
|
+
.enum(['success', 'failed', 'cancel', 'clear'])
|
|
1144
|
+
.describe('success — auth passes silently (fingerprint/face recognised). ' +
|
|
1145
|
+
'failed — auth fails (wrong fingerprint / face not recognised). ' +
|
|
1146
|
+
'cancel — user cancels the biometric dialog. ' +
|
|
1147
|
+
'clear — remove mock; subsequent dialogs behave normally.'),
|
|
1148
|
+
delay: z
|
|
1149
|
+
.number()
|
|
1150
|
+
.int()
|
|
1151
|
+
.min(0)
|
|
1152
|
+
.optional()
|
|
1153
|
+
.describe('Milliseconds to wait after the auth dialog appears before responding. Default 0.'),
|
|
1154
|
+
}, async (args) => {
|
|
1155
|
+
const mobileErr = requireMobileSession(args.handle, 'mock_authentication');
|
|
1156
|
+
if (mobileErr)
|
|
1157
|
+
return mobileErr;
|
|
1158
|
+
try {
|
|
1159
|
+
const result = await mockAuthentication(args.handle, args.reply, args.delay ?? 0);
|
|
1160
|
+
return { content: [{ type: 'text', text: `✅ ${result}` }] };
|
|
1161
|
+
}
|
|
1162
|
+
catch (e) {
|
|
1163
|
+
return {
|
|
1164
|
+
content: [{ type: 'text', text: `Error (mock_authentication): ${e.message}` }],
|
|
1165
|
+
isError: true,
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
//# sourceMappingURL=inspection-tools.js.map
|