xcode_get_test_targets
Extract test target names and identifiers from Xcode projects to automate testing workflows and manage project configurations.
Instructions
Get information about test targets in a project, including names and identifiers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xcodeproj | Yes | Absolute path to the .xcodeproj file (or .xcworkspace if available) |
Implementation Reference
- src/tools/ProjectTools.ts:468-547 (handler)Main handler function that parses project.pbxproj to extract test targets by matching PBXNativeTarget sections with productType containing 'test' or 'xctest'. Returns formatted list of test targets with names, identifiers, and types.public static async getTestTargets(projectPath: string): Promise<McpResult> { try { const { promises: fs } = await import('fs'); // Read the project.pbxproj file const pbxprojPath = `${projectPath}/project.pbxproj`; const projectContent = await fs.readFile(pbxprojPath, 'utf8'); // Parse test targets from the project file const testTargets: Array<{ name: string; identifier: string; productType: string }> = []; // Find PBXNativeTarget sections that are test targets const targetMatches = projectContent.matchAll(/([A-F0-9]{24}) \/\* (.+?) \*\/ = {\s*isa = PBXNativeTarget;[\s\S]*?productType = "([^"]+)";/g); for (const match of targetMatches) { const [, identifier, name, productType] = match; // Only include test targets (with null checks) if (identifier && name && productType && (productType.includes('test') || productType.includes('xctest'))) { testTargets.push({ name: name.trim(), identifier: identifier.trim(), productType: productType.trim() }); } } if (testTargets.length === 0) { return { content: [{ type: 'text', text: `π TEST TARGETS\n\nβ οΈ No test targets found in project.\n\nThis could mean:\n β’ No test targets are configured\n β’ Project file parsing failed\n β’ Test targets use a different naming convention` }] }; } // Helper function to convert product type to human-readable name const getHumanReadableProductType = (productType: string): string => { switch (productType) { case 'com.apple.product-type.bundle.unit-test': return 'Unit Tests'; case 'com.apple.product-type.bundle.ui-testing': return 'UI Tests'; default: return 'Tests'; } }; let message = `π TEST TARGETS\n\n`; message += `Found ${testTargets.length} test target(s):\n\n`; testTargets.forEach((target, index) => { const testType = getHumanReadableProductType(target.productType); message += `${index + 1}. **${target.name}** (${testType})\n\n`; }); message += `π‘ Usage Examples:\n`; if (testTargets.length > 0) { message += ` β’ --test-target-name "${testTargets[0]?.name}"\n\n`; } message += `π Use --test-target-name with the target name for test filtering`; return { content: [{ type: 'text', text: message }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text', text: `Failed to get test targets: ${errorMessage}` }] }; } }
- src/XcodeServer.ts:619-623 (registration)Tool dispatch/registration in the main MCP CallToolRequestSchema switch statement, calling ProjectTools.getTestTargetscase 'xcode_get_test_targets': if (!args.xcodeproj) { throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: xcodeproj`); } return await ProjectTools.getTestTargets(args.xcodeproj as string);
- Tool schema definition including input schema requiring 'xcodeproj' parameter.name: 'xcode_get_test_targets', description: 'Get information about test targets in a project, including names and identifiers', inputSchema: { type: 'object', properties: { xcodeproj: { type: 'string', description: 'Absolute path to the .xcodeproj file (or .xcworkspace if available)', }, }, required: ['xcodeproj'], }, },
- src/XcodeServer.ts:1056-1060 (registration)Duplicate tool dispatch/registration in the callToolDirect method switch statement.case 'xcode_get_test_targets': if (!args.xcodeproj) { throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: xcodeproj`); } return await ProjectTools.getTestTargets(args.xcodeproj as string);