Skip to main content
Glama
ZhipingYang

FFS MCP Server

by ZhipingYang

ffs_get_flag_options

Retrieve all available values for a feature flag to identify correct Value IDs required for updating flag statuses in the Feature Flag Service.

Instructions

Get all available options (values) for a Flag. Shows Value IDs needed for updates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
flagIdYesComplete FFS Flag ID

Implementation Reference

  • src/index.ts:117-162 (registration)
    Registration of 'ffs_get_flag_options' tool with MCP server. Defines the tool name, description, input schema (flagId as string), and the async handler function that calls getFlagOptions and getFlag from ffs-service.
    server.tool(
      'ffs_get_flag_options',
      'Get all available options (values) for a Flag. Shows Value IDs needed for updates.',
      {
        flagId: z.string().describe('Complete FFS Flag ID'),
      },
      async ({ flagId }) => {
        try {
          const options = await getFlagOptions(flagId);
          const flag = await getFlag(flagId);
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  success: true,
                  flagId,
                  dataType: flag.dataType,
                  defaultValue: flag.defaultValue,
                  options: options.map((o) => ({
                    valueId: o.valueId,
                    value: o.parsedValue,
                    mcpConditionName: o.mcpConditionName,
                    currentAccountCount: o.accountCount,
                  })),
                  message: `Found ${options.length} options. Use valueId to update account's flag value.`,
                }, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  success: false,
                  message: error instanceof Error ? error.message : 'Unknown error',
                }, null, 2),
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The handler function for 'ffs_get_flag_options' tool. It calls getFlagOptions() to fetch available options and getFlag() to get flag details, then formats and returns the response with success status, dataType, defaultValue, and options list.
    async ({ flagId }) => {
      try {
        const options = await getFlagOptions(flagId);
        const flag = await getFlag(flagId);
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                success: true,
                flagId,
                dataType: flag.dataType,
                defaultValue: flag.defaultValue,
                options: options.map((o) => ({
                  valueId: o.valueId,
                  value: o.parsedValue,
                  mcpConditionName: o.mcpConditionName,
                  currentAccountCount: o.accountCount,
                })),
                message: `Found ${options.length} options. Use valueId to update account's flag value.`,
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                success: false,
                message: error instanceof Error ? error.message : 'Unknown error',
              }, null, 2),
            },
          ],
          isError: true,
        };
      }
    }
  • The getFlagOptions function is the core implementation that fetches flag details and extracts all available options. It iterates through flag rules, finds MCP Auto conditions, parses JSON values, and builds the FlagOption array with valueId, parsedValue, mcpConditionName, and accountCount.
    export async function getFlagOptions(flagId: string): Promise<FlagOption[]> {
      const flag = await getFlag(flagId);
      const options: FlagOption[] = [];
    
      for (const rule of flag.rules) {
        const mcpCondition = rule.conditions.find((c) =>
          c.description?.startsWith(FFS_CONFIG.mcpAutoPrefix)
        );
        const accountCount = mcpCondition?.argument
          ? mcpCondition.argument.split(',').filter(Boolean).length
          : 0;
    
        let parsedValue: unknown = rule.value.value;
        try {
          parsedValue = JSON.parse(rule.value.value);
        } catch {
          // Keep as string if not valid JSON
        }
    
        options.push({
          valueId: rule.value.id,
          value: rule.value.value,
          parsedValue,
          mcpConditionName: `${FFS_CONFIG.mcpAutoPrefix} [${rule.value.id}]`,
          accountCount,
        });
      }
    
      return options;
    }
  • The FlagOption interface defines the return type for getFlagOptions, containing valueId, value, parsedValue, mcpConditionName, and accountCount fields.
    export interface FlagOption {
      valueId: string;
      value: string;
      parsedValue: unknown;
      mcpConditionName: string;
      accountCount: number;
    }

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/ZhipingYang/ffs-mcp-server'

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