mobile-debug-mcp 0.19.1 → 0.19.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/dist/server.js CHANGED
@@ -8,6 +8,9 @@ import { ToolsObserve } from './observe/index.js';
8
8
  import { AndroidManage } from './manage/index.js';
9
9
  import { iOSManage } from './manage/index.js';
10
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';
11
14
  const server = new Server({
12
15
  name: "mobile-debug-mcp",
13
16
  version: "0.7.0"
@@ -33,6 +36,32 @@ const server = new Server({
33
36
  console.warn('[startup] error during adb healthcheck:', String(e));
34
37
  }
35
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
+ }
36
65
  })();
37
66
  function wrapResponse(data) {
38
67
  return {
@@ -75,12 +75,13 @@ export async function isIDBInstalled() {
75
75
  execSync(`command -v ${cmd}`, { stdio: ['ignore', 'pipe', 'ignore'] });
76
76
  return true;
77
77
  }
78
- catch {
78
+ catch (e) {
79
79
  try {
80
80
  execSync(`${cmd} list-targets --json`, { stdio: ['ignore', 'pipe', 'ignore'], timeout: 2000 });
81
81
  return true;
82
82
  }
83
- catch {
83
+ catch (e2) {
84
+ console.debug(`[isIDBInstalled] idb presence check failed for '${cmd}': ${e instanceof Error ? e.message : String(e2)}`);
84
85
  return false;
85
86
  }
86
87
  }
package/docs/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to the **Mobile Debug MCP** project will be documented in this file.
4
4
 
5
+ ## [0.19.2]
6
+ - Added healthcheck improvments
7
+ - Added skills
8
+
5
9
  ## [0.19.1]
6
10
 
7
11
  - Fixed Android install issues
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobile-debug-mcp",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "description": "MCP server for mobile app debugging (Android + iOS), with focus on security and reliability",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,68 @@
1
+ # MCP Builder skill
2
+
3
+ name: mcp-builder
4
+ version: 0.1.0
5
+ summary: Reusable procedures for building, validating and installing Android/iOS apps in this repo. Designed for agents to act autonomously with project-specific guidance.
6
+
7
+ # Purpose
8
+ Provide concise, actionable procedures and schemas that encode the successful sequences used in mobile-debug-mcp: toolchain detection, build orchestration, install fallbacks, diagnostics collection, and verification (lint/tests). Keep core guidance short; link to references for details.
9
+
10
+ # Activation conditions
11
+ Activate when an agent needs to:
12
+ - build or install an app from this repository
13
+ - diagnose failing CI/dev machine builds
14
+ - run lint/tests and collect reproducible diagnostics
15
+
16
+ # Surface area (actions)
17
+ - detect-toolchain
18
+ - build-android
19
+ - install-android
20
+ - build-ios
21
+ - install-ios
22
+ - run-lint
23
+ - run-tests
24
+ - collect-diagnostics
25
+
26
+ # Core guidance (what agent must do)
27
+ 1. Prefer project conventions and existing helpers in src/utils and src/manage.
28
+ 2. Use detect-toolchain to decide JAVA_HOME/JBR preference and whether adb/idb/xcrun are available.
29
+ 3. For Android builds, call prepareGradle() to prepare child PATH and env, then run ./gradlew (wrapper) if present.
30
+ 4. For installs, parse adb output defensively (ignore streamed-install noise) and on failure fall back to push+pm path.
31
+ 5. For iOS installs, prefer simctl for simulators; if simctl fails check idb and attempt idb install with diagnostics.
32
+ 6. On any error, call collect-diagnostics and attach env snapshot, invoked commands, stdout/stderr, and suggested fixes.
33
+
34
+ # Inputs & outputs (short schemas)
35
+ - detect-toolchain(input: { platform: 'android'|'ios'|'both', preferJBR?: boolean }) -> { tools: [{name, cmd, ok, version, suggestion}] }
36
+ - build-android(input: { projectPath, variant?, clean?, envOverrides? }) -> { success, artifactPath?, logs?, diagnostics? }
37
+ - install-android(input: { appPath, projectPath?, deviceId?, allowBuild? }) -> { installed:boolean, device, output?, diagnostics? }
38
+ - build-ios/install-ios: mirror Android schema but use scheme/workspace/project and resultBundlePath
39
+ - run-lint/run-tests -> { exitCode, stdout, stderr, artifacts[] }
40
+ - collect-diagnostics(input: { reason, platform? }) -> { artifacts: [{ name, contentBase64?, path? }], envSnapshot }
41
+
42
+ # Failure handling & suggestions
43
+ - Always return structured diagnostics instead of throwing when possible.
44
+ - Provide a short human-friendly suggestion in diagnostics (e.g., "Install Android Platform Tools or set ADB_PATH").
45
+ - Redact sensitive env values (tokens, credentials) when including envSnapshot.
46
+
47
+ # Progressive disclosure
48
+ - Keep SKILL.md compact (this file). Place heavy references in skills/mcp-builder/references/*.md and instruct agents to load them only when needed.
49
+
50
+ # References (implement as separate files)
51
+ - references/toolchain-details.md — exact paths/heuristics used for JBR, JAVA_HOME, ANDROID_SDK locations.
52
+ - references/build-flags.md — gradle/xcodebuild flags used, timeouts, and retry rationale.
53
+ - references/diagnostics-schema.md — JSON schema for runResult and collected artifacts.
54
+
55
+ # Implementation notes for maintainers
56
+ - Implement a thin adapter in src/skills/mcp-builder/index.ts that maps skill actions to existing functions in src/manage and src/utils.
57
+ - Provide unit tests under test/skills/mcp-builder that mock child_process to validate happy/failure paths.
58
+ - Add env toggles: MCP_PREFERS_JBR, MCP_GRADLE_RETRIES, MCP_XCODEBUILD_RETRIES.
59
+
60
+ # Example agent flow
61
+ 1. call detect-toolchain({platform:'android', preferJBR:true})
62
+ 2. if ok -> call build-android({projectPath:'/path', variant:'Debug'})
63
+ 3. call install-android({appPath:'/path/to.apk', deviceId:'emulator-5554'})
64
+ 4. if install fails -> call collect-diagnostics({reason:'install failure', platform:'android'})
65
+
66
+ # License
67
+ Same as repository (MIT).
68
+
@@ -0,0 +1,43 @@
1
+ # Build flags and runtime configuration
2
+
3
+ Purpose: describe the flags, environment variables and spawn-environment handling that agents should use when orchestrating Android and iOS builds for this repo.
4
+
5
+ Common env variables
6
+ - MCP_GRADLE_RETRIES (default: 1) — number of retry attempts on watchdog kills for Gradle
7
+ - MCP_GRADLE_TIMEOUT_MS (default: 300000) — gradle watch/duration timeout
8
+ - MCP_XCODEBUILD_RETRIES, MCP_XCODEBUILD_TIMEOUT_MS — similar for xcodebuild
9
+ - MCP_PREFERS_JBR — prefer Android Studio JBR for JAVA_HOME
10
+ - MCP_DERIVED_DATA, MCP_XCODE_RESULTBUNDLE_PATH — override DerivedData/result bundle locations
11
+
12
+ Android (Gradle)
13
+ - Use the Gradle wrapper if present: `./gradlew assemble<Variant>` (e.g., assembleDebug). Prefer wrapper to ensure consistent Gradle version.
14
+ - Prepare spawn env by prepending javaBin and platform-tools dir to PATH and set GRADLE_JAVA_HOME and `-Dorg.gradle.java.home` when necessary.
15
+ - If wrapper exists, ensure `chmod +x ./gradlew` before spawn.
16
+ - Recommended flags:
17
+ - `--no-daemon` sometimes helpful in CI, but wrap with existing project conventions.
18
+ - Set `org.gradle.jvmargs` via env or gradle.properties only if needed.
19
+ - Timeouts & watchdog:
20
+ - Use a watchdog timeout (MCP_GRADLE_TIMEOUT_MS) and retry (MCP_GRADLE_RETRIES) if killed by watchdog. Record stdout/stderr for each attempt.
21
+
22
+ iOS (xcodebuild)
23
+ - Use `xcodebuild -workspace <ws> -scheme <scheme> -configuration Debug -sdk iphonesimulator build` for simulator builds.
24
+ - Provide `-derivedDataPath` and `-resultBundlePath` to isolate builds and produce diagnostics. Default result bundle path should be unique per run to avoid collisions.
25
+ - Recommended flags: `-parallelizeTargets -jobs <N>` where N is from MCP_XCODE_JOBS or sensible default (4).
26
+ - When a destination UDID is available, always pass `-destination "platform=iOS Simulator,id=<UDID>"` to avoid ambiguous device selection.
27
+ - Timeouts & retries: respect MCP_XCODEBUILD_TIMEOUT_MS and MCP_XCODEBUILD_RETRIES; capture stdout/stderr and save logs under build-results.
28
+
29
+ Install-time behavior
30
+ - Android: prefer `adb install -r <apk>` for fast installs. If output contains spurious lines (e.g., "Performing Streamed Install" followed by "Success"), parse to extract final status. On failure try `adb push` to `/data/local/tmp` + `pm install -r <remote>` as a fallback collect push/install diagnostics.
31
+ - iOS: prefer `xcrun simctl install <device> <app>` for simulator. On failure attempt idb install if idb exists: `idb install <ipa|app> --udid <udid>` and record its stdout/stderr.
32
+
33
+ Diagnostics capture
34
+ - Save stdout/stderr, exitCode and environment snapshot for each command. Persist logs under workspace/build-results or a temp dir provided by the caller.
35
+ - For builds, also capture produced artifact paths to return to caller.
36
+
37
+ Examples
38
+ - Gradle invocation (pseudo):
39
+ spawnOpts.env.PATH = `${javaBin}:${platformTools}:${process.env.PATH}`
40
+ spawn('./gradlew', ['assembleDebug'], { cwd: projectRoot, env: spawnOpts.env })
41
+
42
+ - xcodebuild invocation (pseudo):
43
+ xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug -sdk iphonesimulator -derivedDataPath /tmp/derived -resultBundlePath /tmp/Result-123.xcresult -parallelizeTargets -jobs 4 build
@@ -0,0 +1,48 @@
1
+ # Diagnostics schema
2
+
3
+ This document defines the JSON shapes that mcp-builder actions return when collecting diagnostics. Agents and tooling should rely on these keys.
4
+
5
+ Top-level diagnostic object
6
+ {
7
+ "error": "short human-friendly message",
8
+ "runResult": {
9
+ "command": "/usr/bin/adb",
10
+ "args": ["install", "app.apk"],
11
+ "exitCode": 1,
12
+ "stdout": "...",
13
+ "stderr": "...",
14
+ "startTimeMs": 1650000000000,
15
+ "endTimeMs": 1650000001000,
16
+ "envSnapshot": { "PATH": "...", "JAVA_HOME": "REDACTED" }
17
+ },
18
+ "artifacts": [ { name, path?, contentBase64?, type? } ],
19
+ "suggestedFixes": ["Install Android Platform Tools", "Set JAVA_HOME to JDK 17"]
20
+ }
21
+
22
+ Fields
23
+ - error: short message summarising the failure.
24
+ - runResult: information captured from a single command invocation. Use this for programmatic retries or human debugging.
25
+ - command, args: the executed command
26
+ - exitCode: numeric exit code, null for killed/unknown
27
+ - stdout, stderr: captured text
28
+ - startTimeMs, endTimeMs: epoch ms for duration
29
+ - envSnapshot: a restricted set of env variables (PATH, JAVA_HOME, ADB_PATH, IDB_PATH, XCRUN_PATH). Any value matching sensitive patterns (e.g., /token|secret|key|passwd/i) must be redacted to "REDACTED".
30
+ - artifacts: array of captured files. Each artifact: { name: string, path?: string, contentBase64?: string, type?: "log"|"archive"|"image" }
31
+ - suggestedFixes: short actionable suggestions for human/operator.
32
+
33
+ Notes on size and transmission
34
+ - Prefer storing large artifacts on disk and returning paths rather than inlining large base64 blobs. If transmitting, limit base64 inlined artifacts to a configurable max (e.g., 5MB) and prefer compression/archiving.
35
+
36
+ Example: adb install failure
37
+ {
38
+ "error": "adb: device not found",
39
+ "runResult": {
40
+ "command": "adb",
41
+ "args": ["devices"],
42
+ "exitCode": 0,
43
+ "stdout": "List of devices attached\n\n",
44
+ "stderr": "",
45
+ "envSnapshot": { "PATH": "/usr/local/bin:/usr/bin", "JAVA_HOME": null }
46
+ },
47
+ "suggestedFixes": ["Connect an Android device or start an emulator", "Ensure adb is on PATH or set ADB_PATH"]
48
+ }
@@ -0,0 +1,62 @@
1
+ # Toolchain details
2
+
3
+ This reference documents the exact heuristics and commands used by the mcp-builder skill to detect and validate the native toolchain (Android & iOS) on contributor machines.
4
+
5
+ Key environment variables
6
+ - ADB_PATH: explicit path to adb binary
7
+ - ANDROID_SDK_ROOT / ANDROID_HOME: SDK root; platform-tools/adb under these
8
+ - ANDROID_STUDIO_JBR / ANDROID_STUDIO_JDK: explicit Android Studio JBR/JDK path
9
+ - JAVA_HOME: system JDK
10
+ - IDB_PATH / MCP_IDB_PATH: idb path for iOS
11
+ - XCRUN_PATH: explicit xcrun path
12
+ - MCP_PREFERS_JBR: boolean to prefer Android Studio JBR when present
13
+
14
+ Android Java detection precedence
15
+ 1. ANDROID_STUDIO_JBR / ANDROID_STUDIO_JDK env vars (preferred when MCP_PREFERS_JBR set)
16
+ 2. Known Android Studio JBR locations (macOS):
17
+ - /Applications/Android Studio.app/Contents/jbr/Contents/Home
18
+ - /Applications/Android Studio Preview.app/Contents/jbr/Contents/Home
19
+ 3. Explicit JAVA_HOME (validate via `java -version`)
20
+ 4. macOS `/usr/libexec/java_home -v 17` or `-v 21`
21
+ 5. Common Linux JDK locations: `/usr/lib/jvm/*temurin*`, `/usr/lib/jvm/*zulu*`
22
+
23
+ Validation rules
24
+ - Accept only Java 17 or Java 21 for Gradle builds in this project (both tested/known working).
25
+ - Reject GraalVM / Java 23 that causes Gradle jlink errors. If detected, return suggestion: "Prefer an Apple/Temurin/JBR Java 17 or 21. Set ANDROID_STUDIO_JBR or JAVA_HOME to a supported JDK."
26
+
27
+ ADB resolution precedence
28
+ 1. process.env.ADB_PATH (explicit)
29
+ 2. ANDROID_SDK_ROOT or ANDROID_HOME -> platform-tools/adb
30
+ 3. Common SDK locations (macOS/Linux): $HOME/Library/Android/sdk/platform-tools, /opt/android-sdk/platform-tools
31
+ 4. `command -v adb` / `which adb` on PATH
32
+ 5. fallback to `adb` (best-effort)
33
+
34
+ IDB / XCRUN detection (iOS)
35
+ - IDB: check MCP_IDB_PATH -> IDB_PATH -> common locations (/opt/homebrew/bin/idb, /usr/local/bin/idb, $HOME/Library/Python/*/bin/idb). Validate by running `idb --version` or `idb list-targets --json`.
36
+ - XCRUN: check XCRUN_PATH -> run `xcrun --version`.
37
+
38
+ How to probe (commands)
39
+ - adb: `adb --version` and `adb devices --print` (or `adb devices -l`) to list.
40
+ - java: `java -XshowSettings:properties -version` or `java -version` parse first line.
41
+ - xcrun: `xcrun --version`
42
+ - idb: `idb --version` or `idb list-targets --json`
43
+
44
+ Output format
45
+ - Each probe returns { name, cmd, ok, version?, suggestion? } so agents can reason programmatically.
46
+ - Include env snapshot (PATH, JAVA_HOME, ADB_PATH, ANDROID_SDK_ROOT, IDB_PATH, XCRUN_PATH) to aid diagnostics.
47
+
48
+ Notes & rationale
49
+ - Prefer Android Studio JBR (JBR is bundled & known-good) because developer machines often have mismatched system JDKs (e.g., Graal). Allow override via env for CI.
50
+ - For long-running server processes, prepend java/bin and platform-tools to spawn env PATH when running child builds so external PATH/JAVA_HOME changes don't require a server restart.
51
+
52
+ Examples
53
+ - Detected result (JSON):
54
+ {
55
+ "name": "adb",
56
+ "cmd": "/Users/xxx/Library/Android/sdk/platform-tools/adb",
57
+ "ok": true,
58
+ "version": "Android Debug Bridge version 1.0.41"
59
+ }
60
+
61
+ - Java suggestion when incompatible:
62
+ { "name": "java", "ok": false, "suggestion": "Found GraalVM (Java 23). Use Java 17 or 21: set ANDROID_STUDIO_JBR or JAVA_HOME." }
package/src/server.ts CHANGED
@@ -21,6 +21,9 @@ import { ToolsObserve } from './observe/index.js'
21
21
  import { AndroidManage } from './manage/index.js'
22
22
  import { iOSManage } from './manage/index.js'
23
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'
24
27
 
25
28
 
26
29
  const server = new Server(
@@ -48,6 +51,30 @@ const server = new Server(
48
51
  console.warn('[startup] error during adb healthcheck:', String(e))
49
52
  }
50
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
+ }
77
+
51
78
  })()
52
79
 
53
80
  function wrapResponse<T>(data: T) {
@@ -62,11 +62,12 @@ export async function isIDBInstalled(): Promise<boolean> {
62
62
  try {
63
63
  execSync(`command -v ${cmd}`, { stdio: ['ignore','pipe','ignore'] })
64
64
  return true
65
- } catch {
65
+ } catch (e: unknown) {
66
66
  try {
67
67
  execSync(`${cmd} list-targets --json`, { stdio: ['ignore','pipe','ignore'], timeout: 2000 })
68
68
  return true
69
- } catch {
69
+ } catch (e2: unknown) {
70
+ console.debug(`[isIDBInstalled] idb presence check failed for '${cmd}': ${e instanceof Error ? e.message : String(e2)}`)
70
71
  return false
71
72
  }
72
73
  }