getFeatureFlag
Retrieve a specific feature flag by ID to manage feature rollouts and toggle functionality in your application based on environment and version requirements.
Instructions
Get a specific feature flag by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environmentId | No | Environment ID (uses default if not provided) | |
| featureVersion | No | Specific version of the feature to retrieve | |
| id | Yes | The ID of the feature flag to retrieve |
Implementation Reference
- src/tools/get-flag.ts:37-119 (handler)The handler function that executes the getFeatureFlag tool logic: validates input using Zod schema, initializes Bucketeer API client using config, prepares the request, calls the getFeature API, logs the result, and returns a structured MCP response (success with feature data or error).handler: async (input: unknown) => { try { // Validate input const params = getFlagSchema.parse(input); logger.debug("Getting feature flag", params); // Create API client const client = new BucketeerClient( config.bucketeerHost, config.bucketeerApiKey, ); // Prepare request const request: GetFeatureRequest = { id: params.id, environmentId: getEnvironmentId(params.environmentId), featureVersion: params.featureVersion, }; // Make API call const response = await client.getFeature(request); logger.info( `Successfully retrieved feature flag: ${response.feature.id}`, ); return { content: [ { type: "text", text: JSON.stringify( { success: true, feature: response.feature, }, null, 2, ), }, ], }; } catch (error) { logger.error("Failed to get feature flag", error); if (error instanceof z.ZodError) { return { content: [ { type: "text", text: JSON.stringify( { success: false, error: "Invalid input parameters", details: error.issues, }, null, 2, ), }, ], isError: true, }; } return { content: [ { type: "text", text: JSON.stringify( { success: false, error: error instanceof Error ? error.message : "Unknown error", }, null, 2, ), }, ], isError: true, }; } },
- src/tools/get-flag.ts:8-12 (schema)Zod input schema for validating the parameters of the getFeatureFlag tool: requires 'id', optional 'environmentId' and 'featureVersion'.export const getFlagSchema = z.object({ id: z.string().min(1, "Feature flag ID is required"), environmentId: z.string().optional(), featureVersion: z.number().optional(), });
- src/tools/index.ts:7-13 (registration)Registration of the getFlagTool (which defines getFeatureFlag) in the central tools array exported from src/tools/index.ts, making it available for MCP server usage.export const tools = [ listFlagsTool, createFlagTool, getFlagTool, updateFlagTool, archiveFlagTool, ];
- src/tools/get-flag.ts:19-36 (schema)JSON Schema definition for the input of getFeatureFlag tool, used in the tool registration object for MCP protocol compliance.inputSchema: { type: "object" as const, properties: { id: { type: "string", description: "The ID of the feature flag to retrieve", }, environmentId: { type: "string", description: "Environment ID (uses default if not provided)", }, featureVersion: { type: "number", description: "Specific version of the feature to retrieve", }, }, required: ["id"], },
- src/tools/index.ts:3-3 (registration)Import of the getFlagTool from its implementation file in the tools index.import { getFlagTool } from "./get-flag.js";