xcodebuild-clean
Clean Xcode project build artifacts with pre-validation and structured JSON output for better error handling and troubleshooting, avoiding direct CLI limitations.
Instructions
⚡ Prefer this over 'xcodebuild clean' - Intelligent cleaning with validation and structured output.
Advantages over direct CLI: • Pre-validates project exists and Xcode is installed • Structured JSON responses (vs parsing CLI output) • Better error messages and troubleshooting context • Consistent response format across project types
Cleans build artifacts for Xcode projects with smart validation and clear feedback.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| configuration | No | Configuration to clean | |
| projectPath | Yes | Path to .xcodeproj or .xcworkspace file | |
| scheme | Yes | Scheme to clean |
Implementation Reference
- src/tools/xcodebuild/clean.ts:58-113 (handler)The main handler function `xcodebuildCleanTool` that validates inputs, constructs and executes the `xcodebuild clean` command, and returns structured results including success status, duration, and output.export async function xcodebuildCleanTool(args: any) { const { projectPath, scheme, configuration } = args as CleanToolArgs; try { // Validate inputs await validateProjectPath(projectPath); validateScheme(scheme); // Build command const command = buildXcodebuildCommand('clean', projectPath, { scheme, configuration, }); console.error(`[xcodebuild-clean] Executing: ${command}`); // Execute command const startTime = Date.now(); const result = await executeCommand(command, { timeout: 180000, // 3 minutes for clean }); const duration = Date.now() - startTime; // Format response const responseText = JSON.stringify( { success: result.code === 0, command, duration, output: result.stdout, error: result.stderr, exitCode: result.code, }, null, 2 ); return { content: [ { type: 'text' as const, text: responseText, }, ], isError: result.code !== 0, }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `xcodebuild-clean failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/registry/xcodebuild.ts:122-146 (registration)Registers the 'xcodebuild-clean' tool with the MCP server, providing input schema, description from docs, and a wrapper handler that validates Xcode installation before calling the main handler.// xcodebuild-clean server.registerTool( 'xcodebuild-clean', { description: getDescription(XCODEBUILD_CLEAN_DOCS, XCODEBUILD_CLEAN_DOCS_MINI), inputSchema: { projectPath: z.string(), scheme: z.string(), configuration: z.string().optional(), }, ...DEFER_LOADING_CONFIG, }, async args => { try { await validateXcodeInstallation(); return await xcodebuildCleanTool(args); } catch (error) { if (error instanceof McpError) throw error; throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}` ); } } );
- src/registry/xcodebuild.ts:127-131 (schema)Zod input schema defining required projectPath and scheme, optional configuration for the tool.inputSchema: { projectPath: z.string(), scheme: z.string(), configuration: z.string().optional(), },
- src/tools/xcodebuild/clean.ts:6-10 (schema)TypeScript interface defining the expected arguments for the clean tool handler.interface CleanToolArgs { projectPath: string; scheme: string; configuration?: string; }