addStrategy
Define and apply a feature flag strategy for a specific environment within the Unleash MCP server, enabling controlled feature rollouts with constraints and parameters.
Instructions
Add a strategy to a feature flag in a specific environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| constraints | No | ||
| environment | Yes | ||
| featureName | Yes | ||
| parameters | No | ||
| projectId | Yes | ||
| strategyName | Yes |
Implementation Reference
- src/tools/add-strategy.ts:27-85 (handler)The handler function for the addStrategy tool that executes the logic to add a feature strategy to a flag in Unleash by calling addFeatureStrategy and returning formatted success/error responses.export async function handleAddStrategy(params: { projectId: string; featureName: string; environment: string; strategyName: string; parameters?: Record<string, string>; constraints?: Array<{ contextName: string; operator: string; values: string[]; }>; }) { try { // Add the strategy to the feature flag const result = await addFeatureStrategy({ projectId: params.projectId, featureName: params.featureName, environment: params.environment, strategyName: params.strategyName, parameters: params.parameters, constraints: params.constraints }); if (!result) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: `Failed to add strategy '${params.strategyName}' to feature flag '${params.featureName}'` }, null, 2) }], isError: true }; } return { content: [{ type: "text", text: JSON.stringify({ success: true, message: `Successfully added strategy '${params.strategyName}' to feature flag '${params.featureName}' in environment '${params.environment}'`, strategy: result }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: error.message }, null, 2) }], isError: true }; } }
- src/tools/add-strategy.ts:11-22 (schema)Zod schema defining the input parameters for the addStrategy tool.export const AddStrategyParamsSchema = { projectId: z.string().min(1), featureName: z.string().min(1), environment: z.string().min(1), strategyName: z.string().min(1), parameters: z.record(z.string()).optional(), constraints: z.array(z.object({ contextName: z.string(), operator: z.string(), values: z.array(z.string()) })).optional() };
- src/server.ts:115-120 (registration)Registers the addStrategy tool with the MCP server using server.tool().server.tool( addStrategyTool.name, addStrategyTool.description, addStrategyTool.paramsSchema as any, addStrategyTool.handler as any );