createFeatureFlag
Create a new feature flag in Unleash to control feature releases, experiments, kill switches, or operational toggles within a specified project.
Instructions
Create a new feature flag
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| featureData | Yes | ||
| projectId | Yes |
Implementation Reference
- src/tools/index.ts:57-77 (handler)Core handler function that executes the tool logic: parses input, makes POST request to Unleash API to create feature flag, returns response data.async function createFeatureFlag( params: z.infer<typeof CreateFeatureFlagSchema> ) { const { projectId, featureData } = CreateFeatureFlagSchema.parse(params); try { const response = await axios.post( `${UNLEASH_API_URL}/api/admin/projects/${projectId}/features`, featureData, { headers: { Authorization: `Bearer ${UNLEASH_AUTH_TOKEN}`, 'Content-Type': 'application/json', }, } ); return response.data; } catch (error) { console.error('Error creating feature flag:', error); throw error; } }
- src/tools/schema.ts:8-22 (schema)Raw Zod input shape used for tool registration and validation of parameters: projectId and featureData structure.const RawCreateFeatureFlagShape = { projectId: z.string(), featureData: z.object({ name: z.string(), description: z.string().nullable(), impressionData: z.boolean().nullable(), type: z.enum([ 'experiment', 'kill-switch', 'release', 'operational', 'permission', ]), }), };
- src/tools/schema.ts:49-49 (schema)Full Zod schema wrapping the raw shape, used in the handler for parsing.const CreateFeatureFlagSchema = z.object(RawCreateFeatureFlagShape);
- src/index.ts:41-49 (registration)MCP server tool registration: provides name, description, input schema, and thin wrapper that calls the handler and formats JSON response.server.tool( 'createFeatureFlag', 'Create a new feature flag', RawCreateFeatureFlagShape, async (args) => { const data = await createFeatureFlag(args); return { content: [{ type: 'text', text: JSON.stringify(data) }] }; } );