Skip to main content
Glama
cuongtl1992

Unleash MCP (Feature Toggle)

validateFeatureName

Check if a feature flag name is valid and available within the Unleash MCP (Feature Toggle) system by entering the desired name and receiving confirmation.

Instructions

Validate if a feature flag name is valid and available for use

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
featureNameYesName of the feature flag to validate

Implementation Reference

  • The main handler function for the validateFeatureName tool, which calls the validation logic and formats the MCP response.
    export async function handleValidateFeatureName({ featureName }: { featureName: string }) {
      try {
        // Validate the feature name
        const result = await validateFeatureName(featureName);
        
        if (!result.isValid) {
          return {
            content: [{ 
              type: "text", 
              text: JSON.stringify({ 
                success: false,
                featureName,
                valid: false,
                error: result.error
              }, null, 2)
            }],
            isError: false // This is not a tool error, just a validation result
          };
        }
        
        return {
          content: [{ 
            type: "text", 
            text: JSON.stringify({ 
              success: true,
              featureName,
              valid: true,
              message: `Feature name '${featureName}' is valid and available for use`
            }, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{ 
            type: "text", 
            text: JSON.stringify({ 
              success: false,
              featureName,
              error: error.message || 'An unknown error occurred'
            }, null, 2)
          }],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the validateFeatureName tool.
    export const ValidateFeatureNameParamsSchema = {
      featureName: z.string().describe('Name of the feature flag to validate')
    };
  • src/server.ts:164-169 (registration)
    Registers the validateFeatureName tool with the MCP server.
    server.tool(
      validateFeatureNameTool.name,
      validateFeatureNameTool.description,
      validateFeatureNameTool.paramsSchema as any,
      validateFeatureNameTool.handler as any
    );
  • Core validation logic that interacts with the Unleash API to check feature name validity, used by the tool handler.
    export async function validateFeatureName(featureName: string): Promise<FeatureNameValidationResult> {
      try {
        await client.post('/api/admin/features/validate', { name: featureName });
        logger.info(`Feature name '${featureName}' is valid`);
        return { isValid: true };
      } catch (error: any) {
        logger.error(`Error validating feature name '${featureName}':`, error);
        
        let errorMessage = 'An unknown error occurred during validation';
        
        if (error.response) {
          const { status } = error.response;
          
          if (status === 400) {
            errorMessage = 'Feature name is not URL friendly';
          } else if (status === 409) {
            errorMessage = 'Feature name already exists';
          } else if (status === 415) {
            errorMessage = 'Unsupported media type';
          }
        }
        
        return { 
          isValid: false, 
          error: errorMessage 
        };
      }
    } 
  • Defines and exports the validateFeatureNameTool object for use in server registration.
    export const validateFeatureNameTool = {
      name: "validateFeatureName",
      description: "Validate if a feature flag name is valid and available for use",
      paramsSchema: ValidateFeatureNameParamsSchema,
      handler: handleValidateFeatureName
    }; 

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