Skip to content

Commit 1791c3d

Browse files
Merge pull request #619 from scalekit-inc/posthog-connector
docs(agent-connectors): add PostHog MCP connector
2 parents dbb462c + cae8b1d commit 1791c3d

4 files changed

Lines changed: 5503 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Tabs, TabItem } from '@astrojs/starlight/components'
2+
3+
Connect a user's PostHog account and interact with PostHog's analytics, feature flags, experiments, and more through Scalekit. Scalekit handles the OAuth flow, token storage, and tool execution automatically.
4+
5+
PostHog MCP is primarily used through Scalekit tools. Use `scalekit_client.actions.execute_tool()` to query analytics, manage feature flags, run experiments, and retrieve insights without calling the upstream MCP server directly.
6+
7+
## Tool calling
8+
9+
Use this connector when you want an agent to work with PostHog data and configuration.
10+
11+
- List and search feature flags with `posthogmcp_feature_flag_get_all`.
12+
- Run trend, funnel, path, or HogQL queries using `posthogmcp_query_run`.
13+
- Create A/B tests via `posthogmcp_experiment_create` with custom metrics and variant splits.
14+
- Retrieve survey response data with `posthogmcp_survey_stats` after creating surveys using `posthogmcp_survey_create`.
15+
- Discover available events with `posthogmcp_event_definitions_list` before building queries or funnels.
16+
17+
<Tabs syncKey="tech-stack">
18+
<TabItem label="Python">
19+
```python title="examples/posthogmcp_list_flags.py"
20+
import os
21+
from scalekit.client import ScalekitClient
22+
23+
scalekit_client = ScalekitClient(
24+
client_id=os.environ["SCALEKIT_CLIENT_ID"],
25+
client_secret=os.environ["SCALEKIT_CLIENT_SECRET"],
26+
env_url=os.environ["SCALEKIT_ENV_URL"],
27+
)
28+
29+
auth_link = scalekit_client.actions.get_authorization_link(
30+
connection_name="posthogmcp",
31+
identifier="user_123",
32+
)
33+
print("Authorize PostHog MCP:", auth_link.link)
34+
input("Press Enter after authorizing...")
35+
36+
connected_account = scalekit_client.actions.get_or_create_connected_account(
37+
connection_name="posthogmcp",
38+
identifier="user_123",
39+
)
40+
41+
tool_response = scalekit_client.actions.execute_tool(
42+
tool_name="posthogmcp_feature_flag_get_all",
43+
connected_account_id=connected_account.connected_account.id,
44+
tool_input={},
45+
)
46+
print("Feature flags:", tool_response)
47+
```
48+
</TabItem>
49+
<TabItem label="Node.js">
50+
```typescript title="examples/posthogmcp_list_flags.ts"
51+
import { ScalekitClient } from '@scalekit-sdk/node';
52+
import 'dotenv/config';
53+
54+
const scalekit = new ScalekitClient(
55+
process.env.SCALEKIT_ENV_URL!,
56+
process.env.SCALEKIT_CLIENT_ID!,
57+
process.env.SCALEKIT_CLIENT_SECRET!
58+
);
59+
const actions = scalekit.actions;
60+
61+
const { link } = await actions.getAuthorizationLink({
62+
connectionName: 'posthogmcp',
63+
identifier: 'user_123',
64+
});
65+
console.log('Authorize PostHog MCP:', link);
66+
process.stdout.write('Press Enter after authorizing...');
67+
await new Promise((resolve) => process.stdin.once('data', resolve));
68+
69+
const connectedAccount = await actions.getOrCreateConnectedAccount({
70+
connectionName: 'posthogmcp',
71+
identifier: 'user_123',
72+
});
73+
74+
const toolResponse = await actions.executeTool({
75+
toolName: 'posthogmcp_feature_flag_get_all',
76+
connectedAccountId: connectedAccount?.id,
77+
toolInput: {},
78+
});
79+
console.log('Feature flags:', toolResponse.data);
80+
```
81+
</TabItem>
82+
</Tabs>

src/components/templates/agent-connectors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export { default as UsageOnedriveSection } from './_usage-onedrive.mdx'
113113
export { default as UsageOnenoteSection } from './_usage-onenote.mdx'
114114
export { default as UsageOutlookSection } from './_usage-outlook.mdx'
115115
export { default as UsageParallelaitaskmcpSection } from './_usage-parallelaitaskmcp.mdx'
116+
export { default as UsagePosthogmcpSection } from './_usage-posthogmcp.mdx'
116117
export { default as UsagePhantombusterSection } from './_usage-phantombuster.mdx'
117118
export { default as UsageSalesforceSection } from './_usage-salesforce.mdx'
118119
export { default as UsageServicenowSection } from './_usage-servicenow.mdx'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: PostHog MCP
3+
description: Connect to PostHog MCP to query analytics, manage feature flags, run experiments, and interact with your product data.
4+
sidebar:
5+
label: PostHog MCP
6+
tableOfContents: true
7+
connectorIcon: https://cdn.scalekit.com/sk-connect/assets/provider-icons/posthog-1.svg
8+
connectorAuthType: OAuth 2.1/DCR
9+
connectorCategories: [analytics, product, feature-flags]
10+
head:
11+
- tag: style
12+
content: |
13+
.sl-markdown-content h2 {
14+
font-size: var(--sl-text-xl);
15+
}
16+
---
17+
18+
import ToolList from '@/components/ToolList.astro'
19+
import { tools } from '@/data/agent-connectors/posthogmcp'
20+
import { UsagePosthogmcpSection } from '@components/templates'
21+
22+
## What you can do
23+
24+
Connect this agent connector to let your agent:
25+
26+
- **Analytics & insights** — Run trend, funnel, path, and HogQL queries; create and retrieve insights and dashboards
27+
- **Feature flags** — Create, update, evaluate, and delete flags; manage multivariate and early-access feature flags
28+
- **Experiments** — Create A/B tests, configure variants and metrics, launch experiments, and retrieve results
29+
- **Surveys** — Create surveys with multiple question types; retrieve response stats and submissions
30+
- **Persons & cohorts** — List and query persons, create and manage cohorts, retrieve person activity
31+
- **Session recordings** — List and retrieve session recordings and playlists
32+
- **Error tracking** — List, merge, resolve, and suppress error tracking issues
33+
- **Events & actions** — List event and property definitions, create and manage actions
34+
- **CDP & data pipelines** — List and manage transformations, destinations, and external data sources
35+
- **Activity & audit** — Retrieve activity logs and audit trails for all resources
36+
37+
## Authentication
38+
39+
This connector uses **OAuth 2.1/DCR with PKCE**. PostHog MCP is an MCP server that issues credentials dynamically via Dynamic Client Registration — Scalekit handles DCR, obtains an access token, and automatically refreshes it before it expires. Your agent code never handles tokens directly — you only pass a `connectionName` and a user `identifier`.
40+
41+
<details>
42+
<summary>Code examples</summary>
43+
44+
<UsagePosthogmcpSection />
45+
46+
</details>
47+
48+
## Tool list
49+
50+
<ToolList tools={tools} />

0 commit comments

Comments
 (0)