: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
fix(flags): expose ensure_experience_continuity in MCP flag tools (#63880)
Lucky negic2d3c77f54c6
diff --git a/products/feature_flags/backend/api/feature_flag.py b/products/feature_flags/backend/api/feature_flag.pyindex a212756d1536..0d5ff77c4872 100644--- a/products/feature_flags/backend/api/feature_flag.py+++ b/products/feature_flags/backend/api/feature_flag.py@@ -638,6 +638,12 @@ class FeatureFlagCreateRequestSchemaSerializer(serializers.Serializer):allow_null=True,help_text="Whether this flag is a remote configuration flag that delivers a payload rather than gating a feature.",)+ ensure_experience_continuity = serializers.BooleanField(+ required=False,+ allow_null=True,+ help_text="Whether to persist a user's flag value across the anonymous-to-identified transition "+ "(the 'persist across authentication steps' option). Incompatible with device_id bucketing.",+ )class FeatureFlagPartialUpdateRequestSchemaSerializer(serializers.Serializer):@@ -664,6 +670,12 @@ class FeatureFlagPartialUpdateRequestSchemaSerializer(serializers.Serializer):allow_null=True,help_text="Whether this flag is a remote configuration flag that delivers a payload rather than gating a feature.",)+ ensure_experience_continuity = serializers.BooleanField(+ required=False,+ allow_null=True,+ help_text="Whether to persist a user's flag value across the anonymous-to-identified transition "+ "(the 'persist across authentication steps' option). Incompatible with device_id bucketing.",+ )class FeatureFlagExperimentSetMetadataSerializer(serializers.Serializer):diff --git a/products/feature_flags/backend/api/test/feature_flag_openapi_test_helpers.py b/products/feature_flags/backend/api/test/feature_flag_openapi_test_helpers.pynew file mode 100644index 000000000000..04c0be2d46e3--- /dev/null+++ b/products/feature_flags/backend/api/test/feature_flag_openapi_test_helpers.py@@ -0,0 +1,41 @@+"""Shared helpers for ``test_feature_flag_openapi.py`` — not a test module itself."""++from rest_framework import serializers++from products.feature_flags.backend.api.feature_flag import FeatureFlagSerializer++# Runtime FeatureFlagSerializer fields that are writable but intentionally absent from the+# agent-facing ``*RequestSchemaSerializer`` doc serializers (and therefore the OpenAPI spec,+# generated types, and MCP tools). Each omission is deliberate: to expose a field, add it to+# both doc serializers and to ``tools.yaml`` include_params; to keep it hidden, list it here+# with a reason.+FEATURE_FLAG_REQUEST_SCHEMA_EXCLUDED_RUNTIME_FIELDS: frozenset[str] = frozenset(+ {+ "_create_in_folder", # create-only write_only helper for folder placement+ "_should_create_usage_dashboard", # create-only write_only internal toggle+ "analytics_dashboards", # relational link managed via dashboards, not the flag create/update surface+ "bucketing_identifier", # runtime-writable but not yet on the agent-facing MCP contract; candidate for future exposure (#63823)+ "created_at", # server-managed timestamp, not agent-facing+ "creation_context", # write_only origin-product marker set by internal callers+ "deleted", # soft-delete handled via the DELETE endpoint, not the create/update body+ "evaluation_runtime", # runtime-writable but not yet on the agent-facing MCP contract; candidate for future exposure (#63823)+ "has_encrypted_payloads", # server-managed, derived from payload encryption+ "has_enriched_analytics", # internal analytics flag, not agent-facing+ "last_called_at", # server-managed usage timestamp, not agent-facing+ "performed_rollback", # internal rollback state+ "rollback_conditions", # legacy rollback config, not agent-facing+ "version", # server-managed optimistic-concurrency counter+ }+)+++def feature_flag_request_schema_runtime_field_names() -> frozenset[str]:+ serializer = FeatureFlagSerializer()+ writable: set[str] = set()+ for name, field in serializer.fields.items():+ if isinstance(field, serializers.SerializerMethodField):+ continue+ if getattr(field, "read_only", False):+ continue+ writable.add(name)+ return frozenset(writable - FEATURE_FLAG_REQUEST_SCHEMA_EXCLUDED_RUNTIME_FIELDS)diff --git a/products/feature_flags/backend/api/test/test_feature_flag_openapi.py b/products/feature_flags/backend/api/test/test_feature_flag_openapi.pynew file mode 100644index 000000000000..5528dd324a13--- /dev/null+++ b/products/feature_flags/backend/api/test/test_feature_flag_openapi.py@@ -0,0 +1,29 @@+from parameterized import parameterized++from products.feature_flags.backend.api.feature_flag import (+ FeatureFlagCreateRequestSchemaSerializer,+ FeatureFlagPartialUpdateRequestSchemaSerializer,+)+from products.feature_flags.backend.api.test.feature_flag_openapi_test_helpers import (+ feature_flag_request_schema_runtime_field_names,+)+++class TestFeatureFlagRequestSchemaContract:+ @parameterized.expand(+ [+ ("create", FeatureFlagCreateRequestSchemaSerializer),+ ("partial_update", FeatureFlagPartialUpdateRequestSchemaSerializer),+ ]+ )+ def test_request_schema_covers_agent_facing_runtime_fields(self, _name, schema_serializer) -> None:+ runtime_fields = feature_flag_request_schema_runtime_field_names()+ documented = frozenset(schema_serializer().fields.keys())+ missing = runtime_fields - documented+ assert not missing, (+ f"{schema_serializer.__name__} must document every agent-facing FeatureFlagSerializer input. "+ f"Missing: {sorted(missing)}. extend_schema(request=...) replaces the whole request body, so a "+ "writable runtime field absent here never reaches the OpenAPI spec or MCP tools. Add the field to "+ "both doc serializers and tools.yaml include_params to expose it, or to "+ "FEATURE_FLAG_REQUEST_SCHEMA_EXCLUDED_RUNTIME_FIELDS with a reason to keep it hidden."+ )diff --git a/products/feature_flags/frontend/generated/api.schemas.ts b/products/feature_flags/frontend/generated/api.schemas.tsindex 9e1c561fe344..fc9ed807ec89 100644--- a/products/feature_flags/frontend/generated/api.schemas.ts+++ b/products/feature_flags/frontend/generated/api.schemas.ts@@ -701,6 +701,11 @@ export interface FeatureFlagCreateRequestSchemaApi {* @nullable*/is_remote_configuration?: boolean | null+ /**+ * Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing.+ * @nullable+ */+ ensure_experience_continuity?: boolean | null}export interface PatchedFeatureFlagPartialUpdateRequestSchemaApi {@@ -721,6 +726,11 @@ export interface PatchedFeatureFlagPartialUpdateRequestSchemaApi {* @nullable*/is_remote_configuration?: boolean | null+ /**+ * Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing.+ * @nullable+ */+ ensure_experience_continuity?: boolean | null}export interface ChangeApi {diff --git a/products/feature_flags/frontend/generated/api.zod.ts b/products/feature_flags/frontend/generated/api.zod.tsindex 8c377e671176..4d48e13d4eed 100644--- a/products/feature_flags/frontend/generated/api.zod.ts+++ b/products/feature_flags/frontend/generated/api.zod.ts@@ -372,6 +372,12 @@ export const FeatureFlagsCreateBody = /* @__PURE__ */ zod.object({.describe('Whether this flag is a remote configuration flag that delivers a payload rather than gating a feature.'),+ ensure_experience_continuity: zod+ .boolean()+ .nullish()+ .describe(+ "Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing."+ ),})/**@@ -759,6 +765,12 @@ export const FeatureFlagsPartialUpdateBody = /* @__PURE__ */ zod.object({.describe('Whether this flag is a remote configuration flag that delivers a payload rather than gating a feature.'),+ ensure_experience_continuity: zod+ .boolean()+ .nullish()+ .describe(+ "Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing."+ ),})/**diff --git a/products/feature_flags/mcp/tools.yaml b/products/feature_flags/mcp/tools.yamlindex 3c1c18531232..6b1e356ff4ce 100644--- a/products/feature_flags/mcp/tools.yaml+++ b/products/feature_flags/mcp/tools.yaml@@ -42,12 +42,18 @@ tools:- tags- evaluation_contexts- is_remote_configuration+ - ensure_experience_continuityparam_overrides:is_remote_configuration:description:Whether this flag delivers a payload instead of gating a feature (Remote Config mode). When true, set thedelivered payload through the `filters` param under `filters.payloads.true` as a JSON-encodedstring. There is no dedicated payload parameter.+ ensure_experience_continuity:+ description:+ Whether to persist the flag's value for a user across the anonymous-to-identified transition (the "persist+ across authentication steps" option in the UI). Keeps a user's evaluated value stable once they log+ in. Incompatible with `device_id` bucketing.delete-feature-flag:operation: feature_flags_destroyenabled: true@@ -426,6 +432,7 @@ tools:- tags- evaluation_contexts- is_remote_configuration+ - ensure_experience_continuityparam_overrides:id:cast: string-int@@ -434,3 +441,8 @@ tools:Whether this flag delivers a payload instead of gating a feature (Remote Config mode). When true, set thedelivered payload through the `filters` param under `filters.payloads.true` as a JSON-encodedstring. There is no dedicated payload parameter.+ ensure_experience_continuity:+ description:+ Whether to persist the flag's value for a user across the anonymous-to-identified transition (the "persist+ across authentication steps" option in the UI). Keeps a user's evaluated value stable once they log+ in. Incompatible with `device_id` bucketing.diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex cff501ccc8d4..0927cdf03ae4 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -21779,6 +21779,11 @@ export namespace Schemas {* @nullable*/is_remote_configuration?: boolean | null;+ /**+ * Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing.+ * @nullable+ */+ ensure_experience_continuity?: boolean | null;}export interface FeatureFlagStatusResponse {@@ -34230,6 +34235,11 @@ export namespace Schemas {* @nullable*/is_remote_configuration?: boolean | null;+ /**+ * Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing.+ * @nullable+ */+ ensure_experience_continuity?: boolean | null;}/**diff --git a/services/mcp/src/generated/feature_flags/api.ts b/services/mcp/src/generated/feature_flags/api.tsindex 851a490b5b0c..65167e97a2b8 100644--- a/services/mcp/src/generated/feature_flags/api.ts+++ b/services/mcp/src/generated/feature_flags/api.ts@@ -390,6 +390,12 @@ export const FeatureFlagsCreateBody = /* @__PURE__ */ zod.object({.describe('Whether this flag is a remote configuration flag that delivers a payload rather than gating a feature.'),+ ensure_experience_continuity: zod+ .boolean()+ .nullish()+ .describe(+ "Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing."+ ),})/**@@ -720,6 +726,12 @@ export const FeatureFlagsPartialUpdateBody = /* @__PURE__ */ zod.object({.describe('Whether this flag is a remote configuration flag that delivers a payload rather than gating a feature.'),+ ensure_experience_continuity: zod+ .boolean()+ .nullish()+ .describe(+ "Whether to persist a user's flag value across the anonymous-to-identified transition (the 'persist across authentication steps' option). Incompatible with device_id bucketing."+ ),})/**diff --git a/services/mcp/src/tools/generated/feature_flags.ts b/services/mcp/src/tools/generated/feature_flags.tsindex 97c34e0952ea..585737440cb8 100644--- a/services/mcp/src/tools/generated/feature_flags.ts+++ b/services/mcp/src/tools/generated/feature_flags.ts@@ -39,6 +39,9 @@ const CreateFeatureFlagSchema = FeatureFlagsCreateBody.extend({is_remote_configuration: FeatureFlagsCreateBody.shape['is_remote_configuration'].describe('Whether this flag delivers a payload instead of gating a feature (Remote Config mode). When true, set the delivered payload through the `filters` param under `filters.payloads.true` as a JSON-encoded string. There is no dedicated payload parameter.'),+ ensure_experience_continuity: FeatureFlagsCreateBody.shape['ensure_experience_continuity'].describe(+ 'Whether to persist the flag\'s value for a user across the anonymous-to-identified transition (the "persist across authentication steps" option in the UI). Keeps a user\'s evaluated value stable once they log in. Incompatible with `device_id` bucketing.'+ ),})const createFeatureFlag = (): ToolBase<typeof CreateFeatureFlagSchema, WithPostHogUrl<Schemas.FeatureFlag>> => ({@@ -68,6 +71,9 @@ const createFeatureFlag = (): ToolBase<typeof CreateFeatureFlagSchema, WithPostHif (params.is_remote_configuration !== undefined) {body['is_remote_configuration'] = params.is_remote_configuration}+ if (params.ensure_experience_continuity !== undefined) {+ body['ensure_experience_continuity'] = params.ensure_experience_continuity+ }const result = await context.api.request<Schemas.FeatureFlag>({method: 'POST',path: `/api/projects/${encodeURIComponent(String(projectId))}/feature_flags/`,@@ -600,6 +606,9 @@ const UpdateFeatureFlagSchema = FeatureFlagsPartialUpdateParams.omit({ project_iis_remote_configuration: FeatureFlagsPartialUpdateBody.shape['is_remote_configuration'].describe('Whether this flag delivers a payload instead of gating a feature (Remote Config mode). When true, set the delivered payload through the `filters` param under `filters.payloads.true` as a JSON-encoded string. There is no dedicated payload parameter.'),+ ensure_experience_continuity: FeatureFlagsPartialUpdateBody.shape['ensure_experience_continuity'].describe(+ 'Whether to persist the flag\'s value for a user across the anonymous-to-identified transition (the "persist across authentication steps" option in the UI). Keeps a user\'s evaluated value stable once they log in. Incompatible with `device_id` bucketing.'+ ),})const updateFeatureFlag = (): ToolBase<typeof UpdateFeatureFlagSchema, WithPostHogUrl<Schemas.FeatureFlag>> => ({@@ -629,6 +638,9 @@ const updateFeatureFlag = (): ToolBase<typeof UpdateFeatureFlagSchema, WithPostHif (params.is_remote_configuration !== undefined) {body['is_remote_configuration'] = params.is_remote_configuration}+ if (params.ensure_experience_continuity !== undefined) {+ body['ensure_experience_continuity'] = params.ensure_experience_continuity+ }const result = await context.api.request<Schemas.FeatureFlag>({method: 'PATCH',path: `/api/projects/${encodeURIComponent(String(projectId))}/feature_flags/${encodeURIComponent(String(params.id))}/`,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.jsonindex 2f60119682c2..5daf1e140e2f 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json@@ -5,6 +5,17 @@"description": "Whether the feature flag is active.","type": "boolean"},+ "ensure_experience_continuity": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Whether to persist the flag's value for a user across the anonymous-to-identified transition (the \"persist across authentication steps\" option in the UI). Keeps a user's evaluated value stable once they log in. Incompatible with `device_id` bucketing."+ },"evaluation_contexts": {"description": "Evaluation contexts that control where this flag evaluates at runtime.","items": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.jsonindex 0de8a0eb7160..cd38b9d62a64 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json@@ -5,6 +5,17 @@"description": "Whether the feature flag is active.","type": "boolean"},+ "ensure_experience_continuity": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Whether to persist the flag's value for a user across the anonymous-to-identified transition (the \"persist across authentication steps\" option in the UI). Keeps a user's evaluated value stable once they log in. Incompatible with `device_id` bucketing."+ },"evaluation_contexts": {"description": "Evaluation contexts that control where this flag evaluates at runtime.","items": {