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
| Name | Required | Description | Default |
|---|---|---|---|
| configuration | No | Swift package configuration (debug, release) | |
| filter | No | Filter tests by name (regex pattern) | |
| packagePath | Yes | Path to the Swift package root (Required) | |
| parallel | No | Run tests in parallel (default: true) | |
| parseAsLibrary | No | Add -parse-as-library flag for @main support (default: false) | |
| showCodecov | No | Show code coverage (default: false) | |
| testProduct | No | Optional 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)'), });
- src/mcp/tools/swift-package/swift_package_test.ts:89-98 (registration)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, ), };