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.

9.9 KB
Raw Blame
# MCP tool definitions. Tools are opt-in: an operation is exposed only when it has an entry here.
# List operations without an entry: pnpm --filter=@posthog/mcp run scaffold-yaml -- --candidates --product cohorts
# Add one: pnpm --filter=@posthog/mcp run scaffold-yaml -- --add <operationId> --product cohorts
# To keep an operation off on purpose, set enabled: false and give a disabled_reason.
category: Cohorts
feature: cohorts
url_prefix: /cohorts
ui_apps:
    cohort:
        type: detail
        view_prop: cohort
    cohort-list:
        type: list
        detail_tool: cohorts-retrieve
tools:
    cohorts-add-persons-to-static-cohort-partial-update:
        operation: cohorts_add_persons_to_static_cohort_partial_update
        enabled: true
        scopes:
            - cohort:write
        annotations:
            readOnly: false
            destructive: false
            idempotent: false
        title: Add persons to static cohort
        description: >-
            Add persons to a static cohort by their UUIDs. Only works for static cohorts (is_static: true). 'person_ids'
            must be person UUIDs (the 'id' column of the persons table), not distinct IDs or emails.


            Intended for small, ad-hoc additions — pass at most ~20 person UUIDs per call. To build or grow a static
            cohort from a larger set, do NOT loop this tool over many UUIDs; instead create the cohort from a query
            ('cohorts-create' with 'is_static: true' and a 'query'), or add to an existing static cohort by setting a
            'query' on it via 'cohorts-partial-update'. The server then runs the query and inserts every matching person
            in a single call, with no row limit.
    cohorts-create:
        operation: cohorts_create
        enabled: true
        scopes:
            - cohort:write
        annotations:
            readOnly: false
            destructive: false
            idempotent: false
        enrich_url: '{id}'
        title: Create cohort
        description: >-
            Create a cohort (a saved group of persons). Two kinds:


            - Dynamic cohort (default): provide 'filters' with AND/OR groups of property conditions (person properties,
            behavioral filters, or cohort references). Membership is recalculated automatically.

            - Static cohort ('is_static: true'): a fixed snapshot of persons. PREFER populating it from a 'query' (see
            below) — the server runs the query and inserts every matching person in a single call, with no row limit.
            Only use 'cohorts-add-persons-to-static-cohort-partial-update' for tiny, ad-hoc additions (up to ~20
            people).


            Populate a static cohort from a query by setting BOTH 'is_static: true' and 'query'. 'query' accepts a
            HogQLQuery (raw SQL) or an ActorsQuery (the actors behind a product-analytics insight such as trends or
            funnels). The query MUST expose the person identifier under one of these column names, checked in this
            order: 'person_id', 'actor_id', 'id', or 'distinct_id'. Selecting from the 'events' or 'persons' tables
            resolves the actor automatically. If none of those columns is present the call fails with "Could not find a
            person_id, actor_id, id, or distinct_id column in the query".


            ALWAYS validate the query before saving it: run a HogQLQuery through the 'execute-sql' tool, and an
            ActorsQuery through its matching 'query-*-actors' tool (e.g. 'query-trends-actors',
            'query-lifecycle-actors'). Only pass a 'query' that returned successfully — this catches column-name and
            syntax errors before they fail cohort population.


            Example — from SQL (HogQLQuery), alias the id column as person_id:

            {"name": "Power users", "is_static": true, "query": {"kind": "HogQLQuery", "query": "SELECT person_id FROM
            events WHERE event = '$pageview' GROUP BY person_id HAVING count() > 100"}}


            Example — from a product-analytics trends insight (ActorsQuery):

            {"name": "Viewed pricing last 7d", "is_static": true, "query": {"kind": "ActorsQuery", "source": {"kind":
            "InsightActorsQuery", "source": {"kind": "TrendsQuery", "series": [{"kind": "EventsNode", "event":
            "$pageview"}], "dateRange": {"date_from": "-7d"}}}}}
        exclude_params:
            - groups
            - deleted
            - version
            - pending_version
            - is_calculating
            - created_by
            - created_at
            - last_calculation
            - errors_calculating
            - last_error_message
            - count
            - experiment_set
        ui_app: cohort
    cohorts-list:
        operation: cohorts_list
        enabled: true
        scopes:
            - cohort:read
        annotations:
            readOnly: true
            destructive: false
            idempotent: true
        enrich_url: '{id}'
        list: true
        title: List all cohorts
        description: >

            List all cohorts in the project. Returns a summary of each cohort including  id, name, description, count
            (person count), is_static (cohort type), and created_at timestamp. To find a cohort by name, pass 'search'
            rather than listing everything and filtering client-side — it matches the cohort name with fuzzy trigram
            search (tolerates typos and partial words) and orders exact matches first. Use 'cohorts-retrieve' with the
            cohort ID to get full details including filters, calculation status,

            and query definition.
        param_overrides:
            limit:
                cast: string-int
            offset:
                cast: string-int
            search:
                description: Find cohorts by name. Fuzzy trigram match (tolerates typos and partial words), exact matches ordered first.
            hide_behavioral_cohorts:
                description: Set true to exclude behavioral (event-based) cohorts — not usable in batch workflow audiences.
        ui_app: cohort-list
        response:
            include:
                - id
                - name
                - description
                - count
                - is_static
                - created_at
    cohorts-partial-update:
        operation: cohorts_partial_update
        enabled: true
        scopes:
            - cohort:write
        annotations:
            readOnly: false
            destructive: false
            idempotent: true
        enrich_url: '{id}'
        title: Update cohort
        description: >-
            Update an existing cohort's name, description, or filters. Changing filters on a dynamic cohort triggers
            recalculation. To soft-delete a cohort, set 'deleted: true'.


            To add more people to an existing STATIC cohort in bulk, set a 'query' (HogQLQuery or ActorsQuery) on it —
            the server runs the query and inserts every newly matched person (existing members are skipped), with no row
            limit. The query must expose the person id under one of these column names, checked in order: 'person_id',
            'actor_id', 'id', or 'distinct_id' (selecting from the 'events' or 'persons' tables resolves the actor
            automatically). Validate the query before saving it — run a HogQLQuery through 'execute-sql' and an
            ActorsQuery through its matching 'query-*-actors' tool (e.g. 'query-trends-actors') — and only save one that
            returned successfully. Prefer this over 'cohorts-add-persons-to-static-cohort-partial-update' for anything
            beyond a handful (~20) of people.


            An update that sets 'query' returns a 400 while the cohort's 'is_calculating' is true. That includes the
            first population right after 'cohorts-create' with a query. Before you send the next query, call
            'cohorts-retrieve' and wait until 'is_calculating' is false.
        exclude_params:
            - groups
            - version
            - pending_version
            - is_calculating
            - created_by
            - created_at
            - last_calculation
            - errors_calculating
            - last_error_message
            - count
            - experiment_set
        param_overrides:
            id:
                cast: string-int
        ui_app: cohort
    cohorts-retrieve:
        operation: cohorts_retrieve
        enabled: true
        scopes:
            - cohort:read
        annotations:
            readOnly: true
            destructive: false
            idempotent: true
        enrich_url: '{id}'
        title: Get cohort
        description: >
            Get a specific cohort by ID. Returns the cohort name, description, filters (for dynamic cohorts), count of
            matching users, and calculation status.
        param_overrides:
            id:
                cast: string-int
        ui_app: cohort
        response:
            exclude:
                - filters.properties.values.*.values.*.bytecode
                - filters.properties.values.*.values.*.bytecode_error
                - filters.properties.values.*.values.*.conditionHash
                - filters.properties.values.*.bytecode
                - filters.properties.values.*.bytecode_error
                - filters.properties.values.*.conditionHash
    cohorts-rm-person-from-static-cohort-partial-update:
        operation: cohorts_remove_person_from_static_cohort_partial_update
        enabled: true
        scopes:
            - cohort:write
        annotations:
            readOnly: false
            destructive: false
            idempotent: true
        title: Remove person from static cohort
        description: >
            Remove a person from a static cohort by their UUID. Only works for static cohorts (is_static: true). The
            person must exist in the project. Idempotent: removing a person who exists but is not a member of the cohort
            succeeds silently.