Skip to main content
Glama
cuongtl1992

Unleash MCP (Feature Toggle)

createFlag

Add a feature flag to an Unleash project, enabling dynamic toggling of features for controlled rollouts, experiments, or operational adjustments.

Instructions

Create a new feature flag in an Unleash project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNo
impressionDataNo
nameYes
projectYes
typeNo

Implementation Reference

  • The primary handler function that implements the core logic of the createFlag tool. It processes validated parameters, invokes the Unleash API helper, handles success/error cases, and returns MCP-formatted content.
    export async function handleCreateFlag(params: {
      name: string;
      project: string;
      description?: string;
      type?: string;
      impressionData?: boolean;
    }) {
      try {
        // Create the feature flag
        const result = await createFeatureFlag({
          name: params.name,
          project: params.project,
          description: params.description,
          type: params.type,
          impressionData: params.impressionData
        });
        
        if (!result) {
          return {
            content: [{ 
              type: "text", 
              text: JSON.stringify({ 
                success: false,
                error: `Failed to create feature flag '${params.name}'` 
              }, null, 2)
            }],
            isError: true
          };
        }
        
        return {
          content: [{ 
            type: "text", 
            text: JSON.stringify({ 
              success: true,
              message: `Successfully created feature flag '${params.name}' in project '${params.project}'`,
              flag: result
            }, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{ 
            type: "text", 
            text: JSON.stringify({ 
              success: false,
              error: error.message 
            }, null, 2)
          }],
          isError: true
        };
      }
    }
  • Zod-based input schema for validating parameters to the createFlag tool (name, project, description, type, impressionData).
    export const CreateFlagParamsSchema = {
      name: z.string().min(1).max(100).regex(/^[a-z0-9-_.]+$/, {
        message: "Name must be URL-friendly: use only lowercase, numbers, hyphens, underscores, and periods"
      }),
      project: z.string(),
      description: z.string().optional(),
      type: z.enum(['release', 'experiment', 'operational', 'permission', 'kill-switch']).optional(),
      impressionData: z.boolean().optional()
    };
  • src/server.ts:94-99 (registration)
    Registers the createFlag tool with the MCP server instance using server.tool(), referencing the imported tool definition.
    server.tool(
      createFlagTool.name,
      createFlagTool.description,
      createFlagTool.paramsSchema as any,
      createFlagTool.handler as any
    );
  • Supporting helper utility that performs the actual HTTP POST request to the Unleash API to create the feature flag, handling payload preparation, logging, and error recovery.
    export async function createFeatureFlag(params: CreateFeatureFlagParams): Promise<any | null> {
      try {
        const payload = {
          name: params.name,
          description: params.description || '',
          type: params.type || 'release',
          impressionData: params.impressionData !== undefined ? params.impressionData : false
        };
    
        logger.info(`Creating feature flag: ${params.name} in project: ${params.project}`);
        
        const response = await client.post(
          `/api/admin/projects/${params.project}/features`,
          payload
        );
        
        logger.info(`Successfully created feature flag: ${params.name}`);
        return response.data;
      } catch (error: any) {
        logger.error(`Error creating feature flag ${params.name}:`, error.response?.data || error.message);
        return null;
      }
    } 
  • Tool definition object exporting the createFlag metadata (name, description, schema, handler) for use in MCP server registration.
    export const createFlagTool = {
      name: "createFlag",
      description: "Create a new feature flag in an Unleash project",
      paramsSchema: CreateFlagParamsSchema,
      handler: handleCreateFlag
    }; 

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cuongtl1992/unleash-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server