set_network_condition
Simulate specific network conditions (e.g., wifi, 3g, high-latency) in simulators to test application performance under varying connectivity scenarios.
Instructions
Simulates different network conditions (e.g., wifi, 3g, edge, high-latency, dsl, 100%loss, 3g-lossy, very-lossy) in the simulator.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| profile | Yes | The network profile to simulate. Must be one of: wifi, 3g, edge, high-latency, dsl, 100%loss, 3g-lossy, very-lossy. | |
| simulatorUuid | Yes | UUID of the simulator to use (obtained from list_simulators) |
Implementation Reference
- src/tools/simulator.ts:656-686 (handler)Registers the 'set_network_condition' tool and defines its handler. The handler logs the action, then calls executeSimctlCommandAndRespond to run 'xcrun simctl status_bar <simulatorUuid> override --dataNetwork <profile>' and handles the response.export function registerSetNetworkConditionTool(server: McpServer): void { server.tool( 'set_network_condition', 'Simulates different network conditions (e.g., wifi, 3g, edge, high-latency, dsl, 100%loss, 3g-lossy, very-lossy) in the simulator.', { simulatorUuid: z .string() .describe('UUID of the simulator to use (obtained from list_simulators)'), profile: z .enum(['wifi', '3g', 'edge', 'high-latency', 'dsl', '100%loss', '3g-lossy', 'very-lossy']) .describe( 'The network profile to simulate. Must be one of: wifi, 3g, edge, high-latency, dsl, 100%loss, 3g-lossy, very-lossy.', ), }, async (params: { simulatorUuid: string; profile: string }): Promise<ToolResponse> => { log( 'info', `Setting simulator ${params.simulatorUuid} network condition to ${params.profile}`, ); return executeSimctlCommandAndRespond( params, ['status_bar', params.simulatorUuid, 'override', '--dataNetwork', params.profile], 'Set Network Condition', `Successfully set simulator ${params.simulatorUuid} network condition to ${params.profile} profile`, 'Failed to set network condition', 'set network condition', ); }, ); }
- src/tools/simulator.ts:660-669 (schema)Input schema using Zod: simulatorUuid (required string), profile (required enum: ['wifi', '3g', 'edge', 'high-latency', 'dsl', '100%loss', '3g-lossy', 'very-lossy']).{ simulatorUuid: z .string() .describe('UUID of the simulator to use (obtained from list_simulators)'), profile: z .enum(['wifi', '3g', 'edge', 'high-latency', 'dsl', '100%loss', '3g-lossy', 'very-lossy']) .describe( 'The network profile to simulate. Must be one of: wifi, 3g, edge, high-latency, dsl, 100%loss, 3g-lossy, very-lossy.', ), },
- src/utils/register-tools.ts:348-352 (registration)Tool registration entry in the toolRegistrations array. Conditionally registers registerSetNetworkConditionTool if environment variable XCODEBUILDMCP_TOOL_SET_NETWORK_CONDITION is set, in the SIMULATOR_MANAGEMENT group.{ register: registerSetNetworkConditionTool, groups: [ToolGroup.SIMULATOR_MANAGEMENT], envVar: 'XCODEBUILDMCP_TOOL_SET_NETWORK_CONDITION', },
- src/tools/simulator.ts:500-557 (helper)Helper function used by the handler to validate parameters, execute the simctl command via executeCommand, handle success/error responses, and log operations.async function executeSimctlCommandAndRespond( params: { simulatorUuid: string; [key: string]: unknown }, simctlSubCommand: string[], operationDescriptionForXcodeCommand: string, successMessage: string, failureMessagePrefix: string, operationLogContext: string, extraValidation?: () => ToolResponse | null, ): Promise<ToolResponse> { const simulatorUuidValidation = validateRequiredParam( 'simulatorUuid', params.simulatorUuid as string, ); if (!simulatorUuidValidation.isValid) { return simulatorUuidValidation.errorResponse!; } if (extraValidation) { const validationResult = extraValidation(); if (validationResult) { return validationResult; } } try { const command = ['xcrun', 'simctl', ...simctlSubCommand]; const result = await executeCommand(command, operationDescriptionForXcodeCommand); if (!result.success) { const fullFailureMessage = `${failureMessagePrefix}: ${result.error}`; log( 'error', `${fullFailureMessage} (operation: ${operationLogContext}, simulator: ${params.simulatorUuid})`, ); return { content: [{ type: 'text', text: fullFailureMessage }], }; } log( 'info', `${successMessage} (operation: ${operationLogContext}, simulator: ${params.simulatorUuid})`, ); return { content: [{ type: 'text', text: successMessage }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); const fullFailureMessage = `${failureMessagePrefix}: ${errorMessage}`; log( 'error', `Error during ${operationLogContext} for simulator ${params.simulatorUuid}: ${errorMessage}`, ); return { content: [{ type: 'text', text: fullFailureMessage }], }; } }