@posthog/mcp 0.9.1 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/extensions/capture.d.ts.map +1 -1
  2. package/dist/extensions/capture.js +3 -2
  3. package/dist/extensions/capture.mjs +3 -2
  4. package/dist/extensions/client-identity.d.ts +39 -0
  5. package/dist/extensions/client-identity.d.ts.map +1 -0
  6. package/dist/extensions/client-identity.js +68 -0
  7. package/dist/extensions/client-identity.mjs +25 -0
  8. package/dist/extensions/constants.d.ts +1 -0
  9. package/dist/extensions/constants.d.ts.map +1 -1
  10. package/dist/extensions/constants.js +1 -0
  11. package/dist/extensions/constants.mjs +1 -0
  12. package/dist/extensions/instrument-highlevel.d.ts.map +1 -1
  13. package/dist/extensions/instrumentation.d.ts.map +1 -1
  14. package/dist/extensions/instrumentation.js +37 -2
  15. package/dist/extensions/instrumentation.mjs +37 -2
  16. package/dist/extensions/internal.d.ts.map +1 -1
  17. package/dist/extensions/internal.js +2 -0
  18. package/dist/extensions/internal.mjs +2 -0
  19. package/dist/extensions/posthog-events.js +2 -0
  20. package/dist/extensions/posthog-events.mjs +2 -0
  21. package/dist/extensions/posthog-mcp.js +1 -0
  22. package/dist/extensions/posthog-mcp.mjs +1 -0
  23. package/dist/extensions/session-token.d.ts +7 -0
  24. package/dist/extensions/session-token.d.ts.map +1 -1
  25. package/dist/extensions/session-token.js +2 -0
  26. package/dist/extensions/session-token.mjs +2 -0
  27. package/dist/extensions/session.d.ts.map +1 -1
  28. package/dist/extensions/session.js +2 -0
  29. package/dist/extensions/session.mjs +2 -0
  30. package/dist/types.d.ts +17 -0
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/version.d.ts +1 -1
  33. package/dist/version.d.ts.map +1 -1
  34. package/dist/version.js +1 -1
  35. package/dist/version.mjs +1 -1
  36. package/package.json +4 -4
  37. package/src/extensions/capture.ts +9 -2
  38. package/src/extensions/client-identity.ts +81 -0
  39. package/src/extensions/constants.ts +1 -0
  40. package/src/extensions/instrument-highlevel.ts +9 -3
  41. package/src/extensions/instrumentation.ts +83 -7
  42. package/src/extensions/internal.ts +2 -0
  43. package/src/extensions/mcp-sdk-compat.ts +1 -1
  44. package/src/extensions/posthog-events.ts +8 -0
  45. package/src/extensions/posthog-mcp.ts +1 -0
  46. package/src/extensions/session-token.ts +15 -1
  47. package/src/extensions/session.ts +4 -0
  48. package/src/types.ts +17 -0
  49. package/src/version.ts +1 -1
@@ -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,MAAM,UAAU,CAAA;AAMvD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CA2DnG"}
1
+ {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/extensions/capture.ts"],"names":[],"mappings":"AAKA,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,CAkEnG"}
@@ -49,12 +49,13 @@ function captureEvent(server, eventInput) {
49
49
  sdkVersion: sessionInfo.sdkVersion,
50
50
  serverName: sessionInfo.serverName,
51
51
  serverVersion: sessionInfo.serverVersion,
52
- clientName: sessionInfo.clientName,
53
- clientVersion: sessionInfo.clientVersion,
52
+ clientName: eventInput.clientName ?? sessionInfo.clientName,
53
+ clientVersion: eventInput.clientVersion ?? sessionInfo.clientVersion,
54
54
  identifyActorGivenId: sessionInfo.identifyActorGivenId,
55
55
  identifyActorData: sessionInfo.identifyActorData,
56
56
  groups: sessionInfo.identifyActorGroups,
57
57
  resourceName: eventInput.resourceName,
58
+ protocolVersion: eventInput.protocolVersion ?? sessionInfo.protocolVersion,
58
59
  toolCategory: eventInput.toolCategory,
59
60
  toolDescription: eventInput.toolDescription,
60
61
  listedToolNames: eventInput.listedToolNames,
@@ -21,12 +21,13 @@ function captureEvent(server, eventInput) {
21
21
  sdkVersion: sessionInfo.sdkVersion,
22
22
  serverName: sessionInfo.serverName,
23
23
  serverVersion: sessionInfo.serverVersion,
24
- clientName: sessionInfo.clientName,
25
- clientVersion: sessionInfo.clientVersion,
24
+ clientName: eventInput.clientName ?? sessionInfo.clientName,
25
+ clientVersion: eventInput.clientVersion ?? sessionInfo.clientVersion,
26
26
  identifyActorGivenId: sessionInfo.identifyActorGivenId,
27
27
  identifyActorData: sessionInfo.identifyActorData,
28
28
  groups: sessionInfo.identifyActorGroups,
29
29
  resourceName: eventInput.resourceName,
30
+ protocolVersion: eventInput.protocolVersion ?? sessionInfo.protocolVersion,
30
31
  toolCategory: eventInput.toolCategory,
31
32
  toolDescription: eventInput.toolDescription,
32
33
  listedToolNames: eventInput.listedToolNames,
@@ -0,0 +1,39 @@
1
+ import type { McpEvent, MCPRequestLike } from '../types';
2
+ /**
3
+ * Client identity under the MCP 2026-07-28 (stateless) revision.
4
+ *
5
+ * That revision removes the `initialize` handshake and the `Mcp-Session-Id`
6
+ * header (SEP-2575 / SEP-2567). Client name/version and the protocol version no
7
+ * longer arrive once at `initialize` — they travel in every request's
8
+ * `params._meta` under these reverse-DNS keys. We mirror the literal key strings
9
+ * here rather than depend on the (still beta) v2 SDK, which is not a dependency
10
+ * of this package.
11
+ */
12
+ export declare const META_CLIENT_INFO_KEY = "io.modelcontextprotocol/clientInfo";
13
+ export declare const META_PROTOCOL_VERSION_KEY = "io.modelcontextprotocol/protocolVersion";
14
+ export interface MetaClientInfo {
15
+ clientName?: string;
16
+ clientVersion?: string;
17
+ protocolVersion?: string;
18
+ }
19
+ /**
20
+ * Reads the client name/version and protocol version a modern client puts in
21
+ * `params._meta`. Returns `undefined` when the request carries none (e.g. a
22
+ * legacy client, which sends this on `initialize` instead). Never throws.
23
+ */
24
+ export declare function readMetaClientInfo(request: MCPRequestLike): MetaClientInfo | undefined;
25
+ /**
26
+ * Stamps any client identity found in `params._meta` directly onto the event
27
+ * being built for *this* request, so it carries `$mcp_client_name`,
28
+ * `$mcp_client_version`, and `$mcp_protocol_version` even when there was no
29
+ * `initialize` to learn them from (the modern stateless case).
30
+ *
31
+ * Writing to the event — a per-request object — rather than the server-wide
32
+ * `sessionInfo` keeps identity correct when one instrumented server multiplexes
33
+ * concurrent requests from different clients (which the stateless spec allows):
34
+ * a sibling request can't clobber this event's attribution between now and when
35
+ * it's captured. Only fields the request actually carries are set, so a request
36
+ * without `_meta` leaves the event's existing values untouched.
37
+ */
38
+ export declare function stampMetaClientInfo(event: McpEvent, request: MCPRequestLike): void;
39
+ //# sourceMappingURL=client-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-identity.d.ts","sourceRoot":"","sources":["../../src/extensions/client-identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAExD;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,uCAAuC,CAAA;AACxE,eAAO,MAAM,yBAAyB,4CAA4C,CAAA;AAElF,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,GAAG,SAAS,CAyBtF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAclF"}
@@ -0,0 +1,68 @@
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
+ META_CLIENT_INFO_KEY: ()=>META_CLIENT_INFO_KEY,
28
+ META_PROTOCOL_VERSION_KEY: ()=>META_PROTOCOL_VERSION_KEY,
29
+ readMetaClientInfo: ()=>readMetaClientInfo,
30
+ stampMetaClientInfo: ()=>stampMetaClientInfo
31
+ });
32
+ const META_CLIENT_INFO_KEY = 'io.modelcontextprotocol/clientInfo';
33
+ const META_PROTOCOL_VERSION_KEY = 'io.modelcontextprotocol/protocolVersion';
34
+ function readMetaClientInfo(request) {
35
+ const meta = request.params?._meta;
36
+ if (!meta || 'object' != typeof meta) return;
37
+ const record = meta;
38
+ const result = {};
39
+ const clientInfo = record[META_CLIENT_INFO_KEY];
40
+ if (clientInfo && 'object' == typeof clientInfo) {
41
+ const { name, version } = clientInfo;
42
+ if ('string' == typeof name && name.length > 0) result.clientName = name;
43
+ if ('string' == typeof version && version.length > 0) result.clientVersion = version;
44
+ }
45
+ const protocolVersion = record[META_PROTOCOL_VERSION_KEY];
46
+ if ('string' == typeof protocolVersion && protocolVersion.length > 0) result.protocolVersion = protocolVersion;
47
+ return result.clientName || result.clientVersion || result.protocolVersion ? result : void 0;
48
+ }
49
+ function stampMetaClientInfo(event, request) {
50
+ const info = readMetaClientInfo(request);
51
+ if (!info) return;
52
+ if (info.clientName) event.clientName = info.clientName;
53
+ if (info.clientVersion) event.clientVersion = info.clientVersion;
54
+ if (info.protocolVersion) event.protocolVersion = info.protocolVersion;
55
+ }
56
+ exports.META_CLIENT_INFO_KEY = __webpack_exports__.META_CLIENT_INFO_KEY;
57
+ exports.META_PROTOCOL_VERSION_KEY = __webpack_exports__.META_PROTOCOL_VERSION_KEY;
58
+ exports.readMetaClientInfo = __webpack_exports__.readMetaClientInfo;
59
+ exports.stampMetaClientInfo = __webpack_exports__.stampMetaClientInfo;
60
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
61
+ "META_CLIENT_INFO_KEY",
62
+ "META_PROTOCOL_VERSION_KEY",
63
+ "readMetaClientInfo",
64
+ "stampMetaClientInfo"
65
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
66
+ Object.defineProperty(exports, '__esModule', {
67
+ value: true
68
+ });
@@ -0,0 +1,25 @@
1
+ const META_CLIENT_INFO_KEY = 'io.modelcontextprotocol/clientInfo';
2
+ const META_PROTOCOL_VERSION_KEY = 'io.modelcontextprotocol/protocolVersion';
3
+ function readMetaClientInfo(request) {
4
+ const meta = request.params?._meta;
5
+ if (!meta || 'object' != typeof meta) return;
6
+ const record = meta;
7
+ const result = {};
8
+ const clientInfo = record[META_CLIENT_INFO_KEY];
9
+ if (clientInfo && 'object' == typeof clientInfo) {
10
+ const { name, version } = clientInfo;
11
+ if ('string' == typeof name && name.length > 0) result.clientName = name;
12
+ if ('string' == typeof version && version.length > 0) result.clientVersion = version;
13
+ }
14
+ const protocolVersion = record[META_PROTOCOL_VERSION_KEY];
15
+ if ('string' == typeof protocolVersion && protocolVersion.length > 0) result.protocolVersion = protocolVersion;
16
+ return result.clientName || result.clientVersion || result.protocolVersion ? result : void 0;
17
+ }
18
+ function stampMetaClientInfo(event, request) {
19
+ const info = readMetaClientInfo(request);
20
+ if (!info) return;
21
+ if (info.clientName) event.clientName = info.clientName;
22
+ if (info.clientVersion) event.clientVersion = info.clientVersion;
23
+ if (info.protocolVersion) event.protocolVersion = info.protocolVersion;
24
+ }
25
+ export { META_CLIENT_INFO_KEY, META_PROTOCOL_VERSION_KEY, readMetaClientInfo, stampMetaClientInfo };
@@ -29,6 +29,7 @@ export declare const PostHogMCPAnalyticsProperty: {
29
29
  readonly IntentSource: "$mcp_intent_source";
30
30
  readonly ListedToolNames: "$mcp_listed_tool_names";
31
31
  readonly Parameters: "$mcp_parameters";
32
+ readonly ProtocolVersion: "$mcp_protocol_version";
32
33
  readonly ResourceName: "$mcp_resource_name";
33
34
  readonly Response: "$mcp_response";
34
35
  readonly ServerName: "$mcp_server_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;;;;;;;;;;;;;;;;;;;;;CAqB9B,CAAA;AAEV,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA"}
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;;;;;;;;;;;;;;;;;;;;;;CAsB9B,CAAA;AAEV,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA"}
@@ -62,6 +62,7 @@ const PostHogMCPAnalyticsProperty = {
62
62
  IntentSource: '$mcp_intent_source',
63
63
  ListedToolNames: '$mcp_listed_tool_names',
64
64
  Parameters: '$mcp_parameters',
65
+ ProtocolVersion: '$mcp_protocol_version',
65
66
  ResourceName: '$mcp_resource_name',
66
67
  Response: '$mcp_response',
67
68
  ServerName: '$mcp_server_name',
@@ -28,6 +28,7 @@ const PostHogMCPAnalyticsProperty = {
28
28
  IntentSource: '$mcp_intent_source',
29
29
  ListedToolNames: '$mcp_listed_tool_names',
30
30
  Parameters: '$mcp_parameters',
31
+ ProtocolVersion: '$mcp_protocol_version',
31
32
  ResourceName: '$mcp_resource_name',
32
33
  Response: '$mcp_response',
33
34
  ServerName: '$mcp_server_name',
@@ -1 +1 @@
1
- {"version":3,"file":"instrument-highlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-highlevel.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAiC,sBAAsB,EAAiC,MAAM,UAAU,CAAA;AAqPpH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAwB9E"}
1
+ {"version":3,"file":"instrument-highlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-highlevel.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,sBAAsB,EAIvB,MAAM,UAAU,CAAA;AAqPjB,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAwB9E"}
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/extensions/instrumentation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,cAAc,EACd,aAAa,EAGd,MAAM,UAAU,CAAA;AAWjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAYrD;;;;;;GAMG;AAEH,KAAK,iBAAiB,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,6BAA6B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7G;;;;GAIG;AACH,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;;;;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,CAuCnF;AAgHD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,MAA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aAAa,EACrB,wBAAwB,EAAE,iBAAiB,EAC3C,OAAO,EAAE,cAAc,EACvB,KAAK,CAAC,EAAE,6BAA6B,GACpC,OAAO,CAAC;IAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,CAyC9C;AAwDD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,CASnH;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAGtE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,CAUjH;AA8GD;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,aAAa,EACrB,yBAAyB,EAAE,iBAAiB,EAC5C,OAAO,EAAE,cAAc,EACvB,KAAK,CAAC,EAAE,6BAA6B,GACpC,OAAO,CAAC,OAAO,CAAC,CA0ClB"}
@@ -34,6 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
34
34
  });
35
35
  const external_context_parameters_js_namespaceObject = require("./context-parameters.js");
36
36
  const external_conversation_id_js_namespaceObject = require("./conversation-id.js");
37
+ const external_client_identity_js_namespaceObject = require("./client-identity.js");
37
38
  const external_capture_js_namespaceObject = require("./capture.js");
38
39
  const external_event_types_js_namespaceObject = require("./event-types.js");
39
40
  const external_exceptions_js_namespaceObject = require("./exceptions.js");
@@ -79,6 +80,7 @@ async function prepareToolCallEvent(server, data, request, downstreamRequest, ex
79
80
  toolCategory: toolName ? data.toolCategories.get(toolName) : void 0,
80
81
  toolDescription: toolName ? data.toolDescriptions.get(toolName) : void 0
81
82
  };
83
+ (0, external_client_identity_js_namespaceObject.stampMetaClientInfo)(event, request);
82
84
  await (0, external_tracing_helpers_js_namespaceObject.applyResolvedMetadata)(event, data, request, extra);
83
85
  (0, external_intent_js_namespaceObject.setEventIntent)(event, await (0, external_intent_js_namespaceObject.resolveToolCallIntent)(data, request, extra));
84
86
  return event;
@@ -143,6 +145,7 @@ async function handleListToolsRequest(server, originalListToolsHandler, request,
143
145
  eventType: external_event_types_js_namespaceObject.MCPAnalyticsEventType.mcpToolsList,
144
146
  timestamp: startTime
145
147
  };
148
+ (0, external_client_identity_js_namespaceObject.stampMetaClientInfo)(event, request);
146
149
  if (data) await (0, external_tracing_helpers_js_namespaceObject.applyResolvedMetadata)(event, data, request, extra);
147
150
  const tools = await getTracedToolsList(server, originalListToolsHandler, request, extra, event);
148
151
  if (!data) {
@@ -227,20 +230,40 @@ function mintStatelessSessionOnInitialize(server, data, request, extra) {
227
230
  if (!transport || extra?.sessionId || transport.sessionId) return;
228
231
  const sessionId = (0, external_session_js_namespaceObject.newSessionId)();
229
232
  const clientInfo = readInitializeClientInfo(request);
233
+ const requestedProtocolVersion = readProtocolVersion(void 0, request);
230
234
  const token = (0, external_session_token_js_namespaceObject.encodeSessionId)({
231
235
  sessionId,
232
236
  clientName: clientInfo?.name,
233
- clientVersion: clientInfo?.version
237
+ clientVersion: clientInfo?.version,
238
+ protocolVersion: requestedProtocolVersion
234
239
  });
235
240
  if (!(0, external_session_token_js_namespaceObject.writeSessionIdToTransport)(transport, token)) return;
236
241
  data.sessionId = sessionId;
237
242
  data.sessionSource = 'token';
238
243
  data.sessionInfo.clientName = clientInfo?.name;
239
244
  data.sessionInfo.clientVersion = clientInfo?.version;
245
+ data.sessionInfo.protocolVersion = requestedProtocolVersion;
240
246
  data.lastActivity = new Date();
241
247
  (0, external_internal_js_namespaceObject.setServerTrackingData)(server, data);
248
+ return sessionId;
242
249
  } catch (error) {
243
250
  (0, external_logger_js_namespaceObject.log)(`Warning: PostHog MCP analytics failed to mint a stateless session id - ${error}`);
251
+ return;
252
+ }
253
+ }
254
+ function upgradeMintedTokenToNegotiated(server, data, mintedSessionId, negotiatedProtocolVersion) {
255
+ try {
256
+ const transport = server.transport;
257
+ if (!transport) return;
258
+ const token = (0, external_session_token_js_namespaceObject.encodeSessionId)({
259
+ sessionId: mintedSessionId,
260
+ clientName: data.sessionInfo.clientName,
261
+ clientVersion: data.sessionInfo.clientVersion,
262
+ protocolVersion: negotiatedProtocolVersion
263
+ });
264
+ (0, external_session_token_js_namespaceObject.writeSessionIdToTransport)(transport, token);
265
+ } catch (error) {
266
+ (0, external_logger_js_namespaceObject.log)(`Warning: PostHog MCP analytics failed to upgrade the stateless session token - ${error}`);
244
267
  }
245
268
  }
246
269
  function readInitializeClientInfo(request) {
@@ -258,7 +281,7 @@ async function handleInitializeRequest(server, originalInitializeHandler, reques
258
281
  (0, external_logger_js_namespaceObject.log)('Warning: PostHog MCP analytics is unable to find server tracking data. Please ensure you have called instrument(server, options) before using tool calls.');
259
282
  return await originalInitializeHandler(request, extra);
260
283
  }
261
- mintStatelessSessionOnInitialize(server, data, request, extra);
284
+ const mintedSessionId = mintStatelessSessionOnInitialize(server, data, request, extra);
262
285
  const sessionId = (0, external_session_js_namespaceObject.getSessionId)(server, extra);
263
286
  await (0, external_internal_js_namespaceObject.handleIdentify)(server, data, sessionId, request, extra);
264
287
  const event = {
@@ -268,12 +291,24 @@ async function handleInitializeRequest(server, originalInitializeHandler, reques
268
291
  parameters: (0, external_mcp_payloads_js_namespaceObject.buildCapturedMcpParameters)(request),
269
292
  timestamp: new Date()
270
293
  };
294
+ (0, external_client_identity_js_namespaceObject.stampMetaClientInfo)(event, request);
271
295
  await (0, external_tracing_helpers_js_namespaceObject.applyResolvedMetadata)(event, data, request, extra);
272
296
  const result = await originalInitializeHandler(request, extra);
273
297
  event.response = result;
298
+ const negotiatedProtocolVersion = readProtocolVersion(result, request);
299
+ event.protocolVersion = negotiatedProtocolVersion;
300
+ data.sessionInfo.protocolVersion = negotiatedProtocolVersion;
301
+ (0, external_internal_js_namespaceObject.setServerTrackingData)(server, data);
302
+ if (mintedSessionId) upgradeMintedTokenToNegotiated(server, data, mintedSessionId, negotiatedProtocolVersion);
274
303
  (0, external_capture_js_namespaceObject.captureEvent)(server, event);
275
304
  return result;
276
305
  }
306
+ function readProtocolVersion(result, request) {
307
+ const negotiated = result?.protocolVersion;
308
+ if ('string' == typeof negotiated && negotiated.length > 0) return negotiated;
309
+ const requested = request.params?.protocolVersion;
310
+ return 'string' == typeof requested && requested.length > 0 ? requested : void 0;
311
+ }
277
312
  exports.cacheToolCategories = __webpack_exports__.cacheToolCategories;
278
313
  exports.cacheToolDescriptions = __webpack_exports__.cacheToolDescriptions;
279
314
  exports.captureToolCall = __webpack_exports__.captureToolCall;
@@ -1,5 +1,6 @@
1
1
  import { addContextParameterToTools, getContextDescription, isContextEnabled } from "./context-parameters.mjs";
2
2
  import { addConversationIdToTools, canInjectConversationIdPromptBack, cloneRequestWithoutConversationId, injectConversationIdPromptBack, resolveConversationId } from "./conversation-id.mjs";
3
+ import { stampMetaClientInfo } from "./client-identity.mjs";
3
4
  import { captureEvent } from "./capture.mjs";
4
5
  import { MCPAnalyticsEventType } from "./event-types.mjs";
5
6
  import { captureException } from "./exceptions.mjs";
@@ -45,6 +46,7 @@ async function prepareToolCallEvent(server, data, request, downstreamRequest, ex
45
46
  toolCategory: toolName ? data.toolCategories.get(toolName) : void 0,
46
47
  toolDescription: toolName ? data.toolDescriptions.get(toolName) : void 0
47
48
  };
49
+ stampMetaClientInfo(event, request);
48
50
  await applyResolvedMetadata(event, data, request, extra);
49
51
  setEventIntent(event, await resolveToolCallIntent(data, request, extra));
50
52
  return event;
@@ -109,6 +111,7 @@ async function handleListToolsRequest(server, originalListToolsHandler, request,
109
111
  eventType: MCPAnalyticsEventType.mcpToolsList,
110
112
  timestamp: startTime
111
113
  };
114
+ stampMetaClientInfo(event, request);
112
115
  if (data) await applyResolvedMetadata(event, data, request, extra);
113
116
  const tools = await getTracedToolsList(server, originalListToolsHandler, request, extra, event);
114
117
  if (!data) {
@@ -193,20 +196,40 @@ function mintStatelessSessionOnInitialize(server, data, request, extra) {
193
196
  if (!transport || extra?.sessionId || transport.sessionId) return;
194
197
  const sessionId = newSessionId();
195
198
  const clientInfo = readInitializeClientInfo(request);
199
+ const requestedProtocolVersion = readProtocolVersion(void 0, request);
196
200
  const token = encodeSessionId({
197
201
  sessionId,
198
202
  clientName: clientInfo?.name,
199
- clientVersion: clientInfo?.version
203
+ clientVersion: clientInfo?.version,
204
+ protocolVersion: requestedProtocolVersion
200
205
  });
201
206
  if (!writeSessionIdToTransport(transport, token)) return;
202
207
  data.sessionId = sessionId;
203
208
  data.sessionSource = 'token';
204
209
  data.sessionInfo.clientName = clientInfo?.name;
205
210
  data.sessionInfo.clientVersion = clientInfo?.version;
211
+ data.sessionInfo.protocolVersion = requestedProtocolVersion;
206
212
  data.lastActivity = new Date();
207
213
  setServerTrackingData(server, data);
214
+ return sessionId;
208
215
  } catch (error) {
209
216
  log(`Warning: PostHog MCP analytics failed to mint a stateless session id - ${error}`);
217
+ return;
218
+ }
219
+ }
220
+ function upgradeMintedTokenToNegotiated(server, data, mintedSessionId, negotiatedProtocolVersion) {
221
+ try {
222
+ const transport = server.transport;
223
+ if (!transport) return;
224
+ const token = encodeSessionId({
225
+ sessionId: mintedSessionId,
226
+ clientName: data.sessionInfo.clientName,
227
+ clientVersion: data.sessionInfo.clientVersion,
228
+ protocolVersion: negotiatedProtocolVersion
229
+ });
230
+ writeSessionIdToTransport(transport, token);
231
+ } catch (error) {
232
+ log(`Warning: PostHog MCP analytics failed to upgrade the stateless session token - ${error}`);
210
233
  }
211
234
  }
212
235
  function readInitializeClientInfo(request) {
@@ -224,7 +247,7 @@ async function handleInitializeRequest(server, originalInitializeHandler, reques
224
247
  log('Warning: PostHog MCP analytics is unable to find server tracking data. Please ensure you have called instrument(server, options) before using tool calls.');
225
248
  return await originalInitializeHandler(request, extra);
226
249
  }
227
- mintStatelessSessionOnInitialize(server, data, request, extra);
250
+ const mintedSessionId = mintStatelessSessionOnInitialize(server, data, request, extra);
228
251
  const sessionId = getSessionId(server, extra);
229
252
  await handleIdentify(server, data, sessionId, request, extra);
230
253
  const event = {
@@ -234,10 +257,22 @@ async function handleInitializeRequest(server, originalInitializeHandler, reques
234
257
  parameters: buildCapturedMcpParameters(request),
235
258
  timestamp: new Date()
236
259
  };
260
+ stampMetaClientInfo(event, request);
237
261
  await applyResolvedMetadata(event, data, request, extra);
238
262
  const result = await originalInitializeHandler(request, extra);
239
263
  event.response = result;
264
+ const negotiatedProtocolVersion = readProtocolVersion(result, request);
265
+ event.protocolVersion = negotiatedProtocolVersion;
266
+ data.sessionInfo.protocolVersion = negotiatedProtocolVersion;
267
+ setServerTrackingData(server, data);
268
+ if (mintedSessionId) upgradeMintedTokenToNegotiated(server, data, mintedSessionId, negotiatedProtocolVersion);
240
269
  captureEvent(server, event);
241
270
  return result;
242
271
  }
272
+ function readProtocolVersion(result, request) {
273
+ const negotiated = result?.protocolVersion;
274
+ if ('string' == typeof negotiated && negotiated.length > 0) return negotiated;
275
+ const requested = request.params?.protocolVersion;
276
+ return 'string' == typeof requested && requested.length > 0 ? requested : void 0;
277
+ }
243
278
  export { cacheToolCategories, cacheToolDescriptions, captureToolCall, handleInitializeRequest, handleListToolsRequest, patchRequestHandlers, readToolMetaCategory };
@@ -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,YAAY,EACb,MAAM,UAAU,CAAA;AAKjB;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,OAAO,SAAO;IAI1B,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAWhD,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AAO;IAI1B,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAWhD,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI;IAapD,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI/B,IAAI,IAAI,MAAM;CAGf;AAID,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,KAAK,CAAC,EAAE,6BAA6B,GACpC,OAAO,CAAC,IAAI,CAAC,CAgDf;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"}
@@ -35,6 +35,7 @@ __webpack_require__.d(__webpack_exports__, {
35
35
  const external_event_types_js_namespaceObject = require("./event-types.js");
36
36
  const external_logger_js_namespaceObject = require("./logger.js");
37
37
  const external_capture_js_namespaceObject = require("./capture.js");
38
+ const external_client_identity_js_namespaceObject = require("./client-identity.js");
38
39
  class IdentityCache {
39
40
  constructor(maxSize = 1000){
40
41
  this._cache = new Map();
@@ -106,6 +107,7 @@ async function handleIdentify(server, data, sessionId, request, extra) {
106
107
  },
107
108
  timestamp: new Date()
108
109
  };
110
+ (0, external_client_identity_js_namespaceObject.stampMetaClientInfo)(identifyEvent, request);
109
111
  try {
110
112
  const identityResult = 'function' == typeof data.options.identify ? await data.options.identify(request, extra) : data.options.identify;
111
113
  if (identityResult) {
@@ -1,6 +1,7 @@
1
1
  import { MCPAnalyticsEventType } from "./event-types.mjs";
2
2
  import { log } from "./logger.mjs";
3
3
  import { captureEvent } from "./capture.mjs";
4
+ import { stampMetaClientInfo } from "./client-identity.mjs";
4
5
  class IdentityCache {
5
6
  constructor(maxSize = 1000){
6
7
  this._cache = new Map();
@@ -72,6 +73,7 @@ async function handleIdentify(server, data, sessionId, request, extra) {
72
73
  },
73
74
  timestamp: new Date()
74
75
  };
76
+ stampMetaClientInfo(identifyEvent, request);
75
77
  try {
76
78
  const identityResult = 'function' == typeof data.options.identify ? await data.options.identify(request, extra) : data.options.identify;
77
79
  if (identityResult) {
@@ -98,6 +98,7 @@ function addCommonEventProperties(event, properties) {
98
98
  if (event.serverVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
99
99
  if (event.clientName) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
100
100
  if (event.clientVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
101
+ if (event.protocolVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ProtocolVersion] = event.protocolVersion;
101
102
  if (event.userIntent) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.Intent] = event.userIntent;
102
103
  if (event.userIntentSource) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.IntentSource] = event.userIntentSource;
103
104
  if (void 0 !== event.isError) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.IsError] = event.isError;
@@ -135,6 +136,7 @@ function buildExceptionEvent(event) {
135
136
  if (event.serverVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
136
137
  if (event.clientName) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
137
138
  if (event.clientVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
139
+ if (event.protocolVersion) properties[external_constants_js_namespaceObject.PostHogMCPAnalyticsProperty.ProtocolVersion] = event.protocolVersion;
138
140
  addCustomEventProperties(event, properties);
139
141
  return {
140
142
  event: external_constants_js_namespaceObject.PostHogMCPAnalyticsEvent.Exception,
@@ -70,6 +70,7 @@ function addCommonEventProperties(event, properties) {
70
70
  if (event.serverVersion) properties[PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
71
71
  if (event.clientName) properties[PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
72
72
  if (event.clientVersion) properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
73
+ if (event.protocolVersion) properties[PostHogMCPAnalyticsProperty.ProtocolVersion] = event.protocolVersion;
73
74
  if (event.userIntent) properties[PostHogMCPAnalyticsProperty.Intent] = event.userIntent;
74
75
  if (event.userIntentSource) properties[PostHogMCPAnalyticsProperty.IntentSource] = event.userIntentSource;
75
76
  if (void 0 !== event.isError) properties[PostHogMCPAnalyticsProperty.IsError] = event.isError;
@@ -107,6 +108,7 @@ function buildExceptionEvent(event) {
107
108
  if (event.serverVersion) properties[PostHogMCPAnalyticsProperty.ServerVersion] = event.serverVersion;
108
109
  if (event.clientName) properties[PostHogMCPAnalyticsProperty.ClientName] = event.clientName;
109
110
  if (event.clientVersion) properties[PostHogMCPAnalyticsProperty.ClientVersion] = event.clientVersion;
111
+ if (event.protocolVersion) properties[PostHogMCPAnalyticsProperty.ProtocolVersion] = event.protocolVersion;
110
112
  addCustomEventProperties(event, properties);
111
113
  return {
112
114
  event: PostHogMCPAnalyticsEvent.Exception,
@@ -114,6 +114,7 @@ function baseEvent(eventType, common) {
114
114
  const event = {
115
115
  eventType,
116
116
  sessionId: common.sessionId,
117
+ protocolVersion: common.protocolVersion,
117
118
  timestamp: common.timestamp ?? new Date(),
118
119
  properties: common.properties,
119
120
  groups: common.groups
@@ -86,6 +86,7 @@ function baseEvent(eventType, common) {
86
86
  const event = {
87
87
  eventType,
88
88
  sessionId: common.sessionId,
89
+ protocolVersion: common.protocolVersion,
89
90
  timestamp: common.timestamp ?? new Date(),
90
91
  properties: common.properties,
91
92
  groups: common.groups
@@ -18,6 +18,13 @@ export interface SessionTokenPayload {
18
18
  clientName?: string;
19
19
  /** MCP client version → `$mcp_client_version`. */
20
20
  clientVersion?: string;
21
+ /**
22
+ * MCP protocol (spec) version → `$mcp_protocol_version`. The client's
23
+ * *requested* version — the only one known when the token is minted (before
24
+ * the initialize handler negotiates). Lets pods that never saw `initialize`
25
+ * still stamp the spec version on their events.
26
+ */
27
+ protocolVersion?: string;
21
28
  }
22
29
  /**
23
30
  * Encodes a session token for the `Mcp-Session-Id` response header. Also
@@ -1 +1 @@
1
- {"version":3,"file":"session-token.d.ts","sourceRoot":"","sources":["../../src/extensions/session-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,kBAAkB,mBAAmB,CAAA;AAElD,oCAAoC;AACpC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAUD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAYpE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CA8B1E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgBzE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAsBpF"}
1
+ {"version":3,"file":"session-token.d.ts","sourceRoot":"","sources":["../../src/extensions/session-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,kBAAkB,mBAAmB,CAAA;AAElD,oCAAoC;AACpC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAWD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAepE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAiC1E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgBzE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAsBpF"}
@@ -42,6 +42,7 @@ function encodeSessionId(payload) {
42
42
  };
43
43
  if ('string' == typeof payload.clientName && payload.clientName.length > 0) wire.cn = payload.clientName.slice(0, MAX_CLIENT_FIELD_LENGTH);
44
44
  if ('string' == typeof payload.clientVersion && payload.clientVersion.length > 0) wire.cv = payload.clientVersion.slice(0, MAX_CLIENT_FIELD_LENGTH);
45
+ if ('string' == typeof payload.protocolVersion && payload.protocolVersion.length > 0) wire.pv = payload.protocolVersion.slice(0, MAX_CLIENT_FIELD_LENGTH);
45
46
  return utf8ToBase64Url(JSON.stringify(wire));
46
47
  }
47
48
  function decodeSessionId(value) {
@@ -61,6 +62,7 @@ function decodeSessionId(value) {
61
62
  };
62
63
  if ('string' == typeof wire.cn && wire.cn.length > 0) payload.clientName = wire.cn.slice(0, MAX_CLIENT_FIELD_LENGTH);
63
64
  if ('string' == typeof wire.cv && wire.cv.length > 0) payload.clientVersion = wire.cv.slice(0, MAX_CLIENT_FIELD_LENGTH);
65
+ if ('string' == typeof wire.pv && wire.pv.length > 0) payload.protocolVersion = wire.pv.slice(0, MAX_CLIENT_FIELD_LENGTH);
64
66
  return payload;
65
67
  }
66
68
  function readMcpSessionHeader(headers) {
@@ -10,6 +10,7 @@ function encodeSessionId(payload) {
10
10
  };
11
11
  if ('string' == typeof payload.clientName && payload.clientName.length > 0) wire.cn = payload.clientName.slice(0, MAX_CLIENT_FIELD_LENGTH);
12
12
  if ('string' == typeof payload.clientVersion && payload.clientVersion.length > 0) wire.cv = payload.clientVersion.slice(0, MAX_CLIENT_FIELD_LENGTH);
13
+ if ('string' == typeof payload.protocolVersion && payload.protocolVersion.length > 0) wire.pv = payload.protocolVersion.slice(0, MAX_CLIENT_FIELD_LENGTH);
13
14
  return utf8ToBase64Url(JSON.stringify(wire));
14
15
  }
15
16
  function decodeSessionId(value) {
@@ -29,6 +30,7 @@ function decodeSessionId(value) {
29
30
  };
30
31
  if ('string' == typeof wire.cn && wire.cn.length > 0) payload.clientName = wire.cn.slice(0, MAX_CLIENT_FIELD_LENGTH);
31
32
  if ('string' == typeof wire.cv && wire.cv.length > 0) payload.clientVersion = wire.cv.slice(0, MAX_CLIENT_FIELD_LENGTH);
33
+ if ('string' == typeof wire.pv && wire.pv.length > 0) payload.protocolVersion = wire.pv.slice(0, MAX_CLIENT_FIELD_LENGTH);
32
34
  return payload;
33
35
  }
34
36
  function readMcpSessionHeader(headers) {
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/extensions/session.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,aAAa,EAEb,WAAW,EACZ,MAAM,UAAU,CAAA;AAMjB,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,6BAA6B,GAAG,MAAM,CA+BjG;AAgBD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAClC,SAAS,CAAC,EAAE,MAAM,GACjB,WAAW,CAgCb"}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/extensions/session.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,aAAa,EAEb,WAAW,EACZ,MAAM,UAAU,CAAA;AAMjB,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAgCjG;AAgBD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAClC,SAAS,CAAC,EAAE,MAAM,GACjB,WAAW,CAmCb"}
@@ -50,6 +50,7 @@ function getSessionId(server, extra) {
50
50
  data.sessionSource = 'token';
51
51
  data.sessionInfo.clientName = token.clientName;
52
52
  data.sessionInfo.clientVersion = token.clientVersion;
53
+ data.sessionInfo.protocolVersion = token.protocolVersion;
53
54
  sessionId = token.sessionId;
54
55
  } else if (extra?.sessionId) {
55
56
  data.sessionSource = 'mcp';
@@ -81,6 +82,7 @@ function getSessionInfo(server, data, sessionId) {
81
82
  serverVersion: server._serverInfo?.version,
82
83
  clientName: clientInfo?.name,
83
84
  clientVersion: clientInfo?.version,
85
+ protocolVersion: data?.sessionInfo.protocolVersion,
84
86
  identifyActorGivenId: actorInfo?.distinctId,
85
87
  identifyActorData: actorInfo?.properties || {},
86
88
  identifyActorGroups: actorInfo?.groups
@@ -19,6 +19,7 @@ function getSessionId(server, extra) {
19
19
  data.sessionSource = 'token';
20
20
  data.sessionInfo.clientName = token.clientName;
21
21
  data.sessionInfo.clientVersion = token.clientVersion;
22
+ data.sessionInfo.protocolVersion = token.protocolVersion;
22
23
  sessionId = token.sessionId;
23
24
  } else if (extra?.sessionId) {
24
25
  data.sessionSource = 'mcp';
@@ -50,6 +51,7 @@ function getSessionInfo(server, data, sessionId) {
50
51
  serverVersion: server._serverInfo?.version,
51
52
  clientName: clientInfo?.name,
52
53
  clientVersion: clientInfo?.version,
54
+ protocolVersion: data?.sessionInfo.protocolVersion,
53
55
  identifyActorGivenId: actorInfo?.distinctId,
54
56
  identifyActorData: actorInfo?.properties || {},
55
57
  identifyActorGroups: actorInfo?.groups