get_feature_flags
Retrieve all feature flags from the GrowthBook API, sorted by creation date. Configure limit, offset, and project filters to tailor the fetched data to your needs.
Instructions
Fetches all feature flags from the GrowthBook API. Flags are returned in the order they were created, from oldest to newest.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| offset | No | ||
| project | No |
Implementation Reference
- src/tools/features.ts:237-268 (handler)The handler function that implements the logic for fetching feature flags from the GrowthBook API, supporting pagination (limit, offset) and project filtering.async ({ limit, offset, project }) => { try { const queryParams = new URLSearchParams({ limit: limit?.toString(), offset: offset?.toString(), }); if (project) { queryParams.append("projectId", project); } const res = await fetch( `${baseApiUrl}/api/v1/features?${queryParams.toString()}`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, } ); await handleResNotOk(res); const data = await res.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { throw new Error(`Error fetching flags: ${error}`); } }
- src/tools/features.ts:227-269 (registration)The server.tool call that registers the 'get_feature_flags' tool, specifying its name, description, input schema, read-only hint, and handler function.server.tool( "get_feature_flags", "Fetches all feature flags from the GrowthBook API, with optional limit, offset, and project filtering.", { project: featureFlagSchema.project.optional(), ...paginationSchema, }, { readOnlyHint: true, }, async ({ limit, offset, project }) => { try { const queryParams = new URLSearchParams({ limit: limit?.toString(), offset: offset?.toString(), }); if (project) { queryParams.append("projectId", project); } const res = await fetch( `${baseApiUrl}/api/v1/features?${queryParams.toString()}`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, } ); await handleResNotOk(res); const data = await res.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { throw new Error(`Error fetching flags: ${error}`); } } );
- src/utils.ts:218-238 (schema)The paginationSchema defining limit, offset, and mostRecent parameters used in the get_feature_flags tool schema.export const paginationSchema = { limit: z .number() .min(1) .max(100) .default(100) .describe("The number of items to fetch (1-100)"), offset: z .number() .min(0) .default(0) .describe( "The number of items to skip. For example, set to 100 to fetch the second page with default limit. Note: The API returns items in chronological order (oldest first) by default." ), mostRecent: z .boolean() .default(false) .describe( "When true, fetches the most recent items and returns them newest-first. When false (default), returns oldest items first." ), } as const;
- src/utils.ts:254-257 (schema)The 'project' field from featureFlagSchema used optionally in the get_feature_flags tool input schema.project: z .string() .describe("The ID of the project to which the feature flag belongs"), // Contextual info
- src/index.ts:81-87 (registration)High-level registration of feature tools (including get_feature_flags) via registerFeatureTools in the main MCP server setup.registerFeatureTools({ server, baseApiUrl, apiKey, appOrigin, user, });