mobile-debug-mcp 0.3.0 → 0.5.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/.github/copilot-instructions.md +33 -0
- package/README.md +142 -25
- package/dist/android.js +174 -32
- package/dist/ios.js +203 -14
- package/dist/server.js +262 -20
- package/dist/types.js +1 -0
- package/docs/CHANGELOG.md +23 -0
- package/package.json +8 -2
- package/smoke-test.js +102 -0
- package/smoke-test.ts +115 -0
- package/src/android.ts +205 -31
- package/src/ios.ts +234 -16
- package/src/server.ts +304 -24
- package/src/types.ts +58 -0
- package/tsconfig.json +2 -1
package/dist/ios.js
CHANGED
|
@@ -1,21 +1,210 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { execFile, spawn } from "child_process";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
const XCRUN = process.env.XCRUN_PATH || "xcrun";
|
|
4
|
+
// Validate bundle ID to prevent any potential injection or invalid characters
|
|
5
|
+
function validateBundleId(bundleId) {
|
|
6
|
+
if (!bundleId)
|
|
7
|
+
return;
|
|
8
|
+
// Allow alphanumeric, dots, hyphens, and underscores.
|
|
9
|
+
if (!/^[a-zA-Z0-9.\-_]+$/.test(bundleId)) {
|
|
10
|
+
throw new Error(`Invalid Bundle ID: ${bundleId}. Must contain only alphanumeric characters, dots, hyphens, or underscores.`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function execCommand(args, deviceId = "booted") {
|
|
3
14
|
return new Promise((resolve, reject) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
// Use spawn for better stream control and consistency with Android implementation
|
|
16
|
+
const child = spawn(XCRUN, args);
|
|
17
|
+
let stdout = '';
|
|
18
|
+
let stderr = '';
|
|
19
|
+
if (child.stdout) {
|
|
20
|
+
child.stdout.on('data', (data) => {
|
|
21
|
+
stdout += data.toString();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (child.stderr) {
|
|
25
|
+
child.stderr.on('data', (data) => {
|
|
26
|
+
stderr += data.toString();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const timeoutMs = args.includes('log') ? 10000 : 5000; // 10s for logs, 5s for others
|
|
30
|
+
const timeout = setTimeout(() => {
|
|
31
|
+
child.kill();
|
|
32
|
+
reject(new Error(`Command timed out after ${timeoutMs}ms: ${XCRUN} ${args.join(' ')}`));
|
|
33
|
+
}, timeoutMs);
|
|
34
|
+
child.on('close', (code) => {
|
|
35
|
+
clearTimeout(timeout);
|
|
36
|
+
if (code !== 0) {
|
|
37
|
+
reject(new Error(stderr.trim() || `Command failed with code ${code}`));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resolve({ output: stdout.trim(), device: { platform: "ios", id: deviceId } });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
child.on('error', (err) => {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
reject(err);
|
|
9
46
|
});
|
|
10
47
|
});
|
|
11
48
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
49
|
+
function parseRuntimeName(runtime) {
|
|
50
|
+
// Example: com.apple.CoreSimulator.SimRuntime.iOS-17-0 -> iOS 17.0
|
|
51
|
+
try {
|
|
52
|
+
const parts = runtime.split('.');
|
|
53
|
+
const lastPart = parts[parts.length - 1];
|
|
54
|
+
return lastPart.replace(/-/g, ' ').replace('iOS ', 'iOS '); // Keep iOS prefix
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return runtime;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export async function getIOSDeviceMetadata(deviceId = "booted") {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
// If deviceId is provided (and not "booted"), we could try to list just that device.
|
|
63
|
+
// But listing all booted devices is usually fine to find the one we want or just one.
|
|
64
|
+
// Let's stick to listing all and filtering if needed, or just return basic info if we can't find it.
|
|
65
|
+
execFile(XCRUN, ['simctl', 'list', 'devices', 'booted', '--json'], (err, stdout) => {
|
|
66
|
+
// Default fallback
|
|
67
|
+
const fallback = {
|
|
68
|
+
platform: "ios",
|
|
69
|
+
id: deviceId,
|
|
70
|
+
osVersion: "Unknown",
|
|
71
|
+
model: "Simulator",
|
|
72
|
+
simulator: true,
|
|
73
|
+
};
|
|
74
|
+
if (err || !stdout) {
|
|
75
|
+
resolve(fallback);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const data = JSON.parse(stdout);
|
|
80
|
+
const devicesMap = data.devices || {};
|
|
81
|
+
// Find the device
|
|
82
|
+
for (const runtime in devicesMap) {
|
|
83
|
+
const devices = devicesMap[runtime];
|
|
84
|
+
if (Array.isArray(devices)) {
|
|
85
|
+
for (const device of devices) {
|
|
86
|
+
if (deviceId === "booted" || device.udid === deviceId) {
|
|
87
|
+
resolve({
|
|
88
|
+
platform: "ios",
|
|
89
|
+
id: device.udid,
|
|
90
|
+
osVersion: parseRuntimeName(runtime),
|
|
91
|
+
model: device.name,
|
|
92
|
+
simulator: true,
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
resolve(fallback);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
resolve(fallback);
|
|
103
|
+
}
|
|
19
104
|
});
|
|
20
105
|
});
|
|
21
106
|
}
|
|
107
|
+
export async function startIOSApp(bundleId, deviceId = "booted") {
|
|
108
|
+
validateBundleId(bundleId);
|
|
109
|
+
const result = await execCommand(['simctl', 'launch', deviceId, bundleId], deviceId);
|
|
110
|
+
const device = await getIOSDeviceMetadata(deviceId);
|
|
111
|
+
// Simulate launch time and appStarted for demonstration
|
|
112
|
+
return {
|
|
113
|
+
device,
|
|
114
|
+
appStarted: !!result.output,
|
|
115
|
+
launchTimeMs: 1000,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export async function terminateIOSApp(bundleId, deviceId = "booted") {
|
|
119
|
+
validateBundleId(bundleId);
|
|
120
|
+
await execCommand(['simctl', 'terminate', deviceId, bundleId], deviceId);
|
|
121
|
+
const device = await getIOSDeviceMetadata(deviceId);
|
|
122
|
+
return {
|
|
123
|
+
device,
|
|
124
|
+
appTerminated: true
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export async function restartIOSApp(bundleId, deviceId = "booted") {
|
|
128
|
+
// terminateIOSApp already validates bundleId
|
|
129
|
+
await terminateIOSApp(bundleId, deviceId);
|
|
130
|
+
const startResult = await startIOSApp(bundleId, deviceId);
|
|
131
|
+
return {
|
|
132
|
+
device: startResult.device,
|
|
133
|
+
appRestarted: startResult.appStarted,
|
|
134
|
+
launchTimeMs: startResult.launchTimeMs
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export async function resetIOSAppData(bundleId, deviceId = "booted") {
|
|
138
|
+
validateBundleId(bundleId);
|
|
139
|
+
await terminateIOSApp(bundleId, deviceId);
|
|
140
|
+
const device = await getIOSDeviceMetadata(deviceId);
|
|
141
|
+
// Get data container path
|
|
142
|
+
const containerResult = await execCommand(['simctl', 'get_app_container', deviceId, bundleId, 'data'], deviceId);
|
|
143
|
+
const dataPath = containerResult.output.trim();
|
|
144
|
+
if (!dataPath) {
|
|
145
|
+
throw new Error(`Could not find data container for ${bundleId}`);
|
|
146
|
+
}
|
|
147
|
+
// Clear contents of Library and Documents
|
|
148
|
+
try {
|
|
149
|
+
const libraryPath = `${dataPath}/Library`;
|
|
150
|
+
const documentsPath = `${dataPath}/Documents`;
|
|
151
|
+
const tmpPath = `${dataPath}/tmp`;
|
|
152
|
+
await fs.rm(libraryPath, { recursive: true, force: true }).catch(() => { });
|
|
153
|
+
await fs.rm(documentsPath, { recursive: true, force: true }).catch(() => { });
|
|
154
|
+
await fs.rm(tmpPath, { recursive: true, force: true }).catch(() => { });
|
|
155
|
+
// Re-create empty directories as they are expected by apps
|
|
156
|
+
await fs.mkdir(libraryPath, { recursive: true }).catch(() => { });
|
|
157
|
+
await fs.mkdir(documentsPath, { recursive: true }).catch(() => { });
|
|
158
|
+
await fs.mkdir(tmpPath, { recursive: true }).catch(() => { });
|
|
159
|
+
return {
|
|
160
|
+
device,
|
|
161
|
+
dataCleared: true
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
throw new Error(`Failed to clear data for ${bundleId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export async function getIOSLogs(appId, deviceId = "booted") {
|
|
169
|
+
// If appId is provided, use predicate filtering
|
|
170
|
+
// Note: execFile passes args directly, so we don't need shell escaping for the predicate string itself,
|
|
171
|
+
// but we do need to construct the predicate correctly for log show.
|
|
172
|
+
const args = ['simctl', 'spawn', deviceId, 'log', 'show', '--style', 'syslog', '--last', '1m'];
|
|
173
|
+
if (appId) {
|
|
174
|
+
validateBundleId(appId);
|
|
175
|
+
args.push('--predicate', `subsystem contains "${appId}" or process == "${appId}"`);
|
|
176
|
+
}
|
|
177
|
+
const result = await execCommand(args, deviceId);
|
|
178
|
+
const device = await getIOSDeviceMetadata(deviceId);
|
|
179
|
+
const logs = result.output ? result.output.split('\n') : [];
|
|
180
|
+
return {
|
|
181
|
+
device,
|
|
182
|
+
logs,
|
|
183
|
+
logCount: logs.length,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export async function captureIOSScreenshot(deviceId = "booted") {
|
|
187
|
+
const device = await getIOSDeviceMetadata(deviceId);
|
|
188
|
+
const tmpFile = `/tmp/mcp-ios-screenshot-${Date.now()}.png`;
|
|
189
|
+
try {
|
|
190
|
+
// 1. Capture screenshot to temp file
|
|
191
|
+
await execCommand(['simctl', 'io', deviceId, 'screenshot', tmpFile], deviceId);
|
|
192
|
+
// 2. Read file as base64
|
|
193
|
+
const buffer = await fs.readFile(tmpFile);
|
|
194
|
+
const base64 = buffer.toString('base64');
|
|
195
|
+
// 3. Clean up
|
|
196
|
+
await fs.rm(tmpFile).catch(() => { });
|
|
197
|
+
return {
|
|
198
|
+
device,
|
|
199
|
+
screenshot: base64,
|
|
200
|
+
// Default resolution since we can't easily parse it without extra libs
|
|
201
|
+
// Clients will read the real dimensions from the PNG header anyway
|
|
202
|
+
resolution: { width: 0, height: 0 },
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
// Ensure cleanup happens even on error
|
|
207
|
+
await fs.rm(tmpFile).catch(() => { });
|
|
208
|
+
throw new Error(`Failed to capture screenshot: ${err instanceof Error ? err.message : String(err)}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import { startAndroidApp, getAndroidLogs } from "./android.js";
|
|
6
|
-
import { startIOSApp, getIOSLogs } from "./ios.js";
|
|
5
|
+
import { startAndroidApp, getAndroidLogs, captureAndroidScreen, getAndroidDeviceMetadata, terminateAndroidApp, restartAndroidApp, resetAndroidAppData } from "./android.js";
|
|
6
|
+
import { startIOSApp, getIOSLogs, captureIOSScreenshot, getIOSDeviceMetadata, terminateIOSApp, restartIOSApp, resetIOSAppData } from "./ios.js";
|
|
7
7
|
const server = new Server({
|
|
8
8
|
name: "mobile-debug-mcp",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.4.0"
|
|
10
10
|
}, {
|
|
11
11
|
capabilities: {
|
|
12
12
|
tools: {}
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
+
function wrapResponse(data) {
|
|
16
|
+
return {
|
|
17
|
+
content: [{
|
|
18
|
+
type: "text",
|
|
19
|
+
text: JSON.stringify(data, null, 2)
|
|
20
|
+
}]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
16
24
|
tools: [
|
|
17
25
|
{
|
|
@@ -24,17 +32,43 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
24
32
|
type: "string",
|
|
25
33
|
enum: ["android", "ios"]
|
|
26
34
|
},
|
|
27
|
-
|
|
35
|
+
appId: {
|
|
28
36
|
type: "string",
|
|
29
37
|
description: "Android package name or iOS bundle id"
|
|
38
|
+
},
|
|
39
|
+
deviceId: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Device UDID (iOS) or Serial (Android). Defaults to booted/connected."
|
|
30
42
|
}
|
|
31
43
|
},
|
|
32
|
-
required: ["platform", "
|
|
44
|
+
required: ["platform", "appId"]
|
|
33
45
|
}
|
|
34
46
|
},
|
|
35
47
|
{
|
|
36
|
-
name: "
|
|
37
|
-
description: "
|
|
48
|
+
name: "terminate_app",
|
|
49
|
+
description: "Terminate a mobile app on Android or iOS simulator",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
platform: {
|
|
54
|
+
type: "string",
|
|
55
|
+
enum: ["android", "ios"]
|
|
56
|
+
},
|
|
57
|
+
appId: {
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Android package name or iOS bundle id"
|
|
60
|
+
},
|
|
61
|
+
deviceId: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Device UDID (iOS) or Serial (Android). Defaults to booted/connected."
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
required: ["platform", "appId"]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "restart_app",
|
|
71
|
+
description: "Restart a mobile app on Android or iOS simulator",
|
|
38
72
|
inputSchema: {
|
|
39
73
|
type: "object",
|
|
40
74
|
properties: {
|
|
@@ -42,16 +76,82 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
42
76
|
type: "string",
|
|
43
77
|
enum: ["android", "ios"]
|
|
44
78
|
},
|
|
45
|
-
|
|
79
|
+
appId: {
|
|
46
80
|
type: "string",
|
|
47
81
|
description: "Android package name or iOS bundle id"
|
|
48
82
|
},
|
|
83
|
+
deviceId: {
|
|
84
|
+
type: "string",
|
|
85
|
+
description: "Device UDID (iOS) or Serial (Android). Defaults to booted/connected."
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
required: ["platform", "appId"]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "reset_app_data",
|
|
93
|
+
description: "Reset app data (clear storage) for a mobile app on Android or iOS simulator",
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: "object",
|
|
96
|
+
properties: {
|
|
97
|
+
platform: {
|
|
98
|
+
type: "string",
|
|
99
|
+
enum: ["android", "ios"]
|
|
100
|
+
},
|
|
101
|
+
appId: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "Android package name or iOS bundle id"
|
|
104
|
+
},
|
|
105
|
+
deviceId: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "Device UDID (iOS) or Serial (Android). Defaults to booted/connected."
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
required: ["platform", "appId"]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "get_logs",
|
|
115
|
+
description: "Get recent logs from Android or iOS simulator. Returns device metadata and the log output.",
|
|
116
|
+
inputSchema: {
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: {
|
|
119
|
+
platform: {
|
|
120
|
+
type: "string",
|
|
121
|
+
enum: ["android", "ios"]
|
|
122
|
+
},
|
|
123
|
+
appId: {
|
|
124
|
+
type: "string",
|
|
125
|
+
description: "Filter by Android package name or iOS bundle id"
|
|
126
|
+
},
|
|
127
|
+
deviceId: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "Device UDID (iOS) or Serial (Android). Defaults to booted/connected."
|
|
130
|
+
},
|
|
49
131
|
lines: {
|
|
50
132
|
type: "number",
|
|
51
133
|
description: "Number of log lines (android only)"
|
|
52
134
|
}
|
|
53
135
|
},
|
|
54
|
-
required: ["platform"
|
|
136
|
+
required: ["platform"]
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "capture_screenshot",
|
|
141
|
+
description: "Capture a screenshot from an Android device or iOS simulator. Returns device metadata and the screenshot image.",
|
|
142
|
+
inputSchema: {
|
|
143
|
+
type: "object",
|
|
144
|
+
properties: {
|
|
145
|
+
platform: {
|
|
146
|
+
type: "string",
|
|
147
|
+
enum: ["android", "ios"]
|
|
148
|
+
},
|
|
149
|
+
deviceId: {
|
|
150
|
+
type: "string",
|
|
151
|
+
description: "Device UDID (iOS) or Serial (Android). Defaults to booted/connected."
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
required: ["platform"]
|
|
55
155
|
}
|
|
56
156
|
}
|
|
57
157
|
]
|
|
@@ -60,21 +160,163 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
60
160
|
const { name, arguments: args } = request.params;
|
|
61
161
|
try {
|
|
62
162
|
if (name === "start_app") {
|
|
63
|
-
const { platform,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
163
|
+
const { platform, appId, deviceId } = args;
|
|
164
|
+
let appStarted;
|
|
165
|
+
let launchTimeMs;
|
|
166
|
+
let deviceInfo;
|
|
167
|
+
if (platform === "android") {
|
|
168
|
+
const result = await startAndroidApp(appId, deviceId);
|
|
169
|
+
appStarted = result.appStarted;
|
|
170
|
+
launchTimeMs = result.launchTimeMs;
|
|
171
|
+
deviceInfo = await getAndroidDeviceMetadata(appId, deviceId);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const result = await startIOSApp(appId, deviceId);
|
|
175
|
+
appStarted = result.appStarted;
|
|
176
|
+
launchTimeMs = result.launchTimeMs;
|
|
177
|
+
deviceInfo = await getIOSDeviceMetadata(deviceId);
|
|
178
|
+
}
|
|
179
|
+
const response = {
|
|
180
|
+
device: deviceInfo,
|
|
181
|
+
appStarted,
|
|
182
|
+
launchTimeMs
|
|
69
183
|
};
|
|
184
|
+
return wrapResponse(response);
|
|
185
|
+
}
|
|
186
|
+
if (name === "terminate_app") {
|
|
187
|
+
const { platform, appId, deviceId } = args;
|
|
188
|
+
let appTerminated;
|
|
189
|
+
let deviceInfo;
|
|
190
|
+
if (platform === "android") {
|
|
191
|
+
const result = await terminateAndroidApp(appId, deviceId);
|
|
192
|
+
appTerminated = result.appTerminated;
|
|
193
|
+
deviceInfo = await getAndroidDeviceMetadata(appId, deviceId);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const result = await terminateIOSApp(appId, deviceId);
|
|
197
|
+
appTerminated = result.appTerminated;
|
|
198
|
+
deviceInfo = await getIOSDeviceMetadata(deviceId);
|
|
199
|
+
}
|
|
200
|
+
const response = {
|
|
201
|
+
device: deviceInfo,
|
|
202
|
+
appTerminated
|
|
203
|
+
};
|
|
204
|
+
return wrapResponse(response);
|
|
205
|
+
}
|
|
206
|
+
if (name === "restart_app") {
|
|
207
|
+
const { platform, appId, deviceId } = args;
|
|
208
|
+
let appRestarted;
|
|
209
|
+
let launchTimeMs;
|
|
210
|
+
let deviceInfo;
|
|
211
|
+
if (platform === "android") {
|
|
212
|
+
const result = await restartAndroidApp(appId, deviceId);
|
|
213
|
+
appRestarted = result.appRestarted;
|
|
214
|
+
launchTimeMs = result.launchTimeMs;
|
|
215
|
+
deviceInfo = await getAndroidDeviceMetadata(appId, deviceId);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const result = await restartIOSApp(appId, deviceId);
|
|
219
|
+
appRestarted = result.appRestarted;
|
|
220
|
+
launchTimeMs = result.launchTimeMs;
|
|
221
|
+
deviceInfo = await getIOSDeviceMetadata(deviceId);
|
|
222
|
+
}
|
|
223
|
+
const response = {
|
|
224
|
+
device: deviceInfo,
|
|
225
|
+
appRestarted,
|
|
226
|
+
launchTimeMs
|
|
227
|
+
};
|
|
228
|
+
return wrapResponse(response);
|
|
229
|
+
}
|
|
230
|
+
if (name === "reset_app_data") {
|
|
231
|
+
const { platform, appId, deviceId } = args;
|
|
232
|
+
let dataCleared;
|
|
233
|
+
let deviceInfo;
|
|
234
|
+
if (platform === "android") {
|
|
235
|
+
const result = await resetAndroidAppData(appId, deviceId);
|
|
236
|
+
dataCleared = result.dataCleared;
|
|
237
|
+
deviceInfo = await getAndroidDeviceMetadata(appId, deviceId);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const result = await resetIOSAppData(appId, deviceId);
|
|
241
|
+
dataCleared = result.dataCleared;
|
|
242
|
+
deviceInfo = await getIOSDeviceMetadata(deviceId);
|
|
243
|
+
}
|
|
244
|
+
const response = {
|
|
245
|
+
device: deviceInfo,
|
|
246
|
+
dataCleared
|
|
247
|
+
};
|
|
248
|
+
return wrapResponse(response);
|
|
70
249
|
}
|
|
71
250
|
if (name === "get_logs") {
|
|
72
|
-
const { platform,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
251
|
+
const { platform, appId, deviceId, lines } = args;
|
|
252
|
+
let logs;
|
|
253
|
+
let deviceInfo;
|
|
254
|
+
if (platform === "android") {
|
|
255
|
+
deviceInfo = await getAndroidDeviceMetadata(appId || "", deviceId);
|
|
256
|
+
const response = await getAndroidLogs(appId, lines ?? 200, deviceId);
|
|
257
|
+
logs = Array.isArray(response.logs) ? response.logs : [];
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
deviceInfo = await getIOSDeviceMetadata(deviceId);
|
|
261
|
+
const response = await getIOSLogs(appId, deviceId);
|
|
262
|
+
logs = Array.isArray(response.logs) ? response.logs : [];
|
|
263
|
+
}
|
|
264
|
+
// Filter crash lines (e.g. lines containing 'FATAL EXCEPTION') for internal or AI use
|
|
265
|
+
const crashLines = logs.filter(line => line.includes('FATAL EXCEPTION'));
|
|
266
|
+
// Return device metadata plus logs
|
|
76
267
|
return {
|
|
77
|
-
content: [
|
|
268
|
+
content: [
|
|
269
|
+
{
|
|
270
|
+
type: "text",
|
|
271
|
+
text: JSON.stringify({
|
|
272
|
+
device: deviceInfo,
|
|
273
|
+
result: {
|
|
274
|
+
lines: logs.length,
|
|
275
|
+
crashLines: crashLines.length > 0 ? crashLines : undefined
|
|
276
|
+
}
|
|
277
|
+
}, null, 2)
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
type: "text",
|
|
281
|
+
text: logs.join("\n")
|
|
282
|
+
}
|
|
283
|
+
]
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
if (name === "capture_screenshot") {
|
|
287
|
+
const { platform, deviceId } = args;
|
|
288
|
+
let screenshot;
|
|
289
|
+
let resolution;
|
|
290
|
+
let deviceInfo;
|
|
291
|
+
if (platform === "android") {
|
|
292
|
+
deviceInfo = await getAndroidDeviceMetadata("", deviceId);
|
|
293
|
+
const result = await captureAndroidScreen(deviceId);
|
|
294
|
+
screenshot = result.screenshot;
|
|
295
|
+
resolution = result.resolution;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
deviceInfo = await getIOSDeviceMetadata(deviceId);
|
|
299
|
+
const result = await captureIOSScreenshot(deviceId);
|
|
300
|
+
screenshot = result.screenshot;
|
|
301
|
+
resolution = result.resolution;
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
content: [
|
|
305
|
+
{
|
|
306
|
+
type: "text",
|
|
307
|
+
text: JSON.stringify({
|
|
308
|
+
device: deviceInfo,
|
|
309
|
+
result: {
|
|
310
|
+
resolution
|
|
311
|
+
}
|
|
312
|
+
}, null, 2)
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
type: "image",
|
|
316
|
+
data: screenshot,
|
|
317
|
+
mimeType: "image/png"
|
|
318
|
+
}
|
|
319
|
+
]
|
|
78
320
|
};
|
|
79
321
|
}
|
|
80
322
|
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the **Mobile Debug MCP** project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.4.0] - 2026-03-09
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **`terminate_app` tool**: Added ability to terminate apps on Android and iOS.
|
|
9
|
+
- **`restart_app` tool**: Added ability to restart apps (terminate + launch) in a single command.
|
|
10
|
+
- **`reset_app_data` tool**: Added ability to clear app data/storage for fresh install testing.
|
|
11
|
+
- **Unified `capture_screenshot` tool**: Replaces `capture_android_screen` and `capture_ios_screenshot` with a single cross-platform tool. Returns both metadata and image data.
|
|
12
|
+
- **Environment Configuration**: Added support for `XCRUN_PATH` to configure iOS tools path (alongside existing `ADB_PATH`).
|
|
13
|
+
- **Smoke Test**: Added `smoke-test.ts` for end-to-end verification of toolchain.
|
|
14
|
+
|
|
15
|
+
### Security
|
|
16
|
+
- **Shell Injection Prevention**: Refactored Android and iOS tools to use `execFile` with argument arrays instead of string concatenation, preventing potential shell injection attacks via malicious app IDs or inputs.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **Response Format**: Updated all tools to return JSON metadata within `text` content blocks (instead of invalid `application/json` type) to comply with MCP spec.
|
|
20
|
+
- **iOS Device Metadata**: `get_logs` and `capture_screenshot` now return real device metadata (OS version, model) from the booted simulator instead of hardcoded values.
|
|
21
|
+
- **Android Logging**: Improved `get_logs` reliability by removing dependency on `pidof` (which caused hangs) and using robust string-based filtering. Added timeouts to prevent infinite hangs.
|
|
22
|
+
- **Docs**: Updated `README.md` with new tools and workflow recommendations.
|
|
23
|
+
- **Docs**: Created `.github/copilot-instructions.md` to assist AI agents.
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobile-debug-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "MCP server for mobile app debugging (Android + iOS), with focus on security and reliability",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"bin": {
|
|
6
7
|
"mobile-debug-mcp": "./dist/server.js"
|
|
@@ -14,6 +15,11 @@
|
|
|
14
15
|
"node": ">=18"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
19
|
+
"zod": "^3.22.4"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^25.4.0",
|
|
23
|
+
"typescript": "^5.9.3"
|
|
18
24
|
}
|
|
19
25
|
}
|