List physical devices and simulators
listTraceDevicesDiscover iOS devices and simulators along with their UDIDs for performance tracing. Run before recording time profiles to automatically select the correct device.
Instructions
[mg.discover] Run xcrun xctrace list devices and return parsed devices/simulators with their UDIDs. The LLM should call this before recordTimeProfile to discover the right UDID without asking the user. Set includeOffline: true to include disconnected devices.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeOffline | No | Include devices listed under "Devices Offline" (default false). |
Implementation Reference
- src/tools/listTraceDevices.ts:62-78 (handler)Main handler: runs `xcrun xctrace list devices`, parses output, optionally filters offline devices, returns list of devices with UDIDs.
export async function listTraceDevices( input: ListTraceDevicesInput, ): Promise<ListTraceDevicesResult> { const result = await runCommand("xcrun", ["xctrace", "list", "devices"], { timeoutMs: 30_000, }); if (result.code !== 0) { throw new Error( `xctrace list devices failed (code ${result.code}): ${result.stderr || result.stdout}`, ); } let devices = parseDeviceListing(result.stdout); if (!input.includeOffline) { devices = devices.filter((d) => d.kind !== "device-offline"); } return { ok: true, devices }; } - src/tools/listTraceDevices.ts:4-9 (schema)Input schema: accepts optional `includeOffline` boolean (default false).
export const listTraceDevicesSchema = z.object({ includeOffline: z .boolean() .default(false) .describe("Include devices listed under \"Devices Offline\" (default false)."), }); - src/tools/listTraceDevices.ts:13-26 (schema)Output types: DeviceKind, TraceDevice interface, and ListTraceDevicesResult interface.
export type DeviceKind = "device" | "device-offline" | "simulator"; export interface TraceDevice { kind: DeviceKind; name: string; /** OS version when the listing carries one (e.g. "26.3.1"). */ osVersion?: string; udid: string; } export interface ListTraceDevicesResult { ok: boolean; devices: TraceDevice[]; } - src/tools/listTraceDevices.ts:38-60 (helper)Pure parser function: parses the raw text output of `xctrace list devices` into structured TraceDevice objects.
export function parseDeviceListing(text: string): TraceDevice[] { const lines = text.split(/\r?\n/); let kind: DeviceKind | null = null; const devices: TraceDevice[] = []; for (const raw of lines) { const line = raw.trim(); if (!line) continue; if (line in SECTION_TO_KIND) { kind = SECTION_TO_KIND[line]; continue; } if (!kind) continue; const m = line.match(LINE_RE); if (!m) continue; devices.push({ kind, name: m[1].trim(), osVersion: m[2], udid: m[3], }); } return devices; } - src/index.ts:249-263 (registration)Registration of the tool 'listTraceDevices' in the MCP server with title, description, input schema, and handler wrapper.
server.registerTool( "listTraceDevices", { title: "List physical devices and simulators", description: "[mg.discover] Run `xcrun xctrace list devices` and return parsed devices/simulators with their UDIDs. The LLM should call this before `recordTimeProfile` to discover the right UDID without asking the user. Set `includeOffline: true` to include disconnected devices.", inputSchema: listTraceDevicesSchema.shape, }, async (input) => { const result = await listTraceDevices(input); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }, );