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