@posthog/mcp 0.11.6 → 0.12.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/analytics-parameters.d.ts +22 -2
- package/dist/extensions/analytics-parameters.d.ts.map +1 -1
- package/dist/extensions/analytics-parameters.js +39 -0
- package/dist/extensions/analytics-parameters.mjs +37 -1
- package/dist/extensions/capture.d.ts.map +1 -1
- package/dist/extensions/capture.js +2 -0
- package/dist/extensions/capture.mjs +2 -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/context-parameters.d.ts +2 -2
- package/dist/extensions/context-parameters.d.ts.map +1 -1
- package/dist/extensions/context-parameters.js +1 -29
- package/dist/extensions/context-parameters.mjs +2 -30
- package/dist/extensions/conversation-id.d.ts.map +1 -1
- package/dist/extensions/conversation-id.js +3 -1
- package/dist/extensions/conversation-id.mjs +3 -1
- package/dist/extensions/instrument-highlevel.d.ts.map +1 -1
- package/dist/extensions/instrument-highlevel.js +4 -1
- package/dist/extensions/instrument-highlevel.mjs +5 -2
- package/dist/extensions/instrument-lowlevel.d.ts.map +1 -1
- package/dist/extensions/instrument-lowlevel.js +1 -0
- 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 +15 -2
- package/dist/extensions/instrumentation.mjs +11 -1
- 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 +77 -0
- package/dist/extensions/model-parameters.mjs +28 -0
- package/dist/extensions/output-instructions.d.ts +0 -1
- package/dist/extensions/output-instructions.d.ts.map +1 -1
- package/dist/extensions/output-instructions.js +3 -8
- package/dist/extensions/output-instructions.mjs +3 -8
- package/dist/extensions/posthog-events.js +2 -0
- package/dist/extensions/posthog-events.mjs +2 -0
- package/dist/extensions/truncation.d.ts.map +1 -1
- package/dist/extensions/truncation.js +1 -0
- package/dist/extensions/truncation.mjs +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +28 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +24 -7
- 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/conversation-id.ts +4 -1
- 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 +94 -0
- package/src/extensions/output-instructions.ts +3 -9
- package/src/extensions/posthog-events.ts +8 -0
- package/src/extensions/truncation.ts +3 -0
- package/src/index.ts +2 -0
- package/src/types.ts +29 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -149,6 +149,35 @@ instrument(server, posthog, { // keep it, dr
|
|
|
149
149
|
|
|
150
150
|
`intentFallback` is the third option: supply the intent yourself when the agent did not send one.
|
|
151
151
|
|
|
152
|
+
### What `$mcp_llm_model` records, and when it stays empty
|
|
153
|
+
|
|
154
|
+
`captureModel` is **off** by default. Turn it on and the SDK adds a required `llm_model` parameter to
|
|
155
|
+
every tool it advertises — including the `get_more_tools` virtual tool — asks the agent which model
|
|
156
|
+
it runs as, and records the answer as `$mcp_llm_model` with `$mcp_llm_model_source = "self_reported"`.
|
|
157
|
+
|
|
158
|
+
The value is self-reported and unverified, exactly like `clientInfo` in the MCP spec. Use it to spot
|
|
159
|
+
degradation across models ("does our MCP get worse on model X?"), never for billing or access
|
|
160
|
+
control. An agent that answers `unknown` is recorded as nothing rather than as a model called
|
|
161
|
+
"unknown".
|
|
162
|
+
|
|
163
|
+
Unlike `context`, this option degrades to **silence** rather than to a kept argument. Both the strip
|
|
164
|
+
and the capture require the SDK to have confirmed the parameter is its own:
|
|
165
|
+
|
|
166
|
+
- `instrument(server)` on a high-level `McpServer` resolves ownership for your registered tools per
|
|
167
|
+
request from the live tool registry, so those work even on a fresh instance.
|
|
168
|
+
- The `get_more_tools` virtual tool works on any instance and on either server type: the SDK writes
|
|
169
|
+
that descriptor itself, so what it declares is known without a listing.
|
|
170
|
+
- Instrumenting a low-level `Server` learns ownership of **your** tools while serving `tools/list`.
|
|
171
|
+
On a server that builds a fresh instance per HTTP request — `createMcpHandler`, or
|
|
172
|
+
`@rekog/mcp-nest` in its stateless mode — the instance handling a `tools/call` never served one,
|
|
173
|
+
so for those tools it neither strips `llm_model` nor records `$mcp_llm_model`. Nothing breaks and
|
|
174
|
+
no wrong value is stored; the property is simply absent while agents still pay a token for the
|
|
175
|
+
extra field.
|
|
176
|
+
|
|
177
|
+
As with `context`, what matters is instance lifetime rather than statelessness: a transport-stateless
|
|
178
|
+
server (`sessionIdGenerator: undefined`) that keeps one long-lived server object learns ownership
|
|
179
|
+
from the first `tools/list` and keeps it.
|
|
180
|
+
|
|
152
181
|
### If you switched to `instrument(server.server)`
|
|
153
182
|
|
|
154
183
|
Before v2 support landed, the compatibility gate rejected high-level v2 servers, and the usual
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AnalyticsParameterOwnership } from '../types';
|
|
2
|
+
import { type LoggerFn } from './logger';
|
|
2
3
|
export interface AnalyticsInjectableJsonSchema {
|
|
3
4
|
$ref?: unknown;
|
|
4
5
|
additionalProperties?: boolean;
|
|
@@ -11,12 +12,31 @@ export interface AnalyticsInjectableJsonSchema {
|
|
|
11
12
|
}
|
|
12
13
|
export declare function hasAnalyticsParameter(schema: AnalyticsInjectableJsonSchema | undefined, parameterName: string): boolean;
|
|
13
14
|
export declare function canInjectAnalyticsParameter(schema: AnalyticsInjectableJsonSchema | undefined, parameterName: string): boolean;
|
|
15
|
+
export interface AnalyticsInjectableTool {
|
|
16
|
+
inputSchema?: AnalyticsInjectableJsonSchema;
|
|
17
|
+
name?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds a required string parameter to a tool's JSON Schema. Called AFTER the MCP
|
|
22
|
+
* SDK has converted Zod schemas to JSON Schema, so only JSON Schema needs
|
|
23
|
+
* handling.
|
|
24
|
+
*
|
|
25
|
+
* Shared by every analytics parameter we inject (`context`, `llm_model`) so
|
|
26
|
+
* schema ownership, cloning, and required-field behavior cannot drift between
|
|
27
|
+
* them. `injectionLabel` only names the feature in the skip warnings.
|
|
28
|
+
*
|
|
29
|
+
* Skips injection (with a warning) for:
|
|
30
|
+
* - Tools that already declare the parameter — it is theirs, not ours
|
|
31
|
+
* - Complex schemas (oneOf/allOf/anyOf/$ref) that can't safely gain properties
|
|
32
|
+
*/
|
|
33
|
+
export declare function addAnalyticsParameterToTool<TTool extends AnalyticsInjectableTool>(tool: TTool, parameterName: string, description: string, injectionLabel: string, logger?: LoggerFn): TTool;
|
|
14
34
|
export declare function analyticsOwnsParameter(inputSchema: unknown, parameterName: string): boolean;
|
|
15
35
|
export declare function getAnalyticsParameterOwnership(inputSchema: unknown, outputSchema?: unknown): AnalyticsParameterOwnership;
|
|
16
36
|
/**
|
|
17
37
|
* Removes the arguments we injected, leaving the host's own. Input-side only, so
|
|
18
|
-
* it takes just those
|
|
38
|
+
* it takes just those flags rather than the whole ownership record — callers
|
|
19
39
|
* that have no output-schema context should not have to invent a value for it.
|
|
20
40
|
*/
|
|
21
|
-
export declare function stripOwnedAnalyticsArguments(args: unknown, ownership: Pick<AnalyticsParameterOwnership, 'context' | 'conversationId'>): unknown;
|
|
41
|
+
export declare function stripOwnedAnalyticsArguments(args: unknown, ownership: Pick<AnalyticsParameterOwnership, 'context' | 'conversationId' | 'llmModel'>): unknown;
|
|
22
42
|
//# sourceMappingURL=analytics-parameters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics-parameters.d.ts","sourceRoot":"","sources":["../../src/extensions/analytics-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"analytics-parameters.d.ts","sourceRoot":"","sources":["../../src/extensions/analytics-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAiB7C,MAAM,WAAW,6BAA6B;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,6BAA6B,GAAG,SAAS,EACjD,aAAa,EAAE,MAAM,GACpB,OAAO,CAET;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,6BAA6B,GAAG,SAAS,EACjD,aAAa,EAAE,MAAM,GACpB,OAAO,CAIT;AAED,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,SAAS,uBAAuB,EAC/E,IAAI,EAAE,KAAK,EACX,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,MAAM,GAAE,QAAc,GACrB,KAAK,CAqDP;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAyB3F;AAED,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,OAAO,EACpB,YAAY,CAAC,EAAE,OAAO,GACrB,2BAA2B,CAO7B;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,IAAI,CAAC,2BAA2B,EAAE,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC,GACtF,OAAO,CAeT"}
|
|
@@ -24,12 +24,14 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
addAnalyticsParameterToTool: ()=>addAnalyticsParameterToTool,
|
|
27
28
|
hasAnalyticsParameter: ()=>hasAnalyticsParameter,
|
|
28
29
|
analyticsOwnsParameter: ()=>analyticsOwnsParameter,
|
|
29
30
|
getAnalyticsParameterOwnership: ()=>getAnalyticsParameterOwnership,
|
|
30
31
|
canInjectAnalyticsParameter: ()=>canInjectAnalyticsParameter,
|
|
31
32
|
stripOwnedAnalyticsArguments: ()=>stripOwnedAnalyticsArguments
|
|
32
33
|
});
|
|
34
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
33
35
|
const external_mcp_sdk_compat_js_namespaceObject = require("./mcp-sdk-compat.js");
|
|
34
36
|
const external_output_instructions_js_namespaceObject = require("./output-instructions.js");
|
|
35
37
|
const JSON_SCHEMA_KEYWORDS = [
|
|
@@ -50,6 +52,36 @@ function hasAnalyticsParameter(schema, parameterName) {
|
|
|
50
52
|
function canInjectAnalyticsParameter(schema, parameterName) {
|
|
51
53
|
return !hasAnalyticsParameter(schema, parameterName) && !schema?.$ref && !schema?.oneOf && !schema?.allOf && !schema?.anyOf;
|
|
52
54
|
}
|
|
55
|
+
function addAnalyticsParameterToTool(tool, parameterName, description, injectionLabel, logger = external_logger_js_namespaceObject.log) {
|
|
56
|
+
const modifiedTool = {
|
|
57
|
+
...tool
|
|
58
|
+
};
|
|
59
|
+
const toolName = tool.name || 'unknown';
|
|
60
|
+
const schema = modifiedTool.inputSchema;
|
|
61
|
+
if (!canInjectAnalyticsParameter(schema, parameterName)) {
|
|
62
|
+
logger(hasAnalyticsParameter(schema, parameterName) ? `WARN: Tool "${toolName}" already has '${parameterName}' parameter. Skipping ${injectionLabel} injection.` : `WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf/$ref). Skipping ${injectionLabel} injection.`);
|
|
63
|
+
return modifiedTool;
|
|
64
|
+
}
|
|
65
|
+
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {},
|
|
68
|
+
required: []
|
|
69
|
+
};
|
|
70
|
+
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
71
|
+
const inputSchema = modifiedTool.inputSchema;
|
|
72
|
+
if (!inputSchema.properties) inputSchema.properties = {};
|
|
73
|
+
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
74
|
+
inputSchema.properties[parameterName] = {
|
|
75
|
+
type: 'string',
|
|
76
|
+
description
|
|
77
|
+
};
|
|
78
|
+
if (Array.isArray(inputSchema.required)) {
|
|
79
|
+
if (!inputSchema.required.includes(parameterName)) inputSchema.required.push(parameterName);
|
|
80
|
+
} else inputSchema.required = [
|
|
81
|
+
parameterName
|
|
82
|
+
];
|
|
83
|
+
return modifiedTool;
|
|
84
|
+
}
|
|
53
85
|
function analyticsOwnsParameter(inputSchema, parameterName) {
|
|
54
86
|
if (!inputSchema || 'object' != typeof inputSchema) return canInjectAnalyticsParameter(void 0, parameterName);
|
|
55
87
|
if ((0, external_mcp_sdk_compat_js_namespaceObject.isZodRawShapeCompat)(inputSchema)) return canInjectAnalyticsParameter({
|
|
@@ -68,6 +100,7 @@ function getAnalyticsParameterOwnership(inputSchema, outputSchema) {
|
|
|
68
100
|
return {
|
|
69
101
|
context: analyticsOwnsParameter(inputSchema, 'context'),
|
|
70
102
|
conversationId: analyticsOwnsParameter(inputSchema, 'conversation_id'),
|
|
103
|
+
llmModel: analyticsOwnsParameter(inputSchema, 'llm_model'),
|
|
71
104
|
outputInstructions: (0, external_output_instructions_js_namespaceObject.canDeclareOutputInstructions)(outputSchema)
|
|
72
105
|
};
|
|
73
106
|
}
|
|
@@ -81,14 +114,20 @@ function stripOwnedAnalyticsArguments(args, ownership) {
|
|
|
81
114
|
const { conversation_id: _conversationId, ...rest } = cleanedArgs;
|
|
82
115
|
cleanedArgs = rest;
|
|
83
116
|
}
|
|
117
|
+
if (ownership.llmModel && cleanedArgs && 'object' == typeof cleanedArgs && 'llm_model' in cleanedArgs) {
|
|
118
|
+
const { llm_model: _llmModel, ...rest } = cleanedArgs;
|
|
119
|
+
cleanedArgs = rest;
|
|
120
|
+
}
|
|
84
121
|
return cleanedArgs;
|
|
85
122
|
}
|
|
123
|
+
exports.addAnalyticsParameterToTool = __webpack_exports__.addAnalyticsParameterToTool;
|
|
86
124
|
exports.analyticsOwnsParameter = __webpack_exports__.analyticsOwnsParameter;
|
|
87
125
|
exports.canInjectAnalyticsParameter = __webpack_exports__.canInjectAnalyticsParameter;
|
|
88
126
|
exports.getAnalyticsParameterOwnership = __webpack_exports__.getAnalyticsParameterOwnership;
|
|
89
127
|
exports.hasAnalyticsParameter = __webpack_exports__.hasAnalyticsParameter;
|
|
90
128
|
exports.stripOwnedAnalyticsArguments = __webpack_exports__.stripOwnedAnalyticsArguments;
|
|
91
129
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
130
|
+
"addAnalyticsParameterToTool",
|
|
92
131
|
"analyticsOwnsParameter",
|
|
93
132
|
"canInjectAnalyticsParameter",
|
|
94
133
|
"getAnalyticsParameterOwnership",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { log } from "./logger.mjs";
|
|
1
2
|
import { getObjectShape, isZodRawShapeCompat } from "./mcp-sdk-compat.mjs";
|
|
2
3
|
import { canDeclareOutputInstructions } from "./output-instructions.mjs";
|
|
3
4
|
const JSON_SCHEMA_KEYWORDS = [
|
|
@@ -18,6 +19,36 @@ function hasAnalyticsParameter(schema, parameterName) {
|
|
|
18
19
|
function canInjectAnalyticsParameter(schema, parameterName) {
|
|
19
20
|
return !hasAnalyticsParameter(schema, parameterName) && !schema?.$ref && !schema?.oneOf && !schema?.allOf && !schema?.anyOf;
|
|
20
21
|
}
|
|
22
|
+
function addAnalyticsParameterToTool(tool, parameterName, description, injectionLabel, logger = log) {
|
|
23
|
+
const modifiedTool = {
|
|
24
|
+
...tool
|
|
25
|
+
};
|
|
26
|
+
const toolName = tool.name || 'unknown';
|
|
27
|
+
const schema = modifiedTool.inputSchema;
|
|
28
|
+
if (!canInjectAnalyticsParameter(schema, parameterName)) {
|
|
29
|
+
logger(hasAnalyticsParameter(schema, parameterName) ? `WARN: Tool "${toolName}" already has '${parameterName}' parameter. Skipping ${injectionLabel} injection.` : `WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf/$ref). Skipping ${injectionLabel} injection.`);
|
|
30
|
+
return modifiedTool;
|
|
31
|
+
}
|
|
32
|
+
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {},
|
|
35
|
+
required: []
|
|
36
|
+
};
|
|
37
|
+
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
38
|
+
const inputSchema = modifiedTool.inputSchema;
|
|
39
|
+
if (!inputSchema.properties) inputSchema.properties = {};
|
|
40
|
+
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
41
|
+
inputSchema.properties[parameterName] = {
|
|
42
|
+
type: 'string',
|
|
43
|
+
description
|
|
44
|
+
};
|
|
45
|
+
if (Array.isArray(inputSchema.required)) {
|
|
46
|
+
if (!inputSchema.required.includes(parameterName)) inputSchema.required.push(parameterName);
|
|
47
|
+
} else inputSchema.required = [
|
|
48
|
+
parameterName
|
|
49
|
+
];
|
|
50
|
+
return modifiedTool;
|
|
51
|
+
}
|
|
21
52
|
function analyticsOwnsParameter(inputSchema, parameterName) {
|
|
22
53
|
if (!inputSchema || 'object' != typeof inputSchema) return canInjectAnalyticsParameter(void 0, parameterName);
|
|
23
54
|
if (isZodRawShapeCompat(inputSchema)) return canInjectAnalyticsParameter({
|
|
@@ -36,6 +67,7 @@ function getAnalyticsParameterOwnership(inputSchema, outputSchema) {
|
|
|
36
67
|
return {
|
|
37
68
|
context: analyticsOwnsParameter(inputSchema, 'context'),
|
|
38
69
|
conversationId: analyticsOwnsParameter(inputSchema, 'conversation_id'),
|
|
70
|
+
llmModel: analyticsOwnsParameter(inputSchema, 'llm_model'),
|
|
39
71
|
outputInstructions: canDeclareOutputInstructions(outputSchema)
|
|
40
72
|
};
|
|
41
73
|
}
|
|
@@ -49,6 +81,10 @@ function stripOwnedAnalyticsArguments(args, ownership) {
|
|
|
49
81
|
const { conversation_id: _conversationId, ...rest } = cleanedArgs;
|
|
50
82
|
cleanedArgs = rest;
|
|
51
83
|
}
|
|
84
|
+
if (ownership.llmModel && cleanedArgs && 'object' == typeof cleanedArgs && 'llm_model' in cleanedArgs) {
|
|
85
|
+
const { llm_model: _llmModel, ...rest } = cleanedArgs;
|
|
86
|
+
cleanedArgs = rest;
|
|
87
|
+
}
|
|
52
88
|
return cleanedArgs;
|
|
53
89
|
}
|
|
54
|
-
export { analyticsOwnsParameter, canInjectAnalyticsParameter, getAnalyticsParameterOwnership, hasAnalyticsParameter, stripOwnedAnalyticsArguments };
|
|
90
|
+
export { addAnalyticsParameterToTool, analyticsOwnsParameter, canInjectAnalyticsParameter, getAnalyticsParameterOwnership, hasAnalyticsParameter, stripOwnedAnalyticsArguments };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/extensions/capture.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGxC;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,QAAQ,EACpB,MAAM,EAAE,QAAQ,EAChB,kBAAkB,CAAC,EAAE,WAAW,GAC/B,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/extensions/capture.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGxC;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,QAAQ,EACpB,MAAM,EAAE,QAAQ,EAChB,kBAAkB,CAAC,EAAE,WAAW,GAC/B,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CA8E3B"}
|
|
@@ -64,6 +64,8 @@ function captureEvent(server, eventInput, logger, requestAttribution) {
|
|
|
64
64
|
response: eventInput.response,
|
|
65
65
|
userIntent: eventInput.userIntent,
|
|
66
66
|
userIntentSource: eventInput.userIntentSource,
|
|
67
|
+
llmModel: eventInput.llmModel,
|
|
68
|
+
llmModelSource: eventInput.llmModelSource,
|
|
67
69
|
isError: eventInput.isError,
|
|
68
70
|
error: eventInput.error,
|
|
69
71
|
errorType: eventInput.errorType,
|
|
@@ -36,6 +36,8 @@ function captureEvent(server, eventInput, logger, requestAttribution) {
|
|
|
36
36
|
response: eventInput.response,
|
|
37
37
|
userIntent: eventInput.userIntent,
|
|
38
38
|
userIntentSource: eventInput.userIntentSource,
|
|
39
|
+
llmModel: eventInput.llmModel,
|
|
40
|
+
llmModelSource: eventInput.llmModelSource,
|
|
39
41
|
isError: eventInput.isError,
|
|
40
42
|
error: eventInput.error,
|
|
41
43
|
errorType: eventInput.errorType,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
+
export declare const DEFAULT_MODEL_PARAMETER_DESCRIPTION = "The exact model identifier you (the assistant) are running as, taken from your system prompt or environment (e.g. \"claude-opus-4-8\", \"gpt-5.2\"). Used for analytics only. If you do not know your model identifier with certainty, pass \"unknown\" \u2014 never guess.";
|
|
3
4
|
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
5
|
export declare const POSTHOG_MCP_ANALYTICS_SOURCE = "posthog_mcp_analytics";
|
|
5
6
|
export declare const POSTHOG_MCP_LIB_NAME = "posthog-node-mcp";
|
|
@@ -29,6 +30,8 @@ export declare const PostHogMCPAnalyticsProperty: {
|
|
|
29
30
|
readonly Intent: "$mcp_intent";
|
|
30
31
|
readonly IntentSource: "$mcp_intent_source";
|
|
31
32
|
readonly ListedToolNames: "$mcp_listed_tool_names";
|
|
33
|
+
readonly LlmModel: "$mcp_llm_model";
|
|
34
|
+
readonly LlmModelSource: "$mcp_llm_model_source";
|
|
32
35
|
readonly Parameters: "$mcp_parameters";
|
|
33
36
|
readonly ProtocolVersion: "$mcp_protocol_version";
|
|
34
37
|
readonly ResourceName: "$mcp_resource_name";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/extensions/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,6BAA6B,KAAK,CAAA;AAE/C,eAAO,MAAM,qCAAqC,2hBAAyhB,CAAA;AAE3kB,eAAO,MAAM,mCAAmC,4LACsI,CAAA;AAEtL,eAAO,MAAM,4BAA4B,0BAA0B,CAAA;AAMnE,eAAO,MAAM,oBAAoB,qBAAqB,CAAA;AAItD,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
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/extensions/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,6BAA6B,KAAK,CAAA;AAE/C,eAAO,MAAM,qCAAqC,2hBAAyhB,CAAA;AAE3kB,eAAO,MAAM,mCAAmC,gRAAqQ,CAAA;AAErT,eAAO,MAAM,mCAAmC,4LACsI,CAAA;AAEtL,eAAO,MAAM,4BAA4B,0BAA0B,CAAA;AAMnE,eAAO,MAAM,oBAAoB,qBAAqB,CAAA;AAItD,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;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B9B,CAAA;AAEV,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA"}
|
|
@@ -26,6 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
DEFAULT_CONTEXT_PARAMETER_DESCRIPTION: ()=>DEFAULT_CONTEXT_PARAMETER_DESCRIPTION,
|
|
28
28
|
DEFAULT_CONVERSATION_ID_DESCRIPTION: ()=>DEFAULT_CONVERSATION_ID_DESCRIPTION,
|
|
29
|
+
DEFAULT_MODEL_PARAMETER_DESCRIPTION: ()=>DEFAULT_MODEL_PARAMETER_DESCRIPTION,
|
|
29
30
|
INACTIVITY_TIMEOUT_IN_MINUTES: ()=>INACTIVITY_TIMEOUT_IN_MINUTES,
|
|
30
31
|
POSTHOG_MCP_ANALYTICS_SOURCE: ()=>POSTHOG_MCP_ANALYTICS_SOURCE,
|
|
31
32
|
POSTHOG_MCP_LIB_NAME: ()=>POSTHOG_MCP_LIB_NAME,
|
|
@@ -34,6 +35,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
35
|
});
|
|
35
36
|
const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
36
37
|
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.\"";
|
|
38
|
+
const DEFAULT_MODEL_PARAMETER_DESCRIPTION = `The exact model identifier you (the assistant) are running as, taken from your system prompt or environment (e.g. "claude-opus-4-8", "gpt-5.2"). Used for analytics only. If you do not know your model identifier with certainty, pass "unknown" \u{2014} never guess.`;
|
|
37
39
|
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.";
|
|
38
40
|
const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics';
|
|
39
41
|
const POSTHOG_MCP_LIB_NAME = 'posthog-node-mcp';
|
|
@@ -62,6 +64,8 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
62
64
|
Intent: '$mcp_intent',
|
|
63
65
|
IntentSource: '$mcp_intent_source',
|
|
64
66
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
67
|
+
LlmModel: '$mcp_llm_model',
|
|
68
|
+
LlmModelSource: '$mcp_llm_model_source',
|
|
65
69
|
Parameters: '$mcp_parameters',
|
|
66
70
|
ProtocolVersion: '$mcp_protocol_version',
|
|
67
71
|
ResourceName: '$mcp_resource_name',
|
|
@@ -77,6 +81,7 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
77
81
|
};
|
|
78
82
|
exports.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = __webpack_exports__.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION;
|
|
79
83
|
exports.DEFAULT_CONVERSATION_ID_DESCRIPTION = __webpack_exports__.DEFAULT_CONVERSATION_ID_DESCRIPTION;
|
|
84
|
+
exports.DEFAULT_MODEL_PARAMETER_DESCRIPTION = __webpack_exports__.DEFAULT_MODEL_PARAMETER_DESCRIPTION;
|
|
80
85
|
exports.INACTIVITY_TIMEOUT_IN_MINUTES = __webpack_exports__.INACTIVITY_TIMEOUT_IN_MINUTES;
|
|
81
86
|
exports.POSTHOG_MCP_ANALYTICS_SOURCE = __webpack_exports__.POSTHOG_MCP_ANALYTICS_SOURCE;
|
|
82
87
|
exports.POSTHOG_MCP_LIB_NAME = __webpack_exports__.POSTHOG_MCP_LIB_NAME;
|
|
@@ -85,6 +90,7 @@ exports.PostHogMCPAnalyticsProperty = __webpack_exports__.PostHogMCPAnalyticsPro
|
|
|
85
90
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
86
91
|
"DEFAULT_CONTEXT_PARAMETER_DESCRIPTION",
|
|
87
92
|
"DEFAULT_CONVERSATION_ID_DESCRIPTION",
|
|
93
|
+
"DEFAULT_MODEL_PARAMETER_DESCRIPTION",
|
|
88
94
|
"INACTIVITY_TIMEOUT_IN_MINUTES",
|
|
89
95
|
"POSTHOG_MCP_ANALYTICS_SOURCE",
|
|
90
96
|
"POSTHOG_MCP_LIB_NAME",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
+
const DEFAULT_MODEL_PARAMETER_DESCRIPTION = `The exact model identifier you (the assistant) are running as, taken from your system prompt or environment (e.g. "claude-opus-4-8", "gpt-5.2"). Used for analytics only. If you do not know your model identifier with certainty, pass "unknown" \u{2014} never guess.`;
|
|
3
4
|
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
5
|
const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics';
|
|
5
6
|
const POSTHOG_MCP_LIB_NAME = 'posthog-node-mcp';
|
|
@@ -28,6 +29,8 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
28
29
|
Intent: '$mcp_intent',
|
|
29
30
|
IntentSource: '$mcp_intent_source',
|
|
30
31
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
32
|
+
LlmModel: '$mcp_llm_model',
|
|
33
|
+
LlmModelSource: '$mcp_llm_model_source',
|
|
31
34
|
Parameters: '$mcp_parameters',
|
|
32
35
|
ProtocolVersion: '$mcp_protocol_version',
|
|
33
36
|
ResourceName: '$mcp_resource_name',
|
|
@@ -41,4 +44,4 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
41
44
|
ToolName: '$mcp_tool_name',
|
|
42
45
|
VendorClient: '$mcp_vendor_client'
|
|
43
46
|
};
|
|
44
|
-
export { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, DEFAULT_CONVERSATION_ID_DESCRIPTION, INACTIVITY_TIMEOUT_IN_MINUTES, POSTHOG_MCP_ANALYTICS_SOURCE, POSTHOG_MCP_LIB_NAME, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty };
|
|
47
|
+
export { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, DEFAULT_CONVERSATION_ID_DESCRIPTION, DEFAULT_MODEL_PARAMETER_DESCRIPTION, INACTIVITY_TIMEOUT_IN_MINUTES, POSTHOG_MCP_ANALYTICS_SOURCE, POSTHOG_MCP_LIB_NAME, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty };
|
|
@@ -9,8 +9,8 @@ export interface ContextInjectableTool {
|
|
|
9
9
|
export declare function isContextEnabled(context: MCPAnalyticsOptions['context']): boolean;
|
|
10
10
|
export declare function getContextDescription(context: MCPAnalyticsOptions['context']): string | undefined;
|
|
11
11
|
/**
|
|
12
|
-
* Adds a context parameter to a tool's JSON Schema.
|
|
13
|
-
* This
|
|
12
|
+
* Adds a context parameter to a tool's JSON Schema, via the shared injector.
|
|
13
|
+
* This is called AFTER the MCP SDK has converted Zod schemas to JSON Schema,
|
|
14
14
|
* so we only need to handle JSON Schema format.
|
|
15
15
|
*
|
|
16
16
|
* Skips injection (with warning) for:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-parameters.d.ts","sourceRoot":"","sources":["../../src/extensions/context-parameters.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"context-parameters.d.ts","sourceRoot":"","sources":["../../src/extensions/context-parameters.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAA+B,KAAK,6BAA6B,EAAE,MAAM,wBAAwB,CAAA;AAExG,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE7C,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GAAG,OAAO,CAEjF;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAEjG;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,SAAS,qBAAqB,EAC3E,IAAI,EAAE,KAAK,EACX,0BAA0B,CAAC,EAAE,MAAM,EACnC,MAAM,GAAE,QAAc,GACrB,KAAK,CAQP;AAED,wBAAgB,0BAA0B,CAAC,KAAK,SAAS,qBAAqB,EAC5E,KAAK,EAAE,KAAK,EAAE,EACd,0BAA0B,CAAC,EAAE,MAAM,EACnC,MAAM,GAAE,QAAc,GACrB,KAAK,EAAE,CAET"}
|
|
@@ -39,35 +39,7 @@ function getContextDescription(context) {
|
|
|
39
39
|
return 'object' == typeof context ? context.description : void 0;
|
|
40
40
|
}
|
|
41
41
|
function addContextParameterToTool(tool, contextDescriptionOverride, logger = external_logger_js_namespaceObject.log) {
|
|
42
|
-
|
|
43
|
-
...tool
|
|
44
|
-
};
|
|
45
|
-
const toolName = tool.name || 'unknown';
|
|
46
|
-
const schema = modifiedTool.inputSchema;
|
|
47
|
-
if (!(0, external_analytics_parameters_js_namespaceObject.canInjectAnalyticsParameter)(schema, 'context')) {
|
|
48
|
-
logger((0, external_analytics_parameters_js_namespaceObject.hasAnalyticsParameter)(schema, 'context') ? `WARN: Tool "${toolName}" already has 'context' parameter. Skipping context injection.` : `WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf/$ref). Skipping context injection.`);
|
|
49
|
-
return modifiedTool;
|
|
50
|
-
}
|
|
51
|
-
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {},
|
|
54
|
-
required: []
|
|
55
|
-
};
|
|
56
|
-
const contextDescription = contextDescriptionOverride || external_constants_js_namespaceObject.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION;
|
|
57
|
-
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
58
|
-
const inputSchema = modifiedTool.inputSchema;
|
|
59
|
-
if (!inputSchema.properties) inputSchema.properties = {};
|
|
60
|
-
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
61
|
-
inputSchema.properties.context = {
|
|
62
|
-
type: 'string',
|
|
63
|
-
description: contextDescription
|
|
64
|
-
};
|
|
65
|
-
if (Array.isArray(inputSchema.required)) {
|
|
66
|
-
if (!inputSchema.required.includes('context')) inputSchema.required.push('context');
|
|
67
|
-
} else inputSchema.required = [
|
|
68
|
-
'context'
|
|
69
|
-
];
|
|
70
|
-
return modifiedTool;
|
|
42
|
+
return (0, external_analytics_parameters_js_namespaceObject.addAnalyticsParameterToTool)(tool, 'context', contextDescriptionOverride || external_constants_js_namespaceObject.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, 'context', logger);
|
|
71
43
|
}
|
|
72
44
|
function addContextParameterToTools(tools, contextDescriptionOverride, logger = external_logger_js_namespaceObject.log) {
|
|
73
45
|
return tools.map((tool)=>addContextParameterToTool(tool, contextDescriptionOverride, logger));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addAnalyticsParameterToTool } from "./analytics-parameters.mjs";
|
|
2
2
|
import { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION } from "./constants.mjs";
|
|
3
3
|
import { log } from "./logger.mjs";
|
|
4
4
|
function isContextEnabled(context) {
|
|
@@ -8,35 +8,7 @@ function getContextDescription(context) {
|
|
|
8
8
|
return 'object' == typeof context ? context.description : void 0;
|
|
9
9
|
}
|
|
10
10
|
function addContextParameterToTool(tool, contextDescriptionOverride, logger = log) {
|
|
11
|
-
|
|
12
|
-
...tool
|
|
13
|
-
};
|
|
14
|
-
const toolName = tool.name || 'unknown';
|
|
15
|
-
const schema = modifiedTool.inputSchema;
|
|
16
|
-
if (!canInjectAnalyticsParameter(schema, 'context')) {
|
|
17
|
-
logger(hasAnalyticsParameter(schema, 'context') ? `WARN: Tool "${toolName}" already has 'context' parameter. Skipping context injection.` : `WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf/$ref). Skipping context injection.`);
|
|
18
|
-
return modifiedTool;
|
|
19
|
-
}
|
|
20
|
-
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
21
|
-
type: 'object',
|
|
22
|
-
properties: {},
|
|
23
|
-
required: []
|
|
24
|
-
};
|
|
25
|
-
const contextDescription = contextDescriptionOverride || DEFAULT_CONTEXT_PARAMETER_DESCRIPTION;
|
|
26
|
-
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
27
|
-
const inputSchema = modifiedTool.inputSchema;
|
|
28
|
-
if (!inputSchema.properties) inputSchema.properties = {};
|
|
29
|
-
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
30
|
-
inputSchema.properties.context = {
|
|
31
|
-
type: 'string',
|
|
32
|
-
description: contextDescription
|
|
33
|
-
};
|
|
34
|
-
if (Array.isArray(inputSchema.required)) {
|
|
35
|
-
if (!inputSchema.required.includes('context')) inputSchema.required.push('context');
|
|
36
|
-
} else inputSchema.required = [
|
|
37
|
-
'context'
|
|
38
|
-
];
|
|
39
|
-
return modifiedTool;
|
|
11
|
+
return addAnalyticsParameterToTool(tool, 'context', contextDescriptionOverride || DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, 'context', logger);
|
|
40
12
|
}
|
|
41
13
|
function addContextParameterToTools(tools, contextDescriptionOverride, logger = log) {
|
|
42
14
|
return tools.map((tool)=>addContextParameterToTool(tool, contextDescriptionOverride, logger));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-id.d.ts","sourceRoot":"","sources":["../../src/extensions/conversation-id.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,6BAA6B,EACnC,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE7C,eAAO,MAAM,0BAA0B,oBAAoB,CAAA;AAE3D,MAAM,WAAW,4BAA4B;IAC3C,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wBAAgB,uBAAuB,CAAC,KAAK,SAAS,4BAA4B,EAChF,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,QAAc,GACrB,KAAK,CA4CP;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,4BAA4B,EACjF,KAAK,EAAE,KAAK,EAAE,EACd,MAAM,GAAE,QAAc,GACrB,KAAK,EAAE,CAET;AAQD,MAAM,MAAM,wBAAwB,GAChC;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrD;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,wBAAwB,CAY/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAK1E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUvE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAM1D;AAED,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,MAAM,GAAG;IACrE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,
|
|
1
|
+
{"version":3,"file":"conversation-id.d.ts","sourceRoot":"","sources":["../../src/extensions/conversation-id.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,6BAA6B,EACnC,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE7C,eAAO,MAAM,0BAA0B,oBAAoB,CAAA;AAE3D,MAAM,WAAW,4BAA4B;IAC3C,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wBAAgB,uBAAuB,CAAC,KAAK,SAAS,4BAA4B,EAChF,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,QAAc,GACrB,KAAK,CA4CP;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,4BAA4B,EACjF,KAAK,EAAE,KAAK,EAAE,EACd,MAAM,GAAE,QAAc,GACrB,KAAK,EAAE,CAET;AAQD,MAAM,MAAM,wBAAwB,GAChC;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrD;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,wBAAwB,CAY/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAK1E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUvE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAM1D;AAED,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,MAAM,GAAG;IACrE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,CAQA;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAS/F"}
|
|
@@ -102,7 +102,9 @@ function stripConversationId(args) {
|
|
|
102
102
|
function buildConversationIdPromptBack(conversationId) {
|
|
103
103
|
return {
|
|
104
104
|
type: 'text',
|
|
105
|
-
text:
|
|
105
|
+
text: JSON.stringify({
|
|
106
|
+
conversation_id: conversationId
|
|
107
|
+
})
|
|
106
108
|
};
|
|
107
109
|
}
|
|
108
110
|
function injectConversationIdPromptBack(result, conversationId) {
|
|
@@ -66,7 +66,9 @@ function stripConversationId(args) {
|
|
|
66
66
|
function buildConversationIdPromptBack(conversationId) {
|
|
67
67
|
return {
|
|
68
68
|
type: 'text',
|
|
69
|
-
text:
|
|
69
|
+
text: JSON.stringify({
|
|
70
|
+
conversation_id: conversationId
|
|
71
|
+
})
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
function injectConversationIdPromptBack(result, conversationId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrument-highlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-highlevel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,sBAAsB,EAIvB,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"instrument-highlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-highlevel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,sBAAsB,EAIvB,MAAM,UAAU,CAAA;AAUjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAmQxC,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CA0BhG"}
|
|
@@ -28,6 +28,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const external_analytics_parameters_js_namespaceObject = require("./analytics-parameters.js");
|
|
30
30
|
const external_context_parameters_js_namespaceObject = require("./context-parameters.js");
|
|
31
|
+
const external_model_parameters_js_namespaceObject = require("./model-parameters.js");
|
|
31
32
|
const external_event_types_js_namespaceObject = require("./event-types.js");
|
|
32
33
|
const external_internal_js_namespaceObject = require("./internal.js");
|
|
33
34
|
const external_mcp_sdk_compat_js_namespaceObject = require("./mcp-sdk-compat.js");
|
|
@@ -128,7 +129,8 @@ function addTracingToToolCallbackInternal(tool, toolName, server, getCurrentInpu
|
|
|
128
129
|
const inputSchema = getCurrentInputSchema();
|
|
129
130
|
const cleanedArgs = (0, external_analytics_parameters_js_namespaceObject.stripOwnedAnalyticsArguments)(args, {
|
|
130
131
|
context: (0, external_context_parameters_js_namespaceObject.isContextEnabled)(options?.context) && (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(inputSchema, 'context'),
|
|
131
|
-
conversationId: options?.enableConversationId === true && (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(inputSchema, 'conversation_id')
|
|
132
|
+
conversationId: options?.enableConversationId === true && (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(inputSchema, 'conversation_id'),
|
|
133
|
+
llmModel: (0, external_model_parameters_js_namespaceObject.isCaptureModelEnabled)(options?.captureModel) && (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(inputSchema, 'llm_model')
|
|
132
134
|
});
|
|
133
135
|
try {
|
|
134
136
|
if (void 0 === cleanedArgs) {
|
|
@@ -165,6 +167,7 @@ async function handleToolCallRequest(highLevelServer, server, originalCallToolHa
|
|
|
165
167
|
extra,
|
|
166
168
|
eventType: external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpMissingCapability,
|
|
167
169
|
explicitContextIntent: context,
|
|
170
|
+
parameterOwnership: (0, external_instrumentation_js_namespaceObject.getVirtualToolParameterOwnership)(data, toolName),
|
|
168
171
|
execute: async ()=>(0, external_tools_js_namespaceObject.handleReportMissing)({
|
|
169
172
|
context
|
|
170
173
|
}, data.logger)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { analyticsOwnsParameter, getAnalyticsParameterOwnership, stripOwnedAnalyticsArguments } from "./analytics-parameters.mjs";
|
|
2
2
|
import { isContextEnabled } from "./context-parameters.mjs";
|
|
3
|
+
import { isCaptureModelEnabled } from "./model-parameters.mjs";
|
|
3
4
|
import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
4
5
|
import { getServerTrackingData } from "./internal.mjs";
|
|
5
6
|
import { createWrappedTool, getToolFunction, hasToolFunction } from "./mcp-sdk-compat.mjs";
|
|
6
7
|
import { handleReportMissing, resolveMissingCapabilityToolName } from "./tools.mjs";
|
|
7
|
-
import { captureToolCall, handleInitializeRequest, handleListToolsRequest, isToolAdvertised, patchRequestHandlers, readToolMetaCategory } from "./instrumentation.mjs";
|
|
8
|
+
import { captureToolCall, getVirtualToolParameterOwnership, handleInitializeRequest, handleListToolsRequest, isToolAdvertised, patchRequestHandlers, readToolMetaCategory } from "./instrumentation.mjs";
|
|
8
9
|
import { getContextArgument } from "./tracing-helpers.mjs";
|
|
9
10
|
const wrappedCallbacks = new WeakMap();
|
|
10
11
|
const MCP_ANALYTICS_PROCESSED = Symbol('__posthog_mcp_analytics_processed__');
|
|
@@ -100,7 +101,8 @@ function addTracingToToolCallbackInternal(tool, toolName, server, getCurrentInpu
|
|
|
100
101
|
const inputSchema = getCurrentInputSchema();
|
|
101
102
|
const cleanedArgs = stripOwnedAnalyticsArguments(args, {
|
|
102
103
|
context: isContextEnabled(options?.context) && analyticsOwnsParameter(inputSchema, 'context'),
|
|
103
|
-
conversationId: options?.enableConversationId === true && analyticsOwnsParameter(inputSchema, 'conversation_id')
|
|
104
|
+
conversationId: options?.enableConversationId === true && analyticsOwnsParameter(inputSchema, 'conversation_id'),
|
|
105
|
+
llmModel: isCaptureModelEnabled(options?.captureModel) && analyticsOwnsParameter(inputSchema, 'llm_model')
|
|
104
106
|
});
|
|
105
107
|
try {
|
|
106
108
|
if (void 0 === cleanedArgs) {
|
|
@@ -137,6 +139,7 @@ async function handleToolCallRequest(highLevelServer, server, originalCallToolHa
|
|
|
137
139
|
extra,
|
|
138
140
|
eventType: MCPAnalyticsEventType.mcpMissingCapability,
|
|
139
141
|
explicitContextIntent: context,
|
|
142
|
+
parameterOwnership: getVirtualToolParameterOwnership(data, toolName),
|
|
140
143
|
execute: async ()=>handleReportMissing({
|
|
141
144
|
context
|
|
142
145
|
}, data.logger)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrument-lowlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-lowlevel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAiD,aAAa,EAAE,MAAM,UAAU,CAAA;AAG5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"instrument-lowlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-lowlevel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAiD,aAAa,EAAE,MAAM,UAAU,CAAA;AAG5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAoBxC;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAyBtF"}
|
|
@@ -67,6 +67,7 @@ async function handleToolCallRequest(server, originalCallToolHandler, request, e
|
|
|
67
67
|
extra,
|
|
68
68
|
eventType: external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpMissingCapability,
|
|
69
69
|
explicitContextIntent: context,
|
|
70
|
+
parameterOwnership: (0, external_instrumentation_js_namespaceObject.getVirtualToolParameterOwnership)(data, toolName),
|
|
70
71
|
execute: async ()=>(0, external_tools_js_namespaceObject.handleReportMissing)({
|
|
71
72
|
context
|
|
72
73
|
}, data.logger)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
2
2
|
import { getServerTrackingData } from "./internal.mjs";
|
|
3
3
|
import { handleReportMissing, resolveMissingCapabilityToolName } from "./tools.mjs";
|
|
4
|
-
import { captureToolCall, handleInitializeRequest, handleListToolsRequest, isToolAdvertised, patchRequestHandlers, registerFallbackRequestHandler } from "./instrumentation.mjs";
|
|
4
|
+
import { captureToolCall, getVirtualToolParameterOwnership, handleInitializeRequest, handleListToolsRequest, isToolAdvertised, patchRequestHandlers, registerFallbackRequestHandler } from "./instrumentation.mjs";
|
|
5
5
|
import { getContextArgument } from "./tracing-helpers.mjs";
|
|
6
6
|
function instrumentLowLevelServer(server, logger) {
|
|
7
7
|
try {
|
|
@@ -39,6 +39,7 @@ async function handleToolCallRequest(server, originalCallToolHandler, request, e
|
|
|
39
39
|
extra,
|
|
40
40
|
eventType: MCPAnalyticsEventType.mcpMissingCapability,
|
|
41
41
|
explicitContextIntent: context,
|
|
42
|
+
parameterOwnership: getVirtualToolParameterOwnership(data, toolName),
|
|
42
43
|
execute: async ()=>handleReportMissing({
|
|
43
44
|
context
|
|
44
45
|
}, data.logger)
|
|
@@ -84,6 +84,22 @@ export declare function registerFallbackRequestHandler(server: MCPServerLike, ha
|
|
|
84
84
|
* bare server to instrument() and only then registers its handlers.
|
|
85
85
|
*/
|
|
86
86
|
export declare function patchRequestHandlers(server: MCPServerLike, patches: Record<string, HandlerPatch>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Ownership for the `get_more_tools` virtual tool, resolved without the
|
|
89
|
+
* `tools/list` cache.
|
|
90
|
+
*
|
|
91
|
+
* The missing-capability branch is only entered when the application does not
|
|
92
|
+
* advertise a tool by this name, so the descriptor is the SDK's own and what it
|
|
93
|
+
* declares is known statically. An instance that never served a listing — a
|
|
94
|
+
* per-request `McpServer`/`Server`, the topology in ADR-0011 — would otherwise
|
|
95
|
+
* read every injected parameter as not-ours and neither capture nor strip it.
|
|
96
|
+
*
|
|
97
|
+
* `conversation_id` still comes from the cache on purpose: resolving it here too
|
|
98
|
+
* would start minting a handle, and appending its prompt-back block, on
|
|
99
|
+
* instances that today mint none. That changes session anchoring (ADR-0004)
|
|
100
|
+
* rather than closing this gap.
|
|
101
|
+
*/
|
|
102
|
+
export declare function getVirtualToolParameterOwnership(data: MCPAnalyticsData, toolName: string): AnalyticsParameterOwnership;
|
|
87
103
|
/**
|
|
88
104
|
* Checks the server's raw listing for a real owner of a candidate virtual tool.
|
|
89
105
|
* This does not depend on a previous client request and does not call the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/extensions/instrumentation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,aAAa,EAId,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/extensions/instrumentation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,aAAa,EAId,MAAM,UAAU,CAAA;AAqBjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAIrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AASxC;;;;;;GAMG;AAEH,KAAK,iBAAiB,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,6BAA6B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7G,2EAA2E;AAC3E,KAAK,YAAY,GAAG,CAAC,iBAAiB,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE3E,UAAU,mBAAmB;IAC3B,MAAM,EAAE,aAAa,CAAA;IACrB,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,cAAc,CAAA;IACvB,KAAK,CAAC,EAAE,6BAA6B,CAAA;IACrC,OAAO,EAAE,YAAY,CAAA;IACrB,2FAA2F;IAC3F,kBAAkB,CAAC,EAAE,2BAA2B,CAAA;IAChD;;;;OAIG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAA;IACjC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAA;CAClC;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CA8DnF;AA+OD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,MAAM,EAAE,aAAa,EACrB,eAAe,EAAE,iBAAiB,EAClC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,6BAA6B,GAAG,SAAS,KAC7C,OAAO,CAAC,OAAO,CAAC,CAAA;AAkBrB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,iBAAiB,EAClC,KAAK,EAAE,YAAY,GAClB,IAAI,CAGN;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,IAAI,CA0CvG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,MAAM,GACf,2BAA2B,CAK7B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,6BAA6B,GAAG,SAAS,EAChD,MAAM,EAAE,QAAQ,GACf,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAoB9B;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,aAAa,EACrB,wBAAwB,EAAE,iBAAiB,EAC3C,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,6BAA6B,GAAG,SAAS,EAChD,MAAM,EAAE,QAAQ,GACf,OAAO,CAAC,uBAAuB,CAAC,CAmElC;AAiGD,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1B,KAAK,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,SAAS,GAClD,IAAI,CASN;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAGtE;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1B,KAAK,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,SAAS,GAClD,IAAI,CAUN;AAuHD;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,aAAa,EACrB,yBAAyB,EAAE,iBAAiB,EAC5C,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,6BAA6B,GAAG,SAAS,EAChD,MAAM,EAAE,QAAQ,GACf,OAAO,CAAC,OAAO,CAAC,CA2ElB"}
|