: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mcp): accept native arrays for billing filters (#98152)
Pawel Cebula63470435e22d
diff --git a/products/billing/mcp/tools.yaml b/products/billing/mcp/tools.yamlindex 2847c198856f..e5587561e0b9 100644--- a/products/billing/mcp/tools.yaml+++ b/products/billing/mcp/tools.yaml@@ -156,22 +156,11 @@ tools:End date (YYYY-MM-DD), inclusive. Pass this whenever start_date is set; use today's date if the userdid not name one.team_ids:- description: >- JSON-encoded array of numeric team (project) IDs to filter by, NOT a comma-separated string. Pass as- e.g. `[1,2]`. Omit for every project this request can see: all org teams for full billing-access- callers, or the member's visible/project-scoped teams for member read-only callers.+ input_schema: BillingTeamIdsSchemausage_types:- description: >- JSON-encoded array of usage type identifiers to filter on, NOT a comma-separated string. Pass as- e.g. `["event_count_in_period"]` or `["event_count_in_period","recording_count_in_period"]`. Omit- for all usage types.+ input_schema: BillingUsageTypesSchemabreakdowns:- description: >- JSON-encoded array of dimensions to break down by, NOT a comma-separated string. Valid dimensions- are "type" (by product) and "team" (by project). Pass `["type"]` for per-product series, `["team"]`- for one series per project summed across products, or `["type","team"]` for per-project series- within each product. Omit for a single aggregate series. Sending a bare string like "type,team" will- fail with a 400 error.+ input_schema: BillingSpendBreakdownsSchemainterval:description: Time bucket size, one of "day", "week" or "month". Default "day".top_projects:@@ -233,22 +222,11 @@ tools:End date (YYYY-MM-DD), inclusive. Pass this whenever start_date is set; use today's date if the userdid not name one.team_ids:- description: >- JSON-encoded array of numeric team (project) IDs to filter by, NOT a comma-separated string. Pass as- e.g. `[1,2]`. Omit for every project this request can see: all org teams for full billing-access- callers, or the member's visible/project-scoped teams for member read-only callers.+ input_schema: BillingTeamIdsSchemausage_types:- description: >- JSON-encoded array of usage type identifiers to filter on, NOT a comma-separated string. Pass as- e.g. `["event_count_in_period"]` or `["event_count_in_period","recording_count_in_period"]`. Omit- for all usage types.+ input_schema: BillingUsageTypesSchemabreakdowns:- description: >- JSON-encoded array of dimensions to break down by, NOT a comma-separated string. Valid dimensions- are "type" (by usage type) and "team" (by project). Pass `["type"]` for per-usage-type series, or- `["type","team"]` for per-project series within each usage type. Team breakdowns require "type"; do- not pass `["team"]` by itself. Omit for a single aggregate series. Sending a bare string like- "type,team" will fail with a 400 error.+ input_schema: BillingUsageBreakdownsSchemainterval:description: Time bucket size, one of "day" or "week". Default "day".top_projects:diff --git a/services/mcp/schema/tool-inputs.json b/services/mcp/schema/tool-inputs.jsonindex 71d2c91e3350..9dc98f1d30c7 100644--- a/services/mcp/schema/tool-inputs.json+++ b/services/mcp/schema/tool-inputs.json@@ -15,6 +15,67 @@}}},+ "BillingSpendBreakdownsSchema": {+ "description": "Dimensions to break spend down by. Pass `[\"type\"]` for per-product series, `[\"team\"]` for one series per project summed across products, or `[\"type\",\"team\"]` for per-project series within each product. Omit for one aggregate series.",+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string",+ "enum": ["type", "team"]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "BillingTeamIdsSchema": {+ "description": "Project IDs to filter by, e.g. `[1,2]`. Omit for every project this request can see: all organization projects for full billing access, or the member-visible and token-scoped projects for member read-only access.",+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "integer",+ "exclusiveMinimum": 0,+ "maximum": 9007199254740991+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "BillingUsageBreakdownsSchema": {+ "description": "Dimensions to break usage down by. Pass `[\"type\"]` for per-usage-type series or `[\"type\",\"team\"]` for per-project series within each usage type. Team breakdowns require `\"type\"`; do not pass `[\"team\"]` by itself. Omit for one aggregate series.",+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string",+ "enum": ["type", "team"]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "BillingUsageTypesSchema": {+ "description": "Usage type identifiers to filter by, e.g. `[\"event_count_in_period\"]` or `[\"event_count_in_period\",\"recording_count_in_period\"]`. Omit for all usage types.",+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string",+ "minLength": 1+ }+ },+ {+ "type": "null"+ }+ ]+ },"BusinessKnowledgeUrlSourceCreateSchema": {"type": "object","properties": {diff --git a/services/mcp/src/schema/tool-inputs.ts b/services/mcp/src/schema/tool-inputs.tsindex 2390359655df..15714b92e8b9 100644--- a/services/mcp/src/schema/tool-inputs.ts+++ b/services/mcp/src/schema/tool-inputs.ts@@ -73,6 +73,34 @@ export const ExternalDataJobsSchemasSchema = z.array(z.string()).describe('Filter jobs by table schema names (e.g. ["users", "orders"]). Only returns jobs for these tables.')+export const BillingTeamIdsSchema = z+ .array(z.number().int().positive())+ .nullish()+ .describe(+ 'Project IDs to filter by, e.g. `[1,2]`. Omit for every project this request can see: all organization projects for full billing access, or the member-visible and token-scoped projects for member read-only access.'+ )++export const BillingUsageTypesSchema = z+ .array(z.string().min(1))+ .nullish()+ .describe(+ 'Usage type identifiers to filter by, e.g. `["event_count_in_period"]` or `["event_count_in_period","recording_count_in_period"]`. Omit for all usage types.'+ )++export const BillingSpendBreakdownsSchema = z+ .array(z.enum(['type', 'team']))+ .nullish()+ .describe(+ 'Dimensions to break spend down by. Pass `["type"]` for per-product series, `["team"]` for one series per project summed across products, or `["type","team"]` for per-project series within each product. Omit for one aggregate series.'+ )++export const BillingUsageBreakdownsSchema = z+ .array(z.enum(['type', 'team']))+ .nullish()+ .describe(+ 'Dimensions to break usage down by. Pass `["type"]` for per-usage-type series or `["type","team"]` for per-project series within each usage type. Team breakdowns require `"type"`; do not pass `["team"]` by itself. Omit for one aggregate series.'+ )+export const ExternalDataSourcePayloadSchema = z.record(z.string(), z.unknown()).describe(diff --git a/services/mcp/src/tools/generated/billing.ts b/services/mcp/src/tools/generated/billing.tsindex 36d421a12a4d..96f32cdc3c1c 100644--- a/services/mcp/src/tools/generated/billing.ts+++ b/services/mcp/src/tools/generated/billing.ts@@ -3,6 +3,12 @@ import { z } from 'zod'import type { Schemas } from '@/api/generated'import * as orvalSchemas from '@/generated/billing/api'+import {+ BillingSpendBreakdownsSchema,+ BillingTeamIdsSchema,+ BillingUsageBreakdownsSchema,+ BillingUsageTypesSchema,+} from '@/schema/tool-inputs'import { omitResponseFields, withInformationalResponse, type WithInformationalResponse } from '@/tools/tool-utils'import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'@@ -61,15 +67,9 @@ const BillingSpendGetSchema = () => {end_date: BillingSpendRetrieveQueryParams.shape['end_date'].describe("End date (YYYY-MM-DD), inclusive. Pass this whenever start_date is set; use today's date if the user did not name one."),- team_ids: BillingSpendRetrieveQueryParams.shape['team_ids'].describe(- "JSON-encoded array of numeric team (project) IDs to filter by, NOT a comma-separated string. Pass as e.g. `[1,2]`. Omit for every project this request can see: all org teams for full billing-access callers, or the member's visible/project-scoped teams for member read-only callers."- ),- usage_types: BillingSpendRetrieveQueryParams.shape['usage_types'].describe(- 'JSON-encoded array of usage type identifiers to filter on, NOT a comma-separated string. Pass as e.g. `["event_count_in_period"]` or `["event_count_in_period","recording_count_in_period"]`. Omit for all usage types.'- ),- breakdowns: BillingSpendRetrieveQueryParams.shape['breakdowns'].describe(- 'JSON-encoded array of dimensions to break down by, NOT a comma-separated string. Valid dimensions are "type" (by product) and "team" (by project). Pass `["type"]` for per-product series, `["team"]` for one series per project summed across products, or `["type","team"]` for per-project series within each product. Omit for a single aggregate series. Sending a bare string like "type,team" will fail with a 400 error.'- ),+ team_ids: BillingTeamIdsSchema,+ usage_types: BillingUsageTypesSchema,+ breakdowns: BillingSpendBreakdownsSchema,interval: BillingSpendRetrieveQueryParams.shape['interval'].describe('Time bucket size, one of "day", "week" or "month". Default "day".'),@@ -118,15 +118,9 @@ const BillingUsageGetSchema = () => {end_date: BillingUsageRetrieveQueryParams.shape['end_date'].describe("End date (YYYY-MM-DD), inclusive. Pass this whenever start_date is set; use today's date if the user did not name one."),- team_ids: BillingUsageRetrieveQueryParams.shape['team_ids'].describe(- "JSON-encoded array of numeric team (project) IDs to filter by, NOT a comma-separated string. Pass as e.g. `[1,2]`. Omit for every project this request can see: all org teams for full billing-access callers, or the member's visible/project-scoped teams for member read-only callers."- ),- usage_types: BillingUsageRetrieveQueryParams.shape['usage_types'].describe(- 'JSON-encoded array of usage type identifiers to filter on, NOT a comma-separated string. Pass as e.g. `["event_count_in_period"]` or `["event_count_in_period","recording_count_in_period"]`. Omit for all usage types.'- ),- breakdowns: BillingUsageRetrieveQueryParams.shape['breakdowns'].describe(- 'JSON-encoded array of dimensions to break down by, NOT a comma-separated string. Valid dimensions are "type" (by usage type) and "team" (by project). Pass `["type"]` for per-usage-type series, or `["type","team"]` for per-project series within each usage type. Team breakdowns require "type"; do not pass `["team"]` by itself. Omit for a single aggregate series. Sending a bare string like "type,team" will fail with a 400 error.'- ),+ team_ids: BillingTeamIdsSchema,+ usage_types: BillingUsageTypesSchema,+ breakdowns: BillingUsageBreakdownsSchema,interval: BillingUsageRetrieveQueryParams.shape['interval'].describe('Time bucket size, one of "day" or "week". Default "day".'),diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-spend-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-spend-get.jsonindex f4e0a797ec32..96a6eb93dd85 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-spend-get.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-spend-get.json@@ -16,13 +16,17 @@"breakdowns": {"anyOf": [{- "type": "string"+ "items": {+ "enum": ["type", "team"],+ "type": "string"+ },+ "type": "array"},{"type": "null"}],- "description": "JSON-encoded array of dimensions to break down by, NOT a comma-separated string. Valid dimensions are \"type\" (by product) and \"team\" (by project). Pass `[\"type\"]` for per-product series, `[\"team\"]` for one series per project summed across products, or `[\"type\",\"team\"]` for per-project series within each product. Omit for a single aggregate series. Sending a bare string like \"type,team\" will fail with a 400 error."+ "description": "Dimensions to break spend down by. Pass `[\"type\"]` for per-product series, `[\"team\"]` for one series per project summed across products, or `[\"type\",\"team\"]` for per-project series within each product. Omit for one aggregate series."},"end_date": {"anyOf": [@@ -73,13 +77,18 @@"team_ids": {"anyOf": [{- "type": "string"+ "items": {+ "exclusiveMinimum": 0,+ "maximum": 9007199254740991,+ "type": "integer"+ },+ "type": "array"},{"type": "null"}],- "description": "JSON-encoded array of numeric team (project) IDs to filter by, NOT a comma-separated string. Pass as e.g. `[1,2]`. Omit for every project this request can see: all org teams for full billing-access callers, or the member's visible/project-scoped teams for member read-only callers."+ "description": "Project IDs to filter by, e.g. `[1,2]`. Omit for every project this request can see: all organization projects for full billing access, or the member-visible and token-scoped projects for member read-only access."},"top_projects": {"anyOf": [@@ -97,13 +106,17 @@"usage_types": {"anyOf": [{- "type": "string"+ "items": {+ "minLength": 1,+ "type": "string"+ },+ "type": "array"},{"type": "null"}],- "description": "JSON-encoded array of usage type identifiers to filter on, NOT a comma-separated string. Pass as e.g. `[\"event_count_in_period\"]` or `[\"event_count_in_period\",\"recording_count_in_period\"]`. Omit for all usage types."+ "description": "Usage type identifiers to filter by, e.g. `[\"event_count_in_period\"]` or `[\"event_count_in_period\",\"recording_count_in_period\"]`. Omit for all usage types."}},"type": "object"diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-usage-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-usage-get.jsonindex 9999673893ca..4460a4e385eb 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-usage-get.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-usage-get.json@@ -16,13 +16,17 @@"breakdowns": {"anyOf": [{- "type": "string"+ "items": {+ "enum": ["type", "team"],+ "type": "string"+ },+ "type": "array"},{"type": "null"}],- "description": "JSON-encoded array of dimensions to break down by, NOT a comma-separated string. Valid dimensions are \"type\" (by usage type) and \"team\" (by project). Pass `[\"type\"]` for per-usage-type series, or `[\"type\",\"team\"]` for per-project series within each usage type. Team breakdowns require \"type\"; do not pass `[\"team\"]` by itself. Omit for a single aggregate series. Sending a bare string like \"type,team\" will fail with a 400 error."+ "description": "Dimensions to break usage down by. Pass `[\"type\"]` for per-usage-type series or `[\"type\",\"team\"]` for per-project series within each usage type. Team breakdowns require `\"type\"`; do not pass `[\"team\"]` by itself. Omit for one aggregate series."},"end_date": {"anyOf": [@@ -73,13 +77,18 @@"team_ids": {"anyOf": [{- "type": "string"+ "items": {+ "exclusiveMinimum": 0,+ "maximum": 9007199254740991,+ "type": "integer"+ },+ "type": "array"},{"type": "null"}],- "description": "JSON-encoded array of numeric team (project) IDs to filter by, NOT a comma-separated string. Pass as e.g. `[1,2]`. Omit for every project this request can see: all org teams for full billing-access callers, or the member's visible/project-scoped teams for member read-only callers."+ "description": "Project IDs to filter by, e.g. `[1,2]`. Omit for every project this request can see: all organization projects for full billing access, or the member-visible and token-scoped projects for member read-only access."},"top_projects": {"anyOf": [@@ -97,13 +106,17 @@"usage_types": {"anyOf": [{- "type": "string"+ "items": {+ "minLength": 1,+ "type": "string"+ },+ "type": "array"},{"type": "null"}],- "description": "JSON-encoded array of usage type identifiers to filter on, NOT a comma-separated string. Pass as e.g. `[\"event_count_in_period\"]` or `[\"event_count_in_period\",\"recording_count_in_period\"]`. Omit for all usage types."+ "description": "Usage type identifiers to filter by, e.g. `[\"event_count_in_period\"]` or `[\"event_count_in_period\",\"recording_count_in_period\"]`. Omit for all usage types."}},"type": "object"diff --git a/services/mcp/tests/unit/billing-filter-schema.test.ts b/services/mcp/tests/unit/billing-filter-schema.test.tsnew file mode 100644index 000000000000..8b5658dc1c1f--- /dev/null+++ b/services/mcp/tests/unit/billing-filter-schema.test.ts@@ -0,0 +1,13 @@+import { describe, expect, it } from 'vitest'++import { GENERATED_TOOLS } from '@/tools/generated/billing'++describe('billing usage filters', () => {+ it.each(['billing-spend-get', 'billing-usage-get'])('%s accepts null filters', (toolName) => {+ const input = { team_ids: null, usage_types: null, breakdowns: null }+ const result = GENERATED_TOOLS[toolName]!().schema.safeParse(input)++ expect(result.success).toBe(true)+ expect(result.data).toMatchObject(input)+ })+})