generate_flag_types
Create and manage type definitions for feature flags to improve consistency and organization in flag-based development workflows.
Instructions
Generate types for feature flags
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools/features.ts:402-437 (handler)The handler function for the generate_flag_types tool. It runs 'npx growthbook auth login' followed by 'npx growthbook features generate-types' in the specified currentWorkingDirectory to generate TypeScript type definitions for feature flags.async ({ currentWorkingDirectory }) => { function runCommand(command: string, cwd: string): Promise<string> { return new Promise((resolve, reject) => { exec(command, { cwd }, (error, stdout, stderr) => { if (error) { reject(stderr || error.message); } else { resolve(stdout); } }); }); } try { // Login command await runCommand( `npx -y growthbook@latest auth login -k ${apiKey} -u ${baseApiUrl} -p default`, currentWorkingDirectory ); // Generate types command const output = await runCommand( `npx -y growthbook@latest features generate-types -u ${baseApiUrl}`, currentWorkingDirectory ); return { content: [ { type: "text", text: `✅ Types generated successfully:\n${output}`, }, ], }; } catch (error: any) { throw new Error(`Error generating types: ${error}`); } } );
- src/tools/features.ts:393-397 (schema)Zod schema for the tool input, defining the currentWorkingDirectory parameter.{ currentWorkingDirectory: z .string() .describe("The current working directory of the user's project"), },
- src/tools/features.ts:390-437 (registration)Registration of the generate_flag_types tool using server.tool, including description, schema, hints, and handler.server.tool( "generate_flag_types", "Generate types for feature flags", { currentWorkingDirectory: z .string() .describe("The current working directory of the user's project"), }, { readOnlyHint: false, idempotentHint: true, }, async ({ currentWorkingDirectory }) => { function runCommand(command: string, cwd: string): Promise<string> { return new Promise((resolve, reject) => { exec(command, { cwd }, (error, stdout, stderr) => { if (error) { reject(stderr || error.message); } else { resolve(stdout); } }); }); } try { // Login command await runCommand( `npx -y growthbook@latest auth login -k ${apiKey} -u ${baseApiUrl} -p default`, currentWorkingDirectory ); // Generate types command const output = await runCommand( `npx -y growthbook@latest features generate-types -u ${baseApiUrl}`, currentWorkingDirectory ); return { content: [ { type: "text", text: `✅ Types generated successfully:\n${output}`, }, ], }; } catch (error: any) { throw new Error(`Error generating types: ${error}`); } } );