Skip to main content
Glama

flutter_build

Build Flutter applications for specific platforms like Android, iOS, web, or desktop. Compile projects with configurable modes and flavors to create deployable packages.

Instructions

Build Flutter app for specific target platform

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYesWorking directory (Flutter project root)
targetYesBuild target platform
buildModeNoBuild mode
flavorNoBuild flavor

Implementation Reference

  • The async handler function that implements the core logic of the flutter_build tool: input validation, Flutter project validation, command construction (flutter build [target] [--mode] [--flavor]), execution with 30min timeout, error handling, and structured response.
    handler: async (args: any) => { const validation = FlutterBuildSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, target, buildMode = 'debug', flavor } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['build', target]; if (buildMode !== 'debug') { flutter_args.push(`--${buildMode}`); } if (flavor) { flutter_args.push('--flavor', flavor); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 1800000, // 30 minutes timeout for builds }); if (result.exitCode !== 0) { throw new Error(`Flutter build failed: ${result.stderr || result.stdout}`); } return { success: true, data: { target, buildMode, flavor, projectPath: cwd, output: result.stdout, duration: result.duration, exitCode: result.exitCode, }, }; }
  • Zod input validation schema for the flutter_build tool, defining parameters: cwd (required), target (enum of build targets), buildMode (debug|profile|release, default debug), flavor (optional). Used in handler for safeParse.
    const FlutterBuildSchema = z.object({ cwd: z.string().min(1), target: z.enum(['apk', 'appbundle', 'ipa', 'ios', 'android', 'web', 'windows', 'macos', 'linux']), buildMode: z.enum(['debug', 'profile', 'release']).default('debug'), flavor: z.string().optional(), });
  • Registration of the flutter_build tool in the createFlutterTools Map, including name, description, JSON inputSchema (mirroring Zod schema), and reference to the handler function.
    tools.set('flutter_build', { name: 'flutter_build', description: 'Build Flutter app for specific target platform', inputSchema: { type: 'object', properties: { cwd: { type: 'string', minLength: 1, description: 'Working directory (Flutter project root)' }, target: { type: 'string', enum: ['apk', 'appbundle', 'ipa', 'ios', 'android', 'web', 'windows', 'macos', 'linux'], description: 'Build target platform' }, buildMode: { type: 'string', enum: ['debug', 'profile', 'release'], description: 'Build mode' }, flavor: { type: 'string', description: 'Build flavor' } }, required: ['cwd', 'target'] }, handler: async (args: any) => { const validation = FlutterBuildSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, target, buildMode = 'debug', flavor } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['build', target]; if (buildMode !== 'debug') { flutter_args.push(`--${buildMode}`); } if (flavor) { flutter_args.push('--flavor', flavor); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 1800000, // 30 minutes timeout for builds }); if (result.exitCode !== 0) { throw new Error(`Flutter build failed: ${result.stderr || result.stdout}`); } return { success: true, data: { target, buildMode, flavor, projectPath: cwd, output: result.stdout, duration: result.duration, exitCode: result.exitCode, }, }; } });
  • Shared helper function validateFlutterProject used by flutter_build (and other Flutter tools) to ensure the cwd 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}`); } };

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