@arvoretech/posthog-mcp

中文文档
1.0.1发布于 2026/05/11MITTypeScriptES Module构建来源已验证近 30 天下载 2435

PostHog MCP Server for analytics, feature flags, experiments, error tracking and more (self-hosted compatible)

原始使用文档
文档目录20 节
  1. Features
  2. Installation
  3. Configuration
  4. Getting your API Key
  5. Usage
  6. Available MCP Tools
  7. Feature Flags
  8. Experiments
  9. Insights & Analytics
  10. Dashboards
  11. Events & Properties
  12. Persons & Cohorts
  13. Annotations
  14. Surveys & Early Access
  15. Organization & Search
  16. HogQL Examples
  17. Programmatic Usage
  18. Claude Desktop / Kiro Integration
  19. Development
  20. Limitations

PostHog MCP Server

A Model Context Protocol (MCP) server for PostHog that provides access to analytics, feature flags, experiments, dashboards, and more. Works with both PostHog Cloud and self-hosted instances.

Features

  • Analytics: Run HogQL queries and structured queries (Trends, Funnels, Retention, Lifecycle, Paths, Stickiness)
  • Feature Flags: Create, update, list, and delete feature flags with rollout control
  • Experiments: List and inspect A/B test experiments with variants and metrics
  • Dashboards & Insights: Create, list, and inspect dashboards and saved insights
  • Events & Properties: Explore event definitions and property definitions
  • Persons & Cohorts: Search users and manage segments
  • Surveys & Early Access: List surveys and early access features
  • Annotations: Create and list chart annotations for deployments and events
  • Search: Search across all PostHog entities
  • Self-Hosted: Direct API connection with static credentials — no OAuth needed
  • TypeScript: Fully typed with Zod validation

Installation

npm install -g @arvoretech/posthog-mcp

Configuration

The server is configured via environment variables:

export POSTHOG_BASE_URL=https://posthog.example.com  # or https://app.posthog.com
export POSTHOG_API_KEY=phx_your_personal_api_key
export POSTHOG_PROJECT_ID=1                           # optional, defaults to 1

Getting your API Key

  1. Go to PostHog → Settings → Personal API Keys
  2. Click "Create personal API key"
  3. Select the scopes you need (or use the "MCP Server" preset if available)
  4. Copy the generated key (starts with phx_)

Usage

# Development
pnpm dev

# Production
node dist/index.js

Available MCP Tools

Feature Flags

ToolDescription
list_feature_flagsList all feature flags with search and pagination
get_feature_flagGet details of a specific flag by ID
create_feature_flagCreate a new flag with optional rollout percentage
update_feature_flagUpdate flag key, name, or active state
delete_feature_flagDelete a feature flag by ID

Experiments

ToolDescription
list_experimentsList all A/B test experiments
get_experimentGet experiment details including variants and metrics

Insights & Analytics

ToolDescription
list_insightsList saved insights (trends, funnels, retention, etc.)
get_insightGet a specific insight by ID
create_insightCreate a new insight and optionally add to dashboards
execute_sqlExecute a HogQL query against PostHog data
execute_queryRun structured queries (TrendsQuery, FunnelsQuery, RetentionQuery, etc.)

Dashboards

ToolDescription
list_dashboardsList all dashboards with optional search
get_dashboardGet dashboard details including its tiles

Events & Properties

ToolDescription
list_event_definitionsList all tracked event types
list_property_definitionsList event or person property definitions

Persons & Cohorts

ToolDescription
list_personsSearch users by email, name, or distinct ID
list_cohortsList all cohorts (user segments)

Annotations

ToolDescription
list_annotationsList all chart annotations
create_annotationCreate a new annotation marker

Surveys & Early Access

ToolDescription
list_surveysList all surveys
list_early_access_featuresList early access features
ToolDescription
list_projectsList all projects for the current API key
searchSearch across all PostHog entities

HogQL Examples

Daily event counts for the last 7 days:

SELECT toDate(timestamp) as day, count() as events
FROM events
WHERE timestamp > now() - INTERVAL 7 DAY
GROUP BY day ORDER BY day

Unique users by browser:

SELECT properties.$browser as browser, uniq(distinct_id) as users
FROM events
WHERE event = 'pageview' AND timestamp > now() - INTERVAL 30 DAY
GROUP BY browser ORDER BY users DESC

Daily active users:

SELECT toDate(timestamp) as day, uniq(distinct_id) as dau
FROM events
WHERE timestamp > now() - INTERVAL 30 DAY
GROUP BY day ORDER BY day

Programmatic Usage

import { PostHogMCPServer } from "@arvoretech/posthog-mcp";

const server = new PostHogMCPServer({
  baseUrl: "https://posthog.example.com",
  apiKey: "phx_your_key",
  projectId: "1",
});

server.setupGracefulShutdown();
await server.start();

Claude Desktop / Kiro Integration

{
  "mcpServers": {
    "posthog": {
      "command": "npx",
      "args": ["-y", "@arvoretech/posthog-mcp"],
      "env": {
        "POSTHOG_BASE_URL": "https://posthog.example.com",
        "POSTHOG_API_KEY": "phx_your_personal_api_key"
      }
    }
  }
}

Development

pnpm install
pnpm dev
pnpm build
pnpm lint

Limitations

  • Stdio transport only (no HTTP/WebSocket)
  • HogQL queries are read-only by design (PostHog API restriction)
  • Requires a Personal API Key (phx_ prefix), not a project API key

版本与发布记录

@arvoretech/posthog-mcp 共发布 2 个版本,首次发布于 2026/04/29;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.1latest2026/05/115 个月前
1.0.02026/04/296 个月前

关于 @arvoretech/posthog-mcp 的常见问题

@arvoretech/posthog-mcp 是什么?

PostHog MCP Server for analytics, feature flags, experiments, error tracking and more (self-hosted compatible)

如何安装 @arvoretech/posthog-mcp?

在项目目录运行 npm install @arvoretech/posthog-mcp,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 posthog-mcp,可以用 npx posthog-mcp 直接运行。

@arvoretech/posthog-mcp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arvoretech/posthog-mcp 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@arvoretech/posthog-mcp 可以商用吗?

@arvoretech/posthog-mcp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@arvoretech/posthog-mcp 的下载量有多少?

根据 npm 官方下载统计,@arvoretech/posthog-mcp 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,435 次,日均约 81 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arvoretech/posthog-mcp 还在维护吗?

最新版本 1.0.1 发布于 2026/05/11(5 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/04/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。