@posthog/mcp 0.0.4 → 0.0.5

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