:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(flags): expose the rollout actions as MCP tools (#100145)
James Gill9ce3a33daddc
diff --git a/products/feature_flags/evals/scorers.py b/products/feature_flags/evals/scorers.pyindex 88aeaa5d0af0..907832b99947 100644--- a/products/feature_flags/evals/scorers.py+++ b/products/feature_flags/evals/scorers.py@@ -646,6 +646,8 @@ FLAG_MUTATION_TOOLS = frozenset("feature-flag-unarchive","feature-flag-disable","feature-flag-enable",+ "feature-flag-roll-out-to-everyone",+ "feature-flag-set-release-condition-rollout","delete-feature-flag","update-feature-flag","create-feature-flag",diff --git a/products/feature_flags/mcp/tools.yaml b/products/feature_flags/mcp/tools.yamlindex c6d21ce15028..421a529b3088 100644--- a/products/feature_flags/mcp/tools.yaml+++ b/products/feature_flags/mcp/tools.yaml@@ -307,6 +307,154 @@ tools:feature-flag-request-usage-list:operation: feature_flag_request_usage_listenabled: false+ feature-flag-roll-out-to-everyone:+ operation: feature_flags_roll_out_to_everyone_create+ enabled: true+ scopes:+ - feature_flag:write+ annotations:+ readOnly: false+ destructive: false+ idempotent: false+ enrich_url: '{id}'+ title: Roll feature flag out to everyone+ description: >+ Serve a feature flag to its whole audience: every user, or every group of the configured type when the flag+ aggregates by groups. Requires the flag's numeric ID; use `feature-flag-get-definition-by-key` to get it+ from a key, or `feature-flag-get-all` to search by key or name.+++ Adds a release condition with no property filters at 100% and keeps the existing conditions below it. This+ tool never accepts or replaces the `filters` object, so payloads, the holdout and the set of variants cannot+ change. On a boolean flag, removing the new condition puts the previous targeting back. On a multivariate+ flag the variant distribution is rewritten as well, so removing the condition restores the audience but not+ the old split. A flag that already leads with such a condition gains no second one.+++ This tool changes targeting only. A disabled flag still serves nobody, so check `active` in the response and+ use `feature-flag-enable` if it is false. A holdout is evaluated before release conditions, so users in one+ keep getting the holdout variant instead of the rollout. Early access enrollment is evaluated before both.+++ Check `filters.feature_enrollment` in the definition you read. When it is true, this tool refuses the+ rollout with 400 and writes nothing. Only the early access feature's own move to general availability with+ its roll out to everyone option clears the gate. That move writes the 100% condition itself, so do not call+ this tool after it. A plain stage change to general availability leaves `feature_enrollment` true, and this+ tool keeps returning 400. The API does not expose that option, so ask the person to make the move in the+ early access feature.+++ `update-feature-flag` and `feature-flag-set-release-condition-rollout` are not gated on enrollment. A+ rollout written through either returns 200 while the enrollment marker still decides who is served. Do not+ use either tool to bypass the 400.+++ Check `filters.aggregation_group_type_index` in the definition you read. When it is set, the flag buckets+ groups of that type instead of people. The new condition then serves every group of that type, and a user+ evaluated without such a group is served nothing. Say groups when you report the change.+++ A multivariate flag needs `variant_key`, and every other flag rejects it. A release condition decides who+ the flag serves and not which variant they get, so this also gives the named variant 100% of the variant+ distribution and every other variant 0%. When the user says "roll it out to everyone" about a multivariate+ flag, ask which variant they mean rather than guessing. To serve everyone and keep the current split between+ variants, use `update-feature-flag`.+++ Check `experiment_set_metadata` in the definition you read. When it lists an experiment with `is_running`+ true, ship the winner with `experiment-ship-variant`: that tool makes the same distribution change and also+ ends the experiment and records its conclusion. This tool leaves the experiment running with no end date, so+ every later exposure enters one variant and the comparison stops being valid. Use this tool on that flag+ only when the user wants the audience changed and the experiment kept running.+++ Read the flag first and send the `version` that read returned. Returns 409 when anyone changed the flag+ after that version, and writes nothing. Read the flag again, check what changed, and decide the rollout+ against the current definition. Do not retry with the same version: after a call writes a change that+ version is no longer current, so a blind retry is the same 409. A call that finds the flag already rolled+ out to everyone writes nothing and returns the version unchanged.+++ Returns 400 when the flag is gated on early access enrollment, when a multivariate flag has no+ `variant_key`, when the flag defines no such variant, or when `variant_key` is sent for a flag with no+ variants. Returns 409 when an approval policy gates rollout changes.+ param_overrides:+ id:+ cast: string-int+ aliases:+ - flagId+ - flag_id+ - feature_flag_id+ - featureFlagId+ response:+ include:+ - id+ - key+ - active+ - archived+ - status+ - version+ - filters+ feature-flag-set-release-condition-rollout:+ operation: feature_flags_set_release_condition_rollout_create+ enabled: true+ scopes:+ - feature_flag:write+ annotations:+ readOnly: false+ destructive: false+ idempotent: false+ enrich_url: '{id}'+ title: Set feature flag release condition rollout+ description: >+ Set what percentage of one release condition's audience a feature flag is served to. Requires the flag's+ numeric ID; use `feature-flag-get-definition-by-key` to get it from a key, or `feature-flag-get-all` to+ search by key or name.+++ Changes `rollout_percentage` on the release condition at `condition_index` and nothing else. This tool never+ accepts or replaces the `filters` object, so the condition's property filters, the other conditions, the+ variants and the payloads cannot change.+++ Check `aggregation_group_type_index` on the condition, and on `filters` when the condition sets none. When+ it is set, the flag buckets groups of that type instead of people, so 25 serves 25% of those groups rather+ than 25% of users. Say groups when you report the change.+++ Read the flag first. `condition_index` counts the conditions in `filters.groups` from 0, and only the+ definition you read says which condition is which, so never guess an index on a flag with more than one+ condition. Send the `version` that same read returned. Returns 409 when anyone changed the flag after that+ version, and writes nothing. Read the flag again, check the conditions still mean what you thought, and call+ again with the new version. Do not retry with the same version: after a call writes a change that version is+ no longer current, so a blind retry is the same 409. A call that sets the percentage the condition already+ has writes nothing and returns the version unchanged.+++ On a multivariate flag this sets how many of the matching users or groups get a variant at all. It does not+ change how the variants are split between them. When the user asks for a bare percentage on a multivariate+ flag, ask which of the two they mean. Use `update-feature-flag` to change the split between variants.+++ Returns 400 when the flag has no release condition at that index, or when the percentage is outside 0+ through 100. Returns 409 when an approval policy gates rollout changes.+ param_overrides:+ id:+ cast: string-int+ aliases:+ - flagId+ - flag_id+ - feature_flag_id+ - featureFlagId+ response:+ include:+ - id+ - key+ - active+ - archived+ - status+ - version+ - filtersfeature-flag-unarchive:operation: feature_flags_unarchive_createenabled: true@@ -735,8 +883,8 @@ tools:title: Update feature flagdescription: >Update a feature flag by numeric ID (partial update: only the fields you include are changed). Use this for- edits that have no dedicated tool, such as release conditions, rollout percentages, variants, payloads, tags- and the description.+ edits that have no dedicated tool, such as property filters, adding and removing release conditions, variant+ definitions, payloads, tags and the description.Prefer a dedicated tool whenever the request matches one. `feature-flag-enable`, `feature-flag-disable`,@@ -746,6 +894,14 @@ tools:edit lands in one write.+ `feature-flag-set-release-condition-rollout` changes one release condition's percentage and+ `feature-flag-roll-out-to-everyone` serves the flag to its whole audience. Both send no `filters` and both+ refuse the write when the flag changed after the version you read, so a concurrent edit cannot be lost. This+ tool sends no `version`, so it writes even when the flag changed after your read. It replaces the whole+ `filters` object with your copy of it. Use it for a rollout change only when those two tools cannot express+ it, such as changing the split between variants while leaving the audience alone.++Rollout conditions, variants, and payloads live in the structured `filters` param, and sending `filters`replaces the whole object, so read the flag first and merge your change. When the flag targets groups, keep`type: "group"`, `group_type_index`, and `filters.aggregation_group_type_index` in what you send; if youdiff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 17ccfde9b42c..43acd33e71fd 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -5464,6 +5464,34 @@"readOnlyHint": true}},+ "feature-flag-roll-out-to-everyone": {+ "description": "Serve a feature flag to its whole audience: every user, or every group of the configured type when the flag aggregates by groups. Requires the flag's numeric ID; use `feature-flag-get-definition-by-key` to get it from a key, or `feature-flag-get-all` to search by key or name.\n\nAdds a release condition with no property filters at 100% and keeps the existing conditions below it. This tool never accepts or replaces the `filters` object, so payloads, the holdout and the set of variants cannot change. On a boolean flag, removing the new condition puts the previous targeting back. On a multivariate flag the variant distribution is rewritten as well, so removing the condition restores the audience but not the old split. A flag that already leads with such a condition gains no second one.\n\nThis tool changes targeting only. A disabled flag still serves nobody, so check `active` in the response and use `feature-flag-enable` if it is false. A holdout is evaluated before release conditions, so users in one keep getting the holdout variant instead of the rollout. Early access enrollment is evaluated before both.\n\nCheck `filters.feature_enrollment` in the definition you read. When it is true, this tool refuses the rollout with 400 and writes nothing. Only the early access feature's own move to general availability with its roll out to everyone option clears the gate. That move writes the 100% condition itself, so do not call this tool after it. A plain stage change to general availability leaves `feature_enrollment` true, and this tool keeps returning 400. The API does not expose that option, so ask the person to make the move in the early access feature.\n\n`update-feature-flag` and `feature-flag-set-release-condition-rollout` are not gated on enrollment. A rollout written through either returns 200 while the enrollment marker still decides who is served. Do not use either tool to bypass the 400.\n\nCheck `filters.aggregation_group_type_index` in the definition you read. When it is set, the flag buckets groups of that type instead of people. The new condition then serves every group of that type, and a user evaluated without such a group is served nothing. Say groups when you report the change.\n\nA multivariate flag needs `variant_key`, and every other flag rejects it. A release condition decides who the flag serves and not which variant they get, so this also gives the named variant 100% of the variant distribution and every other variant 0%. When the user says \"roll it out to everyone\" about a multivariate flag, ask which variant they mean rather than guessing. To serve everyone and keep the current split between variants, use `update-feature-flag`.\n\nCheck `experiment_set_metadata` in the definition you read. When it lists an experiment with `is_running` true, ship the winner with `experiment-ship-variant`: that tool makes the same distribution change and also ends the experiment and records its conclusion. This tool leaves the experiment running with no end date, so every later exposure enters one variant and the comparison stops being valid. Use this tool on that flag only when the user wants the audience changed and the experiment kept running.\n\nRead the flag first and send the `version` that read returned. Returns 409 when anyone changed the flag after that version, and writes nothing. Read the flag again, check what changed, and decide the rollout against the current definition. Do not retry with the same version: after a call writes a change that version is no longer current, so a blind retry is the same 409. A call that finds the flag already rolled out to everyone writes nothing and returns the version unchanged.\n\nReturns 400 when the flag is gated on early access enrollment, when a multivariate flag has no `variant_key`, when the flag defines no such variant, or when `variant_key` is sent for a flag with no variants. Returns 409 when an approval policy gates rollout changes.",+ "category": "Feature flags",+ "feature": "flags",+ "summary": "Roll feature flag out to everyone",+ "title": "Roll feature flag out to everyone",+ "required_scopes": ["feature_flag:write"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": false,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },+ "feature-flag-set-release-condition-rollout": {+ "description": "Set what percentage of one release condition's audience a feature flag is served to. Requires the flag's numeric ID; use `feature-flag-get-definition-by-key` to get it from a key, or `feature-flag-get-all` to search by key or name.\n\nChanges `rollout_percentage` on the release condition at `condition_index` and nothing else. This tool never accepts or replaces the `filters` object, so the condition's property filters, the other conditions, the variants and the payloads cannot change.\n\nCheck `aggregation_group_type_index` on the condition, and on `filters` when the condition sets none. When it is set, the flag buckets groups of that type instead of people, so 25 serves 25% of those groups rather than 25% of users. Say groups when you report the change.\n\nRead the flag first. `condition_index` counts the conditions in `filters.groups` from 0, and only the definition you read says which condition is which, so never guess an index on a flag with more than one condition. Send the `version` that same read returned. Returns 409 when anyone changed the flag after that version, and writes nothing. Read the flag again, check the conditions still mean what you thought, and call again with the new version. Do not retry with the same version: after a call writes a change that version is no longer current, so a blind retry is the same 409. A call that sets the percentage the condition already has writes nothing and returns the version unchanged.\n\nOn a multivariate flag this sets how many of the matching users or groups get a variant at all. It does not change how the variants are split between them. When the user asks for a bare percentage on a multivariate flag, ask which of the two they mean. Use `update-feature-flag` to change the split between variants.\n\nReturns 400 when the flag has no release condition at that index, or when the percentage is outside 0 through 100. Returns 409 when an approval policy gates rollout changes.",+ "category": "Feature flags",+ "feature": "flags",+ "summary": "Set feature flag release condition rollout",+ "title": "Set feature flag release condition rollout",+ "required_scopes": ["feature_flag:write"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": false,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },"feature-flag-unarchive": {"description": "Restore an archived feature flag to the default flag list. Requires the flag's numeric ID; pass `{\"archived\":\"true\"}` to `feature-flag-get-all` to find archived flags.\n\nSets `archived` to false and changes nothing else. This tool never accepts or replaces the `filters` object. There is no request body.\n\nThe flag stays turned off. Call `feature-flag-enable` when the user also wants it serving again. Unarchiving a flag that is not archived succeeds and changes nothing, so retrying is safe.","category": "Feature flags",@@ -11875,7 +11903,7 @@"feature_flag": "tasks"},"update-feature-flag": {- "description": "Update a feature flag by numeric ID (partial update: only the fields you include are changed). Use this for edits that have no dedicated tool, such as release conditions, rollout percentages, variants, payloads, tags and the description.\n\nPrefer a dedicated tool whenever the request matches one. `feature-flag-enable`, `feature-flag-disable`, `feature-flag-archive` and `feature-flag-unarchive` each change one state field and send no `filters`. A targeting change someone else made between your read and your write is therefore not overwritten. Send `active` or `archived` here only when the same request also changes targeting or another field, so the whole edit lands in one write.\n\nRollout conditions, variants, and payloads live in the structured `filters` param, and sending `filters` replaces the whole object, so read the flag first and merge your change. When the flag targets groups, keep `type: \"group\"`, `group_type_index`, and `filters.aggregation_group_type_index` in what you send; if you omit them this tool restores them from the existing flag so group targeting is not silently converted to person targeting. Use `feature-flag-get-definition-by-key` when you have the string key: it returns the numeric ID and the full definition in one call. Use `feature-flag-get-definition` when you already have the ID. To apply a change at a future time instead, use `scheduled-changes-create`.",+ "description": "Update a feature flag by numeric ID (partial update: only the fields you include are changed). Use this for edits that have no dedicated tool, such as property filters, adding and removing release conditions, variant definitions, payloads, tags and the description.\n\nPrefer a dedicated tool whenever the request matches one. `feature-flag-enable`, `feature-flag-disable`, `feature-flag-archive` and `feature-flag-unarchive` each change one state field and send no `filters`. A targeting change someone else made between your read and your write is therefore not overwritten. Send `active` or `archived` here only when the same request also changes targeting or another field, so the whole edit lands in one write.\n\n`feature-flag-set-release-condition-rollout` changes one release condition's percentage and `feature-flag-roll-out-to-everyone` serves the flag to its whole audience. Both send no `filters` and both refuse the write when the flag changed after the version you read, so a concurrent edit cannot be lost. This tool sends no `version`, so it writes even when the flag changed after your read. It replaces the whole `filters` object with your copy of it. Use it for a rollout change only when those two tools cannot express it, such as changing the split between variants while leaving the audience alone.\n\nRollout conditions, variants, and payloads live in the structured `filters` param, and sending `filters` replaces the whole object, so read the flag first and merge your change. When the flag targets groups, keep `type: \"group\"`, `group_type_index`, and `filters.aggregation_group_type_index` in what you send; if you omit them this tool restores them from the existing flag so group targeting is not silently converted to person targeting. Use `feature-flag-get-definition-by-key` when you have the string key: it returns the numeric ID and the full definition in one call. Use `feature-flag-get-definition` when you already have the ID. To apply a change at a future time instead, use `scheduled-changes-create`.","category": "Feature flags","feature": "flags","summary": "Update feature flag",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex b49ef3725b64..ff955700b55e 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5633,6 +5633,34 @@"readOnlyHint": true}},+ "feature-flag-roll-out-to-everyone": {+ "description": "Serve a feature flag to its whole audience: every user, or every group of the configured type when the flag aggregates by groups. Requires the flag's numeric ID; use `feature-flag-get-definition-by-key` to get it from a key, or `feature-flag-get-all` to search by key or name.\n\nAdds a release condition with no property filters at 100% and keeps the existing conditions below it. This tool never accepts or replaces the `filters` object, so payloads, the holdout and the set of variants cannot change. On a boolean flag, removing the new condition puts the previous targeting back. On a multivariate flag the variant distribution is rewritten as well, so removing the condition restores the audience but not the old split. A flag that already leads with such a condition gains no second one.\n\nThis tool changes targeting only. A disabled flag still serves nobody, so check `active` in the response and use `feature-flag-enable` if it is false. A holdout is evaluated before release conditions, so users in one keep getting the holdout variant instead of the rollout. Early access enrollment is evaluated before both.\n\nCheck `filters.feature_enrollment` in the definition you read. When it is true, this tool refuses the rollout with 400 and writes nothing. Only the early access feature's own move to general availability with its roll out to everyone option clears the gate. That move writes the 100% condition itself, so do not call this tool after it. A plain stage change to general availability leaves `feature_enrollment` true, and this tool keeps returning 400. The API does not expose that option, so ask the person to make the move in the early access feature.\n\n`update-feature-flag` and `feature-flag-set-release-condition-rollout` are not gated on enrollment. A rollout written through either returns 200 while the enrollment marker still decides who is served. Do not use either tool to bypass the 400.\n\nCheck `filters.aggregation_group_type_index` in the definition you read. When it is set, the flag buckets groups of that type instead of people. The new condition then serves every group of that type, and a user evaluated without such a group is served nothing. Say groups when you report the change.\n\nA multivariate flag needs `variant_key`, and every other flag rejects it. A release condition decides who the flag serves and not which variant they get, so this also gives the named variant 100% of the variant distribution and every other variant 0%. When the user says \"roll it out to everyone\" about a multivariate flag, ask which variant they mean rather than guessing. To serve everyone and keep the current split between variants, use `update-feature-flag`.\n\nCheck `experiment_set_metadata` in the definition you read. When it lists an experiment with `is_running` true, ship the winner with `experiment-ship-variant`: that tool makes the same distribution change and also ends the experiment and records its conclusion. This tool leaves the experiment running with no end date, so every later exposure enters one variant and the comparison stops being valid. Use this tool on that flag only when the user wants the audience changed and the experiment kept running.\n\nRead the flag first and send the `version` that read returned. Returns 409 when anyone changed the flag after that version, and writes nothing. Read the flag again, check what changed, and decide the rollout against the current definition. Do not retry with the same version: after a call writes a change that version is no longer current, so a blind retry is the same 409. A call that finds the flag already rolled out to everyone writes nothing and returns the version unchanged.\n\nReturns 400 when the flag is gated on early access enrollment, when a multivariate flag has no `variant_key`, when the flag defines no such variant, or when `variant_key` is sent for a flag with no variants. Returns 409 when an approval policy gates rollout changes.",+ "category": "Feature flags",+ "feature": "flags",+ "summary": "Roll feature flag out to everyone",+ "title": "Roll feature flag out to everyone",+ "required_scopes": ["feature_flag:write"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": false,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },+ "feature-flag-set-release-condition-rollout": {+ "description": "Set what percentage of one release condition's audience a feature flag is served to. Requires the flag's numeric ID; use `feature-flag-get-definition-by-key` to get it from a key, or `feature-flag-get-all` to search by key or name.\n\nChanges `rollout_percentage` on the release condition at `condition_index` and nothing else. This tool never accepts or replaces the `filters` object, so the condition's property filters, the other conditions, the variants and the payloads cannot change.\n\nCheck `aggregation_group_type_index` on the condition, and on `filters` when the condition sets none. When it is set, the flag buckets groups of that type instead of people, so 25 serves 25% of those groups rather than 25% of users. Say groups when you report the change.\n\nRead the flag first. `condition_index` counts the conditions in `filters.groups` from 0, and only the definition you read says which condition is which, so never guess an index on a flag with more than one condition. Send the `version` that same read returned. Returns 409 when anyone changed the flag after that version, and writes nothing. Read the flag again, check the conditions still mean what you thought, and call again with the new version. Do not retry with the same version: after a call writes a change that version is no longer current, so a blind retry is the same 409. A call that sets the percentage the condition already has writes nothing and returns the version unchanged.\n\nOn a multivariate flag this sets how many of the matching users or groups get a variant at all. It does not change how the variants are split between them. When the user asks for a bare percentage on a multivariate flag, ask which of the two they mean. Use `update-feature-flag` to change the split between variants.\n\nReturns 400 when the flag has no release condition at that index, or when the percentage is outside 0 through 100. Returns 409 when an approval policy gates rollout changes.",+ "category": "Feature flags",+ "feature": "flags",+ "summary": "Set feature flag release condition rollout",+ "title": "Set feature flag release condition rollout",+ "required_scopes": ["feature_flag:write"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": false,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },"feature-flag-unarchive": {"description": "Restore an archived feature flag to the default flag list. Requires the flag's numeric ID; pass `{\"archived\":\"true\"}` to `feature-flag-get-all` to find archived flags.\n\nSets `archived` to false and changes nothing else. This tool never accepts or replaces the `filters` object. There is no request body.\n\nThe flag stays turned off. Call `feature-flag-enable` when the user also wants it serving again. Unarchiving a flag that is not archived succeeds and changes nothing, so retrying is safe.","category": "Feature flags",@@ -12520,7 +12548,7 @@"feature_flag": "tasks"},"update-feature-flag": {- "description": "Update a feature flag by numeric ID (partial update: only the fields you include are changed). Use this for edits that have no dedicated tool, such as release conditions, rollout percentages, variants, payloads, tags and the description.\n\nPrefer a dedicated tool whenever the request matches one. `feature-flag-enable`, `feature-flag-disable`, `feature-flag-archive` and `feature-flag-unarchive` each change one state field and send no `filters`. A targeting change someone else made between your read and your write is therefore not overwritten. Send `active` or `archived` here only when the same request also changes targeting or another field, so the whole edit lands in one write.\n\nRollout conditions, variants, and payloads live in the structured `filters` param, and sending `filters` replaces the whole object, so read the flag first and merge your change. When the flag targets groups, keep `type: \"group\"`, `group_type_index`, and `filters.aggregation_group_type_index` in what you send; if you omit them this tool restores them from the existing flag so group targeting is not silently converted to person targeting. Use `feature-flag-get-definition-by-key` when you have the string key: it returns the numeric ID and the full definition in one call. Use `feature-flag-get-definition` when you already have the ID. To apply a change at a future time instead, use `scheduled-changes-create`.",+ "description": "Update a feature flag by numeric ID (partial update: only the fields you include are changed). Use this for edits that have no dedicated tool, such as property filters, adding and removing release conditions, variant definitions, payloads, tags and the description.\n\nPrefer a dedicated tool whenever the request matches one. `feature-flag-enable`, `feature-flag-disable`, `feature-flag-archive` and `feature-flag-unarchive` each change one state field and send no `filters`. A targeting change someone else made between your read and your write is therefore not overwritten. Send `active` or `archived` here only when the same request also changes targeting or another field, so the whole edit lands in one write.\n\n`feature-flag-set-release-condition-rollout` changes one release condition's percentage and `feature-flag-roll-out-to-everyone` serves the flag to its whole audience. Both send no `filters` and both refuse the write when the flag changed after the version you read, so a concurrent edit cannot be lost. This tool sends no `version`, so it writes even when the flag changed after your read. It replaces the whole `filters` object with your copy of it. Use it for a rollout change only when those two tools cannot express it, such as changing the split between variants while leaving the audience alone.\n\nRollout conditions, variants, and payloads live in the structured `filters` param, and sending `filters` replaces the whole object, so read the flag first and merge your change. When the flag targets groups, keep `type: \"group\"`, `group_type_index`, and `filters.aggregation_group_type_index` in what you send; if you omit them this tool restores them from the existing flag so group targeting is not silently converted to person targeting. Use `feature-flag-get-definition-by-key` when you have the string key: it returns the numeric ID and the full definition in one call. Use `feature-flag-get-definition` when you already have the ID. To apply a change at a future time instead, use `scheduled-changes-create`.","category": "Feature flags","feature": "flags","summary": "Update feature flag",diff --git a/services/mcp/src/generated/feature_flags/api.ts b/services/mcp/src/generated/feature_flags/api.tsindex c95795a343f8..04454b5714b9 100644--- a/services/mcp/src/generated/feature_flags/api.ts+++ b/services/mcp/src/generated/feature_flags/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 26 enabled ops+ * PostHog API - MCP 28 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -977,6 +977,111 @@ export const FeatureFlagsEnableCreateParams = () => zod.object({),})+/**+ * Serve a feature flag to every user.+ *+ * Adds a release condition with no property filters at 100% and keeps the existing+ * conditions below it. Payloads, holdout and every other field are left as they are. On a+ * boolean flag, removing the new condition restores the previous targeting. On a+ * multivariate flag the variant distribution is rewritten as well, so removing the+ * condition restores the audience but not the old split. A flag that already leads with+ * such a condition gains no second one.+ *+ * This changes targeting only. A disabled flag still serves nobody, and a holdout is+ * evaluated before release conditions, so users in one keep getting the holdout variant+ * instead of the rollout. A flag gated on early access enrollment is refused, because that+ * gate is evaluated before release conditions too and no targeting change gets past it.+ *+ * A multivariate flag needs `variant_key`, and every other flag rejects it. A release+ * condition decides who the flag serves, not which variant they get, so rolling a+ * multivariate flag out to everyone also gives the named variant 100% of the variant+ * distribution and every other variant 0%. To serve everyone and keep the current split+ * between variants, update the flag instead.+ *+ * Send the `version` your last read returned. A change to the flag after that version is+ * refused with 409. Read the flag again and decide the rollout against its current+ * definition.+ */+export const FeatureFlagsRollOutToEveryoneCreateParams = () => zod.object({+ id: zod.number().describe('A unique integer value identifying this feature flag.'),+ project_id: zod+ .string()+ .describe(+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."+ ),+})++export const featureFlagsRollOutToEveryoneCreateBodyVersionMin = 0++export const FeatureFlagsRollOutToEveryoneCreateBody = () => zod.object({+ version: zod+ .number()+ .min(featureFlagsRollOutToEveryoneCreateBodyVersionMin)+ .nullable()+ .describe(+ 'The `version` from your most recent read of this flag. The change is refused with 409 if anyone else changed the flag after that version. A flag written before versioning reads as `null`; send that back unchanged and it is read as 0, so the value a read returns is always one this accepts.'+ ),+ variant_key: zod+ .string()+ .nullish()+ .describe(+ 'The variant every user gets. Required for a multivariate flag and rejected for any other flag, because a release condition decides who the flag serves and not which variant they get.'+ ),+})++/**+ * Set what percentage of one release condition's audience a feature flag is served to.+ *+ * Changes `rollout_percentage` on the release condition at `condition_index` and nothing+ * else. The condition's property filters, every other condition, the variants, payloads,+ * holdout and every remaining field are left as they are.+ *+ * Send the `version` your last read returned. A change to the flag after that version is+ * refused with 409, because a condition index only names the condition you read. Read the+ * flag again and decide the percentage against its current definition.+ *+ * On a multivariate flag this sets how many of the matching users get a variant at all. It+ * does not change how the variants are split between them.+ */+export const FeatureFlagsSetReleaseConditionRolloutCreateParams = () => zod.object({+ id: zod.number().describe('A unique integer value identifying this feature flag.'),+ project_id: zod+ .string()+ .describe(+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."+ ),+})++export const featureFlagsSetReleaseConditionRolloutCreateBodyConditionIndexMin = 0++export const featureFlagsSetReleaseConditionRolloutCreateBodyRolloutPercentageMin = 0+export const featureFlagsSetReleaseConditionRolloutCreateBodyRolloutPercentageMax = 100++export const featureFlagsSetReleaseConditionRolloutCreateBodyVersionMin = 0++export const FeatureFlagsSetReleaseConditionRolloutCreateBody = () => zod.object({+ condition_index: zod+ .number()+ .min(featureFlagsSetReleaseConditionRolloutCreateBodyConditionIndexMin)+ .describe(+ 'Zero-based position of the release condition in `filters.groups`, counted from the read that produced `version`.'+ ),+ rollout_percentage: zod+ .number()+ .min(featureFlagsSetReleaseConditionRolloutCreateBodyRolloutPercentageMin)+ .max(featureFlagsSetReleaseConditionRolloutCreateBodyRolloutPercentageMax)+ .describe(+ 'Percentage of the users matching that condition who are served the flag, 0 through 100. On a multivariate flag this is how many matching users get a variant at all, not how the variants are split between them. Fractional percentages such as 0.5 are accepted, the same as a write that sends `filters`.'+ ),+ version: zod+ .number()+ .min(featureFlagsSetReleaseConditionRolloutCreateBodyVersionMin)+ .nullable()+ .describe(+ 'The `version` from your most recent read of this flag. The change is refused with 409 if anyone else changed the flag after that version. A flag written before versioning reads as `null`; send that back unchanged and it is read as 0, so the value a read returns is always one this accepts.'+ ),+})+/*** Create, read, update and delete feature flags. [See docs](https://posthog.com/docs/feature-flags) for more information on feature flags.*diff --git a/services/mcp/src/tools/generated/feature_flags.ts b/services/mcp/src/tools/generated/feature_flags.tsindex 1996e9ac7d40..2ca225d71efd 100644--- a/services/mcp/src/tools/generated/feature_flags.ts+++ b/services/mcp/src/tools/generated/feature_flags.ts@@ -285,6 +285,104 @@ const featureFlagGetDefinition = (): ToolBase<},})+const FeatureFlagRollOutToEveryoneSchema = () => {+ const FeatureFlagsRollOutToEveryoneCreateBody = orvalSchemas.FeatureFlagsRollOutToEveryoneCreateBody()+ const FeatureFlagsRollOutToEveryoneCreateParams = orvalSchemas.FeatureFlagsRollOutToEveryoneCreateParams()+ return z.preprocess(+ normalizeParamAliases({ id: ['flagId', 'flag_id', 'feature_flag_id', 'featureFlagId'] }),+ FeatureFlagsRollOutToEveryoneCreateParams.omit({ project_id: true })+ .extend(FeatureFlagsRollOutToEveryoneCreateBody.shape)+ .extend({ id: z.preprocess(castStringToInt, FeatureFlagsRollOutToEveryoneCreateParams.shape['id']) })+ )+}++const featureFlagRollOutToEveryone = (): ToolBase<+ ReturnType<typeof FeatureFlagRollOutToEveryoneSchema>,+ WithPostHogUrl<Schemas.FeatureFlag>+> => ({+ name: 'feature-flag-roll-out-to-everyone',+ schema: FeatureFlagRollOutToEveryoneSchema(),+ handler: async (context: Context, params: z.infer<ReturnType<typeof FeatureFlagRollOutToEveryoneSchema>>) => {+ const projectId = await context.stateManager.getProjectId()+ const body: Record<string, unknown> = {}+ if (params.version !== undefined) {+ body['version'] = params.version+ }+ if (params.variant_key !== undefined) {+ body['variant_key'] = params.variant_key+ }+ const result = await context.api.request<Schemas.FeatureFlag>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/feature_flags/${encodeURIComponent(String(params.id))}/roll_out_to_everyone/`,+ body,+ })+ const filtered = pickResponseFields(result, [+ 'id',+ 'key',+ 'active',+ 'archived',+ 'status',+ 'version',+ 'filters',+ ]) as typeof result+ return await withPostHogUrl(context, filtered, `/feature_flags/${filtered.id}`)+ },+})++const FeatureFlagSetReleaseConditionRolloutSchema = () => {+ const FeatureFlagsSetReleaseConditionRolloutCreateBody =+ orvalSchemas.FeatureFlagsSetReleaseConditionRolloutCreateBody()+ const FeatureFlagsSetReleaseConditionRolloutCreateParams =+ orvalSchemas.FeatureFlagsSetReleaseConditionRolloutCreateParams()+ return z.preprocess(+ normalizeParamAliases({ id: ['flagId', 'flag_id', 'feature_flag_id', 'featureFlagId'] }),+ FeatureFlagsSetReleaseConditionRolloutCreateParams.omit({ project_id: true })+ .extend(FeatureFlagsSetReleaseConditionRolloutCreateBody.shape)+ .extend({+ id: z.preprocess(castStringToInt, FeatureFlagsSetReleaseConditionRolloutCreateParams.shape['id']),+ })+ )+}++const featureFlagSetReleaseConditionRollout = (): ToolBase<+ ReturnType<typeof FeatureFlagSetReleaseConditionRolloutSchema>,+ WithPostHogUrl<Schemas.FeatureFlag>+> => ({+ name: 'feature-flag-set-release-condition-rollout',+ schema: FeatureFlagSetReleaseConditionRolloutSchema(),+ handler: async (+ context: Context,+ params: z.infer<ReturnType<typeof FeatureFlagSetReleaseConditionRolloutSchema>>+ ) => {+ const projectId = await context.stateManager.getProjectId()+ const body: Record<string, unknown> = {}+ if (params.condition_index !== undefined) {+ body['condition_index'] = params.condition_index+ }+ if (params.rollout_percentage !== undefined) {+ body['rollout_percentage'] = params.rollout_percentage+ }+ if (params.version !== undefined) {+ body['version'] = params.version+ }+ const result = await context.api.request<Schemas.FeatureFlag>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/feature_flags/${encodeURIComponent(String(params.id))}/set_release_condition_rollout/`,+ body,+ })+ const filtered = pickResponseFields(result, [+ 'id',+ 'key',+ 'active',+ 'archived',+ 'status',+ 'version',+ 'filters',+ ]) as typeof result+ return await withPostHogUrl(context, filtered, `/feature_flags/${filtered.id}`)+ },+})+const FeatureFlagUnarchiveSchema = () => {const FeatureFlagsUnarchiveCreateParams = orvalSchemas.FeatureFlagsUnarchiveCreateParams()return z.preprocess(@@ -949,6 +1047,8 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'feature-flag-enable': featureFlagEnable,'feature-flag-get-all': featureFlagGetAll,'feature-flag-get-definition': featureFlagGetDefinition,+ 'feature-flag-roll-out-to-everyone': featureFlagRollOutToEveryone,+ 'feature-flag-set-release-condition-rollout': featureFlagSetReleaseConditionRollout,'feature-flag-unarchive': featureFlagUnarchive,'feature-flags-activity-retrieve': featureFlagsActivityRetrieve,'feature-flags-bulk-delete-create': featureFlagsBulkDeleteCreate,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-roll-out-to-everyone.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-roll-out-to-everyone.jsonnew file mode 100644index 000000000000..1ed65f7e0137--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-roll-out-to-everyone.json@@ -0,0 +1,34 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "id": {+ "description": "A unique integer value identifying this feature flag.",+ "type": "number"+ },+ "variant_key": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "The variant every user gets. Required for a multivariate flag and rejected for any other flag, because a release condition decides who the flag serves and not which variant they get."+ },+ "version": {+ "anyOf": [+ {+ "minimum": 0,+ "type": "number"+ },+ {+ "type": "null"+ }+ ],+ "description": "The `version` from your most recent read of this flag. The change is refused with 409 if anyone else changed the flag after that version. A flag written before versioning reads as `null`; send that back unchanged and it is read as 0, so the value a read returns is always one this accepts."+ }+ },+ "required": ["id", "version"],+ "type": "object"+}diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-set-release-condition-rollout.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-set-release-condition-rollout.jsonnew file mode 100644index 000000000000..91f2ccb8ef3c--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-set-release-condition-rollout.json@@ -0,0 +1,34 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "condition_index": {+ "description": "Zero-based position of the release condition in `filters.groups`, counted from the read that produced `version`.",+ "minimum": 0,+ "type": "number"+ },+ "id": {+ "description": "A unique integer value identifying this feature flag.",+ "type": "number"+ },+ "rollout_percentage": {+ "description": "Percentage of the users matching that condition who are served the flag, 0 through 100. On a multivariate flag this is how many matching users get a variant at all, not how the variants are split between them. Fractional percentages such as 0.5 are accepted, the same as a write that sends `filters`.",+ "maximum": 100,+ "minimum": 0,+ "type": "number"+ },+ "version": {+ "anyOf": [+ {+ "minimum": 0,+ "type": "number"+ },+ {+ "type": "null"+ }+ ],+ "description": "The `version` from your most recent read of this flag. The change is refused with 409 if anyone else changed the flag after that version. A flag written before versioning reads as `null`; send that back unchanged and it is read as 0, so the value a read returns is always one this accepts."+ }+ },+ "required": ["id", "condition_index", "rollout_percentage", "version"],+ "type": "object"+}diff --git a/services/mcp/tests/unit/experiment-id-aliases.test.ts b/services/mcp/tests/unit/experiment-id-aliases.test.tsindex a9d91d27d5b6..f919f476dc63 100644--- a/services/mcp/tests/unit/experiment-id-aliases.test.ts+++ b/services/mcp/tests/unit/experiment-id-aliases.test.ts@@ -133,6 +133,8 @@ describe('feature flag id aliases', () => {'feature-flag-disable','feature-flag-enable','feature-flag-get-definition',+ 'feature-flag-roll-out-to-everyone',+ 'feature-flag-set-release-condition-rollout','feature-flag-unarchive','feature-flags-activity-retrieve','feature-flags-dependent-flags-retrieve',@@ -145,6 +147,8 @@ describe('feature flag id aliases', () => {const REQUIRED_EXTRAS: Record<string, Record<string, unknown>> = {'feature-flags-test-evaluation-create': { distinct_id: 'user-1' },+ 'feature-flag-roll-out-to-everyone': { version: 3 },+ 'feature-flag-set-release-condition-rollout': { condition_index: 0, rollout_percentage: 25, version: 3 },}// `id` on these is a scheduled change id, not a flag id.diff --git a/services/mcp/tests/unit/feature-flag-lifecycle-tools.test.ts b/services/mcp/tests/unit/feature-flag-lifecycle-tools.test.tsindex ecd724bb8fb5..339cee85b7fd 100644--- a/services/mcp/tests/unit/feature-flag-lifecycle-tools.test.ts+++ b/services/mcp/tests/unit/feature-flag-lifecycle-tools.test.ts@@ -12,6 +12,25 @@ const LIFECYCLE_TOOLS = ['feature-flag-unarchive',]+const ROLLOUT_TOOLS = [+ {+ name: 'feature-flag-roll-out-to-everyone',+ keys: ['id', 'variant_key', 'version'],+ required: ['id', 'version'],+ input: { id: 42, version: 3, variant_key: 'control' },+ path: '/api/projects/17/feature_flags/42/roll_out_to_everyone/',+ body: { version: 3, variant_key: 'control' },+ },+ {+ name: 'feature-flag-set-release-condition-rollout',+ keys: ['condition_index', 'id', 'rollout_percentage', 'version'],+ required: ['id', 'condition_index', 'rollout_percentage', 'version'],+ input: { id: 42, condition_index: 1, rollout_percentage: 25, version: 3 },+ path: '/api/projects/17/feature_flags/42/set_release_condition_rollout/',+ body: { condition_index: 1, rollout_percentage: 25, version: 3 },+ },+] as const+describe('feature flag lifecycle tools', () => {// The snapshot test would also catch a `filters` param appearing here, but it is// silenced by `vitest -u`. These assertions are not: the whole point of the lifecycle@@ -59,4 +78,40 @@ describe('feature flag lifecycle tools', () => {path: `/api/projects/17/feature_flags/42/${name.replace('feature-flag-', '')}/`,})})+ it.each(ROLLOUT_TOOLS)('$name exposes only the intended fields and annotations', ({ name, keys, required }) => {+ const tool = GENERATED_TOOL_MAP[name]?.()+ expect(tool, `${name} is missing from the generated tool map`).not.toBeUndefined()++ const schema = z.toJSONSchema(tool!.schema, { io: 'input', reused: 'inline' }) as {+ properties?: Record<string, unknown>+ required?: string[]+ }++ expect(Object.keys(schema.properties ?? {}).sort()).toEqual([...keys].sort())+ expect(schema.required?.sort()).toEqual([...required].sort())++ const definition = getToolDefinition(name)+ expect(definition.required_scopes).toEqual(['feature_flag:write'])+ expect(definition.annotations?.readOnlyHint).toBe(false)+ expect(definition.annotations?.destructiveHint).toBe(false)+ expect(definition.annotations?.idempotentHint).toBe(false)+ })++ it.each(ROLLOUT_TOOLS)(+ '$name posts the version and rollout fields to its endpoint',+ async ({ name, input, path, body }) => {+ const requestMock = vi.fn().mockResolvedValue({ id: 42 })+ const context = {+ api: {+ request: requestMock,+ getProjectBaseUrl: () => 'https://app.posthog.com/project/17',+ },+ stateManager: { getProjectId: vi.fn().mockResolvedValue('17') },+ } as unknown as Context++ await GENERATED_TOOL_MAP[name]!().handler(context, input)++ expect(requestMock).toHaveBeenCalledExactlyOnceWith({ method: 'POST', path, body })+ }+ )})