UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

261 lines 9.52 kB
/** * Feature Flag A/B Test Example * Complete example for Feature Experimentation platform */ export const featureFlagABTestComplete = { id: 'tpl_feature_flag_ab_test', name: 'Feature Flag A/B Test Template', description: 'Creates a feature flag with A/B test ruleset for testing new features', version: '1.0.0', type: 'user', platform: 'feature', author: 'orchestration.bible@optimizely.com', template_format_version: 2, parameters: { project_id: { type: 'string', required: true, description: 'Target project ID' }, flag_name: { type: 'string', required: true, description: 'Name of the feature flag', validation: { pattern: '^[a-zA-Z][a-zA-Z0-9_]*$' } }, feature_description: { type: 'string', required: true, description: 'Description of what the feature does' }, environment_key: { type: 'string', required: false, default: 'development', description: 'Environment to deploy the flag to' }, test_percentage: { type: 'number', required: false, default: 50, description: 'Percentage of users to include in test (0-100)', validation: { min: 0, max: 100 } } }, steps: [ { id: 'create_flag', type: 'template', name: 'Create Feature Flag', template: { entity_type: 'flag', mode: 'template', operation: 'create', template_data: { project_id: '${project_id}', key: '${flag_name}', name: '${flag_name}', description: '${feature_description}', variables: [ { key: 'enabled', type: 'boolean', default_value: false }, { key: 'variant', type: 'string', default_value: 'control' }, { key: 'config', type: 'json', default_value: '{"version": "1.0"}' } ] } } }, { id: 'create_beta_users_attribute', type: 'template', name: 'Create Beta Users Attribute', template: { entity_type: 'attribute', mode: 'template', operation: 'create', template_data: { project_id: '${project_id}', key: 'beta_user', name: 'Beta User', description: 'Identifies users in the beta testing program', type: 'boolean' } } }, { id: 'create_ab_test_audience', type: 'template', name: 'Create A/B Test Audience', template: { entity_type: 'audience', mode: 'template', operation: 'create', template_data: { project_id: '${project_id}', name: '${flag_name} Test Audience', key: '${flag_name}_test_audience', conditions: [ { field: 'beta_user', match: 'exact', value: 'true' } ] } }, depends_on: ['create_beta_users_attribute'] }, { id: 'create_conversion_event', type: 'template', name: 'Create Conversion Event', template: { entity_type: 'event', mode: 'template', operation: 'create', template_data: { project_id: '${project_id}', name: '${flag_name} Conversion', key: '${flag_name}_conversion', event_type: 'custom', category: 'convert' } } }, { id: 'create_ab_test_ruleset', type: 'template', name: 'Create A/B Test Ruleset', template: { entity_type: 'ruleset', mode: 'template', operation: 'create', template_data: { project_id: '${project_id}', flag_key: '${create_flag.entity_key}', environment_key: '${environment_key}', name: '${flag_name} A/B Test', type: 'a/b_test', audience_conditions: [ { ref: { id: '${create_ab_test_audience.entity_id}' } } ], metrics: [ { event_id: '${create_conversion_event.entity_id}', scope: 'visitor', winning_direction: 'increasing' } ], variations: [ { key: 'control', name: 'Control', variables: { enabled: false, variant: 'control', config: '{"version": "1.0", "features": []}' }, traffic_allocation: '${test_percentage === 50 ? 5000 : Math.round((100 - test_percentage) * 100)}' }, { key: 'treatment', name: 'Treatment', variables: { enabled: true, variant: 'treatment', config: '{"version": "2.0", "features": ["new_ui", "enhanced_search"]}' }, traffic_allocation: '${test_percentage === 50 ? 5000 : Math.round(test_percentage * 100)}' } ] } }, depends_on: ['create_flag', 'create_ab_test_audience', 'create_conversion_event'] }, { id: 'create_rollout_rule', type: 'template', name: 'Create Default Rollout Rule', template: { entity_type: 'rule', mode: 'template', operation: 'create', template_data: { project_id: '${project_id}', flag_key: '${create_flag.entity_key}', environment_key: '${environment_key}', name: '${flag_name} Default Rollout', type: 'rollout', audience_conditions: [], percentage_included: 0, enabled: true } }, depends_on: ['create_flag'] } ], outputs: { flag_key: { value: '${create_flag.entity_key}', description: 'Created flag key' }, ruleset_id: { value: '${create_ab_test_ruleset.entity_id}', description: 'A/B test ruleset ID' }, audience_id: { value: '${create_ab_test_audience.entity_id}', description: 'Test audience ID' }, event_id: { value: '${create_conversion_event.entity_id}', description: 'Conversion event ID' } }, best_practices: [ 'Always create attributes before using them in audiences', 'Use meaningful flag keys that describe the feature', 'Start with low traffic percentages and gradually increase', 'Include conversion metrics in all A/B tests', 'Use JSON variables for complex configuration', 'Create a default rollout rule for users outside the test' ], common_mistakes: [ { mistake: 'Using percentage values instead of basis points', example: 'traffic_allocation: 50 (wrong) vs traffic_allocation: 5000 (correct)', solution: 'Convert percentages to basis points (multiply by 100)' }, { mistake: 'Forgetting to create attributes before using in audiences', example: 'Using "beta_user" without creating the attribute first', solution: 'Always create attributes in a previous step' }, { mistake: 'Missing environment_key in ruleset creation', example: 'Omitting environment_key leads to deployment issues', solution: 'Always specify the target environment' } ] }; //# sourceMappingURL=FeatureFlagABTestExample.js.map