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): point every url_prefix at a real app route, and lint it (#73984)

Arno Hillen1957a32679ee
diff --git a/products/batch_exports/mcp/tools.yaml b/products/batch_exports/mcp/tools.yaml
index 0227162d6be1..9e1b792f89ff 100644
--- a/products/batch_exports/mcp/tools.yaml
+++ b/products/batch_exports/mcp/tools.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Data pipelines
feature: batch_exports
-url_prefix: /data-pipelines/destinations
+url_prefix: /data-management/destinations
ui_apps: {}
tools:
batch-export-create:
diff --git a/products/cdp/mcp/cdp_function_templates.yaml b/products/cdp/mcp/cdp_function_templates.yaml
index 2bdb4bc3b162..2237124841d1 100644
--- a/products/cdp/mcp/cdp_function_templates.yaml
+++ b/products/cdp/mcp/cdp_function_templates.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Function templates
feature: hog_function_templates
-url_prefix: /pipeline/templates
+url_prefix: /pipeline/new
ui_apps: {}
tools:
cdp-function-templates-list:
diff --git a/products/customer_analytics/mcp/tools.yaml b/products/customer_analytics/mcp/tools.yaml
index 8b2341b07e34..790529ed6f03 100644
--- a/products/customer_analytics/mcp/tools.yaml
+++ b/products/customer_analytics/mcp/tools.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Customer analytics
feature: customer_analytics
-url_prefix: /customer-analytics
+url_prefix: /customer_analytics
ui_apps: {}
tools:
account-notes-list:
diff --git a/products/data_catalog/mcp/tools.yaml b/products/data_catalog/mcp/tools.yaml
index 200715ad81c3..6430b815f574 100644
--- a/products/data_catalog/mcp/tools.yaml
+++ b/products/data_catalog/mcp/tools.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Data catalog
feature: data_catalog
-url_prefix: /data-catalog
+url_prefix: /
ui_apps: {}
tools:
data-catalog-certification-certify:
diff --git a/products/field_notes/mcp/tools.yaml b/products/field_notes/mcp/tools.yaml
index 286b1e58f432..455b23b3e315 100644
--- a/products/field_notes/mcp/tools.yaml
+++ b/products/field_notes/mcp/tools.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Field notes
feature: field_notes
-url_prefix: /field_notes
+url_prefix: /
ui_apps: {}
tools:
field-notes-create:
@@ -24,7 +24,6 @@ tools:
readOnly: true
destructive: false
idempotent: true
- enrich_url: '{id}'
title: Get field note
description: >
Get a single field note by id, including the full element context (selector, element chain, inferred
@@ -39,7 +38,6 @@ tools:
readOnly: true
destructive: false
idempotent: true
- enrich_url: '{id}'
list: true
title: List field notes
description: >
@@ -71,7 +69,6 @@ tools:
readOnly: false
destructive: false
idempotent: true
- enrich_url: '{id}'
title: Update field note
description: >
Update a field note after acting on it — set `field_note_status` to `acknowledged`, `resolved`, or
diff --git a/products/integrations/mcp/tools.yaml b/products/integrations/mcp/tools.yaml
index f80cce902825..b212118b848a 100644
--- a/products/integrations/mcp/tools.yaml
+++ b/products/integrations/mcp/tools.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Integrations
feature: integrations
-url_prefix: /settings/integrations
+url_prefix: /settings/environment-integrations
ui_apps: {}
tools:
integration-delete:
diff --git a/products/mcp_store/mcp/tools.yaml b/products/mcp_store/mcp/tools.yaml
index a7b3a22bcf8f..3b96696f3874 100644
--- a/products/mcp_store/mcp/tools.yaml
+++ b/products/mcp_store/mcp/tools.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: MCP Store
feature: mcp_store
-url_prefix: /settings/environment-mcp-servers
+url_prefix: /settings/mcp-servers
ui_apps: {}
tools:
mcp-connection-tools-list:
diff --git a/services/mcp/definitions/agent_platform.yaml b/services/mcp/definitions/agent_platform.yaml
index 4ab2baeb90d0..1c0ca1f6dea1 100644
--- a/services/mcp/definitions/agent_platform.yaml
+++ b/services/mcp/definitions/agent_platform.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Agent stack
feature: agent_platform
-url_prefix: /agent_applications
+url_prefix: /
feature_flag: agent-platform
ui_apps: {}
tools:
diff --git a/services/mcp/definitions/data_management.yaml b/services/mcp/definitions/data_management.yaml
index b217599fdf7a..844cc0945510 100644
--- a/services/mcp/definitions/data_management.yaml
+++ b/services/mcp/definitions/data_management.yaml
@@ -6,7 +6,7 @@
# All other fields (title, description, enrich_url, etc.) are yours to configure.
category: Data management
feature: data_management
-url_prefix: /data-management/ingestion-warnings-v2
+url_prefix: /data-management/ingestion-warnings
ui_apps: {}
tools:
ingestion-warnings-list:
diff --git a/services/mcp/scripts/lint-tool-names.ts b/services/mcp/scripts/lint-tool-names.ts
index af6d00480a4b..8bf9f0e5b0d7 100644
--- a/services/mcp/scripts/lint-tool-names.ts
+++ b/services/mcp/scripts/lint-tool-names.ts
@@ -19,6 +19,10 @@
* generated schema JSONs) must point at an existing tool/skill. This only covers
* name-level staleness — it cannot validate documented schemas or tool behavior.
*
+ * url_prefix: each category's prefix must be a real frontend route (it becomes the
+ * `_posthogUrl` link on tool results), checked against the generated app-url manifest
+ * plus the SettingSectionId union. Pointing it at an API path is the easy mistake.
+ *
* Usage:
* pnpm --filter=@posthog/mcp lint-tool-names
*/
@@ -89,6 +93,134 @@ function validateYamlDefinitions(violations: Violation[], knownToolNames: Set<st
return hasErrors
}
+/**
+ * Routes the frontend actually serves. Two sources, because neither is complete on its own: the
+ * generated app-url manifest only covers routes that have a `urls` builder, while the route maps in
+ * products.tsx / manifest.tsx carry the rest (scenes reachable by path but with no builder).
+ */
+function loadAppRoutes(): Set<string> {
+ const routes = new Set<string>()
+
+ const manifestPath = path.resolve(MCP_ROOT, 'src/tools/links/app-url-manifest.json')
+ if (fs.existsSync(manifestPath)) {
+ const walk = (node: unknown): void => {
+ if (!node || typeof node !== 'object') {
+ return
+ }
+ const template = (node as { template?: unknown }).template
+ if (typeof template === 'string') {
+ routes.add(template)
+ }
+ for (const value of Object.values(node)) {
+ walk(value)
+ }
+ }
+ walk(JSON.parse(fs.readFileSync(manifestPath, 'utf-8')))
+ }
+
+ const routeMapFiles = [path.resolve(REPO_ROOT, 'frontend/src/products.tsx')]
+ if (fs.existsSync(PRODUCTS_DIR)) {
+ for (const entry of fs.readdirSync(PRODUCTS_DIR, { withFileTypes: true })) {
+ const manifest = path.join(PRODUCTS_DIR, entry.name, 'manifest.tsx')
+ if (entry.isDirectory() && fs.existsSync(manifest)) {
+ routeMapFiles.push(manifest)
+ }
+ }
+ }
+ for (const file of routeMapFiles) {
+ if (!fs.existsSync(file)) {
+ continue
+ }
+ const src = fs.readFileSync(file, 'utf-8')
+ // Route-map keys: `'/path/:param': [...]` and url builders returning a literal path.
+ for (const match of src.matchAll(/['"](\/[a-zA-Z0-9_\-/:{}]*)['"]\s*:/g)) {
+ if (match[1]) {
+ routes.add(match[1])
+ }
+ }
+ for (const match of src.matchAll(/=>\s*[`'"](\/[a-zA-Z0-9_\-/:${}]*)/g)) {
+ if (match[1]) {
+ routes.add(match[1])
+ }
+ }
+ }
+
+ return routes
+}
+
+/**
+ * Settings pages are `/settings/<SettingSectionId>`, and only a couple of sections have a urls.ts
+ * builder, so the app-url manifest doesn't carry them. Read the union instead. It has no terminating
+ * semicolon, so the block runs until the next top-level declaration.
+ */
+function loadSettingSectionIds(): Set<string> {
+ const ids = new Set<string>()
+ const typesPath = path.resolve(REPO_ROOT, 'frontend/src/scenes/settings/types.ts')
+ if (!fs.existsSync(typesPath)) {
+ return ids
+ }
+ const src = fs.readFileSync(typesPath, 'utf-8')
+ const union = /export type SettingSectionId =([\s\S]*?)(?=\n\S|$)/.exec(src)?.[1]
+ for (const match of (union ?? '').matchAll(/'([a-z0-9-]+)'/g)) {
+ if (match[1]) {
+ ids.add(match[1])
+ }
+ }
+ return ids
+}
+
+/**
+ * `url_prefix` is the frontend app route used to build the `_posthogUrl` link on tool results, so a
+ * prefix that isn't a real route hands agents (and the humans they answer) a 404. The API path is the
+ * easy mistake: `/conversations/tickets` is a valid endpoint but the scene lives at `/support/tickets`.
+ */
+function validateUrlPrefixes(violations: Violation[]): void {
+ const routes = loadAppRoutes()
+ const settingSectionIds = loadSettingSectionIds()
+ if (routes.size === 0) {
+ return
+ }
+
+ const isRoute = (prefix: string): boolean =>
+ [...routes].some((route) => route === prefix || route.startsWith(`${prefix}/`))
+ const isSettingsSection = (prefix: string): boolean =>
+ prefix.startsWith('/settings/') && settingSectionIds.has(prefix.slice('/settings/'.length))
+
+ for (const def of discoverDefinitions({ definitionsDir: DEFINITIONS_DIR, productsDir: PRODUCTS_DIR })) {
+ const parsed = parseYaml(fs.readFileSync(def.filePath, 'utf-8')) as {
+ url_prefix?: unknown
+ tools?: Record<string, { enrich_url?: unknown }>
+ }
+ const prefix = parsed?.url_prefix
+ if (typeof prefix !== 'string') {
+ continue
+ }
+ const source = path.relative(REPO_ROOT, def.filePath)
+
+ if (prefix === '/') {
+ // `/` + enrich_url concatenates into `//{id}`, which a browser reads as protocol-relative.
+ const enriching = Object.entries(parsed.tools ?? {}).filter(([, config]) => config?.enrich_url)
+ if (enriching.length > 0) {
+ violations.push({
+ source,
+ tool: `url_prefix: / with enrich_url on ${enriching.map(([name]) => name).join(', ')}`,
+ reason: 'a "/" prefix cannot carry enrich_url (yields "//{id}") — add a real scene path or drop enrich_url',
+ })
+ }
+ continue
+ }
+
+ if (isRoute(prefix) || isSettingsSection(prefix)) {
+ continue
+ }
+ violations.push({
+ source,
+ tool: `url_prefix: ${prefix}`,
+ reason: 'not a frontend app route (use the scene path, or "/" when the product has no page)',
+ })
+ }
+}
+
function validateJsonDefinitions(fileName: string, violations: Violation[], knownToolNames: Set<string>): boolean {
const filePath = path.resolve(SCHEMA_DIR, fileName)
if (!fs.existsSync(filePath)) {
@@ -199,6 +331,7 @@ function main(): void {
const knownToolNames = new Set<string>()
hasErrors = validateYamlDefinitions(violations, knownToolNames) || hasErrors
+ validateUrlPrefixes(violations)
for (const jsonFile of ['tool-definitions.json', 'generated-tool-definitions.json']) {
hasErrors = validateJsonDefinitions(jsonFile, violations, knownToolNames) || hasErrors
@@ -217,11 +350,11 @@ function main(): void {
return
}
- process.stderr.write(`Found ${violations.length} tool name violation(s):\n\n`)
+ process.stderr.write(`Found ${violations.length} violation(s):\n\n`)
for (const v of violations) {
process.stderr.write(` ${v.tool}: ${v.reason} (${v.source})\n`)
}
- process.stderr.write(`\nTo fix: shorten or rename the tool name to satisfy the length/pattern constraints.\n`)
+ process.stderr.write(`\nTo fix: follow the reason on each line above.\n`)
process.exitCode = 1
}
diff --git a/services/mcp/src/tools/generated/batch_exports.ts b/services/mcp/src/tools/generated/batch_exports.ts
index c441fa8a02a7..56cc0f04c60a 100644
--- a/services/mcp/src/tools/generated/batch_exports.ts
+++ b/services/mcp/src/tools/generated/batch_exports.ts
@@ -166,7 +166,7 @@ const batchExportsList = (): ToolBase<
])
),
} as typeof result
- return await withPostHogUrl(context, filtered, '/data-pipelines/destinations')
+ return await withPostHogUrl(context, filtered, '/data-management/destinations')
},
})
diff --git a/services/mcp/src/tools/generated/cdp_function_templates.ts b/services/mcp/src/tools/generated/cdp_function_templates.ts
index 0da3a2798e56..aa988e6593a6 100644
--- a/services/mcp/src/tools/generated/cdp_function_templates.ts
+++ b/services/mcp/src/tools/generated/cdp_function_templates.ts
@@ -46,7 +46,7 @@ const cdpFunctionTemplatesList = (): ToolBase<
])
),
} as typeof result
- return await withPostHogUrl(context, filtered, '/pipeline/templates')
+ return await withPostHogUrl(context, filtered, '/pipeline/new')
},
})
diff --git a/services/mcp/src/tools/generated/customer_analytics.ts b/services/mcp/src/tools/generated/customer_analytics.ts
index bf44d8ca3c30..9df3d1fdca62 100644
--- a/services/mcp/src/tools/generated/customer_analytics.ts
+++ b/services/mcp/src/tools/generated/customer_analytics.ts
@@ -134,7 +134,7 @@ const accountRelationshipDefinitionsList = (): ToolBase<
offset: params.offset,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -267,7 +267,7 @@ const accountsCustomPropertyValuesList = (): ToolBase<
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/accounts/${encodeURIComponent(String(params.account_id))}/custom_property_values/`,
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -312,7 +312,7 @@ const accountsList = (): ToolBase<typeof AccountsListSchema, WithPostHogUrl<Sche
tags: params.tags,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -381,7 +381,7 @@ const accountsNotebooksList = (): ToolBase<
search: params.search,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -503,7 +503,7 @@ const accountsRelationshipsList = (): ToolBase<
include_history: params.include_history,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -596,7 +596,7 @@ const customPropertyDefinitionsList = (): ToolBase<
offset: params.offset,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -753,7 +753,7 @@ const customPropertySourcesList = (): ToolBase<
offset: params.offset,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -826,7 +826,7 @@ const customPropertySourcesRunsList = (): ToolBase<
offset: params.offset,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
@@ -1095,7 +1095,7 @@ const usageMetricsList = (): ToolBase<
offset: params.offset,
},
})
- return await withPostHogUrl(context, result, '/customer-analytics')
+ return await withPostHogUrl(context, result, '/customer_analytics')
},
})
diff --git a/services/mcp/src/tools/generated/data_management.ts b/services/mcp/src/tools/generated/data_management.ts
index 8a808dcfc66e..40185ba61b3f 100644
--- a/services/mcp/src/tools/generated/data_management.ts
+++ b/services/mcp/src/tools/generated/data_management.ts
@@ -31,7 +31,7 @@ const ingestionWarningsList = (): ToolBase<
until: params.until,
},
})
- return await withPostHogUrl(context, result, '/data-management/ingestion-warnings-v2')
+ return await withPostHogUrl(context, result, '/data-management/ingestion-warnings')
},
})
diff --git a/services/mcp/src/tools/generated/field_notes.ts b/services/mcp/src/tools/generated/field_notes.ts
index 72d430b802af..4e4e35e6baae 100644
--- a/services/mcp/src/tools/generated/field_notes.ts
+++ b/services/mcp/src/tools/generated/field_notes.ts
@@ -13,7 +13,7 @@ import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
const FieldNotesGetSchema = FieldNotesRetrieveParams.omit({ project_id: true })
-const fieldNotesGet = (): ToolBase<typeof FieldNotesGetSchema, WithPostHogUrl<Schemas.FieldNote>> => ({
+const fieldNotesGet = (): ToolBase<typeof FieldNotesGetSchema, Schemas.FieldNote> => ({
name: 'field-notes-get',
schema: FieldNotesGetSchema,
handler: async (context: Context, params: z.infer<typeof FieldNotesGetSchema>) => {
@@ -22,7 +22,7 @@ const fieldNotesGet = (): ToolBase<typeof FieldNotesGetSchema, WithPostHogUrl<Sc
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/field_notes/${encodeURIComponent(String(params.id))}/`,
})
- return await withPostHogUrl(context, result, `/field_notes/${result.id}`)
+ return result
},
})
@@ -62,16 +62,7 @@ const fieldNotesList = (): ToolBase<typeof FieldNotesListSchema, WithPostHogUrl<
])
),
} as typeof result
- return await withPostHogUrl(
- context,
- {
- ...filtered,
- results: await Promise.all(
- (filtered.results ?? []).map((item) => withPostHogUrl(context, item, `/field_notes/${item.id}`))
- ),
- },
- '/field_notes'
- )
+ return await withPostHogUrl(context, filtered, '/')
},
})
@@ -79,10 +70,7 @@ const FieldNotesPartialUpdateSchema = FieldNotesPartialUpdateParams.omit({ proje
FieldNotesPartialUpdateBody.shape
)
-const fieldNotesPartialUpdate = (): ToolBase<
- typeof FieldNotesPartialUpdateSchema,
- WithPostHogUrl<Schemas.FieldNote>
-> => ({
+const fieldNotesPartialUpdate = (): ToolBase<typeof FieldNotesPartialUpdateSchema, Schemas.FieldNote> => ({
name: 'field-notes-partial-update',
schema: FieldNotesPartialUpdateSchema,
handler: async (context: Context, params: z.infer<typeof FieldNotesPartialUpdateSchema>) => {
@@ -129,7 +117,7 @@ const fieldNotesPartialUpdate = (): ToolBase<
path: `/api/projects/${encodeURIComponent(String(projectId))}/field_notes/${encodeURIComponent(String(params.id))}/`,
body,
})
- return await withPostHogUrl(context, result, `/field_notes/${result.id}`)
+ return result
},
})
diff --git a/services/mcp/src/tools/generated/integrations.ts b/services/mcp/src/tools/generated/integrations.ts
index e666e955df9d..2d351c8553e9 100644
--- a/services/mcp/src/tools/generated/integrations.ts
+++ b/services/mcp/src/tools/generated/integrations.ts
@@ -165,7 +165,7 @@ const integrationsList = (): ToolBase<
pickResponseFields(item, ['id', 'kind', 'display_name', 'errors', 'created_at', 'created_by'])
),
} as typeof result
- return await withPostHogUrl(context, filtered, '/settings/integrations')
+ return await withPostHogUrl(context, filtered, '/settings/environment-integrations')
},
})
diff --git a/services/mcp/src/tools/generated/mcp_store.ts b/services/mcp/src/tools/generated/mcp_store.ts
index 3615b7095d66..3e5d7c0b4947 100644
--- a/services/mcp/src/tools/generated/mcp_store.ts
+++ b/services/mcp/src/tools/generated/mcp_store.ts
@@ -23,7 +23,7 @@ const mcpConnectionToolsList = (): ToolBase<
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/mcp_server_installations/${encodeURIComponent(String(params.id))}/tools/`,
})
- return await withPostHogUrl(context, result, '/settings/environment-mcp-servers')
+ return await withPostHogUrl(context, result, '/settings/mcp-servers')
},
})
@@ -45,7 +45,7 @@ const mcpConnectionsList = (): ToolBase<
offset: params.offset,
},
})
- return await withPostHogUrl(context, result, '/settings/environment-mcp-servers')
+ return await withPostHogUrl(context, result, '/settings/mcp-servers')
},
})
diff --git a/services/mcp/tests/tools/batchExports.integration.test.ts b/services/mcp/tests/tools/batchExports.integration.test.ts
index 4984d52056dd..0a0b2ac05ed3 100644
--- a/services/mcp/tests/tools/batchExports.integration.test.ts
+++ b/services/mcp/tests/tools/batchExports.integration.test.ts
@@ -65,7 +65,7 @@ describe('Batch exports', { concurrent: false }, () => {
expect(typeof data.count).toBe('number')
expect(Array.isArray(data.results)).toBe(true)
expect(typeof data._posthogUrl).toBe('string')
- expect(data._posthogUrl).toContain('/data-pipelines/destinations')
+ expect(data._posthogUrl).toContain('/data-management/destinations')
})
it('should respect the limit parameter', async () => {
diff --git a/services/mcp/tests/tools/cdpFunctionTemplates.integration.test.ts b/services/mcp/tests/tools/cdpFunctionTemplates.integration.test.ts
index cafdb3cc243e..ebb8e56683db 100644
--- a/services/mcp/tests/tools/cdpFunctionTemplates.integration.test.ts
+++ b/services/mcp/tests/tools/cdpFunctionTemplates.integration.test.ts
@@ -33,7 +33,7 @@ describe('Hog Function Templates', { concurrent: false }, () => {
expect(typeof data.count).toBe('number')
expect(Array.isArray(data.results)).toBe(true)
expect(typeof data._posthogUrl).toBe('string')
- expect(data._posthogUrl).toContain('/pipeline/templates')
+ expect(data._posthogUrl).toContain('/pipeline/new')
})
it('should return templates with required fields', async () => {