launchdarkly-flag-create

作者: launchdarkly

以符合現有程式碼庫的方式建立和設定 LaunchDarkly 功能開關。當使用者想要建立新開關、將程式碼包裝在開關中時使用…

npx skills add https://github.com/launchdarkly/ai-tooling --skill launchdarkly-flag-create

LaunchDarkly Flag Create & Configure

You're using a skill that will guide you through introducing a new feature flag into a codebase. Your job is to explore how flags are already used in this codebase, create the flag in LaunchDarkly in a way that fits, add the evaluation code matching existing patterns, and verify everything is wired up correctly.

Prerequisites

This skill requires the remotely hosted LaunchDarkly MCP server to be configured in your environment.

Required MCP tools:

  • create-flag: create a new feature flag in a project
  • get-flag: verify the flag was created correctly

Optional MCP tools (enhance workflow):

  • list-flags: browse existing flags to understand naming conventions and tags
  • update-flag-settings: update flag metadata (name, description, tags, temporary/permanent status)

Workflow

Step 1: Explore the Codebase

Before creating anything, understand how this codebase uses feature flags.

  1. Find the SDK. Search for LaunchDarkly SDK imports or initialization:

    • Look for launchdarkly, ldclient, ld-client, LDClient in imports
    • Check package.json, requirements.txt, go.mod, Gemfile, or equivalent for the SDK dependency
    • Identify which SDK is in use (server-side Node, React, Python, Go, Java, etc.)
  2. Find existing flag evaluations. Search for variation calls to understand the patterns this codebase uses:

    • Direct SDK calls: variation(), boolVariation(), useFlags(), etc.
    • Wrapper patterns: Does this codebase abstract flags behind a service or utility?
    • Constant definitions: Are flag keys defined as constants somewhere?
    • See SDK Evaluation Patterns for patterns by language
  3. Understand conventions. Look at existing flags to learn:

    • Naming convention: Are keys kebab-case, snake_case, camelCase?
    • Organization: Are flag keys co-located with features, or centralized in a constants file?
    • Default values: What defaults do existing evaluations use?
    • Context/user construction: How does this codebase build the user/context object passed to the SDK?
  4. Check LaunchDarkly project conventions. Optionally use list-flags to see existing flags:

    • What tags are commonly used?
    • Are flags marked as temporary or permanent?
    • What naming patterns exist in the project?

Step 2: Determine the Right Flag Type

Based on what the user needs, choose the appropriate flag configuration. See Flag Types and Patterns for the full guide.

Quick decision:

User intentFlag kindVariations
"Toggle a feature on/off"booleantrue / false
"Gradually roll out a feature"booleantrue / false
"A/B test between options"multivariate (string)User-defined values
"Configure a numeric threshold"multivariate (number)User-defined values
"Serve different config objects"multivariate (JSON)User-defined values

Defaults to apply:

  • Set temporary: true unless the user explicitly says this is a permanent/long-lived flag. Most flags are release flags that should eventually be cleaned up.
  • Generate a key from the name if not provided (e.g., "New Checkout Flow" -> new-checkout-flow), but match the codebase's naming convention if one exists.
  • Suggest relevant tags based on the feature area, team, or context the user mentions.

Step 3: Create the Flag in LaunchDarkly

Use create-flag with the configuration determined in Step 2.

After creation:

  • The flag is created with targeting OFF in all environments.
  • The flag serves the offVariation to everyone until targeting is turned on.
  • Remind the user they'll need to use the flag targeting skill to toggle it on and optionally set up rollout rules.

Step 4: Add Flag Evaluation to Code

Now add the code to evaluate the flag, matching the patterns you found in Step 1.

  1. Use the same SDK patterns the codebase already uses. If there's a wrapper, use the wrapper. If there are constants, add the new key to the constants file.
  2. Use an appropriate default value. The default (fallback) value in code should be the "safe" behavior: typically the existing behavior before the flag. This ensures the feature stays off if the SDK can't reach LaunchDarkly.
  3. Add the conditional logic. Wrap the new behavior in a flag check.
  4. Handle both branches. Make sure the code path for each variation is clear and complete.

See SDK Evaluation Patterns for implementation examples by language and framework.

Step 5: Verify

Confirm the flag is properly set up:

  1. Code compiles/passes linting. Run the project's build or lint step.
  2. Flag exists in LaunchDarkly. Use get-flag to confirm it was created with the right configuration.
  3. Both code paths work. The flag-off path preserves existing behavior; the flag-on path enables the new feature.
  4. Default value is safe. If LaunchDarkly is unreachable, the code falls back to the default: make sure that's the existing/safe behavior.

Updating Flag Settings

If the user wants to change flag metadata (not targeting), use update-flag-settings. Supported changes:

ChangeInstruction
Rename{kind: "updateName", value: "New Name"}
Update description{kind: "updateDescription", value: "New description"}
Add tags{kind: "addTags", values: ["tag1", "tag2"]}
Remove tags{kind: "removeTags", values: ["old-tag"]}
Mark as temporary{kind: "markTemporary"}
Mark as permanent{kind: "markPermanent"}

Multiple instructions can be batched in a single call. These changes are project-wide, not environment-specific.

Important: Metadata updates (above) are separate from targeting changes (toggle, rollout, rules). If the user wants to change who sees what, direct them to the flag targeting skill.

Important Context

  • Flag keys are immutable. Once created, a flag's key cannot be changed. Choose carefully.
  • Flags start OFF. Creation never enables a flag. This is a safety feature.
  • The default value in code is your safety net. It's what gets served when the SDK can't connect to LaunchDarkly. Always use the "safe" / existing behavior as the default.
  • Follow existing codebase conventions. The most common mistake is introducing a flag pattern that doesn't match what the team already does. Step 1 exists to prevent this.

References

來自 launchdarkly 的更多技能

aiconfig-agent-graphs
launchdarkly
建立並管理代理圖表——由帶有交接邏輯的邊連接的AI Configs有向圖。適用於建構多代理工作流程,其中配置…
official
aiconfig-ai-metrics
launchdarkly
為現有程式碼庫加入 LaunchDarkly AI Config 追蹤功能。逐步走過四層階梯(受管執行器 → 提供者套件 → 自訂提取器 +…)
official
aiconfig-create
launchdarkly
在 LaunchDarkly 中建立和設定 AI Config。協助你選擇 agent 或 completion 模式、建立設定、新增包含模型和提示的變體…
official
aiconfig-custom-metrics
launchdarkly
為 AI Configs 建立、追蹤、擷取、更新及刪除自訂業務指標。涵蓋完整生命週期:透過 API 定義指標類型,透過 SDK 發送事件,…
official
aiconfig-migrate
launchdarkly
將具有硬編碼 LLM 提示的應用程式遷移至完整的 LaunchDarkly AI Configs 實作,分為五個階段:審查程式碼、封裝呼叫、移動…
official
aiconfig-online-evals
launchdarkly
為 AI Config 變體附加評判員,以進行自動化的 LLM-as-a-judge 評估。建立自訂評判員、設定抽樣率,並監控品質分數。
official
aiconfig-projects
launchdarkly
在程式碼庫中設定 LaunchDarkly 專案的指南。協助您評估技術堆疊、選擇合適的方法,並整合專案管理,以便…
official
aiconfig-snippets
launchdarkly
建立並管理提示片段 — 可在 AI Config 變體提示中重複使用的文字區塊。保留常用指令、角色設定及防護措施…
official