Skip to main content
Glama

flutter_clean

Clean Flutter build cache and generated files to resolve project issues and free up disk space by specifying the Flutter project directory.

Instructions

Clean Flutter build cache and generated files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYesWorking directory (Flutter project root)

Implementation Reference

  • The handler function for the flutter_clean tool. It validates the input arguments using the FlutterCleanSchema, ensures the cwd is a valid Flutter project, executes the 'flutter clean' command with a 2-minute timeout, and returns structured results including success status, project path, exit code, stdout, and duration.
    handler: async (args: any) => { const validation = FlutterCleanSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const result = await processExecutor.execute('flutter', ['clean'], { cwd, timeout: 120000, // 2 minutes timeout for clean }); return { success: true, data: { projectPath: cwd, exitCode: result.exitCode, output: result.stdout, duration: result.duration, }, }; }
  • Zod validation schema defining the input for flutter_clean: requires a 'cwd' string (minimum length 1) for the Flutter project working directory.
    const FlutterCleanSchema = z.object({ cwd: z.string().min(1), });
  • Tool registration within createFlutterTools function: registers 'flutter_clean' in the tools Map with name, description, JSON inputSchema equivalent to Zod schema, and references the handler function.
    // Flutter Clean - Clean build cache tools.set('flutter_clean', { name: 'flutter_clean', description: 'Clean Flutter build cache and generated files', inputSchema: { type: 'object', properties: { cwd: { type: 'string', minLength: 1, description: 'Working directory (Flutter project root)' } }, required: ['cwd'] }, handler: async (args: any) => { const validation = FlutterCleanSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const result = await processExecutor.execute('flutter', ['clean'], { cwd, timeout: 120000, // 2 minutes timeout for clean }); return { success: true, data: { projectPath: cwd, exitCode: result.exitCode, output: result.stdout, duration: result.duration, }, }; } });
  • Supporting helper function validateFlutterProject used by the flutter_clean handler to verify that the provided cwd directory is a valid Flutter project by checking for pubspec.yaml with 'flutter:' section.
    const validateFlutterProject = async (cwd: string): Promise<void> => { const pubspecPath = path.join(cwd, 'pubspec.yaml'); try { await fs.access(pubspecPath); const pubspecContent = await fs.readFile(pubspecPath, 'utf8'); if (!pubspecContent.includes('flutter:')) { throw new Error(`Directory does not appear to be a Flutter project. No flutter section found in ${pubspecPath}`); } } catch { throw new Error(`pubspec.yaml not found. Flutter project must contain pubspec.yaml at: ${pubspecPath}`); } };
  • Usage of flutter_clean tool within the flutter_fix_common_issues super-tool handler as the first step in auto-fixing common Flutter issues.
    const cleanResult = await flutterTools.get('flutter_clean').handler({ cwd: args.cwd }); fixes.push({ step: 'flutter_clean', ...cleanResult });

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/cristianoaredes/mcp-mobile-server'

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