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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but provides minimal behavioral context. It doesn't disclose whether this is a read-only operation, what permissions are needed, how it handles errors, or the format/structure of the returned information. The description is too vague to guide safe or effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It front-loads the core purpose and includes key details without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that retrieves information. It doesn't explain what 'information' includes beyond names/identifiers, how results are structured, or potential limitations, leaving significant gaps for an AI agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents the single parameter. The description adds no additional meaning about the parameter beyond what the schema provides (e.g., no examples or edge cases), meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get information about') and resource ('test targets in a project'), specifying the type of information returned ('names and identifiers'). It distinguishes from siblings like 'xcode_get_projects' or 'xcode_get_schemes' by focusing on test targets, but doesn't explicitly contrast with them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an open project), exclusions, or compare to siblings like 'xcode_test' or 'xcode_get_schemes' for related functionality.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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