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(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.yaml
index 8b1b3871407c..c642719d046e 100644
--- a/products/data_warehouse/mcp/tools.yaml
+++ b/products/data_warehouse/mcp/tools.yaml
@@ -278,7 +278,7 @@ tools:
readOnly: true
destructive: false
idempotent: true
- enrich_url: ?open_view={id}
+ enrich_url: ?open_view={params.id}
title: Get run history
description: >
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: false
destructive: false
idempotent: true
- enrich_url: ?open_view={id}
+ enrich_url: ?open_view={params.id}
title: Revert materialization
description: |
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.ts
index 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.ts
new file mode 100644
index 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}`,
+ })
+ })
+})