| title | Create Your First Feature Flag |
|---|---|
| description | Create a boolean feature flag, add evaluation code, and toggle it to demonstrate end-to-end functionality |
The SDK is connected. Now help the user create their first feature flag and see it work end-to-end.
If the LaunchDarkly MCP server is available, use create-flag:
- Key:
my-first-flag(or a name relevant to the user's project) - Name: "My First Flag"
- Kind:
boolean - Variations:
true/false - Temporary:
true
curl -s -X POST \
"https://app.launchdarkly.com/api/v2/flags/PROJECT_KEY" \
-H "Authorization: LAUNCHDARKLY_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "My First Flag",
"key": "my-first-flag",
"kind": "boolean",
"variations": [
{"value": true},
{"value": false}
],
"temporary": true
}'ldcli flags create \
--access-token YOUR_ACCESS_TOKEN \
--project PROJECT_KEY \
--data '{"name": "My First Flag", "key": "my-first-flag", "kind": "boolean"}'After creation, the flag starts with targeting OFF, serving the off variation (false) to everyone.
Add code to evaluate the flag in the application. Place this where it makes sense for the user's feature.
// Node.js
const context = { kind: 'user', key: 'example-user-key', name: 'Example User' };
const showFeature = await ldClient.variation('my-first-flag', context, false);
if (showFeature) {
console.log('Feature is ON');
} else {
console.log('Feature is OFF');
}# Python
context = Context.builder("example-user-key").name("Example User").build()
show_feature = client.variation("my-first-flag", context, False)
if show_feature:
print("Feature is ON")
else:
print("Feature is OFF")// Go
context := ldcontext.NewBuilder("example-user-key").Name("Example User").Build()
showFeature, _ := ldClient.BoolVariation("my-first-flag", context, false)
if showFeature {
fmt.Println("Feature is ON")
} else {
fmt.Println("Feature is OFF")
}// React
import { useFlags } from 'launchdarkly-react-client-sdk';
function MyComponent() {
const { myFirstFlag } = useFlags();
return (
<div>
{myFirstFlag ? <p>Feature is ON</p> : <p>Feature is OFF</p>}
</div>
);
}Note: Client-side React SDK camelCases flag keys, so my-first-flag becomes myFirstFlag.
With targeting OFF, the flag should evaluate to false. Run the application and confirm:
Feature is OFF
Use the toggle-flag tool to enable the flag in the target environment.
curl -s -X PATCH \
"https://app.launchdarkly.com/api/v2/flags/PROJECT_KEY/my-first-flag" \
-H "Authorization: LAUNCHDARKLY_ACCESS_TOKEN" \
-H "Content-Type: application/json; domain-model=launchdarkly.semanticpatch" \
-d '{
"environmentKey": "ENVIRONMENT_KEY",
"instructions": [
{"kind": "turnFlagOn"}
]
}'ldcli flags toggle-on \
--access-token YOUR_ACCESS_TOKEN \
--project PROJECT_KEY \
--environment ENVIRONMENT_KEY \
--flag my-first-flagAfter toggling the flag on, the application should now show:
Feature is ON
For server-side SDKs using streaming (the default), the change should be reflected within seconds. For client-side SDKs, the change appears on the next page load or when the SDK polls for updates.
The user has successfully:
- Installed the LaunchDarkly SDK
- Connected it to LaunchDarkly
- Created a feature flag
- Evaluated it in code
- Toggled it and seen the result
If any step returns an authorization error (401 or 403):
- Check if the user is logged in: The access token may be expired or invalid.
- Prompt the user to log in: Direct them to
ldcli loginor https://app.launchdarkly.com to sign in. - If the user doesn't have an account: Prompt them to sign up at https://launchdarkly.com.
- If the project or environment doesn't exist: Guide the user to create one via the dashboard or
ldcli.
Do not retry authorization errors automatically — they require user action.
Next steps to suggest:
- Use the flag create skill to create flags that fit the codebase's patterns
- Use the flag targeting skill to set up percentage rollouts and targeting rules
- Read the LaunchDarkly docs for advanced topics like contexts, experimentation, and metrics
[STATUS] Creating feature flag
[STATUS] Adding flag evaluation code
[STATUS] Verifying flag evaluates to default
[STATUS] Toggling flag on
[STATUS] Verifying flag toggle works