: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): default get-llm-total-costs-for-project to active project (#73593)
Radu Raiceaa5d244e05488
diff --git a/services/mcp/schema/tool-inputs.json b/services/mcp/schema/tool-inputs.jsonindex 777e82da5984..c5f9fd439e09 100644--- a/services/mcp/schema/tool-inputs.json+++ b/services/mcp/schema/tool-inputs.json@@ -5,6 +5,7 @@"type": "object","properties": {"projectId": {+ "description": "Project ID. Defaults to the active project when omitted.","type": "integer","exclusiveMinimum": 0,"maximum": 9007199254740991@@ -12,8 +13,7 @@"days": {"type": "number"}- },- "required": ["projectId"]+ }},"AgentResolveResourceSchema": {"type": "object",diff --git a/services/mcp/src/schema/tool-inputs.ts b/services/mcp/src/schema/tool-inputs.tsindex 861c7b60c559..c5b85c6e6ab0 100644--- a/services/mcp/src/schema/tool-inputs.ts+++ b/services/mcp/src/schema/tool-inputs.ts@@ -366,7 +366,12 @@ export const InsightQueryInputSchema = z.preprocess()export const AIObservabilityGetCostsSchema = z.object({- projectId: z.number().int().positive(),+ projectId: z+ .number()+ .int()+ .positive()+ .optional()+ .describe('Project ID. Defaults to the active project when omitted.'),days: z.number().optional(),})diff --git a/services/mcp/src/tools/aiObservability/getLLMCosts.ts b/services/mcp/src/tools/aiObservability/getLLMCosts.tsindex 771eb1d6cc24..b81646d45a7e 100644--- a/services/mcp/src/tools/aiObservability/getLLMCosts.ts+++ b/services/mcp/src/tools/aiObservability/getLLMCosts.ts@@ -14,7 +14,8 @@ export const getLLMCostsHandler: ToolBase<typeof schema, Result>['handler'] = ascontext: Context,params: Params) => {- const { projectId, days } = params+ const { days } = params+ const projectId = params.projectId ? String(params.projectId) : await context.stateManager.getProjectId()const trendsQuery = {kind: 'TrendsQuery',@@ -38,7 +39,7 @@ export const getLLMCostsHandler: ToolBase<typeof schema, Result>['handler'] = as},}- const costsResult = await context.api.query({ projectId: String(projectId) }).execute({ queryBody: trendsQuery })+ const costsResult = await context.api.query({ projectId }).execute({ queryBody: trendsQuery })if (!costsResult.success) {throw new Error(`Failed to get LLM costs: ${costsResult.error.message}`)}diff --git a/services/mcp/tests/tools/aiObservability.integration.test.ts b/services/mcp/tests/tools/aiObservability.integration.test.tsindex 9010ec9e29a9..205d0cdf6685 100644--- a/services/mcp/tests/tools/aiObservability.integration.test.ts+++ b/services/mcp/tests/tools/aiObservability.integration.test.ts@@ -67,6 +67,13 @@ describe('AI observability', { concurrent: false }, () => {const costsData = parseToolResponse(result)expect(Array.isArray(costsData.results)).toBe(true)})++ it('should fall back to the active project when projectId is omitted', async () => {+ const result = await costsTool.handler(context, {})++ const costsData = parseToolResponse(result)+ expect(Array.isArray(costsData.results)).toBe(true)+ })})describe('AI observability workflow', () => {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/get-llm-total-costs-for-project.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/get-llm-total-costs-for-project.jsonindex 452a1a653b43..9e4c6d865a92 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/get-llm-total-costs-for-project.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/get-llm-total-costs-for-project.json@@ -5,11 +5,11 @@"type": "number"},"projectId": {+ "description": "Project ID. Defaults to the active project when omitted.","exclusiveMinimum": 0,"maximum": 9007199254740991,"type": "integer"}},- "required": ["projectId"],"type": "object"}