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(customer-analytics): Expose account CRUD as MCP tools (#58156)

Arthur Moreira de Deus8dc00246893f
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 914a7292f626..563a2733c07c 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -256,6 +256,7 @@ export const FEATURE_FLAGS = {
CRM_ITERATION_ONE: 'crm-iteration-one', // owner: @arthurdedeus #team-customer-analytics
CUSTOM_PRODUCTS_SIDEBAR: 'custom-products-sidebar', // owner: @rafaeelaudibert #team-growth
CUSTOMER_ANALYTICS: 'customer-analytics-roadmap', // owner: @arthurdedeus #team-customer-analytics
+ CUSTOMER_ANALYTICS_CSP: 'customer-analytics-csp', // owner: @arthurdedeus #team-customer-analytics, gates the Customer analytics > Accounts settings tab (account_group_type_index dropdown)
CUSTOMER_ANALYTICS_JOURNEYS: 'customer-analytics-journeys', // owner: @arthurdedeus #team-customer-analytics
CUSTOMER_DASHBOARD_TEMPLATE_AUTHORING: 'customer-dashboard-template-authoring', // owner: @mattp #team-analytics-platform org-scoped; project templates for non-staff
CUSTOMER_PROFILE_CONFIG_BUTTON: 'customer-profile-config-button', // owner: @arthurdedeus #team-customer-analytics
@@ -410,7 +411,6 @@ export const FEATURE_FLAGS = {
POSTHOG_AI_QUEUE_MESSAGES_SYSTEM: 'posthog-ai-queue-messages-system', // owner: #team-posthog-ai
POSTHOG_CODE_BILLING: 'posthog-code-billing', // owner: #team-posthog-code
POSTHOG_CODE_SLACK_AVAILABILITY: 'posthog-code-slack-availability', // owner: #team-posthog-code, gates the PostHog Code Slack integration UI
- POSTHOG_CSP: 'posthog-csp', // owner: @arthurdedeus #team-customer-analytics, gates the Customer analytics > Accounts settings tab (account_group_type_index dropdown)
PRODUCT_ANALYTICS_DASHBOARD_AI_ANALYSIS: 'product-analytics-dashboard-ai-analysis', // owner: @anirudhpillai #team-product-analytics
PRODUCT_ANALYTICS_DASHBOARD_COLORS: 'dashboard-colors', // owner: @thmsobrmlr #team-product-analytics
PRODUCT_ANALYTICS_DASHBOARD_MODAL_SMART_DEFAULTS: 'product-analytics-dashboard-modal-smart-defaults', // owner: @sam #team-product-analytics
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index bceaa34fd30b..3b107bf7103b 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -442,7 +442,7 @@ export const SETTINGS_MAP: SettingSection[] = [
title: 'Accounts',
description: 'Select which group type represents an account in customer analytics.',
component: <CustomerAnalyticsAccountConfig />,
- flag: ['CUSTOMER_ANALYTICS', 'POSTHOG_CSP'],
+ flag: ['CUSTOMER_ANALYTICS', 'CUSTOMER_ANALYTICS_CSP'],
keywords: ['accounts', 'group', 'b2b'],
},
],
diff --git a/products/customer_analytics/backend/api/views.py b/products/customer_analytics/backend/api/views.py
index 6306439c1662..a6fe86f36279 100644
--- a/products/customer_analytics/backend/api/views.py
+++ b/products/customer_analytics/backend/api/views.py
@@ -1,3 +1,4 @@
+from drf_spectacular.utils import extend_schema
from rest_framework import viewsets
from posthog.api.routing import TeamAndOrgViewSetMixin
@@ -58,6 +59,7 @@ class CustomerJourneyViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin,
super().perform_destroy(instance)
+@extend_schema(tags=["customer_analytics"])
class AccountViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.ModelViewSet):
scope_object = "account"
queryset = Account.objects.unscoped().order_by("-created_at")
diff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.ts
index 393ae2424b61..954edfbcf137 100644
--- a/products/customer_analytics/frontend/generated/api.schemas.ts
+++ b/products/customer_analytics/frontend/generated/api.schemas.ts
@@ -63,6 +63,53 @@ export interface PaginatedAccountListApi {
results: AccountApi[]
}
+/**
+ * Typed account properties: assignment fields (csm, account_executive, account_owner). Defaults to an empty object. Unknown keys are rejected.
+ * @nullable
+ */
+export type PatchedAccountApiProperties = {
+ /** @nullable */
+ csm?: {
+ id: number
+ email: string
+ } | null
+ /** @nullable */
+ account_executive?: {
+ id: number
+ email: string
+ } | null
+ /** @nullable */
+ account_owner?: {
+ id: number
+ email: string
+ } | null
+} | null
+
+export interface PatchedAccountApi {
+ readonly id?: string
+ /**
+ * Human-readable name of the account.
+ * @maxLength 400
+ */
+ name?: string
+ /**
+ * Identifier for the account in an external system (e.g. CRM ID). Optional.
+ * @maxLength 400
+ * @nullable
+ */
+ external_id?: string | null
+ /**
+ * Typed account properties: assignment fields (csm, account_executive, account_owner). Defaults to an empty object. Unknown keys are rejected.
+ * @nullable
+ */
+ properties?: PatchedAccountApiProperties
+ readonly created_at?: string
+ /** @nullable */
+ readonly created_by?: number | null
+ /** @nullable */
+ readonly updated_at?: string | null
+}
+
export interface CustomerJourneyApi {
readonly id: string
insight: number
diff --git a/products/customer_analytics/frontend/generated/api.ts b/products/customer_analytics/frontend/generated/api.ts
index d71c8a090630..9c1bbba88087 100644
--- a/products/customer_analytics/frontend/generated/api.ts
+++ b/products/customer_analytics/frontend/generated/api.ts
@@ -21,6 +21,7 @@ import type {
PaginatedCustomerJourneyListApi,
PaginatedCustomerProfileConfigListApi,
PaginatedGroupUsageMetricListApi,
+ PatchedAccountApi,
PatchedGroupUsageMetricApi,
} from './api.schemas'
@@ -85,6 +86,64 @@ export const accountsCreate = async (
})
}
+export const getAccountsRetrieveUrl = (projectId: string, id: string) => {
+ return `/api/environments/${projectId}/accounts/${id}/`
+}
+
+export const accountsRetrieve = async (projectId: string, id: string, options?: RequestInit): Promise<AccountApi> => {
+ return apiMutator<AccountApi>(getAccountsRetrieveUrl(projectId, id), {
+ ...options,
+ method: 'GET',
+ })
+}
+
+export const getAccountsUpdateUrl = (projectId: string, id: string) => {
+ return `/api/environments/${projectId}/accounts/${id}/`
+}
+
+export const accountsUpdate = async (
+ projectId: string,
+ id: string,
+ accountApi: NonReadonly<AccountApi>,
+ options?: RequestInit
+): Promise<AccountApi> => {
+ return apiMutator<AccountApi>(getAccountsUpdateUrl(projectId, id), {
+ ...options,
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(accountApi),
+ })
+}
+
+export const getAccountsPartialUpdateUrl = (projectId: string, id: string) => {
+ return `/api/environments/${projectId}/accounts/${id}/`
+}
+
+export const accountsPartialUpdate = async (
+ projectId: string,
+ id: string,
+ patchedAccountApi?: NonReadonly<PatchedAccountApi>,
+ options?: RequestInit
+): Promise<AccountApi> => {
+ return apiMutator<AccountApi>(getAccountsPartialUpdateUrl(projectId, id), {
+ ...options,
+ method: 'PATCH',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(patchedAccountApi),
+ })
+}
+
+export const getAccountsDestroyUrl = (projectId: string, id: string) => {
+ return `/api/environments/${projectId}/accounts/${id}/`
+}
+
+export const accountsDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
+ return apiMutator<void>(getAccountsDestroyUrl(projectId, id), {
+ ...options,
+ method: 'DELETE',
+ })
+}
+
export const getCustomerJourneysListUrl = (projectId: string, params?: CustomerJourneysListParams) => {
const normalizedParams = new URLSearchParams()
diff --git a/products/customer_analytics/frontend/generated/api.zod.ts b/products/customer_analytics/frontend/generated/api.zod.ts
index b754338af9af..c13a4f3fcc1c 100644
--- a/products/customer_analytics/frontend/generated/api.zod.ts
+++ b/products/customer_analytics/frontend/generated/api.zod.ts
@@ -47,6 +47,82 @@ export const AccountsCreateBody = /* @__PURE__ */ zod.object({
),
})
+export const accountsUpdateBodyNameMax = 400
+
+export const accountsUpdateBodyExternalIdMax = 400
+
+export const AccountsUpdateBody = /* @__PURE__ */ zod.object({
+ name: zod.string().max(accountsUpdateBodyNameMax).describe('Human-readable name of the account.'),
+ external_id: zod
+ .string()
+ .max(accountsUpdateBodyExternalIdMax)
+ .nullish()
+ .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ properties: zod
+ .object({
+ csm: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_executive: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_owner: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ })
+ .nullish()
+ .describe(
+ 'Typed account properties: assignment fields (csm, account_executive, account_owner). Defaults to an empty object. Unknown keys are rejected.'
+ ),
+})
+
+export const accountsPartialUpdateBodyNameMax = 400
+
+export const accountsPartialUpdateBodyExternalIdMax = 400
+
+export const AccountsPartialUpdateBody = /* @__PURE__ */ zod.object({
+ name: zod.string().max(accountsPartialUpdateBodyNameMax).optional().describe('Human-readable name of the account.'),
+ external_id: zod
+ .string()
+ .max(accountsPartialUpdateBodyExternalIdMax)
+ .nullish()
+ .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ properties: zod
+ .object({
+ csm: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_executive: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_owner: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ })
+ .nullish()
+ .describe(
+ 'Typed account properties: assignment fields (csm, account_executive, account_owner). Defaults to an empty object. Unknown keys are rejected.'
+ ),
+})
+
export const customerJourneysCreateBodyNameMax = 400
export const CustomerJourneysCreateBody = /* @__PURE__ */ zod.object({
diff --git a/products/customer_analytics/mcp/tools.yaml b/products/customer_analytics/mcp/tools.yaml
index 999b22d16dc2..9fb54005c846 100644
--- a/products/customer_analytics/mcp/tools.yaml
+++ b/products/customer_analytics/mcp/tools.yaml
@@ -11,9 +11,89 @@ ui_apps: {}
tools:
accounts-create:
operation: accounts_create
- enabled: false
+ enabled: true
+ scopes:
+ - account:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: false
+ title: Create account
+ description: >
+ Create a new Customer Analytics account. An account is a logical container for assigning ownership across
+ the customer-success org. Provide `name` (required), optional `external_id` (CRM ID or similar), and
+ optional `properties` to set role assignments (`csm`, `account_executive`, `account_owner`).
+ param_overrides:
+ properties:
+ description: >
+ Typed account properties. `csm`, `account_executive`, `account_owner` are role assignments — each
+ takes `{id, email}` of an existing user. All three are optional.
+ feature_flag: customer-analytics-csp
+ accounts-destroy:
+ operation: accounts_destroy
+ enabled: true
+ scopes:
+ - account:write
+ annotations:
+ readOnly: false
+ destructive: true
+ idempotent: true
+ title: Delete account
+ description: |
+ Permanently delete a Customer Analytics account by id.
+ feature_flag: customer-analytics-csp
accounts-list:
operation: accounts_list
+ enabled: true
+ scopes:
+ - account:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ list: true
+ title: List accounts
+ description: >
+ List Customer Analytics accounts in the project, ordered by most recently created. Each result includes the
+ account `id`, `name`, `external_id`, typed `properties` (csm, account_executive, account_owner), and
+ creation/update metadata. Use `accounts-retrieve` for a single account by id.
+ feature_flag: customer-analytics-csp
+ accounts-partial-update:
+ operation: accounts_partial_update
+ enabled: true
+ scopes:
+ - account:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: true
+ title: Update account
+ description: >
+ Update fields on an existing Customer Analytics account. Accepts a subset of fields; unspecified fields are
+ left unchanged.
+ param_overrides:
+ properties:
+ description: >
+ Typed account properties. The server replaces the `properties` object as a whole, so include any
+ existing values you want to preserve. Supported keys: `csm`, `account_executive`, `account_owner`,
+ each taking `{id, email}` of an existing user.
+ feature_flag: customer-analytics-csp
+ accounts-retrieve:
+ operation: accounts_retrieve
+ enabled: true
+ scopes:
+ - account:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Get account
+ description: >
+ Fetch a single Customer Analytics account by id. Returns the full account including typed `properties` (csm,
+ account_executive, account_owner assignments).
+ feature_flag: customer-analytics-csp
+ accounts-update:
+ operation: accounts_update
enabled: false
customer-journeys-create:
operation: customer_journeys_create
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index de46428f257f..891177b658fd 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -1,4 +1,84 @@
{
+ "accounts-create": {
+ "description": "Create a new Customer Analytics account. An account is a logical container for assigning ownership across the customer-success org. Provide `name` (required), optional `external_id` (CRM ID or similar), and optional `properties` to set role assignments (`csm`, `account_executive`, `account_owner`).",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Create account",
+ "title": "Create account",
+ "required_scopes": ["account:write"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-destroy": {
+ "description": "Permanently delete a Customer Analytics account by id.",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Delete account",
+ "title": "Delete account",
+ "required_scopes": ["account:write"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": true,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-list": {
+ "description": "List Customer Analytics accounts in the project, ordered by most recently created. Each result includes the account `id`, `name`, `external_id`, typed `properties` (csm, account_executive, account_owner), and creation/update metadata. Use `accounts-retrieve` for a single account by id.",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "List accounts",
+ "title": "List accounts",
+ "required_scopes": ["account:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-partial-update": {
+ "description": "Update fields on an existing Customer Analytics account. Accepts a subset of fields; unspecified fields are left unchanged.",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Update account",
+ "title": "Update account",
+ "required_scopes": ["account:write"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-retrieve": {
+ "description": "Fetch a single Customer Analytics account by id. Returns the full account including typed `properties` (csm, account_executive, account_owner assignments).",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Get account",
+ "title": "Get account",
+ "required_scopes": ["account:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
"action-create": {
"description": "Create a new action in the project. Actions define reusable event triggers based on page views, clicks, form submissions, or custom events. Each action can have multiple steps (OR conditions). Use actions to create composite events for insights and funnels. Example: Create a 'Sign Up Click' action with steps matching button clicks on the signup page.",
"category": "Actions",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 39857c34da30..d07bb46e9da7 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -1,4 +1,84 @@
{
+ "accounts-create": {
+ "description": "Create a new Customer Analytics account. An account is a logical container for assigning ownership across the customer-success org. Provide `name` (required), optional `external_id` (CRM ID or similar), and optional `properties` to set role assignments (`csm`, `account_executive`, `account_owner`).",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Create account",
+ "title": "Create account",
+ "required_scopes": ["account:write"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-destroy": {
+ "description": "Permanently delete a Customer Analytics account by id.",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Delete account",
+ "title": "Delete account",
+ "required_scopes": ["account:write"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": true,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-list": {
+ "description": "List Customer Analytics accounts in the project, ordered by most recently created. Each result includes the account `id`, `name`, `external_id`, typed `properties` (csm, account_executive, account_owner), and creation/update metadata. Use `accounts-retrieve` for a single account by id.",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "List accounts",
+ "title": "List accounts",
+ "required_scopes": ["account:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-partial-update": {
+ "description": "Update fields on an existing Customer Analytics account. Accepts a subset of fields; unspecified fields are left unchanged.",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Update account",
+ "title": "Update account",
+ "required_scopes": ["account:write"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
+ "accounts-retrieve": {
+ "description": "Fetch a single Customer Analytics account by id. Returns the full account including typed `properties` (csm, account_executive, account_owner assignments).",
+ "category": "Customer analytics",
+ "feature": "customer_analytics",
+ "summary": "Get account",
+ "title": "Get account",
+ "required_scopes": ["account:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "customer-analytics-csp"
+ },
"action-create": {
"description": "Create a new action in the project. Actions define reusable event triggers based on page views, clicks, form submissions, or custom events. Each action can have multiple steps (OR conditions). Use actions to create composite events for insights and funnels. Example: Create a 'Sign Up Click' action with steps matching button clicks on the signup page.",
"category": "Actions",
diff --git a/services/mcp/src/generated/customer_analytics/api.ts b/services/mcp/src/generated/customer_analytics/api.ts
index 5117eeda093d..8a11118bfbdd 100644
--- a/services/mcp/src/generated/customer_analytics/api.ts
+++ b/services/mcp/src/generated/customer_analytics/api.ts
@@ -3,11 +3,135 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 5 enabled ops
+ * PostHog API - MCP 10 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
+export const AccountsListParams = /* @__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 AccountsListQueryParams = /* @__PURE__ */ zod.object({
+ limit: zod.number().optional().describe('Number of results to return per page.'),
+ offset: zod.number().optional().describe('The initial index from which to return the results.'),
+})
+
+export const AccountsCreateParams = /* @__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 accountsCreateBodyNameMax = 400
+
+export const accountsCreateBodyExternalIdMax = 400
+
+export const AccountsCreateBody = /* @__PURE__ */ zod.object({
+ name: zod.string().max(accountsCreateBodyNameMax).describe('Human-readable name of the account.'),
+ external_id: zod
+ .string()
+ .max(accountsCreateBodyExternalIdMax)
+ .nullish()
+ .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ properties: zod
+ .object({
+ csm: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_executive: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_owner: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ })
+ .nullish()
+ .describe(
+ 'Typed account properties: assignment fields (csm, account_executive, account_owner). Defaults to an empty object. Unknown keys are rejected.'
+ ),
+})
+
+export const AccountsRetrieveParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this account.'),
+ 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 AccountsPartialUpdateParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this account.'),
+ 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 accountsPartialUpdateBodyNameMax = 400
+
+export const accountsPartialUpdateBodyExternalIdMax = 400
+
+export const AccountsPartialUpdateBody = /* @__PURE__ */ zod.object({
+ name: zod.string().max(accountsPartialUpdateBodyNameMax).optional().describe('Human-readable name of the account.'),
+ external_id: zod
+ .string()
+ .max(accountsPartialUpdateBodyExternalIdMax)
+ .nullish()
+ .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ properties: zod
+ .object({
+ csm: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_executive: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ account_owner: zod
+ .object({
+ id: zod.number(),
+ email: zod.string(),
+ })
+ .nullish(),
+ })
+ .nullish()
+ .describe(
+ 'Typed account properties: assignment fields (csm, account_executive, account_owner). Defaults to an empty object. Unknown keys are rejected.'
+ ),
+})
+
+export const AccountsDestroyParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this account.'),
+ 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 groupsTypesMetricsListPathGroupTypeIndexMin = -2147483648
export const groupsTypesMetricsListPathGroupTypeIndexMax = 2147483647
diff --git a/services/mcp/src/tools/generated/customer_analytics.ts b/services/mcp/src/tools/generated/customer_analytics.ts
index 13da9f00cb59..14d69ca24508 100644
--- a/services/mcp/src/tools/generated/customer_analytics.ts
+++ b/services/mcp/src/tools/generated/customer_analytics.ts
@@ -3,6 +3,12 @@ import { z } from 'zod'
import type { Schemas } from '@/api/generated'
import {
+ AccountsCreateBody,
+ AccountsDestroyParams,
+ AccountsListQueryParams,
+ AccountsPartialUpdateBody,
+ AccountsPartialUpdateParams,
+ AccountsRetrieveParams,
GroupsTypesMetricsCreateBody,
GroupsTypesMetricsCreateParams,
GroupsTypesMetricsDestroyParams,
@@ -16,6 +22,117 @@ import { UsageMetricFiltersSchema } from '@/schema/tool-inputs'
import { withPostHogUrl, type WithPostHogUrl } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
+const AccountsCreateSchema = AccountsCreateBody.extend({
+ properties: AccountsCreateBody.shape['properties'].describe(
+ 'Typed account properties. `csm`, `account_executive`, `account_owner` are role assignments — each takes `{id, email}` of an existing user. All three are optional.'
+ ),
+})
+
+const accountsCreate = (): ToolBase<typeof AccountsCreateSchema, Schemas.Account> => ({
+ name: 'accounts-create',
+ schema: AccountsCreateSchema,
+ handler: async (context: Context, params: z.infer<typeof AccountsCreateSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.name !== undefined) {
+ body['name'] = params.name
+ }
+ if (params.external_id !== undefined) {
+ body['external_id'] = params.external_id
+ }
+ if (params.properties !== undefined) {
+ body['properties'] = params.properties
+ }
+ const result = await context.api.request<Schemas.Account>({
+ method: 'POST',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/accounts/`,
+ body,
+ })
+ return result
+ },
+})
+
+const AccountsDestroySchema = AccountsDestroyParams.omit({ project_id: true })
+
+const accountsDestroy = (): ToolBase<typeof AccountsDestroySchema, unknown> => ({
+ name: 'accounts-destroy',
+ schema: AccountsDestroySchema,
+ handler: async (context: Context, params: z.infer<typeof AccountsDestroySchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<unknown>({
+ method: 'DELETE',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/accounts/${encodeURIComponent(String(params.id))}/`,
+ })
+ return result
+ },
+})
+
+const AccountsListSchema = AccountsListQueryParams
+
+const accountsList = (): ToolBase<typeof AccountsListSchema, WithPostHogUrl<Schemas.PaginatedAccountList>> => ({
+ name: 'accounts-list',
+ schema: AccountsListSchema,
+ handler: async (context: Context, params: z.infer<typeof AccountsListSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.PaginatedAccountList>({
+ method: 'GET',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/accounts/`,
+ query: {
+ limit: params.limit,
+ offset: params.offset,
+ },
+ })
+ return await withPostHogUrl(context, result, '/customer-analytics')
+ },
+})
+
+const AccountsPartialUpdateSchema = AccountsPartialUpdateParams.omit({ project_id: true })
+ .extend(AccountsPartialUpdateBody.shape)
+ .extend({
+ properties: AccountsPartialUpdateBody.shape['properties'].describe(
+ 'Typed account properties. The server replaces the `properties` object as a whole, so include any existing values you want to preserve. Supported keys: `csm`, `account_executive`, `account_owner`, each taking `{id, email}` of an existing user.'
+ ),
+ })
+
+const accountsPartialUpdate = (): ToolBase<typeof AccountsPartialUpdateSchema, Schemas.Account> => ({
+ name: 'accounts-partial-update',
+ schema: AccountsPartialUpdateSchema,
+ handler: async (context: Context, params: z.infer<typeof AccountsPartialUpdateSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.name !== undefined) {
+ body['name'] = params.name
+ }
+ if (params.external_id !== undefined) {
+ body['external_id'] = params.external_id
+ }
+ if (params.properties !== undefined) {
+ body['properties'] = params.properties
+ }
+ const result = await context.api.request<Schemas.Account>({
+ method: 'PATCH',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/accounts/${encodeURIComponent(String(params.id))}/`,
+ body,
+ })
+ return result
+ },
+})
+
+const AccountsRetrieveSchema = AccountsRetrieveParams.omit({ project_id: true })
+
+const accountsRetrieve = (): ToolBase<typeof AccountsRetrieveSchema, Schemas.Account> => ({
+ name: 'accounts-retrieve',
+ schema: AccountsRetrieveSchema,
+ handler: async (context: Context, params: z.infer<typeof AccountsRetrieveSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.Account>({
+ method: 'GET',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/accounts/${encodeURIComponent(String(params.id))}/`,
+ })
+ return result
+ },
+})
+
const UsageMetricsCreateSchema = GroupsTypesMetricsCreateParams.omit({ project_id: true })
.extend(GroupsTypesMetricsCreateBody.shape)
.extend({
@@ -181,6 +298,11 @@ const usageMetricsRetrieve = (): ToolBase<typeof UsageMetricsRetrieveSchema, Sch
})
export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
+ 'accounts-create': accountsCreate,
+ 'accounts-destroy': accountsDestroy,
+ 'accounts-list': accountsList,
+ 'accounts-partial-update': accountsPartialUpdate,
+ 'accounts-retrieve': accountsRetrieve,
'usage-metrics-create': usageMetricsCreate,
'usage-metrics-destroy': usageMetricsDestroy,
'usage-metrics-list': usageMetricsList,
diff --git a/services/mcp/tests/unit/tool-filtering.test.ts b/services/mcp/tests/unit/tool-filtering.test.ts
index ee8eae2c487b..6a5850e71d0b 100644
--- a/services/mcp/tests/unit/tool-filtering.test.ts
+++ b/services/mcp/tests/unit/tool-filtering.test.ts
@@ -643,9 +643,10 @@ describe('Tool Filtering - Feature Flags', () => {
'visual-review',
'mcp-feedback-tool',
'user-interviews',
+ 'customer-analytics-csp',
])
)
- expect(flags).toHaveLength(6)
+ expect(flags).toHaveLength(7)
})
// Test the filtering logic with a direct unit test approach using