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): expose my_flags feature flag endpoint as MCP tool (#57882)

Dylan Martin2b9269efb4b7
diff --git a/products/feature_flags/mcp/tools.yaml b/products/feature_flags/mcp/tools.yaml
index 9d8bb9e32750..0e027a019404 100644
--- a/products/feature_flags/mcp/tools.yaml
+++ b/products/feature_flags/mcp/tools.yaml
@@ -194,7 +194,20 @@ tools:
enabled: false
feature-flags-my-flags-retrieve:
operation: feature_flags_my_flags_retrieve
- enabled: false
+ enabled: true
+ scopes:
+ - feature_flag:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ list: true
+ title: Get my evaluated feature flags
+ description: >
+ List all feature flags in the current project along with their evaluated value for the authenticated user
+ (the API key owner). Each item includes the flag definition and its current `value` (boolean for simple
+ flags, variant key string for multivariate flags, false if disabled). Optionally pass `groups` as a JSON
+ object to evaluate group-based flags.
feature-flags-remote-config-retrieve:
operation: feature_flags_remote_config_retrieve
enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 97f4431a816b..de46428f257f 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -2150,6 +2150,21 @@
"readOnlyHint": true
}
},
+ "feature-flags-my-flags-retrieve": {
+ "description": "List all feature flags in the current project along with their evaluated value for the authenticated user (the API key owner). Each item includes the flag definition and its current `value` (boolean for simple flags, variant key string for multivariate flags, false if disabled). Optionally pass `groups` as a JSON object to evaluate group-based flags.",
+ "category": "Feature flags",
+ "feature": "flags",
+ "summary": "Get my evaluated feature flags",
+ "title": "Get my evaluated feature flags",
+ "required_scopes": ["feature_flag:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"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.",
"category": "Feature flags",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 6789f6480e06..39857c34da30 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -2418,6 +2418,21 @@
"readOnlyHint": true
}
},
+ "feature-flags-my-flags-retrieve": {
+ "description": "List all feature flags in the current project along with their evaluated value for the authenticated user (the API key owner). Each item includes the flag definition and its current `value` (boolean for simple flags, variant key string for multivariate flags, false if disabled). Optionally pass `groups` as a JSON object to evaluate group-based flags.",
+ "category": "Feature flags",
+ "feature": "flags",
+ "summary": "Get my evaluated feature flags",
+ "title": "Get my evaluated feature flags",
+ "required_scopes": ["feature_flag:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"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.",
"category": "Feature flags",
diff --git a/services/mcp/src/generated/feature_flags/api.ts b/services/mcp/src/generated/feature_flags/api.ts
index 4c01b88dfe19..abaed6046253 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 17 enabled ops
+ * PostHog API - MCP 18 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -824,6 +824,28 @@ export const FeatureFlagsEvaluationReasonsRetrieveQueryParams = /* @__PURE__ */
.describe('Groups for feature flag evaluation (JSON object string)'),
})
+/**
+ * Create, read, update and delete feature flags. [See docs](https://posthog.com/docs/feature-flags) for more information on feature flags.
+
+If you're looking to use feature flags on your application, you can either use our JavaScript Library or our dedicated endpoint to check if feature flags are enabled for a given user.
+ */
+export const FeatureFlagsMyFlagsRetrieveParams = /* @__PURE__ */ zod.object({
+ 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 featureFlagsMyFlagsRetrieveQueryGroupsDefault = `{}`
+
+export const FeatureFlagsMyFlagsRetrieveQueryParams = /* @__PURE__ */ zod.object({
+ groups: zod
+ .string()
+ .default(featureFlagsMyFlagsRetrieveQueryGroupsDefault)
+ .describe('Groups for feature flag evaluation (JSON object string)'),
+})
+
/**
* 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 0d863208f1e3..925839009cf3 100644
--- a/services/mcp/src/tools/generated/feature_flags.ts
+++ b/services/mcp/src/tools/generated/feature_flags.ts
@@ -11,6 +11,7 @@ import {
FeatureFlagsDestroyParams,
FeatureFlagsEvaluationReasonsRetrieveQueryParams,
FeatureFlagsListQueryParams,
+ FeatureFlagsMyFlagsRetrieveQueryParams,
FeatureFlagsPartialUpdateBody,
FeatureFlagsPartialUpdateParams,
FeatureFlagsRetrieveParams,
@@ -256,6 +257,27 @@ const featureFlagsEvaluationReasonsRetrieve = (): ToolBase<
},
})
+const FeatureFlagsMyFlagsRetrieveSchema = FeatureFlagsMyFlagsRetrieveQueryParams
+
+const featureFlagsMyFlagsRetrieve = (): ToolBase<
+ typeof FeatureFlagsMyFlagsRetrieveSchema,
+ WithPostHogUrl<Schemas.MyFlagsResponse[]>
+> => ({
+ name: 'feature-flags-my-flags-retrieve',
+ schema: FeatureFlagsMyFlagsRetrieveSchema,
+ handler: async (context: Context, params: z.infer<typeof FeatureFlagsMyFlagsRetrieveSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.MyFlagsResponse[]>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/feature_flags/my_flags/`,
+ query: {
+ groups: params.groups,
+ },
+ })
+ return await withPostHogUrl(context, result, '/feature_flags')
+ },
+})
+
const FeatureFlagsStatusRetrieveSchema = FeatureFlagsStatusRetrieveParams.omit({ project_id: true }).extend({
id: z.preprocess(castStringToInt, FeatureFlagsStatusRetrieveParams.shape['id']),
})
@@ -529,6 +551,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'feature-flags-copy-flags-create': featureFlagsCopyFlagsCreate,
'feature-flags-dependent-flags-retrieve': featureFlagsDependentFlagsRetrieve,
'feature-flags-evaluation-reasons-retrieve': featureFlagsEvaluationReasonsRetrieve,
+ 'feature-flags-my-flags-retrieve': featureFlagsMyFlagsRetrieve,
'feature-flags-status-retrieve': featureFlagsStatusRetrieve,
'feature-flags-test-evaluation-create': featureFlagsTestEvaluationCreate,
'feature-flags-user-blast-radius-create': featureFlagsUserBlastRadiusCreate,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/feature-flags-my-flags-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/feature-flags-my-flags-retrieve.json
new file mode 100644
index 000000000000..011dc11cae61
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/feature-flags-my-flags-retrieve.json
@@ -0,0 +1,11 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "groups": {
+ "default": "{}",
+ "description": "Groups for feature flag evaluation (JSON object string)",
+ "type": "string"
+ }
+ },
+ "type": "object"
+}