Skip to main content
Glama

mobile_use_default_device

Automate mobile testing by setting the default device to a simulator in Mobile Next MCP. Simplifies device selection for iOS and Android automation tasks.

Instructions

Use the default device. This is a shortcut for mobile_use_device with deviceType=simulator and device=simulator_name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
noParamsYes

Implementation Reference

  • src/server.ts:112-147 (registration)
    Registration of the 'mobile_use_default_device' tool, which uses the 'tool' helper to register an inline handler. The handler checks for exactly one available device (simulator, Android, or iOS) and selects it, throwing actionable errors if none or multiple.
    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."); } );
  • Inline handler function for 'mobile_use_default_device' that lists available devices and sets the robot to the single one found, or throws errors.
    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."); }
  • Shared schema definition 'noParams' used as input schema for 'mobile_use_default_device' (and other tools), defining no parameters.
    const noParams = z.object({});
  • 'tool' helper function used to register all tools, including wrapping the handler with error handling and logging.
    const tool = (name: string, description: string, paramsSchema: ZodRawShape, cb: (args: z.objectOutputType<ZodRawShape, ZodTypeAny>) => Promise<string>) => { const wrappedCb = async (args: ZodRawShape): Promise<CallToolResult> => { try { trace(`Invoking ${name} with args: ${JSON.stringify(args)}`); const response = await cb(args); trace(`=> ${response}`); return { content: [{ type: "text", text: response }], }; } catch (error: any) { if (error instanceof ActionableError) { return { content: [{ type: "text", text: `${error.message}. Please fix the issue and try again.` }], }; } else { // a real exception trace(`Tool '${description}' failed: ${error.message} stack: ${error.stack}`); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } } }; server.tool(name, description, paramsSchema, args => wrappedCb(args));

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/EmpathySlainLovers/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server