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(cdp): accept id as an alias for template_id on the template tool (#125381)

Meikel Ratz5c0bdd375130
diff --git a/products/cdp/mcp/cdp_function_templates.yaml b/products/cdp/mcp/cdp_function_templates.yaml
index 9b7bf8b81007..d945433ee540 100644
--- a/products/cdp/mcp/cdp_function_templates.yaml
+++ b/products/cdp/mcp/cdp_function_templates.yaml
@@ -48,3 +48,7 @@ tools:
Get a specific function template by its template ID (e.g. 'template-slack', 'template-geoip'). Returns the
full template including source code, inputs schema, default filters, and mapping templates. Use this to
understand what inputs a template requires before creating a function from it.
+ param_overrides:
+ template_id:
+ aliases:
+ - id
diff --git a/services/mcp/src/tools/generated/cdp_function_templates.ts b/services/mcp/src/tools/generated/cdp_function_templates.ts
index 44ab79a5e7c0..549393ba8c61 100644
--- a/services/mcp/src/tools/generated/cdp_function_templates.ts
+++ b/services/mcp/src/tools/generated/cdp_function_templates.ts
@@ -3,6 +3,7 @@ import { z } from 'zod'
import type { Schemas } from '@/api/generated'
import * as orvalSchemas from '@/generated/cdp_function_templates/api'
+import { normalizeParamAliases } from '@/tools/cast-helpers'
import { withPostHogUrl, pickResponseFields, type WithPostHogUrl } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
@@ -52,7 +53,10 @@ const cdpFunctionTemplatesList = (): ToolBase<
const CdpFunctionTemplatesRetrieveSchema = () => {
const HogFunctionTemplatesRetrieveParams = orvalSchemas.HogFunctionTemplatesRetrieveParams()
- return HogFunctionTemplatesRetrieveParams.omit({ project_id: true })
+ return z.preprocess(
+ normalizeParamAliases({ template_id: ['id'] }),
+ HogFunctionTemplatesRetrieveParams.omit({ project_id: true })
+ )
}
const cdpFunctionTemplatesRetrieve = (): ToolBase<
diff --git a/services/mcp/tests/unit/cdp-function-templates-retrieve-schema.test.ts b/services/mcp/tests/unit/cdp-function-templates-retrieve-schema.test.ts
new file mode 100644
index 000000000000..be0dcba1fa9d
--- /dev/null
+++ b/services/mcp/tests/unit/cdp-function-templates-retrieve-schema.test.ts
@@ -0,0 +1,28 @@
+import { describe, expect, it } from 'vitest'
+
+import { GENERATED_TOOLS } from '@/tools/generated/cdp_function_templates'
+
+const schema = GENERATED_TOOLS['cdp-function-templates-retrieve']!().schema
+
+describe('cdp-function-templates-retrieve schema', () => {
+ it.each([
+ ['template_id', { template_id: 'template-slack' }, 'template-slack'],
+ // Every other PostHog tool names its identifier `id`, and cdp-function-templates-list
+ // returns the template under `id`, so agents reach for `id` here too.
+ ['id alias', { id: 'template-slack' }, 'template-slack'],
+ [
+ 'template_id takes precedence over id',
+ { template_id: 'template-geoip', id: 'template-slack' },
+ 'template-geoip',
+ ],
+ ])('accepts %s and normalizes to template_id', (_label, input, expected) => {
+ const result = schema.safeParse(input)
+
+ expect(result.success).toBe(true)
+ expect(result.data).toEqual({ template_id: expected })
+ })
+
+ it('rejects input with no recognized identifier', () => {
+ expect(schema.safeParse({}).success).toBe(false)
+ })
+})