Skip to content

Mobile MCP: let AI agents drive your iOS and Android apps. MCP server for simulators, emulators and real devices. Works with Claude Code, Codex, Cursor and any MCP client.

feat: save_screenshot tool, and use_default_device

Gil Megidishe1647c5d7cc6
diff --git a/src/ios.ts b/src/ios.ts
index 58d1b4e..89297d4 100644
--- a/src/ios.ts
+++ b/src/ios.ts
@@ -208,25 +208,25 @@ export class IosManager {
}
}
- public async getDeviceName(deviceId: string): Promise<string> {
+ public getDeviceName(deviceId: string): string {
const output = execFileSync(getGoIosPath(), ["info", "--udid", deviceId]).toString();
const json: InfoCommandOutput = JSON.parse(output);
return json.DeviceName;
}
- public async listDevices(): Promise<IosDevice[]> {
- if (!(await this.isGoIosInstalled())) {
+ public listDevices(): IosDevice[] {
+ if (!this.isGoIosInstalled()) {
console.error("go-ios is not installed, no physical iOS devices can be detected");
return [];
}
const output = execFileSync(getGoIosPath(), ["list"]).toString();
const json: ListCommandOutput = JSON.parse(output);
- const devices = json.deviceList.map(async device => ({
+ const devices = json.deviceList.map(device => ({
deviceId: device,
- deviceName: await this.getDeviceName(device),
+ deviceName: this.getDeviceName(device),
}));
- return Promise.all(devices);
+ return devices;
}
}
diff --git a/src/server.ts b/src/server.ts
index 2661970..92bd184 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -1,6 +1,7 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { z, ZodRawShape, ZodTypeAny } from "zod";
+import * as fs from "fs";
import { error, trace } from "./logger";
import { AndroidRobot, AndroidDeviceManager } from "./android";
@@ -44,6 +45,7 @@ export const createMcpServer = (): McpServer => {
},
});
+ // an empty object to satisfy windsurf
const noParams = z.object({});
const tool = (name: string, description: string, paramsSchema: ZodRawShape, cb: (args: z.objectOutputType<ZodRawShape, ZodTypeAny>) => Promise<string>) => {
@@ -83,6 +85,43 @@ export const createMcpServer = (): McpServer => {
}
};
+ tool(
+ "mobile_use_default_device",
+ "Use the default device. This is a shortcut for mobile_use_device with deviceType=simulator and device=simulator_name",
+ {
+ noParams
+ },
+ async () => {
+ const iosManager = new IosManager();
+ const androidManager = new AndroidDeviceManager();
+ const simulators = simulatorManager.listBootedSimulators();
+ const androidDevices = androidManager.getConnectedDevices();
+ const iosDevices = iosManager.listDevices();
+
+ const sum = simulators.length + androidDevices.length + iosDevices.length;
+ if (sum === 0) {
+ throw new ActionableError("No devices found. Please connect a device and try again.");
+ } else if (sum >= 2) {
+ throw new ActionableError("Multiple devices found. Please use the mobile_list_available_devices tool to list available devices and select one.");
+ }
+
+ // only one device connected, let's find it now
+ if (simulators.length === 1) {
+ robot = simulatorManager.getSimulator(simulators[0].name);
+ return `Selected default device: ${simulators[0].name}`;
+ } else if (androidDevices.length === 1) {
+ robot = new AndroidRobot(androidDevices[0].deviceId);
+ return `Selected default device: ${androidDevices[0].deviceId}`;
+ } else if (iosDevices.length === 1) {
+ robot = new IosRobot(iosDevices[0].deviceId);
+ return `Selected default device: ${iosDevices[0].deviceId}`;
+ }
+
+ // how did this happen?
+ throw new ActionableError("No device selected. Please use the mobile_list_available_devices tool to list available devices and select one.");
+ }
+ );
+
tool(
"mobile_list_available_devices",
"List all available devices. This includes both physical devices and simulators. If there is more than one device returned, you need to let the user select one of them.",
@@ -92,8 +131,8 @@ export const createMcpServer = (): McpServer => {
async ({}) => {
const iosManager = new IosManager();
const androidManager = new AndroidDeviceManager();
- const devices = simulatorManager.listBootedSimulators();
- const simulatorNames = devices.map(d => d.name);
+ const simulators = simulatorManager.listBootedSimulators();
+ const simulatorNames = simulators.map(d => d.name);
const androidDevices = androidManager.getConnectedDevices();
const iosDevices = await iosManager.listDevices();
const iosDeviceNames = iosDevices.map(d => d.deviceId);
@@ -318,6 +357,21 @@ export const createMcpServer = (): McpServer => {
}
);
+ tool(
+ "mobile_save_screenshot",
+ "Save a screenshot of the mobile device to a file",
+ {
+ saveTo: z.string().describe("The path to save the screenshot to"),
+ },
+ async ({ saveTo }) => {
+ requireRobot();
+
+ const screenshot = await robot!.getScreenshot();
+ fs.writeFileSync(saveTo, screenshot);
+ return `Screenshot saved to: ${saveTo}`;
+ }
+ );
+
server.tool(
"mobile_take_screenshot",
"Take a screenshot of the mobile device. Use this to understand what's on screen, if you need to press an element that is available through view hierarchy then you must list elements on screen instead. Do not cache this result.",