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.

feat(data-warehouse): add MCP tool to refresh warehouse table schema (#65188)

Jovan Sakovic7b8be0af96b0
diff --git a/frontend/src/lib/agentScopes.generated.ts b/frontend/src/lib/agentScopes.generated.ts
index ffc338bca5ae..88c0d17b9dc8 100644
--- a/frontend/src/lib/agentScopes.generated.ts
+++ b/frontend/src/lib/agentScopes.generated.ts
@@ -115,6 +115,7 @@ export const AGENT_USE_CASE_SCOPES = [
'visual_review:read',
'visual_review:write',
'warehouse_table:read',
+ 'warehouse_table:write',
'warehouse_view:read',
'warehouse_view:write',
'web_analytics:read',
diff --git a/products/data_warehouse/backend/api/table.py b/products/data_warehouse/backend/api/table.py
index 3e9a9116db5c..e24ce668aa6e 100644
--- a/products/data_warehouse/backend/api/table.py
+++ b/products/data_warehouse/backend/api/table.py
@@ -5,7 +5,7 @@ from django.conf import settings
import boto3
import posthoganalytics
-from drf_spectacular.utils import extend_schema_field
+from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_field
from rest_framework import filters, parsers, request, response, serializers, status, viewsets
from posthog.schema import DatabaseSerializedFieldType
@@ -375,7 +375,19 @@ class TableViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.M
return response.Response(status=status.HTTP_200_OK)
- @action(methods=["POST"], detail=True)
+ @extend_schema(
+ request=None,
+ responses={200: OpenApiResponse(description="Schema refreshed from the table's underlying source")},
+ summary="Refresh table schema from source",
+ description=(
+ "Re-introspect a self-managed (manually linked) warehouse table's schema from its underlying "
+ "source files and overwrite its stored column list. Use when the source schema has evolved "
+ "(e.g. new columns in the underlying Delta/Parquet/CSV files) but queries still can't see the "
+ "new columns, because PostHog serves a cached column snapshot until the table is refreshed. "
+ "Not for tables managed by an external data source sync — those refresh on their own schedule."
+ ),
+ )
+ @action(methods=["POST"], detail=True, required_scopes=["warehouse_table:write"])
def refresh_schema(self, request: request.Request, *args: Any, **kwargs: Any) -> response.Response:
table: DataWarehouseTable = self.get_object()
diff --git a/products/data_warehouse/frontend/generated/api.ts b/products/data_warehouse/frontend/generated/api.ts
index e1b6628ae5b2..79b3dadaf68d 100644
--- a/products/data_warehouse/frontend/generated/api.ts
+++ b/products/data_warehouse/frontend/generated/api.ts
@@ -1472,19 +1472,17 @@ export const getWarehouseTablesRefreshSchemaCreateUrl = (projectId: string, id:
}
/**
- * Create, Read, Update and Delete Warehouse Tables.
+ * Re-introspect a self-managed (manually linked) warehouse table's schema from its underlying source files and overwrite its stored column list. Use when the source schema has evolved (e.g. new columns in the underlying Delta/Parquet/CSV files) but queries still can't see the new columns, because PostHog serves a cached column snapshot until the table is refreshed. Not for tables managed by an external data source sync — those refresh on their own schedule.
+ * @summary Refresh table schema from source
*/
export const warehouseTablesRefreshSchemaCreate = async (
projectId: string,
id: string,
- tableApi: NonReadonly<TableApi>,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getWarehouseTablesRefreshSchemaCreateUrl(projectId, id), {
...options,
method: 'POST',
- headers: { 'Content-Type': 'application/json', ...options?.headers },
- body: JSON.stringify(tableApi),
})
}
diff --git a/products/data_warehouse/frontend/generated/api.zod.ts b/products/data_warehouse/frontend/generated/api.zod.ts
index d7d80049a3a9..439b29d986b9 100644
--- a/products/data_warehouse/frontend/generated/api.zod.ts
+++ b/products/data_warehouse/frontend/generated/api.zod.ts
@@ -832,84 +832,6 @@ export const WarehouseTablesPartialUpdateBody = /* @__PURE__ */ zod
})
.describe('Mixin for serializers to add user access control fields')
-/**
- * Create, Read, Update and Delete Warehouse Tables.
- */
-export const warehouseTablesRefreshSchemaCreateBodyNameMax = 128
-
-export const warehouseTablesRefreshSchemaCreateBodyUrlPatternMax = 500
-
-export const warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneDistinctIdMax = 200
-
-export const warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneFirstNameMax = 150
-
-export const warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneLastNameMax = 150
-
-export const warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneEmailMax = 254
-
-export const warehouseTablesRefreshSchemaCreateBodyCredentialAccessKeyMax = 500
-
-export const warehouseTablesRefreshSchemaCreateBodyCredentialAccessSecretMax = 500
-
-export const WarehouseTablesRefreshSchemaCreateBody = /* @__PURE__ */ zod
- .object({
- deleted: zod.boolean().nullish(),
- name: zod.string().max(warehouseTablesRefreshSchemaCreateBodyNameMax),
- format: zod
- .enum(['CSV', 'CSVWithNames', 'Parquet', 'JSONEachRow', 'Delta', 'DeltaS3Wrapper'])
- .describe(
- '\* `CSV` - CSV\n\* `CSVWithNames` - CSVWithNames\n\* `Parquet` - Parquet\n\* `JSONEachRow` - JSON\n\* `Delta` - Delta\n\* `DeltaS3Wrapper` - DeltaS3Wrapper'
- ),
- url_pattern: zod.string().max(warehouseTablesRefreshSchemaCreateBodyUrlPatternMax),
- credential: zod.object({
- id: zod.uuid(),
- created_by: zod.object({
- id: zod.number(),
- uuid: zod.uuid(),
- distinct_id: zod
- .string()
- .max(warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneDistinctIdMax)
- .nullish(),
- first_name: zod
- .string()
- .max(warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneFirstNameMax)
- .optional(),
- last_name: zod
- .string()
- .max(warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneLastNameMax)
- .optional(),
- email: zod.email().max(warehouseTablesRefreshSchemaCreateBodyCredentialCreatedByOneEmailMax),
- is_email_verified: zod.boolean().nullish(),
- hedgehog_config: zod.record(zod.string(), zod.unknown()).nullable(),
- role_at_organization: zod
- .union([
- zod
- .enum([
- 'engineering',
- 'data',
- 'product',
- 'founder',
- 'leadership',
- 'marketing',
- 'sales',
- 'other',
- ])
- .describe(
- '\* `engineering` - Engineering\n\* `data` - Data\n\* `product` - Product Management\n\* `founder` - Founder\n\* `leadership` - Leadership\n\* `marketing` - Marketing\n\* `sales` - Sales \/ Success\n\* `other` - Other'
- ),
- zod.enum(['']),
- zod.null(),
- ])
- .optional(),
- }),
- created_at: zod.iso.datetime({ offset: true }),
- access_key: zod.string().max(warehouseTablesRefreshSchemaCreateBodyCredentialAccessKeyMax),
- access_secret: zod.string().max(warehouseTablesRefreshSchemaCreateBodyCredentialAccessSecretMax),
- }),
- options: zod.record(zod.string(), zod.unknown()).optional(),
- })
- .describe('Mixin for serializers to add user access control fields')
-
/**
* Create, Read, Update and Delete Warehouse Tables.
*/
diff --git a/products/data_warehouse/mcp/tools.yaml b/products/data_warehouse/mcp/tools.yaml
index cb7d0bed2e4c..31e1221e8a8c 100644
--- a/products/data_warehouse/mcp/tools.yaml
+++ b/products/data_warehouse/mcp/tools.yaml
@@ -425,7 +425,20 @@ tools:
enabled: false
warehouse-tables-refresh-schema-create:
operation: warehouse_tables_refresh_schema_create
- enabled: false
+ enabled: true
+ scopes:
+ - warehouse_table:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: true
+ title: Refresh table schema from source
+ description: >
+ Re-introspect a self-managed (manually linked) data warehouse table's schema from its underlying source
+ files and overwrite its stored column list. Use this when the source schema has evolved (e.g. new columns
+ added to the underlying Delta/Parquet/CSV files) but HogQL queries still fail to resolve the new columns —
+ PostHog serves a cached column snapshot until the table is refreshed. Does not apply to tables managed by an
+ external data source sync (those refresh on their own schedule); for those, trigger a sync instead.
warehouse-tables-retrieve:
operation: warehouse_tables_retrieve
enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 2aedef519ed1..1ba6a85de9fb 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -7650,6 +7650,20 @@
},
"feature_flag": "visual-review"
},
+ "warehouse-tables-refresh-schema-create": {
+ "description": "Re-introspect a self-managed (manually linked) data warehouse table's schema from its underlying source files and overwrite its stored column list. Use this when the source schema has evolved (e.g. new columns added to the underlying Delta/Parquet/CSV files) but HogQL queries still fail to resolve the new columns — PostHog serves a cached column snapshot until the table is refreshed. Does not apply to tables managed by an external data source sync (those refresh on their own schedule); for those, trigger a sync instead.",
+ "category": "Data warehouse",
+ "feature": "data_warehouse",
+ "summary": "Refresh table schema from source",
+ "title": "Refresh table schema from source",
+ "required_scopes": ["warehouse_table:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"web-analytics-weekly-digest": {
"description": "Summarizes a project's web analytics over a lookback window (default 7 days): unique visitors, pageviews, sessions, bounce rate, and average session duration with period-over-period comparisons, plus the top 5 pages, top 5 traffic sources, and goal conversions. Accepts optional `days` (1–90, default 7) and `compare` (bool, default true) query params — pass `days=30` to summarize the last month, or `compare=false` to skip the period-over-period comparison for a faster response. Use this to answer questions like \"how are my web analytics?\", \"how did the site do last week?\", or \"what's my traffic looking like this month?\".",
"category": "Web analytics",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 8d7fecfeb2fb..e0c7f7eb1d10 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -8173,6 +8173,20 @@
},
"feature_flag": "visual-review"
},
+ "warehouse-tables-refresh-schema-create": {
+ "description": "Re-introspect a self-managed (manually linked) data warehouse table's schema from its underlying source files and overwrite its stored column list. Use this when the source schema has evolved (e.g. new columns added to the underlying Delta/Parquet/CSV files) but HogQL queries still fail to resolve the new columns — PostHog serves a cached column snapshot until the table is refreshed. Does not apply to tables managed by an external data source sync (those refresh on their own schedule); for those, trigger a sync instead.",
+ "category": "Data warehouse",
+ "feature": "data_warehouse",
+ "summary": "Refresh table schema from source",
+ "title": "Refresh table schema from source",
+ "required_scopes": ["warehouse_table:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"web-analytics-weekly-digest": {
"description": "Summarizes a project's web analytics over a lookback window (default 7 days): unique visitors, pageviews, sessions, bounce rate, and average session duration with period-over-period comparisons, plus the top 5 pages, top 5 traffic sources, and goal conversions. Accepts optional `days` (1–90, default 7) and `compare` (bool, default true) query params — pass `days=30` to summarize the last month, or `compare=false` to skip the period-over-period comparison for a faster response. Use this to answer questions like \"how are my web analytics?\", \"how did the site do last week?\", or \"what's my traffic looking like this month?\".",
"category": "Web analytics",
diff --git a/services/mcp/src/generated/data_warehouse/api.ts b/services/mcp/src/generated/data_warehouse/api.ts
index 9fa03f4782c9..fb3ba2a4895a 100644
--- a/services/mcp/src/generated/data_warehouse/api.ts
+++ b/services/mcp/src/generated/data_warehouse/api.ts
@@ -3,7 +3,7 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 13 enabled ops
+ * PostHog API - MCP 14 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -380,3 +380,16 @@ export const WarehouseSavedQueriesRunHistoryRetrieveParams = /* @__PURE__ */ zod
"Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
),
})
+
+/**
+ * Re-introspect a self-managed (manually linked) warehouse table's schema from its underlying source files and overwrite its stored column list. Use when the source schema has evolved (e.g. new columns in the underlying Delta/Parquet/CSV files) but queries still can't see the new columns, because PostHog serves a cached column snapshot until the table is refreshed. Not for tables managed by an external data source sync — those refresh on their own schedule.
+ * @summary Refresh table schema from source
+ */
+export const WarehouseTablesRefreshSchemaCreateParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this data warehouse table.'),
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
diff --git a/services/mcp/src/tools/generated/data_warehouse.ts b/services/mcp/src/tools/generated/data_warehouse.ts
index 024a05ba6e0f..13cc94e0d26a 100644
--- a/services/mcp/src/tools/generated/data_warehouse.ts
+++ b/services/mcp/src/tools/generated/data_warehouse.ts
@@ -20,6 +20,7 @@ import {
WarehouseSavedQueriesRunCreateBody,
WarehouseSavedQueriesRunCreateParams,
WarehouseSavedQueriesRunHistoryRetrieveParams,
+ WarehouseTablesRefreshSchemaCreateParams,
} from '@/generated/data_warehouse/api'
import { withPostHogUrl, type WithPostHogUrl } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
@@ -410,6 +411,21 @@ const viewUpdate = (): ToolBase<typeof ViewUpdateSchema, WithPostHogUrl<Schemas.
},
})
+const WarehouseTablesRefreshSchemaCreateSchema = WarehouseTablesRefreshSchemaCreateParams.omit({ project_id: true })
+
+const warehouseTablesRefreshSchemaCreate = (): ToolBase<typeof WarehouseTablesRefreshSchemaCreateSchema, unknown> => ({
+ name: 'warehouse-tables-refresh-schema-create',
+ schema: WarehouseTablesRefreshSchemaCreateSchema,
+ handler: async (context: Context, params: z.infer<typeof WarehouseTablesRefreshSchemaCreateSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<unknown>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/warehouse_tables/${encodeURIComponent(String(params.id))}/refresh_schema/`,
+ })
+ return result
+ },
+})
+
export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'data-warehouse-data-health-issues-retrieve': dataWarehouseDataHealthIssuesRetrieve,
'sql-variables-create': sqlVariablesCreate,
@@ -424,4 +440,5 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'view-run-history': viewRunHistory,
'view-unmaterialize': viewUnmaterialize,
'view-update': viewUpdate,
+ 'warehouse-tables-refresh-schema-create': warehouseTablesRefreshSchemaCreate,
}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-tables-refresh-schema-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-tables-refresh-schema-create.json
new file mode 100644
index 000000000000..5613914768cf
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-tables-refresh-schema-create.json
@@ -0,0 +1,11 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "id": {
+ "description": "A UUID string identifying this data warehouse table.",
+ "type": "string"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+}