Loading...
Loading...
Guide for exposing PostHog product endpoints as MCP tools. Use when creating new or updating API endpoints, adding MCP tool definitions, scaffolding YAML configs, or writing serializers with good descriptions. Covers the full pipeline from Django serializer to generated TypeScript tool handler.
npx skill4agent add posthog/posthog implementing-mcp-tools# 1. Scaffold a starter YAML with all operations disabled.
# --product is a substring match on URL paths: it selects every endpoint
# whose path contains /<name>/ (hyphens normalized to underscores).
# The value can be a product name or any path-segment needle
# (e.g. --product actions matches /api/projects/{project_id}/actions/).
pnpm --filter=@posthog/mcp run scaffold-yaml -- --product your_product \
--output ../../products/your_product/mcp/tools.yaml
# 2. Configure the YAML — enable tools, add scopes, annotations, descriptions
# Place in products/<product>/mcp/*.yaml (preferred) or services/mcp/definitions/*.yaml
# 3. Add a HogQL system table in posthog/hogql/database/schema/system.py
# and a model reference in products/posthog_ai/skills/query-examples/references/
# 4. Generate handlers and schemas
hogli build:openapihelp_text.describe()ListField(child=serializers.CharField())ListField()@extend_schema_field(PydanticModel)JSONFieldposthog/api/alert.pyViewSet@extend_schema(request=...)z.object({})ModelViewSetserializer_classViewSet@validated_request@extend_schemaproducts/<product>/mcp/*.yamlservices/mcp/definitions/*.yamlcategory: Human readable name
feature: snake_case_name
url_prefix: /path
tools:
your-tool-name: # kebab-case
operation: operationId_from_openapi
enabled: true
scopes:
- your_product:read
annotations:
readOnly: true
destructive: false
idempotent: true
# Optional:
mcp_version: 1 # 2 for create/update/delete ops, 1 for read/list if available via HogQL
title: List things
description: >
Human-friendly description for the LLM.
list: true
enrich_url: '{id}'
param_overrides:
name:
description: Custom description for the LLM.strict()pnpm --filter=@posthog/mcp run scaffold-yaml -- --sync-allenabled: falseDjango serializer field → OpenAPI spec → Zod schema → MCP tool descriptionhelp_textparam_overridesposthog/hogql/database/schema/system.pyteam_idmcp_version: 1models-<domain>.mdproducts/posthog_ai/skills/query-examples/references/products/posthog_ai/skills/query-examples/SKILL.mdmcp_version: 1/2