Skip to main content
Glama

swift_package_test

Run tests for Swift packages using specified configurations, filters, and parallel execution, with optional code coverage and @main support via XcodeBuildMCP.

Instructions

Runs tests for a Swift Package with swift test

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
configurationNoSwift package configuration (debug, release)
filterNoFilter tests by name (regex pattern)
packagePathYesPath to the Swift package root (Required)
parallelNoRun tests in parallel (default: true)
parseAsLibraryNoAdd -parse-as-library flag for @main support (default: false)
showCodecovNoShow code coverage (default: false)
testProductNoOptional specific test product to run

Implementation Reference

  • Main handler function that constructs and executes the 'swift test' command with provided parameters, handles errors, and returns formatted responses.
    export async function swift_package_testLogic(
      params: SwiftPackageTestParams,
      executor: CommandExecutor,
    ): Promise<ToolResponse> {
      const resolvedPath = path.resolve(params.packagePath);
      const swiftArgs = ['test', '--package-path', resolvedPath];
    
      if (params.configuration && params.configuration.toLowerCase() === 'release') {
        swiftArgs.push('-c', 'release');
      } else if (params.configuration && params.configuration.toLowerCase() !== 'debug') {
        return createTextResponse("Invalid configuration. Use 'debug' or 'release'.", true);
      }
    
      if (params.testProduct) {
        swiftArgs.push('--test-product', params.testProduct);
      }
    
      if (params.filter) {
        swiftArgs.push('--filter', params.filter);
      }
    
      if (params.parallel === false) {
        swiftArgs.push('--no-parallel');
      }
    
      if (params.showCodecov) {
        swiftArgs.push('--show-code-coverage');
      }
    
      if (params.parseAsLibrary) {
        swiftArgs.push('-Xswiftc', '-parse-as-library');
      }
    
      log('info', `Running swift ${swiftArgs.join(' ')}`);
      try {
        const result = await executor(['swift', ...swiftArgs], 'Swift Package Test', true, undefined);
        if (!result.success) {
          const errorMessage = result.error ?? result.output ?? 'Unknown error';
          return createErrorResponse('Swift package tests failed', errorMessage);
        }
    
        return {
          content: [
            { type: 'text', text: '✅ Swift package tests completed.' },
            {
              type: 'text',
              text: '💡 Next: Execute your app with swift_package_run if tests passed',
            },
            { type: 'text', text: result.output },
          ],
          isError: false,
        };
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        log('error', `Swift package test failed: ${message}`);
        return createErrorResponse('Failed to execute swift test', message);
      }
    }
  • Zod schema defining input parameters for the swift_package_test tool.
    const swiftPackageTestSchema = z.object({
      packagePath: z.string().describe('Path to the Swift package root (Required)'),
      testProduct: z.string().optional().describe('Optional specific test product to run'),
      filter: z.string().optional().describe('Filter tests by name (regex pattern)'),
      configuration: z
        .enum(['debug', 'release'])
        .optional()
        .describe('Swift package configuration (debug, release)'),
      parallel: z.boolean().optional().describe('Run tests in parallel (default: true)'),
      showCodecov: z.boolean().optional().describe('Show code coverage (default: false)'),
      parseAsLibrary: z
        .boolean()
        .optional()
        .describe('Add -parse-as-library flag for @main support (default: false)'),
    });
  • Tool registration exporting the name, description, schema, and handler created with createTypedTool.
    export default {
      name: 'swift_package_test',
      description: 'Runs tests for a Swift Package with swift test',
      schema: swiftPackageTestSchema.shape, // MCP SDK compatibility
      handler: createTypedTool(
        swiftPackageTestSchema,
        swift_package_testLogic,
        getDefaultCommandExecutor,
      ),
    };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Runs tests' implies execution and potential side effects, it doesn't disclose important behavioral traits like whether tests run in a sandbox, if they modify the package, what happens on test failure, expected runtime, or output format. The description is minimal and lacks the context needed for safe, informed tool invocation.

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 ('Runs tests for a Swift Package') and includes the exact command ('swift test') for clarity. Every element earns its place, making it appropriately sized for a tool with comprehensive schema documentation.

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?

For a tool with 7 parameters, no annotations, and no output schema, the description is insufficiently complete. While the schema covers parameters well, the description lacks crucial context about what the tool actually does behaviorally, what output to expect, error conditions, or how it integrates with the testing workflow. Given the complexity and absence of structured behavioral hints, more descriptive context is needed.

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?

With 100% schema description coverage, the schema already documents all 7 parameters thoroughly. The description adds no parameter information beyond what's in the schema, so it meets the baseline of 3. It doesn't provide additional context about parameter interactions, default behaviors beyond schema defaults, or usage examples that would enhance understanding.

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

Purpose5/5

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

The description clearly states the specific action ('Runs tests') and resource ('for a Swift Package') using the exact command 'swift test'. It distinguishes itself from sibling tools like swift_package_build, swift_package_run, and test_* tools by focusing exclusively on Swift Package testing rather than building, running, or testing other project types.

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

Usage Guidelines3/5

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

The description implies usage context (testing Swift Packages) but doesn't explicitly state when to use this tool versus alternatives like test_device_proj or test_sim_id_proj. It differentiates from swift_package_build and swift_package_run by function, but lacks explicit guidance on when testing is preferred over other verification methods or which sibling tools are complementary.

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

Related 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/getsentry/XcodeBuildMCP'

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