@posthog/mcp 0.4.4 → 0.5.1

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
@@ -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
+ ```
@@ -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,CA8Bb"}
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
- name: void 0,
78
- version: void 0
79
- };
80
- if (!data?.sessionInfo.clientName) clientInfo = server.getClientVersion();
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
- name: void 0,
46
- version: void 0
47
- };
48
- if (!data?.sessionInfo.clientName) clientInfo = server.getClientVersion();
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/index.d.ts CHANGED
@@ -28,6 +28,25 @@ import type { McpAnalytics, MCPAnalyticsOptions } from './types';
28
28
  * ```
29
29
  */
30
30
  declare function instrument(server: unknown, posthog: PostHog, options?: MCPAnalyticsOptions): McpAnalytics;
31
+ /**
32
+ * A point-free `(server) => server` helper for framework server-mutation hooks (e.g.
33
+ * `@rekog/mcp-nest`'s `serverMutator`). It instruments the server and returns it, so you
34
+ * don't trip over {@link instrument} returning the analytics handle rather than the server —
35
+ * the bare `(s) => instrument(s, posthog)` would replace the server with the handle.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * McpModule.forRoot({ serverMutator: instrumentMutator(posthog) })
40
+ * ```
41
+ *
42
+ * Need the handle for custom events? Call {@link instrument} directly inside your own mutator
43
+ * and return the server. See https://posthog.com/docs/mcp-analytics/installation.
44
+ *
45
+ * @param posthog - A `posthog-node` client you construct and own.
46
+ * @param options - Optional configuration. See `MCPAnalyticsOptions`.
47
+ * @returns A `(server) => server` mutator that instruments the server and returns it.
48
+ */
49
+ declare function instrumentMutator<TServer>(posthog: PostHog, options?: MCPAnalyticsOptions): (server: TServer) => TServer;
31
50
  export { deriveSessionIdFromMCPSession };
32
51
  export { POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty, } from './extensions/constants';
33
52
  export { PostHogMCP, type PostHogMCPOptions } from './extensions/posthog-mcp';
@@ -36,5 +55,5 @@ export { setLogger } from './extensions/logger';
36
55
  export { PostHog, type PostHogOptions } from 'posthog-node';
37
56
  export type { BeforeSendFn, CaptureEventData, InitializeCaptureData, McpAnalytics, McpCaptureCommon, MCPAnalyticsContextOptions, MCPAnalyticsIntentSource, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PrepareToolListOptions, ToolCallCaptureData, ToolsListCaptureData, UserIdentity, } from './types';
38
57
  export type IdentifyFunction = MCPAnalyticsOptions['identify'];
39
- export { instrument };
58
+ export { instrument, instrumentMutator };
40
59
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAO3C,OAAO,EAAE,6BAA6B,EAAgC,MAAM,sBAAsB,CAAA;AAGlG,OAAO,KAAK,EAGV,YAAY,EAEZ,mBAAmB,EAGpB,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,mBAAwB,GAAG,YAAY,CA6BtG;AAmFD,OAAO,EAAE,6BAA6B,EAAE,CAAA;AACxC,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAI/C,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAC3D,YAAY,EACV,YAAY,EACZ,gBAA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Ac,CAAA;AAC3D,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,GACb,MAAM,SAAS,CAAA;AAChB,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAA"}
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __webpack_require__.d(__webpack_exports__, {
29
29
  deriveSessionIdFromMCPSession: ()=>session_js_namespaceObject.deriveSessionIdFromMCPSession,
30
30
  POSTHOG_MCP_ANALYTICS_SOURCE: ()=>constants_js_namespaceObject.POSTHOG_MCP_ANALYTICS_SOURCE,
31
31
  instrument: ()=>instrument,
32
+ instrumentMutator: ()=>instrumentMutator,
32
33
  setLogger: ()=>logger_js_namespaceObject.setLogger,
33
34
  PostHogMCPAnalyticsEvent: ()=>constants_js_namespaceObject.PostHogMCPAnalyticsEvent,
34
35
  getMoreToolsResult: ()=>tools_js_namespaceObject.getMoreToolsResult,
@@ -69,6 +70,12 @@ function instrument(server, posthog, options = {}) {
69
70
  };
70
71
  }
71
72
  }
73
+ function instrumentMutator(posthog, options) {
74
+ return (server)=>{
75
+ instrument(server, posthog, options);
76
+ return server;
77
+ };
78
+ }
72
79
  function createAnalyticsHandle(lowLevelServer) {
73
80
  return {
74
81
  capture: (eventData)=>captureCustomEvent(lowLevelServer, eventData)
@@ -131,6 +138,7 @@ exports.PostHogMCPAnalyticsProperty = __webpack_exports__.PostHogMCPAnalyticsPro
131
138
  exports.deriveSessionIdFromMCPSession = __webpack_exports__.deriveSessionIdFromMCPSession;
132
139
  exports.getMoreToolsResult = __webpack_exports__.getMoreToolsResult;
133
140
  exports.instrument = __webpack_exports__.instrument;
141
+ exports.instrumentMutator = __webpack_exports__.instrumentMutator;
134
142
  exports.setLogger = __webpack_exports__.setLogger;
135
143
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
136
144
  "POSTHOG_MCP_ANALYTICS_SOURCE",
@@ -141,6 +149,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
141
149
  "deriveSessionIdFromMCPSession",
142
150
  "getMoreToolsResult",
143
151
  "instrument",
152
+ "instrumentMutator",
144
153
  "setLogger"
145
154
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
146
155
  Object.defineProperty(exports, '__esModule', {
package/dist/index.mjs CHANGED
@@ -33,6 +33,12 @@ function instrument(server, posthog, options = {}) {
33
33
  };
34
34
  }
35
35
  }
36
+ function instrumentMutator(posthog, options) {
37
+ return (server)=>{
38
+ instrument(server, posthog, options);
39
+ return server;
40
+ };
41
+ }
36
42
  function createAnalyticsHandle(lowLevelServer) {
37
43
  return {
38
44
  capture: (eventData)=>captureCustomEvent(lowLevelServer, eventData)
@@ -87,4 +93,4 @@ async function captureCustomEvent(lowLevelServer, eventData) {
87
93
  await captureEvent(lowLevelServer, event);
88
94
  log(`Captured event "${eventData.event}" for session ${trackingData.sessionId}`);
89
95
  }
90
- export { POSTHOG_MCP_ANALYTICS_SOURCE, PostHog, PostHogMCP, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty, deriveSessionIdFromMCPSession, getMoreToolsResult, instrument, setLogger };
96
+ export { POSTHOG_MCP_ANALYTICS_SOURCE, PostHog, PostHogMCP, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty, deriveSessionIdFromMCPSession, getMoreToolsResult, instrument, instrumentMutator, setLogger };
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "0.4.4";
1
+ export declare const version = "0.5.1";
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.4.4';
29
+ const version = '0.5.1';
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.4.4';
1
+ const version = '0.5.1';
2
2
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/mcp",
3
- "version": "0.4.4",
3
+ "version": "0.5.1",
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.38.0"
31
+ "@posthog/core": "^1.38.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/preset-env": "^7.27.1",
@@ -39,7 +39,7 @@
39
39
  "@types/node": "^20.0.0",
40
40
  "jest": "29.7.0",
41
41
  "zod": "^3.25.0",
42
- "posthog-node": "^5.38.6",
42
+ "posthog-node": "^5.38.8",
43
43
  "@posthog-tooling/tsconfig-base": "1.1.1"
44
44
  },
45
45
  "peerDependencies": {
@@ -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
- name: undefined,
94
- version: undefined,
95
- }
96
- if (!data?.sessionInfo.clientName) {
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/index.ts CHANGED
@@ -79,6 +79,31 @@ function instrument(server: unknown, posthog: PostHog, options: MCPAnalyticsOpti
79
79
  }
80
80
  }
81
81
 
82
+ /**
83
+ * A point-free `(server) => server` helper for framework server-mutation hooks (e.g.
84
+ * `@rekog/mcp-nest`'s `serverMutator`). It instruments the server and returns it, so you
85
+ * don't trip over {@link instrument} returning the analytics handle rather than the server —
86
+ * the bare `(s) => instrument(s, posthog)` would replace the server with the handle.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * McpModule.forRoot({ serverMutator: instrumentMutator(posthog) })
91
+ * ```
92
+ *
93
+ * Need the handle for custom events? Call {@link instrument} directly inside your own mutator
94
+ * and return the server. See https://posthog.com/docs/mcp-analytics/installation.
95
+ *
96
+ * @param posthog - A `posthog-node` client you construct and own.
97
+ * @param options - Optional configuration. See `MCPAnalyticsOptions`.
98
+ * @returns A `(server) => server` mutator that instruments the server and returns it.
99
+ */
100
+ function instrumentMutator<TServer>(posthog: PostHog, options?: MCPAnalyticsOptions): (server: TServer) => TServer {
101
+ return (server: TServer): TServer => {
102
+ instrument(server, posthog, options)
103
+ return server
104
+ }
105
+ }
106
+
82
107
  function createAnalyticsHandle(lowLevelServer: MCPServerLike): McpAnalytics {
83
108
  return {
84
109
  capture: (eventData) => captureCustomEvent(lowLevelServer, eventData),
@@ -190,4 +215,4 @@ export type {
190
215
  UserIdentity,
191
216
  } from './types'
192
217
  export type IdentifyFunction = MCPAnalyticsOptions['identify']
193
- export { instrument }
218
+ export { instrument, instrumentMutator }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '0.4.4'
1
+ export const version = '0.5.1'