@posthog/mcp 0.0.9 → 0.1.17
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/LICENSE +307 -3
- package/README.md +182 -90
- package/dist/extensions/capture.d.ts +13 -0
- package/dist/extensions/capture.d.ts.map +1 -0
- package/dist/extensions/capture.js +80 -0
- package/dist/extensions/capture.mjs +46 -0
- package/dist/extensions/compatibility.d.ts +23 -0
- package/dist/extensions/compatibility.d.ts.map +1 -0
- package/dist/extensions/compatibility.js +113 -0
- package/dist/extensions/compatibility.mjs +67 -0
- package/dist/extensions/constants.d.ts +39 -0
- package/dist/extensions/constants.d.ts.map +1 -0
- package/dist/extensions/constants.js +86 -0
- package/dist/extensions/constants.mjs +37 -0
- package/dist/extensions/context-parameters.d.ts +31 -0
- package/dist/extensions/context-parameters.d.ts.map +1 -0
- package/dist/extensions/context-parameters.js +93 -0
- package/dist/extensions/context-parameters.mjs +50 -0
- package/dist/extensions/conversation-id.d.ts +52 -0
- package/dist/extensions/conversation-id.d.ts.map +1 -0
- package/dist/extensions/conversation-id.js +164 -0
- package/dist/extensions/conversation-id.mjs +103 -0
- package/dist/extensions/event-types.d.ts +21 -0
- package/dist/extensions/event-types.d.ts.map +1 -0
- package/dist/extensions/event-types.js +47 -0
- package/dist/extensions/event-types.mjs +13 -0
- package/dist/extensions/exceptions.d.ts +13 -0
- package/dist/extensions/exceptions.d.ts.map +1 -0
- package/dist/extensions/exceptions.js +58 -0
- package/dist/extensions/exceptions.mjs +24 -0
- package/dist/extensions/ids.d.ts +13 -0
- package/dist/extensions/ids.d.ts.map +1 -0
- package/dist/extensions/ids.js +55 -0
- package/dist/extensions/ids.mjs +18 -0
- package/dist/extensions/instrument-highlevel.d.ts +3 -0
- package/dist/extensions/instrument-highlevel.d.ts.map +1 -0
- package/dist/extensions/instrument-highlevel.js +229 -0
- package/dist/extensions/instrument-highlevel.mjs +195 -0
- package/dist/extensions/instrument-lowlevel.d.ts +8 -0
- package/dist/extensions/instrument-lowlevel.d.ts.map +1 -0
- package/dist/extensions/instrument-lowlevel.js +85 -0
- package/dist/extensions/instrument-lowlevel.mjs +51 -0
- package/dist/extensions/instrumentation.d.ts +59 -0
- package/dist/extensions/instrumentation.d.ts.map +1 -0
- package/dist/extensions/instrumentation.js +237 -0
- package/dist/extensions/instrumentation.mjs +194 -0
- package/dist/extensions/intent.d.ts +10 -0
- package/dist/extensions/intent.d.ts.map +1 -0
- package/dist/extensions/intent.js +84 -0
- package/dist/extensions/intent.mjs +44 -0
- package/dist/extensions/internal.d.ts +32 -0
- package/dist/extensions/internal.d.ts.map +1 -0
- package/dist/extensions/internal.js +158 -0
- package/dist/extensions/internal.mjs +106 -0
- package/dist/extensions/logger.d.ts +14 -0
- package/dist/extensions/logger.d.ts.map +1 -0
- package/dist/extensions/logger.js +47 -0
- package/dist/extensions/logger.mjs +10 -0
- package/dist/extensions/mcp-payloads.d.ts +5 -0
- package/dist/extensions/mcp-payloads.d.ts.map +1 -0
- package/dist/extensions/mcp-payloads.js +91 -0
- package/dist/extensions/mcp-payloads.mjs +54 -0
- package/dist/extensions/mcp-sdk-compat.d.ts +33 -0
- package/dist/extensions/mcp-sdk-compat.d.ts.map +1 -0
- package/dist/extensions/mcp-sdk-compat.js +112 -0
- package/dist/extensions/mcp-sdk-compat.mjs +60 -0
- package/dist/extensions/posthog-events.d.ts +14 -0
- package/dist/extensions/posthog-events.d.ts.map +1 -0
- package/dist/extensions/posthog-events.js +143 -0
- package/dist/extensions/posthog-events.mjs +109 -0
- package/dist/extensions/sanitization.d.ts +10 -0
- package/dist/extensions/sanitization.d.ts.map +1 -0
- package/dist/extensions/sanitization.js +96 -0
- package/dist/extensions/sanitization.mjs +62 -0
- package/dist/extensions/session.d.ts +20 -0
- package/dist/extensions/session.d.ts.map +1 -0
- package/dist/extensions/session.js +113 -0
- package/dist/extensions/session.mjs +67 -0
- package/dist/extensions/sink.d.ts +44 -0
- package/dist/extensions/sink.d.ts.map +1 -0
- package/dist/extensions/sink.js +102 -0
- package/dist/extensions/sink.mjs +65 -0
- package/dist/extensions/tools.d.ts +9 -0
- package/dist/extensions/tools.d.ts.map +1 -0
- package/dist/extensions/tools.js +79 -0
- package/dist/extensions/tools.mjs +39 -0
- package/dist/extensions/tracing-helpers.d.ts +29 -0
- package/dist/extensions/tracing-helpers.d.ts.map +1 -0
- package/dist/extensions/tracing-helpers.js +59 -0
- package/dist/extensions/tracing-helpers.mjs +16 -0
- package/dist/extensions/truncation.d.ts +25 -0
- package/dist/extensions/truncation.d.ts.map +1 -0
- package/dist/extensions/truncation.js +277 -0
- package/dist/extensions/truncation.mjs +228 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -0
- package/dist/index.mjs +83 -2929
- package/dist/types.d.ts +220 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +36 -0
- package/dist/version.mjs +2 -0
- package/package.json +55 -87
- package/src/extensions/capture.ts +68 -0
- package/src/extensions/compatibility.ts +138 -0
- package/src/extensions/constants.ts +48 -0
- package/src/extensions/context-parameters.ts +119 -0
- package/src/extensions/conversation-id.ts +177 -0
- package/src/extensions/event-types.ts +21 -0
- package/src/extensions/exceptions.ts +83 -0
- package/src/extensions/ids.ts +32 -0
- package/src/extensions/instrument-highlevel.ts +297 -0
- package/src/extensions/instrument-lowlevel.ts +83 -0
- package/src/extensions/instrumentation.ts +415 -0
- package/src/extensions/intent.ts +78 -0
- package/src/extensions/internal.ts +193 -0
- package/src/extensions/logger.ts +27 -0
- package/src/extensions/mcp-payloads.ts +98 -0
- package/src/extensions/mcp-sdk-compat.ts +160 -0
- package/src/extensions/posthog-events.ts +212 -0
- package/src/extensions/sanitization.ts +121 -0
- package/src/extensions/session.ts +117 -0
- package/src/extensions/sink.ts +130 -0
- package/src/extensions/tools.ts +50 -0
- package/src/extensions/tracing-helpers.ts +51 -0
- package/src/extensions/truncation.ts +453 -0
- package/src/index.ts +174 -0
- package/src/types.ts +244 -0
- package/src/version.ts +1 -0
- package/dist/index.cjs +0 -2937
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -264
- package/dist/index.d.mts +0 -263
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MCPServerLike, McpEvent } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Materializes an `McpEvent` against the server's tracking data + session info,
|
|
4
|
+
* then hands it to the `McpEventSink` (wrapping the user's posthog-node client) for the
|
|
5
|
+
* sanitize/truncate/beforeSend pipeline and capture. No-ops if the server isn't tracked or
|
|
6
|
+
* no PostHog client is attached — not passing `posthog` is how you turn capture off.
|
|
7
|
+
*
|
|
8
|
+
* Returns the sink's capture promise so the user-facing `capture()` can await it.
|
|
9
|
+
* Auto-capture callers (tool calls, listings, identify) intentionally ignore the
|
|
10
|
+
* return value, keeping the tool path isolated from analytics latency/errors.
|
|
11
|
+
*/
|
|
12
|
+
export declare function captureEvent(server: MCPServerLike, eventInput: McpEvent): Promise<void> | undefined;
|
|
13
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/extensions/capture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAMvD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAmDnG"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
captureEvent: ()=>captureEvent
|
|
28
|
+
});
|
|
29
|
+
const external_event_types_js_namespaceObject = require("./event-types.js");
|
|
30
|
+
const external_internal_js_namespaceObject = require("./internal.js");
|
|
31
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
32
|
+
const external_session_js_namespaceObject = require("./session.js");
|
|
33
|
+
function captureEvent(server, eventInput) {
|
|
34
|
+
const data = (0, external_internal_js_namespaceObject.getServerTrackingData)(server);
|
|
35
|
+
if (!data) return void (0, external_logger_js_namespaceObject.log)('Warning: Server tracking data not found. Event will not be published.');
|
|
36
|
+
const sink = data.sink;
|
|
37
|
+
if (!sink) return;
|
|
38
|
+
const sessionInfo = (0, external_session_js_namespaceObject.getSessionInfo)(server, data, eventInput.sessionId);
|
|
39
|
+
const duration = eventInput.duration || (eventInput.timestamp ? Date.now() - eventInput.timestamp.getTime() : void 0);
|
|
40
|
+
const fullEvent = {
|
|
41
|
+
id: eventInput.id || '',
|
|
42
|
+
sessionId: eventInput.sessionId || data.sessionId,
|
|
43
|
+
eventType: eventInput.eventType || external_event_types_js_namespaceObject.MCPAnalyticsEventType.custom,
|
|
44
|
+
eventName: eventInput.eventName,
|
|
45
|
+
timestamp: eventInput.timestamp || new Date(),
|
|
46
|
+
duration,
|
|
47
|
+
ipAddress: sessionInfo.ipAddress,
|
|
48
|
+
sdkLanguage: sessionInfo.sdkLanguage,
|
|
49
|
+
sdkVersion: sessionInfo.sdkVersion,
|
|
50
|
+
serverName: sessionInfo.serverName,
|
|
51
|
+
serverVersion: sessionInfo.serverVersion,
|
|
52
|
+
clientName: sessionInfo.clientName,
|
|
53
|
+
clientVersion: sessionInfo.clientVersion,
|
|
54
|
+
identifyActorGivenId: sessionInfo.identifyActorGivenId,
|
|
55
|
+
identifyActorData: sessionInfo.identifyActorData,
|
|
56
|
+
groups: sessionInfo.identifyActorGroups,
|
|
57
|
+
resourceName: eventInput.resourceName,
|
|
58
|
+
toolDescription: eventInput.toolDescription,
|
|
59
|
+
listedToolNames: eventInput.listedToolNames,
|
|
60
|
+
parameters: eventInput.parameters,
|
|
61
|
+
response: eventInput.response,
|
|
62
|
+
userIntent: eventInput.userIntent,
|
|
63
|
+
userIntentSource: eventInput.userIntentSource,
|
|
64
|
+
isError: eventInput.isError,
|
|
65
|
+
error: eventInput.error,
|
|
66
|
+
conversationId: eventInput.conversationId,
|
|
67
|
+
properties: eventInput.properties
|
|
68
|
+
};
|
|
69
|
+
return sink.capture(fullEvent, {
|
|
70
|
+
enableExceptionAutocapture: data.options.enableExceptionAutocapture ?? true,
|
|
71
|
+
beforeSend: data.options.beforeSend
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.captureEvent = __webpack_exports__.captureEvent;
|
|
75
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
76
|
+
"captureEvent"
|
|
77
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
78
|
+
Object.defineProperty(exports, '__esModule', {
|
|
79
|
+
value: true
|
|
80
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
2
|
+
import { getServerTrackingData } from "./internal.mjs";
|
|
3
|
+
import { log } from "./logger.mjs";
|
|
4
|
+
import { getSessionInfo } from "./session.mjs";
|
|
5
|
+
function captureEvent(server, eventInput) {
|
|
6
|
+
const data = getServerTrackingData(server);
|
|
7
|
+
if (!data) return void log('Warning: Server tracking data not found. Event will not be published.');
|
|
8
|
+
const sink = data.sink;
|
|
9
|
+
if (!sink) return;
|
|
10
|
+
const sessionInfo = getSessionInfo(server, data, eventInput.sessionId);
|
|
11
|
+
const duration = eventInput.duration || (eventInput.timestamp ? Date.now() - eventInput.timestamp.getTime() : void 0);
|
|
12
|
+
const fullEvent = {
|
|
13
|
+
id: eventInput.id || '',
|
|
14
|
+
sessionId: eventInput.sessionId || data.sessionId,
|
|
15
|
+
eventType: eventInput.eventType || MCPAnalyticsEventType.custom,
|
|
16
|
+
eventName: eventInput.eventName,
|
|
17
|
+
timestamp: eventInput.timestamp || new Date(),
|
|
18
|
+
duration,
|
|
19
|
+
ipAddress: sessionInfo.ipAddress,
|
|
20
|
+
sdkLanguage: sessionInfo.sdkLanguage,
|
|
21
|
+
sdkVersion: sessionInfo.sdkVersion,
|
|
22
|
+
serverName: sessionInfo.serverName,
|
|
23
|
+
serverVersion: sessionInfo.serverVersion,
|
|
24
|
+
clientName: sessionInfo.clientName,
|
|
25
|
+
clientVersion: sessionInfo.clientVersion,
|
|
26
|
+
identifyActorGivenId: sessionInfo.identifyActorGivenId,
|
|
27
|
+
identifyActorData: sessionInfo.identifyActorData,
|
|
28
|
+
groups: sessionInfo.identifyActorGroups,
|
|
29
|
+
resourceName: eventInput.resourceName,
|
|
30
|
+
toolDescription: eventInput.toolDescription,
|
|
31
|
+
listedToolNames: eventInput.listedToolNames,
|
|
32
|
+
parameters: eventInput.parameters,
|
|
33
|
+
response: eventInput.response,
|
|
34
|
+
userIntent: eventInput.userIntent,
|
|
35
|
+
userIntentSource: eventInput.userIntentSource,
|
|
36
|
+
isError: eventInput.isError,
|
|
37
|
+
error: eventInput.error,
|
|
38
|
+
conversationId: eventInput.conversationId,
|
|
39
|
+
properties: eventInput.properties
|
|
40
|
+
};
|
|
41
|
+
return sink.capture(fullEvent, {
|
|
42
|
+
enableExceptionAutocapture: data.options.enableExceptionAutocapture ?? true,
|
|
43
|
+
beforeSend: data.options.beforeSend
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export { captureEvent };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HighLevelMCPServerLike, MCPServerLike } from '../types';
|
|
2
|
+
type ServerRecord = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* PostHog MCP analytics Compatibility Module
|
|
5
|
+
*
|
|
6
|
+
* This module ensures compatibility with Model Context Protocol TypeScript SDK.
|
|
7
|
+
* PostHog MCP analytics only supports MCP SDK version 1.11 and above.
|
|
8
|
+
*
|
|
9
|
+
* Version 1.11+ is required because it introduced stable APIs for:
|
|
10
|
+
* - Tool registration and handling
|
|
11
|
+
* - Request handler access patterns
|
|
12
|
+
* - Client version detection
|
|
13
|
+
* - Server info structure
|
|
14
|
+
*/
|
|
15
|
+
export declare function logCompatibilityWarning(): void;
|
|
16
|
+
export declare function isHighLevelServer(server: unknown): server is ServerRecord & {
|
|
17
|
+
server: ServerRecord;
|
|
18
|
+
};
|
|
19
|
+
export declare function isLowLevelServer(server: unknown): server is ServerRecord;
|
|
20
|
+
export declare function isCompatibleServerType(server: unknown): MCPServerLike | HighLevelMCPServerLike;
|
|
21
|
+
export declare function getMCPCompatibleErrorMessage(error: unknown): string;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=compatibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../../src/extensions/compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAGrE,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE3C;;;;;;;;;;;GAWG;AAGH,wBAAgB,uBAAuB,IAAI,IAAI,CAI9C;AAGD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,GAAG;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,CAIpG;AAGD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAExE;AAGD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,GAAG,sBAAsB,CAgC9F;AAsDD,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAanE"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
isLowLevelServer: ()=>isLowLevelServer,
|
|
28
|
+
isHighLevelServer: ()=>isHighLevelServer,
|
|
29
|
+
logCompatibilityWarning: ()=>logCompatibilityWarning,
|
|
30
|
+
isCompatibleServerType: ()=>isCompatibleServerType,
|
|
31
|
+
getMCPCompatibleErrorMessage: ()=>getMCPCompatibleErrorMessage
|
|
32
|
+
});
|
|
33
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
34
|
+
function logCompatibilityWarning() {
|
|
35
|
+
(0, external_logger_js_namespaceObject.log)('PostHog MCP analytics SDK Compatibility: This version only supports Model Context Protocol TypeScript SDK v1.11 and above. Please upgrade if using an older version.');
|
|
36
|
+
}
|
|
37
|
+
function isHighLevelServer(server) {
|
|
38
|
+
return !!server && 'object' == typeof server && 'server' in server && !!server.server && 'object' == typeof server.server;
|
|
39
|
+
}
|
|
40
|
+
function isLowLevelServer(server) {
|
|
41
|
+
return !!server && 'object' == typeof server && !('server' in server);
|
|
42
|
+
}
|
|
43
|
+
function isCompatibleServerType(server) {
|
|
44
|
+
if (!server || 'object' != typeof server) {
|
|
45
|
+
logCompatibilityWarning();
|
|
46
|
+
throw new Error("PostHog MCP analytics SDK compatibility error: Server must be an object. Ensure you're using MCP SDK v1.11 or higher.");
|
|
47
|
+
}
|
|
48
|
+
if (isHighLevelServer(server)) {
|
|
49
|
+
if (!server._registeredTools || 'object' != typeof server._registeredTools) {
|
|
50
|
+
logCompatibilityWarning();
|
|
51
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: High-level server must have _registeredTools object. This requires MCP SDK v1.11 or higher.');
|
|
52
|
+
}
|
|
53
|
+
if ('function' != typeof server.tool) {
|
|
54
|
+
logCompatibilityWarning();
|
|
55
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: High-level server must have tool() method. This requires MCP SDK v1.11 or higher.');
|
|
56
|
+
}
|
|
57
|
+
const targetServer = server.server;
|
|
58
|
+
validateLowLevelServer(targetServer);
|
|
59
|
+
return server;
|
|
60
|
+
}
|
|
61
|
+
validateLowLevelServer(server);
|
|
62
|
+
return server;
|
|
63
|
+
}
|
|
64
|
+
function validateLowLevelServer(server) {
|
|
65
|
+
if (!server || 'object' != typeof server) {
|
|
66
|
+
logCompatibilityWarning();
|
|
67
|
+
throw new Error("PostHog MCP analytics SDK compatibility error: Server must be an object. Ensure you're using MCP SDK v1.11 or higher.");
|
|
68
|
+
}
|
|
69
|
+
const serverRecord = server;
|
|
70
|
+
if ('function' != typeof serverRecord.setRequestHandler) {
|
|
71
|
+
logCompatibilityWarning();
|
|
72
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server must have a setRequestHandler method. This requires MCP SDK v1.11 or higher.');
|
|
73
|
+
}
|
|
74
|
+
if (!(serverRecord._requestHandlers && serverRecord._requestHandlers instanceof Map)) {
|
|
75
|
+
logCompatibilityWarning();
|
|
76
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server._requestHandlers is not accessible. This requires MCP SDK v1.11 or higher.');
|
|
77
|
+
}
|
|
78
|
+
if ('function' != typeof serverRecord._requestHandlers.get) {
|
|
79
|
+
logCompatibilityWarning();
|
|
80
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server._requestHandlers must be a Map with a get method. This requires MCP SDK v1.11 or higher.');
|
|
81
|
+
}
|
|
82
|
+
if ('function' != typeof serverRecord.getClientVersion) {
|
|
83
|
+
logCompatibilityWarning();
|
|
84
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server.getClientVersion must be a function. This requires MCP SDK v1.11 or higher.');
|
|
85
|
+
}
|
|
86
|
+
if (!serverRecord._serverInfo || 'object' != typeof serverRecord._serverInfo || !('name' in serverRecord._serverInfo)) {
|
|
87
|
+
logCompatibilityWarning();
|
|
88
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server._serverInfo is not accessible or missing name. This requires MCP SDK v1.11 or higher.');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function getMCPCompatibleErrorMessage(error) {
|
|
92
|
+
if (error instanceof Error) try {
|
|
93
|
+
return JSON.stringify(error, Object.getOwnPropertyNames(error));
|
|
94
|
+
} catch {}
|
|
95
|
+
else if ('string' == typeof error) return error;
|
|
96
|
+
else if ('object' == typeof error && null !== error) return JSON.stringify(error);
|
|
97
|
+
return 'Unknown error';
|
|
98
|
+
}
|
|
99
|
+
exports.getMCPCompatibleErrorMessage = __webpack_exports__.getMCPCompatibleErrorMessage;
|
|
100
|
+
exports.isCompatibleServerType = __webpack_exports__.isCompatibleServerType;
|
|
101
|
+
exports.isHighLevelServer = __webpack_exports__.isHighLevelServer;
|
|
102
|
+
exports.isLowLevelServer = __webpack_exports__.isLowLevelServer;
|
|
103
|
+
exports.logCompatibilityWarning = __webpack_exports__.logCompatibilityWarning;
|
|
104
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
105
|
+
"getMCPCompatibleErrorMessage",
|
|
106
|
+
"isCompatibleServerType",
|
|
107
|
+
"isHighLevelServer",
|
|
108
|
+
"isLowLevelServer",
|
|
109
|
+
"logCompatibilityWarning"
|
|
110
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
111
|
+
Object.defineProperty(exports, '__esModule', {
|
|
112
|
+
value: true
|
|
113
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { log } from "./logger.mjs";
|
|
2
|
+
function logCompatibilityWarning() {
|
|
3
|
+
log('PostHog MCP analytics SDK Compatibility: This version only supports Model Context Protocol TypeScript SDK v1.11 and above. Please upgrade if using an older version.');
|
|
4
|
+
}
|
|
5
|
+
function isHighLevelServer(server) {
|
|
6
|
+
return !!server && 'object' == typeof server && 'server' in server && !!server.server && 'object' == typeof server.server;
|
|
7
|
+
}
|
|
8
|
+
function isLowLevelServer(server) {
|
|
9
|
+
return !!server && 'object' == typeof server && !('server' in server);
|
|
10
|
+
}
|
|
11
|
+
function isCompatibleServerType(server) {
|
|
12
|
+
if (!server || 'object' != typeof server) {
|
|
13
|
+
logCompatibilityWarning();
|
|
14
|
+
throw new Error("PostHog MCP analytics SDK compatibility error: Server must be an object. Ensure you're using MCP SDK v1.11 or higher.");
|
|
15
|
+
}
|
|
16
|
+
if (isHighLevelServer(server)) {
|
|
17
|
+
if (!server._registeredTools || 'object' != typeof server._registeredTools) {
|
|
18
|
+
logCompatibilityWarning();
|
|
19
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: High-level server must have _registeredTools object. This requires MCP SDK v1.11 or higher.');
|
|
20
|
+
}
|
|
21
|
+
if ('function' != typeof server.tool) {
|
|
22
|
+
logCompatibilityWarning();
|
|
23
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: High-level server must have tool() method. This requires MCP SDK v1.11 or higher.');
|
|
24
|
+
}
|
|
25
|
+
const targetServer = server.server;
|
|
26
|
+
validateLowLevelServer(targetServer);
|
|
27
|
+
return server;
|
|
28
|
+
}
|
|
29
|
+
validateLowLevelServer(server);
|
|
30
|
+
return server;
|
|
31
|
+
}
|
|
32
|
+
function validateLowLevelServer(server) {
|
|
33
|
+
if (!server || 'object' != typeof server) {
|
|
34
|
+
logCompatibilityWarning();
|
|
35
|
+
throw new Error("PostHog MCP analytics SDK compatibility error: Server must be an object. Ensure you're using MCP SDK v1.11 or higher.");
|
|
36
|
+
}
|
|
37
|
+
const serverRecord = server;
|
|
38
|
+
if ('function' != typeof serverRecord.setRequestHandler) {
|
|
39
|
+
logCompatibilityWarning();
|
|
40
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server must have a setRequestHandler method. This requires MCP SDK v1.11 or higher.');
|
|
41
|
+
}
|
|
42
|
+
if (!(serverRecord._requestHandlers && serverRecord._requestHandlers instanceof Map)) {
|
|
43
|
+
logCompatibilityWarning();
|
|
44
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server._requestHandlers is not accessible. This requires MCP SDK v1.11 or higher.');
|
|
45
|
+
}
|
|
46
|
+
if ('function' != typeof serverRecord._requestHandlers.get) {
|
|
47
|
+
logCompatibilityWarning();
|
|
48
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server._requestHandlers must be a Map with a get method. This requires MCP SDK v1.11 or higher.');
|
|
49
|
+
}
|
|
50
|
+
if ('function' != typeof serverRecord.getClientVersion) {
|
|
51
|
+
logCompatibilityWarning();
|
|
52
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server.getClientVersion must be a function. This requires MCP SDK v1.11 or higher.');
|
|
53
|
+
}
|
|
54
|
+
if (!serverRecord._serverInfo || 'object' != typeof serverRecord._serverInfo || !('name' in serverRecord._serverInfo)) {
|
|
55
|
+
logCompatibilityWarning();
|
|
56
|
+
throw new Error('PostHog MCP analytics SDK compatibility error: Server._serverInfo is not accessible or missing name. This requires MCP SDK v1.11 or higher.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function getMCPCompatibleErrorMessage(error) {
|
|
60
|
+
if (error instanceof Error) try {
|
|
61
|
+
return JSON.stringify(error, Object.getOwnPropertyNames(error));
|
|
62
|
+
} catch {}
|
|
63
|
+
else if ('string' == typeof error) return error;
|
|
64
|
+
else if ('object' == typeof error && null !== error) return JSON.stringify(error);
|
|
65
|
+
return 'Unknown error';
|
|
66
|
+
}
|
|
67
|
+
export { getMCPCompatibleErrorMessage, isCompatibleServerType, isHighLevelServer, isLowLevelServer, logCompatibilityWarning };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
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_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
|
+
export declare const POSTHOG_MCP_ANALYTICS_SOURCE = "posthog_mcp_analytics";
|
|
5
|
+
export declare const PostHogMCPAnalyticsEvent: {
|
|
6
|
+
readonly Custom: "$mcp_custom";
|
|
7
|
+
readonly Exception: "$exception";
|
|
8
|
+
readonly Identify: "$identify";
|
|
9
|
+
readonly Initialize: "$mcp_initialize";
|
|
10
|
+
readonly MissingCapability: "$mcp_missing_capability";
|
|
11
|
+
readonly PromptGet: "$mcp_prompt_get";
|
|
12
|
+
readonly PromptsList: "$mcp_prompts_list";
|
|
13
|
+
readonly ResourceRead: "$mcp_resource_read";
|
|
14
|
+
readonly ResourcesList: "$mcp_resources_list";
|
|
15
|
+
readonly ToolCall: "$mcp_tool_call";
|
|
16
|
+
readonly ToolsList: "$mcp_tools_list";
|
|
17
|
+
};
|
|
18
|
+
export type PostHogMCPAnalyticsEvent = (typeof PostHogMCPAnalyticsEvent)[keyof typeof PostHogMCPAnalyticsEvent];
|
|
19
|
+
export declare const PostHogMCPAnalyticsProperty: {
|
|
20
|
+
readonly ClientName: "$mcp_client_name";
|
|
21
|
+
readonly ClientVersion: "$mcp_client_version";
|
|
22
|
+
readonly ConversationId: "$mcp_conversation_id";
|
|
23
|
+
readonly DurationMs: "$mcp_duration_ms";
|
|
24
|
+
readonly IsError: "$mcp_is_error";
|
|
25
|
+
readonly Intent: "$mcp_intent";
|
|
26
|
+
readonly IntentSource: "$mcp_intent_source";
|
|
27
|
+
readonly ListedToolNames: "$mcp_listed_tool_names";
|
|
28
|
+
readonly Parameters: "$mcp_parameters";
|
|
29
|
+
readonly ResourceName: "$mcp_resource_name";
|
|
30
|
+
readonly Response: "$mcp_response";
|
|
31
|
+
readonly ServerName: "$mcp_server_name";
|
|
32
|
+
readonly ServerVersion: "$mcp_server_version";
|
|
33
|
+
readonly SessionId: "$session_id";
|
|
34
|
+
readonly Source: "$mcp_source";
|
|
35
|
+
readonly ToolDescription: "$mcp_tool_description";
|
|
36
|
+
readonly ToolName: "$mcp_tool_name";
|
|
37
|
+
};
|
|
38
|
+
export type PostHogMCPAnalyticsProperty = (typeof PostHogMCPAnalyticsProperty)[keyof typeof PostHogMCPAnalyticsProperty];
|
|
39
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/extensions/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,KAAK,CAAA;AAE/C,eAAO,MAAM,qCAAqC,2hBAAyhB,CAAA;AAE3kB,eAAO,MAAM,mCAAmC,4LACsI,CAAA;AAEtL,eAAO,MAAM,4BAA4B,0BAA0B,CAAA;AAInE,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;;;;;;;;;;;;;;;;;;CAkB9B,CAAA;AAEV,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
DEFAULT_CONTEXT_PARAMETER_DESCRIPTION: ()=>DEFAULT_CONTEXT_PARAMETER_DESCRIPTION,
|
|
28
|
+
DEFAULT_CONVERSATION_ID_DESCRIPTION: ()=>DEFAULT_CONVERSATION_ID_DESCRIPTION,
|
|
29
|
+
INACTIVITY_TIMEOUT_IN_MINUTES: ()=>INACTIVITY_TIMEOUT_IN_MINUTES,
|
|
30
|
+
POSTHOG_MCP_ANALYTICS_SOURCE: ()=>POSTHOG_MCP_ANALYTICS_SOURCE,
|
|
31
|
+
PostHogMCPAnalyticsEvent: ()=>PostHogMCPAnalyticsEvent,
|
|
32
|
+
PostHogMCPAnalyticsProperty: ()=>PostHogMCPAnalyticsProperty
|
|
33
|
+
});
|
|
34
|
+
const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
35
|
+
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.\"";
|
|
36
|
+
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.";
|
|
37
|
+
const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics';
|
|
38
|
+
const PostHogMCPAnalyticsEvent = {
|
|
39
|
+
Custom: '$mcp_custom',
|
|
40
|
+
Exception: '$exception',
|
|
41
|
+
Identify: '$identify',
|
|
42
|
+
Initialize: '$mcp_initialize',
|
|
43
|
+
MissingCapability: '$mcp_missing_capability',
|
|
44
|
+
PromptGet: '$mcp_prompt_get',
|
|
45
|
+
PromptsList: '$mcp_prompts_list',
|
|
46
|
+
ResourceRead: '$mcp_resource_read',
|
|
47
|
+
ResourcesList: '$mcp_resources_list',
|
|
48
|
+
ToolCall: '$mcp_tool_call',
|
|
49
|
+
ToolsList: '$mcp_tools_list'
|
|
50
|
+
};
|
|
51
|
+
const PostHogMCPAnalyticsProperty = {
|
|
52
|
+
ClientName: '$mcp_client_name',
|
|
53
|
+
ClientVersion: '$mcp_client_version',
|
|
54
|
+
ConversationId: '$mcp_conversation_id',
|
|
55
|
+
DurationMs: '$mcp_duration_ms',
|
|
56
|
+
IsError: '$mcp_is_error',
|
|
57
|
+
Intent: '$mcp_intent',
|
|
58
|
+
IntentSource: '$mcp_intent_source',
|
|
59
|
+
ListedToolNames: '$mcp_listed_tool_names',
|
|
60
|
+
Parameters: '$mcp_parameters',
|
|
61
|
+
ResourceName: '$mcp_resource_name',
|
|
62
|
+
Response: '$mcp_response',
|
|
63
|
+
ServerName: '$mcp_server_name',
|
|
64
|
+
ServerVersion: '$mcp_server_version',
|
|
65
|
+
SessionId: '$session_id',
|
|
66
|
+
Source: '$mcp_source',
|
|
67
|
+
ToolDescription: "$mcp_tool_description",
|
|
68
|
+
ToolName: '$mcp_tool_name'
|
|
69
|
+
};
|
|
70
|
+
exports.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = __webpack_exports__.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION;
|
|
71
|
+
exports.DEFAULT_CONVERSATION_ID_DESCRIPTION = __webpack_exports__.DEFAULT_CONVERSATION_ID_DESCRIPTION;
|
|
72
|
+
exports.INACTIVITY_TIMEOUT_IN_MINUTES = __webpack_exports__.INACTIVITY_TIMEOUT_IN_MINUTES;
|
|
73
|
+
exports.POSTHOG_MCP_ANALYTICS_SOURCE = __webpack_exports__.POSTHOG_MCP_ANALYTICS_SOURCE;
|
|
74
|
+
exports.PostHogMCPAnalyticsEvent = __webpack_exports__.PostHogMCPAnalyticsEvent;
|
|
75
|
+
exports.PostHogMCPAnalyticsProperty = __webpack_exports__.PostHogMCPAnalyticsProperty;
|
|
76
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
77
|
+
"DEFAULT_CONTEXT_PARAMETER_DESCRIPTION",
|
|
78
|
+
"DEFAULT_CONVERSATION_ID_DESCRIPTION",
|
|
79
|
+
"INACTIVITY_TIMEOUT_IN_MINUTES",
|
|
80
|
+
"POSTHOG_MCP_ANALYTICS_SOURCE",
|
|
81
|
+
"PostHogMCPAnalyticsEvent",
|
|
82
|
+
"PostHogMCPAnalyticsProperty"
|
|
83
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
84
|
+
Object.defineProperty(exports, '__esModule', {
|
|
85
|
+
value: true
|
|
86
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
|
|
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_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
|
+
const POSTHOG_MCP_ANALYTICS_SOURCE = 'posthog_mcp_analytics';
|
|
5
|
+
const PostHogMCPAnalyticsEvent = {
|
|
6
|
+
Custom: '$mcp_custom',
|
|
7
|
+
Exception: '$exception',
|
|
8
|
+
Identify: '$identify',
|
|
9
|
+
Initialize: '$mcp_initialize',
|
|
10
|
+
MissingCapability: '$mcp_missing_capability',
|
|
11
|
+
PromptGet: '$mcp_prompt_get',
|
|
12
|
+
PromptsList: '$mcp_prompts_list',
|
|
13
|
+
ResourceRead: '$mcp_resource_read',
|
|
14
|
+
ResourcesList: '$mcp_resources_list',
|
|
15
|
+
ToolCall: '$mcp_tool_call',
|
|
16
|
+
ToolsList: '$mcp_tools_list'
|
|
17
|
+
};
|
|
18
|
+
const PostHogMCPAnalyticsProperty = {
|
|
19
|
+
ClientName: '$mcp_client_name',
|
|
20
|
+
ClientVersion: '$mcp_client_version',
|
|
21
|
+
ConversationId: '$mcp_conversation_id',
|
|
22
|
+
DurationMs: '$mcp_duration_ms',
|
|
23
|
+
IsError: '$mcp_is_error',
|
|
24
|
+
Intent: '$mcp_intent',
|
|
25
|
+
IntentSource: '$mcp_intent_source',
|
|
26
|
+
ListedToolNames: '$mcp_listed_tool_names',
|
|
27
|
+
Parameters: '$mcp_parameters',
|
|
28
|
+
ResourceName: '$mcp_resource_name',
|
|
29
|
+
Response: '$mcp_response',
|
|
30
|
+
ServerName: '$mcp_server_name',
|
|
31
|
+
ServerVersion: '$mcp_server_version',
|
|
32
|
+
SessionId: '$session_id',
|
|
33
|
+
Source: '$mcp_source',
|
|
34
|
+
ToolDescription: "$mcp_tool_description",
|
|
35
|
+
ToolName: '$mcp_tool_name'
|
|
36
|
+
};
|
|
37
|
+
export { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION, DEFAULT_CONVERSATION_ID_DESCRIPTION, INACTIVITY_TIMEOUT_IN_MINUTES, POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MCPAnalyticsOptions } from '../types';
|
|
2
|
+
interface JsonSchema {
|
|
3
|
+
additionalProperties?: boolean;
|
|
4
|
+
allOf?: unknown;
|
|
5
|
+
anyOf?: unknown;
|
|
6
|
+
oneOf?: unknown;
|
|
7
|
+
properties?: Record<string, unknown>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
type?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ContextInjectableTool {
|
|
12
|
+
inputSchema?: JsonSchema;
|
|
13
|
+
name?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export declare function isContextEnabled(context: MCPAnalyticsOptions['context']): boolean;
|
|
17
|
+
export declare function getContextDescription(context: MCPAnalyticsOptions['context']): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a context parameter to a tool's JSON Schema.
|
|
20
|
+
* This function is called AFTER the MCP SDK has converted Zod schemas to JSON Schema,
|
|
21
|
+
* so we only need to handle JSON Schema format.
|
|
22
|
+
*
|
|
23
|
+
* Skips injection (with warning) for:
|
|
24
|
+
* - Tools that already have a 'context' parameter
|
|
25
|
+
* - Complex schemas (oneOf/allOf/anyOf) that can't safely have properties added
|
|
26
|
+
* - Schemas with additionalProperties: false
|
|
27
|
+
*/
|
|
28
|
+
export declare function addContextParameterToTool<TTool extends ContextInjectableTool>(tool: TTool, contextDescriptionOverride?: string): TTool;
|
|
29
|
+
export declare function addContextParameterToTools<TTool extends ContextInjectableTool>(tools: TTool[], contextDescriptionOverride?: string): TTool[];
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=context-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-parameters.d.ts","sourceRoot":"","sources":["../../src/extensions/context-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAInD,UAAU,UAAU;IAClB,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,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB,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,GAClC,KAAK,CAgEP;AAED,wBAAgB,0BAA0B,CAAC,KAAK,SAAS,qBAAqB,EAC5E,KAAK,EAAE,KAAK,EAAE,EACd,0BAA0B,CAAC,EAAE,MAAM,GAClC,KAAK,EAAE,CAQT"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
addContextParameterToTools: ()=>addContextParameterToTools,
|
|
28
|
+
addContextParameterToTool: ()=>addContextParameterToTool,
|
|
29
|
+
getContextDescription: ()=>getContextDescription,
|
|
30
|
+
isContextEnabled: ()=>isContextEnabled
|
|
31
|
+
});
|
|
32
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
33
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
34
|
+
function isContextEnabled(context) {
|
|
35
|
+
return false !== context;
|
|
36
|
+
}
|
|
37
|
+
function getContextDescription(context) {
|
|
38
|
+
return 'object' == typeof context ? context.description : void 0;
|
|
39
|
+
}
|
|
40
|
+
function addContextParameterToTool(tool, contextDescriptionOverride) {
|
|
41
|
+
const modifiedTool = {
|
|
42
|
+
...tool
|
|
43
|
+
};
|
|
44
|
+
const toolName = tool.name || 'unknown';
|
|
45
|
+
const schema = modifiedTool.inputSchema;
|
|
46
|
+
if (schema?.properties?.context) {
|
|
47
|
+
(0, external_logger_js_namespaceObject.log)(`WARN: Tool "${toolName}" already has 'context' parameter. Skipping context injection.`);
|
|
48
|
+
return modifiedTool;
|
|
49
|
+
}
|
|
50
|
+
if (schema?.oneOf || schema?.allOf || schema?.anyOf) {
|
|
51
|
+
(0, external_logger_js_namespaceObject.log)(`WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf). Skipping context injection.`);
|
|
52
|
+
return modifiedTool;
|
|
53
|
+
}
|
|
54
|
+
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: {},
|
|
57
|
+
required: []
|
|
58
|
+
};
|
|
59
|
+
const contextDescription = contextDescriptionOverride || external_constants_js_namespaceObject.DEFAULT_CONTEXT_PARAMETER_DESCRIPTION;
|
|
60
|
+
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
61
|
+
const inputSchema = modifiedTool.inputSchema;
|
|
62
|
+
if (!inputSchema.properties) inputSchema.properties = {};
|
|
63
|
+
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
64
|
+
inputSchema.properties.context = {
|
|
65
|
+
type: 'string',
|
|
66
|
+
description: contextDescription
|
|
67
|
+
};
|
|
68
|
+
if (Array.isArray(inputSchema.required)) {
|
|
69
|
+
if (!inputSchema.required.includes('context')) inputSchema.required.push('context');
|
|
70
|
+
} else inputSchema.required = [
|
|
71
|
+
'context'
|
|
72
|
+
];
|
|
73
|
+
return modifiedTool;
|
|
74
|
+
}
|
|
75
|
+
function addContextParameterToTools(tools, contextDescriptionOverride) {
|
|
76
|
+
return tools.map((tool)=>{
|
|
77
|
+
if ('get_more_tools' === tool.name) return tool;
|
|
78
|
+
return addContextParameterToTool(tool, contextDescriptionOverride);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.addContextParameterToTool = __webpack_exports__.addContextParameterToTool;
|
|
82
|
+
exports.addContextParameterToTools = __webpack_exports__.addContextParameterToTools;
|
|
83
|
+
exports.getContextDescription = __webpack_exports__.getContextDescription;
|
|
84
|
+
exports.isContextEnabled = __webpack_exports__.isContextEnabled;
|
|
85
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
86
|
+
"addContextParameterToTool",
|
|
87
|
+
"addContextParameterToTools",
|
|
88
|
+
"getContextDescription",
|
|
89
|
+
"isContextEnabled"
|
|
90
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
91
|
+
Object.defineProperty(exports, '__esModule', {
|
|
92
|
+
value: true
|
|
93
|
+
});
|