Skip to main content
Glama

flutter_pub_get

Install Flutter project dependencies by running pub get in the specified working directory to resolve and fetch required packages.

Instructions

Install Flutter project dependencies (pub get)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYesWorking directory (Flutter project root)

Implementation Reference

  • The handler function executes the 'flutter pub get' command. It validates the input using FlutterPubGetSchema, ensures the directory is a valid Flutter project, runs the command with a 5-minute timeout, and returns structured results including output, errors, exit code, and duration.
    handler: async (args: any) => { const validation = FlutterPubGetSchema.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', ['pub', 'get'], { cwd, timeout: 300000, // 5 minutes timeout for pub get }); return { success: true, data: { projectPath: cwd, exitCode: result.exitCode, output: result.stdout, errors: result.stderr, duration: result.duration, success: result.exitCode === 0, }, }; }
  • Zod schema for validating the tool's input parameters. Requires a 'cwd' string (working directory of the Flutter project).
    const FlutterPubGetSchema = z.object({ cwd: z.string().min(1), });
  • Registers the 'flutter_pub_get' tool in the tools Map within createFlutterTools function. Includes name, description, JSON inputSchema mirroring the Zod schema, and references the handler function.
    tools.set('flutter_pub_get', { name: 'flutter_pub_get', description: 'Install Flutter project dependencies (pub get)', inputSchema: { type: 'object', properties: { cwd: { type: 'string', minLength: 1, description: 'Working directory (Flutter project root)' } }, required: ['cwd'] }, handler: async (args: any) => { const validation = FlutterPubGetSchema.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', ['pub', 'get'], { cwd, timeout: 300000, // 5 minutes timeout for pub get }); return { success: true, data: { projectPath: cwd, exitCode: result.exitCode, output: result.stdout, errors: result.stderr, duration: result.duration, success: result.exitCode === 0, }, }; } });
  • Helper function used by the handler to validate that the provided cwd is a valid Flutter project by checking for pubspec.yaml with a '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