@posthog/mcp 0.0.2 → 0.0.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.
- package/README.md +61 -0
- package/dist/index.cjs +261 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -1
- package/dist/index.d.mts +23 -1
- package/dist/index.mjs +260 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -23,11 +23,13 @@ interface MCPAnalyticsOptions {
|
|
|
23
23
|
apiKey?: string | null;
|
|
24
24
|
context?: boolean | MCPAnalyticsContextOptions;
|
|
25
25
|
enableAITracing?: boolean;
|
|
26
|
+
enableConversationId?: boolean;
|
|
26
27
|
enableTracing?: boolean;
|
|
27
28
|
eventProperties?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => JsonRecord | null | Promise<JsonRecord | null>;
|
|
28
29
|
eventTags?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => Record<string, string> | null | Promise<Record<string, string> | null>;
|
|
29
30
|
host?: string;
|
|
30
31
|
identify?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => Promise<UserIdentity | null>;
|
|
32
|
+
intentFallback?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => MaybePromise<string | null | undefined>;
|
|
31
33
|
posthogClient?: PostHogCaptureClient;
|
|
32
34
|
posthogOptions?: Pick<PostHogOptions, "fetch" | "flushAt" | "flushInterval" | "host" | "requestTimeout" | "waitUntil" | "waitUntilDebounceMs" | "waitUntilMaxWaitMs">;
|
|
33
35
|
redactSensitiveInformation?: RedactFunction;
|
|
@@ -36,6 +38,8 @@ interface MCPAnalyticsOptions {
|
|
|
36
38
|
interface MCPAnalyticsContextOptions {
|
|
37
39
|
description?: string;
|
|
38
40
|
}
|
|
41
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
42
|
+
type MCPAnalyticsIntentSource = "context_parameter" | "inferred";
|
|
39
43
|
type RedactFunction = (text: string) => Promise<string>;
|
|
40
44
|
interface CompatibleRequestHandlerExtra {
|
|
41
45
|
headers?: Record<string, string | string[]>;
|
|
@@ -62,6 +66,21 @@ interface CustomEventData {
|
|
|
62
66
|
}
|
|
63
67
|
//#endregion
|
|
64
68
|
//#region src/modules/constants.d.ts
|
|
69
|
+
declare const POSTHOG_MCP_ANALYTICS_SOURCE = "posthog_mcp_analytics";
|
|
70
|
+
declare const PostHogMCPAnalyticsEvent: {
|
|
71
|
+
readonly AiSpan: "$ai_span";
|
|
72
|
+
readonly Custom: "mcp_custom";
|
|
73
|
+
readonly Exception: "$exception";
|
|
74
|
+
readonly Identify: "$identify";
|
|
75
|
+
readonly Initialize: "mcp_initialize";
|
|
76
|
+
readonly PromptGet: "mcp_prompt_get";
|
|
77
|
+
readonly PromptsList: "mcp_prompts_list";
|
|
78
|
+
readonly ResourceRead: "mcp_resource_read";
|
|
79
|
+
readonly ResourcesList: "mcp_resources_list";
|
|
80
|
+
readonly ToolCall: "mcp_tool_call";
|
|
81
|
+
readonly ToolsList: "mcp_tools_list";
|
|
82
|
+
};
|
|
83
|
+
type PostHogMCPAnalyticsEvent = (typeof PostHogMCPAnalyticsEvent)[keyof typeof PostHogMCPAnalyticsEvent];
|
|
65
84
|
declare const PostHogMCPAnalyticsProperty: {
|
|
66
85
|
readonly AiInputState: "$ai_input_state";
|
|
67
86
|
readonly AiIsError: "$ai_is_error";
|
|
@@ -74,9 +93,11 @@ declare const PostHogMCPAnalyticsProperty: {
|
|
|
74
93
|
readonly AiTraceId: "$ai_trace_id";
|
|
75
94
|
readonly ClientName: "$mcp_client_name";
|
|
76
95
|
readonly ClientVersion: "$mcp_client_version";
|
|
96
|
+
readonly ConversationId: "$mcp_conversation_id";
|
|
77
97
|
readonly DurationMs: "$mcp_duration_ms";
|
|
78
98
|
readonly IsError: "$mcp_is_error";
|
|
79
99
|
readonly Intent: "$mcp_intent";
|
|
100
|
+
readonly IntentSource: "$mcp_intent_source";
|
|
80
101
|
readonly Parameters: "$mcp_parameters";
|
|
81
102
|
readonly ResourceName: "$mcp_resource_name";
|
|
82
103
|
readonly Response: "$mcp_response";
|
|
@@ -100,6 +121,7 @@ type PostHogMCPAnalyticsProperty = (typeof PostHogMCPAnalyticsProperty)[keyof ty
|
|
|
100
121
|
* @param options.enableAITracing - Emits `$ai_span` events for tool calls so MCP activity appears in PostHog LLM analytics. Defaults to false.
|
|
101
122
|
* @param options.enableTracing - Enables tracking of tool calls and usage patterns.
|
|
102
123
|
* @param options.context - Enables the required "context" parameter on tools to capture user intent. Pass false to disable, or an object with a custom description.
|
|
124
|
+
* @param options.intentFallback - Optional consumer-supplied callback invoked when a tool call has no explicit `context` argument. Return a short user intent string to capture as `$mcp_intent` (with `$mcp_intent_source = "inferred"`). The SDK does not infer anything on its own — this is purely a slot for your own derivation logic (e.g. a switch on `request.params.name`, an LLM call, etc.). Runs on the hot path of every uncontextualized tool call.
|
|
103
125
|
* @param options.identify - Async function to identify users and attach custom data to their sessions.
|
|
104
126
|
* @param options.redactSensitiveInformation - Function to redact sensitive data before sending to PostHog.
|
|
105
127
|
* @param options.eventTags - Callback invoked on every auto-captured event (tool calls, tool lists, initialize) to attach string key-value tags. Tags are intended to be indexed and queryable in PostHog — use them for structured metadata you'll want to filter or group by (e.g., trace IDs, environments, regions). Tags are validated client-side: keys must be ≤32 chars matching `[a-zA-Z0-9$_.:\- ]`, values must be strings ≤200 chars with no newlines, max 50 entries per event. Invalid entries are silently dropped with a warning logged to `~/posthog-mcp-analytics.log`. If the callback throws or returns null, tags are omitted. Receives the same `(request, extra)` arguments as `identify`.
|
|
@@ -236,5 +258,5 @@ declare function track<TServer>(server: TServer, options?: MCPAnalyticsOptions):
|
|
|
236
258
|
declare function publishCustomEvent(serverOrSessionId: unknown, eventData?: CustomEventData): Promise<void>;
|
|
237
259
|
type IdentifyFunction = MCPAnalyticsOptions["identify"];
|
|
238
260
|
//#endregion
|
|
239
|
-
export { type CustomEventData, IdentifyFunction, type MCPAnalyticsContextOptions, type MCPAnalyticsOptions, PostHogMCPAnalyticsProperty, type RedactFunction, type UserIdentity, publishCustomEvent, track };
|
|
261
|
+
export { type CustomEventData, IdentifyFunction, type MCPAnalyticsContextOptions, type MCPAnalyticsIntentSource, type MCPAnalyticsOptions, POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty, type RedactFunction, type UserIdentity, publishCustomEvent, track };
|
|
240
262
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -22,11 +22,13 @@ interface MCPAnalyticsOptions {
|
|
|
22
22
|
apiKey?: string | null;
|
|
23
23
|
context?: boolean | MCPAnalyticsContextOptions;
|
|
24
24
|
enableAITracing?: boolean;
|
|
25
|
+
enableConversationId?: boolean;
|
|
25
26
|
enableTracing?: boolean;
|
|
26
27
|
eventProperties?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => JsonRecord | null | Promise<JsonRecord | null>;
|
|
27
28
|
eventTags?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => Record<string, string> | null | Promise<Record<string, string> | null>;
|
|
28
29
|
host?: string;
|
|
29
30
|
identify?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => Promise<UserIdentity | null>;
|
|
31
|
+
intentFallback?: (request: MCPRequestLike, extra?: CompatibleRequestHandlerExtra) => MaybePromise<string | null | undefined>;
|
|
30
32
|
posthogClient?: PostHogCaptureClient;
|
|
31
33
|
posthogOptions?: Pick<PostHogOptions, "fetch" | "flushAt" | "flushInterval" | "host" | "requestTimeout" | "waitUntil" | "waitUntilDebounceMs" | "waitUntilMaxWaitMs">;
|
|
32
34
|
redactSensitiveInformation?: RedactFunction;
|
|
@@ -35,6 +37,8 @@ interface MCPAnalyticsOptions {
|
|
|
35
37
|
interface MCPAnalyticsContextOptions {
|
|
36
38
|
description?: string;
|
|
37
39
|
}
|
|
40
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
41
|
+
type MCPAnalyticsIntentSource = "context_parameter" | "inferred";
|
|
38
42
|
type RedactFunction = (text: string) => Promise<string>;
|
|
39
43
|
interface CompatibleRequestHandlerExtra {
|
|
40
44
|
headers?: Record<string, string | string[]>;
|
|
@@ -61,6 +65,21 @@ interface CustomEventData {
|
|
|
61
65
|
}
|
|
62
66
|
//#endregion
|
|
63
67
|
//#region src/modules/constants.d.ts
|
|
68
|
+
declare const POSTHOG_MCP_ANALYTICS_SOURCE = "posthog_mcp_analytics";
|
|
69
|
+
declare const PostHogMCPAnalyticsEvent: {
|
|
70
|
+
readonly AiSpan: "$ai_span";
|
|
71
|
+
readonly Custom: "mcp_custom";
|
|
72
|
+
readonly Exception: "$exception";
|
|
73
|
+
readonly Identify: "$identify";
|
|
74
|
+
readonly Initialize: "mcp_initialize";
|
|
75
|
+
readonly PromptGet: "mcp_prompt_get";
|
|
76
|
+
readonly PromptsList: "mcp_prompts_list";
|
|
77
|
+
readonly ResourceRead: "mcp_resource_read";
|
|
78
|
+
readonly ResourcesList: "mcp_resources_list";
|
|
79
|
+
readonly ToolCall: "mcp_tool_call";
|
|
80
|
+
readonly ToolsList: "mcp_tools_list";
|
|
81
|
+
};
|
|
82
|
+
type PostHogMCPAnalyticsEvent = (typeof PostHogMCPAnalyticsEvent)[keyof typeof PostHogMCPAnalyticsEvent];
|
|
64
83
|
declare const PostHogMCPAnalyticsProperty: {
|
|
65
84
|
readonly AiInputState: "$ai_input_state";
|
|
66
85
|
readonly AiIsError: "$ai_is_error";
|
|
@@ -73,9 +92,11 @@ declare const PostHogMCPAnalyticsProperty: {
|
|
|
73
92
|
readonly AiTraceId: "$ai_trace_id";
|
|
74
93
|
readonly ClientName: "$mcp_client_name";
|
|
75
94
|
readonly ClientVersion: "$mcp_client_version";
|
|
95
|
+
readonly ConversationId: "$mcp_conversation_id";
|
|
76
96
|
readonly DurationMs: "$mcp_duration_ms";
|
|
77
97
|
readonly IsError: "$mcp_is_error";
|
|
78
98
|
readonly Intent: "$mcp_intent";
|
|
99
|
+
readonly IntentSource: "$mcp_intent_source";
|
|
79
100
|
readonly Parameters: "$mcp_parameters";
|
|
80
101
|
readonly ResourceName: "$mcp_resource_name";
|
|
81
102
|
readonly Response: "$mcp_response";
|
|
@@ -99,6 +120,7 @@ type PostHogMCPAnalyticsProperty = (typeof PostHogMCPAnalyticsProperty)[keyof ty
|
|
|
99
120
|
* @param options.enableAITracing - Emits `$ai_span` events for tool calls so MCP activity appears in PostHog LLM analytics. Defaults to false.
|
|
100
121
|
* @param options.enableTracing - Enables tracking of tool calls and usage patterns.
|
|
101
122
|
* @param options.context - Enables the required "context" parameter on tools to capture user intent. Pass false to disable, or an object with a custom description.
|
|
123
|
+
* @param options.intentFallback - Optional consumer-supplied callback invoked when a tool call has no explicit `context` argument. Return a short user intent string to capture as `$mcp_intent` (with `$mcp_intent_source = "inferred"`). The SDK does not infer anything on its own — this is purely a slot for your own derivation logic (e.g. a switch on `request.params.name`, an LLM call, etc.). Runs on the hot path of every uncontextualized tool call.
|
|
102
124
|
* @param options.identify - Async function to identify users and attach custom data to their sessions.
|
|
103
125
|
* @param options.redactSensitiveInformation - Function to redact sensitive data before sending to PostHog.
|
|
104
126
|
* @param options.eventTags - Callback invoked on every auto-captured event (tool calls, tool lists, initialize) to attach string key-value tags. Tags are intended to be indexed and queryable in PostHog — use them for structured metadata you'll want to filter or group by (e.g., trace IDs, environments, regions). Tags are validated client-side: keys must be ≤32 chars matching `[a-zA-Z0-9$_.:\- ]`, values must be strings ≤200 chars with no newlines, max 50 entries per event. Invalid entries are silently dropped with a warning logged to `~/posthog-mcp-analytics.log`. If the callback throws or returns null, tags are omitted. Receives the same `(request, extra)` arguments as `identify`.
|
|
@@ -235,5 +257,5 @@ declare function track<TServer>(server: TServer, options?: MCPAnalyticsOptions):
|
|
|
235
257
|
declare function publishCustomEvent(serverOrSessionId: unknown, eventData?: CustomEventData): Promise<void>;
|
|
236
258
|
type IdentifyFunction = MCPAnalyticsOptions["identify"];
|
|
237
259
|
//#endregion
|
|
238
|
-
export { type CustomEventData, IdentifyFunction, type MCPAnalyticsContextOptions, type MCPAnalyticsOptions, PostHogMCPAnalyticsProperty, type RedactFunction, type UserIdentity, publishCustomEvent, track };
|
|
260
|
+
export { type CustomEventData, IdentifyFunction, type MCPAnalyticsContextOptions, type MCPAnalyticsIntentSource, type MCPAnalyticsOptions, POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty, type RedactFunction, type UserIdentity, publishCustomEvent, track };
|
|
239
261
|
//# sourceMappingURL=index.d.mts.map
|