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.

fix(billing): hide billing alerts from public api docs and mcp (#110196)

Pawel Cebula7a8549fd6a5d
diff --git a/posthog/api/test/test_api_docs.py b/posthog/api/test/test_api_docs.py
index ef9a526d0f88..6076667f68ae 100644
--- a/posthog/api/test/test_api_docs.py
+++ b/posthog/api/test/test_api_docs.py
@@ -4,10 +4,12 @@ import re
from posthog.test.base import APIBaseTest
from unittest import mock
-from django.urls import path
+from django.urls import URLPattern, path
from drf_spectacular.generators import SchemaGenerator
+from parameterized import parameterized
from rest_framework import serializers, viewsets
+from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response
@@ -26,6 +28,19 @@ class _XInternalMarkerViewSet(viewsets.ViewSet):
return Response({"ok": True})
+@extend_schema(responses={200: _XInternalMarkerSerializer}, extensions={"x-internal": True})
+class _XInternalClassMarkerViewSet(viewsets.ViewSet):
+ scope_object = "project"
+
+ def list(self, request: Request) -> Response:
+ return Response({"ok": True})
+
+ @extend_schema(description="Marker action with its own schema annotation.")
+ @action(detail=False, methods=["GET"])
+ def summary(self, request: Request) -> Response:
+ return Response({"ok": True})
+
+
class _RequestDependentScopesViewSet(viewsets.ViewSet):
scope_object = "project"
request_dependent_scope_actions = frozenset({"retrieve"})
@@ -55,16 +70,34 @@ class TestAPIDocsSchema(APIBaseTest):
# The same action survives under the live project route
assert any(p.endswith("/tracing_config/") for p in paths)
- def test_x_internal_operations_are_only_in_the_codegen_schema(self) -> None:
- patterns = [path("api/x_internal_marker/", _XInternalMarkerViewSet.as_view({"get": "list"}))]
+ @parameterized.expand(
+ [
+ (
+ "method_annotation",
+ [path("api/x_internal_marker/", _XInternalMarkerViewSet.as_view({"get": "list"}))],
+ ),
+ (
+ "class_annotation_reaches_annotated_action",
+ [
+ path("api/x_internal_class_marker/", _XInternalClassMarkerViewSet.as_view({"get": "list"})),
+ path(
+ "api/x_internal_class_marker/summary/",
+ _XInternalClassMarkerViewSet.as_view({"get": "summary"}),
+ ),
+ ],
+ ),
+ ]
+ )
+ def test_x_internal_operations_are_only_in_the_codegen_schema(self, _name: str, patterns: list[URLPattern]) -> None:
+ expected_paths = sorted(f"/{pattern.pattern}" for pattern in patterns)
served_schema = SchemaGenerator(patterns=patterns).get_schema(request=None, public=True)
- assert "/api/x_internal_marker/" not in served_schema["paths"]
+ assert sorted(served_schema["paths"]) == []
codegen_env = {"OPENAPI_INCLUDE_INTERNAL": "1", "OPENAPI_MOCK_INTERNAL_API_SECRET": "1"}
with mock.patch.dict(os.environ, codegen_env):
codegen_schema = SchemaGenerator(patterns=patterns).get_schema(request=None, public=True)
- assert "/api/x_internal_marker/" in codegen_schema["paths"]
+ assert sorted(codegen_schema["paths"]) == expected_paths
def test_request_dependent_scope_marker_covers_only_listed_actions(self) -> None:
patterns = [
diff --git a/products/billing_alerts/backend/presentation/views.py b/products/billing_alerts/backend/presentation/views.py
index 483fa2414670..a9eca5fe1c68 100644
--- a/products/billing_alerts/backend/presentation/views.py
+++ b/products/billing_alerts/backend/presentation/views.py
@@ -32,7 +32,9 @@ from products.billing_alerts.backend.presentation.serializers import (
from products.billing_alerts.backend.presentation.throttles import BillingAlertCheckNowThrottle
-@extend_schema(tags=["billing"])
+# x-internal removes these operations from the public API docs because the API is behind the
+# `billing-alerts` flag. Codegen still includes them, so the frontend types stay.
+@extend_schema(tags=["billing"], extensions={"x-internal": True})
class BillingAlertViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
scope_object = "organization"
queryset = BillingAlertConfiguration.objects.all()
diff --git a/products/billing_alerts/mcp/tools.yaml b/products/billing_alerts/mcp/tools.yaml
index 1ce62b962b7d..9283dc40f878 100644
--- a/products/billing_alerts/mcp/tools.yaml
+++ b/products/billing_alerts/mcp/tools.yaml
@@ -9,7 +9,8 @@ ui_apps: {}
tools:
billing-alert-create:
operation: billing_alerts_create
- enabled: true
+ enabled: false
+ disabled_reason: Billing alerts are not ready for general use.
scopes:
- organization:write
annotations:
@@ -27,7 +28,8 @@ tools:
feature_flag: billing-alerts
billing-alert-update:
operation: billing_alerts_partial_update
- enabled: true
+ enabled: false
+ disabled_reason: Billing alerts are not ready for general use.
scopes:
- organization:write
annotations:
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 69005826e9c4..55a6dd2f6a12 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -1504,36 +1504,6 @@
"readOnlyHint": true
}
},
- "billing-alert-create": {
- "description": "Create a billing-period spend alert in the active organization. The caller must be an organization Admin or Owner. Billing owns the trigger configuration and evaluation; the shared alerting backend handles lifecycle, scheduling, destinations, and delivery. The metric picks the billing-period total to watch: spend (current period total so far) or projected_spend (projected period-end total). The first version supports only the absolute_value threshold rule with threshold_value, in USD. Optional destination_changes can create Slack, Microsoft Teams, or HTTPS webhook destinations atomically with the alert.",
- "category": "Billing alerts",
- "feature": "billing_alerts",
- "summary": "Create billing alert",
- "title": "Create billing alert",
- "required_scopes": ["organization:write"],
- "annotations": {
- "destructiveHint": false,
- "idempotentHint": false,
- "openWorldHint": true,
- "readOnlyHint": false
- },
- "feature_flag": "billing-alerts"
- },
- "billing-alert-update": {
- "description": "Partially update a billing alert by ID in the active organization. The caller must be an organization Admin or Owner. Change only the supplied trigger fields, alert copy, enabled state, snooze, or cooldown. The metric picks the billing-period total to watch (spend or projected_spend); the first version supports only the absolute_value threshold rule with threshold_value, in USD. Optional destination_changes applies destination creation or complete-group deletion in the same backend transaction as the configuration update. Repeating a request that creates a destination of the same type is rejected, because an alert allows one destination group per type.",
- "category": "Billing alerts",
- "feature": "billing_alerts",
- "summary": "Update billing alert",
- "title": "Update billing alert",
- "required_scopes": ["organization:write"],
- "annotations": {
- "destructiveHint": true,
- "idempotentHint": false,
- "openWorldHint": true,
- "readOnlyHint": false
- },
- "feature_flag": "billing-alerts"
- },
"billing-features-get": {
"description": "The product features the organization's plans include, with any overrides applied. The cheapest read in the billing API, readable by any member. Use it to check whether a feature such as group analytics or white-labelling is available before suggesting it. Beta: behind the organization-billing-api flag, and the output shape may change while it is.",
"category": "Billing",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index e466ed8c2eeb..cb78e93719d5 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -1519,36 +1519,6 @@
"readOnlyHint": true
}
},
- "billing-alert-create": {
- "description": "Create a billing-period spend alert in the active organization. The caller must be an organization Admin or Owner. Billing owns the trigger configuration and evaluation; the shared alerting backend handles lifecycle, scheduling, destinations, and delivery. The metric picks the billing-period total to watch: spend (current period total so far) or projected_spend (projected period-end total). The first version supports only the absolute_value threshold rule with threshold_value, in USD. Optional destination_changes can create Slack, Microsoft Teams, or HTTPS webhook destinations atomically with the alert.",
- "category": "Billing alerts",
- "feature": "billing_alerts",
- "summary": "Create billing alert",
- "title": "Create billing alert",
- "required_scopes": ["organization:write"],
- "annotations": {
- "destructiveHint": false,
- "idempotentHint": false,
- "openWorldHint": true,
- "readOnlyHint": false
- },
- "feature_flag": "billing-alerts"
- },
- "billing-alert-update": {
- "description": "Partially update a billing alert by ID in the active organization. The caller must be an organization Admin or Owner. Change only the supplied trigger fields, alert copy, enabled state, snooze, or cooldown. The metric picks the billing-period total to watch (spend or projected_spend); the first version supports only the absolute_value threshold rule with threshold_value, in USD. Optional destination_changes applies destination creation or complete-group deletion in the same backend transaction as the configuration update. Repeating a request that creates a destination of the same type is rejected, because an alert allows one destination group per type.",
- "category": "Billing alerts",
- "feature": "billing_alerts",
- "summary": "Update billing alert",
- "title": "Update billing alert",
- "required_scopes": ["organization:write"],
- "annotations": {
- "destructiveHint": true,
- "idempotentHint": false,
- "openWorldHint": true,
- "readOnlyHint": false
- },
- "feature_flag": "billing-alerts"
- },
"billing-features-get": {
"description": "The product features the organization's plans include, with any overrides applied. The cheapest read in the billing API, readable by any member. Use it to check whether a feature such as group analytics or white-labelling is available before suggesting it. Beta: behind the organization-billing-api flag, and the output shape may change while it is.",
"category": "Billing",
diff --git a/services/mcp/src/generated/billing_alerts/api.ts b/services/mcp/src/generated/billing_alerts/api.ts
deleted file mode 100644
index 035e9dd7109e..000000000000
--- a/services/mcp/src/generated/billing_alerts/api.ts
+++ /dev/null
@@ -1,240 +0,0 @@
-/**
- * Auto-generated from the Django backend OpenAPI schema.
- * MCP service uses these Zod schemas for generated tool handlers.
- * To regenerate: hogli build:openapi
- *
- * PostHog API - MCP 2 enabled ops
- * OpenAPI spec version: 1.0.0
- */
-import * as zod from 'zod'
-
-export const BillingAlertsCreateParams = () => zod.object({
- organization_id: zod
- .string()
- .describe(
- "ID of the organization you're trying to access. To find the ID of the organization, make a call to \/api\/organizations\/."
- ),
-})
-
-export const billingAlertsCreateBodyNameMax = 160
-
-export const billingAlertsCreateBodyThresholdPercentageRegExp = new RegExp('^-?\\d{0,6}(?:\\.\\d{0,2})?$')
-export const billingAlertsCreateBodyThresholdValueRegExp = new RegExp('^-?\\d{0,14}(?:\\.\\d{0,6})?$')
-export const billingAlertsCreateBodyMinimumValueRegExp = new RegExp('^-?\\d{0,14}(?:\\.\\d{0,6})?$')
-export const billingAlertsCreateBodyBaselineWindowDaysMax = 90
-
-export const billingAlertsCreateBodyEvaluationDelayHoursMin = 0
-export const billingAlertsCreateBodyEvaluationDelayHoursMax = 72
-
-export const billingAlertsCreateBodyCooldownHoursMin = 0
-export const billingAlertsCreateBodyCooldownHoursMax = 720
-
-export const billingAlertsCreateBodyDestinationChangesOneDeleteItemMax = 100
-
-export const BillingAlertsCreateBody = () => zod.object({
- name: zod.string().max(billingAlertsCreateBodyNameMax).describe('Display name for this billing alert.'),
- description: zod.string().optional().describe('Optional internal description.'),
- enabled: zod.boolean().optional().describe('Whether scheduled checks should evaluate this alert.'),
- metric: zod
- .enum(['spend', 'projected_spend'])
- .describe('\* `spend` - Spend\n\* `projected_spend` - Projected spend')
- .optional()
- .describe(
- 'Billing-period total to evaluate: current spend so far, or projected period-end spend.\n\n\* `spend` - Spend\n\* `projected_spend` - Projected spend'
- ),
- threshold_type: zod
- .enum(['relative_increase', 'absolute_value', 'absolute_increase'])
- .describe(
- '\* `relative_increase` - Relative increase\n\* `absolute_value` - Absolute value\n\* `absolute_increase` - Absolute increase'
- )
- .optional()
- .describe(
- 'Threshold rule type. The first version supports absolute value only.\n\n\* `relative_increase` - Relative increase\n\* `absolute_value` - Absolute value\n\* `absolute_increase` - Absolute increase'
- ),
- threshold_percentage: zod
- .stringFormat('decimal', billingAlertsCreateBodyThresholdPercentageRegExp)
- .nullish()
- .describe('Reserved for future increase-over-baseline rules. Not used by absolute value alerts.'),
- threshold_value: zod
- .stringFormat('decimal', billingAlertsCreateBodyThresholdValueRegExp)
- .nullish()
- .describe('Absolute value or absolute increase that triggers absolute threshold alerts.'),
- minimum_value: zod
- .stringFormat('decimal', billingAlertsCreateBodyMinimumValueRegExp)
- .optional()
- .describe('Minimum current value before the alert can fire.'),
- baseline_window_days: zod
- .number()
- .min(1)
- .max(billingAlertsCreateBodyBaselineWindowDaysMax)
- .optional()
- .describe('Reserved for future increase-over-baseline rules. Not used by absolute value alerts.'),
- evaluation_delay_hours: zod
- .number()
- .min(billingAlertsCreateBodyEvaluationDelayHoursMin)
- .max(billingAlertsCreateBodyEvaluationDelayHoursMax)
- .optional()
- .describe('Hours after a UTC billing date ends before it becomes eligible for evaluation.'),
- cooldown_hours: zod
- .number()
- .min(billingAlertsCreateBodyCooldownHoursMin)
- .max(billingAlertsCreateBodyCooldownHoursMax)
- .optional()
- .describe('Minimum hours between repeated firing notifications.'),
- snoozed_until: zod.iso
- .datetime({ offset: true })
- .nullish()
- .describe('ISO 8601 timestamp until which evaluation and notifications are snoozed, or null to resume.'),
- destination_changes: zod
- .object({
- delete: zod
- .array(zod.array(zod.string()).min(1).max(billingAlertsCreateBodyDestinationChangesOneDeleteItemMax))
- .optional(),
- create: zod
- .array(
- zod.object({
- type: zod
- .enum(['slack', 'webhook', 'teams'])
- .describe('\* `slack` - slack\n\* `webhook` - webhook\n\* `teams` - teams')
- .describe(
- 'Destination type.\n\n\* `slack` - slack\n\* `webhook` - webhook\n\* `teams` - teams'
- ),
- slack_workspace_id: zod
- .number()
- .optional()
- .describe('Slack integration ID in the alert execution project.'),
- slack_channel_id: zod.string().optional().describe('Slack channel ID for alert delivery.'),
- slack_channel_name: zod
- .string()
- .optional()
- .describe('Optional Slack channel name shown in the UI.'),
- webhook_url: zod
- .url()
- .optional()
- .describe('HTTPS webhook URL for webhook or Microsoft Teams delivery.'),
- })
- )
- .optional(),
- })
- .optional()
- .describe('Destination groups to create or delete in the same transaction as this configuration write.'),
-})
-
-export const BillingAlertsPartialUpdateParams = () => zod.object({
- id: zod.string().describe('A UUID string identifying this billing alert configuration.'),
- organization_id: zod
- .string()
- .describe(
- "ID of the organization you're trying to access. To find the ID of the organization, make a call to \/api\/organizations\/."
- ),
-})
-
-export const billingAlertsPartialUpdateBodyNameMax = 160
-
-export const billingAlertsPartialUpdateBodyThresholdPercentageRegExp = new RegExp('^-?\\d{0,6}(?:\\.\\d{0,2})?$')
-export const billingAlertsPartialUpdateBodyThresholdValueRegExp = new RegExp('^-?\\d{0,14}(?:\\.\\d{0,6})?$')
-export const billingAlertsPartialUpdateBodyMinimumValueRegExp = new RegExp('^-?\\d{0,14}(?:\\.\\d{0,6})?$')
-export const billingAlertsPartialUpdateBodyBaselineWindowDaysMax = 90
-
-export const billingAlertsPartialUpdateBodyEvaluationDelayHoursMin = 0
-export const billingAlertsPartialUpdateBodyEvaluationDelayHoursMax = 72
-
-export const billingAlertsPartialUpdateBodyCooldownHoursMin = 0
-export const billingAlertsPartialUpdateBodyCooldownHoursMax = 720
-
-export const billingAlertsPartialUpdateBodyDestinationChangesOneDeleteItemMax = 100
-
-export const BillingAlertsPartialUpdateBody = () => zod.object({
- name: zod
- .string()
- .max(billingAlertsPartialUpdateBodyNameMax)
- .optional()
- .describe('Display name for this billing alert.'),
- description: zod.string().optional().describe('Optional internal description.'),
- enabled: zod.boolean().optional().describe('Whether scheduled checks should evaluate this alert.'),
- metric: zod
- .enum(['spend', 'projected_spend'])
- .describe('\* `spend` - Spend\n\* `projected_spend` - Projected spend')
- .optional()
- .describe(
- 'Billing-period total to evaluate: current spend so far, or projected period-end spend.\n\n\* `spend` - Spend\n\* `projected_spend` - Projected spend'
- ),
- threshold_type: zod
- .enum(['relative_increase', 'absolute_value', 'absolute_increase'])
- .describe(
- '\* `relative_increase` - Relative increase\n\* `absolute_value` - Absolute value\n\* `absolute_increase` - Absolute increase'
- )
- .optional()
- .describe(
- 'Threshold rule type. The first version supports absolute value only.\n\n\* `relative_increase` - Relative increase\n\* `absolute_value` - Absolute value\n\* `absolute_increase` - Absolute increase'
- ),
- threshold_percentage: zod
- .stringFormat('decimal', billingAlertsPartialUpdateBodyThresholdPercentageRegExp)
- .nullish()
- .describe('Reserved for future increase-over-baseline rules. Not used by absolute value alerts.'),
- threshold_value: zod
- .stringFormat('decimal', billingAlertsPartialUpdateBodyThresholdValueRegExp)
- .nullish()
- .describe('Absolute value or absolute increase that triggers absolute threshold alerts.'),
- minimum_value: zod
- .stringFormat('decimal', billingAlertsPartialUpdateBodyMinimumValueRegExp)
- .optional()
- .describe('Minimum current value before the alert can fire.'),
- baseline_window_days: zod
- .number()
- .min(1)
- .max(billingAlertsPartialUpdateBodyBaselineWindowDaysMax)
- .optional()
- .describe('Reserved for future increase-over-baseline rules. Not used by absolute value alerts.'),
- evaluation_delay_hours: zod
- .number()
- .min(billingAlertsPartialUpdateBodyEvaluationDelayHoursMin)
- .max(billingAlertsPartialUpdateBodyEvaluationDelayHoursMax)
- .optional()
- .describe('Hours after a UTC billing date ends before it becomes eligible for evaluation.'),
- cooldown_hours: zod
- .number()
- .min(billingAlertsPartialUpdateBodyCooldownHoursMin)
- .max(billingAlertsPartialUpdateBodyCooldownHoursMax)
- .optional()
- .describe('Minimum hours between repeated firing notifications.'),
- snoozed_until: zod.iso
- .datetime({ offset: true })
- .nullish()
- .describe('ISO 8601 timestamp until which evaluation and notifications are snoozed, or null to resume.'),
- destination_changes: zod
- .object({
- delete: zod
- .array(
- zod.array(zod.string()).min(1).max(billingAlertsPartialUpdateBodyDestinationChangesOneDeleteItemMax)
- )
- .optional(),
- create: zod
- .array(
- zod.object({
- type: zod
- .enum(['slack', 'webhook', 'teams'])
- .describe('\* `slack` - slack\n\* `webhook` - webhook\n\* `teams` - teams')
- .describe(
- 'Destination type.\n\n\* `slack` - slack\n\* `webhook` - webhook\n\* `teams` - teams'
- ),
- slack_workspace_id: zod
- .number()
- .optional()
- .describe('Slack integration ID in the alert execution project.'),
- slack_channel_id: zod.string().optional().describe('Slack channel ID for alert delivery.'),
- slack_channel_name: zod
- .string()
- .optional()
- .describe('Optional Slack channel name shown in the UI.'),
- webhook_url: zod
- .url()
- .optional()
- .describe('HTTPS webhook URL for webhook or Microsoft Teams delivery.'),
- })
- )
- .optional(),
- })
- .optional()
- .describe('Destination groups to create or delete in the same transaction as this configuration write.'),
-})
diff --git a/services/mcp/src/tools/generated/billing_alerts.ts b/services/mcp/src/tools/generated/billing_alerts.ts
deleted file mode 100644
index 8f011d9dcf5c..000000000000
--- a/services/mcp/src/tools/generated/billing_alerts.ts
+++ /dev/null
@@ -1,136 +0,0 @@
-// AUTO-GENERATED from products/billing_alerts/mcp/tools.yaml + OpenAPI — do not edit
-import { z } from 'zod'
-
-import type { Schemas } from '@/api/generated'
-import * as orvalSchemas from '@/generated/billing_alerts/api'
-import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
-
-const BillingAlertCreateSchema = () => {
- const BillingAlertsCreateBody = orvalSchemas.BillingAlertsCreateBody()
- return BillingAlertsCreateBody
-}
-
-const billingAlertCreate = (): ToolBase<
- ReturnType<typeof BillingAlertCreateSchema>,
- Schemas.BillingAlertConfiguration
-> => ({
- name: 'billing-alert-create',
- schema: BillingAlertCreateSchema(),
- handler: async (context: Context, params: z.infer<ReturnType<typeof BillingAlertCreateSchema>>) => {
- const orgId = await context.stateManager.getOrgID()
- const body: Record<string, unknown> = {}
- if (params.name !== undefined) {
- body['name'] = params.name
- }
- if (params.description !== undefined) {
- body['description'] = params.description
- }
- if (params.enabled !== undefined) {
- body['enabled'] = params.enabled
- }
- if (params.metric !== undefined) {
- body['metric'] = params.metric
- }
- if (params.threshold_type !== undefined) {
- body['threshold_type'] = params.threshold_type
- }
- if (params.threshold_percentage !== undefined) {
- body['threshold_percentage'] = params.threshold_percentage
- }
- if (params.threshold_value !== undefined) {
- body['threshold_value'] = params.threshold_value
- }
- if (params.minimum_value !== undefined) {
- body['minimum_value'] = params.minimum_value
- }
- if (params.baseline_window_days !== undefined) {
- body['baseline_window_days'] = params.baseline_window_days
- }
- if (params.evaluation_delay_hours !== undefined) {
- body['evaluation_delay_hours'] = params.evaluation_delay_hours
- }
- if (params.cooldown_hours !== undefined) {
- body['cooldown_hours'] = params.cooldown_hours
- }
- if (params.snoozed_until !== undefined) {
- body['snoozed_until'] = params.snoozed_until
- }
- if (params.destination_changes !== undefined) {
- body['destination_changes'] = params.destination_changes
- }
- const result = await context.api.request<Schemas.BillingAlertConfiguration>({
- method: 'POST',
- path: `/api/organizations/${encodeURIComponent(String(orgId))}/billing/alerts/`,
- body,
- })
- return result
- },
-})
-
-const BillingAlertUpdateSchema = () => {
- const BillingAlertsPartialUpdateBody = orvalSchemas.BillingAlertsPartialUpdateBody()
- const BillingAlertsPartialUpdateParams = orvalSchemas.BillingAlertsPartialUpdateParams()
- return BillingAlertsPartialUpdateParams.omit({ organization_id: true }).extend(BillingAlertsPartialUpdateBody.shape)
-}
-
-const billingAlertUpdate = (): ToolBase<
- ReturnType<typeof BillingAlertUpdateSchema>,
- Schemas.BillingAlertConfiguration
-> => ({
- name: 'billing-alert-update',
- schema: BillingAlertUpdateSchema(),
- handler: async (context: Context, params: z.infer<ReturnType<typeof BillingAlertUpdateSchema>>) => {
- const orgId = await context.stateManager.getOrgID()
- const body: Record<string, unknown> = {}
- if (params.name !== undefined) {
- body['name'] = params.name
- }
- if (params.description !== undefined) {
- body['description'] = params.description
- }
- if (params.enabled !== undefined) {
- body['enabled'] = params.enabled
- }
- if (params.metric !== undefined) {
- body['metric'] = params.metric
- }
- if (params.threshold_type !== undefined) {
- body['threshold_type'] = params.threshold_type
- }
- if (params.threshold_percentage !== undefined) {
- body['threshold_percentage'] = params.threshold_percentage
- }
- if (params.threshold_value !== undefined) {
- body['threshold_value'] = params.threshold_value
- }
- if (params.minimum_value !== undefined) {
- body['minimum_value'] = params.minimum_value
- }
- if (params.baseline_window_days !== undefined) {
- body['baseline_window_days'] = params.baseline_window_days
- }
- if (params.evaluation_delay_hours !== undefined) {
- body['evaluation_delay_hours'] = params.evaluation_delay_hours
- }
- if (params.cooldown_hours !== undefined) {
- body['cooldown_hours'] = params.cooldown_hours
- }
- if (params.snoozed_until !== undefined) {
- body['snoozed_until'] = params.snoozed_until
- }
- if (params.destination_changes !== undefined) {
- body['destination_changes'] = params.destination_changes
- }
- const result = await context.api.request<Schemas.BillingAlertConfiguration>({
- method: 'PATCH',
- path: `/api/organizations/${encodeURIComponent(String(orgId))}/billing/alerts/${encodeURIComponent(String(params.id))}/`,
- body,
- })
- return result
- },
-})
-
-export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
- 'billing-alert-create': billingAlertCreate,
- 'billing-alert-update': billingAlertUpdate,
-}
diff --git a/services/mcp/src/tools/generated/index.ts b/services/mcp/src/tools/generated/index.ts
index 2783c4c0be02..20d29ea8ce60 100644
--- a/services/mcp/src/tools/generated/index.ts
+++ b/services/mcp/src/tools/generated/index.ts
@@ -9,7 +9,6 @@ import { GENERATED_TOOLS as annotations } from './annotations'
import { GENERATED_TOOLS as autoresearch } from './autoresearch'
import { GENERATED_TOOLS as batch_exports } from './batch_exports'
import { GENERATED_TOOLS as billing } from './billing'
-import { GENERATED_TOOLS as billing_alerts } from './billing_alerts'
import { GENERATED_TOOLS as business_knowledge } from './business_knowledge'
import { GENERATED_TOOLS as canvas } from './canvas'
import { GENERATED_TOOLS as cdp_function_templates } from './cdp_function_templates'
@@ -78,7 +77,6 @@ export const GENERATED_TOOL_MAP: Record<string, () => ToolBase<ZodObjectAny>> =
...autoresearch,
...batch_exports,
...billing,
- ...billing_alerts,
...business_knowledge,
...canvas,
...cdp_function_templates,
diff --git a/services/mcp/tests/tools/billingAlerts.integration.test.ts b/services/mcp/tests/tools/billingAlerts.integration.test.ts
deleted file mode 100644
index 8b47b1f341c7..000000000000
--- a/services/mcp/tests/tools/billingAlerts.integration.test.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-import { afterEach, beforeAll, describe, expect, it } from 'vitest'
-
-import {
- TEST_ORG_ID,
- TEST_PROJECT_ID,
- createTestClient,
- createTestContext,
- generateUniqueKey,
- parseToolResponse,
- setActiveProjectAndOrg,
- validateEnvironmentVariables,
-} from '@/shared/test-utils'
-import { GENERATED_TOOLS } from '@/tools/generated/billing_alerts'
-import type { Context } from '@/tools/types'
-
-describe('Billing alerts', { concurrent: false }, () => {
- let context: Context
- const createdAlertIds: string[] = []
-
- const createTool = GENERATED_TOOLS['billing-alert-create']!()
- const updateTool = GENERATED_TOOLS['billing-alert-update']!()
-
- beforeAll(async () => {
- validateEnvironmentVariables()
- const client = createTestClient()
- context = createTestContext(client)
- await setActiveProjectAndOrg(context, TEST_PROJECT_ID!, TEST_ORG_ID!)
- })
-
- afterEach(async () => {
- for (const id of createdAlertIds) {
- try {
- await context.api.request({
- method: 'DELETE',
- path: `/api/organizations/${encodeURIComponent(TEST_ORG_ID!)}/billing/alerts/${encodeURIComponent(id)}/`,
- })
- } catch {
- // Best effort. The alert may already have been removed.
- }
- }
- createdAlertIds.length = 0
- })
-
- it('creates and partially updates an organization billing alert', async () => {
- const name = `MCP billing alert ${generateUniqueKey('billing')}`
- const createResult = await createTool.handler(context, {
- name,
- enabled: false,
- threshold_type: 'absolute_value',
- threshold_value: '100.000000',
- })
- const created = parseToolResponse(createResult)
- createdAlertIds.push(created.id)
-
- expect(created.name).toBe(name)
- expect(created.threshold_type).toBe('absolute_value')
- expect(created.threshold_value).toBe('100.000000')
- expect(created.configuration_revision).toBe(1)
-
- const updatedName = `${name} updated`
- const updateResult = await updateTool.handler(context, {
- id: created.id,
- name: updatedName,
- threshold_value: '125.000000',
- })
- const updated = parseToolResponse(updateResult)
-
- expect(updated.id).toBe(created.id)
- expect(updated.name).toBe(updatedName)
- expect(updated.threshold_value).toBe('125.000000')
- expect(updated.configuration_revision).toBe(2)
- })
-})
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-alert-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-alert-create.json
deleted file mode 100644
index 3683509a0820..000000000000
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-alert-create.json
+++ /dev/null
@@ -1,141 +0,0 @@
-{
- "$schema": "https://json-schema.org/draft/2020-12/schema",
- "properties": {
- "baseline_window_days": {
- "description": "Reserved for future increase-over-baseline rules. Not used by absolute value alerts.",
- "maximum": 90,
- "minimum": 1,
- "type": "number"
- },
- "cooldown_hours": {
- "description": "Minimum hours between repeated firing notifications.",
- "maximum": 720,
- "minimum": 0,
- "type": "number"
- },
- "description": {
- "description": "Optional internal description.",
- "type": "string"
- },
- "destination_changes": {
- "description": "Destination groups to create or delete in the same transaction as this configuration write.",
- "properties": {
- "create": {
- "items": {
- "properties": {
- "slack_channel_id": {
- "description": "Slack channel ID for alert delivery.",
- "type": "string"
- },
- "slack_channel_name": {
- "description": "Optional Slack channel name shown in the UI.",
- "type": "string"
- },
- "slack_workspace_id": {
- "description": "Slack integration ID in the alert execution project.",
- "type": "number"
- },
- "type": {
- "description": "Destination type.\n\n* `slack` - slack\n* `webhook` - webhook\n* `teams` - teams",
- "enum": ["slack", "webhook", "teams"],
- "type": "string"
- },
- "webhook_url": {
- "description": "HTTPS webhook URL for webhook or Microsoft Teams delivery.",
- "format": "uri",
- "type": "string"
- }
- },
- "required": ["type"],
- "type": "object"
- },
- "type": "array"
- },
- "delete": {
- "items": {
- "items": {
- "type": "string"
- },
- "maxItems": 100,
- "minItems": 1,
- "type": "array"
- },
- "type": "array"
- }
- },
- "type": "object"
- },
- "enabled": {
- "description": "Whether scheduled checks should evaluate this alert.",
- "type": "boolean"
- },
- "evaluation_delay_hours": {
- "description": "Hours after a UTC billing date ends before it becomes eligible for evaluation.",
- "maximum": 72,
- "minimum": 0,
- "type": "number"
- },
- "metric": {
- "description": "Billing-period total to evaluate: current spend so far, or projected period-end spend.\n\n* `spend` - Spend\n* `projected_spend` - Projected spend",
- "enum": ["spend", "projected_spend"],
- "type": "string"
- },
- "minimum_value": {
- "description": "Minimum current value before the alert can fire.",
- "format": "decimal",
- "pattern": "^-?\\d{0,14}(?:\\.\\d{0,6})?$",
- "type": "string"
- },
- "name": {
- "description": "Display name for this billing alert.",
- "maxLength": 160,
- "type": "string"
- },
- "snoozed_until": {
- "anyOf": [
- {
- "format": "date-time",
- "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "description": "ISO 8601 timestamp until which evaluation and notifications are snoozed, or null to resume."
- },
- "threshold_percentage": {
- "anyOf": [
- {
- "format": "decimal",
- "pattern": "^-?\\d{0,6}(?:\\.\\d{0,2})?$",
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "description": "Reserved for future increase-over-baseline rules. Not used by absolute value alerts."
- },
- "threshold_type": {
- "description": "Threshold rule type. The first version supports absolute value only.\n\n* `relative_increase` - Relative increase\n* `absolute_value` - Absolute value\n* `absolute_increase` - Absolute increase",
- "enum": ["relative_increase", "absolute_value", "absolute_increase"],
- "type": "string"
- },
- "threshold_value": {
- "anyOf": [
- {
- "format": "decimal",
- "pattern": "^-?\\d{0,14}(?:\\.\\d{0,6})?$",
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "description": "Absolute value or absolute increase that triggers absolute threshold alerts."
- }
- },
- "required": ["name"],
- "type": "object"
-}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-alert-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-alert-update.json
deleted file mode 100644
index be7198c060f2..000000000000
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/billing-alert-update.json
+++ /dev/null
@@ -1,145 +0,0 @@
-{
- "$schema": "https://json-schema.org/draft/2020-12/schema",
- "properties": {
- "baseline_window_days": {
- "description": "Reserved for future increase-over-baseline rules. Not used by absolute value alerts.",
- "maximum": 90,
- "minimum": 1,
- "type": "number"
- },
- "cooldown_hours": {
- "description": "Minimum hours between repeated firing notifications.",
- "maximum": 720,
- "minimum": 0,
- "type": "number"
- },
- "description": {
- "description": "Optional internal description.",
- "type": "string"
- },
- "destination_changes": {
- "description": "Destination groups to create or delete in the same transaction as this configuration write.",
- "properties": {
- "create": {
- "items": {
- "properties": {
- "slack_channel_id": {
- "description": "Slack channel ID for alert delivery.",
- "type": "string"
- },
- "slack_channel_name": {
- "description": "Optional Slack channel name shown in the UI.",
- "type": "string"
- },
- "slack_workspace_id": {
- "description": "Slack integration ID in the alert execution project.",
- "type": "number"
- },
- "type": {
- "description": "Destination type.\n\n* `slack` - slack\n* `webhook` - webhook\n* `teams` - teams",
- "enum": ["slack", "webhook", "teams"],
- "type": "string"
- },
- "webhook_url": {
- "description": "HTTPS webhook URL for webhook or Microsoft Teams delivery.",
- "format": "uri",
- "type": "string"
- }
- },
- "required": ["type"],
- "type": "object"
- },
- "type": "array"
- },
- "delete": {
- "items": {
- "items": {
- "type": "string"
- },
- "maxItems": 100,
- "minItems": 1,
- "type": "array"
- },
- "type": "array"
- }
- },
- "type": "object"
- },
- "enabled": {
- "description": "Whether scheduled checks should evaluate this alert.",
- "type": "boolean"
- },
- "evaluation_delay_hours": {
- "description": "Hours after a UTC billing date ends before it becomes eligible for evaluation.",
- "maximum": 72,
- "minimum": 0,
- "type": "number"
- },
- "id": {
- "description": "A UUID string identifying this billing alert configuration.",
- "type": "string"
- },
- "metric": {
- "description": "Billing-period total to evaluate: current spend so far, or projected period-end spend.\n\n* `spend` - Spend\n* `projected_spend` - Projected spend",
- "enum": ["spend", "projected_spend"],
- "type": "string"
- },
- "minimum_value": {
- "description": "Minimum current value before the alert can fire.",
- "format": "decimal",
- "pattern": "^-?\\d{0,14}(?:\\.\\d{0,6})?$",
- "type": "string"
- },
- "name": {
- "description": "Display name for this billing alert.",
- "maxLength": 160,
- "type": "string"
- },
- "snoozed_until": {
- "anyOf": [
- {
- "format": "date-time",
- "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "description": "ISO 8601 timestamp until which evaluation and notifications are snoozed, or null to resume."
- },
- "threshold_percentage": {
- "anyOf": [
- {
- "format": "decimal",
- "pattern": "^-?\\d{0,6}(?:\\.\\d{0,2})?$",
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "description": "Reserved for future increase-over-baseline rules. Not used by absolute value alerts."
- },
- "threshold_type": {
- "description": "Threshold rule type. The first version supports absolute value only.\n\n* `relative_increase` - Relative increase\n* `absolute_value` - Absolute value\n* `absolute_increase` - Absolute increase",
- "enum": ["relative_increase", "absolute_value", "absolute_increase"],
- "type": "string"
- },
- "threshold_value": {
- "anyOf": [
- {
- "format": "decimal",
- "pattern": "^-?\\d{0,14}(?:\\.\\d{0,6})?$",
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "description": "Absolute value or absolute increase that triggers absolute threshold alerts."
- }
- },
- "required": ["id"],
- "type": "object"
-}
diff --git a/services/mcp/tests/unit/tool-filtering.test.ts b/services/mcp/tests/unit/tool-filtering.test.ts
index 95608861275a..06f59231f956 100644
--- a/services/mcp/tests/unit/tool-filtering.test.ts
+++ b/services/mcp/tests/unit/tool-filtering.test.ts
@@ -1087,7 +1087,6 @@ describe('Tool Filtering - Feature Flags', () => {
'loops-hog-flows',
'review-hog',
'warehouse-person-properties',
- 'billing-alerts',
'organization-billing-api',
'streamlit-apps',
'posthog-connect',
@@ -1102,7 +1101,7 @@ describe('Tool Filtering - Feature Flags', () => {
])
)
expect(flags).toContain('ai-observability-offline-evaluations')
- expect(flags).toHaveLength(39)
+ expect(flags).toHaveLength(38)
})
it('every loops tool is gated on the loops flag', () => {
diff --git a/services/mcp/tests/unit/tool-schema-snapshots.test.ts b/services/mcp/tests/unit/tool-schema-snapshots.test.ts
index 1ba8f59b9a14..5c698cdf7ab8 100644
--- a/services/mcp/tests/unit/tool-schema-snapshots.test.ts
+++ b/services/mcp/tests/unit/tool-schema-snapshots.test.ts
@@ -96,7 +96,6 @@ async function loadSnapshotTools(): Promise<Tool<ZodObjectAny>[]> {
loops: true,
'dashboard-widgets': true,
'agent-platform': true,
- 'billing-alerts': true,
'experiment-setup-context': true,
'scout-trials': true,
'signals-report-checks-replace': true,