@posthog/mcp 0.18.1 → 0.19.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/dist/extensions/constants.d.ts +2 -0
- package/dist/extensions/constants.d.ts.map +1 -1
- package/dist/extensions/constants.js +2 -0
- package/dist/extensions/constants.mjs +2 -0
- package/dist/extensions/instrument-highlevel.d.ts.map +1 -1
- package/dist/extensions/instrument-highlevel.js +1 -0
- package/dist/extensions/instrument-highlevel.mjs +1 -0
- package/dist/extensions/instrumentation.d.ts +1 -0
- package/dist/extensions/instrumentation.d.ts.map +1 -1
- package/dist/extensions/instrumentation.js +27 -2
- package/dist/extensions/instrumentation.mjs +28 -3
- package/dist/extensions/internal.d.ts +9 -8
- package/dist/extensions/internal.d.ts.map +1 -1
- package/dist/extensions/internal.js +17 -12
- package/dist/extensions/internal.mjs +15 -13
- package/dist/extensions/mcp-sdk-compat.d.ts +7 -0
- package/dist/extensions/mcp-sdk-compat.d.ts.map +1 -1
- package/dist/extensions/mcp-sdk-compat.js +21 -3
- package/dist/extensions/mcp-sdk-compat.mjs +17 -2
- package/dist/extensions/tool-input.d.ts +9 -0
- package/dist/extensions/tool-input.d.ts.map +1 -0
- package/dist/extensions/tool-input.js +117 -0
- package/dist/extensions/tool-input.mjs +79 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.mjs +3 -1
- package/dist/types.d.ts +31 -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 +3 -3
- package/src/extensions/constants.ts +2 -0
- package/src/extensions/instrument-highlevel.ts +1 -0
- package/src/extensions/instrumentation.ts +37 -1
- package/src/extensions/internal.ts +18 -17
- package/src/extensions/mcp-sdk-compat.ts +38 -1
- package/src/extensions/tool-input.ts +92 -0
- package/src/index.ts +6 -1
- package/src/types.ts +32 -1
- package/src/version.ts +1 -1
|
@@ -36,6 +36,8 @@ export declare const PostHogMCPAnalyticsProperty: {
|
|
|
36
36
|
readonly FeedbackTool: '$mcp_feedback_tool';
|
|
37
37
|
readonly FeedbackType: '$mcp_feedback_type';
|
|
38
38
|
readonly IsError: '$mcp_is_error';
|
|
39
|
+
readonly InputAliasesUsed: '$mcp_input_aliases_used';
|
|
40
|
+
readonly InputKeys: '$mcp_input_keys';
|
|
39
41
|
readonly Intent: '$mcp_intent';
|
|
40
42
|
readonly IntentSource: '$mcp_intent_source';
|
|
41
43
|
readonly ListedToolNames: '$mcp_listed_tool_names';
|
|
@@ -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,onBAA4mB,CAAA;AAE9pB,eAAO,MAAM,mCAAmC,gRAAqQ,CAAA;AAErT,eAAO,MAAM,mCAAmC,qYAC+U,CAAA;AAE/X,eAAO,MAAM,4BAA4B,0BAA0B,CAAA;AAMnE,eAAO,MAAM,oBAAoB,qBAAqB,CAAA;AAItD,eAAO,MAAM,wBAAwB;aACnC,MAAM,EAAE,aAAa;aACrB,SAAS,EAAE,YAAY;aACvB,QAAQ,EAAE,eAAe;aACzB,QAAQ,EAAE,WAAW;aACrB,UAAU,EAAE,iBAAiB;aAC7B,iBAAiB,EAAE,yBAAyB;aAC5C,SAAS,EAAE,iBAAiB;aAC5B,WAAW,EAAE,mBAAmB;aAChC,YAAY,EAAE,oBAAoB;aAClC,aAAa,EAAE,qBAAqB;aACpC,QAAQ,EAAE,gBAAgB;aAC1B,SAAS,EAAE,iBAAiB;CACpB,CAAA;AAEV,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,OAAO,wBAAwB,CAAC,CAAA;AAE/G,eAAO,MAAM,2BAA2B;aACtC,UAAU,EAAE,kBA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AAuB;aACxC,YAAY,EAAE,oBAAoB;aAClC,QAAQ,EAAE,eAAe;aACzB,UAAU,EAAE,kBAAkB;aAC9B,aAAa,EAAE,qBAAqB;aACpC,SAAS,EAAE,aAAa;aACxB,MAAM,EAAE,aAAa;aACrB,YAAY,EAAE,oBAAoB;aAClC,eAAe,EAAE,uBAAuB;aACxC,QAAQ,EAAE,gBAAgB;aAC1B,YAAY,EAAE,oBAAoB;CAC1B,CAAA;AAEV,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA"}
|
|
@@ -64,6 +64,8 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
64
64
|
FeedbackTool: '$mcp_feedback_tool',
|
|
65
65
|
FeedbackType: '$mcp_feedback_type',
|
|
66
66
|
IsError: '$mcp_is_error',
|
|
67
|
+
InputAliasesUsed: '$mcp_input_aliases_used',
|
|
68
|
+
InputKeys: '$mcp_input_keys',
|
|
67
69
|
Intent: '$mcp_intent',
|
|
68
70
|
IntentSource: '$mcp_intent_source',
|
|
69
71
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
@@ -35,6 +35,8 @@ const PostHogMCPAnalyticsProperty = {
|
|
|
35
35
|
FeedbackTool: '$mcp_feedback_tool',
|
|
36
36
|
FeedbackType: '$mcp_feedback_type',
|
|
37
37
|
IsError: '$mcp_is_error',
|
|
38
|
+
InputAliasesUsed: '$mcp_input_aliases_used',
|
|
39
|
+
InputKeys: '$mcp_input_keys',
|
|
38
40
|
Intent: '$mcp_intent',
|
|
39
41
|
IntentSource: '$mcp_intent_source',
|
|
40
42
|
ListedToolNames: '$mcp_listed_tool_names',
|
|
@@ -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;AAmBjB,OAAO,KAAK,EAAE,QAAQ,EAAE,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;AAmBjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAwRxC,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CA+BhG"}
|
|
@@ -203,6 +203,7 @@ async function handleToolCallRequest(highLevelServer, server, originalCallToolHa
|
|
|
203
203
|
extra,
|
|
204
204
|
execute: (downstreamRequest)=>originalCallToolHandler(downstreamRequest, extra),
|
|
205
205
|
parameterOwnership: registeredTool ? (0, external_analytics_parameters_js_namespaceObject.getAnalyticsParameterOwnership)(registeredTool.inputSchema, registeredTool.outputSchema) : void 0,
|
|
206
|
+
inputSchema: registeredTool?.inputSchema,
|
|
206
207
|
takeCapturedError: ()=>{
|
|
207
208
|
const captured = extra?.__mcp_analytics_error;
|
|
208
209
|
if (extra) extra.__mcp_analytics_error = void 0;
|
|
@@ -171,6 +171,7 @@ async function handleToolCallRequest(highLevelServer, server, originalCallToolHa
|
|
|
171
171
|
extra,
|
|
172
172
|
execute: (downstreamRequest)=>originalCallToolHandler(downstreamRequest, extra),
|
|
173
173
|
parameterOwnership: registeredTool ? getAnalyticsParameterOwnership(registeredTool.inputSchema, registeredTool.outputSchema) : void 0,
|
|
174
|
+
inputSchema: registeredTool?.inputSchema,
|
|
174
175
|
takeCapturedError: ()=>{
|
|
175
176
|
const captured = extra?.__mcp_analytics_error;
|
|
176
177
|
if (extra) extra.__mcp_analytics_error = void 0;
|
|
@@ -19,6 +19,7 @@ interface TraceToolCallParams {
|
|
|
19
19
|
execute: ToolExecutor;
|
|
20
20
|
/** Optional schema-derived ownership override for adapters with direct registry access. */
|
|
21
21
|
parameterOwnership?: AnalyticsParameterOwnership;
|
|
22
|
+
inputSchema?: unknown;
|
|
22
23
|
/**
|
|
23
24
|
* Event type to capture. Defaults to a tool call; the `get_more_tools` virtual
|
|
24
25
|
* tool passes `mcpMissingCapability` and `send_feedback` passes
|
|
@@ -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,UAAU,EACV,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;
|
|
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,UAAU,EACV,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;AAiBxC;;;;;;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;AAS3E,UAAU,mBAAmB;IAC3B,MAAM,EAAE,aAAa,CAAA;IACrB,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,cAAc,CAAA;IACvB,KAAK,CAAC,EAA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,CA0CvG;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;AA2ID,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"}
|
|
@@ -59,16 +59,34 @@ const external_session_token_js_namespaceObject = require("./session-token.js");
|
|
|
59
59
|
const external_feedback_js_namespaceObject = require("./feedback.js");
|
|
60
60
|
const external_tools_js_namespaceObject = require("./tools.js");
|
|
61
61
|
const external_tracing_helpers_js_namespaceObject = require("./tracing-helpers.js");
|
|
62
|
+
const external_tool_input_js_namespaceObject = require("./tool-input.js");
|
|
63
|
+
function resolveToolSchemaSessionId(data, extra) {
|
|
64
|
+
const token = (0, external_session_token_js_namespaceObject.decodeSessionId)((0, external_session_token_js_namespaceObject.readMcpSessionHeader)((0, external_request_headers_js_namespaceObject.getRequestHeaders)(extra)));
|
|
65
|
+
if (token) return token.sessionId;
|
|
66
|
+
if (extra?.sessionId) return (0, external_session_js_namespaceObject.deriveSessionIdFromMCPSession)(extra.sessionId);
|
|
67
|
+
return data.sessionId;
|
|
68
|
+
}
|
|
62
69
|
async function captureToolCall(params) {
|
|
63
|
-
const { server, data, request, extra, execute, parameterOwnership, eventType, explicitContextIntent, extraEventProperties, omitCapturedParameters, takeCapturedError } = params;
|
|
70
|
+
const { server, data, request, extra, execute, parameterOwnership, inputSchema, eventType, explicitContextIntent, extraEventProperties, omitCapturedParameters, takeCapturedError } = params;
|
|
64
71
|
const resolvedEventType = eventType ?? external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpToolsCall;
|
|
65
72
|
const isVirtualAnalyticsTool = resolvedEventType === external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpMissingCapability || resolvedEventType === external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpFeedback;
|
|
66
73
|
const ownership = getActiveAnalyticsParameterOwnership(data, request.params?.name, parameterOwnership, isVirtualAnalyticsTool);
|
|
67
74
|
const canCaptureContextIntent = ownership.read.context;
|
|
68
75
|
const conversation = resolveToolConversation(ownership.read.conversationId, request.params?.arguments, extra);
|
|
69
76
|
const downstreamRequest = cloneRequestWithoutOwnedAnalyticsArguments(request, ownership.strip);
|
|
77
|
+
const schemaSessionId = resolveToolSchemaSessionId(data, extra);
|
|
70
78
|
const startTime = new Date();
|
|
71
79
|
const preparedEvent = await prepareToolCallEvent(server, data, request, downstreamRequest, extra, startTime, conversation, ownership, resolvedEventType, canCaptureContextIntent);
|
|
80
|
+
if (preparedEvent && resolvedEventType === external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpToolsCall) {
|
|
81
|
+
const sessionSchemas = (preparedEvent.event.sessionId ? data.toolInputSchemas.get(preparedEvent.event.sessionId) : void 0) ?? data.toolInputSchemas.get(schemaSessionId);
|
|
82
|
+
const schema = inputSchema ?? sessionSchemas?.get(request.params?.name ?? '');
|
|
83
|
+
preparedEvent.event.properties = {
|
|
84
|
+
...preparedEvent.event.properties,
|
|
85
|
+
...(0, external_tool_input_js_namespaceObject.getToolInputProperties)(request.params?.arguments ?? {}, schema, {
|
|
86
|
+
shouldRecordInputKey: data.options.shouldRecordInputKey
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
}
|
|
72
90
|
if (preparedEvent && explicitContextIntent) (0, external_intent_js_namespaceObject.setExplicitContextIntent)(preparedEvent.event, explicitContextIntent);
|
|
73
91
|
if (preparedEvent && extraEventProperties) preparedEvent.event.properties = {
|
|
74
92
|
...preparedEvent.event.properties,
|
|
@@ -386,7 +404,14 @@ async function getTracedToolsList(server, originalListToolsHandler, request, ext
|
|
|
386
404
|
let tools = [
|
|
387
405
|
...originalResponse.tools || []
|
|
388
406
|
];
|
|
389
|
-
if (data)
|
|
407
|
+
if (data) {
|
|
408
|
+
cacheToolAnalyticsParameterOwnership(data.toolAnalyticsParameterOwnership, tools);
|
|
409
|
+
if (event.sessionId) {
|
|
410
|
+
const sessionSchemas = data.toolInputSchemas.get(event.sessionId) ?? new Map();
|
|
411
|
+
for (const tool of tools)if (tool?.name) sessionSchemas.set(tool.name, tool.inputSchema);
|
|
412
|
+
data.toolInputSchemas.set(event.sessionId, sessionSchemas);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
390
415
|
if (data && (0, external_context_parameters_js_namespaceObject.isContextEnabled)(data.options.context)) tools = (0, external_context_parameters_js_namespaceObject.addContextParameterToTools)(tools, (0, external_context_parameters_js_namespaceObject.getContextDescription)(data.options.context), data.logger);
|
|
391
416
|
if (data) {
|
|
392
417
|
const isFirstPage = request.params?.cursor == null;
|
|
@@ -13,21 +13,39 @@ import { getServerTrackingData, handleIdentify, setServerTrackingData, withIdent
|
|
|
13
13
|
import { buildCapturedMcpParameters } from "./mcp-payloads.mjs";
|
|
14
14
|
import { readRequestHandlerMethod } from "./mcp-sdk-compat.mjs";
|
|
15
15
|
import { getRequestHeaders } from "./request-headers.mjs";
|
|
16
|
-
import { getSessionId, getSessionInfo, isModernEraRequest, newSessionId } from "./session.mjs";
|
|
16
|
+
import { deriveSessionIdFromMCPSession, getSessionId, getSessionInfo, isModernEraRequest, newSessionId } from "./session.mjs";
|
|
17
17
|
import { decodeSessionId, encodeSessionId, readMcpSessionHeader, writeSessionIdToTransport } from "./session-token.mjs";
|
|
18
18
|
import { SEND_FEEDBACK_TOOL_NAME, getFeedbackToolDescriptor, resolveCollectFeedbackOptions } from "./feedback.mjs";
|
|
19
19
|
import { getReportMissingToolDescriptor, resolveMissingCapabilityToolName } from "./tools.mjs";
|
|
20
20
|
import { applyResolvedMetadata, isToolResultError } from "./tracing-helpers.mjs";
|
|
21
|
+
import { getToolInputProperties } from "./tool-input.mjs";
|
|
22
|
+
function resolveToolSchemaSessionId(data, extra) {
|
|
23
|
+
const token = decodeSessionId(readMcpSessionHeader(getRequestHeaders(extra)));
|
|
24
|
+
if (token) return token.sessionId;
|
|
25
|
+
if (extra?.sessionId) return deriveSessionIdFromMCPSession(extra.sessionId);
|
|
26
|
+
return data.sessionId;
|
|
27
|
+
}
|
|
21
28
|
async function captureToolCall(params) {
|
|
22
|
-
const { server, data, request, extra, execute, parameterOwnership, eventType, explicitContextIntent, extraEventProperties, omitCapturedParameters, takeCapturedError } = params;
|
|
29
|
+
const { server, data, request, extra, execute, parameterOwnership, inputSchema, eventType, explicitContextIntent, extraEventProperties, omitCapturedParameters, takeCapturedError } = params;
|
|
23
30
|
const resolvedEventType = eventType ?? MCPAnalyticsEventType.mcpToolsCall;
|
|
24
31
|
const isVirtualAnalyticsTool = resolvedEventType === MCPAnalyticsEventType.mcpMissingCapability || resolvedEventType === MCPAnalyticsEventType.mcpFeedback;
|
|
25
32
|
const ownership = getActiveAnalyticsParameterOwnership(data, request.params?.name, parameterOwnership, isVirtualAnalyticsTool);
|
|
26
33
|
const canCaptureContextIntent = ownership.read.context;
|
|
27
34
|
const conversation = resolveToolConversation(ownership.read.conversationId, request.params?.arguments, extra);
|
|
28
35
|
const downstreamRequest = cloneRequestWithoutOwnedAnalyticsArguments(request, ownership.strip);
|
|
36
|
+
const schemaSessionId = resolveToolSchemaSessionId(data, extra);
|
|
29
37
|
const startTime = new Date();
|
|
30
38
|
const preparedEvent = await prepareToolCallEvent(server, data, request, downstreamRequest, extra, startTime, conversation, ownership, resolvedEventType, canCaptureContextIntent);
|
|
39
|
+
if (preparedEvent && resolvedEventType === MCPAnalyticsEventType.mcpToolsCall) {
|
|
40
|
+
const sessionSchemas = (preparedEvent.event.sessionId ? data.toolInputSchemas.get(preparedEvent.event.sessionId) : void 0) ?? data.toolInputSchemas.get(schemaSessionId);
|
|
41
|
+
const schema = inputSchema ?? sessionSchemas?.get(request.params?.name ?? '');
|
|
42
|
+
preparedEvent.event.properties = {
|
|
43
|
+
...preparedEvent.event.properties,
|
|
44
|
+
...getToolInputProperties(request.params?.arguments ?? {}, schema, {
|
|
45
|
+
shouldRecordInputKey: data.options.shouldRecordInputKey
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
}
|
|
31
49
|
if (preparedEvent && explicitContextIntent) setExplicitContextIntent(preparedEvent.event, explicitContextIntent);
|
|
32
50
|
if (preparedEvent && extraEventProperties) preparedEvent.event.properties = {
|
|
33
51
|
...preparedEvent.event.properties,
|
|
@@ -345,7 +363,14 @@ async function getTracedToolsList(server, originalListToolsHandler, request, ext
|
|
|
345
363
|
let tools = [
|
|
346
364
|
...originalResponse.tools || []
|
|
347
365
|
];
|
|
348
|
-
if (data)
|
|
366
|
+
if (data) {
|
|
367
|
+
cacheToolAnalyticsParameterOwnership(data.toolAnalyticsParameterOwnership, tools);
|
|
368
|
+
if (event.sessionId) {
|
|
369
|
+
const sessionSchemas = data.toolInputSchemas.get(event.sessionId) ?? new Map();
|
|
370
|
+
for (const tool of tools)if (tool?.name) sessionSchemas.set(tool.name, tool.inputSchema);
|
|
371
|
+
data.toolInputSchemas.set(event.sessionId, sessionSchemas);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
349
374
|
if (data && isContextEnabled(data.options.context)) tools = addContextParameterToTools(tools, getContextDescription(data.options.context), data.logger);
|
|
350
375
|
if (data) {
|
|
351
376
|
const isFirstPage = request.params?.cursor == null;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { CompatibleRequestHandlerExtra, MCPAnalyticsData, MCPRequestLike, MCPServerLike, SessionInfo, UserIdentity } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Bounded LRU cache
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* server instances, so identities never bleed between servers.
|
|
3
|
+
* Bounded LRU cache, capped at `maxSize` entries so a long-lived server cannot
|
|
4
|
+
* accumulate state for unboundedly many sessions. One instance lives on each
|
|
5
|
+
* server's tracking data and is never shared across server instances.
|
|
7
6
|
*/
|
|
8
|
-
export declare class
|
|
7
|
+
export declare class BoundedCache<T> {
|
|
9
8
|
private readonly _cache;
|
|
10
9
|
private readonly _maxSize;
|
|
11
10
|
constructor(maxSize?: number);
|
|
12
|
-
get(
|
|
13
|
-
set(
|
|
14
|
-
has(
|
|
11
|
+
get(key: string): T | undefined;
|
|
12
|
+
set(key: string, value: T): void;
|
|
13
|
+
has(key: string): boolean;
|
|
15
14
|
size(): number;
|
|
16
15
|
}
|
|
16
|
+
export declare class IdentityCache extends BoundedCache<UserIdentity> {
|
|
17
|
+
}
|
|
17
18
|
export declare function getServerTrackingData(server: MCPServerLike): MCPAnalyticsData | undefined;
|
|
18
19
|
export declare function setServerTrackingData(server: MCPServerLike, data: MCPAnalyticsData): void;
|
|
19
20
|
export declare function areIdentitiesEqual(a: UserIdentity, b: UserIdentity): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/extensions/internal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,cAAc,EACd,aAAa,EAEb,WAAW,EACX,YAAY,EACb,MAAM,UAAU,CAAA;AAMjB
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/extensions/internal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,cAAc,EACd,aAAa,EAEb,WAAW,EACX,YAAY,EACb,MAAM,UAAU,CAAA;AAMjB;;;;GAIG;AACH,qBAAa,YAAY,CAAC,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IAEjC,YAAY,OAAO,SAAO,EAEzB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAS9B;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAW/B;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAExB;IAED,IAAI,IAAI,MAAM,CAEb;CACF;AAED,qBAAa,aAAc,SAAQ,YAAY,CAAC,YAAY,CAAC;CAAG;AAIhE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,GAAG,SAAS,CAEzF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAEzF;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,OAAO,CA4B5E;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,YAAY,CAapG;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,gBAAgB,EACtB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,cAAc,EACvB,kBAAkB,EAAE,WAAW,EAC/B,KAAK,CAAC,EAAE,6BAA6B;AACrC;;;;;GAKG;AACH,uBAAuB,UAAQ,GAC9B,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAuDnC;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,GAAG,SAAS,GAAG,WAAW,CAOtG;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,cAAc,EACvB,KAAK,CAAC,EAAE,6BAA6B,GACpC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAUzC"}
|
|
@@ -28,6 +28,7 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
BoundedCache: ()=>BoundedCache,
|
|
31
32
|
IdentityCache: ()=>IdentityCache,
|
|
32
33
|
areIdentitiesEqual: ()=>areIdentitiesEqual,
|
|
33
34
|
getServerTrackingData: ()=>getServerTrackingData,
|
|
@@ -41,33 +42,35 @@ const external_event_types_js_namespaceObject = require("./event-types.js");
|
|
|
41
42
|
const external_capture_js_namespaceObject = require("./capture.js");
|
|
42
43
|
const external_client_identity_js_namespaceObject = require("./client-identity.js");
|
|
43
44
|
const external_transport_identity_js_namespaceObject = require("./transport-identity.js");
|
|
44
|
-
class
|
|
45
|
+
class BoundedCache {
|
|
45
46
|
constructor(maxSize = 1000){
|
|
46
47
|
this._cache = new Map();
|
|
47
48
|
this._maxSize = maxSize;
|
|
48
49
|
}
|
|
49
|
-
get(
|
|
50
|
-
const
|
|
51
|
-
if (void 0 ===
|
|
52
|
-
this._cache.delete(
|
|
53
|
-
this._cache.set(
|
|
54
|
-
return
|
|
50
|
+
get(key) {
|
|
51
|
+
const value = this._cache.get(key);
|
|
52
|
+
if (void 0 === value) return;
|
|
53
|
+
this._cache.delete(key);
|
|
54
|
+
this._cache.set(key, value);
|
|
55
|
+
return value;
|
|
55
56
|
}
|
|
56
|
-
set(
|
|
57
|
-
this._cache.delete(
|
|
57
|
+
set(key, value) {
|
|
58
|
+
this._cache.delete(key);
|
|
58
59
|
if (this._cache.size >= this._maxSize) {
|
|
59
60
|
const oldestKey = this._cache.keys().next().value;
|
|
60
61
|
if (void 0 !== oldestKey) this._cache.delete(oldestKey);
|
|
61
62
|
}
|
|
62
|
-
this._cache.set(
|
|
63
|
+
this._cache.set(key, value);
|
|
63
64
|
}
|
|
64
|
-
has(
|
|
65
|
-
return this._cache.has(
|
|
65
|
+
has(key) {
|
|
66
|
+
return this._cache.has(key);
|
|
66
67
|
}
|
|
67
68
|
size() {
|
|
68
69
|
return this._cache.size;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
class IdentityCache extends BoundedCache {
|
|
73
|
+
}
|
|
71
74
|
const _serverTracking = new WeakMap();
|
|
72
75
|
function getServerTrackingData(server) {
|
|
73
76
|
return _serverTracking.get(server);
|
|
@@ -168,6 +171,7 @@ function getRequestResourceName(request) {
|
|
|
168
171
|
}
|
|
169
172
|
return 'Unknown';
|
|
170
173
|
}
|
|
174
|
+
exports.BoundedCache = __webpack_exports__.BoundedCache;
|
|
171
175
|
exports.IdentityCache = __webpack_exports__.IdentityCache;
|
|
172
176
|
exports.areIdentitiesEqual = __webpack_exports__.areIdentitiesEqual;
|
|
173
177
|
exports.getServerTrackingData = __webpack_exports__.getServerTrackingData;
|
|
@@ -177,6 +181,7 @@ exports.resolveEventProperties = __webpack_exports__.resolveEventProperties;
|
|
|
177
181
|
exports.setServerTrackingData = __webpack_exports__.setServerTrackingData;
|
|
178
182
|
exports.withIdentity = __webpack_exports__.withIdentity;
|
|
179
183
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
184
|
+
"BoundedCache",
|
|
180
185
|
"IdentityCache",
|
|
181
186
|
"areIdentitiesEqual",
|
|
182
187
|
"getServerTrackingData",
|
|
@@ -2,33 +2,35 @@ import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
|
2
2
|
import { captureEvent } from "./capture.mjs";
|
|
3
3
|
import { stampClientIdentity } from "./client-identity.mjs";
|
|
4
4
|
import { stampTransportIdentity } from "./transport-identity.mjs";
|
|
5
|
-
class
|
|
5
|
+
class BoundedCache {
|
|
6
6
|
constructor(maxSize = 1000){
|
|
7
7
|
this._cache = new Map();
|
|
8
8
|
this._maxSize = maxSize;
|
|
9
9
|
}
|
|
10
|
-
get(
|
|
11
|
-
const
|
|
12
|
-
if (void 0 ===
|
|
13
|
-
this._cache.delete(
|
|
14
|
-
this._cache.set(
|
|
15
|
-
return
|
|
10
|
+
get(key) {
|
|
11
|
+
const value = this._cache.get(key);
|
|
12
|
+
if (void 0 === value) return;
|
|
13
|
+
this._cache.delete(key);
|
|
14
|
+
this._cache.set(key, value);
|
|
15
|
+
return value;
|
|
16
16
|
}
|
|
17
|
-
set(
|
|
18
|
-
this._cache.delete(
|
|
17
|
+
set(key, value) {
|
|
18
|
+
this._cache.delete(key);
|
|
19
19
|
if (this._cache.size >= this._maxSize) {
|
|
20
20
|
const oldestKey = this._cache.keys().next().value;
|
|
21
21
|
if (void 0 !== oldestKey) this._cache.delete(oldestKey);
|
|
22
22
|
}
|
|
23
|
-
this._cache.set(
|
|
23
|
+
this._cache.set(key, value);
|
|
24
24
|
}
|
|
25
|
-
has(
|
|
26
|
-
return this._cache.has(
|
|
25
|
+
has(key) {
|
|
26
|
+
return this._cache.has(key);
|
|
27
27
|
}
|
|
28
28
|
size() {
|
|
29
29
|
return this._cache.size;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
class IdentityCache extends BoundedCache {
|
|
33
|
+
}
|
|
32
34
|
const _serverTracking = new WeakMap();
|
|
33
35
|
function getServerTrackingData(server) {
|
|
34
36
|
return _serverTracking.get(server);
|
|
@@ -129,4 +131,4 @@ function getRequestResourceName(request) {
|
|
|
129
131
|
}
|
|
130
132
|
return 'Unknown';
|
|
131
133
|
}
|
|
132
|
-
export { IdentityCache, areIdentitiesEqual, getServerTrackingData, handleIdentify, mergeIdentities, resolveEventProperties, setServerTrackingData, withIdentity };
|
|
134
|
+
export { BoundedCache, IdentityCache, areIdentitiesEqual, getServerTrackingData, handleIdentify, mergeIdentities, resolveEventProperties, setServerTrackingData, withIdentity };
|
|
@@ -29,6 +29,13 @@ export declare function hasToolFunction(tool: unknown): tool is RegisteredTool;
|
|
|
29
29
|
export declare function createWrappedTool(originalTool: RegisteredTool, wrappedFunction: ToolCallback): RegisteredTool;
|
|
30
30
|
export declare function isZ4Schema(schema: unknown): boolean;
|
|
31
31
|
export declare function isZodRawShapeCompat(schema: unknown): schema is Record<string, unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* Follows Zod wrappers to the schema that parses the caller's input: v3 effects
|
|
34
|
+
* (refine, transform, preprocess) and pipelines, v4 pipes (which include
|
|
35
|
+
* transforms), and optional, nullable, default, catch, and readonly wrappers.
|
|
36
|
+
* A v4 `z.preprocess` is a pipe whose input side is the transform, so its output side is followed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function unwrapInputSchema(schema: unknown): unknown;
|
|
32
39
|
export declare function getObjectShape(schema: unknown): Record<string, unknown> | undefined;
|
|
33
40
|
/**
|
|
34
41
|
* Reads the method name a `setRequestHandler` registration is for.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-sdk-compat.d.ts","sourceRoot":"","sources":["../../src/extensions/mcp-sdk-compat.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAK5D,MAAM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AC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGtF;AAkBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAY1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA6BnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOnF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAkCxD"}
|
|
@@ -56,7 +56,22 @@ function isZodTypeLike(value) {
|
|
|
56
56
|
return !!value && 'object' == typeof value && 'parse' in value && 'function' == typeof value.parse && 'safeParse' in value && 'function' == typeof value.safeParse;
|
|
57
57
|
}
|
|
58
58
|
function isZodRawShapeCompat(schema) {
|
|
59
|
-
return !!schema && 'object' == typeof schema && Object.values(schema).some(isZodTypeLike);
|
|
59
|
+
return !!schema && 'object' == typeof schema && !isZodTypeLike(schema) && Object.values(schema).some(isZodTypeLike);
|
|
60
|
+
}
|
|
61
|
+
const MAX_UNWRAP_DEPTH = 8;
|
|
62
|
+
function zodDef(schema) {
|
|
63
|
+
return isZ4Schema(schema) ? schema._zod?.def : schema._def;
|
|
64
|
+
}
|
|
65
|
+
function unwrapInputSchema(schema) {
|
|
66
|
+
let current = schema;
|
|
67
|
+
for(let depth = 0; depth < MAX_UNWRAP_DEPTH && isZodTypeLike(current); depth++){
|
|
68
|
+
const def = zodDef(current);
|
|
69
|
+
const pipeInput = def?.in !== void 0 && zodDef(def.in)?.type === 'transform' ? def.out : def?.in;
|
|
70
|
+
const inner = def?.schema ?? pipeInput ?? def?.innerType;
|
|
71
|
+
if (!inner) break;
|
|
72
|
+
current = inner;
|
|
73
|
+
}
|
|
74
|
+
return current;
|
|
60
75
|
}
|
|
61
76
|
function getObjectShape(schema) {
|
|
62
77
|
if (!schema || 'object' != typeof schema) return;
|
|
@@ -107,7 +122,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
107
122
|
hasToolFunction: ()=>hasToolFunction,
|
|
108
123
|
isZ4Schema: ()=>isZ4Schema,
|
|
109
124
|
isZodRawShapeCompat: ()=>isZodRawShapeCompat,
|
|
110
|
-
readRequestHandlerMethod: ()=>readRequestHandlerMethod
|
|
125
|
+
readRequestHandlerMethod: ()=>readRequestHandlerMethod,
|
|
126
|
+
unwrapInputSchema: ()=>unwrapInputSchema
|
|
111
127
|
});
|
|
112
128
|
exports.createWrappedTool = __webpack_exports__.createWrappedTool;
|
|
113
129
|
exports.getLiteralValue = __webpack_exports__.getLiteralValue;
|
|
@@ -118,6 +134,7 @@ exports.hasToolFunction = __webpack_exports__.hasToolFunction;
|
|
|
118
134
|
exports.isZ4Schema = __webpack_exports__.isZ4Schema;
|
|
119
135
|
exports.isZodRawShapeCompat = __webpack_exports__.isZodRawShapeCompat;
|
|
120
136
|
exports.readRequestHandlerMethod = __webpack_exports__.readRequestHandlerMethod;
|
|
137
|
+
exports.unwrapInputSchema = __webpack_exports__.unwrapInputSchema;
|
|
121
138
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
122
139
|
"createWrappedTool",
|
|
123
140
|
"getLiteralValue",
|
|
@@ -127,7 +144,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
127
144
|
"hasToolFunction",
|
|
128
145
|
"isZ4Schema",
|
|
129
146
|
"isZodRawShapeCompat",
|
|
130
|
-
"readRequestHandlerMethod"
|
|
147
|
+
"readRequestHandlerMethod",
|
|
148
|
+
"unwrapInputSchema"
|
|
131
149
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
132
150
|
Object.defineProperty(exports, '__esModule', {
|
|
133
151
|
value: true
|
|
@@ -27,7 +27,22 @@ function isZodTypeLike(value) {
|
|
|
27
27
|
return !!value && 'object' == typeof value && 'parse' in value && 'function' == typeof value.parse && 'safeParse' in value && 'function' == typeof value.safeParse;
|
|
28
28
|
}
|
|
29
29
|
function isZodRawShapeCompat(schema) {
|
|
30
|
-
return !!schema && 'object' == typeof schema && Object.values(schema).some(isZodTypeLike);
|
|
30
|
+
return !!schema && 'object' == typeof schema && !isZodTypeLike(schema) && Object.values(schema).some(isZodTypeLike);
|
|
31
|
+
}
|
|
32
|
+
const MAX_UNWRAP_DEPTH = 8;
|
|
33
|
+
function zodDef(schema) {
|
|
34
|
+
return isZ4Schema(schema) ? schema._zod?.def : schema._def;
|
|
35
|
+
}
|
|
36
|
+
function unwrapInputSchema(schema) {
|
|
37
|
+
let current = schema;
|
|
38
|
+
for(let depth = 0; depth < MAX_UNWRAP_DEPTH && isZodTypeLike(current); depth++){
|
|
39
|
+
const def = zodDef(current);
|
|
40
|
+
const pipeInput = def?.in !== void 0 && zodDef(def.in)?.type === 'transform' ? def.out : def?.in;
|
|
41
|
+
const inner = def?.schema ?? pipeInput ?? def?.innerType;
|
|
42
|
+
if (!inner) break;
|
|
43
|
+
current = inner;
|
|
44
|
+
}
|
|
45
|
+
return current;
|
|
31
46
|
}
|
|
32
47
|
function getObjectShape(schema) {
|
|
33
48
|
if (!schema || 'object' != typeof schema) return;
|
|
@@ -69,4 +84,4 @@ function getLiteralValue(schema) {
|
|
|
69
84
|
const directValue = schema.value;
|
|
70
85
|
if (void 0 !== directValue) return directValue;
|
|
71
86
|
}
|
|
72
|
-
export { createWrappedTool, getLiteralValue, getObjectShape, getToolFunction, getToolFunctionKey, hasToolFunction, isZ4Schema, isZodRawShapeCompat, readRequestHandlerMethod };
|
|
87
|
+
export { createWrappedTool, getLiteralValue, getObjectShape, getToolFunction, getToolFunctionKey, hasToolFunction, isZ4Schema, isZodRawShapeCompat, readRequestHandlerMethod, unwrapInputSchema };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsonRecord, ToolInputOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Describe the original arguments without reading their values.
|
|
4
|
+
* Pass a server-owned JSON Schema or Zod object schema, never a schema from the caller.
|
|
5
|
+
* By default unknown names become `[redacted]` because an argument name can contain private data;
|
|
6
|
+
* `shouldRecordInputKey` replaces that rule.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getToolInputProperties(input: unknown, inputSchema?: unknown, options?: ToolInputOptions): JsonRecord;
|
|
9
|
+
//# sourceMappingURL=tool-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-input.d.ts","sourceRoot":"","sources":["../../src/extensions/tool-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,UAAU,EAA0B,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAqDnG;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAgCpH"}
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
getToolInputProperties: ()=>getToolInputProperties
|
|
32
|
+
});
|
|
33
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
34
|
+
const external_mcp_sdk_compat_js_namespaceObject = require("./mcp-sdk-compat.js");
|
|
35
|
+
const MAX_INPUT_KEYS = 20;
|
|
36
|
+
const MAX_KEY_LENGTH = 64;
|
|
37
|
+
const ANALYTICS_KEYS = new Set([
|
|
38
|
+
'context',
|
|
39
|
+
'llm_model',
|
|
40
|
+
'conversation_id'
|
|
41
|
+
]);
|
|
42
|
+
function isRecord(value) {
|
|
43
|
+
return null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
function declaredProperties(schema) {
|
|
46
|
+
if (!isRecord(schema)) return;
|
|
47
|
+
const properties = schema.properties;
|
|
48
|
+
if ((0, external_mcp_sdk_compat_js_namespaceObject.isZodRawShapeCompat)(schema)) return schema;
|
|
49
|
+
return (0, external_mcp_sdk_compat_js_namespaceObject.getObjectShape)((0, external_mcp_sdk_compat_js_namespaceObject.unwrapInputSchema)(schema)) ?? (isRecord(properties) ? properties : void 0);
|
|
50
|
+
}
|
|
51
|
+
const recordDeclaredOnly = (_key, { declared })=>declared;
|
|
52
|
+
function shouldRecord(fn, key, declared) {
|
|
53
|
+
try {
|
|
54
|
+
return true === fn(key, {
|
|
55
|
+
declared
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function aliasNames(aliases) {
|
|
62
|
+
if (!isRecord(aliases)) return [];
|
|
63
|
+
return Object.values(aliases).flatMap((names)=>Array.isArray(names) ? names.filter((name)=>'string' == typeof name) : []);
|
|
64
|
+
}
|
|
65
|
+
function describeAliasesUsed(aliases, input) {
|
|
66
|
+
if (!isRecord(aliases)) return [];
|
|
67
|
+
const used = [];
|
|
68
|
+
for (const [canonical, names] of Object.entries(aliases)){
|
|
69
|
+
if (!Array.isArray(names) || Object.prototype.hasOwnProperty.call(input, canonical)) continue;
|
|
70
|
+
const alias = names.find((name)=>'string' == typeof name && Object.prototype.hasOwnProperty.call(input, name));
|
|
71
|
+
if (alias && alias.length <= MAX_KEY_LENGTH && canonical.length <= MAX_KEY_LENGTH) used.push(`${alias}:${canonical}`);
|
|
72
|
+
}
|
|
73
|
+
return used.sort().slice(0, MAX_INPUT_KEYS);
|
|
74
|
+
}
|
|
75
|
+
function getToolInputProperties(input, inputSchema, options) {
|
|
76
|
+
try {
|
|
77
|
+
if (!isRecord(input)) return {};
|
|
78
|
+
const prototype = Object.getPrototypeOf(input);
|
|
79
|
+
if (null !== prototype && prototype !== Object.prototype) return {};
|
|
80
|
+
const properties = declaredProperties(inputSchema);
|
|
81
|
+
const known = new Set([
|
|
82
|
+
...Object.keys(properties ?? {}),
|
|
83
|
+
...aliasNames(options?.inputAliases)
|
|
84
|
+
]);
|
|
85
|
+
const keys = Object.keys(input).filter((key)=>known.has(key) || !ANALYTICS_KEYS.has(key));
|
|
86
|
+
const record = options?.shouldRecordInputKey ?? recordDeclaredOnly;
|
|
87
|
+
const declared = [];
|
|
88
|
+
const undeclared = [];
|
|
89
|
+
let hasRedacted = false;
|
|
90
|
+
for (const key of keys){
|
|
91
|
+
const isDeclared = known.has(key);
|
|
92
|
+
if (key.length <= MAX_KEY_LENGTH && shouldRecord(record, key, isDeclared)) (isDeclared ? declared : undeclared).push(key);
|
|
93
|
+
else hasRedacted = true;
|
|
94
|
+
}
|
|
95
|
+
const visibleKeys = [
|
|
96
|
+
...declared.sort(),
|
|
97
|
+
...undeclared.sort()
|
|
98
|
+
].slice(0, MAX_INPUT_KEYS);
|
|
99
|
+
if (hasRedacted && visibleKeys.length < MAX_INPUT_KEYS) visibleKeys.push('[redacted]');
|
|
100
|
+
const aliasesUsed = describeAliasesUsed(options?.inputAliases, input);
|
|
101
|
+
return {
|
|
102
|
+
[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.InputKeys]: visibleKeys,
|
|
103
|
+
...aliasesUsed.length > 0 ? {
|
|
104
|
+
[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.InputAliasesUsed]: aliasesUsed
|
|
105
|
+
} : {}
|
|
106
|
+
};
|
|
107
|
+
} catch {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.getToolInputProperties = __webpack_exports__.getToolInputProperties;
|
|
112
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
113
|
+
"getToolInputProperties"
|
|
114
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
115
|
+
Object.defineProperty(exports, '__esModule', {
|
|
116
|
+
value: true
|
|
117
|
+
});
|