@arvoretech/posthog-mcp 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +1 -1
- package/dist/index.js.map +1 -0
- package/dist/posthog-client.d.ts +105 -0
- package/dist/posthog-client.d.ts.map +1 -0
- package/dist/posthog-client.js +211 -0
- package/dist/posthog-client.js.map +1 -0
- package/dist/server.d.ts +11 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +488 -0
- package/dist/server.js.map +1 -0
- package/package.json +14 -10
- package/LICENSE +0 -21
- package/src/posthog-client.ts +0 -356
- package/src/server.ts +0 -608
- package/tsconfig.json +0 -9
package/src/posthog-client.ts
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
export interface PostHogConfig {
|
|
2
|
-
baseUrl: string;
|
|
3
|
-
apiKey: string;
|
|
4
|
-
projectId?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class PostHogClient {
|
|
8
|
-
private baseUrl: string;
|
|
9
|
-
private apiKey: string;
|
|
10
|
-
private projectId: string;
|
|
11
|
-
|
|
12
|
-
constructor(config: PostHogConfig) {
|
|
13
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
14
|
-
this.apiKey = config.apiKey;
|
|
15
|
-
this.projectId = config.projectId || "1";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private async request<T>(
|
|
19
|
-
method: string,
|
|
20
|
-
path: string,
|
|
21
|
-
body?: unknown
|
|
22
|
-
): Promise<T> {
|
|
23
|
-
const url = `${this.baseUrl}${path}`;
|
|
24
|
-
const headers: Record<string, string> = {
|
|
25
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
26
|
-
"Content-Type": "application/json",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const response = await fetch(url, {
|
|
30
|
-
method,
|
|
31
|
-
headers,
|
|
32
|
-
...(body ? { body: JSON.stringify(body) } : {}),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
const errorText = await response.text();
|
|
37
|
-
throw new Error(
|
|
38
|
-
`PostHog API error: ${response.status} ${response.statusText} - ${errorText}`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const text = await response.text();
|
|
43
|
-
if (!text) return {} as T;
|
|
44
|
-
return JSON.parse(text) as T;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async testConnection(): Promise<boolean> {
|
|
48
|
-
try {
|
|
49
|
-
await this.request("GET", "/api/projects/");
|
|
50
|
-
return true;
|
|
51
|
-
} catch {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async listProjects(): Promise<unknown> {
|
|
57
|
-
return this.request("GET", "/api/projects/");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async getProject(projectId?: string): Promise<unknown> {
|
|
61
|
-
return this.request("GET", `/api/projects/${projectId || this.projectId}/`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async listFeatureFlags(params?: {
|
|
65
|
-
limit?: number;
|
|
66
|
-
offset?: number;
|
|
67
|
-
search?: string;
|
|
68
|
-
}): Promise<unknown> {
|
|
69
|
-
const qs = new URLSearchParams();
|
|
70
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
71
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
72
|
-
if (params?.search) qs.set("search", params.search);
|
|
73
|
-
const query = qs.toString();
|
|
74
|
-
return this.request(
|
|
75
|
-
"GET",
|
|
76
|
-
`/api/projects/${this.projectId}/feature_flags/${query ? `?${query}` : ""}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async getFeatureFlag(id: number): Promise<unknown> {
|
|
81
|
-
return this.request(
|
|
82
|
-
"GET",
|
|
83
|
-
`/api/projects/${this.projectId}/feature_flags/${id}/`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async createFeatureFlag(data: {
|
|
88
|
-
key: string;
|
|
89
|
-
name?: string;
|
|
90
|
-
active?: boolean;
|
|
91
|
-
filters?: unknown;
|
|
92
|
-
rollout_percentage?: number;
|
|
93
|
-
}): Promise<unknown> {
|
|
94
|
-
return this.request(
|
|
95
|
-
"POST",
|
|
96
|
-
`/api/projects/${this.projectId}/feature_flags/`,
|
|
97
|
-
data
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async updateFeatureFlag(
|
|
102
|
-
id: number,
|
|
103
|
-
data: {
|
|
104
|
-
key?: string;
|
|
105
|
-
name?: string;
|
|
106
|
-
active?: boolean;
|
|
107
|
-
filters?: unknown;
|
|
108
|
-
rollout_percentage?: number;
|
|
109
|
-
}
|
|
110
|
-
): Promise<unknown> {
|
|
111
|
-
return this.request(
|
|
112
|
-
"PATCH",
|
|
113
|
-
`/api/projects/${this.projectId}/feature_flags/${id}/`,
|
|
114
|
-
data
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async deleteFeatureFlag(id: number): Promise<unknown> {
|
|
119
|
-
return this.request(
|
|
120
|
-
"DELETE",
|
|
121
|
-
`/api/projects/${this.projectId}/feature_flags/${id}/`
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async listExperiments(params?: {
|
|
126
|
-
limit?: number;
|
|
127
|
-
offset?: number;
|
|
128
|
-
}): Promise<unknown> {
|
|
129
|
-
const qs = new URLSearchParams();
|
|
130
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
131
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
132
|
-
const query = qs.toString();
|
|
133
|
-
return this.request(
|
|
134
|
-
"GET",
|
|
135
|
-
`/api/projects/${this.projectId}/experiments/${query ? `?${query}` : ""}`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async getExperiment(id: number): Promise<unknown> {
|
|
140
|
-
return this.request(
|
|
141
|
-
"GET",
|
|
142
|
-
`/api/projects/${this.projectId}/experiments/${id}/`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async listInsights(params?: {
|
|
147
|
-
limit?: number;
|
|
148
|
-
offset?: number;
|
|
149
|
-
search?: string;
|
|
150
|
-
}): Promise<unknown> {
|
|
151
|
-
const qs = new URLSearchParams();
|
|
152
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
153
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
154
|
-
if (params?.search) qs.set("search", params.search);
|
|
155
|
-
const query = qs.toString();
|
|
156
|
-
return this.request(
|
|
157
|
-
"GET",
|
|
158
|
-
`/api/projects/${this.projectId}/insights/${query ? `?${query}` : ""}`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async getInsight(id: number): Promise<unknown> {
|
|
163
|
-
return this.request(
|
|
164
|
-
"GET",
|
|
165
|
-
`/api/projects/${this.projectId}/insights/${id}/`
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async listDashboards(params?: {
|
|
170
|
-
limit?: number;
|
|
171
|
-
offset?: number;
|
|
172
|
-
search?: string;
|
|
173
|
-
}): Promise<unknown> {
|
|
174
|
-
const qs = new URLSearchParams();
|
|
175
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
176
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
177
|
-
if (params?.search) qs.set("search", params.search);
|
|
178
|
-
const query = qs.toString();
|
|
179
|
-
return this.request(
|
|
180
|
-
"GET",
|
|
181
|
-
`/api/projects/${this.projectId}/dashboards/${query ? `?${query}` : ""}`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async getDashboard(id: number): Promise<unknown> {
|
|
186
|
-
return this.request(
|
|
187
|
-
"GET",
|
|
188
|
-
`/api/projects/${this.projectId}/dashboards/${id}/`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async executeQuery(query: unknown): Promise<unknown> {
|
|
193
|
-
return this.request(
|
|
194
|
-
"POST",
|
|
195
|
-
`/api/projects/${this.projectId}/query/`,
|
|
196
|
-
{ query }
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
async executeSql(sql: string): Promise<unknown> {
|
|
201
|
-
return this.executeQuery({
|
|
202
|
-
kind: "HogQLQuery",
|
|
203
|
-
query: sql,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async listEventDefinitions(params?: {
|
|
208
|
-
limit?: number;
|
|
209
|
-
offset?: number;
|
|
210
|
-
search?: string;
|
|
211
|
-
}): Promise<unknown> {
|
|
212
|
-
const qs = new URLSearchParams();
|
|
213
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
214
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
215
|
-
if (params?.search) qs.set("search", params.search);
|
|
216
|
-
const query = qs.toString();
|
|
217
|
-
return this.request(
|
|
218
|
-
"GET",
|
|
219
|
-
`/api/projects/${this.projectId}/event_definitions/${query ? `?${query}` : ""}`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async listPropertyDefinitions(params?: {
|
|
224
|
-
limit?: number;
|
|
225
|
-
offset?: number;
|
|
226
|
-
type?: "event" | "person";
|
|
227
|
-
search?: string;
|
|
228
|
-
}): Promise<unknown> {
|
|
229
|
-
const qs = new URLSearchParams();
|
|
230
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
231
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
232
|
-
if (params?.type) qs.set("type", params.type);
|
|
233
|
-
if (params?.search) qs.set("search", params.search);
|
|
234
|
-
const query = qs.toString();
|
|
235
|
-
return this.request(
|
|
236
|
-
"GET",
|
|
237
|
-
`/api/projects/${this.projectId}/property_definitions/${query ? `?${query}` : ""}`
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
async listCohorts(params?: {
|
|
242
|
-
limit?: number;
|
|
243
|
-
offset?: number;
|
|
244
|
-
}): Promise<unknown> {
|
|
245
|
-
const qs = new URLSearchParams();
|
|
246
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
247
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
248
|
-
const query = qs.toString();
|
|
249
|
-
return this.request(
|
|
250
|
-
"GET",
|
|
251
|
-
`/api/projects/${this.projectId}/cohorts/${query ? `?${query}` : ""}`
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async listAnnotations(params?: {
|
|
256
|
-
limit?: number;
|
|
257
|
-
offset?: number;
|
|
258
|
-
}): Promise<unknown> {
|
|
259
|
-
const qs = new URLSearchParams();
|
|
260
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
261
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
262
|
-
const query = qs.toString();
|
|
263
|
-
return this.request(
|
|
264
|
-
"GET",
|
|
265
|
-
`/api/projects/${this.projectId}/annotations/${query ? `?${query}` : ""}`
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
async createAnnotation(data: {
|
|
270
|
-
content: string;
|
|
271
|
-
date_marker: string;
|
|
272
|
-
scope?: "project" | "organization";
|
|
273
|
-
}): Promise<unknown> {
|
|
274
|
-
return this.request(
|
|
275
|
-
"POST",
|
|
276
|
-
`/api/projects/${this.projectId}/annotations/`,
|
|
277
|
-
data
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
async listPersons(params?: {
|
|
282
|
-
limit?: number;
|
|
283
|
-
offset?: number;
|
|
284
|
-
search?: string;
|
|
285
|
-
distinct_id?: string;
|
|
286
|
-
}): Promise<unknown> {
|
|
287
|
-
const qs = new URLSearchParams();
|
|
288
|
-
if (params?.limit) qs.set("limit", String(params.limit));
|
|
289
|
-
if (params?.offset) qs.set("offset", String(params.offset));
|
|
290
|
-
if (params?.search) qs.set("search", params.search);
|
|
291
|
-
if (params?.distinct_id) qs.set("distinct_id", params.distinct_id);
|
|
292
|
-
const query = qs.toString();
|
|
293
|
-
return this.request(
|
|
294
|
-
"GET",
|
|
295
|
-
`/api/projects/${this.projectId}/persons/${query ? `?${query}` : ""}`
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async listSurveys(): Promise<unknown> {
|
|
300
|
-
return this.request(
|
|
301
|
-
"GET",
|
|
302
|
-
`/api/projects/${this.projectId}/surveys/`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
async listEarlyAccessFeatures(): Promise<unknown> {
|
|
307
|
-
return this.request(
|
|
308
|
-
"GET",
|
|
309
|
-
`/api/projects/${this.projectId}/early_access_feature/`
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
async createInsight(data: {
|
|
314
|
-
name: string;
|
|
315
|
-
description?: string;
|
|
316
|
-
query?: unknown;
|
|
317
|
-
dashboards?: number[];
|
|
318
|
-
saved?: boolean;
|
|
319
|
-
}): Promise<unknown> {
|
|
320
|
-
return this.request(
|
|
321
|
-
"POST",
|
|
322
|
-
`/api/projects/${this.projectId}/insights/`,
|
|
323
|
-
data
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async updateDashboard(
|
|
328
|
-
id: number,
|
|
329
|
-
data: {
|
|
330
|
-
name?: string;
|
|
331
|
-
description?: string;
|
|
332
|
-
pinned?: boolean;
|
|
333
|
-
tags?: string[];
|
|
334
|
-
}
|
|
335
|
-
): Promise<unknown> {
|
|
336
|
-
return this.request(
|
|
337
|
-
"PATCH",
|
|
338
|
-
`/api/projects/${this.projectId}/dashboards/${id}/`,
|
|
339
|
-
data
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async search(query: string, entities?: string[]): Promise<unknown> {
|
|
344
|
-
const qs = new URLSearchParams();
|
|
345
|
-
qs.set("q", query);
|
|
346
|
-
if (entities) {
|
|
347
|
-
for (const entity of entities) {
|
|
348
|
-
qs.append("entities", entity);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return this.request(
|
|
352
|
-
"GET",
|
|
353
|
-
`/api/projects/${this.projectId}/search/?${qs.toString()}`
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
}
|