@posthog/mcp 0.5.0 → 0.6.0
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 +29 -0
- package/dist/extensions/constants.d.ts +3 -0
- package/dist/extensions/constants.d.ts.map +1 -1
- package/dist/extensions/constants.js +6 -0
- package/dist/extensions/constants.mjs +4 -1
- package/dist/extensions/posthog-events.d.ts.map +1 -1
- package/dist/extensions/posthog-events.js +8 -0
- package/dist/extensions/posthog-events.mjs +9 -1
- package/dist/extensions/posthog-mcp.d.ts.map +1 -1
- package/dist/extensions/posthog-mcp.js +3 -1
- package/dist/extensions/posthog-mcp.mjs +3 -1
- package/dist/extensions/session.d.ts.map +1 -1
- package/dist/extensions/session.js +5 -5
- package/dist/extensions/session.mjs +5 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +4 -4
- package/src/extensions/constants.ts +7 -0
- package/src/extensions/posthog-events.ts +20 -1
- package/src/extensions/posthog-mcp.ts +2 -0
- package/src/extensions/session.ts +7 -5
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -7,3 +7,32 @@ SDK usage examples and code snippets live in the official documentation so they
|
|
|
7
7
|
## Documentation
|
|
8
8
|
|
|
9
9
|
- [MCP analytics docs](https://posthog.com/docs/mcp-analytics)
|
|
10
|
+
|
|
11
|
+
## Developing locally
|
|
12
|
+
|
|
13
|
+
To test local changes in a consumer app (e.g. a dummy MCP server), symlink **both**
|
|
14
|
+
`@posthog/mcp` and its `posthog-node` peer from this monorepo into the app — run from the
|
|
15
|
+
app's directory:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
mkdir -p node_modules/@posthog # in case the app has no other @posthog/-scoped deps yet
|
|
19
|
+
ln -s /absolute/path/to/posthog-js/packages/mcp node_modules/@posthog/mcp
|
|
20
|
+
ln -s /absolute/path/to/posthog-js/packages/node node_modules/posthog-node
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then keep a watch build running and restart the app after each change:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cd /absolute/path/to/posthog-js/packages/mcp && pnpm dev # rebuilds dist/ on save
|
|
27
|
+
|
|
28
|
+
# in the app (e.g. dummy mcp), after each rebuild:
|
|
29
|
+
npm start # Node caches dist/ at startup, so restart to pick it up
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- **`npm install` in the app replaces both symlinks with published copies** — re-create them if you run it.
|
|
33
|
+
|
|
34
|
+
## Run tests
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cd packages/mcp && pnpm test:unit
|
|
38
|
+
```
|
|
@@ -2,6 +2,7 @@ export declare const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
|
2
2
|
export declare const DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = "Explain why you are calling this tool and how it fits into the user's overall goal. This parameter is used for analytics and user intent tracking. YOU MUST provide 15-25 words (count carefully). NEVER use first person ('I', 'we', 'you') - maintain third-person perspective. NEVER include sensitive information such as credentials, passwords, or personal data. Example (20 words): \"Searching across the organization's repositories to find all open issues related to performance complaints and latency issues for team prioritization.\"";
|
|
3
3
|
export declare const DEFAULT_CONVERSATION_ID_DESCRIPTION = "Echo the conversation_id from the server's previous response. The server provides it on the first call \u2014 never invent one, and do not issue parallel tool calls until you have it.";
|
|
4
4
|
export declare const POSTHOG_MCP_ANALYTICS_SOURCE = "posthog_mcp_analytics";
|
|
5
|
+
export declare const POSTHOG_MCP_LIB_NAME = "@posthog/mcp";
|
|
5
6
|
export declare const PostHogMCPAnalyticsEvent: {
|
|
6
7
|
readonly Custom: "$mcp_custom";
|
|
7
8
|
readonly Exception: "$exception";
|
|
@@ -25,6 +26,8 @@ export declare const PostHogMCPAnalyticsProperty: {
|
|
|
25
26
|
readonly Intent: "$mcp_intent";
|
|
26
27
|
readonly IntentSource: "$mcp_intent_source";
|
|
27
28
|
readonly ListedToolNames: "$mcp_listed_tool_names";
|
|
29
|
+
readonly McpLib: "$mcp_lib";
|
|
30
|
+
readonly McpLibVersion: "$mcp_lib_version";
|
|
28
31
|
readonly Parameters: "$mcp_parameters";
|
|
29
32
|
readonly ResourceName: "$mcp_resource_name";
|
|
30
33
|
readonly Response: "$mcp_response";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/extensions/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,6BAA6B,KAAK,CAAA;AAE/C,eAAO,MAAM,qCAAqC,2hBAAyhB,CAAA;AAE3kB,eAAO,MAAM,mCAAmC,4LACsI,CAAA;AAEtL,eAAO,MAAM,4BAA4B,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/extensions/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,6BAA6B,KAAK,CAAA;AAE/C,eAAO,MAAM,qCAAqC,2hBAAyhB,CAAA;AAE3kB,eAAO,MAAM,mCAAmC,4LACsI,CAAA;AAEtL,eAAO,MAAM,4BAA4B,0BAA0B,CAAA;AAKnE,eAAO,MAAM,oBAAoB,iBAAiB,CAAA;AAIlD,eAAO,MAAM,wBAAwB;;;;;;;;;;;;CAY3B,CAAA;AAEV,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,OAAO,wBAAwB,CAAC,CAAA;AAE/G,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;CAqB9B,CAAA;AAEV,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA"}
|
|
@@ -28,6 +28,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
DEFAULT_CONVERSATION_ID_DESCRIPTION: ()=>DEFAULT_CONVERSATION_ID_DESCRIPTION,
|
|
29
29
|
INACTIVITY_TIMEOUT_IN_MINUTES: ()=>INACTIVITY_TIMEOUT_IN_MINUTES,
|
|
30
30
|
POSTHOG_MCP_ANALYTICS_SOURCE: ()=>POSTHOG_MCP_ANALYTICS_SOURCE,
|
|
31
|
+
POSTHOG_MCP_LIB_NAME: ()=>POSTHOG_MCP_LIB_NAME,
|
|
31
32
|
PostHogMCPAnalyticsEvent: ()=>PostHogMCPAnalyticsEvent,
|
|
32
33
|
PostHogMCPAnalyticsProperty: ()=>PostHogMCPAnalyticsProperty
|
|
33
34
|
});
|
|
@@ -35,6 +36,7 @@ const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
|
35
36
|
const DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = "Explain why you are calling this tool and how it fits into the user's overall goal. This parameter is used for analytics and user intent tracking. YOU MUST provide 15-25 words (count carefully). NEVER use first person ('I', 'we', 'you') - maintain third-person perspective. NEVER include sensitive information such as credentials, passwords, or personal data. Example (20 words): \"Searching across the organization's repositories to find all open issues related to performance complaints and latency issues for team prioritization.\"";
|
|
36
37
|
const DEFAULT_CONVERSATION_ID_DESCRIPTION = "Echo the conversation_id from the server's previous response. The server provides it on the first call \u2014 never invent one, and do not issue parallel tool calls until you have it.";
|
|
37
38
|
const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics';
|
|
39
|
+
const POSTHOG_MCP_LIB_NAME = '@posthog/mcp';
|
|
38
40
|
const PostHogMCPAnalyticsEvent = {
|
|
39
41
|
Custom: '$mcp_custom',
|
|
40
42
|
Exception: '$exception',
|
|
@@ -57,6 +59,8 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
57
59
|
Intent: '$mcp_intent',
|
|
58
60
|
IntentSource: '$mcp_intent_source',
|
|
59
61
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
62
|
+
McpLib: '$mcp_lib',
|
|
63
|
+
McpLibVersion: '$mcp_lib_version',
|
|
60
64
|
Parameters: '$mcp_parameters',
|
|
61
65
|
ResourceName: '$mcp_resource_name',
|
|
62
66
|
Response: '$mcp_response',
|
|
@@ -72,6 +76,7 @@ exports.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = __webpack_exports__.DEFAULT_CONT
|
|
|
72
76
|
exports.DEFAULT_CONVERSATION_ID_DESCRIPTION = __webpack_exports__.DEFAULT_CONVERSATION_ID_DESCRIPTION;
|
|
73
77
|
exports.INACTIVITY_TIMEOUT_IN_MINUTES = __webpack_exports__.INACTIVITY_TIMEOUT_IN_MINUTES;
|
|
74
78
|
exports.POSTHOG_MCP_ANALYTICS_SOURCE = __webpack_exports__.POSTHOG_MCP_ANALYTICS_SOURCE;
|
|
79
|
+
exports.POSTHOG_MCP_LIB_NAME = __webpack_exports__.POSTHOG_MCP_LIB_NAME;
|
|
75
80
|
exports.PostHogMCPAnalyticsEvent = __webpack_exports__.PostHogMCPAnalyticsEvent;
|
|
76
81
|
exports.PostHogMCPAnalyticsProperty = __webpack_exports__.PostHogMCPAnalyticsProperty;
|
|
77
82
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
@@ -79,6 +84,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
79
84
|
"DEFAULT_CONVERSATION_ID_DESCRIPTION",
|
|
80
85
|
"INACTIVITY_TIMEOUT_IN_MINUTES",
|
|
81
86
|
"POSTHOG_MCP_ANALYTICS_SOURCE",
|
|
87
|
+
"POSTHOG_MCP_LIB_NAME",
|
|
82
88
|
"PostHogMCPAnalyticsEvent",
|
|
83
89
|
"PostHogMCPAnalyticsProperty"
|
|
84
90
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
@@ -2,6 +2,7 @@ const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
|
2
2
|
const DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = "Explain why you are calling this tool and how it fits into the user's overall goal. This parameter is used for analytics and user intent tracking. YOU MUST provide 15-25 words (count carefully). NEVER use first person ('I', 'we', 'you') - maintain third-person perspective. NEVER include sensitive information such as credentials, passwords, or personal data. Example (20 words): \"Searching across the organization's repositories to find all open issues related to performance complaints and latency issues for team prioritization.\"";
|
|
3
3
|
const DEFAULT_CONVERSATION_ID_DESCRIPTION = "Echo the conversation_id from the server's previous response. The server provides it on the first call \u2014 never invent one, and do not issue parallel tool calls until you have it.";
|
|
4
4
|
const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics';
|
|
5
|
+
const POSTHOG_MCP_LIB_NAME = '@posthog/mcp';
|
|
5
6
|
const PostHogMCPAnalyticsEvent = {
|
|
6
7
|
Custom: '$mcp_custom',
|
|
7
8
|
Exception: '$exception',
|
|
@@ -24,6 +25,8 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
24
25
|
Intent: '$mcp_intent',
|
|
25
26
|
IntentSource: '$mcp_intent_source',
|
|
26
27
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
28
|
+
McpLib: '$mcp_lib',
|
|
29
|
+
McpLibVersion: '$mcp_lib_version',
|
|
27
30
|
Parameters: '$mcp_parameters',
|
|
28
31
|
ResourceName: '$mcp_resource_name',
|
|
29
32
|
Response: '$mcp_response',
|
|
@@ -35,4 +38,4 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
35
38
|
ToolDescription: "$mcp_tool_description",
|
|
36
39
|
ToolName: '$mcp_tool_name'
|
|
37
40
|
};
|
|
38
|
-
export { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, DEFAULT_CONVERSATION_ID_DESCRIPTION, INACTIVITY_TIMEOUT_IN_MINUTES, POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty };
|
|
41
|
+
export { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, DEFAULT_CONVERSATION_ID_DESCRIPTION, INACTIVITY_TIMEOUT_IN_MINUTES, POSTHOG_MCP_ANALYTICS_SOURCE, POSTHOG_MCP_LIB_NAME, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-events.d.ts","sourceRoot":"","sources":["../../src/extensions/posthog-events.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"posthog-events.d.ts","sourceRoot":"","sources":["../../src/extensions/posthog-events.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AA8BrC,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,SAAS,CAAA;CAChB;AAED,MAAM,WAAW,gCAAgC;IAC/C,2FAA2F;IAC3F,0BAA0B,CAAC,EAAE,OAAO,CAAA;CACrC;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,gCAAqC,GAC7C,mBAAmB,EAAE,CAQvB"}
|
|
@@ -98,6 +98,7 @@ function addCommonEventProperties(event, properties) {
|
|
|
98
98
|
if (event.serverVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
|
|
99
99
|
if (event.clientName) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
|
|
100
100
|
if (event.clientVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
|
|
101
|
+
addMcpLibProperties(event, properties);
|
|
101
102
|
if (event.userIntent) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.Intent] = event.userIntent;
|
|
102
103
|
if (event.userIntentSource) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.IntentSource] = event.userIntentSource;
|
|
103
104
|
if (void 0 !== event.isError) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.IsError] = event.isError;
|
|
@@ -110,6 +111,12 @@ function addCommonEventProperties(event, properties) {
|
|
|
110
111
|
function addCustomEventProperties(event, properties) {
|
|
111
112
|
if (event.properties) for (const [key, value] of Object.entries(event.properties))properties[key] = value;
|
|
112
113
|
}
|
|
114
|
+
function addMcpLibProperties(event, properties) {
|
|
115
|
+
if (event.sdkVersion) {
|
|
116
|
+
properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.McpLib] = external_constants_js_namespaceObject.POSTHOG_MCP_LIB_NAME;
|
|
117
|
+
properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.McpLibVersion] = event.sdkVersion;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
113
120
|
function buildExceptionEvent(event) {
|
|
114
121
|
const distinctId = getDistinctId(event);
|
|
115
122
|
const timestamp = getTimestamp(event);
|
|
@@ -129,6 +136,7 @@ function buildExceptionEvent(event) {
|
|
|
129
136
|
if (event.serverVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
|
|
130
137
|
if (event.clientName) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
|
|
131
138
|
if (event.clientVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
|
|
139
|
+
addMcpLibProperties(event, properties);
|
|
132
140
|
addCustomEventProperties(event, properties);
|
|
133
141
|
return {
|
|
134
142
|
event: external_constants_js_namespaceObject.PostHogMCPAnalyticsEvent.Exception,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty } from "./constants.mjs";
|
|
1
|
+
import { POSTHOG_MCP_ANALYTICS_SOURCE, POSTHOG_MCP_LIB_NAME, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty } from "./constants.mjs";
|
|
2
2
|
import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
3
3
|
const BUILT_IN_EVENT_NAME_BY_TYPE = {
|
|
4
4
|
[MCPAnalyticsEventType.custom]: PostHogMCPAnalyticsEvent.Custom,
|
|
@@ -70,6 +70,7 @@ function addCommonEventProperties(event, properties) {
|
|
|
70
70
|
if (event.serverVersion) properties[PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
|
|
71
71
|
if (event.clientName) properties[PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
|
|
72
72
|
if (event.clientVersion) properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
|
|
73
|
+
addMcpLibProperties(event, properties);
|
|
73
74
|
if (event.userIntent) properties[PostHogMCPAnalyticsProperty.Intent] = event.userIntent;
|
|
74
75
|
if (event.userIntentSource) properties[PostHogMCPAnalyticsProperty.IntentSource] = event.userIntentSource;
|
|
75
76
|
if (void 0 !== event.isError) properties[PostHogMCPAnalyticsProperty.IsError] = event.isError;
|
|
@@ -82,6 +83,12 @@ function addCommonEventProperties(event, properties) {
|
|
|
82
83
|
function addCustomEventProperties(event, properties) {
|
|
83
84
|
if (event.properties) for (const [key, value] of Object.entries(event.properties))properties[key] = value;
|
|
84
85
|
}
|
|
86
|
+
function addMcpLibProperties(event, properties) {
|
|
87
|
+
if (event.sdkVersion) {
|
|
88
|
+
properties[PostHogMCPAnalyticsProperty.McpLib] = POSTHOG_MCP_LIB_NAME;
|
|
89
|
+
properties[PostHogMCPAnalyticsProperty.McpLibVersion] = event.sdkVersion;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
85
92
|
function buildExceptionEvent(event) {
|
|
86
93
|
const distinctId = getDistinctId(event);
|
|
87
94
|
const timestamp = getTimestamp(event);
|
|
@@ -101,6 +108,7 @@ function buildExceptionEvent(event) {
|
|
|
101
108
|
if (event.serverVersion) properties[PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
|
|
102
109
|
if (event.clientName) properties[PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
|
|
103
110
|
if (event.clientVersion) properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
|
|
111
|
+
addMcpLibProperties(event, properties);
|
|
104
112
|
addCustomEventProperties(event, properties);
|
|
105
113
|
return {
|
|
106
114
|
event: PostHogMCPAnalyticsEvent.Exception,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-mcp.d.ts","sourceRoot":"","sources":["../../src/extensions/posthog-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"posthog-mcp.d.ts","sourceRoot":"","sources":["../../src/extensions/posthog-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAG3D,OAAO,KAAK,EACV,qBAAqB,EAIrB,4BAA4B,EAC5B,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,UAAU,CAAA;AACjB,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAA;AAO7B;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,UAAW,SAAQ,OAAO;;gBAWzB,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAK3D,8FAA8F;IAC9F,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI;IAgBhD,iEAAiE;IACjE,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAUpD;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI;IAalD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,eAAe,CAAC,KAAK,SAAS,qBAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,OAAO,GAAE,sBAA2B,GAAG,KAAK,EAAE;IAYnH;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB;IAW/E;;;;OAIG;IACH,wBAAwB,CAAC,IAAI,EAAE,4BAA4B,GAAG,IAAI;CAkBnE"}
|
|
@@ -27,6 +27,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
PostHogMCP: ()=>PostHogMCP
|
|
28
28
|
});
|
|
29
29
|
const external_posthog_node_namespaceObject = require("posthog-node");
|
|
30
|
+
const external_version_js_namespaceObject = require("../version.js");
|
|
30
31
|
const external_context_parameters_js_namespaceObject = require("./context-parameters.js");
|
|
31
32
|
const external_event_types_js_namespaceObject = require("./event-types.js");
|
|
32
33
|
const external_exceptions_js_namespaceObject = require("./exceptions.js");
|
|
@@ -112,7 +113,8 @@ function baseEvent(eventType, common) {
|
|
|
112
113
|
sessionId: common.sessionId,
|
|
113
114
|
timestamp: common.timestamp ?? new Date(),
|
|
114
115
|
properties: common.properties,
|
|
115
|
-
groups: common.groups
|
|
116
|
+
groups: common.groups,
|
|
117
|
+
sdkVersion: external_version_js_namespaceObject.version
|
|
116
118
|
};
|
|
117
119
|
if (common.distinctId) event.identifyActorGivenId = common.distinctId;
|
|
118
120
|
if (common.setProperties && Object.keys(common.setProperties).length > 0) event.identifyActorData = common.setProperties;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PostHog } from "posthog-node";
|
|
2
|
+
import { version } from "../version.mjs";
|
|
2
3
|
import { addContextParameterToTools, getContextDescription, isContextEnabled } from "./context-parameters.mjs";
|
|
3
4
|
import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
4
5
|
import { captureException } from "./exceptions.mjs";
|
|
@@ -84,7 +85,8 @@ function baseEvent(eventType, common) {
|
|
|
84
85
|
sessionId: common.sessionId,
|
|
85
86
|
timestamp: common.timestamp ?? new Date(),
|
|
86
87
|
properties: common.properties,
|
|
87
|
-
groups: common.groups
|
|
88
|
+
groups: common.groups,
|
|
89
|
+
sdkVersion: version
|
|
88
90
|
};
|
|
89
91
|
if (common.distinctId) event.identifyActorGivenId = common.distinctId;
|
|
90
92
|
if (common.setProperties && Object.keys(common.setProperties).length > 0) event.identifyActorData = common.setProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/extensions/session.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,aAAa,EAEb,WAAW,EACZ,MAAM,UAAU,CAAA;AAKjB,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAoCvG;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAS3D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAClC,SAAS,CAAC,EAAE,MAAM,GACjB,WAAW,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/extensions/session.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,aAAa,EAEb,WAAW,EACZ,MAAM,UAAU,CAAA;AAKjB,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAoCvG;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAS3D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAClC,SAAS,CAAC,EAAE,MAAM,GACjB,WAAW,CAgCb"}
|
|
@@ -73,11 +73,11 @@ function setLastActivity(server) {
|
|
|
73
73
|
(0, external_internal_js_namespaceObject.setServerTrackingData)(server, data);
|
|
74
74
|
}
|
|
75
75
|
function getSessionInfo(server, data, sessionId) {
|
|
76
|
-
let clientInfo
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
let clientInfo;
|
|
77
|
+
clientInfo = data?.sessionInfo.clientName ? {
|
|
78
|
+
name: data.sessionInfo.clientName,
|
|
79
|
+
version: data.sessionInfo.clientVersion
|
|
80
|
+
} : server.getClientVersion();
|
|
81
81
|
const actorInfo = data?.identifiedSessions.get(sessionId ?? data.sessionId);
|
|
82
82
|
const sessionInfo = {
|
|
83
83
|
ipAddress: void 0,
|
|
@@ -41,11 +41,11 @@ function setLastActivity(server) {
|
|
|
41
41
|
setServerTrackingData(server, data);
|
|
42
42
|
}
|
|
43
43
|
function getSessionInfo(server, data, sessionId) {
|
|
44
|
-
let clientInfo
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
let clientInfo;
|
|
45
|
+
clientInfo = data?.sessionInfo.clientName ? {
|
|
46
|
+
name: data.sessionInfo.clientName,
|
|
47
|
+
version: data.sessionInfo.clientVersion
|
|
48
|
+
} : server.getClientVersion();
|
|
49
49
|
const actorInfo = data?.identifiedSessions.get(sessionId ?? data.sessionId);
|
|
50
50
|
const sessionInfo = {
|
|
51
51
|
ipAddress: void 0,
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.6.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
version: ()=>version
|
|
28
28
|
});
|
|
29
|
-
const version = '0.
|
|
29
|
+
const version = '0.6.0';
|
|
30
30
|
exports.version = __webpack_exports__.version;
|
|
31
31
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
32
32
|
"version"
|
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '0.
|
|
1
|
+
const version = '0.6.0';
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"module": "dist/index.mjs",
|
|
29
29
|
"types": "dist/index.d.ts",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@posthog/core": "^1.
|
|
31
|
+
"@posthog/core": "^1.39.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/preset-env": "^7.27.1",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@types/node": "^20.0.0",
|
|
40
40
|
"jest": "29.7.0",
|
|
41
41
|
"zod": "^3.25.0",
|
|
42
|
-
"posthog-
|
|
43
|
-
"
|
|
42
|
+
"@posthog-tooling/tsconfig-base": "1.1.1",
|
|
43
|
+
"posthog-node": "^5.39.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@modelcontextprotocol/sdk": ">=1.26.0",
|
|
@@ -11,6 +11,11 @@ export const DEFAULT_CONVERSATION_ID_DESCRIPTION =
|
|
|
11
11
|
|
|
12
12
|
export const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics'
|
|
13
13
|
|
|
14
|
+
// Identifies the SDK that produced an `$mcp_*` event. Distinct from `$lib`
|
|
15
|
+
// (posthog-node, the transport that actually sends the event) — this names the
|
|
16
|
+
// higher-level analytics layer, mirroring `@posthog/ai`'s `$ai_lib`.
|
|
17
|
+
export const POSTHOG_MCP_LIB_NAME = '@posthog/mcp'
|
|
18
|
+
|
|
14
19
|
// All PostHog-owned event names start with `$` per the PostHog convention.
|
|
15
20
|
// Non-`$` names would be treated as customer-defined events and confuse the schema.
|
|
16
21
|
export const PostHogMCPAnalyticsEvent = {
|
|
@@ -38,6 +43,8 @@ export const PostHogMCPAnalyticsProperty = {
|
|
|
38
43
|
Intent: '$mcp_intent',
|
|
39
44
|
IntentSource: '$mcp_intent_source',
|
|
40
45
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
46
|
+
McpLib: '$mcp_lib',
|
|
47
|
+
McpLibVersion: '$mcp_lib_version',
|
|
41
48
|
Parameters: '$mcp_parameters',
|
|
42
49
|
ResourceName: '$mcp_resource_name',
|
|
43
50
|
Response: '$mcp_response',
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
// Licensed under the MIT License: https://github.com/MCPCat/mcpcat-typescript-sdk/blob/main/LICENSE
|
|
4
4
|
|
|
5
5
|
import type { Event } from '../types'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
POSTHOG_MCP_ANALYTICS_SOURCE,
|
|
8
|
+
POSTHOG_MCP_LIB_NAME,
|
|
9
|
+
PostHogMCPAnalyticsEvent,
|
|
10
|
+
PostHogMCPAnalyticsProperty,
|
|
11
|
+
} from './constants'
|
|
7
12
|
import { MCPAnalyticsEventType } from './event-types'
|
|
8
13
|
|
|
9
14
|
const BUILT_IN_EVENT_NAME_BY_TYPE = {
|
|
@@ -150,6 +155,7 @@ function addCommonEventProperties(event: Event, properties: Record<string, unkno
|
|
|
150
155
|
if (event.clientVersion) {
|
|
151
156
|
properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion
|
|
152
157
|
}
|
|
158
|
+
addMcpLibProperties(event, properties)
|
|
153
159
|
if (event.userIntent) {
|
|
154
160
|
properties[PostHogMCPAnalyticsProperty.Intent] = event.userIntent
|
|
155
161
|
}
|
|
@@ -181,6 +187,18 @@ function addCustomEventProperties(event: Event, properties: Record<string, unkno
|
|
|
181
187
|
}
|
|
182
188
|
}
|
|
183
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Stamps the `@posthog/mcp` SDK identity (`$mcp_lib` / `$mcp_lib_version`) onto
|
|
192
|
+
* the event. Shared by the regular and `$exception` builders so both report
|
|
193
|
+
* which analytics SDK release produced the event.
|
|
194
|
+
*/
|
|
195
|
+
function addMcpLibProperties(event: Event, properties: Record<string, unknown>): void {
|
|
196
|
+
if (event.sdkVersion) {
|
|
197
|
+
properties[PostHogMCPAnalyticsProperty.McpLib] = POSTHOG_MCP_LIB_NAME
|
|
198
|
+
properties[PostHogMCPAnalyticsProperty.McpLibVersion] = event.sdkVersion
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
184
202
|
function buildExceptionEvent(event: Event): PostHogCaptureEvent {
|
|
185
203
|
const distinctId = getDistinctId(event)
|
|
186
204
|
const timestamp = getTimestamp(event)
|
|
@@ -221,6 +239,7 @@ function buildExceptionEvent(event: Event): PostHogCaptureEvent {
|
|
|
221
239
|
if (event.clientVersion) {
|
|
222
240
|
properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion
|
|
223
241
|
}
|
|
242
|
+
addMcpLibProperties(event, properties)
|
|
224
243
|
|
|
225
244
|
addCustomEventProperties(event, properties)
|
|
226
245
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PostHog, type PostHogOptions } from 'posthog-node'
|
|
2
2
|
|
|
3
|
+
import { version } from '../version'
|
|
3
4
|
import type {
|
|
4
5
|
InitializeCaptureData,
|
|
5
6
|
JsonRecord,
|
|
@@ -241,6 +242,7 @@ function baseEvent(eventType: MCPAnalyticsEventType, common: McpCaptureCommon):
|
|
|
241
242
|
timestamp: common.timestamp ?? new Date(),
|
|
242
243
|
properties: common.properties,
|
|
243
244
|
groups: common.groups,
|
|
245
|
+
sdkVersion: version,
|
|
244
246
|
}
|
|
245
247
|
if (common.distinctId) {
|
|
246
248
|
event.identifyActorGivenId = common.distinctId
|
|
@@ -89,11 +89,13 @@ export function getSessionInfo(
|
|
|
89
89
|
data: MCPAnalyticsData | undefined,
|
|
90
90
|
sessionId?: string
|
|
91
91
|
): SessionInfo {
|
|
92
|
-
let clientInfo: ServerClientInfoLike | undefined
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
let clientInfo: ServerClientInfoLike | undefined
|
|
93
|
+
if (data?.sessionInfo.clientName) {
|
|
94
|
+
clientInfo = {
|
|
95
|
+
name: data.sessionInfo.clientName,
|
|
96
|
+
version: data.sessionInfo.clientVersion,
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
97
99
|
clientInfo = server.getClientVersion()
|
|
98
100
|
}
|
|
99
101
|
const actorInfo = data?.identifiedSessions.get(sessionId ?? data.sessionId)
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.
|
|
1
|
+
export const version = '0.6.0'
|