: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
feat(dashboards): expose dashboard templates to MCP as reference material (#71930)
Paul D'Ambraad70351a45fe
diff --git a/ee/hogai/tools/upsert_dashboard/prompts.py b/ee/hogai/tools/upsert_dashboard/prompts.pyindex ede2b56baff3..6eb1fe1064a7 100644--- a/ee/hogai/tools/upsert_dashboard/prompts.py+++ b/ee/hogai/tools/upsert_dashboard/prompts.py@@ -13,6 +13,11 @@ Proactively use list_data and search tools to find existing insights.If there are matching insights, read their insight schemas to understand whether they match the user's intent and have data.Next, read the data schema and data warehouse schema and create new insights or SQL queries.+## Use dashboard templates as reference+PostHog ships vetted dashboard templates for common topics (product analytics, retention, revenue, etc.).+When they're available to you, browse the templates for one close to the user's topic and look at the insights it pairs together — they're a good signal of what a strong dashboard on that topic looks like.+Treat templates as examples, not instructions: take inspiration from the insights and their groupings, but tailor every insight to the user's own events, properties, and intent rather than copying a template verbatim.+## FinalizeCall this tool when you have enough information to create or update the dashboard.diff --git a/frontend/src/lib/agentScopes.generated.ts b/frontend/src/lib/agentScopes.generated.tsindex 64165e6c5917..a1169480c326 100644--- a/frontend/src/lib/agentScopes.generated.ts+++ b/frontend/src/lib/agentScopes.generated.ts@@ -28,6 +28,7 @@ export const AGENT_USE_CASE_SCOPES = ['comment:read','dashboard:read','dashboard:write',+ 'dashboard_template:read','early_access_feature:read','early_access_feature:write','endpoint:read',diff --git a/products/dashboards/backend/api/dashboard_templates.py b/products/dashboards/backend/api/dashboard_templates.pyindex 6768ea941c49..3d6f705ea68d 100644--- a/products/dashboards/backend/api/dashboard_templates.py+++ b/products/dashboards/backend/api/dashboard_templates.py@@ -416,6 +416,15 @@ def _assert_user_can_read_source_for_copy(*, user: User, source_team: Team) -> N@extend_schema_view(list=extend_schema(parameters=[+ OpenApiParameter(+ "search",+ OpenApiTypes.STR,+ location=OpenApiParameter.QUERY,+ description=(+ "Optional. Full-text search across template name, tags, and description, ranked by relevance. "+ "Use it to find templates for a topic (e.g. `retention`, `revenue`, `product analytics`)."+ ),+ ),OpenApiParameter("ordering",OpenApiTypes.STR,diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex 5ffbb8311b7c..2d65fd7aebe9 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -9228,6 +9228,10 @@ export type DashboardTemplatesListParams = {* Optional. `global`: official templates only. `team`: this project's saved templates only (`scope=team` rows for the current project). `organization`: templates shared across all projects in this organization. `feature_flag`: feature-flag dashboard templates only. Omit for official, organization, and this project's templates (default dashboard template picker behavior).*/scope?: DashboardTemplatesListScope+ /**+ * Optional. Full-text search across template name, tags, and description, ranked by relevance. Use it to find templates for a topic (e.g. `retention`, `revenue`, `product analytics`).+ */+ search?: string}export type DashboardTemplatesListScope = (typeof DashboardTemplatesListScope)[keyof typeof DashboardTemplatesListScope]diff --git a/products/dashboards/mcp/tools.yaml b/products/dashboards/mcp/tools.yamlindex cca8b9ef2ba9..ec95b804c178 100644--- a/products/dashboards/mcp/tools.yaml+++ b/products/dashboards/mcp/tools.yaml@@ -241,13 +241,50 @@ tools:enabled: falsedashboard-templates-list:operation: dashboard_templates_list- enabled: false+ enabled: true+ scopes:+ - dashboard_template:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ list: true+ title: List dashboard templates+ description: >+ List dashboard templates — vetted, ready-made dashboards curated by PostHog (global scope) or shared within+ the project/organization. Use these as reference material for what good insights and dashboards look like on+ a topic (e.g. product analytics, retention, revenue): browse for a template close to what the user wants,+ then call dashboard-templates-retrieve to inspect its tiles and insight queries. Templates are examples, not+ a spec — take inspiration from the insights they include, but tailor everything to the user's data and+ request rather than copying blindly. Use `search` to match by name, tags, or description, and `scope`+ (global | team | organization) to narrow where templates come from. Tiles, variables, and filters are+ omitted here to save context — fetch a single template with dashboard-templates-retrieve to see them.+ response:+ exclude:+ - tiles+ - variables+ - dashboard_filters+ - non_portable_references+ - availability_contextsdashboard-templates-partial-update:operation: dashboard_templates_partial_updateenabled: falsedashboard-templates-retrieve:operation: dashboard_templates_retrieve- enabled: false+ enabled: true+ scopes:+ - dashboard_template:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: Get dashboard template+ description: >+ Get a single dashboard template by ID, including its full `tiles` (each tile's insight query and layout) and+ `variables`. Use this after dashboard-templates-list to study how a vetted dashboard on a topic is composed+ — which insights it pairs together and how they are queried — as reference when building or improving a+ dashboard. Treat the tiles as illustrative examples: adapt the insight queries to the user's events and+ intent rather than reproducing the template verbatim.dashboard-templates-update:operation: dashboard_templates_updateenabled: falsediff --git a/products/dashboards/skills/building-a-dashboard/SKILL.md b/products/dashboards/skills/building-a-dashboard/SKILL.mdnew file mode 100644index 000000000000..0c5d3afbdf66--- /dev/null+++ b/products/dashboards/skills/building-a-dashboard/SKILL.md@@ -0,0 +1,65 @@+---+name: building-a-dashboard+description: >+ Build a new dashboard, or update an existing one, from a set of insights — the same job the in-app+ assistant does with its upsert-dashboard tool, but over MCP. Use when a user asks to create a dashboard,+ put several metrics/charts together on one page, assemble a dashboard for a topic (product analytics,+ retention, revenue, activation, etc.), or add/remove/replace insights on a dashboard they already have.+ Covers deciding create vs update, reusing existing insights vs creating new ones, and using PostHog's+ vetted dashboard templates as reference for what a strong dashboard on a topic looks like.+---++# Building a dashboard++A dashboard is a collection of insight tiles on one page. Your job is to figure out which insights belong on it,+reuse what already exists, create what's missing, and lay them out sensibly — not to blindly generate charts.++## Create vs update++First work out whether you're creating a new dashboard or changing an existing one.++- Search existing dashboards with `dashboards-get-all` (its `search` param does fuzzy name/description matching). If the+ user is clearly describing something that already exists, they probably want an update.+- Read a candidate with `dashboard-get` to see its current tiles before you change anything.+- If the request is ambiguous — "get my financial metrics together" could mean build new or add to an existing one —+ ask a short clarifying question rather than guessing.++## Use templates as reference++PostHog ships vetted dashboard templates for common topics, and orgs can share their own. Consult them before you+build — they're a strong signal of which insights pair well on a topic.++1. `dashboard-templates-list` — browse templates (use `search` for a topic, `scope` to narrow to global / team /+ organization). This returns names, descriptions, and tags only.+2. `dashboard-templates-retrieve` — open the closest template to see its `tiles`: which insights it groups together and+ how each is queried.++Treat templates as **examples, not a spec**. Take inspiration from the insights and their groupings, but tailor every+insight to the user's own events, properties, and intent. Don't copy a template verbatim, and don't force a template+onto a request it doesn't fit — a good bespoke dashboard beats a mismatched template every time.++## Select the insights++Prefer reusing existing insights over recreating them.++- Search with `insights-list` and read promising ones with `insight-get` to check they match the user's intent and+ actually have data. Full-text search misses things named differently, so list broadly before concluding an insight+ doesn't exist.+- For anything missing, create it with `insight-create` (see the product-analytics insight skills for query shape).+- Keep the set minimal — only the insights the request needs. A focused dashboard is more useful than an exhaustive one.++## Assemble the dashboard++- New dashboard: `dashboard-create` with a short (3–7 word) name and a concise description, then add the insight tiles.+- Existing dashboard: `dashboard-update`. Adding, replacing, or removing insights means sending the full intended set of+ tiles — insights you omit are removed, so include the ones you want to keep.+- Layout: by default preserve existing tile placement. Only reflow (`dashboard-reorder-tiles`) when the user explicitly+ asks to rearrange, reorder, or move tiles.+- Verify with `dashboard-insights-run` to confirm the tiles return data, then summarize what you built and invite the+ user to refine it.++## When not to use this++- Saving a single insight — just create the insight; it doesn't need a dashboard.+- Adding non-insight widget tiles (text cards, widgets) — see the widget tools (`dashboard-widget-catalog-list`,+ `dashboard-widgets-batch-add`) instead.diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 89b16856cc14..c25bf063e080 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -2100,6 +2100,34 @@"readOnlyHint": false}},+ "dashboard-templates-list": {+ "description": "List dashboard templates — vetted, ready-made dashboards curated by PostHog (global scope) or shared within the project/organization. Use these as reference material for what good insights and dashboards look like on a topic (e.g. product analytics, retention, revenue): browse for a template close to what the user wants, then call dashboard-templates-retrieve to inspect its tiles and insight queries. Templates are examples, not a spec — take inspiration from the insights they include, but tailor everything to the user's data and request rather than copying blindly. Use `search` to match by name, tags, or description, and `scope` (global | team | organization) to narrow where templates come from. Tiles, variables, and filters are omitted here to save context — fetch a single template with dashboard-templates-retrieve to see them.",+ "category": "Dashboards",+ "feature": "dashboards",+ "summary": "List dashboard templates",+ "title": "List dashboard templates",+ "required_scopes": ["dashboard_template:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ }+ },+ "dashboard-templates-retrieve": {+ "description": "Get a single dashboard template by ID, including its full `tiles` (each tile's insight query and layout) and `variables`. Use this after dashboard-templates-list to study how a vetted dashboard on a topic is composed — which insights it pairs together and how they are queried — as reference when building or improving a dashboard. Treat the tiles as illustrative examples: adapt the insight queries to the user's events and intent rather than reproducing the template verbatim.",+ "category": "Dashboards",+ "feature": "dashboards",+ "summary": "Get dashboard template",+ "title": "Get dashboard template",+ "required_scopes": ["dashboard_template:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ }+ },"dashboard-tile-copy": {"description": "Copy an insight, text card, or widget tile from one dashboard to another. The path dashboard ID is the destination. Provide fromDashboardId (source dashboard) and tileId (tile to copy). Widget tiles require the dashboard-widgets feature flag and are deep-cloned with a new widget row.","category": "Dashboards",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex cb5d5e759fe1..6a39f9119077 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -2129,6 +2129,34 @@"readOnlyHint": false}},+ "dashboard-templates-list": {+ "description": "List dashboard templates — vetted, ready-made dashboards curated by PostHog (global scope) or shared within the project/organization. Use these as reference material for what good insights and dashboards look like on a topic (e.g. product analytics, retention, revenue): browse for a template close to what the user wants, then call dashboard-templates-retrieve to inspect its tiles and insight queries. Templates are examples, not a spec — take inspiration from the insights they include, but tailor everything to the user's data and request rather than copying blindly. Use `search` to match by name, tags, or description, and `scope` (global | team | organization) to narrow where templates come from. Tiles, variables, and filters are omitted here to save context — fetch a single template with dashboard-templates-retrieve to see them.",+ "category": "Dashboards",+ "feature": "dashboards",+ "summary": "List dashboard templates",+ "title": "List dashboard templates",+ "required_scopes": ["dashboard_template:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ }+ },+ "dashboard-templates-retrieve": {+ "description": "Get a single dashboard template by ID, including its full `tiles` (each tile's insight query and layout) and `variables`. Use this after dashboard-templates-list to study how a vetted dashboard on a topic is composed — which insights it pairs together and how they are queried — as reference when building or improving a dashboard. Treat the tiles as illustrative examples: adapt the insight queries to the user's events and intent rather than reproducing the template verbatim.",+ "category": "Dashboards",+ "feature": "dashboards",+ "summary": "Get dashboard template",+ "title": "Get dashboard template",+ "required_scopes": ["dashboard_template:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ }+ },"dashboard-tile-copy": {"description": "Copy an insight, text card, or widget tile from one dashboard to another. The path dashboard ID is the destination. Provide fromDashboardId (source dashboard) and tileId (tile to copy). Widget tiles require the dashboard-widgets feature flag and are deep-cloned with a new widget row.","category": "Dashboards",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex c70e2c791928..90c84e4f3cbf 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -72346,6 +72346,10 @@ export namespace Schemas {* Optional. `global`: official templates only. `team`: this project's saved templates only (`scope=team` rows for the current project). `organization`: templates shared across all projects in this organization. `feature_flag`: feature-flag dashboard templates only. Omit for official, organization, and this project's templates (default dashboard template picker behavior).*/scope?: DashboardTemplatesListScope;+ /**+ * Optional. Full-text search across template name, tags, and description, ranked by relevance. Use it to find templates for a topic (e.g. `retention`, `revenue`, `product analytics`).+ */+ search?: string;};export type DashboardTemplatesListScope = typeof DashboardTemplatesListScope[keyof typeof DashboardTemplatesListScope];diff --git a/services/mcp/src/generated/dashboards/api.ts b/services/mcp/src/generated/dashboards/api.tsindex 04ffef2025b6..e065a345e883 100644--- a/services/mcp/src/generated/dashboards/api.ts+++ b/services/mcp/src/generated/dashboards/api.ts@@ -3,11 +3,57 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 16 enabled ops+ * PostHog API - MCP 18 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'+export const DashboardTemplatesListParams = /* @__PURE__ */ zod.object({+ 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/."+ ),+})++export const DashboardTemplatesListQueryParams = /* @__PURE__ */ zod.object({+ is_featured: zod+ .boolean()+ .optional()+ .describe(+ 'Omit for all templates. When set, filter by featured flag; parsed with str_to_bool (same as other API query booleans).'+ ),+ limit: zod.number().optional().describe('Number of results to return per page.'),+ offset: zod.number().optional().describe('The initial index from which to return the results.'),+ ordering: zod+ .string()+ .optional()+ .describe(+ 'Optional. When not using `search`, results are sorted with featured templates first (`is_featured=true`), then by `template_name` (case-insensitive A–Z; `-template_name` for Z–A) or by `created_at` (`-created_at` for newest first). When `search` is set, order is featured first, then relevance rank, then case-insensitive name for ties.'+ ),+ scope: zod+ .enum(['feature_flag', 'global', 'organization', 'team'])+ .optional()+ .describe(+ "Optional. `global`: official templates only. `team`: this project's saved templates only (`scope=team` rows for the current project). `organization`: templates shared across all projects in this organization. `feature_flag`: feature-flag dashboard templates only. Omit for official, organization, and this project's templates (default dashboard template picker behavior)."+ ),+ search: zod+ .string()+ .optional()+ .describe(+ 'Optional. Full-text search across template name, tags, and description, ranked by relevance. Use it to find templates for a topic (e.g. `retention`, `revenue`, `product analytics`).'+ ),+})++export const DashboardTemplatesRetrieveParams = /* @__PURE__ */ zod.object({+ id: zod.string().describe('A UUID string identifying this dashboard template.'),+ 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/."+ ),+})+export const DashboardsListParams = /* @__PURE__ */ zod.object({project_id: zod.string()diff --git a/services/mcp/src/tools/generated/dashboards.ts b/services/mcp/src/tools/generated/dashboards.tsindex 9876d59a2e72..582d8f4bff4f 100644--- a/services/mcp/src/tools/generated/dashboards.ts+++ b/services/mcp/src/tools/generated/dashboards.ts@@ -3,6 +3,8 @@ import { z } from 'zod'import type { Schemas } from '@/api/generated'import {+ DashboardTemplatesListQueryParams,+ DashboardTemplatesRetrieveParams,DashboardsCopyTileCreateBody,DashboardsCopyTileCreateParams,DashboardsCreateBody,@@ -338,6 +340,62 @@ const dashboardReorderTiles = (): ToolBase<typeof DashboardReorderTilesSchema, W},})+const DashboardTemplatesListSchema = DashboardTemplatesListQueryParams++const dashboardTemplatesList = (): ToolBase<+ typeof DashboardTemplatesListSchema,+ WithPostHogUrl<Schemas.PaginatedDashboardTemplateList>+> => ({+ name: 'dashboard-templates-list',+ schema: DashboardTemplatesListSchema,+ handler: async (context: Context, params: z.infer<typeof DashboardTemplatesListSchema>) => {+ const projectId = await context.stateManager.getProjectId()+ const result = await context.api.request<Schemas.PaginatedDashboardTemplateList>({+ method: 'GET',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/dashboard_templates/`,+ query: {+ is_featured: params.is_featured,+ limit: params.limit,+ offset: params.offset,+ ordering: params.ordering,+ scope: params.scope,+ search: params.search,+ },+ })+ const filtered = {+ ...result,+ results: (result.results ?? []).map((item: any) =>+ omitResponseFields(item, [+ 'tiles',+ 'variables',+ 'dashboard_filters',+ 'non_portable_references',+ 'availability_contexts',+ ])+ ),+ } as typeof result+ return await withPostHogUrl(context, filtered, '/dashboard')+ },+})++const DashboardTemplatesRetrieveSchema = DashboardTemplatesRetrieveParams.omit({ project_id: true })++const dashboardTemplatesRetrieve = (): ToolBase<+ typeof DashboardTemplatesRetrieveSchema,+ Schemas.DashboardTemplate+> => ({+ name: 'dashboard-templates-retrieve',+ schema: DashboardTemplatesRetrieveSchema,+ handler: async (context: Context, params: z.infer<typeof DashboardTemplatesRetrieveSchema>) => {+ const projectId = await context.stateManager.getProjectId()+ const result = await context.api.request<Schemas.DashboardTemplate>({+ method: 'GET',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/dashboard_templates/${encodeURIComponent(String(params.id))}/`,+ })+ return result+ },+})+const DashboardTileCopySchema = DashboardsCopyTileCreateParams.omit({ project_id: true }).extend(DashboardsCopyTileCreateBody.shape).extend({ id: z.preprocess(castStringToInt, DashboardsCopyTileCreateParams.shape['id']) })@@ -660,6 +718,8 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'dashboard-get': dashboardGet,'dashboard-insights-run': dashboardInsightsRun,'dashboard-reorder-tiles': dashboardReorderTiles,+ 'dashboard-templates-list': dashboardTemplatesList,+ 'dashboard-templates-retrieve': dashboardTemplatesRetrieve,'dashboard-tile-copy': dashboardTileCopy,'dashboard-update': dashboardUpdate,'dashboard-update-text-tile': dashboardUpdateTextTile,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-templates-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-templates-list.jsonnew file mode 100644index 000000000000..3894f1252803--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-templates-list.json@@ -0,0 +1,31 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "is_featured": {+ "description": "Omit for all templates. When set, filter by featured flag; parsed with str_to_bool (same as other API query booleans).",+ "type": "boolean"+ },+ "limit": {+ "description": "Number of results to return per page.",+ "type": "number"+ },+ "offset": {+ "description": "The initial index from which to return the results.",+ "type": "number"+ },+ "ordering": {+ "description": "Optional. When not using `search`, results are sorted with featured templates first (`is_featured=true`), then by `template_name` (case-insensitive A–Z; `-template_name` for Z–A) or by `created_at` (`-created_at` for newest first). When `search` is set, order is featured first, then relevance rank, then case-insensitive name for ties.",+ "type": "string"+ },+ "scope": {+ "description": "Optional. `global`: official templates only. `team`: this project's saved templates only (`scope=team` rows for the current project). `organization`: templates shared across all projects in this organization. `feature_flag`: feature-flag dashboard templates only. Omit for official, organization, and this project's templates (default dashboard template picker behavior).",+ "enum": ["feature_flag", "global", "organization", "team"],+ "type": "string"+ },+ "search": {+ "description": "Optional. Full-text search across template name, tags, and description, ranked by relevance. Use it to find templates for a topic (e.g. `retention`, `revenue`, `product analytics`).",+ "type": "string"+ }+ },+ "type": "object"+}diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-templates-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-templates-retrieve.jsonnew file mode 100644index 000000000000..6dfd8ea5a791--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-templates-retrieve.json@@ -0,0 +1,11 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "id": {+ "description": "A UUID string identifying this dashboard template.",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+}