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(mcp): expose products-enable so agents can turn products on (#86979)

Tue Haulund16747b40d6b9
diff --git a/frontend/src/lib/agentScopes.generated.ts b/frontend/src/lib/agentScopes.generated.ts
index 7a80c322915e..4fda486edd62 100644
--- a/frontend/src/lib/agentScopes.generated.ts
+++ b/frontend/src/lib/agentScopes.generated.ts
@@ -97,6 +97,7 @@ export const AGENT_USE_CASE_SCOPES = [
'organization_member:read',
'person:read',
'person:write',
+ 'product_enablement:write',
'project:read',
'project:write',
'property_definition:read',
diff --git a/services/mcp/definitions/core.yaml b/services/mcp/definitions/core.yaml
index bc067ba58550..52a4b18d5856 100644
--- a/services/mcp/definitions/core.yaml
+++ b/services/mcp/definitions/core.yaml
@@ -268,9 +268,24 @@ tools:
organizations-projects-settings-as-of-retrieve:
operation: organizations_projects_settings_as_of_retrieve
enabled: false
- product-enablement-create:
+ products-enable:
operation: product_enablement_create
- enabled: false
+ enabled: true
+ scopes:
+ - product_enablement:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: true
+ title: Enable PostHog products
+ description: >
+ Turn PostHog products on for the current project so they start collecting data. Pass one or more of
+ `session_replay`, `error_tracking`, or `conversations`. The server owns each product's setup, applying the
+ primary toggle plus conservative defaults, so this can never weaken privacy settings or change anything else
+ about the project. Safe to call more than once: each product comes back as either `enabled` or
+ `already_enabled`. Turning on `session_replay` flips the server-side recording toggle only. The app still
+ needs a PostHog SDK installed before recordings arrive. Enabling a product starts collecting data and
+ spending quota, so always confirm with the user before calling this.
project-get:
operation: organizations_projects_retrieve
enabled: true
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 283ab2d03362..56a3237a3957 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -7922,6 +7922,20 @@
},
"feature_flag": "engineering-analytics"
},
+ "products-enable": {
+ "description": "Turn PostHog products on for the current project so they start collecting data. Pass one or more of `session_replay`, `error_tracking`, or `conversations`. The server owns each product's setup, applying the primary toggle plus conservative defaults, so this can never weaken privacy settings or change anything else about the project. Safe to call more than once: each product comes back as either `enabled` or `already_enabled`. Turning on `session_replay` flips the server-side recording toggle only. The app still needs a PostHog SDK installed before recordings arrive. Enabling a product starts collecting data and spending quota, so always confirm with the user before calling this.",
+ "category": "Core",
+ "feature": "core",
+ "summary": "Enable PostHog products",
+ "title": "Enable PostHog products",
+ "required_scopes": ["product_enablement:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"project-get": {
"description": "Retrieve a project and its settings. Omit the ID to get the caller's active project.",
"category": "Core",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index c2fa126f09e9..379bc20ac837 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -8421,6 +8421,20 @@
},
"feature_flag": "engineering-analytics"
},
+ "products-enable": {
+ "description": "Turn PostHog products on for the current project so they start collecting data. Pass one or more of `session_replay`, `error_tracking`, or `conversations`. The server owns each product's setup, applying the primary toggle plus conservative defaults, so this can never weaken privacy settings or change anything else about the project. Safe to call more than once: each product comes back as either `enabled` or `already_enabled`. Turning on `session_replay` flips the server-side recording toggle only. The app still needs a PostHog SDK installed before recordings arrive. Enabling a product starts collecting data and spending quota, so always confirm with the user before calling this.",
+ "category": "Core",
+ "feature": "core",
+ "summary": "Enable PostHog products",
+ "title": "Enable PostHog products",
+ "required_scopes": ["product_enablement:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"project-get": {
"description": "Retrieve a project and its settings. Omit the ID to get the caller's active project.",
"category": "Core",
diff --git a/services/mcp/src/generated/core/api.ts b/services/mcp/src/generated/core/api.ts
index 85cf32ba3088..fd18a1c3d02f 100644
--- a/services/mcp/src/generated/core/api.ts
+++ b/services/mcp/src/generated/core/api.ts
@@ -3,7 +3,7 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 4 enabled ops
+ * PostHog API - MCP 5 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -2650,6 +2650,27 @@ export const OrganizationsProjectsPartialUpdateBody = /* @__PURE__ */ zod
})
.describe('Mixin for serializers to add user access control fields')
+export const ProductEnablementCreateParams = /* @__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 ProductEnablementCreateBody = /* @__PURE__ */ zod.object({
+ products: zod
+ .array(
+ zod
+ .enum(['conversations', 'error_tracking', 'session_replay'])
+ .describe(
+ '\* `conversations` - conversations\n\* `error_tracking` - error_tracking\n\* `session_replay` - session_replay'
+ )
+ )
+ .min(1)
+ .describe('Products to turn on for this project, each enabled with server-owned conservative defaults.'),
+})
+
/**
* Retrieve a user's profile and settings. Pass `@me` as the UUID to fetch the authenticated user; non-staff callers may only access their own account.
*/
diff --git a/services/mcp/src/tools/generated/core.ts b/services/mcp/src/tools/generated/core.ts
index c763210b26e8..03d818b7c367 100644
--- a/services/mcp/src/tools/generated/core.ts
+++ b/services/mcp/src/tools/generated/core.ts
@@ -6,6 +6,7 @@ import {
OrganizationsProjectsPartialUpdateBody,
OrganizationsProjectsPartialUpdateParams,
OrganizationsProjectsRetrieveParams,
+ ProductEnablementCreateBody,
UsersPartialUpdateBody,
UsersPartialUpdateParams,
UsersRetrieveParams,
@@ -14,6 +15,26 @@ import { castStringToInt } from '@/tools/cast-helpers'
import { omitResponseFields, pickResponseFields } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
+const ProductsEnableSchema = ProductEnablementCreateBody
+
+const productsEnable = (): ToolBase<typeof ProductsEnableSchema, Schemas.ProductEnablementResult> => ({
+ name: 'products-enable',
+ schema: ProductsEnableSchema,
+ handler: async (context: Context, params: z.infer<typeof ProductsEnableSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.products !== undefined) {
+ body['products'] = params.products
+ }
+ const result = await context.api.request<Schemas.ProductEnablementResult>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/product_enablement/`,
+ body,
+ })
+ return result
+ },
+})
+
const ProjectGetSchema = OrganizationsProjectsRetrieveParams.omit({ organization_id: true }).extend({
id: z
.preprocess(
@@ -411,6 +432,7 @@ const userSettingsUpdate = (): ToolBase<typeof UserSettingsUpdateSchema, Schemas
})
export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
+ 'products-enable': productsEnable,
'project-get': projectGet,
'project-settings-update': projectSettingsUpdate,
'user-get': userGet,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/products-enable.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/products-enable.json
new file mode 100644
index 000000000000..a6d79a7a383f
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/products-enable.json
@@ -0,0 +1,17 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "products": {
+ "description": "Products to turn on for this project, each enabled with server-owned conservative defaults.",
+ "items": {
+ "description": "* `conversations` - conversations\n* `error_tracking` - error_tracking\n* `session_replay` - session_replay",
+ "enum": ["conversations", "error_tracking", "session_replay"],
+ "type": "string"
+ },
+ "minItems": 1,
+ "type": "array"
+ }
+ },
+ "required": ["products"],
+ "type": "object"
+}