get_single_feature_flag
Retrieve a specific feature flag from the GrowthBook API by providing its unique ID and project details, enabling targeted feature management.
Instructions
Fetches a specific feature flag from the GrowthBook API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the feature flag | |
| project | No |
Implementation Reference
- src/tools/features.ts:283-316 (handler)Handler function that fetches a specific feature flag by ID from the GrowthBook API, processes the response, generates a GrowthBook link, and returns formatted text content including instructions for the user.async ({ id }) => { try { const res = await fetch(`${baseApiUrl}/api/v1/features/${id}`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, }); await handleResNotOk(res); const data = await res.json(); const linkToGrowthBook = generateLinkToGrowthBook( appOrigin, "features", id ); const text = ` ${JSON.stringify(data.feature, null, 2)} Share information about the feature flag with the user. In particular, give details about the enabled environments, rules for each environment, and the default value. If the feature flag is archived or doesnt exist, inform the user and ask if they want to remove references to the feature flag from the codebase. [View it in GrowthBook](${linkToGrowthBook}) `; return { content: [{ type: "text", text }], }; } catch (error) { throw new Error(`Error fetching flags: ${error}`); } }
- src/utils.ts:240-263 (schema)Zod schema definition for feature flag properties, including 'id' used as input schema for the get_single_feature_flag tool.export const featureFlagSchema = { id: z .string() .regex( /^[a-zA-Z0-9_.:|_-]+$/, "Feature key can only include letters, numbers, and the characters _, -, ., :, and |" ) .describe("A unique key name for the feature"), valueType: z .enum(["string", "number", "boolean", "json"]) .describe("The value type the feature flag will return"), defaultValue: z.string().describe("The default value of the feature flag"), description: z.string().describe("A brief description of the feature flag"), archived: z.boolean().describe("Whether the feature flag should be archived"), project: z .string() .describe("The ID of the project to which the feature flag belongs"), // Contextual info fileExtension: z .enum(SUPPORTED_FILE_EXTENSIONS) .describe( "The extension of the current file. If it's unclear, ask the user." ), } as const;
- src/tools/features.ts:274-317 (registration)Registration of the get_single_feature_flag tool using server.tool, including description, input schema, options, and handler reference.server.tool( "get_single_feature_flag", "Fetches a specific feature flag from the GrowthBook API", { id: featureFlagSchema.id, }, { readOnlyHint: true, }, async ({ id }) => { try { const res = await fetch(`${baseApiUrl}/api/v1/features/${id}`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, }); await handleResNotOk(res); const data = await res.json(); const linkToGrowthBook = generateLinkToGrowthBook( appOrigin, "features", id ); const text = ` ${JSON.stringify(data.feature, null, 2)} Share information about the feature flag with the user. In particular, give details about the enabled environments, rules for each environment, and the default value. If the feature flag is archived or doesnt exist, inform the user and ask if they want to remove references to the feature flag from the codebase. [View it in GrowthBook](${linkToGrowthBook}) `; return { content: [{ type: "text", text }], }; } catch (error) { throw new Error(`Error fetching flags: ${error}`); } } );
- src/index.ts:81-87 (registration)Top-level registration call to registerFeatureTools which includes the get_single_feature_flag tool among others.registerFeatureTools({ server, baseApiUrl, apiKey, appOrigin, user, });