setStrategySortOrder
Define the execution sequence of strategies for a feature flag in a specified environment, ensuring precise control over feature activation logic.
Instructions
Set the sort order of strategies for a feature flag in a specific environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environment | Yes | ||
| featureName | Yes | ||
| projectId | Yes | ||
| strategyIds | Yes |
Implementation Reference
- The main handler function for the setStrategySortOrder tool, which calls the underlying setStrategySortOrder function and formats the response.export async function handleSetStrategySortOrder(params: { projectId: string; featureName: string; environment: string; strategyIds: string[]; }) { try { // Set the strategy sort order const result = await setStrategySortOrder( params.projectId, params.featureName, params.environment, params.strategyIds ); if (!result) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: `Failed to set strategy sort order for feature flag '${params.featureName}'` }, null, 2) }], isError: true }; } return { content: [{ type: "text", text: JSON.stringify({ success: true, message: `Successfully set strategy sort order for feature flag '${params.featureName}' in environment '${params.environment}'` }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: error.message }, null, 2) }], isError: true }; } }
- Zod schema defining the input parameters for the setStrategySortOrder tool.export const SetStrategySortOrderParamsSchema = { projectId: z.string().min(1), featureName: z.string().min(1).max(100).regex(/^[a-z0-9-_.]+$/, { message: "Name must be URL-friendly: use only lowercase, numbers, hyphens, underscores, and periods" }), environment: z.string().min(1), strategyIds: z.array(z.string()).min(1) };
- src/server.ts:136-141 (registration)Registration of the setStrategySortOrderTool in the MCP server using server.tool().server.tool( setStrategySortOrderTool.name, setStrategySortOrderTool.description, setStrategySortOrderTool.paramsSchema as any, setStrategySortOrderTool.handler as any );
- Core helper function that makes the HTTP POST request to Unleash API to set the strategy sort order.export async function setStrategySortOrder( projectId: string, featureName: string, environment: string, strategyIds: string[] ): Promise<boolean> { try { const endpoint = `/api/admin/projects/${projectId}/features/${featureName}/environments/${environment}/strategies/set-sort-order`; await client.post(endpoint, strategyIds); logger.info(`Successfully set strategy sort order for feature ${featureName} in environment ${environment}`); return true; } catch (error) { logger.error(`Error setting strategy sort order for feature ${featureName}:`, error); return false; } }