@armature-tech/mcp-analytics 0.6.21 → 0.6.23

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/SKILL.md CHANGED
@@ -313,6 +313,51 @@ wrapMastraTools(tools, {
313
313
  });
314
314
  ```
315
315
 
316
+ **Stateless / serverless HTTP (Vercel, Lambda):** do NOT serve with
317
+ `startHTTP({ options: { serverless: true } })`. Mastra's serverless mode
318
+ hard-codes `sessionIdGenerator: undefined` on the transient transport (your
319
+ generator is ignored), so no `Mcp-Session-Id` is ever issued at `initialize`,
320
+ clients have nothing to echo, and every tool call ships with no session hint —
321
+ ingest falls back to per-actor-per-day bucketing and concurrent conversations
322
+ merge into one dashboard session with client "unknown".
323
+
324
+ Use the hybrid instead: resolve the session from the request body first, then
325
+ let `initialize` (the only request where the resolved `sessionIdGenerator` is
326
+ defined) take Mastra's stateful branch and issue the identity-bearing id. Every
327
+ other request carries `sessionIdGenerator: undefined`, which Mastra treats as
328
+ stateless — fresh transient transport, no in-memory session lookup, so warm and
329
+ cold instances behave identically:
330
+
331
+ ```ts
332
+ import { resolveStatelessHttpSession } from "@armature-tech/mcp-analytics";
333
+
334
+ const body = req.method === "POST" ? await readJsonBody(req) : undefined;
335
+ // Mastra's own readJsonBody reuses a pre-parsed body — set it so the stream
336
+ // isn't consumed twice.
337
+ (req as IncomingMessage & { body?: unknown }).body = body;
338
+ const session = resolveStatelessHttpSession({ body, headers: req.headers });
339
+ await mcpServer.startHTTP({
340
+ url: new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`),
341
+ httpPath: "/mcp",
342
+ req,
343
+ res,
344
+ options: {
345
+ sessionIdGenerator: session.sessionIdGenerator, // defined only at initialize
346
+ enableJsonResponse: true,
347
+ },
348
+ });
349
+ await analytics.flush(); // with createMastraAnalytics; or rely on delivery: "await"
350
+ ```
351
+
352
+ The client echoes the issued `Mcp-Session-Id` (`mcp_<name>_v_<version>_<uuid>`)
353
+ on every subsequent request; the adapter forwards `requestInfo.headers` from
354
+ `context.mcp.extra`, and the recorder recovers the session from that header —
355
+ stable sessions and client attribution with no session store. Verify the wiring
356
+ with one curl: POST an `initialize` and check the response carries an
357
+ `mcp-session-id` header shaped `mcp_<client>_v_<version>_<uuid>`. If it's
358
+ missing, the request took the serverless path — make sure the `options` object
359
+ passes the resolved `sessionIdGenerator` field itself, not a wrapper function.
360
+
316
361
  The SDK also recognises `authInfo.apiKey` and `authInfo.principalId` as actor-seed
317
362
  aliases (alongside `authInfo.token` and `authInfo.clientId`), so Mastra setups that
318
363
  expose auth under those names don't need a custom `actorId` resolver.
@@ -334,6 +334,12 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
334
334
  ...(registration.title !== undefined ? { title: registration.title } : {}),
335
335
  ...(description !== undefined ? { description } : {}),
336
336
  ...(registeredHasInputSchema ? { inputSchema: plan.inputSchema } : {}),
337
+ ...(registration.outputSchema !== undefined
338
+ ? { outputSchema: registration.outputSchema }
339
+ : {}),
340
+ ...(registration.annotations !== undefined
341
+ ? { annotations: registration.annotations }
342
+ : {}),
337
343
  }, (async (...callbackArgs) => {
338
344
  const argsOrExtra = callbackArgs[0];
339
345
  const maybeExtra = callbackArgs[1];
@@ -398,6 +404,12 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
398
404
  if (registration.inputSchema !== undefined) {
399
405
  definition.inputSchema = registration.inputSchema;
400
406
  }
407
+ if (registration.outputSchema !== undefined) {
408
+ definition.outputSchema = registration.outputSchema;
409
+ }
410
+ if (registration.annotations !== undefined) {
411
+ definition.annotations = registration.annotations;
412
+ }
401
413
  definitions.push(...decorateDefinitions([definition]));
402
414
  }
403
415
  return definitions;
@@ -182,6 +182,8 @@ export type ToolRegistration = {
182
182
  title?: string;
183
183
  description?: string;
184
184
  inputSchema?: unknown;
185
+ outputSchema?: unknown;
186
+ annotations?: unknown;
185
187
  };
186
188
  export type McpServerInfo = {
187
189
  name: string;
@@ -331,6 +331,12 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
331
331
  ...(registration.title !== undefined ? { title: registration.title } : {}),
332
332
  ...(description !== undefined ? { description } : {}),
333
333
  ...(registeredHasInputSchema ? { inputSchema: plan.inputSchema } : {}),
334
+ ...(registration.outputSchema !== undefined
335
+ ? { outputSchema: registration.outputSchema }
336
+ : {}),
337
+ ...(registration.annotations !== undefined
338
+ ? { annotations: registration.annotations }
339
+ : {}),
334
340
  }, (async (...callbackArgs) => {
335
341
  const argsOrExtra = callbackArgs[0];
336
342
  const maybeExtra = callbackArgs[1];
@@ -395,6 +401,12 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
395
401
  if (registration.inputSchema !== undefined) {
396
402
  definition.inputSchema = registration.inputSchema;
397
403
  }
404
+ if (registration.outputSchema !== undefined) {
405
+ definition.outputSchema = registration.outputSchema;
406
+ }
407
+ if (registration.annotations !== undefined) {
408
+ definition.annotations = registration.annotations;
409
+ }
398
410
  definitions.push(...decorateDefinitions([definition]));
399
411
  }
400
412
  return definitions;
@@ -182,6 +182,8 @@ export type ToolRegistration = {
182
182
  title?: string;
183
183
  description?: string;
184
184
  inputSchema?: unknown;
185
+ outputSchema?: unknown;
186
+ annotations?: unknown;
185
187
  };
186
188
  export type McpServerInfo = {
187
189
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armature-tech/mcp-analytics",
3
- "version": "0.6.21",
3
+ "version": "0.6.23",
4
4
  "type": "module",
5
5
  "description": "MCP analytics wrapper SDK that instruments MCP tool declarations with telemetry.",
6
6
  "license": "Apache-2.0",