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