Skip to content

: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.

chore(flags): expose the cross-project dependency preflight to agents (#90935)

James Gilld63178e9a156
diff --git a/products/feature_flags/backend/api/test/test_organization_feature_flag.py b/products/feature_flags/backend/api/test/test_organization_feature_flag.py
index 74d169345860..5aa386d24a1f 100644
--- a/products/feature_flags/backend/api/test/test_organization_feature_flag.py
+++ b/products/feature_flags/backend/api/test/test_organization_feature_flag.py
@@ -2020,6 +2020,21 @@ class TestOrganizationFeatureFlagCopy(APIBaseTest, QueryMatchingTest):
self.assertEqual(body["warnings"], ["Project not found."])
self.assertEqual(body["reason"], "Project not found.")
+ def test_copy_feature_flag_dependency_requirements_aggregates_mixed_targets(self):
+ target_team_3 = Team.objects.create(organization=self.organization)
+ flag_a, _ = self._create_dependency_chain("flag-a", "flag-b")
+ FeatureFlag.objects.create(team=self.team_2, created_by=self.user, key="flag-b", active=True)
+
+ response = self._post_dependency_requirements(flag_a, [self.team_2.id, target_team_3.id])
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ body = response.json()
+ self.assertTrue(body["can_copy_dependencies"])
+ self.assertEqual(body["dependency_count"], 1)
+ self.assertEqual(body["copied_dependency_keys"], ["flag-b"])
+ self.assertEqual(body["reused_dependency_keys"], [])
+ self.assertEqual(body["warnings"], [])
+
def test_copy_feature_flag_rejects_more_than_50_target_projects(self):
flag_to_copy = FeatureFlag.objects.create(
team=self.team_1,
diff --git a/products/feature_flags/mcp/tools.yaml b/products/feature_flags/mcp/tools.yaml
index 7739e243af05..f900bdb2382e 100644
--- a/products/feature_flags/mcp/tools.yaml
+++ b/products/feature_flags/mcp/tools.yaml
@@ -384,6 +384,33 @@ tools:
Add, remove, or replace tags on multiple feature flags in one call. Provide `ids` (up to 500), an `action`
('add', 'remove', or 'set'), and a list of tag names. Returns `updated` (per-flag final tag list) and
`skipped` (flags missing or without edit permission, with reason).
+ feature-flags-copy-dependencies-check:
+ operation: feature_flags_copy_flags_dependency_requirements_create
+ enabled: true
+ scopes:
+ - feature_flag:write
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Check whether a flag's dependencies can be copied
+ description: >
+ Preview what a cross-project copy would do to a flag's transitive flag dependencies. Copies nothing and
+ changes nothing. Provide `feature_flag_key`, `from_project` (the source project ID) and
+ `target_project_ids`. Returns `can_copy_dependencies`, `dependency_count`, `copied_dependency_keys`
+ (dependencies missing from a target project, which a copy would create), `reused_dependency_keys`
+ (dependencies that already have an active same-key flag in every target project), plus `warnings` and a
+ human-readable `reason`. A false `can_copy_dependencies` does not always mean the copy is blocked: it is
+ also false when there is nothing to copy, because the flag has no dependencies or every dependency is
+ already satisfied in each target project. Read `warnings` to tell the two apart and report a problem only
+ when it is non-empty. Call this before every `feature-flags-copy-flags-create` copy; it is read-only and
+ returns an empty result when the flag has no dependencies. Set that tool's `copy_dependencies` only when the
+ user approves copying the keys this check reports. Requires write scope because it checks the same copy
+ eligibility and edit permissions the copy itself enforces.
+ include_params:
+ - feature_flag_key
+ - from_project
+ - target_project_ids
feature-flags-copy-flags-create:
operation: feature_flags_copy_flags_create
enabled: true
@@ -401,9 +428,6 @@ tools:
existing active same-key dependencies in target projects are reused, disabled same-key dependencies are left
untouched, and warnings explain any dependencies or schedules that could not be copied. Returns lists of
successful and failed copies.
- feature-flags-copy-flags-dependency-requirements-create:
- operation: feature_flags_copy_flags_dependency_requirements_create
- enabled: false
feature-flags-create-static-cohort-for-flag-create:
operation: feature_flags_create_static_cohort_for_flag_create
enabled: false
diff --git a/products/feature_flags/skills/copying-flags-across-projects/SKILL.md b/products/feature_flags/skills/copying-flags-across-projects/SKILL.md
index 4980de5cc4d3..38f51e36a9e4 100644
--- a/products/feature_flags/skills/copying-flags-across-projects/SKILL.md
+++ b/products/feature_flags/skills/copying-flags-across-projects/SKILL.md
@@ -36,22 +36,28 @@ Targets must be in the same organization as the source. Call `posthog:projects-g
For a multi-target copy, the tool accepts up to 50 target project ids in a single call. Successes and failures are reported per target, so a partial failure does not block the rest.
-### 3. Preview the source flag
+### 3. Preview the source flag and its dependencies
-Call `posthog:feature-flag-get-definition` on the source flag and present a concise summary to the user before copying:
+Call `posthog:feature-flag-get-definition` on the source flag. Then always call `posthog:feature-flags-copy-dependencies-check` with `feature_flag_key`, `from_project`, and `target_project_ids`, rather than trying to detect dependencies first — it copies nothing, and returns an empty result with no warnings when the flag has none, so running it on every copy is cheap and never skips a real dependency.
+
+A false `can_copy_dependencies` does not always mean the copy is blocked. It is also false when there is nothing to copy. Report a problem only when `warnings` is non-empty.
+
+Present a concise summary to the user before copying:
- Flag key, name, and active state in the source
- Filter groups (rollout %, property filters, variant splits)
- Any cohort references in `filters.groups[].properties[]` — these will be remapped server-side, but the user should know whether the target project already has matching cohorts
- Whether the flag has encrypted payloads (`has_encrypted_payloads`) or is remote configuration (`is_remote_configuration`)
- Whether scheduled changes exist (the user can opt to copy them in step 4)
+- The dependency check's `copied_dependency_keys` (dependencies a copy would create in a target), `reused_dependency_keys` (dependencies a target already satisfies), and any `warnings`
### 4. Confirm copy options
-Default to the safest combination and ask the user to override only if they explicitly want different behavior:
+One confirmation covers all three options. Default to the safest combination and ask the user to override only if they explicitly want different behavior:
- **`disable_copied_flag: true`** — the copied flag lands disabled in the target. Recommended by default; turning a flag on in a new project should be a deliberate, observed action.
- **`copy_schedule: false`** — scheduled changes do not come along. Recommended by default; schedules are usually project-specific.
+- **`copy_dependencies: false`** — dependency flags do not come along. Set it to `true` only when the user approves copying the keys step 3's check reported.
If the user says "promote it as-is" or "turn it on in prod", switch `disable_copied_flag` to `false`. If they say "include the rollout schedule" or "with the scheduled rollout", switch `copy_schedule` to `true`.
@@ -64,6 +70,7 @@ Call `posthog:feature-flags-copy-flags-create` with:
- `target_project_ids`: the resolved list of target project ids
- `disable_copied_flag`: from step 4 (default `true`)
- `copy_schedule`: from step 4 (default `false`)
+- `copy_dependencies`: from step 4 (default `false`). Omitting it silently skips dependency copying, even when the user approved it.
### 6. Report per-target outcome
@@ -104,7 +111,8 @@ If any targets failed, ask the user whether to retry the failed ones, skip them,
## Available tools
-- `posthog:feature-flags-copy-flags-create` — performs the copy. Required fields: `feature_flag_key`, `from_project`, `target_project_ids`. Optional: `disable_copied_flag`, `copy_schedule`.
+- `posthog:feature-flags-copy-flags-create` — performs the copy. Required fields: `feature_flag_key`, `from_project`, `target_project_ids`. Optional: `disable_copied_flag`, `copy_schedule`, `copy_dependencies`.
+- `posthog:feature-flags-copy-dependencies-check` — previews what a copy would do to the flag's transitive flag dependencies. Copies nothing. Call it before every copy; it returns an empty result when the flag has no dependencies.
- `posthog:feature-flag-get-all` — find a flag by key/name in a given project when the user only gave a friendly name.
- `posthog:feature-flag-get-definition` — fetch the full source flag (filters, variants, cohort references, encryption flags) so you can preview before copying.
- `posthog:projects-get` — list projects in the active organization, used to resolve and validate target project ids.
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 358914d73dd6..4f5ad1dba036 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -5003,6 +5003,20 @@
"readOnlyHint": false
}
},
+ "feature-flags-copy-dependencies-check": {
+ "description": "Preview what a cross-project copy would do to a flag's transitive flag dependencies. Copies nothing and changes nothing. Provide `feature_flag_key`, `from_project` (the source project ID) and `target_project_ids`. Returns `can_copy_dependencies`, `dependency_count`, `copied_dependency_keys` (dependencies missing from a target project, which a copy would create), `reused_dependency_keys` (dependencies that already have an active same-key flag in every target project), plus `warnings` and a human-readable `reason`. A false `can_copy_dependencies` does not always mean the copy is blocked: it is also false when there is nothing to copy, because the flag has no dependencies or every dependency is already satisfied in each target project. Read `warnings` to tell the two apart and report a problem only when it is non-empty. Call this before every `feature-flags-copy-flags-create` copy; it is read-only and returns an empty result when the flag has no dependencies. Set that tool's `copy_dependencies` only when the user approves copying the keys this check reports. Requires write scope because it checks the same copy eligibility and edit permissions the copy itself enforces.",
+ "category": "Feature flags",
+ "feature": "flags",
+ "summary": "Check whether a flag's dependencies can be copied",
+ "title": "Check whether a flag's dependencies can be copied",
+ "required_scopes": ["feature_flag:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"feature-flags-copy-flags-create": {
"description": "Copy a feature flag from one project to other projects within the same organization. Provide the flag key, source project ID, and a list of target project IDs. Optionally copy scheduled changes with copy_schedule. Set copy_dependencies only when the user explicitly wants missing transitive flag dependencies copied too; existing active same-key dependencies in target projects are reused, disabled same-key dependencies are left untouched, and warnings explain any dependencies or schedules that could not be copied. Returns lists of successful and failed copies.",
"category": "Feature flags",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 785832430aad..ea429c656cab 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -5172,6 +5172,20 @@
"readOnlyHint": false
}
},
+ "feature-flags-copy-dependencies-check": {
+ "description": "Preview what a cross-project copy would do to a flag's transitive flag dependencies. Copies nothing and changes nothing. Provide `feature_flag_key`, `from_project` (the source project ID) and `target_project_ids`. Returns `can_copy_dependencies`, `dependency_count`, `copied_dependency_keys` (dependencies missing from a target project, which a copy would create), `reused_dependency_keys` (dependencies that already have an active same-key flag in every target project), plus `warnings` and a human-readable `reason`. A false `can_copy_dependencies` does not always mean the copy is blocked: it is also false when there is nothing to copy, because the flag has no dependencies or every dependency is already satisfied in each target project. Read `warnings` to tell the two apart and report a problem only when it is non-empty. Call this before every `feature-flags-copy-flags-create` copy; it is read-only and returns an empty result when the flag has no dependencies. Set that tool's `copy_dependencies` only when the user approves copying the keys this check reports. Requires write scope because it checks the same copy eligibility and edit permissions the copy itself enforces.",
+ "category": "Feature flags",
+ "feature": "flags",
+ "summary": "Check whether a flag's dependencies can be copied",
+ "title": "Check whether a flag's dependencies can be copied",
+ "required_scopes": ["feature_flag:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"feature-flags-copy-flags-create": {
"description": "Copy a feature flag from one project to other projects within the same organization. Provide the flag key, source project ID, and a list of target project IDs. Optionally copy scheduled changes with copy_schedule. Set copy_dependencies only when the user explicitly wants missing transitive flag dependencies copied too; existing active same-key dependencies in target projects are reused, disabled same-key dependencies are left untouched, and warnings explain any dependencies or schedules that could not be copied. Returns lists of successful and failed copies.",
"category": "Feature flags",
diff --git a/services/mcp/src/generated/feature_flags/api.ts b/services/mcp/src/generated/feature_flags/api.ts
index 785642981058..f97424086302 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 25 enabled ops
+ * PostHog API - MCP 26 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -46,6 +46,26 @@ export const FeatureFlagsCopyFlagsCreateBody = () => zod.object({
.describe('Whether to also copy missing feature flags that this flag depends on'),
})
+export const FeatureFlagsCopyFlagsDependencyRequirementsCreateParams = () => zod.object({
+ organization_id: zod
+ .string()
+ .describe(
+ "ID of the organization you're trying to access. To find the ID of the organization, make a call to \/api\/organizations\/."
+ ),
+})
+
+export const featureFlagsCopyFlagsDependencyRequirementsCreateBodyTargetProjectIdsMax = 50
+
+export const FeatureFlagsCopyFlagsDependencyRequirementsCreateBody = () => zod.object({
+ feature_flag_key: zod.string().describe('Key of the feature flag to check'),
+ from_project: zod.number().describe('Source project ID to copy the flag from'),
+ target_project_ids: zod
+ .array(zod.number())
+ .min(1)
+ .max(featureFlagsCopyFlagsDependencyRequirementsCreateBodyTargetProjectIdsMax)
+ .describe('List of target project IDs to check dependency copy eligibility for'),
+})
+
/**
* 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.ts
index fff91d492b2b..93af7e5847f9 100644
--- a/services/mcp/src/tools/generated/feature_flags.ts
+++ b/services/mcp/src/tools/generated/feature_flags.ts
@@ -416,6 +416,39 @@ const featureFlagsBulkUpdateTagsCreate = (): ToolBase<
},
})
+const FeatureFlagsCopyDependenciesCheckSchema = () => {
+ const FeatureFlagsCopyFlagsDependencyRequirementsCreateBody =
+ orvalSchemas.FeatureFlagsCopyFlagsDependencyRequirementsCreateBody()
+ return FeatureFlagsCopyFlagsDependencyRequirementsCreateBody
+}
+
+const featureFlagsCopyDependenciesCheck = (): ToolBase<
+ ReturnType<typeof FeatureFlagsCopyDependenciesCheckSchema>,
+ Schemas.CopyFlagsDependencyRequirementsResponse
+> => ({
+ name: 'feature-flags-copy-dependencies-check',
+ schema: FeatureFlagsCopyDependenciesCheckSchema(),
+ handler: async (context: Context, params: z.infer<ReturnType<typeof FeatureFlagsCopyDependenciesCheckSchema>>) => {
+ const orgId = await context.stateManager.getOrgID()
+ const body: Record<string, unknown> = {}
+ if (params.feature_flag_key !== undefined) {
+ body['feature_flag_key'] = params.feature_flag_key
+ }
+ if (params.from_project !== undefined) {
+ body['from_project'] = params.from_project
+ }
+ if (params.target_project_ids !== undefined) {
+ body['target_project_ids'] = params.target_project_ids
+ }
+ const result = await context.api.request<Schemas.CopyFlagsDependencyRequirementsResponse>({
+ method: 'POST',
+ path: `/api/organizations/${encodeURIComponent(String(orgId))}/feature_flags/copy_flags/dependency_requirements/`,
+ body,
+ })
+ return result
+ },
+})
+
const FeatureFlagsCopyFlagsCreateSchema = () => {
const FeatureFlagsCopyFlagsCreateBody = orvalSchemas.FeatureFlagsCopyFlagsCreateBody()
return FeatureFlagsCopyFlagsCreateBody
@@ -883,6 +916,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'feature-flags-bulk-delete-create': featureFlagsBulkDeleteCreate,
'feature-flags-bulk-keys-retrieve': featureFlagsBulkKeysRetrieve,
'feature-flags-bulk-update-tags-create': featureFlagsBulkUpdateTagsCreate,
+ 'feature-flags-copy-dependencies-check': featureFlagsCopyDependenciesCheck,
'feature-flags-copy-flags-create': featureFlagsCopyFlagsCreate,
'feature-flags-dependent-flags-retrieve': featureFlagsDependentFlagsRetrieve,
'feature-flags-evaluation-reasons-retrieve': featureFlagsEvaluationReasonsRetrieve,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-copy-dependencies-check.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-copy-dependencies-check.json
new file mode 100644
index 000000000000..1d6c6f3cbd1b
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-copy-dependencies-check.json
@@ -0,0 +1,24 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "feature_flag_key": {
+ "description": "Key of the feature flag to check",
+ "type": "string"
+ },
+ "from_project": {
+ "description": "Source project ID to copy the flag from",
+ "type": "number"
+ },
+ "target_project_ids": {
+ "description": "List of target project IDs to check dependency copy eligibility for",
+ "items": {
+ "type": "number"
+ },
+ "maxItems": 50,
+ "minItems": 1,
+ "type": "array"
+ }
+ },
+ "required": ["feature_flag_key", "from_project", "target_project_ids"],
+ "type": "object"
+}