MCPcopy Create free account
hub / github.com/getsentry/XcodeBuildMCP / determineSimulatorUuid

Function determineSimulatorUuid

src/utils/simulator-utils.ts:43–121  ·  view source on GitHub ↗
(
  params: { simulatorUuid?: string; simulatorId?: string; simulatorName?: string },
  executor: CommandExecutor,
)

Source from the content-addressed store, hash-verified

41}
42
43export async function determineSimulatorUuid(
44 params: { simulatorUuid?: string; simulatorId?: string; simulatorName?: string },
45 executor: CommandExecutor,
46): Promise<{ uuid?: string; warning?: string; error?: string }> {
47 const directUuid = params.simulatorUuid ?? params.simulatorId;
48
49 if (directUuid) {
50 log('info', `Using provided simulator UUID: ${directUuid}`);
51 return { uuid: directUuid };
52 }
53
54 if (params.simulatorName) {
55 if (UUID_REGEX.test(params.simulatorName)) {
56 log(
57 'info',
58 `Simulator name '${params.simulatorName}' appears to be a UUID, using it directly`,
59 );
60 return {
61 uuid: params.simulatorName,
62 warning: `The simulatorName '${params.simulatorName}' appears to be a UUID. Consider using simulatorUuid parameter instead.`,
63 };
64 }
65
66 log('info', `Looking up simulator UUID for name: ${params.simulatorName}`);
67
68 const listResult = await executor(
69 ['xcrun', 'simctl', 'list', 'devices', 'available', '-j'],
70 'List available simulators',
71 );
72
73 if (!listResult.success) {
74 return {
75 error: `Failed to list simulators: ${listResult.error ?? 'Unknown error'}`,
76 };
77 }
78
79 try {
80 interface SimulatorDevice {
81 udid: string;
82 name: string;
83 isAvailable: boolean;
84 }
85
86 interface DevicesData {
87 devices: Record<string, SimulatorDevice[]>;
88 }
89
90 const devicesData = JSON.parse(listResult.output ?? '{}') as DevicesData;
91
92 const allDevices = Object.values(devicesData.devices).filter(Array.isArray).flat();
93
94 const namedDevices = allDevices.filter((d) => d.name === params.simulatorName);
95
96 const availableDevice = namedDevices.find((d) => d.isAvailable);
97 if (availableDevice) {
98 log('info', `Found simulator '${params.simulatorName}' with UUID: ${availableDevice.udid}`);
99 return { uuid: availableDevice.udid };
100 }

Callers 7

install_app_simLogicFunction · 0.90
boot_simLogicFunction · 0.90
launch_app_simLogicFunction · 0.90
stop_app_simLogicFunction · 0.90

Calls 2

logFunction · 0.90
executorFunction · 0.50

Tested by

no test coverage detected