连接器指南阅读约 6 分钟28 个 MCP 工具7 种语言

如何通过 MCP 将 PostHog 连接到 Gemini

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

HC作者:HelpCode 团队更新于 6 分钟阅读 在 GitHub 开源

无需信用卡 · 7 天试用 · 提供自托管方案

PostHog

PostHog

Let your AI answer product analytics questions from PostHog: run read-only SQL (HogQL) over events and persons, compute trends, funnels and retention, read saved insights and dashboards, look up persons, cohorts, annotations and experiments, and manage insights and feature flags. PostHog Cloud (US or EU) or self-hosted, with a personal API key.

个工具

28

区域

INTL

类别

数据分析

身份验证

Bearer Token

所需环境变量

POSTHOG_HOSTPOSTHOG_PERSONAL_API_KEY
在 Cloud 上一键安装

7 天免费试用 · 无需信用卡

  • 7 天免费试用
    无需信用卡
  • 符合 GDPR,SOC 2 就绪
    数据驻留欧盟,审计日志
  • 在 GitHub 开源
    开源 · AGPL-3.0
  • 支持 ChatGPT、Claude、Gemini
    任何兼容 MCP 的客户端

跳过安装。2 分钟内即可运行。

在 cloud.anythingmcp.com 开始免费试用,一键添加 PostHog,然后将你的 AI 客户端(Claude、ChatGPT、Copilot 或 Cursor)指向生成的 MCP 端点。无需 Docker,无需 git clone,无需任何工程经验。

开始免费试用

摘要

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

试试这样问

PostHog 的示例提示

点击任意提示即可复制,然后粘贴到 Claude、ChatGPT、Cursor、Gemini、Copilot 或 OpenClaw 中,在该连接器上运行。

PostHog · 通过 MCP 实时
分享
Opus 4.7

Claude 是 AI,可能会出错。请核对回答。

💡 无需安装? 直接使用 cloud.anythingmcp.com。 登录、点击 Connectors → PostHog、粘贴凭证、生成 MCP API key,即可完成。无 Docker、无 git clone、无本地服务器。

PostHog + Gemini

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

前提条件

完整的设置说明已内置在连接器中 (在 store 中选择连接器时可见)。所需环境变量:

POSTHOG_HOST, POSTHOG_PERSONAL_API_KEY

步骤 1 — 获取凭证

  1. 在 PostHog 中打开 Settings → User → Personal API keys(US Cloud:https://us.posthog.com/settings/user-api-keys,EU Cloud:https://eu.posthog.com/settings/user-api-keys),点击 + Create a personal API key。
  2. 为密钥设置标签(例如 "AnythingMCP"),并选择 organization and project access:全部、某一个组织或指定项目。仅限指定项目的密钥无法列出组织或项目,但 posthog_get_current_user 仍然可用,并会显示当前项目。
  3. 勾选以下权限范围:
    • user:read, organization:read, project:read
    • query:read, person:read, cohort:read, experiment:read
    • insight:read, insight:write, dashboard:read
    • feature_flag:read, feature_flag:write
    • annotation:read, annotation:write
  4. 立即复制密钥:PostHog 只显示一次。密钥以 phx_ 开头(以 phc_ 开头的项目令牌在这里无效)。把它填入 POSTHOG_PERSONAL_API_KEY,不要带 Bearer 字样。
  5. 将 POSTHOG_HOST 设为你打开 PostHog 时使用的地址:US Cloud 用 https://us.posthog.com,EU Cloud 用 https://eu.posthog.com,自托管则填你自己实例的地址,末尾不要带斜杠或路径。数据接收地址 us.i.posthog.com 和 eu.i.posthog.com 会被拒绝,而且密钥只在创建它的云区域内有效。然后安装连接器。
  6. 先运行 posthog_get_current_user:它会显示该密钥属于哪个 PostHog 用户、当前项目以及组织下的项目。

只读配置:创建密钥时只勾选 :read 权限范围,并关闭 posthog_create_insight、posthog_update_insight、posthog_create_feature_flag、posthog_update_feature_flag 和 posthog_create_annotation。查询永远不会修改数据,因为 HogQL 只接受 SELECT。AI 能看到和修改的内容与密钥所属用户完全一致。

安装时默认关闭:posthog_delete_insight、posthog_delete_feature_flag 和 posthog_delete_annotation。PostHog 通过 API 从不彻底删除:这些工具只是把洞察、开关或注释标记为已删除,之后可以在 PostHog 应用中恢复。被删除的开关会被关闭,检查其 key 的代码将得到 false。

项目 ID:每个项目级工具都需要 project_id,即 PostHog URL 中的数字(/project/12345/...),也可以在 Settings → Project → General 中找到。@current 也可以使用,但它指的是用户在应用中最后打开的项目,可能随时变化:建议使用数字。其他项目可通过 posthog_list_organizations 和 posthog_list_projects 列出。

查询:posthog_run_hogql_query 对 events、persons、sessions 和 groups 运行一条 HogQL(PostHog 的 SQL)SELECT 语句;属性用 properties.$browser 或 person.properties.email 的方式读取。请始终按时间过滤(例如 WHERE timestamp >= now() - INTERVAL 7 DAY):不加过滤的扫描很慢,还会消耗读取预算。不加 LIMIT 时返回 100 行,加上后最多 50,000 行。OFFSET 会被拒绝,因此 AI 按 timestamp 或 id 分页。日期按项目时区解析,而不是 UTC。趋势、漏斗、留存、粘性、生命周期和路径分析使用 posthog_run_insight_query;转化率和留存率根据 count 值计算。查询接口用于即席分析,不适合批量导出。

洞察、看板和开关:posthog_get_insight 默认返回最近一次缓存的结果;refresh 设为 blocking 时会重新计算过期结果。posthog_get_dashboard 返回看板的卡片及其洞察。功能开关决定真实用户看到的内容:在创建或修改开关之前,AI 会向你展示开关的 key、active 和发布比例,并等待你确认。新开关最安全的做法是 active 设为 false 或发布比例设为 0。修改时会带上最近一次读取到的 version,以免覆盖他人的改动。

分页:列表类工具接受 limit 和 offset,返回 count、next(最后一页为 null)和 results。超过 200 KB 的响应会被截断。

速率限制:按组织计算,所有密钥和用户共享。普通读写为每分钟 480 次、每小时 4,800 次;用户查询和洞察计算等分析接口为每分钟 240 次、每小时 1,200 次。查询接口为每分钟 240 次、每小时 2,400 次,每个项目最多同时运行 3 个查询,并消耗每个项目的每小时读取预算(免费套餐更少)。超出限制时 PostHog 返回 429;预算用尽时返回 api_queries_budget_exceeded,但缓存的结果仍可使用。

常见错误:401 表示密钥错误、已删除或属于另一个云区域:请检查 POSTHOG_HOST。403 "API key missing required scope" 会指出需要添加的权限范围(密钥的权限范围之后可以修改);其他 403 表示密钥仅限其他项目或组织,或者组织不允许成员使用个人 API 密钥。404 "Project not found." 表示 project_id 错误或该用户无权查看。400 会指出无效字段,HogQL 查询还会附带解析器错误。开关返回 409 表示其 version 已过期:请重新读取该开关。

连接器不会发送事件或设置用户属性,不会删除用户,不读取会话回放或问卷,不创建或编辑看板、群组和实验,也不管理批量导出、成员和账单。

步骤 2 — 安装 adapter

curl -fsSL https://raw.githubusercontent.com/HelpCode-ai/anythingmcp/main/docker-compose.quickstart.yml -o docker-compose.yml
printf 'JWT_SECRET=%s\nENCRYPTION_KEY=%s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 32)" > .env
docker compose up -d

步骤 3 — 在 Gemini 中添加连接器

你的服务器 URL: 在 AnythingMCP 中打开 MCP Servers → 此连接器所在的服务器,复制它的 URL(https://cloud.anythingmcp.com/mcp/…)。本指南中出现 YOUR_SERVER_ID 的地方都用它替换。

Gemini CLI 从 ~/.gemini/settings.json(Windows 上为 %USERPROFILE%\.gemini\settings.json)读取 MCP 服务器。添加:

{
  "mcpServers": {
    "anythingmcp": {
      "httpUrl": "https://cloud.anythingmcp.com/mcp/YOUR_SERVER_ID",
      "headers": { "X-API-Key": "YOUR_MCP_API_KEY" }
    }
  }
}
  1. 在 AnythingMCP 的 MCP Servers → 你的服务器 → API keys 中创建 MCP API 密钥,并用它替换 YOUR_MCP_API_KEY。
  2. 保存文件并重启 gemini。
  3. 在 Gemini CLI 中运行 /mcp(或在终端运行 gemini mcp list),anythingmcp 应显示为已连接。
  4. 开始输入提示,Gemini CLI 现在可以调用 PostHog 的工具。

可用工具

ToolWhat it does
posthog_get_current_userGet the user the personal API key belongs to: uuid, email and name, the current project (id, name, project_id, timezone), the current…
posthog_list_organizationsList the organizations the user belongs to: id (a UUID), name, slug, membership_level, and each organization's projects
posthog_list_projectsList the projects of an organization: id (the project_id every other tool takes), name, project_id, timezone, tags, is_demo and…
posthog_get_projectGet one project's settings: name, timezone, week_start_day, base_currency, app_urls, test account filters, group types, whether events…
posthog_run_hogql_queryRun one read-only HogQL (PostHog SQL) SELECT over events, persons, sessions, groups or warehouse tables and return columns, results (rows…
posthog_run_insight_queryRun one of PostHog's insight calculations without saving it: TrendsQuery, FunnelsQuery, RetentionQuery, StickinessQuery, LifecycleQuery or…
posthog_list_personsList or search persons (identified users and anonymous visitors): id, uuid, name, distinct_ids, properties, created_at and last_seen_at.…
posthog_get_personGet one person by numeric id or UUID: name, distinct_ids, all person properties (email, initial UTM and referrer, geo), created_at and…
posthog_list_insightsList saved insights (charts): id, short_id, name, description, query, tags, favorited, dashboard_tiles, created_by and last_modified_at
posthog_get_insightGet one insight by numeric id or 8-character short_id: name, description, query, result, columns, last_refresh, is_cached, the hogql it ran…
posthog_create_insightSave a new insight (chart) in the project from a query: a product analytics chart or a SQL insight
posthog_update_insightChange a saved insight: name, description, query, tags or favorited
posthog_delete_insightDelete a saved insight (PostHog marks it deleted; it disappears from every dashboard and can be restored in the app)
posthog_list_dashboardsList dashboards: id, name, description, pinned, tags, created_by, created_at and last_viewed_at
posthog_get_dashboardGet one dashboard with its filters and tiles: each tile carries its insight (id, short_id, name, query and the last cached result) or a…
posthog_list_feature_flagsList feature flags: id, key, name (the description), active, filters (release conditions with rollout_percentage, variants, payloads)…
posthog_get_feature_flagGet one feature flag by id: key, name, active, filters (release condition groups with properties and rollout_percentage, multivariate…
posthog_create_feature_flagCreate a feature flag
posthog_update_feature_flagChange a feature flag: switch it on or off, change its rollout or targeting, rename its description, archive it or retag it
posthog_delete_feature_flagDelete a feature flag (PostHog marks it deleted and switches it off; code that checks the key then gets false)
posthog_list_cohortsList cohorts (saved groups of persons): id, name, description, count (persons in it), is_static, is_calculating, filters and created_at
posthog_get_cohortGet one cohort by id: name, description, its definition (filters or query), count of persons, whether it is static or behavioral…
posthog_list_annotationsList annotations (notes on charts such as releases or incidents): id, content, date_marker, scope, the insight or dashboard they belong to…
posthog_get_annotationGet one annotation by id: content, date_marker, scope (project, organization, dashboard or insight), emoji, the insight or dashboard it is…
posthog_create_annotationAdd an annotation, a note shown on charts at a point in time, e.g. a release, a campaign start or an incident
posthog_delete_annotationDelete an annotation (PostHog marks it deleted; it disappears from every chart and can be restored)
posthog_list_experimentsList A/B test experiments: id, name, description, status, start_date, end_date, feature_flag_key, type, conclusion, archived and created_by
posthog_get_experimentGet one experiment by id: status, start and end dates, its feature flag and variants, metrics, parameters, exposure cohort, conclusion and…

示例提示

  • “上周每天有多少独立用户访问了我们的价格页面?他们用的是哪些浏览器?”
  • “过去 30 天里,我们的注册漏斗从浏览价格页面到完成结账的转化率是多少?”
  • “现在哪些功能开关处于开启状态?每个开关的发布比例是多少?”
  • “在我们的主项目中添加一条今天的注释:春季活动已上线。”

FAQ

Gemini CLI 从哪里读取 MCP 服务器? 用户级配置位于 ~/.gemini/settings.json,项目级配置位于项目内的 .gemini/settings.json。gemini mcp list 会列出每个服务器及其连接状态。

下一步

这份指南对你有帮助吗?

你的 PostHog 智能体只差一次点击。

安装连接器,粘贴密钥,向 Gemini 提问。免费试用 7 天,无需信用卡。

相关指南

连接器

如何通过 MCP 将 PostHog 连接到 ChatGPT

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

连接器

如何通过 MCP 将 PostHog 连接到 Claude

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

连接器

如何通过 MCP 将 PostHog 连接到 Cursor

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

连接器

如何通过 MCP 将 PostHog 连接到 Meta Muse

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

连接器

PostHog 接入 MCP:从任意 AI 代理驱动 PostHog

让你的 AI 基于 PostHog 回答产品分析问题:对事件和用户运行只读 SQL(HogQL),计算趋势、漏斗和留存,读取已保存的洞察和看板,查找用户、群组、注释和实验,并管理洞察和功能开关。支持 PostHog Cloud(US 或 EU)或自托管实例,使用个人 API 密钥。

连接器

如何通过 MCP 将 Canva 连接到 Gemini

让你的 AI 在 Canva 中工作:查找和读取设计,创建新设计,将设计导出为 PDF、PNG、PowerPoint 或视频并获取下载链接,整理文件夹,通过链接上传图片,读取品牌模板,并在设计上发表评论。