posthog-toolkit-mcp
Provides tools for interacting with a PostHog instance, including HogQL queries, event and property definitions, session replays, project listing, and general REST API access with read-only by default and optional write support.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@posthog-toolkit-mcp Run a HogQL query for daily active users over the last 7 days"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
posthog-toolkit-mcp
An MCP server for PostHog, on PostHog Cloud or a self-hosted instance: HogQL queries, event and property definitions, session replays and the REST API — with guards that keep an agent from sending the API key elsewhere or writing by accident.
Tools
Tool | What it does |
| Runs a HogQL query. Refuses insight placeholders like |
| Event names seen in the project, with last-seen time; optional substring |
| Event or person property names with their types. |
| Session recordings of a |
| Projects of the organization. Works with personal API keys scoped to specific projects. |
| GET any PostHog REST endpoint; |
| Any method, including writes. Registered only with |
Related MCP server: pg-readonly-mcp
Configuration
Variable | |
| Required. |
| Required. A personal API key ( |
| Default project for the tools and for |
|
|
| Cap on a tool response. Default |
| Request timeout. Default |
The key needs read access to the project (and user read access for posthog_projects; without it the tool falls
back to the organization project list).
Install
{
"mcpServers": {
"posthog": {
"command": "npx",
"args": ["-y", "posthog-toolkit-mcp"],
"env": {
"POSTHOG_HOST": "https://posthog.example.com",
"POSTHOG_API_KEY": "${POSTHOG_API_KEY}",
"POSTHOG_PROJECT_ID": "1"
}
}
}
}In Claude Code this block goes into the project's .mcp.json; keep the key itself out of the file, e.g. in the
env block of .claude/settings.local.json, and pin the version (posthog-toolkit-mcp@0.1.0) so every machine runs
the same server.
Security
Read-only by default; writes need
POSTHOG_ALLOW_WRITE.Requests go only to the
POSTHOG_HOSTorigin: a path like//other-host/...is refused before the API key could leave with it.Project ids are validated as numbers before they reach a URL.
Development
npm install
npm run typecheck # tsc --noEmit
npm run build # esbuild bundles src/index.ts into dist/server.mjs with no runtime dependencies
npm run smoke # stdio checks: configuration errors, tool list, guards that fire before any network call
npm run check # all threeFile | |
| Entry point: builds the server from the environment and connects stdio. |
| Reads and validates environment variables. |
| PostHog API client; refuses paths that would leave |
| Zod input schemas of the tools; handler argument types are inferred from them. |
| Tool registration and result formatting. |
| HogQL literals, insight placeholder detection, the recordings query. |
The bundle is a single file on purpose: npx starts it without installing any dependencies.
License
MIT — see LICENSE. Dependencies bundled into dist/server.mjs keep their own licenses, listed in
THIRD_PARTY_NOTICES.md.
Available Tools
6 toolsposthog_api_getGET a PostHog API endpointARead-only
GET any PostHog REST endpoint for what HogQL does not cover: feature flags, insights, dashboards, experiments, cohorts. {project_id} in the path is replaced with the default project, e.g. /api/projects/{project_id}/feature_flags/
Inputs: path (required), params.
posthog_event_definitionsList event namesARead-only
Event names seen in a project, with when each was last seen. Use it instead of guessing event names in HogQL.
Inputs: limit, offset, search, project_id.
posthog_projectsList projectsARead-only
Projects of the organization with their ids. Works with API keys scoped to specific projects.
Inputs: no named parameters.
posthog_property_definitionsList property namesARead-only
Event or person property names in a project, with their types. Use it instead of guessing property names in HogQL.
Inputs: type, limit, offset, search, +1 more.
posthog_queryRun a HogQL queryARead-only
Runs a HogQL (ClickHouse SQL dialect) query: tables events, persons, sessions, groups, raw_session_replay_events. Example: SELECT event, count() FROM events WHERE timestamp > now() - INTERVAL 7 DAY GROUP BY event ORDER BY 2 DESC LIMIT 20.
Inputs: query (required), project_id.
posthog_replaysFind session replaysARead-only
Session recordings of one distinct_id in a time window, newest first, with links to watch them. Recordings older than the instance retention are gone. Naive timestamps are read in the project timezone.
Inputs: distinct_id (required), to, from, limit, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a distinct area—definitions, projects, HogQL querying, replays, and generic REST access—so an agent can usually choose correctly. The only mild overlap is between posthog_query and posthog_api_get, but the HogQL vs REST distinction is clearly drawn.
All tools share a posthog_ prefix and snake_case, but the pattern is mixed: event_definitions, projects, property_definitions, and replays are resource nouns, while posthog_query is an operation and posthog_api_get introduces a verb suffix. It is readable but not a consistent verb_noun scheme.
Six tools cover the core PostHog introspection and querying use cases without padding. The generic posthog_api_get tool avoids the need for many narrowly-scoped REST endpoint tools.
Event/property definitions, project selection, HogQL querying, session replays, and a generic REST GET cover the main read and analysis workflows. Write/update operations are not exposed through the REST wrapper, but that appears intentionally out of scope for this query-oriented toolkit.
Maintenance
Related MCP Connectors
Query website traffic, events, signup goals, funnels, and errors with scoped Databuddy access.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceProvides secure read-only SQL access to PostgreSQL and ClickHouse databases with built-in safety features like read-only enforcement, timeouts, and managed result files.MIT
- FlicenseAqualityDmaintenanceEnables read-only exploration of a Postgres database using natural language, with multiple safety layers to prevent any modifications.5-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to query PostgreSQL, inspect schemas, and explain queries, designed for local and development databases with read-only safety by default.45 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables agents to inspect PostgreSQL schemas, run read-only queries and explain plans, and, when explicitly permitted, execute writes and DDL on a per-project database with layered safety controls.MIT