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: add actions to experiment exposures for MCP (#62348)

Luke Beltonf0f98bfe6ea9
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 102e3ee53b62..8143d16e99a4 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -18398,14 +18398,19 @@
},
"ExperimentApiExposureConfig": {
"additionalProperties": false,
- "description": "Slim exposure config for experiment API payloads.",
+ "description": "Slim exposure config for experiment API payloads. Discriminated by `kind`: 'ExperimentEventExposureConfig' tracks exposure via a custom event, 'ActionsNode' tracks exposure via an action.",
"properties": {
"event": {
- "description": "Custom exposure event name.",
+ "description": "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'.",
"type": "string"
},
+ "id": {
+ "$ref": "#/definitions/integer",
+ "description": "Action ID. Required when kind is 'ActionsNode'."
+ },
"kind": {
- "const": "ExperimentEventExposureConfig",
+ "description": "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure.",
+ "enum": ["ExperimentEventExposureConfig", "ActionsNode"],
"type": "string"
},
"properties": {
@@ -18416,7 +18421,7 @@
"type": "array"
}
},
- "required": ["kind", "event", "properties"],
+ "required": ["properties"],
"type": "object"
},
"ExperimentApiExposureCriteria": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 311629ce0e39..112f48fe4115 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -3707,11 +3707,16 @@ export interface ExperimentParameters {
excluded_variants?: string[]
}
-/** Slim exposure config for experiment API payloads. */
+/** Slim exposure config for experiment API payloads. Discriminated by `kind`:
+ * 'ExperimentEventExposureConfig' tracks exposure via a custom event,
+ * 'ActionsNode' tracks exposure via an action. */
export interface ExperimentApiExposureConfig {
- kind: NodeKind.ExperimentEventExposureConfig
- /** Custom exposure event name. */
- event: string
+ /** Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure. */
+ kind?: 'ExperimentEventExposureConfig' | 'ActionsNode'
+ /** Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'. */
+ event?: string
+ /** Action ID. Required when kind is 'ActionsNode'. */
+ id?: integer
/** Event property filters. Pass an empty array if no filters needed. */
properties: EventPropertyFilter[]
}
diff --git a/posthog/schema.py b/posthog/schema.py
index 69e0e9b4734b..bc9ce1710330 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -1934,6 +1934,11 @@ class Kind(StrEnum):
ACTIONS_NODE = "ActionsNode"
+class Kind1(StrEnum):
+ EXPERIMENT_EVENT_EXPOSURE_CONFIG = "ExperimentEventExposureConfig"
+ ACTIONS_NODE = "ActionsNode"
+
+
class StartHandling(StrEnum):
FIRST_SEEN = "first_seen"
LAST_SEEN = "last_seen"
@@ -7157,8 +7162,17 @@ class ExperimentApiExposureConfig(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
- event: str = Field(..., description="Custom exposure event name.")
- kind: Literal["ExperimentEventExposureConfig"] = "ExperimentEventExposureConfig"
+ event: str | None = Field(
+ default=None,
+ description=("Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."),
+ )
+ id: int | None = Field(default=None, description="Action ID. Required when kind is 'ActionsNode'.")
+ kind: Kind1 | None = Field(
+ default=None,
+ description=(
+ "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
+ ),
+ )
properties: list[EventPropertyFilter] = Field(
...,
description="Event property filters. Pass an empty array if no filters needed.",
diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.ts
index 529d0d4099d3..e594b784fa65 100644
--- a/products/experiments/frontend/generated/api.schemas.ts
+++ b/products/experiments/frontend/generated/api.schemas.ts
@@ -210,6 +210,13 @@ export const ExperimentTypeEnumApi = {
Product: 'product',
} as const
+export type Kind1Api = (typeof Kind1Api)[keyof typeof Kind1Api]
+
+export const Kind1Api = {
+ ExperimentEventExposureConfig: 'ExperimentEventExposureConfig',
+ ActionsNode: 'ActionsNode',
+} as const
+
export type PropertyOperatorApi = (typeof PropertyOperatorApi)[keyof typeof PropertyOperatorApi]
export const PropertyOperatorApi = {
@@ -259,9 +266,12 @@ export interface EventPropertyFilterApi {
}
export interface ExperimentApiExposureConfigApi {
- /** Custom exposure event name. */
- event: string
- kind?: 'ExperimentEventExposureConfig'
+ /** Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'. */
+ event?: string | null
+ /** Action ID. Required when kind is 'ActionsNode'. */
+ id?: number | null
+ /** Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure. */
+ kind?: Kind1Api | null
/** Event property filters. Pass an empty array if no filters needed. */
properties: EventPropertyFilterApi[]
}
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index aecbc2c0a2c6..9682034a8073 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -16812,10 +16812,21 @@ export namespace Schemas {
Product: 'product',
} as const;
+ export type Kind1 = typeof Kind1[keyof typeof Kind1];
+
+
+ export const Kind1 = {
+ ExperimentEventExposureConfig: 'ExperimentEventExposureConfig',
+ ActionsNode: 'ActionsNode',
+ } as const;
+
export interface ExperimentApiExposureConfig {
- /** Custom exposure event name. */
- event: string;
- kind?: 'ExperimentEventExposureConfig';
+ /** Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'. */
+ event?: string | null;
+ /** Action ID. Required when kind is 'ActionsNode'. */
+ id?: number | null;
+ /** Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure. */
+ kind?: Kind1 | null;
/** Event property filters. Pass an empty array if no filters needed. */
properties: EventPropertyFilter[];
}
diff --git a/services/mcp/src/generated/experiments/api.ts b/services/mcp/src/generated/experiments/api.ts
index 8957baf37097..600eaaa98cf9 100644
--- a/services/mcp/src/generated/experiments/api.ts
+++ b/services/mcp/src/generated/experiments/api.ts
@@ -161,7 +161,6 @@ export const experimentsCreateBodyNameMax = 400
export const experimentsCreateBodyDescriptionMax = 3000
export const experimentsCreateBodyArchivedDefault = false
-export const experimentsCreateBodyExposureCriteriaOneExposureConfigOneKindDefault = `ExperimentEventExposureConfig`
export const experimentsCreateBodyExposureCriteriaOneExposureConfigOnePropertiesItemOperatorDefault = `exact`
export const experimentsCreateBodyExposureCriteriaOneExposureConfigOnePropertiesItemTypeDefault = `event`
export const experimentsCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
@@ -326,10 +325,22 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
exposure_config: zod
.union([
zod.object({
- event: zod.string().describe('Custom exposure event name.'),
+ event: zod
+ .union([zod.string(), zod.null()])
+ .optional()
+ .describe(
+ "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."
+ ),
+ id: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe("Action ID. Required when kind is 'ActionsNode'."),
kind: zod
- .literal('ExperimentEventExposureConfig')
- .default(experimentsCreateBodyExposureCriteriaOneExposureConfigOneKindDefault),
+ .union([zod.enum(['ExperimentEventExposureConfig', 'ActionsNode']), zod.null()])
+ .optional()
+ .describe(
+ "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
+ ),
properties: zod
.array(
zod.object({
@@ -2451,7 +2462,6 @@ export const experimentsPartialUpdateBodyNameMax = 400
export const experimentsPartialUpdateBodyDescriptionMax = 3000
-export const experimentsPartialUpdateBodyExposureCriteriaOneExposureConfigOneKindDefault = `ExperimentEventExposureConfig`
export const experimentsPartialUpdateBodyExposureCriteriaOneExposureConfigOnePropertiesItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyExposureCriteriaOneExposureConfigOnePropertiesItemTypeDefault = `event`
export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
@@ -2611,11 +2621,21 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
exposure_config: zod
.union([
zod.object({
- event: zod.string().describe('Custom exposure event name.'),
+ event: zod
+ .union([zod.string(), zod.null()])
+ .optional()
+ .describe(
+ "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."
+ ),
+ id: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe("Action ID. Required when kind is 'ActionsNode'."),
kind: zod
- .literal('ExperimentEventExposureConfig')
- .default(
- experimentsPartialUpdateBodyExposureCriteriaOneExposureConfigOneKindDefault
+ .union([zod.enum(['ExperimentEventExposureConfig', 'ActionsNode']), zod.null()])
+ .optional()
+ .describe(
+ "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
),
properties: zod
.array(
@@ -4767,7 +4787,6 @@ export const experimentsDuplicateCreateBodyNameMax = 400
export const experimentsDuplicateCreateBodyDescriptionMax = 3000
export const experimentsDuplicateCreateBodyArchivedDefault = false
-export const experimentsDuplicateCreateBodyExposureCriteriaOneExposureConfigOneKindDefault = `ExperimentEventExposureConfig`
export const experimentsDuplicateCreateBodyExposureCriteriaOneExposureConfigOnePropertiesItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyExposureCriteriaOneExposureConfigOnePropertiesItemTypeDefault = `event`
export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
@@ -4932,11 +4951,21 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
exposure_config: zod
.union([
zod.object({
- event: zod.string().describe('Custom exposure event name.'),
+ event: zod
+ .union([zod.string(), zod.null()])
+ .optional()
+ .describe(
+ "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."
+ ),
+ id: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe("Action ID. Required when kind is 'ActionsNode'."),
kind: zod
- .literal('ExperimentEventExposureConfig')
- .default(
- experimentsDuplicateCreateBodyExposureCriteriaOneExposureConfigOneKindDefault
+ .union([zod.enum(['ExperimentEventExposureConfig', 'ActionsNode']), zod.null()])
+ .optional()
+ .describe(
+ "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
),
properties: zod
.array(
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json
index fc7ad51f518f..efcfd8121400 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json
@@ -27,13 +27,38 @@
{
"properties": {
"event": {
- "description": "Custom exposure event name.",
- "type": "string"
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."
+ },
+ "id": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Action ID. Required when kind is 'ActionsNode'."
},
"kind": {
- "const": "ExperimentEventExposureConfig",
- "default": "ExperimentEventExposureConfig",
- "type": "string"
+ "anyOf": [
+ {
+ "enum": ["ExperimentEventExposureConfig", "ActionsNode"],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
},
"properties": {
"description": "Event property filters. Pass an empty array if no filters needed.",
@@ -144,7 +169,7 @@
"type": "array"
}
},
- "required": ["event", "properties"],
+ "required": ["properties"],
"type": "object"
},
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-duplicate.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-duplicate.json
index 253fb7a3c837..a62cab646a5a 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-duplicate.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-duplicate.json
@@ -78,13 +78,38 @@
{
"properties": {
"event": {
- "description": "Custom exposure event name.",
- "type": "string"
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."
+ },
+ "id": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Action ID. Required when kind is 'ActionsNode'."
},
"kind": {
- "const": "ExperimentEventExposureConfig",
- "default": "ExperimentEventExposureConfig",
- "type": "string"
+ "anyOf": [
+ {
+ "enum": ["ExperimentEventExposureConfig", "ActionsNode"],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
},
"properties": {
"description": "Event property filters. Pass an empty array if no filters needed.",
@@ -195,7 +220,7 @@
"type": "array"
}
},
- "required": ["event", "properties"],
+ "required": ["properties"],
"type": "object"
},
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json
index 5bac75854219..5df0d8131dd0 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json
@@ -54,13 +54,38 @@
{
"properties": {
"event": {
- "description": "Custom exposure event name.",
- "type": "string"
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Custom exposure event name. Required when kind is 'ExperimentEventExposureConfig'."
+ },
+ "id": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Action ID. Required when kind is 'ActionsNode'."
},
"kind": {
- "const": "ExperimentEventExposureConfig",
- "default": "ExperimentEventExposureConfig",
- "type": "string"
+ "anyOf": [
+ {
+ "enum": ["ExperimentEventExposureConfig", "ActionsNode"],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Defaults to 'ExperimentEventExposureConfig' when omitted. Pass 'ActionsNode' for an action-based exposure."
},
"properties": {
"description": "Event property filters. Pass an empty array if no filters needed.",
@@ -171,7 +196,7 @@
"type": "array"
}
},
- "required": ["event", "properties"],
+ "required": ["properties"],
"type": "object"
},
{