@posthog/mcp 0.21.3 → 0.21.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"truncation.d.ts","sourceRoot":"","sources":["../../src/extensions/truncation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAmB,KAAK,EAAc,QAAQ,EAAE,MAAM,UAAU,CAAA;AAG5E,eAAO,MAAM,SAAS,KAAK,CAAA;AAC3B,eAAO,MAAM,WAAW,MAAM,CAAA;AAC9B,eAAO,MAAM,iBAAiB,QAAS,CAAA;AACvC,eAAO,MAAM,eAAe,SAAU,CAAA;AAWtC,eAAO,MAAM,iBAAiB,QAAQ,CAAA;AAKtC;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAkB,EACzB,UAAU,GAAE,MAAoB,EAChC,eAAe,GAAE,MAA0B,GAC1C,OAAO,CAGT;AAqXD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,GAAG,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CA2CrE"}
1
+ {"version":3,"file":"truncation.d.ts","sourceRoot":"","sources":["../../src/extensions/truncation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAmB,KAAK,EAAc,QAAQ,EAAE,MAAM,UAAU,CAAA;AAG5E,eAAO,MAAM,SAAS,KAAK,CAAA;AAC3B,eAAO,MAAM,WAAW,MAAM,CAAA;AAC9B,eAAO,MAAM,iBAAiB,QAAS,CAAA;AACvC,eAAO,MAAM,eAAe,SAAU,CAAA;AAWtC,eAAO,MAAM,iBAAiB,QAAQ,CAAA;AAKtC;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAkB,EACzB,UAAU,GAAE,MAAoB,EAChC,eAAe,GAAE,MAA0B,GAC1C,OAAO,CAGT;AA+XD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,GAAG,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CA2CrE"}
@@ -216,26 +216,38 @@ function setNestedValue(obj, path, value) {
216
216
  const finalKey = path.at(-1);
217
217
  if (void 0 !== finalKey && null != current && 'object' == typeof current) current[finalKey] = value;
218
218
  }
219
+ const REDUCIBLE_FIELDS = [
220
+ 'parameters',
221
+ 'response',
222
+ 'identifyActorData',
223
+ 'error'
224
+ ];
219
225
  function truncateToSize(event) {
220
226
  if (jsonByteSize(event) <= MAX_EVENT_BYTES) return event;
221
- for(let depth = MAX_DEPTH - 1; depth >= 1; depth--){
222
- const reduced = {
223
- ...event
224
- };
225
- if (null != reduced.parameters) reduced.parameters = normalize(reduced.parameters, depth);
226
- if (null != reduced.response) reduced.response = normalize(reduced.response, depth);
227
- if (null != reduced.identifyActorData) reduced.identifyActorData = normalize(reduced.identifyActorData, depth);
228
- if (null != reduced.error) reduced.error = normalize(reduced.error, depth);
227
+ const nesting = Math.max(...REDUCIBLE_FIELDS.map((field)=>nestingDepth(event[field])));
228
+ let atDepthOne;
229
+ for(let depth = nesting - 1; depth >= 1; depth--){
230
+ const reduced = normalizeReducibleFields(event, depth);
229
231
  if (jsonByteSize(reduced) <= MAX_EVENT_BYTES) return reduced;
232
+ if (1 === depth) atDepthOne = reduced;
233
+ }
234
+ return truncateLargestFields(atDepthOne ?? normalizeReducibleFields(event, 1), MAX_EVENT_BYTES);
235
+ }
236
+ function nestingDepth(value, limit = MAX_DEPTH) {
237
+ if (0 === limit || null === value || 'object' != typeof value) return 0;
238
+ let deepest = 0;
239
+ for (const item of Array.isArray(value) ? value : Object.values(value)){
240
+ deepest = Math.max(deepest, nestingDepth(item, limit - 1));
241
+ if (deepest === limit - 1) break;
230
242
  }
231
- const minimal = {
243
+ return deepest + 1;
244
+ }
245
+ function normalizeReducibleFields(event, depth) {
246
+ const reduced = {
232
247
  ...event
233
248
  };
234
- if (null != minimal.parameters) minimal.parameters = normalize(minimal.parameters, 1);
235
- if (null != minimal.response) minimal.response = normalize(minimal.response, 1);
236
- if (null != minimal.identifyActorData) minimal.identifyActorData = normalize(minimal.identifyActorData, 1);
237
- if (null != minimal.error) minimal.error = normalize(minimal.error, 1);
238
- return truncateLargestFields(minimal, MAX_EVENT_BYTES);
249
+ for (const field of REDUCIBLE_FIELDS)if (null != reduced[field]) reduced[field] = normalize(reduced[field], depth);
250
+ return reduced;
239
251
  }
240
252
  function truncateEvent(event) {
241
253
  const result = {
@@ -187,26 +187,38 @@ function setNestedValue(obj, path, value) {
187
187
  const finalKey = path.at(-1);
188
188
  if (void 0 !== finalKey && null != current && 'object' == typeof current) current[finalKey] = value;
189
189
  }
190
+ const REDUCIBLE_FIELDS = [
191
+ 'parameters',
192
+ 'response',
193
+ 'identifyActorData',
194
+ 'error'
195
+ ];
190
196
  function truncateToSize(event) {
191
197
  if (jsonByteSize(event) <= MAX_EVENT_BYTES) return event;
192
- for(let depth = MAX_DEPTH - 1; depth >= 1; depth--){
193
- const reduced = {
194
- ...event
195
- };
196
- if (null != reduced.parameters) reduced.parameters = normalize(reduced.parameters, depth);
197
- if (null != reduced.response) reduced.response = normalize(reduced.response, depth);
198
- if (null != reduced.identifyActorData) reduced.identifyActorData = normalize(reduced.identifyActorData, depth);
199
- if (null != reduced.error) reduced.error = normalize(reduced.error, depth);
198
+ const nesting = Math.max(...REDUCIBLE_FIELDS.map((field)=>nestingDepth(event[field])));
199
+ let atDepthOne;
200
+ for(let depth = nesting - 1; depth >= 1; depth--){
201
+ const reduced = normalizeReducibleFields(event, depth);
200
202
  if (jsonByteSize(reduced) <= MAX_EVENT_BYTES) return reduced;
203
+ if (1 === depth) atDepthOne = reduced;
204
+ }
205
+ return truncateLargestFields(atDepthOne ?? normalizeReducibleFields(event, 1), MAX_EVENT_BYTES);
206
+ }
207
+ function nestingDepth(value, limit = MAX_DEPTH) {
208
+ if (0 === limit || null === value || 'object' != typeof value) return 0;
209
+ let deepest = 0;
210
+ for (const item of Array.isArray(value) ? value : Object.values(value)){
211
+ deepest = Math.max(deepest, nestingDepth(item, limit - 1));
212
+ if (deepest === limit - 1) break;
201
213
  }
202
- const minimal = {
214
+ return deepest + 1;
215
+ }
216
+ function normalizeReducibleFields(event, depth) {
217
+ const reduced = {
203
218
  ...event
204
219
  };
205
- if (null != minimal.parameters) minimal.parameters = normalize(minimal.parameters, 1);
206
- if (null != minimal.response) minimal.response = normalize(minimal.response, 1);
207
- if (null != minimal.identifyActorData) minimal.identifyActorData = normalize(minimal.identifyActorData, 1);
208
- if (null != minimal.error) minimal.error = normalize(minimal.error, 1);
209
- return truncateLargestFields(minimal, MAX_EVENT_BYTES);
220
+ for (const field of REDUCIBLE_FIELDS)if (null != reduced[field]) reduced[field] = normalize(reduced[field], depth);
221
+ return reduced;
210
222
  }
211
223
  function truncateEvent(event) {
212
224
  const result = {
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "0.21.3";
1
+ export declare const version = "0.21.4";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -27,7 +27,7 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- const version = "0.21.3";
30
+ const version = "0.21.4";
31
31
  __webpack_require__.d(__webpack_exports__, {}, {
32
32
  version: version
33
33
  });
package/dist/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- const version = "0.21.3";
1
+ const version = "0.21.4";
2
2
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/mcp",
3
- "version": "0.21.3",
3
+ "version": "0.21.4",
4
4
  "bugs": {
5
5
  "url": "https://github.com/PostHog/posthog-js/issues"
6
6
  },
@@ -53,8 +53,8 @@
53
53
  "zod4": "npm:zod@^4.4.3",
54
54
  "@vitest/coverage-v8": "^1.6.1",
55
55
  "vitest": "^1.6.1",
56
- "@posthog-tooling/tsconfig-base": "1.1.1",
57
- "posthog-node": "^5.55.0"
56
+ "posthog-node": "^5.55.0",
57
+ "@posthog-tooling/tsconfig-base": "1.1.1"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@modelcontextprotocol/sdk": ">=1.26.0",
@@ -366,6 +366,8 @@ function setNestedValue(obj: unknown, path: string[], value: unknown): void {
366
366
  }
367
367
  }
368
368
 
369
+ const REDUCIBLE_FIELDS = ['parameters', 'response', 'identifyActorData', 'error'] as const
370
+
369
371
  /**
370
372
  * Ensures an event fits within MAX_EVENT_BYTES by progressively reducing
371
373
  * normalization depth, then truncating largest string fields as a last resort.
@@ -376,43 +378,51 @@ function truncateToSize(event: MutableEvent): MutableEvent {
376
378
  return event
377
379
  }
378
380
 
379
- // Progressive depth reduction
380
- for (let depth = MAX_DEPTH - 1; depth >= 1; depth--) {
381
- const reduced: MutableEvent = { ...event }
382
- if (reduced.parameters != null) {
383
- reduced.parameters = normalize(reduced.parameters, depth)
384
- }
385
- if (reduced.response != null) {
386
- reduced.response = normalize(reduced.response, depth)
387
- }
388
- if (reduced.identifyActorData != null) {
389
- reduced.identifyActorData = normalize(reduced.identifyActorData, depth) as Event['identifyActorData']
390
- }
391
- if (reduced.error != null) {
392
- reduced.error = normalize(reduced.error, depth) as Event['error']
393
- }
394
-
381
+ // Progressive depth reduction, from the first depth that collapses anything.
382
+ // Any deeper depth leaves the event as it is, and it is already too large.
383
+ const nesting = Math.max(...REDUCIBLE_FIELDS.map((field) => nestingDepth(event[field])))
384
+ let atDepthOne: MutableEvent | undefined
385
+ for (let depth = nesting - 1; depth >= 1; depth--) {
386
+ const reduced = normalizeReducibleFields(event, depth)
395
387
  if (jsonByteSize(reduced) <= MAX_EVENT_BYTES) {
396
388
  return reduced
397
389
  }
390
+ if (depth === 1) {
391
+ atDepthOne = reduced
392
+ }
398
393
  }
399
394
 
400
- // Last resort: truncate largest string fields
401
- const minimal: MutableEvent = { ...event }
402
- if (minimal.parameters != null) {
403
- minimal.parameters = normalize(minimal.parameters, 1)
404
- }
405
- if (minimal.response != null) {
406
- minimal.response = normalize(minimal.response, 1)
407
- }
408
- if (minimal.identifyActorData != null) {
409
- minimal.identifyActorData = normalize(minimal.identifyActorData, 1) as Event['identifyActorData']
410
- }
411
- if (minimal.error != null) {
412
- minimal.error = normalize(minimal.error, 1) as Event['error']
395
+ // Last resort: truncate largest string fields. Reuse the loop's depth-1
396
+ // result when it already computed one, instead of normalizing again.
397
+ return truncateLargestFields(atDepthOne ?? normalizeReducibleFields(event, 1), MAX_EVENT_BYTES)
398
+ }
399
+
400
+ /**
401
+ * The number of object and array levels in `value`, up to `limit`. `normalize`
402
+ * at this depth or deeper collapses nothing.
403
+ */
404
+ function nestingDepth(value: unknown, limit: number = MAX_DEPTH): number {
405
+ if (limit === 0 || value === null || typeof value !== 'object') {
406
+ return 0
407
+ }
408
+ let deepest = 0
409
+ for (const item of Array.isArray(value) ? value : Object.values(value)) {
410
+ deepest = Math.max(deepest, nestingDepth(item, limit - 1))
411
+ if (deepest === limit - 1) {
412
+ break
413
+ }
413
414
  }
415
+ return deepest + 1
416
+ }
414
417
 
415
- return truncateLargestFields(minimal, MAX_EVENT_BYTES)
418
+ function normalizeReducibleFields(event: MutableEvent, depth: number): MutableEvent {
419
+ const reduced: MutableEvent = { ...event }
420
+ for (const field of REDUCIBLE_FIELDS) {
421
+ if (reduced[field] != null) {
422
+ ;(reduced as MutableRecord)[field] = normalize(reduced[field], depth)
423
+ }
424
+ }
425
+ return reduced
416
426
  }
417
427
 
418
428
  /**
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "0.21.3"
1
+ export const version = "0.21.4"