@posthog/mcp 0.12.0 → 0.13.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.
Files changed (63) hide show
  1. package/README.md +22 -2
  2. package/dist/extensions/analytics-parameters.js +14 -10
  3. package/dist/extensions/capture.js +12 -8
  4. package/dist/extensions/client-identity.js +18 -14
  5. package/dist/extensions/compatibility.js +16 -12
  6. package/dist/extensions/constants.js +24 -20
  7. package/dist/extensions/constants.mjs +2 -2
  8. package/dist/extensions/context-parameters.js +13 -9
  9. package/dist/extensions/conversation-id.js +18 -14
  10. package/dist/extensions/detect.js +23 -19
  11. package/dist/extensions/event-types.js +15 -11
  12. package/dist/extensions/exceptions.js +12 -8
  13. package/dist/extensions/headers.js +16 -12
  14. package/dist/extensions/ids.js +12 -8
  15. package/dist/extensions/instrument-highlevel.js +12 -8
  16. package/dist/extensions/instrument-lowlevel.js +12 -8
  17. package/dist/extensions/instrumentation.js +19 -15
  18. package/dist/extensions/intent.js +14 -10
  19. package/dist/extensions/internal.js +17 -13
  20. package/dist/extensions/lib-identity.js +12 -8
  21. package/dist/extensions/logger.js +17 -13
  22. package/dist/extensions/mcp-payloads.js +16 -12
  23. package/dist/extensions/mcp-sdk-compat.js +23 -19
  24. package/dist/extensions/model-parameters.d.ts.map +1 -1
  25. package/dist/extensions/model-parameters.js +21 -14
  26. package/dist/extensions/model-parameters.mjs +6 -3
  27. package/dist/extensions/output-instructions.js +15 -11
  28. package/dist/extensions/posthog-events.js +12 -8
  29. package/dist/extensions/posthog-mcp.d.ts +23 -12
  30. package/dist/extensions/posthog-mcp.d.ts.map +1 -1
  31. package/dist/extensions/posthog-mcp.js +49 -11
  32. package/dist/extensions/posthog-mcp.mjs +37 -3
  33. package/dist/extensions/request-headers.js +15 -11
  34. package/dist/extensions/sanitization.d.ts +2 -2
  35. package/dist/extensions/sanitization.d.ts.map +1 -1
  36. package/dist/extensions/sanitization.js +13 -8
  37. package/dist/extensions/sanitization.mjs +1 -0
  38. package/dist/extensions/session-token.js +17 -13
  39. package/dist/extensions/session-token.mjs +2 -2
  40. package/dist/extensions/session.js +16 -12
  41. package/dist/extensions/sink.js +14 -10
  42. package/dist/extensions/tools.js +15 -11
  43. package/dist/extensions/tracing-helpers.js +15 -11
  44. package/dist/extensions/transport-identity.js +15 -11
  45. package/dist/extensions/truncation.js +21 -16
  46. package/dist/index.d.ts +1 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +22 -18
  49. package/dist/index.mjs +7 -7
  50. package/dist/types.d.ts +28 -4
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/types.js +2 -2
  53. package/dist/types.mjs +1 -0
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +15 -11
  56. package/dist/version.mjs +1 -1
  57. package/package.json +11 -11
  58. package/src/extensions/model-parameters.ts +7 -3
  59. package/src/extensions/posthog-mcp.ts +84 -12
  60. package/src/extensions/sanitization.ts +6 -2
  61. package/src/index.ts +1 -0
  62. package/src/types.ts +27 -4
  63. package/src/version.ts +1 -1
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -13,7 +17,7 @@ var __webpack_require__ = {};
13
17
  })();
14
18
  (()=>{
15
19
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
21
  value: 'Module'
18
22
  });
19
23
  Object.defineProperty(exports1, '__esModule', {
@@ -23,17 +27,6 @@ var __webpack_require__ = {};
23
27
  })();
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- createWrappedTool: ()=>createWrappedTool,
28
- getLiteralValue: ()=>getLiteralValue,
29
- getObjectShape: ()=>getObjectShape,
30
- getToolFunction: ()=>getToolFunction,
31
- getToolFunctionKey: ()=>getToolFunctionKey,
32
- hasToolFunction: ()=>hasToolFunction,
33
- isZ4Schema: ()=>isZ4Schema,
34
- isZodRawShapeCompat: ()=>isZodRawShapeCompat,
35
- readRequestHandlerMethod: ()=>readRequestHandlerMethod
36
- });
37
30
  function getToolFunction(tool) {
38
31
  if ('handler' in tool && 'function' == typeof tool.handler) return tool.handler;
39
32
  if ('callback' in tool && 'function' == typeof tool.callback) return tool.callback;
@@ -105,6 +98,17 @@ function getLiteralValue(schema) {
105
98
  const directValue = schema.value;
106
99
  if (void 0 !== directValue) return directValue;
107
100
  }
101
+ __webpack_require__.d(__webpack_exports__, {
102
+ createWrappedTool: ()=>createWrappedTool,
103
+ getLiteralValue: ()=>getLiteralValue,
104
+ getObjectShape: ()=>getObjectShape,
105
+ getToolFunction: ()=>getToolFunction,
106
+ getToolFunctionKey: ()=>getToolFunctionKey,
107
+ hasToolFunction: ()=>hasToolFunction,
108
+ isZ4Schema: ()=>isZ4Schema,
109
+ isZodRawShapeCompat: ()=>isZodRawShapeCompat,
110
+ readRequestHandlerMethod: ()=>readRequestHandlerMethod
111
+ });
108
112
  exports.createWrappedTool = __webpack_exports__.createWrappedTool;
109
113
  exports.getLiteralValue = __webpack_exports__.getLiteralValue;
110
114
  exports.getObjectShape = __webpack_exports__.getObjectShape;
@@ -114,7 +118,7 @@ exports.hasToolFunction = __webpack_exports__.hasToolFunction;
114
118
  exports.isZ4Schema = __webpack_exports__.isZ4Schema;
115
119
  exports.isZodRawShapeCompat = __webpack_exports__.isZodRawShapeCompat;
116
120
  exports.readRequestHandlerMethod = __webpack_exports__.readRequestHandlerMethod;
117
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
121
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
118
122
  "createWrappedTool",
119
123
  "getLiteralValue",
120
124
  "getObjectShape",
@@ -124,7 +128,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
124
128
  "isZ4Schema",
125
129
  "isZodRawShapeCompat",
126
130
  "readRequestHandlerMethod"
127
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
131
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
128
132
  Object.defineProperty(exports, '__esModule', {
129
133
  value: true
130
134
  });
@@ -1 +1 @@
1
- {"version":3,"file":"model-parameters.d.ts","sourceRoot":"","sources":["../../src/extensions/model-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC7E,OAAO,EAA+B,KAAK,6BAA6B,EAAE,MAAM,wBAAwB,CAAA;AAExG,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,gFAAgF;AAChF,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,mBAAmB,CAAC,cAAc,CAAC,GAAG,OAAO,CAEhG;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,mBAAmB,CAAC,cAAc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;AACH,wBAAgB,uBAAuB,CAAC,KAAK,SAAS,mBAAmB,EACvE,IAAI,EAAE,KAAK,EACX,wBAAwB,CAAC,EAAE,MAAM,EACjC,MAAM,GAAE,QAAc,GACrB,KAAK,CAQP;AAED,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,mBAAmB,EACxE,KAAK,EAAE,KAAK,EAAE,EACd,wBAAwB,CAAC,EAAE,MAAM,EACjC,MAAM,GAAE,QAAc,GACrB,KAAK,EAAE,CAET;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAE5E;AAaD,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAO9E"}
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -13,7 +17,7 @@ var __webpack_require__ = {};
13
17
  })();
14
18
  (()=>{
15
19
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
21
  value: 'Module'
18
22
  });
19
23
  Object.defineProperty(exports1, '__esModule', {
@@ -24,12 +28,12 @@ var __webpack_require__ = {};
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
30
  __webpack_require__.d(__webpack_exports__, {
27
- setEventModel: ()=>setEventModel,
28
31
  addModelParameterToTool: ()=>addModelParameterToTool,
32
+ addModelParameterToTools: ()=>addModelParameterToTools,
29
33
  getModelArgument: ()=>getModelArgument,
30
34
  getModelDescription: ()=>getModelDescription,
31
- addModelParameterToTools: ()=>addModelParameterToTools,
32
- isCaptureModelEnabled: ()=>isCaptureModelEnabled
35
+ isCaptureModelEnabled: ()=>isCaptureModelEnabled,
36
+ setEventModel: ()=>setEventModel
33
37
  });
34
38
  const external_analytics_parameters_js_namespaceObject = require("./analytics-parameters.js");
35
39
  const external_constants_js_namespaceObject = require("./constants.js");
@@ -47,15 +51,18 @@ function addModelParameterToTools(tools, modelDescriptionOverride, logger = exte
47
51
  return tools.map((tool)=>addModelParameterToTool(tool, modelDescriptionOverride, logger));
48
52
  }
49
53
  function getModelArgument(request) {
50
- const model = request.params?.arguments?.llm_model;
54
+ return normalizeModel(request.params?.arguments?.llm_model);
55
+ }
56
+ function normalizeModel(model) {
51
57
  if ('string' != typeof model) return;
52
58
  const trimmed = model.trim();
53
59
  if (!trimmed || 'unknown' === trimmed.toLowerCase()) return;
54
60
  return trimmed;
55
61
  }
56
62
  function setEventModel(event, model) {
57
- if (!model) return;
58
- event.llmModel = model;
63
+ const normalizedModel = normalizeModel(model);
64
+ if (!normalizedModel) return;
65
+ event.llmModel = normalizedModel;
59
66
  event.llmModelSource = 'self_reported';
60
67
  }
61
68
  exports.addModelParameterToTool = __webpack_exports__.addModelParameterToTool;
@@ -64,14 +71,14 @@ exports.getModelArgument = __webpack_exports__.getModelArgument;
64
71
  exports.getModelDescription = __webpack_exports__.getModelDescription;
65
72
  exports.isCaptureModelEnabled = __webpack_exports__.isCaptureModelEnabled;
66
73
  exports.setEventModel = __webpack_exports__.setEventModel;
67
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
74
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
68
75
  "addModelParameterToTool",
69
76
  "addModelParameterToTools",
70
77
  "getModelArgument",
71
78
  "getModelDescription",
72
79
  "isCaptureModelEnabled",
73
80
  "setEventModel"
74
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
81
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
75
82
  Object.defineProperty(exports, '__esModule', {
76
83
  value: true
77
84
  });
@@ -14,15 +14,18 @@ function addModelParameterToTools(tools, modelDescriptionOverride, logger = log)
14
14
  return tools.map((tool)=>addModelParameterToTool(tool, modelDescriptionOverride, logger));
15
15
  }
16
16
  function getModelArgument(request) {
17
- const model = request.params?.arguments?.llm_model;
17
+ return normalizeModel(request.params?.arguments?.llm_model);
18
+ }
19
+ function normalizeModel(model) {
18
20
  if ('string' != typeof model) return;
19
21
  const trimmed = model.trim();
20
22
  if (!trimmed || 'unknown' === trimmed.toLowerCase()) return;
21
23
  return trimmed;
22
24
  }
23
25
  function setEventModel(event, model) {
24
- if (!model) return;
25
- event.llmModel = model;
26
+ const normalizedModel = normalizeModel(model);
27
+ if (!normalizedModel) return;
28
+ event.llmModel = normalizedModel;
26
29
  event.llmModelSource = 'self_reported';
27
30
  }
28
31
  export { addModelParameterToTool, addModelParameterToTools, getModelArgument, getModelDescription, isCaptureModelEnabled, setEventModel };
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -13,7 +17,7 @@ var __webpack_require__ = {};
13
17
  })();
14
18
  (()=>{
15
19
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
21
  value: 'Module'
18
22
  });
19
23
  Object.defineProperty(exports1, '__esModule', {
@@ -24,12 +28,12 @@ var __webpack_require__ = {};
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
30
  __webpack_require__.d(__webpack_exports__, {
27
- mirrorInstructionsIntoStructuredContent: ()=>mirrorInstructionsIntoStructuredContent,
31
+ MCP_INSTRUCTIONS_KEY: ()=>MCP_INSTRUCTIONS_KEY,
28
32
  addInstructionsToOutputSchema: ()=>addInstructionsToOutputSchema,
29
33
  addInstructionsToOutputSchemas: ()=>addInstructionsToOutputSchemas,
30
- MCP_INSTRUCTIONS_KEY: ()=>MCP_INSTRUCTIONS_KEY,
31
34
  buildConversationInstructions: ()=>buildConversationInstructions,
32
- canDeclareOutputInstructions: ()=>canDeclareOutputInstructions
35
+ canDeclareOutputInstructions: ()=>canDeclareOutputInstructions,
36
+ mirrorInstructionsIntoStructuredContent: ()=>mirrorInstructionsIntoStructuredContent
33
37
  });
34
38
  const external_logger_js_namespaceObject = require("./logger.js");
35
39
  const MCP_INSTRUCTIONS_KEY = '_mcp_instructions';
@@ -113,14 +117,14 @@ exports.addInstructionsToOutputSchemas = __webpack_exports__.addInstructionsToOu
113
117
  exports.buildConversationInstructions = __webpack_exports__.buildConversationInstructions;
114
118
  exports.canDeclareOutputInstructions = __webpack_exports__.canDeclareOutputInstructions;
115
119
  exports.mirrorInstructionsIntoStructuredContent = __webpack_exports__.mirrorInstructionsIntoStructuredContent;
116
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
120
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
117
121
  "MCP_INSTRUCTIONS_KEY",
118
122
  "addInstructionsToOutputSchema",
119
123
  "addInstructionsToOutputSchemas",
120
124
  "buildConversationInstructions",
121
125
  "canDeclareOutputInstructions",
122
126
  "mirrorInstructionsIntoStructuredContent"
123
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
127
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
124
128
  Object.defineProperty(exports, '__esModule', {
125
129
  value: true
126
130
  });
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -13,7 +17,7 @@ var __webpack_require__ = {};
13
17
  })();
14
18
  (()=>{
15
19
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
21
  value: 'Module'
18
22
  });
19
23
  Object.defineProperty(exports1, '__esModule', {
@@ -153,9 +157,9 @@ function buildExceptionEvent(event) {
153
157
  };
154
158
  }
155
159
  exports.buildPostHogCaptureEvents = __webpack_exports__.buildPostHogCaptureEvents;
156
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
160
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
157
161
  "buildPostHogCaptureEvents"
158
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
162
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
159
163
  Object.defineProperty(exports, '__esModule', {
160
164
  value: true
161
165
  });
@@ -1,5 +1,5 @@
1
1
  import { PostHog, type PostHogOptions } from 'posthog-node';
2
- import type { InitializeCaptureData, MissingCapabilityCaptureData, PreparedToolCall, PrepareToolListOptions, ToolCallCaptureData, ToolsListCaptureData } from '../types';
2
+ import type { InitializeCaptureData, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PrepareToolCallOptions, PrepareToolListOptions, ToolCallCaptureData, ToolsListCaptureData } from '../types';
3
3
  import { type ContextInjectableTool } from './context-parameters';
4
4
  /**
5
5
  * Options for {@link PostHogMCP}. A superset of `posthog-node`'s options, plus
@@ -13,6 +13,11 @@ export interface PostHogMCPOptions extends PostHogOptions {
13
13
  * can't drift. Defaults to `get_more_tools`.
14
14
  */
15
15
  missingCapabilityToolName?: string;
16
+ /**
17
+ * Inject a required `llm_model` argument into advertised tools and capture
18
+ * the agent's self-reported value. Off by default.
19
+ */
20
+ captureModel?: MCPAnalyticsOptions['captureModel'];
16
21
  }
17
22
  /**
18
23
  * A `posthog-node` client with first-class MCP analytics. Use this when there is
@@ -32,7 +37,10 @@ export interface PostHogMCPOptions extends PostHogOptions {
32
37
  * ```ts
33
38
  * import { PostHogMCP } from "@posthog/mcp"
34
39
  *
35
- * const posthog = new PostHogMCP("phc_your_project_token", { host: "https://us.i.posthog.com" })
40
+ * const posthog = new PostHogMCP("phc_your_project_token", {
41
+ * host: "https://us.i.posthog.com",
42
+ * captureModel: true,
43
+ * })
36
44
  *
37
45
  * posthog.captureToolCall({
38
46
  * toolName: "search_docs",
@@ -64,9 +72,9 @@ export declare class PostHogMCP extends PostHog {
64
72
  /**
65
73
  * Decorate your `tools/list` response with PostHog's analytics affordances:
66
74
  * injects the `context` argument into every tool (so agents state their intent,
67
- * captured as `$mcp_intent`) and, when `reportMissing` is on, appends the
68
- * `get_more_tools` virtual tool (rename it via the `missingCapabilityToolName`
69
- * constructor option). Returns a new array; your tools are untouched.
75
+ * captured as `$mcp_intent`), injects `llm_model` when the constructor's
76
+ * `captureModel` option is enabled, and appends `get_more_tools` when
77
+ * `reportMissing` is on. Returns a new array; your tools are untouched.
70
78
  *
71
79
  * The appended `get_more_tools` descriptor carries only the base MCP tool fields
72
80
  * (name, description, input schema) — not any framework-specific fields your
@@ -85,14 +93,16 @@ export declare class PostHogMCP extends PostHog {
85
93
  */
86
94
  prepareToolList<TTool extends ContextInjectableTool>(tools: TTool[], options?: PrepareToolListOptions): TTool[];
87
95
  /**
88
- * Read an incoming `tools/call` before you dispatch it: pulls the agent's
89
- * intent off the injected `context` argument, strips `context` from the
90
- * arguments (so your handler and its schema validation never see it), and flags
96
+ * Read an incoming `tools/call` before you dispatch it: pulls analytics values
97
+ * from SDK-owned arguments, strips those arguments before validation, and flags
91
98
  * whether the call targeted the `get_more_tools` virtual tool.
92
99
  *
93
- * Pass the returned `intent` / `intentSource` to {@link captureToolCall}, and
100
+ * Pass the returned intent and model fields to {@link captureToolCall}, and
94
101
  * dispatch the returned `args` to your tool.
95
102
  *
103
+ * On stateless or multi-replica servers, pass the original tool descriptor
104
+ * so ownership does not depend on which process served `tools/list`.
105
+ *
96
106
  * This only extracts the explicit `context` argument (`intentSource:
97
107
  * 'context_parameter'`); it does not infer intent. If you run your own
98
108
  * inference, pass that string with `intentSource: 'inferred'` straight to
@@ -101,16 +111,17 @@ export declare class PostHogMCP extends PostHog {
101
111
  *
102
112
  * @example
103
113
  * ```ts
104
- * const { intent, intentSource, args, isMissingCapability } = posthog.prepareToolCall(name, rawArgs)
114
+ * const { intent, intentSource, llmModel, llmModelSource, args, isMissingCapability } =
115
+ * posthog.prepareToolCall(name, rawArgs)
105
116
  * if (isMissingCapability) {
106
- * posthog.captureMissingCapability({ context: intent, ...identity })
117
+ * posthog.captureMissingCapability({ context: intent, llmModel, llmModelSource, ...identity })
107
118
  * return getMoreToolsResult()
108
119
  * }
109
120
  * const result = await runTool(name, args)
110
121
  * posthog.captureToolCall({ toolName: name, intent, intentSource, ...identity })
111
122
  * ```
112
123
  */
113
- prepareToolCall(name: string, args?: Record<string, unknown>): PreparedToolCall;
124
+ prepareToolCall(name: string, args?: Record<string, unknown>, options?: PrepareToolCallOptions): PreparedToolCall;
114
125
  /**
115
126
  * Capture a `get_more_tools` call as a missing-capability report. Emits
116
127
  * `$mcp_missing_capability` with the agent's description as `$mcp_intent`. Reply
@@ -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;AAE3D,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;AAS7B;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,UAAW,SAAQ,OAAO;;gBAOzB,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAM3D,8FAA8F;IAC9F,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI;IAiBhD,iEAAiE;IACjE,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAUpD;;;;;OAKG;IACH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AI,EAAE,qBAAqB,GAAG,IAAI;IAUpD;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI;IAclD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,eAAe,CAAC,KAAK,SAAS,qBAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,OAAO,GAAE,sBAA2B,GAAG,KAAK,EAAE;IAiCnH;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,eAAe,CACb,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,GAAE,sBAA2B,GACnC,gBAAgB;IA0BnB;;;;OAIG;IACH,wBAAwB,CAAC,IAAI,EAAE,4BAA4B,GAAG,IAAI;CAsBnE"}
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -13,7 +17,7 @@ var __webpack_require__ = {};
13
17
  })();
14
18
  (()=>{
15
19
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
21
  value: 'Module'
18
22
  });
19
23
  Object.defineProperty(exports1, '__esModule', {
@@ -27,20 +31,25 @@ __webpack_require__.d(__webpack_exports__, {
27
31
  PostHogMCP: ()=>PostHogMCP
28
32
  });
29
33
  const external_posthog_node_namespaceObject = require("posthog-node");
34
+ const external_analytics_parameters_js_namespaceObject = require("./analytics-parameters.js");
30
35
  const external_context_parameters_js_namespaceObject = require("./context-parameters.js");
31
36
  const external_event_types_js_namespaceObject = require("./event-types.js");
32
37
  const external_exceptions_js_namespaceObject = require("./exceptions.js");
33
38
  const external_headers_js_namespaceObject = require("./headers.js");
34
39
  const external_lib_identity_js_namespaceObject = require("./lib-identity.js");
35
40
  const external_logger_js_namespaceObject = require("./logger.js");
41
+ const external_model_parameters_js_namespaceObject = require("./model-parameters.js");
36
42
  const external_sink_js_namespaceObject = require("./sink.js");
37
43
  const external_tools_js_namespaceObject = require("./tools.js");
38
44
  class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
39
45
  #sink;
40
46
  #missingCapabilityToolName;
47
+ #captureModel;
48
+ #modelParameterOwnership;
41
49
  constructor(apiKey, options = {}){
42
- super(apiKey, options), this.#sink = new external_sink_js_namespaceObject.McpEventSink(this);
50
+ super(apiKey, options), this.#sink = new external_sink_js_namespaceObject.McpEventSink(this), this.#modelParameterOwnership = new Map();
43
51
  this.#missingCapabilityToolName = options.missingCapabilityToolName ?? external_tools_js_namespaceObject.GET_MORE_TOOLS_NAME;
52
+ this.#captureModel = options.captureModel;
44
53
  (0, external_lib_identity_js_namespaceObject.applyMcpLibIdentity)(this);
45
54
  }
46
55
  captureToolCall(data) {
@@ -54,6 +63,8 @@ class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
54
63
  event.isError = data.isError;
55
64
  event.errorType = data.errorType;
56
65
  applyIntent(event, data.intent, data.intentSource);
66
+ (0, external_model_parameters_js_namespaceObject.setEventModel)(event, data.llmModel);
67
+ if (event.llmModel && data.llmModelSource) event.llmModelSource = data.llmModelSource;
57
68
  if (data.isError) event.error = (0, external_exceptions_js_namespaceObject.captureException)(data.error ?? `Tool ${data.toolName} returned an error`);
58
69
  this.#emit(event);
59
70
  }
@@ -86,15 +97,40 @@ class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
86
97
  ...prepared,
87
98
  (0, external_tools_js_namespaceObject.getReportMissingToolDescriptor)(this.#missingCapabilityToolName)
88
99
  ];
100
+ if ((0, external_model_parameters_js_namespaceObject.isCaptureModelEnabled)(this.#captureModel)) {
101
+ this.#modelParameterOwnership.clear();
102
+ const ownershipByName = new Map();
103
+ for (const tool of prepared){
104
+ if ('string' != typeof tool.name) continue;
105
+ const ownsModel = (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(tool.inputSchema, 'llm_model');
106
+ ownershipByName.set(tool.name, (ownershipByName.get(tool.name) ?? true) && ownsModel);
107
+ }
108
+ for (const [toolName, ownsModel] of ownershipByName)this.#modelParameterOwnership.set(toolName, ownsModel);
109
+ const modelDescription = (0, external_model_parameters_js_namespaceObject.getModelDescription)(this.#captureModel);
110
+ prepared = prepared.map((tool)=>'string' == typeof tool.name && false === ownershipByName.get(tool.name) ? tool : (0, external_model_parameters_js_namespaceObject.addModelParameterToTool)(tool, modelDescription));
111
+ }
89
112
  return prepared;
90
113
  }
91
- prepareToolCall(name, args) {
114
+ prepareToolCall(name, args, options = {}) {
92
115
  const rawContext = args?.context;
93
116
  const intent = 'string' == typeof rawContext && rawContext.trim() ? rawContext.trim() : void 0;
117
+ const ownsModel = (0, external_model_parameters_js_namespaceObject.isCaptureModelEnabled)(this.#captureModel) && (options.originalTool ? (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(options.originalTool.inputSchema, 'llm_model') : true === this.#modelParameterOwnership.get(name));
118
+ const llmModel = ownsModel ? (0, external_model_parameters_js_namespaceObject.getModelArgument)({
119
+ params: {
120
+ arguments: args
121
+ }
122
+ }) : void 0;
123
+ const strippedArgs = stripContext(args);
94
124
  return {
95
125
  intent,
96
126
  intentSource: intent ? 'context_parameter' : void 0,
97
- args: stripContext(args),
127
+ llmModel,
128
+ llmModelSource: llmModel ? 'self_reported' : void 0,
129
+ args: ownsModel ? (0, external_analytics_parameters_js_namespaceObject.stripOwnedAnalyticsArguments)(strippedArgs, {
130
+ context: false,
131
+ conversationId: false,
132
+ llmModel: true
133
+ }) : strippedArgs,
98
134
  isMissingCapability: name === this.#missingCapabilityToolName
99
135
  };
100
136
  }
@@ -103,6 +139,8 @@ class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
103
139
  event.resourceName = this.#missingCapabilityToolName;
104
140
  event.parameters = data.parameters;
105
141
  applyIntent(event, data.context, 'context_parameter');
142
+ (0, external_model_parameters_js_namespaceObject.setEventModel)(event, data.llmModel);
143
+ if (event.llmModel && data.llmModelSource) event.llmModelSource = data.llmModelSource;
106
144
  this.#emit(event);
107
145
  }
108
146
  #emit(event) {
@@ -138,9 +176,9 @@ function stripContext(args) {
138
176
  return rest;
139
177
  }
140
178
  exports.PostHogMCP = __webpack_exports__.PostHogMCP;
141
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
179
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
142
180
  "PostHogMCP"
143
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
181
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
144
182
  Object.defineProperty(exports, '__esModule', {
145
183
  value: true
146
184
  });
@@ -1,18 +1,23 @@
1
1
  import { PostHog } from "posthog-node";
2
+ import { analyticsOwnsParameter, stripOwnedAnalyticsArguments } from "./analytics-parameters.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";
5
6
  import { normalizeHeaderString } from "./headers.mjs";
6
7
  import { applyMcpLibIdentity } from "./lib-identity.mjs";
7
8
  import { log } from "./logger.mjs";
9
+ import { addModelParameterToTool, getModelArgument, getModelDescription, isCaptureModelEnabled, setEventModel } from "./model-parameters.mjs";
8
10
  import { McpEventSink } from "./sink.mjs";
9
11
  import { GET_MORE_TOOLS_NAME, getReportMissingToolDescriptor } from "./tools.mjs";
10
12
  class PostHogMCP extends PostHog {
11
13
  #sink;
12
14
  #missingCapabilityToolName;
15
+ #captureModel;
16
+ #modelParameterOwnership;
13
17
  constructor(apiKey, options = {}){
14
- super(apiKey, options), this.#sink = new McpEventSink(this);
18
+ super(apiKey, options), this.#sink = new McpEventSink(this), this.#modelParameterOwnership = new Map();
15
19
  this.#missingCapabilityToolName = options.missingCapabilityToolName ?? GET_MORE_TOOLS_NAME;
20
+ this.#captureModel = options.captureModel;
16
21
  applyMcpLibIdentity(this);
17
22
  }
18
23
  captureToolCall(data) {
@@ -26,6 +31,8 @@ class PostHogMCP extends PostHog {
26
31
  event.isError = data.isError;
27
32
  event.errorType = data.errorType;
28
33
  applyIntent(event, data.intent, data.intentSource);
34
+ setEventModel(event, data.llmModel);
35
+ if (event.llmModel && data.llmModelSource) event.llmModelSource = data.llmModelSource;
29
36
  if (data.isError) event.error = captureException(data.error ?? `Tool ${data.toolName} returned an error`);
30
37
  this.#emit(event);
31
38
  }
@@ -58,15 +65,40 @@ class PostHogMCP extends PostHog {
58
65
  ...prepared,
59
66
  getReportMissingToolDescriptor(this.#missingCapabilityToolName)
60
67
  ];
68
+ if (isCaptureModelEnabled(this.#captureModel)) {
69
+ this.#modelParameterOwnership.clear();
70
+ const ownershipByName = new Map();
71
+ for (const tool of prepared){
72
+ if ('string' != typeof tool.name) continue;
73
+ const ownsModel = analyticsOwnsParameter(tool.inputSchema, 'llm_model');
74
+ ownershipByName.set(tool.name, (ownershipByName.get(tool.name) ?? true) && ownsModel);
75
+ }
76
+ for (const [toolName, ownsModel] of ownershipByName)this.#modelParameterOwnership.set(toolName, ownsModel);
77
+ const modelDescription = getModelDescription(this.#captureModel);
78
+ prepared = prepared.map((tool)=>'string' == typeof tool.name && false === ownershipByName.get(tool.name) ? tool : addModelParameterToTool(tool, modelDescription));
79
+ }
61
80
  return prepared;
62
81
  }
63
- prepareToolCall(name, args) {
82
+ prepareToolCall(name, args, options = {}) {
64
83
  const rawContext = args?.context;
65
84
  const intent = 'string' == typeof rawContext && rawContext.trim() ? rawContext.trim() : void 0;
85
+ const ownsModel = isCaptureModelEnabled(this.#captureModel) && (options.originalTool ? analyticsOwnsParameter(options.originalTool.inputSchema, 'llm_model') : true === this.#modelParameterOwnership.get(name));
86
+ const llmModel = ownsModel ? getModelArgument({
87
+ params: {
88
+ arguments: args
89
+ }
90
+ }) : void 0;
91
+ const strippedArgs = stripContext(args);
66
92
  return {
67
93
  intent,
68
94
  intentSource: intent ? 'context_parameter' : void 0,
69
- args: stripContext(args),
95
+ llmModel,
96
+ llmModelSource: llmModel ? 'self_reported' : void 0,
97
+ args: ownsModel ? stripOwnedAnalyticsArguments(strippedArgs, {
98
+ context: false,
99
+ conversationId: false,
100
+ llmModel: true
101
+ }) : strippedArgs,
70
102
  isMissingCapability: name === this.#missingCapabilityToolName
71
103
  };
72
104
  }
@@ -75,6 +107,8 @@ class PostHogMCP extends PostHog {
75
107
  event.resourceName = this.#missingCapabilityToolName;
76
108
  event.parameters = data.parameters;
77
109
  applyIntent(event, data.context, 'context_parameter');
110
+ setEventModel(event, data.llmModel);
111
+ if (event.llmModel && data.llmModelSource) event.llmModelSource = data.llmModelSource;
78
112
  this.#emit(event);
79
113
  }
80
114
  #emit(event) {