@posthog/mcp 0.11.7 → 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.
- package/README.md +51 -2
- package/dist/extensions/analytics-parameters.d.ts +22 -2
- package/dist/extensions/analytics-parameters.d.ts.map +1 -1
- package/dist/extensions/analytics-parameters.js +53 -10
- package/dist/extensions/analytics-parameters.mjs +37 -1
- package/dist/extensions/capture.d.ts.map +1 -1
- package/dist/extensions/capture.js +14 -8
- package/dist/extensions/capture.mjs +2 -0
- package/dist/extensions/client-identity.js +18 -14
- package/dist/extensions/compatibility.js +16 -12
- package/dist/extensions/constants.d.ts +3 -0
- package/dist/extensions/constants.d.ts.map +1 -1
- package/dist/extensions/constants.js +28 -18
- package/dist/extensions/constants.mjs +5 -2
- package/dist/extensions/context-parameters.d.ts +2 -2
- package/dist/extensions/context-parameters.d.ts.map +1 -1
- package/dist/extensions/context-parameters.js +14 -38
- package/dist/extensions/context-parameters.mjs +2 -30
- package/dist/extensions/conversation-id.js +18 -14
- package/dist/extensions/detect.js +23 -19
- package/dist/extensions/event-types.js +15 -11
- package/dist/extensions/exceptions.js +12 -8
- package/dist/extensions/headers.js +16 -12
- package/dist/extensions/ids.js +12 -8
- package/dist/extensions/instrument-highlevel.d.ts.map +1 -1
- package/dist/extensions/instrument-highlevel.js +16 -9
- package/dist/extensions/instrument-highlevel.mjs +5 -2
- package/dist/extensions/instrument-lowlevel.d.ts.map +1 -1
- package/dist/extensions/instrument-lowlevel.js +13 -8
- package/dist/extensions/instrument-lowlevel.mjs +2 -1
- package/dist/extensions/instrumentation.d.ts +16 -0
- package/dist/extensions/instrumentation.d.ts.map +1 -1
- package/dist/extensions/instrumentation.js +31 -14
- package/dist/extensions/instrumentation.mjs +11 -1
- package/dist/extensions/intent.js +14 -10
- package/dist/extensions/internal.js +17 -13
- package/dist/extensions/lib-identity.js +12 -8
- package/dist/extensions/logger.js +17 -13
- package/dist/extensions/mcp-payloads.js +16 -12
- package/dist/extensions/mcp-sdk-compat.js +23 -19
- package/dist/extensions/model-parameters.d.ts +48 -0
- package/dist/extensions/model-parameters.d.ts.map +1 -0
- package/dist/extensions/model-parameters.js +84 -0
- package/dist/extensions/model-parameters.mjs +31 -0
- package/dist/extensions/output-instructions.js +15 -11
- package/dist/extensions/posthog-events.js +14 -8
- package/dist/extensions/posthog-events.mjs +2 -0
- package/dist/extensions/posthog-mcp.d.ts +23 -12
- package/dist/extensions/posthog-mcp.d.ts.map +1 -1
- package/dist/extensions/posthog-mcp.js +49 -11
- package/dist/extensions/posthog-mcp.mjs +37 -3
- package/dist/extensions/request-headers.js +15 -11
- package/dist/extensions/sanitization.d.ts +2 -2
- package/dist/extensions/sanitization.d.ts.map +1 -1
- package/dist/extensions/sanitization.js +13 -8
- package/dist/extensions/sanitization.mjs +1 -0
- package/dist/extensions/session-token.js +17 -13
- package/dist/extensions/session-token.mjs +2 -2
- package/dist/extensions/session.js +16 -12
- package/dist/extensions/sink.js +14 -10
- package/dist/extensions/tools.js +15 -11
- package/dist/extensions/tracing-helpers.js +15 -11
- package/dist/extensions/transport-identity.js +15 -11
- package/dist/extensions/truncation.d.ts.map +1 -1
- package/dist/extensions/truncation.js +22 -16
- package/dist/extensions/truncation.mjs +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -18
- package/dist/index.mjs +7 -7
- package/dist/types.d.ts +55 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.mjs +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +15 -11
- package/dist/version.mjs +1 -1
- package/package.json +28 -11
- package/src/extensions/analytics-parameters.ts +88 -2
- package/src/extensions/capture.ts +4 -0
- package/src/extensions/constants.ts +4 -0
- package/src/extensions/context-parameters.ts +10 -59
- package/src/extensions/instrument-highlevel.ts +4 -0
- package/src/extensions/instrument-lowlevel.ts +2 -0
- package/src/extensions/instrumentation.ts +51 -0
- package/src/extensions/model-parameters.ts +98 -0
- package/src/extensions/posthog-events.ts +8 -0
- package/src/extensions/posthog-mcp.ts +84 -12
- package/src/extensions/sanitization.ts +6 -2
- package/src/extensions/truncation.ts +3 -0
- package/src/index.ts +3 -0
- package/src/types.ts +55 -4
- package/src/version.ts +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { MCPAnalyticsOptions, MCPRequestLike, McpEvent } from '../types';
|
|
2
|
+
import { type AnalyticsInjectableJsonSchema } from './analytics-parameters';
|
|
3
|
+
import { type LoggerFn } from './logger';
|
|
4
|
+
/**
|
|
5
|
+
* Self-reported model capture (`captureModel`).
|
|
6
|
+
*
|
|
7
|
+
* MCP keeps servers deliberately model-ignorant: the wire carries client
|
|
8
|
+
* name/version and protocol version, never the LLM behind the client, and no
|
|
9
|
+
* spec revision changes that. The one place the information exists on the
|
|
10
|
+
* server side of the connection is the agent itself — harnesses inject the
|
|
11
|
+
* model id into the system prompt, so the agent can state it the same way it
|
|
12
|
+
* states its intent through the `context` parameter.
|
|
13
|
+
*
|
|
14
|
+
* This module injects a required `llm_model` string parameter into every tool
|
|
15
|
+
* (mirroring `context-parameters.ts`), strips it before the tool runs, and
|
|
16
|
+
* captures it as `$mcp_llm_model` with `$mcp_llm_model_source = "self_reported"`.
|
|
17
|
+
* The source property is deliberate: like `clientInfo` in the MCP spec, the
|
|
18
|
+
* value is self-reported and unverified — right for degradation analytics
|
|
19
|
+
* ("does our MCP get worse on model X?"), never for billing or security.
|
|
20
|
+
*
|
|
21
|
+
* Reasoning effort is deliberately NOT captured: it never crosses the wire,
|
|
22
|
+
* and models cannot reliably self-report it (harnesses apply it as a sampling
|
|
23
|
+
* parameter the model never sees), so any captured value would be noise.
|
|
24
|
+
*/
|
|
25
|
+
export interface ModelInjectableTool {
|
|
26
|
+
inputSchema?: AnalyticsInjectableJsonSchema;
|
|
27
|
+
name?: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
/** Unlike `context`, model capture is opt-in: off unless explicitly enabled. */
|
|
31
|
+
export declare function isCaptureModelEnabled(captureModel: MCPAnalyticsOptions['captureModel']): boolean;
|
|
32
|
+
export declare function getModelDescription(captureModel: MCPAnalyticsOptions['captureModel']): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Adds an `llm_model` parameter to a tool's JSON Schema, via the shared
|
|
35
|
+
* injector so schema handling stays identical to `context`: a tool that already
|
|
36
|
+
* declares `llm_model` owns it, and complex schemas can't safely gain keys.
|
|
37
|
+
*/
|
|
38
|
+
export declare function addModelParameterToTool<TTool extends ModelInjectableTool>(tool: TTool, modelDescriptionOverride?: string, logger?: LoggerFn): TTool;
|
|
39
|
+
export declare function addModelParameterToTools<TTool extends ModelInjectableTool>(tools: TTool[], modelDescriptionOverride?: string, logger?: LoggerFn): TTool[];
|
|
40
|
+
/**
|
|
41
|
+
* Reads the self-reported model off a tool-call request. Returns `undefined`
|
|
42
|
+
* for a missing, blank, or `"unknown"` value — the parameter description asks
|
|
43
|
+
* agents to pass `unknown` when uncertain, and an honest "I don't know" must
|
|
44
|
+
* not become a property value queries would group by.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getModelArgument(request: MCPRequestLike): string | undefined;
|
|
47
|
+
export declare function setEventModel(event: McpEvent, model: string | undefined): void;
|
|
48
|
+
//# sourceMappingURL=model-parameters.d.ts.map
|
|
@@ -0,0 +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,CAAC,GAAG,MAAM,GAAG,SAAS,CAEzG;AAED;;;;GAIG;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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
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");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
addModelParameterToTool: ()=>addModelParameterToTool,
|
|
32
|
+
addModelParameterToTools: ()=>addModelParameterToTools,
|
|
33
|
+
getModelArgument: ()=>getModelArgument,
|
|
34
|
+
getModelDescription: ()=>getModelDescription,
|
|
35
|
+
isCaptureModelEnabled: ()=>isCaptureModelEnabled,
|
|
36
|
+
setEventModel: ()=>setEventModel
|
|
37
|
+
});
|
|
38
|
+
const external_analytics_parameters_js_namespaceObject = require("./analytics-parameters.js");
|
|
39
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
40
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
41
|
+
function isCaptureModelEnabled(captureModel) {
|
|
42
|
+
return true === captureModel || 'object' == typeof captureModel && null !== captureModel;
|
|
43
|
+
}
|
|
44
|
+
function getModelDescription(captureModel) {
|
|
45
|
+
return 'object' == typeof captureModel && null !== captureModel ? captureModel.description : void 0;
|
|
46
|
+
}
|
|
47
|
+
function addModelParameterToTool(tool, modelDescriptionOverride, logger = external_logger_js_namespaceObject.log) {
|
|
48
|
+
return (0, external_analytics_parameters_js_namespaceObject.addAnalyticsParameterToTool)(tool, 'llm_model', modelDescriptionOverride || external_constants_js_namespaceObject.DEFAULT_MODEL_PARAMETER_DESCRIPTION, 'model', logger);
|
|
49
|
+
}
|
|
50
|
+
function addModelParameterToTools(tools, modelDescriptionOverride, logger = external_logger_js_namespaceObject.log) {
|
|
51
|
+
return tools.map((tool)=>addModelParameterToTool(tool, modelDescriptionOverride, logger));
|
|
52
|
+
}
|
|
53
|
+
function getModelArgument(request) {
|
|
54
|
+
return normalizeModel(request.params?.arguments?.llm_model);
|
|
55
|
+
}
|
|
56
|
+
function normalizeModel(model) {
|
|
57
|
+
if ('string' != typeof model) return;
|
|
58
|
+
const trimmed = model.trim();
|
|
59
|
+
if (!trimmed || 'unknown' === trimmed.toLowerCase()) return;
|
|
60
|
+
return trimmed;
|
|
61
|
+
}
|
|
62
|
+
function setEventModel(event, model) {
|
|
63
|
+
const normalizedModel = normalizeModel(model);
|
|
64
|
+
if (!normalizedModel) return;
|
|
65
|
+
event.llmModel = normalizedModel;
|
|
66
|
+
event.llmModelSource = 'self_reported';
|
|
67
|
+
}
|
|
68
|
+
exports.addModelParameterToTool = __webpack_exports__.addModelParameterToTool;
|
|
69
|
+
exports.addModelParameterToTools = __webpack_exports__.addModelParameterToTools;
|
|
70
|
+
exports.getModelArgument = __webpack_exports__.getModelArgument;
|
|
71
|
+
exports.getModelDescription = __webpack_exports__.getModelDescription;
|
|
72
|
+
exports.isCaptureModelEnabled = __webpack_exports__.isCaptureModelEnabled;
|
|
73
|
+
exports.setEventModel = __webpack_exports__.setEventModel;
|
|
74
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
75
|
+
"addModelParameterToTool",
|
|
76
|
+
"addModelParameterToTools",
|
|
77
|
+
"getModelArgument",
|
|
78
|
+
"getModelDescription",
|
|
79
|
+
"isCaptureModelEnabled",
|
|
80
|
+
"setEventModel"
|
|
81
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
82
|
+
Object.defineProperty(exports, '__esModule', {
|
|
83
|
+
value: true
|
|
84
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { addAnalyticsParameterToTool } from "./analytics-parameters.mjs";
|
|
2
|
+
import { DEFAULT_MODEL_PARAMETER_DESCRIPTION } from "./constants.mjs";
|
|
3
|
+
import { log } from "./logger.mjs";
|
|
4
|
+
function isCaptureModelEnabled(captureModel) {
|
|
5
|
+
return true === captureModel || 'object' == typeof captureModel && null !== captureModel;
|
|
6
|
+
}
|
|
7
|
+
function getModelDescription(captureModel) {
|
|
8
|
+
return 'object' == typeof captureModel && null !== captureModel ? captureModel.description : void 0;
|
|
9
|
+
}
|
|
10
|
+
function addModelParameterToTool(tool, modelDescriptionOverride, logger = log) {
|
|
11
|
+
return addAnalyticsParameterToTool(tool, 'llm_model', modelDescriptionOverride || DEFAULT_MODEL_PARAMETER_DESCRIPTION, 'model', logger);
|
|
12
|
+
}
|
|
13
|
+
function addModelParameterToTools(tools, modelDescriptionOverride, logger = log) {
|
|
14
|
+
return tools.map((tool)=>addModelParameterToTool(tool, modelDescriptionOverride, logger));
|
|
15
|
+
}
|
|
16
|
+
function getModelArgument(request) {
|
|
17
|
+
return normalizeModel(request.params?.arguments?.llm_model);
|
|
18
|
+
}
|
|
19
|
+
function normalizeModel(model) {
|
|
20
|
+
if ('string' != typeof model) return;
|
|
21
|
+
const trimmed = model.trim();
|
|
22
|
+
if (!trimmed || 'unknown' === trimmed.toLowerCase()) return;
|
|
23
|
+
return trimmed;
|
|
24
|
+
}
|
|
25
|
+
function setEventModel(event, model) {
|
|
26
|
+
const normalizedModel = normalizeModel(model);
|
|
27
|
+
if (!normalizedModel) return;
|
|
28
|
+
event.llmModel = normalizedModel;
|
|
29
|
+
event.llmModelSource = 'self_reported';
|
|
30
|
+
}
|
|
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,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
|
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(
|
|
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,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 (
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
21
|
value: 'Module'
|
|
18
22
|
});
|
|
19
23
|
Object.defineProperty(exports1, '__esModule', {
|
|
@@ -103,6 +107,8 @@ function addCommonEventProperties(event, properties) {
|
|
|
103
107
|
if (event.protocolVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ProtocolVersion] = event.protocolVersion;
|
|
104
108
|
if (event.userIntent) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.Intent] = event.userIntent;
|
|
105
109
|
if (event.userIntentSource) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.IntentSource] = event.userIntentSource;
|
|
110
|
+
if (event.llmModel) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.LlmModel] = event.llmModel;
|
|
111
|
+
if (event.llmModelSource) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.LlmModelSource] = event.llmModelSource;
|
|
106
112
|
if (void 0 !== event.isError) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.IsError] = event.isError;
|
|
107
113
|
if (event.isError) {
|
|
108
114
|
const firstException = event.error?.$exception_list?.[0];
|
|
@@ -151,9 +157,9 @@ function buildExceptionEvent(event) {
|
|
|
151
157
|
};
|
|
152
158
|
}
|
|
153
159
|
exports.buildPostHogCaptureEvents = __webpack_exports__.buildPostHogCaptureEvents;
|
|
154
|
-
for(var
|
|
160
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
155
161
|
"buildPostHogCaptureEvents"
|
|
156
|
-
].indexOf(
|
|
162
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
157
163
|
Object.defineProperty(exports, '__esModule', {
|
|
158
164
|
value: true
|
|
159
165
|
});
|
|
@@ -75,6 +75,8 @@ function addCommonEventProperties(event, properties) {
|
|
|
75
75
|
if (event.protocolVersion) properties[PostHogMCPAnalyticsProperty.ProtocolVersion] = event.protocolVersion;
|
|
76
76
|
if (event.userIntent) properties[PostHogMCPAnalyticsProperty.Intent] = event.userIntent;
|
|
77
77
|
if (event.userIntentSource) properties[PostHogMCPAnalyticsProperty.IntentSource] = event.userIntentSource;
|
|
78
|
+
if (event.llmModel) properties[PostHogMCPAnalyticsProperty.LlmModel] = event.llmModel;
|
|
79
|
+
if (event.llmModelSource) properties[PostHogMCPAnalyticsProperty.LlmModelSource] = event.llmModelSource;
|
|
78
80
|
if (void 0 !== event.isError) properties[PostHogMCPAnalyticsProperty.IsError] = event.isError;
|
|
79
81
|
if (event.isError) {
|
|
80
82
|
const firstException = event.error?.$exception_list?.[0];
|
|
@@ -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", {
|
|
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`)
|
|
68
|
-
* `
|
|
69
|
-
*
|
|
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
|
|
89
|
-
*
|
|
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
|
|
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 } =
|
|
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
|
|
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,
|
|
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,EAErB,mBAAmB,EAGnB,4BAA4B,EAC5B,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAA;AAgB7B;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC;;;OAGG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;CACnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,UAAW,SAAQ,OAAO;;gBASzB,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAO3D,8FAA8F;IAC9F,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI;IAqBhD,iEAAiE;IACjE,iBAAiB,CAAC,IAAI,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,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
|
179
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
142
180
|
"PostHogMCP"
|
|
143
|
-
].indexOf(
|
|
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
|
-
|
|
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) {
|