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.

feat(flags): tell MCP agents about the stale flag filter (#108420)

James Gill4b791d6e3ca1
diff --git a/products/feature_flags/mcp/tools.yaml b/products/feature_flags/mcp/tools.yaml
index 421a529b3088..57fe740dcb6d 100644
--- a/products/feature_flags/mcp/tools.yaml
+++ b/products/feature_flags/mcp/tools.yaml
@@ -263,12 +263,23 @@ tools:
title: Get all feature flags
description: >
Get feature flags in the current project. Supports list filters including search by feature flag key or name
- (case-insensitive), then use the returned ID for get/update/delete tools.
+ (case-insensitive), then use the returned ID for get/update/delete tools. Pass `active: "STALE"` to list
+ only stale flags. PostHog calls a flag stale when it is enabled and was last called over 30 days ago, or was
+ never called, is over 30 days old and is rolled out to everyone. The filter does not return a never-called
+ flag with an empty `groups` list in `filters`, even when `feature-flags-status-retrieve` calls it stale.
+ Stale flags are cleanup candidates, not proof that a flag is unused. Disabled flags are not checked for
+ staleness, so `status: ACTIVE` on a disabled flag is expected. Each row carries `status`, `last_called_at`,
+ `active` and `created_at`. For the reason behind one flag's status, and its rollout summary, use
+ `feature-flags-status-retrieve`.
param_overrides:
search:
description:
Search by feature flag key or name (case-insensitive). Use this to find the flag ID for get/update/delete
tools.
+ active:
+ description:
+ Filter by flag state. `"true"` returns enabled flags, `"false"` returns disabled flags, and `"STALE"`
+ returns enabled flags that PostHog classifies as stale.
limit:
cast: string-int
offset:
@@ -281,6 +292,9 @@ tools:
- updated_at
- status
- tags
+ - last_called_at
+ - active
+ - created_at
feature-flag-get-definition:
operation: feature_flags_retrieve
enabled: true
@@ -718,7 +732,9 @@ tools:
unknown) and a human-readable reason explaining the status. The status reflects recent evaluation (whether
the flag was called), NOT rollout completeness. To determine whether a flag is fully rolled out / GA, use
the returned `rollout` object: `effectively_full_rollout` (true when targeted to everyone with no
- conditions), `has_targeting_conditions`, `max_rollout_percentage`, and `is_multivariate`.
+ conditions), `has_targeting_conditions`, `max_rollout_percentage`, and `is_multivariate`. To scan the whole
+ project for stale flags, use `feature-flag-get-all` with `active: "STALE"`. That filter does not return a
+ never-called flag with an empty `groups` list in `filters`, even when this tool calls it stale.
param_overrides:
id:
cast: string-int
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 0fd0c414fc3b..e81ee80f317b 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -5838,7 +5838,7 @@
}
},
"feature-flag-get-all": {
- "description": "Get feature flags in the current project. Supports list filters including search by feature flag key or name (case-insensitive), then use the returned ID for get/update/delete tools.",
+ "description": "Get feature flags in the current project. Supports list filters including search by feature flag key or name (case-insensitive), then use the returned ID for get/update/delete tools. Pass `active: \"STALE\"` to list only stale flags. PostHog calls a flag stale when it is enabled and was last called over 30 days ago, or was never called, is over 30 days old and is rolled out to everyone. The filter does not return a never-called flag with an empty `groups` list in `filters`, even when `feature-flags-status-retrieve` calls it stale. Stale flags are cleanup candidates, not proof that a flag is unused. Disabled flags are not checked for staleness, so `status: ACTIVE` on a disabled flag is expected. Each row carries `status`, `last_called_at`, `active` and `created_at`. For the reason behind one flag's status, and its rollout summary, use `feature-flags-status-retrieve`.",
"category": "Feature flags",
"feature": "flags",
"summary": "Get all feature flags",
@@ -6034,7 +6034,7 @@
}
},
"feature-flags-status-retrieve": {
- "description": "Check the health and evaluation status of a feature flag by ID. Returns a status (active, stale, deleted, or unknown) and a human-readable reason explaining the status. The status reflects recent evaluation (whether the flag was called), NOT rollout completeness. To determine whether a flag is fully rolled out / GA, use the returned `rollout` object: `effectively_full_rollout` (true when targeted to everyone with no conditions), `has_targeting_conditions`, `max_rollout_percentage`, and `is_multivariate`.",
+ "description": "Check the health and evaluation status of a feature flag by ID. Returns a status (active, stale, deleted, or unknown) and a human-readable reason explaining the status. The status reflects recent evaluation (whether the flag was called), NOT rollout completeness. To determine whether a flag is fully rolled out / GA, use the returned `rollout` object: `effectively_full_rollout` (true when targeted to everyone with no conditions), `has_targeting_conditions`, `max_rollout_percentage`, and `is_multivariate`. To scan the whole project for stale flags, use `feature-flag-get-all` with `active: \"STALE\"`. That filter does not return a never-called flag with an empty `groups` list in `filters`, even when this tool calls it stale.",
"category": "Feature flags",
"feature": "flags",
"summary": "Get feature flag status",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index f1689e7d8996..56de6593741e 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -5993,7 +5993,7 @@
}
},
"feature-flag-get-all": {
- "description": "Get feature flags in the current project. Supports list filters including search by feature flag key or name (case-insensitive), then use the returned ID for get/update/delete tools.",
+ "description": "Get feature flags in the current project. Supports list filters including search by feature flag key or name (case-insensitive), then use the returned ID for get/update/delete tools. Pass `active: \"STALE\"` to list only stale flags. PostHog calls a flag stale when it is enabled and was last called over 30 days ago, or was never called, is over 30 days old and is rolled out to everyone. The filter does not return a never-called flag with an empty `groups` list in `filters`, even when `feature-flags-status-retrieve` calls it stale. Stale flags are cleanup candidates, not proof that a flag is unused. Disabled flags are not checked for staleness, so `status: ACTIVE` on a disabled flag is expected. Each row carries `status`, `last_called_at`, `active` and `created_at`. For the reason behind one flag's status, and its rollout summary, use `feature-flags-status-retrieve`.",
"category": "Feature flags",
"feature": "flags",
"summary": "Get all feature flags",
@@ -6203,7 +6203,7 @@
}
},
"feature-flags-status-retrieve": {
- "description": "Check the health and evaluation status of a feature flag by ID. Returns a status (active, stale, deleted, or unknown) and a human-readable reason explaining the status. The status reflects recent evaluation (whether the flag was called), NOT rollout completeness. To determine whether a flag is fully rolled out / GA, use the returned `rollout` object: `effectively_full_rollout` (true when targeted to everyone with no conditions), `has_targeting_conditions`, `max_rollout_percentage`, and `is_multivariate`.",
+ "description": "Check the health and evaluation status of a feature flag by ID. Returns a status (active, stale, deleted, or unknown) and a human-readable reason explaining the status. The status reflects recent evaluation (whether the flag was called), NOT rollout completeness. To determine whether a flag is fully rolled out / GA, use the returned `rollout` object: `effectively_full_rollout` (true when targeted to everyone with no conditions), `has_targeting_conditions`, `max_rollout_percentage`, and `is_multivariate`. To scan the whole project for stale flags, use `feature-flag-get-all` with `active: \"STALE\"`. That filter does not return a never-called flag with an empty `groups` list in `filters`, even when this tool calls it stale.",
"category": "Feature flags",
"feature": "flags",
"summary": "Get feature flag status",
diff --git a/services/mcp/src/tools/generated/feature_flags.ts b/services/mcp/src/tools/generated/feature_flags.ts
index 2ca225d71efd..9c0b9c18f34e 100644
--- a/services/mcp/src/tools/generated/feature_flags.ts
+++ b/services/mcp/src/tools/generated/feature_flags.ts
@@ -207,6 +207,9 @@ const FeatureFlagGetAllSchema = () => {
search: FeatureFlagsListQueryParams.shape['search'].describe(
'Search by feature flag key or name (case-insensitive). Use this to find the flag ID for get/update/delete tools.'
),
+ active: FeatureFlagsListQueryParams.shape['active'].describe(
+ 'Filter by flag state. `"true"` returns enabled flags, `"false"` returns disabled flags, and `"STALE"` returns enabled flags that PostHog classifies as stale.'
+ ),
limit: z.preprocess(castStringToInt, FeatureFlagsListQueryParams.shape['limit']).optional(),
offset: z.preprocess(castStringToInt, FeatureFlagsListQueryParams.shape['offset']).optional(),
})
@@ -243,7 +246,17 @@ const featureFlagGetAll = (): ToolBase<
const filtered = {
...result,
results: (result.results ?? []).map((item: any) =>
- pickResponseFields(item, ['id', 'key', 'name', 'updated_at', 'status', 'tags'])
+ pickResponseFields(item, [
+ 'id',
+ 'key',
+ 'name',
+ 'updated_at',
+ 'status',
+ 'tags',
+ 'last_called_at',
+ 'active',
+ 'created_at',
+ ])
),
} as typeof result
return await withPostHogUrl(
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-get-all.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-get-all.json
index 230e96d38d93..b3bf0fdc237a 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-get-all.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flag-get-all.json
@@ -2,6 +2,7 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"active": {
+ "description": "Filter by flag state. `\"true\"` returns enabled flags, `\"false\"` returns disabled flags, and `\"STALE\"` returns enabled flags that PostHog classifies as stale.",
"enum": ["STALE", "false", "true"],
"type": "string"
},
diff --git a/services/mcp/tests/unit/feature-flag-get-all-response-shape.test.ts b/services/mcp/tests/unit/feature-flag-get-all-response-shape.test.ts
new file mode 100644
index 000000000000..f4bad57ff92b
--- /dev/null
+++ b/services/mcp/tests/unit/feature-flag-get-all-response-shape.test.ts
@@ -0,0 +1,50 @@
+import { describe, expect, it, vi } from 'vitest'
+
+import { GENERATED_TOOLS } from '@/tools/generated/feature_flags'
+import type { Context } from '@/tools/types'
+
+function createMockContext(requestMock: ReturnType<typeof vi.fn>): Context {
+ return {
+ api: {
+ request: requestMock,
+ getProjectBaseUrl: (projectId: string) => `https://us.posthog.com/project/${projectId}`,
+ } as any,
+ stateManager: { getProjectId: vi.fn().mockResolvedValue('42') } as any,
+ env: {} as any,
+ sessionManager: {} as any,
+ cache: {} as any,
+ getDistinctId: async () => 'test-distinct-id',
+ trackEvent: async () => {},
+ }
+}
+
+const staleFlag = (): Record<string, unknown> => ({
+ id: 1,
+ key: 'checkout-redesign',
+ status: 'STALE',
+ last_called_at: '2026-06-01T00:00:00Z',
+ active: true,
+ created_at: '2026-01-01T00:00:00Z',
+ filters: { groups: [{ rollout_percentage: 100, properties: [] }] },
+ created_by: { id: 7, email: '[email protected]' },
+})
+
+describe('feature-flag-get-all response shape', () => {
+ it('keeps the staleness evidence on every row and drops filters', async () => {
+ const request = vi.fn().mockResolvedValue({ results: [staleFlag()], next: null, previous: null })
+
+ const result = await GENERATED_TOOLS['feature-flag-get-all']!().handler(createMockContext(request), {})
+
+ const row = (result as any).results[0]
+ // pickResponseFields drops an unmatched path with no error, so a typo in the yaml include
+ // list would silently send agents back to one definition call per flag.
+ expect(row).toMatchObject({
+ status: 'STALE',
+ last_called_at: '2026-06-01T00:00:00Z',
+ active: true,
+ created_at: '2026-01-01T00:00:00Z',
+ })
+ expect(row).not.toHaveProperty('filters')
+ expect(row).not.toHaveProperty('created_by')
+ })
+})