@armature-tech/mcp-analytics 0.6.0 → 0.6.2
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/cjs/events.d.ts +1 -1
- package/dist/cjs/events.js +10 -2
- package/dist/cjs/mastra.d.ts +1 -1
- package/dist/cjs/mastra.js +5 -1
- package/dist/cjs/recorder.js +7 -2
- package/dist/esm/events.d.ts +1 -1
- package/dist/esm/events.js +10 -2
- package/dist/esm/mastra.d.ts +1 -1
- package/dist/esm/mastra.js +5 -1
- package/dist/esm/recorder.js +7 -2
- package/package.json +1 -1
package/dist/cjs/events.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare const buildSessionInitBatch: ({ actorId, sessionId, requestId, st
|
|
|
47
47
|
clientInfo?: McpClientInfo;
|
|
48
48
|
}) => AnalyticsIngestBatch | null;
|
|
49
49
|
export declare const normalizeSessionId: (eventSessionId: string | undefined, extra: RequestExtra | undefined) => string | undefined;
|
|
50
|
-
export declare const normalizeRequestId: (eventRequestId: string | undefined
|
|
50
|
+
export declare const normalizeRequestId: (eventRequestId: string | undefined) => string;
|
|
51
51
|
export declare const normalizeStartedAt: ({ startedAt, durationMs, finishedAtMs, }: {
|
|
52
52
|
startedAt?: string | Date | number;
|
|
53
53
|
durationMs?: number;
|
package/dist/cjs/events.js
CHANGED
|
@@ -143,8 +143,16 @@ const normalizeSessionId = (eventSessionId, extra) => {
|
|
|
143
143
|
return trimOrUndefined((0, utils_js_1.headerValue)(extra?.requestInfo?.headers, "mcp-session-id"));
|
|
144
144
|
};
|
|
145
145
|
exports.normalizeSessionId = normalizeSessionId;
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
// The analytics request id seeds `event_id` (see `buildEventId`), so it MUST be
|
|
147
|
+
// unique per tool-call invocation. We intentionally do NOT derive it from the
|
|
148
|
+
// MCP JSON-RPC request id (`extra.requestId`): that is an in-memory per-client
|
|
149
|
+
// counter (0, 1, 2, …) that restarts on reconnect, across stateless gateway
|
|
150
|
+
// instances, etc., so two unrelated tool calls routinely share `extra.requestId`
|
|
151
|
+
// and would collide on `event_id` — making ingest dedupe the second call away.
|
|
152
|
+
// An explicit caller-supplied id still wins (it's a deliberate idempotency key);
|
|
153
|
+
// otherwise we mint a fresh uuid, matching the prototype-patch path in server.ts.
|
|
154
|
+
const normalizeRequestId = (eventRequestId) => {
|
|
155
|
+
return eventRequestId ?? (0, node_crypto_1.randomUUID)();
|
|
148
156
|
};
|
|
149
157
|
exports.normalizeRequestId = normalizeRequestId;
|
|
150
158
|
const normalizeStartedAt = ({ startedAt, durationMs, finishedAtMs, }) => {
|
package/dist/cjs/mastra.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export type MastraTool = {
|
|
|
5
5
|
description?: string;
|
|
6
6
|
inputSchema?: unknown;
|
|
7
7
|
outputSchema?: unknown;
|
|
8
|
+
annotations?: unknown;
|
|
8
9
|
execute?: MastraToolExecute;
|
|
9
|
-
[key: string]: unknown;
|
|
10
10
|
};
|
|
11
11
|
export type MastraToolMap = Record<string, MastraTool>;
|
|
12
12
|
export type MastraAdapterOptions = McpAnalyticsConfig & {
|
package/dist/cjs/mastra.js
CHANGED
|
@@ -109,7 +109,11 @@ const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra) => {
|
|
|
109
109
|
ctx: mastraContext,
|
|
110
110
|
extra,
|
|
111
111
|
sessionId: extra?.sessionId,
|
|
112
|
-
|
|
112
|
+
// Deliberately NOT forwarding `extra.requestId` (the MCP JSON-RPC id):
|
|
113
|
+
// it's a per-client counter that resets on reconnect, so reusing it as
|
|
114
|
+
// the event-id seed causes cross-session `event_id` collisions and lost
|
|
115
|
+
// events. Let the recorder mint a fresh per-call id (see
|
|
116
|
+
// `normalizeRequestId`). The JSON-RPC id stays available via `extra`.
|
|
113
117
|
authInfo: extra?.authInfo,
|
|
114
118
|
headers: extra?.requestInfo?.headers,
|
|
115
119
|
}, (strippedArgs) => originalExecute(strippedArgs, mastraContext));
|
package/dist/cjs/recorder.js
CHANGED
|
@@ -115,7 +115,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
115
115
|
durationMs,
|
|
116
116
|
finishedAtMs,
|
|
117
117
|
});
|
|
118
|
-
const requestId = (0, events_js_1.normalizeRequestId)(event.requestId
|
|
118
|
+
const requestId = (0, events_js_1.normalizeRequestId)(event.requestId);
|
|
119
119
|
const sessionId = (0, events_js_1.normalizeSessionId)(event.sessionId, event.extra);
|
|
120
120
|
const errorMessage = event.error === undefined
|
|
121
121
|
? undefined
|
|
@@ -193,7 +193,12 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
193
193
|
const buildHandlerContext = (extra) => ({
|
|
194
194
|
extra,
|
|
195
195
|
sessionId: extra?.sessionId,
|
|
196
|
-
|
|
196
|
+
// Deliberately NOT surfacing `extra.requestId` (the MCP JSON-RPC id) as
|
|
197
|
+
// `context.requestId`: `dispatch` spreads the handler context into
|
|
198
|
+
// `instrumentToolCall`, so a handler that forwards its context into a nested
|
|
199
|
+
// tool call would seed that call's `event_id` with the JSON-RPC id — a
|
|
200
|
+
// per-client counter that resets on reconnect — re-introducing the exact
|
|
201
|
+
// collisions this fix removes. The id stays reachable via `context.extra`.
|
|
197
202
|
authInfo: extra?.authInfo,
|
|
198
203
|
headers: extra?.requestInfo?.headers,
|
|
199
204
|
ctx: extra,
|
package/dist/esm/events.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare const buildSessionInitBatch: ({ actorId, sessionId, requestId, st
|
|
|
47
47
|
clientInfo?: McpClientInfo;
|
|
48
48
|
}) => AnalyticsIngestBatch | null;
|
|
49
49
|
export declare const normalizeSessionId: (eventSessionId: string | undefined, extra: RequestExtra | undefined) => string | undefined;
|
|
50
|
-
export declare const normalizeRequestId: (eventRequestId: string | undefined
|
|
50
|
+
export declare const normalizeRequestId: (eventRequestId: string | undefined) => string;
|
|
51
51
|
export declare const normalizeStartedAt: ({ startedAt, durationMs, finishedAtMs, }: {
|
|
52
52
|
startedAt?: string | Date | number;
|
|
53
53
|
durationMs?: number;
|
package/dist/esm/events.js
CHANGED
|
@@ -133,8 +133,16 @@ export const normalizeSessionId = (eventSessionId, extra) => {
|
|
|
133
133
|
return explicit;
|
|
134
134
|
return trimOrUndefined(headerValue(extra?.requestInfo?.headers, "mcp-session-id"));
|
|
135
135
|
};
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
// The analytics request id seeds `event_id` (see `buildEventId`), so it MUST be
|
|
137
|
+
// unique per tool-call invocation. We intentionally do NOT derive it from the
|
|
138
|
+
// MCP JSON-RPC request id (`extra.requestId`): that is an in-memory per-client
|
|
139
|
+
// counter (0, 1, 2, …) that restarts on reconnect, across stateless gateway
|
|
140
|
+
// instances, etc., so two unrelated tool calls routinely share `extra.requestId`
|
|
141
|
+
// and would collide on `event_id` — making ingest dedupe the second call away.
|
|
142
|
+
// An explicit caller-supplied id still wins (it's a deliberate idempotency key);
|
|
143
|
+
// otherwise we mint a fresh uuid, matching the prototype-patch path in server.ts.
|
|
144
|
+
export const normalizeRequestId = (eventRequestId) => {
|
|
145
|
+
return eventRequestId ?? randomUUID();
|
|
138
146
|
};
|
|
139
147
|
export const normalizeStartedAt = ({ startedAt, durationMs, finishedAtMs, }) => {
|
|
140
148
|
if (startedAt instanceof Date)
|
package/dist/esm/mastra.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export type MastraTool = {
|
|
|
5
5
|
description?: string;
|
|
6
6
|
inputSchema?: unknown;
|
|
7
7
|
outputSchema?: unknown;
|
|
8
|
+
annotations?: unknown;
|
|
8
9
|
execute?: MastraToolExecute;
|
|
9
|
-
[key: string]: unknown;
|
|
10
10
|
};
|
|
11
11
|
export type MastraToolMap = Record<string, MastraTool>;
|
|
12
12
|
export type MastraAdapterOptions = McpAnalyticsConfig & {
|
package/dist/esm/mastra.js
CHANGED
|
@@ -105,7 +105,11 @@ const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra) => {
|
|
|
105
105
|
ctx: mastraContext,
|
|
106
106
|
extra,
|
|
107
107
|
sessionId: extra?.sessionId,
|
|
108
|
-
|
|
108
|
+
// Deliberately NOT forwarding `extra.requestId` (the MCP JSON-RPC id):
|
|
109
|
+
// it's a per-client counter that resets on reconnect, so reusing it as
|
|
110
|
+
// the event-id seed causes cross-session `event_id` collisions and lost
|
|
111
|
+
// events. Let the recorder mint a fresh per-call id (see
|
|
112
|
+
// `normalizeRequestId`). The JSON-RPC id stays available via `extra`.
|
|
109
113
|
authInfo: extra?.authInfo,
|
|
110
114
|
headers: extra?.requestInfo?.headers,
|
|
111
115
|
}, (strippedArgs) => originalExecute(strippedArgs, mastraContext));
|
package/dist/esm/recorder.js
CHANGED
|
@@ -112,7 +112,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
112
112
|
durationMs,
|
|
113
113
|
finishedAtMs,
|
|
114
114
|
});
|
|
115
|
-
const requestId = normalizeRequestId(event.requestId
|
|
115
|
+
const requestId = normalizeRequestId(event.requestId);
|
|
116
116
|
const sessionId = normalizeSessionId(event.sessionId, event.extra);
|
|
117
117
|
const errorMessage = event.error === undefined
|
|
118
118
|
? undefined
|
|
@@ -190,7 +190,12 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
190
190
|
const buildHandlerContext = (extra) => ({
|
|
191
191
|
extra,
|
|
192
192
|
sessionId: extra?.sessionId,
|
|
193
|
-
|
|
193
|
+
// Deliberately NOT surfacing `extra.requestId` (the MCP JSON-RPC id) as
|
|
194
|
+
// `context.requestId`: `dispatch` spreads the handler context into
|
|
195
|
+
// `instrumentToolCall`, so a handler that forwards its context into a nested
|
|
196
|
+
// tool call would seed that call's `event_id` with the JSON-RPC id — a
|
|
197
|
+
// per-client counter that resets on reconnect — re-introducing the exact
|
|
198
|
+
// collisions this fix removes. The id stays reachable via `context.extra`.
|
|
194
199
|
authInfo: extra?.authInfo,
|
|
195
200
|
headers: extra?.requestInfo?.headers,
|
|
196
201
|
ctx: extra,
|