: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): build saved-view links from the requested view id (#115166)
posthog[bot]accc1bd695f9
diff --git a/products/data_warehouse/mcp/tools.yaml b/products/data_warehouse/mcp/tools.yamlindex 8b1b3871407c..c642719d046e 100644--- a/products/data_warehouse/mcp/tools.yaml+++ b/products/data_warehouse/mcp/tools.yaml@@ -278,7 +278,7 @@ tools:readOnly: truedestructive: falseidempotent: true- enrich_url: ?open_view={id}+ enrich_url: ?open_view={params.id}title: Get run historydescription: >Get the 5 most recent materialization run statuses for a saved query. Each entry includes the run status and@@ -292,7 +292,7 @@ tools:readOnly: falsedestructive: falseidempotent: true- enrich_url: ?open_view={id}+ enrich_url: ?open_view={params.id}title: Revert materializationdescription: |Undo materialization for a saved query. Deletes the materialized table and removes the sync schedule,diff --git a/services/mcp/src/tools/generated/data_warehouse.ts b/services/mcp/src/tools/generated/data_warehouse.tsindex d1532d7e5fcb..2f51d05d03a4 100644--- a/services/mcp/src/tools/generated/data_warehouse.ts+++ b/services/mcp/src/tools/generated/data_warehouse.ts@@ -464,7 +464,7 @@ const viewRunHistory = (): ToolBase<method: 'GET',path: `/api/projects/${encodeURIComponent(String(projectId))}/warehouse_saved_queries/${encodeURIComponent(String(params.id))}/run_history/`,})- return await withPostHogUrl(context, result, `/sql?open_view=${result.id}`)+ return await withPostHogUrl(context, result, `/sql?open_view=${params.id}`)},})@@ -519,7 +519,7 @@ const viewUnmaterialize = (): ToolBase<path: `/api/projects/${encodeURIComponent(String(projectId))}/warehouse_saved_queries/${encodeURIComponent(String(params.id))}/revert_materialization/`,body,})- return await withPostHogUrl(context, result, `/sql?open_view=${result.id}`)+ return await withPostHogUrl(context, result, `/sql?open_view=${params.id}`)},})diff --git a/services/mcp/tests/unit/data-warehouse-view-urls.test.ts b/services/mcp/tests/unit/data-warehouse-view-urls.test.tsnew file mode 100644index 000000000000..f1e750febef4--- /dev/null+++ b/services/mcp/tests/unit/data-warehouse-view-urls.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it, vi } from 'vitest'++import { GENERATED_TOOLS } from '@/tools/generated/data_warehouse'+import type { Context } from '@/tools/types'++const VIEW_ID = '00000000-0000-4000-8000-000000000001'++describe('Generated data warehouse view tools', () => {+ it.each([+ { name: 'view-run-history', input: { id: VIEW_ID }, response: { run_history: [] } },+ {+ name: 'view-unmaterialize',+ input: { id: VIEW_ID, name: 'orders', query: { kind: 'HogQLQuery', query: 'SELECT 1' } },+ response: undefined,+ },+ ])('$name links to the requested view when the response has no id', async ({ name, input, response }) => {+ const context = {+ api: {+ request: vi.fn().mockResolvedValue(response),+ getProjectBaseUrl: (projectId: string) => `https://us.posthog.com/project/${projectId}`,+ },+ stateManager: { getProjectId: async () => '42' },+ } as unknown as Context+ const tool = GENERATED_TOOLS[name]!()++ const result = await tool.handler(context, tool.schema.parse(input))++ expect(result).toEqual({+ ...response,+ _posthogUrl: `https://us.posthog.com/project/42/sql?open_view=${VIEW_ID}`,+ })+ })+})