mobile-debug-mcp 0.19.2 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +14 -48
- package/dist/system/android.js +78 -0
- package/dist/system/index.js +26 -0
- package/dist/system/ios.js +38 -0
- package/docs/CHANGELOG.md +6 -0
- package/docs/tools/TOOLS.md +1 -0
- package/docs/tools/system.md +48 -0
- package/package.json +1 -1
- package/src/server.ts +15 -41
- package/src/system/android.ts +62 -0
- package/src/system/index.ts +27 -0
- package/src/system/ios.ts +28 -0
- package/test/system/adb_version.test.ts +25 -0
- package/test/system/get_system_status.test.ts +52 -0
- package/test/system/system_status.test.ts +109 -0
package/dist/server.js
CHANGED
|
@@ -7,10 +7,6 @@ import { ToolsInteract } from './interact/index.js';
|
|
|
7
7
|
import { ToolsObserve } from './observe/index.js';
|
|
8
8
|
import { AndroidManage } from './manage/index.js';
|
|
9
9
|
import { iOSManage } from './manage/index.js';
|
|
10
|
-
import { ensureAdbAvailable } from './utils/android/utils.js';
|
|
11
|
-
import { getIdbCmd, isIDBInstalled } from './utils/ios/utils.js';
|
|
12
|
-
import { getXcrunCmd } from './utils/ios/utils.js';
|
|
13
|
-
import { execSync } from 'child_process';
|
|
14
10
|
const server = new Server({
|
|
15
11
|
name: "mobile-debug-mcp",
|
|
16
12
|
version: "0.7.0"
|
|
@@ -19,50 +15,11 @@ const server = new Server({
|
|
|
19
15
|
tools: {}
|
|
20
16
|
}
|
|
21
17
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.debug('[startup] adb available:', adbCheck.adbCmd, adbCheck.version);
|
|
28
|
-
else
|
|
29
|
-
console.warn('[startup] adb not available or failed to run:', adbCheck.adbCmd, adbCheck.error);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
if (e instanceof Error) {
|
|
33
|
-
console.warn('[startup] error during adb healthcheck:', e.message);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
console.warn('[startup] error during adb healthcheck:', String(e));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Check idb availability (non-fatal)
|
|
40
|
-
try {
|
|
41
|
-
const idbInstalled = await isIDBInstalled();
|
|
42
|
-
const idbCmd = getIdbCmd();
|
|
43
|
-
if (idbInstalled)
|
|
44
|
-
console.debug('[startup] idb available:', idbCmd);
|
|
45
|
-
else
|
|
46
|
-
console.debug('[startup] idb not available or failed to run:', idbCmd);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.warn('[startup] error during idb healthcheck:', e instanceof Error ? e.message : String(e));
|
|
50
|
-
}
|
|
51
|
-
// Check xcrun availability (non-fatal)
|
|
52
|
-
try {
|
|
53
|
-
const xcrun = getXcrunCmd();
|
|
54
|
-
try {
|
|
55
|
-
const out = execSync(`${xcrun} --version`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
|
56
|
-
console.debug('[startup] xcrun available:', xcrun, out.split('\n')[0]);
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
console.warn('[startup] xcrun not available or failed to run:', xcrun, err instanceof Error ? err.message : String(err));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
console.warn('[startup] error during xcrun healthcheck:', e instanceof Error ? e.message : String(e));
|
|
64
|
-
}
|
|
65
|
-
})();
|
|
18
|
+
import { getSystemStatus } from './system/index.js';
|
|
19
|
+
// Run a quick startup healthcheck (non-fatal) by calling getSystemStatus directly and log a short summary
|
|
20
|
+
getSystemStatus().then(res => {
|
|
21
|
+
console.debug('[startup] system status summary:', { adb: res.adbAvailable, ios: res.iosAvailable, devices: res.devices, iosDevices: res.iosDevices });
|
|
22
|
+
}).catch(e => console.warn('[startup] healthcheck failed:', e instanceof Error ? e.message : String(e)));
|
|
66
23
|
function wrapResponse(data) {
|
|
67
24
|
return {
|
|
68
25
|
content: [{
|
|
@@ -225,6 +182,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
225
182
|
}
|
|
226
183
|
}
|
|
227
184
|
},
|
|
185
|
+
{
|
|
186
|
+
name: "get_system_status",
|
|
187
|
+
description: "Quick healthcheck of local mobile debugging environment (adb, devices, logs, env, iOS).",
|
|
188
|
+
inputSchema: { type: "object", properties: {} }
|
|
189
|
+
},
|
|
228
190
|
{
|
|
229
191
|
name: "capture_screenshot",
|
|
230
192
|
description: "Capture a screenshot from an Android device or iOS simulator. Returns device metadata and the screenshot image.",
|
|
@@ -625,6 +587,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
625
587
|
const res = await ToolsManage.listDevicesHandler({ platform, appId });
|
|
626
588
|
return wrapResponse(res);
|
|
627
589
|
}
|
|
590
|
+
if (name === "get_system_status") {
|
|
591
|
+
const result = await getSystemStatus();
|
|
592
|
+
return wrapResponse(result);
|
|
593
|
+
}
|
|
628
594
|
if (name === "capture_screenshot") {
|
|
629
595
|
const { platform, deviceId } = args;
|
|
630
596
|
const res = await ToolsObserve.captureScreenshotHandler({ platform, deviceId });
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { ensureAdbAvailable } from '../utils/android/utils.js';
|
|
3
|
+
export async function checkAndroid() {
|
|
4
|
+
const issues = [];
|
|
5
|
+
let adbAvailable = false;
|
|
6
|
+
let adbVersion = '';
|
|
7
|
+
let devices = 0;
|
|
8
|
+
let deviceStates = '';
|
|
9
|
+
let logsAvailable = false;
|
|
10
|
+
let envValid = false;
|
|
11
|
+
let appInstalled = undefined;
|
|
12
|
+
try {
|
|
13
|
+
const adbCheck = ensureAdbAvailable();
|
|
14
|
+
const adbCmd = adbCheck.adbCmd || 'adb';
|
|
15
|
+
adbAvailable = !!adbCheck.ok;
|
|
16
|
+
adbVersion = (adbCheck.version || '').toString().split('\n')[0];
|
|
17
|
+
if (!adbAvailable)
|
|
18
|
+
issues.push('ADB not available');
|
|
19
|
+
try {
|
|
20
|
+
const out = execSync(`${adbCmd} devices -l`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
|
|
21
|
+
const lines = out.split('\n').map(l => l.trim()).filter(Boolean);
|
|
22
|
+
const deviceLines = lines.filter(l => !l.startsWith('List of devices'));
|
|
23
|
+
const stateCounts = {};
|
|
24
|
+
for (const l of deviceLines) {
|
|
25
|
+
const parts = l.split(/\s+/);
|
|
26
|
+
const state = parts[1] || '';
|
|
27
|
+
stateCounts[state] = (stateCounts[state] || 0) + 1;
|
|
28
|
+
}
|
|
29
|
+
devices = deviceLines.length;
|
|
30
|
+
const parts = Object.entries(stateCounts).map(([k, v]) => `${v} ${k}`);
|
|
31
|
+
deviceStates = parts.join(', ');
|
|
32
|
+
if (devices === 0)
|
|
33
|
+
issues.push('No Android devices connected');
|
|
34
|
+
if (stateCounts['unauthorized'])
|
|
35
|
+
issues.push(`${stateCounts['unauthorized']} device(s) unauthorized`);
|
|
36
|
+
if (stateCounts['offline'])
|
|
37
|
+
issues.push(`${stateCounts['offline']} device(s) offline`);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
console.debug('[get_system_status] adb devices failed: ' + String(e));
|
|
41
|
+
issues.push('Failed to list Android devices');
|
|
42
|
+
}
|
|
43
|
+
if (adbAvailable && devices > 0) {
|
|
44
|
+
try {
|
|
45
|
+
const lo = execSync(`${adbCmd} logcat -d -t 1`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
|
|
46
|
+
logsAvailable = !!lo;
|
|
47
|
+
if (!logsAvailable)
|
|
48
|
+
issues.push('Log access failed');
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
logsAvailable = false;
|
|
52
|
+
console.debug('[get_system_status] logcat check failed: ' + String(e));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const sdkRoot = process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME;
|
|
56
|
+
envValid = !!sdkRoot || (adbAvailable === true && !!(adbCheck.adbCmd && adbCheck.adbCmd !== 'adb'));
|
|
57
|
+
if (!envValid)
|
|
58
|
+
issues.push('ANDROID_SDK_ROOT/ANDROID_HOME missing and adb not found in PATH');
|
|
59
|
+
const pkg = process.env.MCP_TARGET_PACKAGE || process.env.MCP_TARGET_APP_ID;
|
|
60
|
+
if (pkg && adbAvailable && devices > 0) {
|
|
61
|
+
try {
|
|
62
|
+
const pm = execSync(`${adbCmd} shell pm path ${pkg}`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
|
|
63
|
+
appInstalled = (pm || '').includes('package:');
|
|
64
|
+
if (!appInstalled)
|
|
65
|
+
issues.push(`App ${pkg} not installed on devices`);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
appInstalled = false;
|
|
69
|
+
console.debug('[get_system_status] pm check failed: ' + String(e));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.debug('[get_system_status] adb availability check failed: ' + String(e));
|
|
75
|
+
issues.push('ADB check failed');
|
|
76
|
+
}
|
|
77
|
+
return { adbAvailable, adbVersion, devices, deviceStates, logsAvailable, envValid, appInstalled, issues };
|
|
78
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { checkAndroid } from './android.js';
|
|
2
|
+
import { checkIOS } from './ios.js';
|
|
3
|
+
export async function getSystemStatus() {
|
|
4
|
+
try {
|
|
5
|
+
const android = await checkAndroid();
|
|
6
|
+
const ios = await checkIOS();
|
|
7
|
+
const issues = [...android.issues, ...ios.issues];
|
|
8
|
+
const success = issues.length === 0;
|
|
9
|
+
return {
|
|
10
|
+
success,
|
|
11
|
+
adbAvailable: android.adbAvailable,
|
|
12
|
+
adbVersion: android.adbVersion,
|
|
13
|
+
devices: android.devices,
|
|
14
|
+
deviceStates: android.deviceStates,
|
|
15
|
+
logsAvailable: android.logsAvailable,
|
|
16
|
+
envValid: android.envValid,
|
|
17
|
+
issues,
|
|
18
|
+
appInstalled: android.appInstalled,
|
|
19
|
+
iosAvailable: ios.iosAvailable,
|
|
20
|
+
iosDevices: ios.iosDevices
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return { success: false, issues: ['Internal error: ' + (e instanceof Error ? e.message : String(e))] };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { getXcrunCmd } from '../utils/ios/utils.js';
|
|
3
|
+
export async function checkIOS() {
|
|
4
|
+
const issues = [];
|
|
5
|
+
let iosAvailable = false;
|
|
6
|
+
let iosDevices = 0;
|
|
7
|
+
try {
|
|
8
|
+
const xcrun = getXcrunCmd();
|
|
9
|
+
try {
|
|
10
|
+
execSync(`${xcrun} --version`, { stdio: ['ignore', 'pipe', 'ignore'], timeout: 1500 });
|
|
11
|
+
iosAvailable = true;
|
|
12
|
+
try {
|
|
13
|
+
const simOut = execSync(`${xcrun} simctl list devices booted --json`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
14
|
+
const data = JSON.parse(simOut);
|
|
15
|
+
let count = 0;
|
|
16
|
+
for (const k in data.devices) {
|
|
17
|
+
const arr = data.devices[k];
|
|
18
|
+
if (Array.isArray(arr))
|
|
19
|
+
count += arr.filter((d) => (d.state || '').toLowerCase() === 'booted').length;
|
|
20
|
+
}
|
|
21
|
+
iosDevices = count;
|
|
22
|
+
if (iosDevices === 0)
|
|
23
|
+
issues.push('No iOS simulators/devices booted');
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
console.debug('[get_system_status] simctl list failed: ' + String(e));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
iosAvailable = false;
|
|
31
|
+
console.debug('[get_system_status] xcrun --version failed: ' + String(e));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.debug('[get_system_status] xcrun check failed: ' + String(e));
|
|
36
|
+
}
|
|
37
|
+
return { iosAvailable, iosDevices, issues };
|
|
38
|
+
}
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the **Mobile Debug MCP** project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.20.0]
|
|
6
|
+
- Added `get_system_status` tool and refactored system health checks into `src/system`.
|
|
7
|
+
- Provides a fast environment healthcheck (ADB availability/version, connected devices, log access, Android env vars, and basic iOS xcrun/simulator checks).
|
|
8
|
+
- Designed to be fast, non-throwing, and to gate agent actions early. Unit tests added.
|
|
9
|
+
|
|
10
|
+
|
|
5
11
|
## [0.19.2]
|
|
6
12
|
- Added healthcheck improvments
|
|
7
13
|
- Added skills
|
package/docs/tools/TOOLS.md
CHANGED
|
@@ -7,5 +7,6 @@ See:
|
|
|
7
7
|
- [mange](manage.md) — build, install and device management tools
|
|
8
8
|
- [observe](observe.md) — logs, screenshots and UI inspection tools
|
|
9
9
|
- [interact](interact.md) — UI interaction tools (tap, swipe, type, wait)
|
|
10
|
+
- [system](system.md) — environment and health checks (get_system_status)
|
|
10
11
|
|
|
11
12
|
For per-tool deep dives, open the linked files above.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# System (environment & health checks)
|
|
2
|
+
|
|
3
|
+
Tools that provide a lightweight view of the local mobile debugging environment and surface issues early so agents can decide whether to proceed.
|
|
4
|
+
|
|
5
|
+
## get_system_status
|
|
6
|
+
A fast, non-throwing healthcheck that inspects key dependencies and connections required for mobile debugging.
|
|
7
|
+
|
|
8
|
+
Input:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
{}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Response (example):
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"success": true,
|
|
19
|
+
"adbAvailable": true,
|
|
20
|
+
"adbVersion": "8.1.0",
|
|
21
|
+
"devices": 1,
|
|
22
|
+
"deviceStates": "1 device",
|
|
23
|
+
"logsAvailable": true,
|
|
24
|
+
"envValid": true,
|
|
25
|
+
"issues": [],
|
|
26
|
+
"appInstalled": true,
|
|
27
|
+
"iosAvailable": true,
|
|
28
|
+
"iosDevices": 1
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Checks performed (fast, best-effort):
|
|
33
|
+
- ADB availability and version (adb --version)
|
|
34
|
+
- Connected Android devices (adb devices -l), counts and state summary (device/unauthorized/offline)
|
|
35
|
+
- Log access probe (adb logcat -d -t 1)
|
|
36
|
+
- Android environment variables (ANDROID_SDK_ROOT / ANDROID_HOME / PATH contains adb)
|
|
37
|
+
- Optional: app installation check if MCP_TARGET_PACKAGE/MCP_TARGET_APP_ID is set (pm path)
|
|
38
|
+
- Basic iOS checks (xcrun --version and simctl list devices booted)
|
|
39
|
+
|
|
40
|
+
Behavior notes:
|
|
41
|
+
- Always returns structured JSON and never throws; any failures are surfaced in the `issues` array.
|
|
42
|
+
- Designed to be fast (<~1s probes where possible); startup callers may prefer a `fastMode` variant that only checks existence.
|
|
43
|
+
- Useful to call at the start of an agent session to gate subsequent actions.
|
|
44
|
+
|
|
45
|
+
Usage guidance:
|
|
46
|
+
- Call before build/install flows to avoid wasted build attempts on misconfigured systems.
|
|
47
|
+
- If `success: false`, attempt recovery steps or report issues to the user.
|
|
48
|
+
|
package/package.json
CHANGED
package/src/server.ts
CHANGED
|
@@ -20,10 +20,6 @@ import { ToolsInteract } from './interact/index.js'
|
|
|
20
20
|
import { ToolsObserve } from './observe/index.js'
|
|
21
21
|
import { AndroidManage } from './manage/index.js'
|
|
22
22
|
import { iOSManage } from './manage/index.js'
|
|
23
|
-
import { ensureAdbAvailable } from './utils/android/utils.js'
|
|
24
|
-
import { getIdbCmd, isIDBInstalled } from './utils/ios/utils.js'
|
|
25
|
-
import { getXcrunCmd } from './utils/ios/utils.js'
|
|
26
|
-
import { execSync } from 'child_process'
|
|
27
23
|
|
|
28
24
|
|
|
29
25
|
const server = new Server(
|
|
@@ -38,44 +34,12 @@ const server = new Server(
|
|
|
38
34
|
}
|
|
39
35
|
);
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
(async () => {
|
|
43
|
-
try {
|
|
44
|
-
const adbCheck = ensureAdbAvailable()
|
|
45
|
-
if (adbCheck.ok) console.debug('[startup] adb available:', adbCheck.adbCmd, adbCheck.version)
|
|
46
|
-
else console.warn('[startup] adb not available or failed to run:', adbCheck.adbCmd, adbCheck.error)
|
|
47
|
-
} catch (e: unknown) {
|
|
48
|
-
if (e instanceof Error) {
|
|
49
|
-
console.warn('[startup] error during adb healthcheck:', e.message)
|
|
50
|
-
} else {
|
|
51
|
-
console.warn('[startup] error during adb healthcheck:', String(e))
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Check idb availability (non-fatal)
|
|
56
|
-
try {
|
|
57
|
-
const idbInstalled = await isIDBInstalled()
|
|
58
|
-
const idbCmd = getIdbCmd()
|
|
59
|
-
if (idbInstalled) console.debug('[startup] idb available:', idbCmd)
|
|
60
|
-
else console.debug('[startup] idb not available or failed to run:', idbCmd)
|
|
61
|
-
} catch (e: unknown) {
|
|
62
|
-
console.warn('[startup] error during idb healthcheck:', e instanceof Error ? e.message : String(e))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Check xcrun availability (non-fatal)
|
|
66
|
-
try {
|
|
67
|
-
const xcrun = getXcrunCmd()
|
|
68
|
-
try {
|
|
69
|
-
const out = execSync(`${xcrun} --version`, { stdio: ['ignore','pipe','ignore'] }).toString().trim()
|
|
70
|
-
console.debug('[startup] xcrun available:', xcrun, out.split('\n')[0])
|
|
71
|
-
} catch (err: unknown) {
|
|
72
|
-
console.warn('[startup] xcrun not available or failed to run:', xcrun, err instanceof Error ? err.message : String(err))
|
|
73
|
-
}
|
|
74
|
-
} catch (e: unknown) {
|
|
75
|
-
console.warn('[startup] error during xcrun healthcheck:', e instanceof Error ? e.message : String(e))
|
|
76
|
-
}
|
|
37
|
+
import { getSystemStatus } from './system/index.js'
|
|
77
38
|
|
|
78
|
-
|
|
39
|
+
// Run a quick startup healthcheck (non-fatal) by calling getSystemStatus directly and log a short summary
|
|
40
|
+
getSystemStatus().then(res => {
|
|
41
|
+
console.debug('[startup] system status summary:', { adb: res.adbAvailable, ios: res.iosAvailable, devices: res.devices, iosDevices: res.iosDevices })
|
|
42
|
+
}).catch(e => console.warn('[startup] healthcheck failed:', e instanceof Error ? e.message : String(e)))
|
|
79
43
|
|
|
80
44
|
function wrapResponse<T>(data: T) {
|
|
81
45
|
return {
|
|
@@ -241,6 +205,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
241
205
|
}
|
|
242
206
|
}
|
|
243
207
|
},
|
|
208
|
+
{
|
|
209
|
+
name: "get_system_status",
|
|
210
|
+
description: "Quick healthcheck of local mobile debugging environment (adb, devices, logs, env, iOS).",
|
|
211
|
+
inputSchema: { type: "object", properties: {} }
|
|
212
|
+
},
|
|
244
213
|
{
|
|
245
214
|
name: "capture_screenshot",
|
|
246
215
|
description: "Capture a screenshot from an Android device or iOS simulator. Returns device metadata and the screenshot image.",
|
|
@@ -658,6 +627,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request: SchemaOutput<typ
|
|
|
658
627
|
return wrapResponse(res)
|
|
659
628
|
}
|
|
660
629
|
|
|
630
|
+
if (name === "get_system_status") {
|
|
631
|
+
const result = await getSystemStatus()
|
|
632
|
+
return wrapResponse(result)
|
|
633
|
+
}
|
|
634
|
+
|
|
661
635
|
|
|
662
636
|
if (name === "capture_screenshot") {
|
|
663
637
|
const { platform, deviceId } = args as any
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { execSync } from 'child_process'
|
|
2
|
+
import { ensureAdbAvailable } from '../utils/android/utils.js'
|
|
3
|
+
|
|
4
|
+
export async function checkAndroid() {
|
|
5
|
+
const issues: string[] = []
|
|
6
|
+
let adbAvailable = false
|
|
7
|
+
let adbVersion = ''
|
|
8
|
+
let devices = 0
|
|
9
|
+
let deviceStates = ''
|
|
10
|
+
let logsAvailable = false
|
|
11
|
+
let envValid = false
|
|
12
|
+
let appInstalled: boolean | undefined = undefined
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const adbCheck = ensureAdbAvailable()
|
|
16
|
+
const adbCmd = adbCheck.adbCmd || 'adb'
|
|
17
|
+
adbAvailable = !!adbCheck.ok
|
|
18
|
+
adbVersion = (adbCheck.version || '').toString().split('\n')[0]
|
|
19
|
+
if (!adbAvailable) issues.push('ADB not available')
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const out = execSync(`${adbCmd} devices -l`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore','pipe','ignore'] }).toString()
|
|
23
|
+
const lines = out.split('\n').map(l => l.trim()).filter(Boolean)
|
|
24
|
+
const deviceLines = lines.filter(l => !l.startsWith('List of devices'))
|
|
25
|
+
const stateCounts: Record<string, number> = {}
|
|
26
|
+
for (const l of deviceLines) {
|
|
27
|
+
const parts = l.split(/\s+/)
|
|
28
|
+
const state = parts[1] || ''
|
|
29
|
+
stateCounts[state] = (stateCounts[state] || 0) + 1
|
|
30
|
+
}
|
|
31
|
+
devices = deviceLines.length
|
|
32
|
+
const parts = Object.entries(stateCounts).map(([k,v]) => `${v} ${k}`)
|
|
33
|
+
deviceStates = parts.join(', ')
|
|
34
|
+
if (devices === 0) issues.push('No Android devices connected')
|
|
35
|
+
if (stateCounts['unauthorized']) issues.push(`${stateCounts['unauthorized']} device(s) unauthorized`)
|
|
36
|
+
if (stateCounts['offline']) issues.push(`${stateCounts['offline']} device(s) offline`)
|
|
37
|
+
} catch (e: unknown) { console.debug('[get_system_status] adb devices failed: ' + String(e)); issues.push('Failed to list Android devices') }
|
|
38
|
+
|
|
39
|
+
if (adbAvailable && devices > 0) {
|
|
40
|
+
try {
|
|
41
|
+
const lo = execSync(`${adbCmd} logcat -d -t 1`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore','pipe','ignore'] }).toString()
|
|
42
|
+
logsAvailable = !!lo
|
|
43
|
+
if (!logsAvailable) issues.push('Log access failed')
|
|
44
|
+
} catch (e: unknown) { logsAvailable = false; console.debug('[get_system_status] logcat check failed: ' + String(e)) }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const sdkRoot = process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME
|
|
48
|
+
envValid = !!sdkRoot || (adbAvailable === true && !!(adbCheck.adbCmd && adbCheck.adbCmd !== 'adb'))
|
|
49
|
+
if (!envValid) issues.push('ANDROID_SDK_ROOT/ANDROID_HOME missing and adb not found in PATH')
|
|
50
|
+
|
|
51
|
+
const pkg = process.env.MCP_TARGET_PACKAGE || process.env.MCP_TARGET_APP_ID
|
|
52
|
+
if (pkg && adbAvailable && devices > 0) {
|
|
53
|
+
try {
|
|
54
|
+
const pm = execSync(`${adbCmd} shell pm path ${pkg}`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore','pipe','ignore'] }).toString()
|
|
55
|
+
appInstalled = (pm || '').includes('package:')
|
|
56
|
+
if (!appInstalled) issues.push(`App ${pkg} not installed on devices`)
|
|
57
|
+
} catch (e: unknown) { appInstalled = false; console.debug('[get_system_status] pm check failed: ' + String(e)) }
|
|
58
|
+
}
|
|
59
|
+
} catch (e: unknown) { console.debug('[get_system_status] adb availability check failed: ' + String(e)); issues.push('ADB check failed') }
|
|
60
|
+
|
|
61
|
+
return { adbAvailable, adbVersion, devices, deviceStates, logsAvailable, envValid, appInstalled, issues }
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { checkAndroid } from './android.js'
|
|
2
|
+
import { checkIOS } from './ios.js'
|
|
3
|
+
|
|
4
|
+
export async function getSystemStatus() {
|
|
5
|
+
try {
|
|
6
|
+
const android = await checkAndroid()
|
|
7
|
+
const ios = await checkIOS()
|
|
8
|
+
const issues = [...android.issues, ...ios.issues]
|
|
9
|
+
|
|
10
|
+
const success = issues.length === 0
|
|
11
|
+
return {
|
|
12
|
+
success,
|
|
13
|
+
adbAvailable: android.adbAvailable,
|
|
14
|
+
adbVersion: android.adbVersion,
|
|
15
|
+
devices: android.devices,
|
|
16
|
+
deviceStates: android.deviceStates,
|
|
17
|
+
logsAvailable: android.logsAvailable,
|
|
18
|
+
envValid: android.envValid,
|
|
19
|
+
issues,
|
|
20
|
+
appInstalled: android.appInstalled,
|
|
21
|
+
iosAvailable: ios.iosAvailable,
|
|
22
|
+
iosDevices: ios.iosDevices
|
|
23
|
+
}
|
|
24
|
+
} catch (e: unknown) {
|
|
25
|
+
return { success: false, issues: ['Internal error: ' + (e instanceof Error ? e.message : String(e))] }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { execSync } from 'child_process'
|
|
2
|
+
import { getXcrunCmd } from '../utils/ios/utils.js'
|
|
3
|
+
|
|
4
|
+
export async function checkIOS() {
|
|
5
|
+
const issues: string[] = []
|
|
6
|
+
let iosAvailable = false
|
|
7
|
+
let iosDevices = 0
|
|
8
|
+
try {
|
|
9
|
+
const xcrun = getXcrunCmd()
|
|
10
|
+
try {
|
|
11
|
+
execSync(`${xcrun} --version`, { stdio: ['ignore','pipe','ignore'], timeout: 1500 })
|
|
12
|
+
iosAvailable = true
|
|
13
|
+
try {
|
|
14
|
+
const simOut = execSync(`${xcrun} simctl list devices booted --json`, { encoding: 'utf8', timeout: 1500, stdio: ['ignore','pipe','ignore'] })
|
|
15
|
+
const data = JSON.parse(simOut)
|
|
16
|
+
type SimDevice = { state?: string }
|
|
17
|
+
let count = 0
|
|
18
|
+
for (const k in data.devices) {
|
|
19
|
+
const arr = data.devices[k]
|
|
20
|
+
if (Array.isArray(arr)) count += arr.filter((d: SimDevice) => (d.state || '').toLowerCase() === 'booted').length
|
|
21
|
+
}
|
|
22
|
+
iosDevices = count
|
|
23
|
+
if (iosDevices === 0) issues.push('No iOS simulators/devices booted')
|
|
24
|
+
} catch (e: unknown) { console.debug('[get_system_status] simctl list failed: ' + String(e)) }
|
|
25
|
+
} catch (e: unknown) { iosAvailable = false; console.debug('[get_system_status] xcrun --version failed: ' + String(e)) }
|
|
26
|
+
} catch (e: unknown) { console.debug('[get_system_status] xcrun check failed: ' + String(e)) }
|
|
27
|
+
return { iosAvailable, iosDevices, issues }
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import * as androidUtils from '../../src/utils/android/utils.js'
|
|
3
|
+
import * as systemStatus from '../../src/system/index.js'
|
|
4
|
+
|
|
5
|
+
const origEnsure = (androidUtils as any).ensureAdbAvailable
|
|
6
|
+
|
|
7
|
+
function mockEnsure(returnVal: any) {
|
|
8
|
+
(androidUtils as any).ensureAdbAvailable = () => returnVal
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function restoreEnsure() {
|
|
12
|
+
(androidUtils as any).ensureAdbAvailable = origEnsure
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('adb version parsing', () => {
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
restoreEnsure()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('uses only the first line of multi-line adb --version output', async () => {
|
|
21
|
+
mockEnsure({ adbCmd: 'adb', ok: true, version: 'Android Debug Bridge version 1.0.41\nRevision 8f3b7' })
|
|
22
|
+
const res = await systemStatus.getSystemStatus()
|
|
23
|
+
assert.strictEqual(res.adbVersion, 'Android Debug Bridge version 1.0.41')
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import { ensureAdbAvailable } from '../../src/utils/android/utils.js'
|
|
3
|
+
import { getXcrunCmd } from '../../src/utils/ios/utils.js'
|
|
4
|
+
|
|
5
|
+
// We import the server handler module to access the internal get_system_status implementation.
|
|
6
|
+
import * as server from '../../src/server.js'
|
|
7
|
+
|
|
8
|
+
// Small helper to call the tool handler similarly to how the MCP transport would.
|
|
9
|
+
async function callGetSystemStatus() {
|
|
10
|
+
const req = { params: { name: 'get_system_status', arguments: {} } }
|
|
11
|
+
// @ts-ignore - use the handler exported from server
|
|
12
|
+
const handler = (server as any).defaultRequestHandler || (server as any).callToolHandler || (server as any).__callTool
|
|
13
|
+
if (!handler) {
|
|
14
|
+
// fallback: require the module and call the exported server instance's request handler
|
|
15
|
+
// The server code registers the handler directly; we will emulate by requiring compiled code in dist if available.
|
|
16
|
+
try {
|
|
17
|
+
const dist = await import('../../dist/server.js')
|
|
18
|
+
// Try to execute by sending a call via the server instance if exported
|
|
19
|
+
if (dist && dist.server && typeof dist.server._handleCall === 'function') {
|
|
20
|
+
return dist.server._handleCall(req)
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// best effort only
|
|
24
|
+
}
|
|
25
|
+
throw new Error('Cannot locate server call handler for tests')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return handler(req)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('get_system_status tool (unit)', () => {
|
|
32
|
+
it('returns structured result without throwing', async () => {
|
|
33
|
+
const res = await callGetSystemStatus()
|
|
34
|
+
// Handler returns { content: [{ type: 'text', text: JSON.stringify(...) }] }
|
|
35
|
+
assert(res && res.content && Array.isArray(res.content))
|
|
36
|
+
const textBlock = res.content.find((c: any) => c.type === 'text')
|
|
37
|
+
assert(textBlock && textBlock.text)
|
|
38
|
+
const payload = JSON.parse(textBlock.text)
|
|
39
|
+
assert(typeof payload.success === 'boolean')
|
|
40
|
+
assert(Array.isArray(payload.issues))
|
|
41
|
+
}).timeout(5000)
|
|
42
|
+
|
|
43
|
+
it('detects adb availability helper works', () => {
|
|
44
|
+
const adb = ensureAdbAvailable()
|
|
45
|
+
assert(adb && typeof adb.ok === 'boolean')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('detects xcrun command helper exists', () => {
|
|
49
|
+
const cmd = getXcrunCmd()
|
|
50
|
+
assert(typeof cmd === 'string')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import child_process from 'child_process'
|
|
3
|
+
|
|
4
|
+
import * as androidUtils from '../../src/utils/android/utils.js'
|
|
5
|
+
import * as iosUtils from '../../src/utils/ios/utils.js'
|
|
6
|
+
import * as systemStatus from '../../src/system/index.js'
|
|
7
|
+
|
|
8
|
+
const origExecSync = child_process.execSync
|
|
9
|
+
const origEnsure = (androidUtils as any).ensureAdbAvailable
|
|
10
|
+
const origGetXcrun = (iosUtils as any).getXcrunCmd
|
|
11
|
+
|
|
12
|
+
function mockExec(behaviour: (cmd: string) => string) {
|
|
13
|
+
(child_process as any).execSync = (cmd: string) => {
|
|
14
|
+
const s = typeof cmd === 'string' ? cmd : (Array.isArray(cmd) ? cmd.join(' ') : String(cmd))
|
|
15
|
+
const out = behaviour(s)
|
|
16
|
+
if (out instanceof Error) throw out
|
|
17
|
+
return out
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function restoreExec() {
|
|
22
|
+
(child_process as any).execSync = origExecSync
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function mockEnsure(returnVal: any) {
|
|
26
|
+
(androidUtils as any).ensureAdbAvailable = () => returnVal
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function restoreEnsure() {
|
|
30
|
+
(androidUtils as any).ensureAdbAvailable = origEnsure
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mockGetXcrun(val: string) {
|
|
34
|
+
(iosUtils as any).getXcrunCmd = () => val
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function restoreGetXcrun() {
|
|
38
|
+
(iosUtils as any).getXcrunCmd = origGetXcrun
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('system_status checks', () => {
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
restoreExec(); restoreEnsure(); restoreGetXcrun()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('reports healthy system when adb and xcrun present', async () => {
|
|
47
|
+
mockEnsure({ adbCmd: 'adb', ok: true, version: '8.1.0' })
|
|
48
|
+
mockGetXcrun('xcrun')
|
|
49
|
+
|
|
50
|
+
mockExec((cmd) => {
|
|
51
|
+
if (cmd.startsWith('adb devices')) return 'List of devices attached\nemulator-5554\tdevice'
|
|
52
|
+
if (cmd.includes('adb logcat')) return 'I/Tag: ok'
|
|
53
|
+
if (cmd.includes('adb shell pm path')) return 'package:/data/app/com.example-1/base.apk'
|
|
54
|
+
if (cmd.startsWith('xcrun --version')) return 'xcrun version 123'
|
|
55
|
+
if (cmd.includes('simctl list devices booted --json')) return JSON.stringify({ devices: {} })
|
|
56
|
+
return ''
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const res = await systemStatus.getSystemStatus()
|
|
60
|
+
assert.strictEqual(res.success, true)
|
|
61
|
+
assert.strictEqual(res.adbAvailable, true)
|
|
62
|
+
assert.strictEqual(typeof res.adbVersion, 'string')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('reports adb missing', async () => {
|
|
66
|
+
mockEnsure({ adbCmd: 'adb', ok: false, error: 'not found' })
|
|
67
|
+
mockGetXcrun('xcrun')
|
|
68
|
+
mockExec((cmd) => {
|
|
69
|
+
if (cmd.startsWith('xcrun --version')) return 'xcrun version'
|
|
70
|
+
return ''
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const res = await systemStatus.getSystemStatus()
|
|
74
|
+
assert.strictEqual(res.success, false)
|
|
75
|
+
assert(res.issues.some((i: string) => i.includes('ADB')))
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('detects unauthorized/offline devices', async () => {
|
|
79
|
+
mockEnsure({ adbCmd: 'adb', ok: true, version: '8.1.0' })
|
|
80
|
+
mockGetXcrun('xcrun')
|
|
81
|
+
mockExec((cmd) => {
|
|
82
|
+
if (cmd.startsWith('adb devices')) return 'List of devices attached\nserial1\tunauthorized\nserial2\toffline\n'
|
|
83
|
+
if (cmd.startsWith('xcrun --version')) return 'xcrun version'
|
|
84
|
+
return ''
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const res = await systemStatus.getSystemStatus()
|
|
88
|
+
assert.strictEqual(res.success, false)
|
|
89
|
+
assert(res.issues.some((i: string) => i.includes('unauthorized')))
|
|
90
|
+
assert(res.issues.some((i: string) => i.includes('offline')))
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('handles missing xcrun gracefully', async () => {
|
|
94
|
+
mockEnsure({ adbCmd: 'adb', ok: true, version: '8.1.0' })
|
|
95
|
+
mockGetXcrun('xcrun')
|
|
96
|
+
mockExec((cmd) => {
|
|
97
|
+
if (cmd.startsWith('adb devices')) return 'List of devices attached\nemulator-5554\tdevice'
|
|
98
|
+
if (cmd.startsWith('xcrun --version')) throw new Error('not found')
|
|
99
|
+
return ''
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const res = await systemStatus.getSystemStatus()
|
|
103
|
+
// Expect iOS check to be false and Android to be healthy
|
|
104
|
+
assert.strictEqual(res.iosAvailable, false)
|
|
105
|
+
assert.strictEqual(res.adbAvailable, true)
|
|
106
|
+
// overall success may still be true (Android ok) but issues should include an xcrun-related message
|
|
107
|
+
assert(res.issues.some((i: string) => i.toLowerCase().includes('xcrun') || i.toLowerCase().includes('ios')))
|
|
108
|
+
})
|
|
109
|
+
})
|