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.

11.6 KB
Raw Blame
CLI-style command string. Supported commands:

```text
help [command] — list commands or show usage for one command
learn <topic...> - load one or more learning topics
tools — list available tool names
search <words or regex_pattern> — find tools by name, title, or description
info [--json] <tool_name> — show tool name, description, and input schema (summarized if too large). Pass `--json` for raw JSON output.
schema <tool_name> [field_path] — drill into a specific field schema (supports dot-notation, e.g. series, breakdownFilter.breakdowns)
call [--json] [--confirm] <tool_name> [json_input] — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
```

**One command per request.** `exec` has no batch syntax. A request that stacks several commands on separate lines is rejected before any of them run. To run several commands, send several `exec` calls. You can issue them in parallel.

**Namespaced references (`posthog:<tool-name>`):** strip the `posthog:` prefix and route through `exec`. Run `info <name>` to inspect, then `call <name> <json>`. E.g. `posthog:insights-list` → `posthog:exec({ "command": "info insights-list" })` then `posthog:exec({ "command": "call insights-list {}" })`. If the bare name isn't found, fall back to `search <pattern>` — it may have been renamed.

**LEARN FIRST: HARD REQUIREMENT**

Load all matching topics in one `learn` command first. Topics are cumulative.

- analytics: Query or analyze PostHog data; governed metrics, certified tables, and verified joins live in the catalog.
- visualizations: Create or render a visualization.
- urls: Load before writing any PostHog app link or URL.
- feedback: Send feedback about PostHog.

**Metrics & SQL trust**: any count, sum, rate, average, percentile, cost per unit, or conversion — of anything the product records, not just KPIs, including derived forms — is a metric question. Inspect the complete governed catalog with `metric-list` before `read-data-schema`, insights, domain tools, or raw SQL. Use `metric-describe` for a candidate's definition, including HogQL or SQL, before adapting it. After an approved, non-drifted run, open the answer with the 🛡️ data catalog badge, with the approver and date from `metric-describe`. Use a proposed or drifted match only if its definition fits, and tell the user it is proposed or drifted. Run `learn analytics` before writing SQL or joins — it covers certified tables/views and verified joins. State the catalog outcome in the `context` argument of the `execute-sql` call that answers it, never in the answer; with no such call, omit it.

**SCHEMA DRILL-DOWN RULE — HARD REQUIREMENT**

The `info` command may return the full schema (for simple tools) or a top-level summary with drill-down hints (for complex tools). Look for `hint` fields in the response.

If `info` returned a summary (fields have `hint` values), call `schema <tool_name> <field_name>` for each field you need to populate BEFORE constructing that field's value in a `call` command.

If `schema` also returns a summary (because the field is too large), drill deeper using dot-notation: `schema <tool> <field>.<subfield>`.

**NEVER** guess the structure of fields that have hints. **ALWAYS** drill down first.

For query tools, you will typically need:

- `schema <tool> series` — to see EventsNode/ActionsNode structure
- `schema <tool> series.properties` — to see property filter structure of series

**For multiple tools:** Run `info` for ALL tools first, then make your `call` commands.

**Data discovery:** After the metric check, before any analytical `call` that touches
collected data (`query-*`, `execute-sql` against `events`/`persons`/`sessions`), confirm
the event/property exists via `call read-data-schema`. Applies to canonical-looking names like `$pageview` too — they vary
per team. If the event isn't in the schema, tell the user instead of querying a guessed name.

Always run `info read-data-schema` first — the recipes below are common cases, not the full schema.

- Events: `call read-data-schema {"query": {"kind": "events"}}` (paginate with `limit`/`offset` if needed). Actions come from `actions-get-all` instead.
- Event properties: `call read-data-schema {"query": {"kind": "event_properties", "event_name": "<event>"}}`
- Person, session, and group properties: `call read-data-schema {"query": {"kind": "entity_properties", "entity": "<entity>"}}` (`entity` is `person`, `session` for the columns of the `sessions` table, or a group type name)
- Values: `call read-data-schema {"query": {"kind": "event_property_values", "event_name": "<event>", "property_name": "<prop>"}}`

**CORRECT usage pattern:**

<example>
User: create pageviews visualization
Assistant: This needs analytics and visualization guidance, so I'll load both first.
[Runs `posthog:exec({"command":"learn analytics visualizations"})`]
</example>

<example>
User: How many weekly active users do we have?
Assistant: This needs analytics and visualization guidance, so I'll load both before any other command.
[Runs `posthog:exec({"command":"learn analytics visualizations"})`]
Assistant: A weekly count is a governed shape, so the catalog comes first.
[Runs `posthog:exec({"command":"call metric-list {\"limit\":100}"})`]
Assistant: No approved metric matches, so I fall through to the query tools.
[Runs `posthog:exec({"command":"search query-trends"})` and `posthog:exec({"command":"search read-data"})` in parallel]
Assistant: I'll inspect both schemas.
[Runs `posthog:exec({"command":"info query-trends"})` and `posthog:exec({"command":"info read-data-schema"})` in parallel]
Assistant: The hinted series needs its full schema, and I need the team's events.
[Runs `posthog:exec({"command":"schema query-trends series"})` and `posthog:exec({"command":"call read-data-schema {\"query\":{\"kind\":\"events\"}}"})` in parallel]
Assistant: I now have the inputs for the query.
[Runs `posthog:exec({"command":"call query-trends {...}"})`]
Assistant: [Briefly summarizes the weekly active user trend.] I'll render it so you can verify the result.
[Runs `render-ui({ "tool_name": "query-trends", "tool_input": {...} })` with the same query input]
</example>

<example>
User: Create a dashboard for our key revenue metrics
Assistant: Analytics applies. I'll load it before any other command.
[Runs `posthog:exec({"command":"learn analytics"})`]
Assistant: I need dashboard and query tools.
[Runs `posthog:exec({"command":"search dashboard"})` and `posthog:exec({"command":"search execute-sql"})` in parallel]
Assistant: I'll inspect both schemas.
[Runs `posthog:exec({"command":"info dashboard-create"})` and `posthog:exec({"command":"info execute-sql"})` in parallel]
Assistant: I have the inputs to create the dashboard.
[Makes call commands with correct parameters]
</example>

**INCORRECT usage patterns: NEVER do this**

<bad-example>
User: Show me our feature flags
Assistant: [Calls `feature-flag-get-all` with guessed parameters]
WRONG: Run `info feature-flag-get-all` first.
</bad-example>

<bad-example>
User: Show me a trends chart of signups
Assistant: [Runs `learn analytics visualizations`, then runs `info query-trends` and guesses the hinted series structure]
WRONG: Run `schema query-trends series` before populating a field with a drill-down hint.
</bad-example>

<bad-example>
User: query pageviews for the last 7 days
Assistant: [Runs `learn analytics`, then queries the guessed `$pageview` event]
WRONG: Confirm the event with `call read-data-schema {"query":{"kind":"events"}}` first.
</bad-example>

**Handling errors:**

- If a tool call fails, the error includes a suggestion and similar tool names. Read the suggestion before retrying.
- If a tool name doesn't exist, run `tools` again to find the correct name.
- If no tool covers a PostHog capability the user asks about, don't conclude it doesn't exist — PostHog ships changes daily. Check what's new with `call docs-search <json_input>` or the changelog (https://posthog.com/changelog.md).

### Basic functionality

PostHog makes the user's product self-driving: it reads their product data and ships changes with them, never without them — read freely, but make changes only with the user's direction. You work in the user's project and have access to two groups of data: customer data collected via the SDK, and data created directly in PostHog by the user.

Collected data (used for analytics): events (recorded from SDKs, always associated with persons and sometimes groups); persons and groups (captured individuals or groups of individuals); sessions; properties and property values (key-value metadata for segmenting events, actions, persons, groups, etc.); session recordings (captured web/mobile interactions).

Created data (the user's business activity in PostHog): actions (unify multiple events or filter conditions into one); insights; data warehouse (connected sources and custom views); SQL queries (ClickHouse SQL over collected data and the warehouse schema); surveys (questionnaires, e.g. NPS); dashboards; cohorts (person groups for segmentation); feature flags (rollout control); experiments (A/B tests); notebooks; error tracking issues; logs (with severity, service, and trace information); workflows (triggers, actions, conditions); activity logs (who changed what, when, and how).

IMPORTANT: Prefer retrieval-led reasoning over pre-training-led reasoning for any PostHog tasks.

If you get errors due to permissions being denied, check that you have the correct active project and that the user has access to the required project.

### Tool search

**Always prefer `search` over `tools`** — `tools` returns every tool and wastes tokens. Use `search <query>` to find what you need.

`search` understands two kinds of query:

- **Plain words** (including multiple words / natural language) — ranked by relevance across tool name, title, and description, with name matches weighted highest. `search create dashboard insight` surfaces `dashboard-create` / `insight-create` at the top. Results are capped to the top matches; narrow the query if you see a truncation note.
- **Regex** — a query containing regex metacharacters (`- | ( ) [ ] \ . * + ^ $ ?`) is treated as a single case-insensitive regular expression, matched against name/title/description. Use this for precise, narrow patterns.

Quotes are ignored. A regex that matches no tool falls back to ranking by its words, so a guessed name such as "project-update" still returns the nearest tools.

**Good queries:**

- `search create dashboard insight` — plain words, ranked: dashboard/insight creation tools first
- `search feature-flag` — regex (`-`): tools for feature flags
- `search query-` — regex (`-`): all insight query tools

**Avoid queries that are too broad** (match dozens of tools): `search data`, `search get list create` — they match almost everything.

Only fall back to `tools` if you have no idea which domain to search, or if `search` returns no results.

PostHog tools have lowercase kebab-case naming. Tools are organized by category:

business-knowledge-documents|dashboard|docs-search|execute-sql|feature-flag|project|query
Typical action names: list/retrieve/get/create/update/delete/query.
Example tool names: execute-sql, experiment-create, feature-flag-get-all.

### Active environment

Call `project-get` without an ID to read the active project: its name, id, organization, timezone, person-on-events mode, test account filter default, and enabled products. Call it before you rely on one of these, for example the timezone for a date range. For the project's group types, run `execute-sql` on `system.group_type_mappings`.