@posthog/mcp 0.0.4 → 0.0.6

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/dist/index.d.cts CHANGED
@@ -105,6 +105,7 @@ declare const PostHogMCPAnalyticsProperty: {
105
105
  readonly ServerVersion: "$mcp_server_version";
106
106
  readonly SessionId: "$session_id";
107
107
  readonly Source: "$mcp_source";
108
+ readonly ToolDescription: "$mcp_tool_description";
108
109
  readonly ToolName: "$mcp_tool_name";
109
110
  };
110
111
  type PostHogMCPAnalyticsProperty = (typeof PostHogMCPAnalyticsProperty)[keyof typeof PostHogMCPAnalyticsProperty];
package/dist/index.d.mts CHANGED
@@ -104,6 +104,7 @@ declare const PostHogMCPAnalyticsProperty: {
104
104
  readonly ServerVersion: "$mcp_server_version";
105
105
  readonly SessionId: "$session_id";
106
106
  readonly Source: "$mcp_source";
107
+ readonly ToolDescription: "$mcp_tool_description";
107
108
  readonly ToolName: "$mcp_tool_name";
108
109
  };
109
110
  type PostHogMCPAnalyticsProperty = (typeof PostHogMCPAnalyticsProperty)[keyof typeof PostHogMCPAnalyticsProperty];
package/dist/index.mjs CHANGED
@@ -388,6 +388,7 @@ const PostHogMCPAnalyticsProperty = {
388
388
  ServerVersion: "$mcp_server_version",
389
389
  SessionId: "$session_id",
390
390
  Source: "$mcp_source",
391
+ ToolDescription: "$mcp_tool_description",
391
392
  ToolName: "$mcp_tool_name"
392
393
  };
393
394
  //#endregion
@@ -456,6 +457,7 @@ function addCommonEventProperties(event, properties) {
456
457
  properties[PostHogMCPAnalyticsProperty.ResourceName] = event.resourceName;
457
458
  if (event.eventType === MCPAnalyticsEventType.mcpToolsCall) properties[PostHogMCPAnalyticsProperty.ToolName] = event.resourceName;
458
459
  }
460
+ if (event.toolDescription && event.eventType === MCPAnalyticsEventType.mcpToolsCall) properties[PostHogMCPAnalyticsProperty.ToolDescription] = event.toolDescription;
459
461
  if (event.duration !== void 0) properties[PostHogMCPAnalyticsProperty.DurationMs] = event.duration;
460
462
  if (event.serverName) properties[PostHogMCPAnalyticsProperty.ServerName] = event.serverName;
461
463
  if (event.serverVersion) properties[PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
@@ -492,10 +494,12 @@ function buildExceptionEvent(event) {
492
494
  properties[PostHogMCPAnalyticsProperty.ResourceName] = event.resourceName;
493
495
  if (event.eventType === MCPAnalyticsEventType.mcpToolsCall) properties[PostHogMCPAnalyticsProperty.ToolName] = event.resourceName;
494
496
  }
497
+ if (event.toolDescription && event.eventType === MCPAnalyticsEventType.mcpToolsCall) properties[PostHogMCPAnalyticsProperty.ToolDescription] = event.toolDescription;
495
498
  if (event.serverName) properties[PostHogMCPAnalyticsProperty.ServerName] = event.serverName;
496
499
  if (event.serverVersion) properties[PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
497
500
  if (event.clientName) properties[PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
498
501
  if (event.clientVersion) properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
502
+ addCustomEventProperties(event, properties);
499
503
  return {
500
504
  event: PostHogMCPAnalyticsEvent.Exception,
501
505
  distinct_id: distinctId,
@@ -551,6 +555,7 @@ const PROTECTED_FIELDS = new Set([
551
555
  "identifyActorName",
552
556
  "identifyData",
553
557
  "resourceName",
558
+ "toolDescription",
554
559
  "eventType",
555
560
  "actorId",
556
561
  "tags",
@@ -728,7 +733,7 @@ function sanitizeParameters(obj) {
728
733
  }
729
734
  //#endregion
730
735
  //#region package.json
731
- var version = "0.0.4";
736
+ var version = "0.0.6";
732
737
  //#endregion
733
738
  //#region src/modules/session.ts
734
739
  function newSessionId() {
@@ -1188,6 +1193,7 @@ function publishEvent(server, eventInput) {
1188
1193
  identifyActorName: sessionInfo.identifyActorName,
1189
1194
  identifyActorData: sessionInfo.identifyActorData,
1190
1195
  resourceName: eventInput.resourceName,
1196
+ toolDescription: eventInput.toolDescription,
1191
1197
  parameters: eventInput.parameters,
1192
1198
  response: eventInput.response,
1193
1199
  userIntent: eventInput.userIntent,
@@ -2136,6 +2142,7 @@ async function getTracedToolsList(server, originalListToolsHandler, request, ext
2136
2142
  if (data?.options.reportMissing) {
2137
2143
  if (!tools.some((tool) => tool?.name === "get_more_tools")) tools.push(getReportMissingToolDescriptor());
2138
2144
  }
2145
+ if (data) cacheToolDescriptions(data.toolDescriptions, tools);
2139
2146
  return tools;
2140
2147
  } catch (error) {
2141
2148
  writeToLog(`Warning: Original list tools handler failed, this suggests an error PostHog MCP analytics did not cause - ${error}`);
@@ -2219,13 +2226,15 @@ async function handleToolCallRequest(server, originalCallToolHandler, request, e
2219
2226
  }
2220
2227
  const conversation = resolveConversationId(data.options.enableConversationId ?? false, request.params?.arguments, request.params?.name);
2221
2228
  const downstreamRequest = conversation.conversationId ? cloneRequestWithoutConversationId(request) : request;
2229
+ const toolName = request.params?.name;
2222
2230
  const event = {
2223
2231
  sessionId: getServerSessionId(server, extra),
2224
2232
  conversationId: conversation.conversationId,
2225
- resourceName: request.params?.name || "Unknown Tool Name",
2233
+ resourceName: toolName || "Unknown Tool Name",
2226
2234
  parameters: buildCapturedMcpParameters(downstreamRequest),
2227
2235
  eventType: MCPAnalyticsEventType.mcpToolsCall,
2228
2236
  timestamp: /* @__PURE__ */ new Date(),
2237
+ toolDescription: toolName ? data.toolDescriptions.get(toolName) : void 0,
2229
2238
  redactionFn: data.options.redactSensitiveInformation
2230
2239
  };
2231
2240
  try {
@@ -2279,6 +2288,10 @@ function getContextArgument$1(request) {
2279
2288
  function getEventDuration(event) {
2280
2289
  return event.timestamp ? Date.now() - event.timestamp.getTime() : 0;
2281
2290
  }
2291
+ function cacheToolDescriptions(cache, tools) {
2292
+ if (!tools) return;
2293
+ for (const tool of tools) if (tool?.name && typeof tool.description === "string") cache.set(tool.name, tool.description);
2294
+ }
2282
2295
  //#endregion
2283
2296
  //#region src/modules/mcp-sdk-compat.ts
2284
2297
  /**
@@ -2366,7 +2379,8 @@ function addTracingToToolRegistry(tools, server) {
2366
2379
  }
2367
2380
  function setupListenerToRegisteredTools(server) {
2368
2381
  try {
2369
- if (!getServerTrackingData(server.server)) {
2382
+ const data = getServerTrackingData(server.server);
2383
+ if (!data) {
2370
2384
  writeToLog("Warning: Cannot setup listener - no tracking data found");
2371
2385
  return;
2372
2386
  }
@@ -2374,6 +2388,7 @@ function setupListenerToRegisteredTools(server) {
2374
2388
  set(target, property, value) {
2375
2389
  try {
2376
2390
  if (typeof property === "string" && value && typeof value === "object" && hasToolFunction(value)) {
2391
+ if (typeof value.description === "string") data.toolDescriptions.set(property, value.description);
2377
2392
  if (value[MCP_ANALYTICS_PROCESSED]) {
2378
2393
  writeToLog(`Tool ${String(property)} already processed, skipping proxy wrapping`);
2379
2394
  return Reflect.set(target, property, value);
@@ -2496,13 +2511,15 @@ async function initializeToolCallEvent(server, request, downstreamRequest, extra
2496
2511
  shouldPublishEvent: false
2497
2512
  };
2498
2513
  }
2514
+ const toolName = request.params?.name;
2499
2515
  const event = {
2500
2516
  sessionId: getServerSessionId(server, extra),
2501
2517
  conversationId: conversation.conversationId,
2502
- resourceName: request.params?.name || "Unknown Tool",
2518
+ resourceName: toolName || "Unknown Tool",
2503
2519
  parameters: buildCapturedMcpParameters(downstreamRequest),
2504
2520
  eventType: MCPAnalyticsEventType.mcpToolsCall,
2505
2521
  timestamp: startTime,
2522
+ toolDescription: toolName ? data.toolDescriptions.get(toolName) : void 0,
2506
2523
  redactionFn: data.options.redactSensitiveInformation
2507
2524
  };
2508
2525
  await handleIdentify(server, data, request, extra);
@@ -2592,16 +2609,20 @@ function publishFailedToolEvent(server, tracing, error, startTime) {
2592
2609
  }
2593
2610
  function setupTracking(server) {
2594
2611
  try {
2595
- getServerTrackingData(server.server);
2612
+ const mcpAnalyticsData = getServerTrackingData(server.server);
2596
2613
  setupToolsCallHandlerWrapping(server);
2597
2614
  setupInitializeTracing(server);
2598
2615
  server._registeredTools = addTracingToToolRegistry(server._registeredTools, server);
2616
+ if (mcpAnalyticsData) seedToolDescriptionsFromRegistry(mcpAnalyticsData.toolDescriptions, server._registeredTools);
2599
2617
  setupListToolsTracing(server);
2600
2618
  setupListenerToRegisteredTools(server);
2601
2619
  } catch (error) {
2602
2620
  writeToLog(`Warning: Failed to setup tool call tracing - ${error}`);
2603
2621
  }
2604
2622
  }
2623
+ function seedToolDescriptionsFromRegistry(cache, tools) {
2624
+ for (const [name, tool] of Object.entries(tools)) if (typeof tool?.description === "string") cache.set(name, tool.description);
2625
+ }
2605
2626
  //#endregion
2606
2627
  //#region src/index.ts
2607
2628
  /**
@@ -2737,6 +2758,7 @@ function buildTrackingData(lowLevelServer, options) {
2737
2758
  sessionId: newSessionId(),
2738
2759
  lastActivity: /* @__PURE__ */ new Date(),
2739
2760
  identifiedSessions: /* @__PURE__ */ new Map(),
2761
+ toolDescriptions: /* @__PURE__ */ new Map(),
2740
2762
  sessionInfo: getSessionInfo(lowLevelServer, void 0),
2741
2763
  options: {
2742
2764
  reportMissing: options.reportMissing ?? false,