clean_project
Remove build caches, DerivedData, and temporary files to resolve project build issues caused by stale data.
Instructions
Clean project build caches, DerivedData, and other temporary files. Helps resolve build issues caused by stale caches.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | Yes | Path to the project root directory | |
| cleanGradle | No | Clean Gradle caches and run gradlew clean (default: true) | |
| cleanDerivedData | No | Clean Xcode DerivedData (default: true) | |
| cleanBuild | No | Clean build directories (default: true) | |
| cleanNodeModules | No | Clean node_modules directory (default: false) | |
| cleanPods | No | Clean CocoaPods Pods directory (default: false) | |
| module | No | Specific Gradle module to clean (e.g., :app) |
Implementation Reference
- Main handler function for the 'clean_project' tool. It validates the project path and conditionally cleans Gradle caches, Xcode DerivedData, build directories, node_modules, and CocoaPods based on input flags, returning a CleanResult.export async function cleanProject(args: CleanProjectArgs): Promise<CleanResult> { const { projectPath, cleanGradle = true, cleanDerivedData = true, cleanBuild = true, cleanNodeModules = false, cleanPods = false, module, } = args; const startTime = Date.now(); const cleaned: CleanResult['cleaned'] = []; const resolvedPath = resolve(projectPath); // Validate project path exists if (!existsSync(resolvedPath)) { return { success: false, cleaned: [{ type: 'validation', path: resolvedPath, success: false, error: 'Project path does not exist', }], durationMs: Date.now() - startTime, }; } // Clean Gradle if (cleanGradle) { const gradleResult = await cleanGradleProject(resolvedPath, module); cleaned.push(...gradleResult); } // Clean Xcode DerivedData if (cleanDerivedData) { const xcodeResult = await cleanXcodeDerivedData(resolvedPath); cleaned.push(...xcodeResult); } // Clean build directories if (cleanBuild) { const buildResult = await cleanBuildDirectories(resolvedPath); cleaned.push(...buildResult); } // Clean node_modules if (cleanNodeModules) { const nodeResult = await cleanNodeModulesDir(resolvedPath); cleaned.push(...nodeResult); } // Clean CocoaPods if (cleanPods) { const podsResult = await cleanCocoaPods(resolvedPath); cleaned.push(...podsResult); } const success = cleaned.every((c) => c.success); return { success, cleaned, durationMs: Date.now() - startTime, }; }
- TypeScript interface defining the input arguments for the clean_project tool handler.export interface CleanProjectArgs { /** Project root path */ projectPath: string; /** Clean Gradle caches (default: true) */ cleanGradle?: boolean; /** Clean Xcode DerivedData (default: true) */ cleanDerivedData?: boolean; /** Clean build directories (default: true) */ cleanBuild?: boolean; /** Clean node_modules (default: false) */ cleanNodeModules?: boolean; /** Clean CocoaPods (default: false) */ cleanPods?: boolean; /** Specific Gradle module to clean */ module?: string; }
- src/tools/environment/clean-project.ts:383-425 (registration)Function that registers the 'clean_project' tool with the global tool registry, providing description, JSON input schema, and binding the cleanProject handler.export function registerCleanProjectTool(): void { getToolRegistry().register( 'clean_project', { description: 'Clean project build caches, DerivedData, and other temporary files. Helps resolve build issues caused by stale caches.', inputSchema: createInputSchema( { projectPath: { type: 'string', description: 'Path to the project root directory', }, cleanGradle: { type: 'boolean', description: 'Clean Gradle caches and run gradlew clean (default: true)', }, cleanDerivedData: { type: 'boolean', description: 'Clean Xcode DerivedData (default: true)', }, cleanBuild: { type: 'boolean', description: 'Clean build directories (default: true)', }, cleanNodeModules: { type: 'boolean', description: 'Clean node_modules directory (default: false)', }, cleanPods: { type: 'boolean', description: 'Clean CocoaPods Pods directory (default: false)', }, module: { type: 'string', description: 'Specific Gradle module to clean (e.g., :app)', }, }, ['projectPath'] ), }, (args) => cleanProject(args as unknown as CleanProjectArgs) ); }
- src/tools/register.ts:149-153 (registration)Central registration point in registerAllTools() where registerCleanProjectTool() is called to register the tool during server startup.const { registerCleanProjectTool } = await import('./environment/clean-project.js'); registerListDevicesTool(); registerManageEnvTool(); registerCleanProjectTool();