Skip to main content
Glama

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
NameRequiredDescriptionDefault
xcodeprojYesAbsolute path to the .xcodeproj file (or .xcworkspace if available)

Implementation Reference

  • 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}` }] }; } }
  • Tool dispatch/registration in the main MCP CallToolRequestSchema switch statement, calling ProjectTools.getTestTargets
    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);
  • 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'], }, },
  • 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);

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/lapfelix/XcodeMCP'

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