@brizz/sdk 0.1.42 → 0.1.44

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 (33) hide show
  1. package/README.md +44 -0
  2. package/dist/{chunk-QUV5HYJ2.cjs → chunk-3IGBYXLR.cjs} +4 -4
  3. package/dist/{chunk-FORVS4QW.cjs → chunk-5WBPX342.cjs} +7 -1
  4. package/dist/chunk-A3HH5OUL.cjs +240 -0
  5. package/dist/chunk-AELIATPI.js +240 -0
  6. package/dist/{chunk-Y7NMZAQT.js → chunk-AOT5NJDV.js} +6 -0
  7. package/dist/{chunk-7FQQHF5U.js → chunk-APOYOP7D.js} +1 -1
  8. package/dist/index.cjs +270 -128
  9. package/dist/index.js +154 -12
  10. package/dist/{interrupt-ERCX5RXR.js → interrupt-A6O7N72X.js} +2 -2
  11. package/dist/interrupt-IKOUBQGN.cjs +12 -0
  12. package/dist/{mcp-GVGTOWHP.cjs → mcp-5FSUXYHM.cjs} +97 -100
  13. package/dist/{mcp-5BFXKN63.js → mcp-7EJXVCPI.js} +83 -86
  14. package/dist/types/cjs/index.d.ts +2 -2
  15. package/dist/types/cjs/internal/instrumentation/mcp/client-session.d.ts +24 -0
  16. package/dist/types/cjs/internal/instrumentation/mcp/session.d.ts +3 -1
  17. package/dist/types/cjs/internal/sdk.d.ts +2 -0
  18. package/dist/types/cjs/internal/semantic-conventions.d.ts +3 -0
  19. package/dist/types/cjs/internal/trace/agent.d.ts +18 -0
  20. package/dist/types/cjs/internal/trace/index.d.ts +2 -0
  21. package/dist/types/cjs/internal/trace/session.d.ts +2 -1
  22. package/dist/types/esm/index.d.ts +2 -2
  23. package/dist/types/esm/internal/instrumentation/mcp/client-session.d.ts +24 -0
  24. package/dist/types/esm/internal/instrumentation/mcp/session.d.ts +3 -1
  25. package/dist/types/esm/internal/sdk.d.ts +2 -0
  26. package/dist/types/esm/internal/semantic-conventions.d.ts +3 -0
  27. package/dist/types/esm/internal/trace/agent.d.ts +18 -0
  28. package/dist/types/esm/internal/trace/index.d.ts +2 -0
  29. package/dist/types/esm/internal/trace/session.d.ts +2 -1
  30. package/package.json +10 -10
  31. package/dist/chunk-K3NPYISB.cjs +0 -8
  32. package/dist/chunk-KVOGOKOB.js +0 -8
  33. package/dist/interrupt-3NXOTY4N.cjs +0 -12
package/dist/index.js CHANGED
@@ -3,8 +3,9 @@ import {
3
3
  parseDSN
4
4
  } from "./chunk-7SUF4VVI.js";
5
5
  import {
6
+ configure,
6
7
  getSDKVersion
7
- } from "./chunk-KVOGOKOB.js";
8
+ } from "./chunk-AELIATPI.js";
8
9
  import {
9
10
  DEFAULT_LOG_LEVEL,
10
11
  LogLevel,
@@ -15,8 +16,11 @@ import {
15
16
  } from "./chunk-Y4HNUX3Q.js";
16
17
  import {
17
18
  InterruptPropagator
18
- } from "./chunk-7FQQHF5U.js";
19
+ } from "./chunk-APOYOP7D.js";
19
20
  import {
21
+ AGENT_ID,
22
+ AGENT_NAME,
23
+ AGENT_PARENT_ID,
20
24
  BRIZZ,
21
25
  EXTERNAL_LINK_EVENT_NAME,
22
26
  EXTERNAL_LINK_TITLE,
@@ -69,7 +73,7 @@ import {
69
73
  USER_NAME,
70
74
  USER_PLAN,
71
75
  USER_ROLE
72
- } from "./chunk-Y7NMZAQT.js";
76
+ } from "./chunk-AOT5NJDV.js";
73
77
  import {
74
78
  __require
75
79
  } from "./chunk-3RG5ZIWI.js";
@@ -126,7 +130,7 @@ function loadGenAIInstrumentations() {
126
130
  function loadMCPInstrumentation() {
127
131
  void (async () => {
128
132
  try {
129
- const { MCPInstrumentation } = await import("./mcp-5BFXKN63.js");
133
+ const { MCPInstrumentation } = await import("./mcp-7EJXVCPI.js");
130
134
  const mcp = new MCPInstrumentation({ exceptionLogger });
131
135
  registerInstrumentations({ instrumentations: [mcp] });
132
136
  logger.debug("Auto-loaded MCP instrumentation");
@@ -182,7 +186,7 @@ function loadVercelAITelemetry() {
182
186
  }
183
187
  const isV7 = typeof ai.registerTelemetry === "function";
184
188
  const integrations = [];
185
- const { createInterruptIntegration } = await import("./interrupt-ERCX5RXR.js");
189
+ const { createInterruptIntegration } = await import("./interrupt-A6O7N72X.js");
186
190
  integrations.push(createInterruptIntegration());
187
191
  let otelCollectorLoaded = false;
188
192
  try {
@@ -509,7 +513,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
509
513
  const mcpModules = this.manualModules.mcp;
510
514
  void (async () => {
511
515
  try {
512
- const { MCPInstrumentation } = await import("./mcp-5BFXKN63.js");
516
+ const { MCPInstrumentation } = await import("./mcp-7EJXVCPI.js");
513
517
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
514
518
  instrumentation.manuallyInstrument(mcpModules);
515
519
  logger.debug("Manual instrumentation enabled for MCP");
@@ -582,7 +586,7 @@ function withProperties(properties, fn, thisArg) {
582
586
  );
583
587
  };
584
588
  }
585
- function propagatePropertiesImperatively(properties) {
589
+ function propagatePropertiesImperatively(properties, base = context.active()) {
586
590
  try {
587
591
  const manager = context;
588
592
  const mgr = manager._getContextManager?.();
@@ -590,7 +594,6 @@ function propagatePropertiesImperatively(properties) {
590
594
  if (!store || typeof store.enterWith !== "function") {
591
595
  return;
592
596
  }
593
- const base = context.active();
594
597
  const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
595
598
  const merged = prev ? { ...prev, ...properties } : properties;
596
599
  store.enterWith(base.setValue(PROPERTIES_CONTEXT_KEY, merged));
@@ -814,9 +817,9 @@ var Session = class {
814
817
  * @param text - Text to append (null becomes a null/"hide marker")
815
818
  * @param context - Optional per-turn context bag to attach to this turn
816
819
  */
817
- setInput(text, context4) {
820
+ setInput(text, context5) {
818
821
  this.inputs.push(text);
819
- this.inputContexts.push(context4 ?? {});
822
+ this.inputContexts.push(context5 ?? {});
820
823
  this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
821
824
  this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
822
825
  }
@@ -830,9 +833,9 @@ var Session = class {
830
833
  * @param text - Text to append (null becomes a null/"hide marker")
831
834
  * @param context - Optional per-turn context bag to attach to this turn
832
835
  */
833
- setOutput(text, context4) {
836
+ setOutput(text, context5) {
834
837
  this.outputs.push(text);
835
- this.outputContexts.push(context4 ?? {});
838
+ this.outputContexts.push(context5 ?? {});
836
839
  this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
837
840
  this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
838
841
  }
@@ -2361,7 +2364,142 @@ function getSpanProcessor() {
2361
2364
  return TracingModule.getInstance().getSpanProcessor();
2362
2365
  }
2363
2366
 
2367
+ // src/internal/trace/agent.ts
2368
+ import { randomUUID } from "crypto";
2369
+ import { context as context4, propagation } from "@opentelemetry/api";
2370
+ function newInstanceId() {
2371
+ return randomUUID().replaceAll("-", "").slice(0, 8);
2372
+ }
2373
+ function activeProperties() {
2374
+ return context4.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
2375
+ }
2376
+ function encodeToken(agent) {
2377
+ const payload = {
2378
+ id: agent.id,
2379
+ parentId: agent.parentId,
2380
+ name: agent.name,
2381
+ traceparent: agent.traceparent,
2382
+ sessionId: agent.sessionId
2383
+ };
2384
+ return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
2385
+ }
2386
+ function currentTraceparent() {
2387
+ const carrier = {};
2388
+ try {
2389
+ propagation.inject(context4.active(), carrier);
2390
+ } catch {
2391
+ }
2392
+ return carrier["traceparent"] ?? "";
2393
+ }
2394
+ function agentHandle(id, parentId, name) {
2395
+ const opened = {
2396
+ id,
2397
+ parentId,
2398
+ name,
2399
+ traceparent: currentTraceparent(),
2400
+ sessionId: activeProperties()[SESSION_ID] ?? ""
2401
+ };
2402
+ return {
2403
+ ...opened,
2404
+ get token() {
2405
+ return encodeToken(opened);
2406
+ }
2407
+ };
2408
+ }
2409
+ function decodeToken(token) {
2410
+ try {
2411
+ const payload = JSON.parse(Buffer.from(token, "base64url").toString("utf8"));
2412
+ return payload.id ? payload : void 0;
2413
+ } catch {
2414
+ return void 0;
2415
+ }
2416
+ }
2417
+ function unreadableAgent(agent) {
2418
+ return {
2419
+ id: "",
2420
+ parentId: "",
2421
+ name: "",
2422
+ traceparent: "",
2423
+ sessionId: "",
2424
+ token: typeof agent === "string" ? "" : agent.token ?? ""
2425
+ };
2426
+ }
2427
+ function resolveAgent(agent) {
2428
+ const options = typeof agent === "string" ? { name: agent } : agent;
2429
+ let id;
2430
+ let parentId;
2431
+ let name;
2432
+ let sessionId = "";
2433
+ let parentContext = context4.active();
2434
+ if (options.token === void 0) {
2435
+ id = options.id || newInstanceId();
2436
+ parentId = options.parentId || activeProperties()[AGENT_ID] || "";
2437
+ name = options.name ?? "";
2438
+ } else {
2439
+ const decoded = decodeToken(options.token);
2440
+ if (!decoded) {
2441
+ logger.warn("Brizz: ignoring an unreadable agent token");
2442
+ return void 0;
2443
+ }
2444
+ id = decoded.id;
2445
+ parentId = decoded.parentId;
2446
+ name = decoded.name;
2447
+ sessionId = decoded.sessionId;
2448
+ if (decoded.traceparent) {
2449
+ try {
2450
+ parentContext = propagation.extract(parentContext, { traceparent: decoded.traceparent });
2451
+ } catch {
2452
+ }
2453
+ }
2454
+ }
2455
+ const properties = { [AGENT_ID]: id, [AGENT_NAME]: name };
2456
+ if (parentId) {
2457
+ properties[AGENT_PARENT_ID] = parentId;
2458
+ }
2459
+ if (sessionId) {
2460
+ properties[SESSION_ID] = sessionId;
2461
+ }
2462
+ return { id, parentId, name, properties, parentContext };
2463
+ }
2464
+ function startAgent(agent, callback) {
2465
+ const resolved = resolveAgent(agent);
2466
+ if (!resolved) {
2467
+ return callback(unreadableAgent(agent));
2468
+ }
2469
+ const { id, parentId, name, properties, parentContext } = resolved;
2470
+ return context4.with(
2471
+ parentContext,
2472
+ () => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
2473
+ );
2474
+ }
2475
+ function withAgent(agent, fn, thisArg) {
2476
+ return function wrapped(...args) {
2477
+ return startAgent(
2478
+ agent,
2479
+ () => fn.apply(thisArg !== void 0 ? thisArg : this, args)
2480
+ );
2481
+ };
2482
+ }
2483
+ function setAgent(agent) {
2484
+ const resolved = resolveAgent(agent);
2485
+ if (!resolved) {
2486
+ return unreadableAgent(agent);
2487
+ }
2488
+ const { id, parentId, name, properties, parentContext } = resolved;
2489
+ setCurrentSpanCustomProperties(properties);
2490
+ propagatePropertiesImperatively(properties, parentContext);
2491
+ return agentHandle(id, parentId, name);
2492
+ }
2493
+
2364
2494
  // src/internal/sdk.ts
2495
+ function resolveMcpSessionTracking(configured) {
2496
+ const fromEnv = process.env["BRIZZ_MCP_SESSION_TRACKING"];
2497
+ if (fromEnv === void 0) {
2498
+ return configured;
2499
+ }
2500
+ const enabled = fromEnv === "true";
2501
+ return typeof configured === "object" ? { ...configured, enabled } : enabled;
2502
+ }
2365
2503
  var _Brizz = class __Brizz {
2366
2504
  static instance = null;
2367
2505
  static getInstance() {
@@ -2382,6 +2520,7 @@ var _Brizz = class __Brizz {
2382
2520
  */
2383
2521
  setupInstrumentation(options) {
2384
2522
  const registry = InstrumentationRegistry.getInstance();
2523
+ configure(resolveMcpSessionTracking(options.mcpSessionTracking));
2385
2524
  if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
2386
2525
  registry.setManualModules(options.instrumentModules);
2387
2526
  }
@@ -2603,6 +2742,7 @@ export {
2603
2742
  maskValue,
2604
2743
  recordFeedback,
2605
2744
  recordMetric,
2745
+ setAgent,
2606
2746
  setCurrentSpanCustomProperties,
2607
2747
  setLogLevel,
2608
2748
  setMessageId,
@@ -2610,8 +2750,10 @@ export {
2610
2750
  setServiceName,
2611
2751
  setSessionId,
2612
2752
  setUser,
2753
+ startAgent,
2613
2754
  startSession,
2614
2755
  startSessionTitle,
2756
+ withAgent,
2615
2757
  withMessageId,
2616
2758
  withMute,
2617
2759
  withOrganization,
@@ -2,8 +2,8 @@ import {
2
2
  InterruptPropagator,
3
3
  _resetInterruptState,
4
4
  createInterruptIntegration
5
- } from "./chunk-7FQQHF5U.js";
6
- import "./chunk-Y7NMZAQT.js";
5
+ } from "./chunk-APOYOP7D.js";
6
+ import "./chunk-AOT5NJDV.js";
7
7
  import "./chunk-3RG5ZIWI.js";
8
8
  export {
9
9
  InterruptPropagator,
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunk3IGBYXLRcjs = require('./chunk-3IGBYXLR.cjs');
6
+ require('./chunk-5WBPX342.cjs');
7
+ require('./chunk-OBGZSXTJ.cjs');
8
+
9
+
10
+
11
+
12
+ exports.InterruptPropagator = _chunk3IGBYXLRcjs.InterruptPropagator; exports._resetInterruptState = _chunk3IGBYXLRcjs._resetInterruptState; exports.createInterruptIntegration = _chunk3IGBYXLRcjs.createInterruptIntegration;
@@ -1,14 +1,18 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkK3NPYISBcjs = require('./chunk-K3NPYISB.cjs');
4
3
 
5
4
 
6
- var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
7
5
 
8
6
 
9
7
 
10
8
 
11
- var _chunkFORVS4QWcjs = require('./chunk-FORVS4QW.cjs');
9
+
10
+
11
+ var _chunkA3HH5OULcjs = require('./chunk-A3HH5OUL.cjs');
12
+
13
+
14
+ var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
15
+ require('./chunk-5WBPX342.cjs');
12
16
  require('./chunk-OBGZSXTJ.cjs');
13
17
 
14
18
  // src/internal/instrumentation/mcp/instrumentation.ts
@@ -130,88 +134,24 @@ function extractTools(result) {
130
134
  );
131
135
  }
132
136
 
133
- // src/internal/instrumentation/mcp/session.ts
134
-
135
- var FALLBACK_SESSION_ID = /* @__PURE__ */ Symbol("brizz.mcp.fallback-session-id");
136
- var FALLBACK_SESSION_ID_BYTES = 16;
137
- function generateSessionId() {
138
- let id = "";
139
- for (let i = 0; i < FALLBACK_SESSION_ID_BYTES; i++) {
140
- id += Math.floor(Math.random() * 256).toString(16).padStart(2, "0");
141
- }
142
- return id;
143
- }
144
- function isSessionCarrier(value) {
145
- return typeof value === "object" && value !== null;
146
- }
147
- function resolveTransportSessionId(protocol) {
148
- if (!isSessionCarrier(protocol)) {
149
- return void 0;
150
- }
151
- return _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access', _ => _._transport, 'optionalAccess', _2 => _2.sessionId])));
152
- }
153
- function resolveSessionId(protocol, baseContext) {
154
- if (!isSessionCarrier(protocol)) {
155
- return void 0;
156
- }
157
- const fromTransport = resolveTransportSessionId(protocol);
158
- if (fromTransport) {
159
- return fromTransport;
160
- }
161
- try {
162
- const bound = baseContext.getValue(_chunkFORVS4QWcjs.PROPERTIES_CONTEXT_KEY);
163
- if (_optionalChain([bound, 'optionalAccess', _3 => _3[_chunkFORVS4QWcjs.SESSION_ID]])) {
164
- return void 0;
165
- }
166
- } catch (e2) {
167
- }
168
- protocol[FALLBACK_SESSION_ID] ??= generateSessionId();
169
- return protocol[FALLBACK_SESSION_ID];
170
- }
171
- function stampAndPropagateSession(span, sessionId, baseContext = _api.context.active()) {
172
- if (!sessionId) {
173
- return { context: baseContext, sessionId: null };
174
- }
175
- if (span.isRecording()) {
176
- try {
177
- span.setAttribute(`${_chunkFORVS4QWcjs.BRIZZ}.${_chunkFORVS4QWcjs.SESSION_ID}`, sessionId);
178
- } catch (error) {
179
- _chunkWC573FCIcjs.logger.warn(
180
- `Brizz MCP: failed to stamp session id on span: ${String(error)}`
181
- );
182
- }
183
- }
184
- try {
185
- const prev = baseContext.getValue(_chunkFORVS4QWcjs.PROPERTIES_CONTEXT_KEY);
186
- const merged = prev ? { ...prev, [_chunkFORVS4QWcjs.SESSION_ID]: sessionId } : { [_chunkFORVS4QWcjs.SESSION_ID]: sessionId };
187
- return {
188
- context: baseContext.setValue(_chunkFORVS4QWcjs.PROPERTIES_CONTEXT_KEY, merged),
189
- sessionId
190
- };
191
- } catch (error) {
192
- _chunkWC573FCIcjs.logger.warn(`Brizz MCP: failed to attach session context: ${String(error)}`);
193
- return { context: baseContext, sessionId };
194
- }
195
- }
196
-
197
137
  // src/internal/instrumentation/mcp/patches/attributes.ts
198
138
 
199
139
  function deriveSpanName(method, params) {
200
140
  try {
201
141
  if (method === METHOD_TOOLS_CALL) {
202
- const name = typeof _optionalChain([params, 'optionalAccess', _4 => _4["name"]]) === "string" ? params["name"] : "";
142
+ const name = typeof _optionalChain([params, 'optionalAccess', _ => _["name"]]) === "string" ? params["name"] : "";
203
143
  return name ? `${SPAN_NAME_TOOLS_CALL} ${name}` : SPAN_NAME_TOOLS_CALL;
204
144
  }
205
145
  if (method === METHOD_RESOURCES_READ) {
206
- const uri = typeof _optionalChain([params, 'optionalAccess', _5 => _5["uri"]]) === "string" ? params["uri"] : "";
146
+ const uri = typeof _optionalChain([params, 'optionalAccess', _2 => _2["uri"]]) === "string" ? params["uri"] : "";
207
147
  return uri ? `${METHOD_RESOURCES_READ} ${uri}` : METHOD_RESOURCES_READ;
208
148
  }
209
149
  if (method === METHOD_PROMPTS_GET) {
210
- const name = typeof _optionalChain([params, 'optionalAccess', _6 => _6["name"]]) === "string" ? params["name"] : "";
150
+ const name = typeof _optionalChain([params, 'optionalAccess', _3 => _3["name"]]) === "string" ? params["name"] : "";
211
151
  return name ? `${METHOD_PROMPTS_GET} ${name}` : METHOD_PROMPTS_GET;
212
152
  }
213
153
  return method;
214
- } catch (e3) {
154
+ } catch (e2) {
215
155
  return method || "mcp";
216
156
  }
217
157
  }
@@ -240,12 +180,12 @@ function applyServerRequestAttributes(span, request, protocol) {
240
180
  applyBaseAttributes(span, request);
241
181
  applyMethodSpecificRequestAttributes(span, request);
242
182
  if (request.method === METHOD_TOOLS_CALL) {
243
- const args = _optionalChain([request, 'access', _7 => _7.params, 'optionalAccess', _8 => _8["arguments"]]);
183
+ const args = _optionalChain([request, 'access', _4 => _4.params, 'optionalAccess', _5 => _5["arguments"]]);
244
184
  if (args !== void 0) {
245
185
  span.setAttribute(MCP_TOOL_ARGUMENTS, serializeForAttribute(args));
246
186
  }
247
187
  }
248
- const sessionId = _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access', _9 => _9._transport, 'optionalAccess', _10 => _10.sessionId])));
188
+ const sessionId = _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access', _6 => _6._transport, 'optionalAccess', _7 => _7.sessionId])));
249
189
  if (sessionId) {
250
190
  span.setAttribute(MCP_SESSION_ID, sessionId);
251
191
  }
@@ -293,7 +233,7 @@ function applyResultAttributes(span, method, result) {
293
233
  return;
294
234
  }
295
235
  const obj = result && typeof result === "object" ? result : null;
296
- const content = _nullishCoalesce(_optionalChain([obj, 'optionalAccess', _11 => _11["content"]]), () => ( result));
236
+ const content = _nullishCoalesce(_optionalChain([obj, 'optionalAccess', _8 => _8["content"]]), () => ( result));
297
237
  span.setAttribute(MCP_TOOL_RESULT, serializeForAttribute(content));
298
238
  if (obj && obj["isError"] === true) {
299
239
  span.setAttribute(ERROR_TYPE, ERROR_TYPE_TOOL);
@@ -303,24 +243,24 @@ function applyResultAttributes(span, method, result) {
303
243
  }
304
244
  function applyErrorAttributes(span, err) {
305
245
  const error = err;
306
- const code = _optionalChain([error, 'optionalAccess', _12 => _12.code]);
246
+ const code = _optionalChain([error, 'optionalAccess', _9 => _9.code]);
307
247
  if (typeof code === "number") {
308
248
  span.setAttribute(RPC_RESPONSE_STATUS_CODE, code);
309
249
  span.setAttribute(ERROR_TYPE, String(code));
310
- } else if (_optionalChain([error, 'optionalAccess', _13 => _13.name]) === "AbortError") {
250
+ } else if (_optionalChain([error, 'optionalAccess', _10 => _10.name]) === "AbortError") {
311
251
  span.setAttribute(ERROR_TYPE, "cancelled");
312
- } else if (_optionalChain([error, 'optionalAccess', _14 => _14.name]) === "TimeoutError") {
252
+ } else if (_optionalChain([error, 'optionalAccess', _11 => _11.name]) === "TimeoutError") {
313
253
  span.setAttribute(ERROR_TYPE, "timeout");
314
254
  } else {
315
- span.setAttribute(ERROR_TYPE, _optionalChain([error, 'optionalAccess', _15 => _15.constructor, 'optionalAccess', _16 => _16.name]) || _optionalChain([error, 'optionalAccess', _17 => _17.name]) || "Error");
255
+ span.setAttribute(ERROR_TYPE, _optionalChain([error, 'optionalAccess', _12 => _12.constructor, 'optionalAccess', _13 => _13.name]) || _optionalChain([error, 'optionalAccess', _14 => _14.name]) || "Error");
316
256
  }
317
257
  try {
318
258
  span.recordException(error);
319
- } catch (e4) {
259
+ } catch (e3) {
320
260
  }
321
261
  span.setStatus({
322
262
  code: _api.SpanStatusCode.ERROR,
323
- message: typeof _optionalChain([error, 'optionalAccess', _18 => _18.message]) === "string" ? error.message : void 0
263
+ message: typeof _optionalChain([error, 'optionalAccess', _15 => _15.message]) === "string" ? error.message : void 0
324
264
  });
325
265
  }
326
266
  function serializeForAttribute(value) {
@@ -339,7 +279,7 @@ function rawSerialize(value) {
339
279
  }
340
280
  try {
341
281
  return JSON.stringify(value);
342
- } catch (e5) {
282
+ } catch (e4) {
343
283
  try {
344
284
  if (value === null || value === void 0) {
345
285
  return "";
@@ -349,7 +289,7 @@ function rawSerialize(value) {
349
289
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
350
290
  String(value)
351
291
  ) : tag;
352
- } catch (e6) {
292
+ } catch (e5) {
353
293
  return "";
354
294
  }
355
295
  }
@@ -447,11 +387,15 @@ function wrapOnRequest(original, tracer) {
447
387
  return original.apply(this, args);
448
388
  }
449
389
  const method = request.method;
390
+ if (method === METHOD_TOOLS_CALL && _chunkA3HH5OULcjs.isSessionToolCall.call(void 0, request)) {
391
+ return answerSessionToolCall(this, request, tracer, args, original);
392
+ }
450
393
  const handler = _nullishCoalesce(handlers.get(method), () => ( this.fallbackRequestHandler));
451
394
  if (!handler) {
452
395
  return original.apply(this, args);
453
396
  }
454
- const started = safeStartServerSpan(tracer, request, this);
397
+ const tracking = _chunkA3HH5OULcjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkA3HH5OULcjs.popTrackingArguments.call(void 0, request) : {};
398
+ const started = safeStartServerSpan(tracer, request, this, tracking);
455
399
  if (!started) {
456
400
  return original.apply(this, args);
457
401
  }
@@ -459,10 +403,21 @@ function wrapOnRequest(original, tracer) {
459
403
  const hooks = {};
460
404
  if (method === METHOD_TOOLS_LIST) {
461
405
  hooks.onResult = (result) => {
406
+ let advertised = result;
407
+ if (_chunkA3HH5OULcjs.isEnabled.call(void 0, )) {
408
+ try {
409
+ advertised = _chunkA3HH5OULcjs.patchListToolsResult.call(void 0, result);
410
+ } catch (error) {
411
+ _chunkWC573FCIcjs.logger.warn(
412
+ `Brizz MCP: failed to patch tools/list schemas: ${String(error)}`
413
+ );
414
+ advertised = result;
415
+ }
416
+ }
462
417
  try {
463
418
  emitSchemaSpansFromListResponse(
464
- result,
465
- resolveTransportSessionId(this),
419
+ advertised,
420
+ _chunkA3HH5OULcjs.resolveTransportSessionId.call(void 0, this),
466
421
  tracer
467
422
  );
468
423
  } catch (error) {
@@ -470,11 +425,12 @@ function wrapOnRequest(original, tracer) {
470
425
  `Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
471
426
  );
472
427
  }
428
+ return advertised;
473
429
  };
474
430
  }
475
431
  if (method !== METHOD_TOOLS_CALL) {
476
432
  hooks.onError = () => {
477
- stampAndPropagateSession(span, resolveSessionId(this, spanCtx), spanCtx);
433
+ _chunkA3HH5OULcjs.stampAndPropagateSession.call(void 0, span, _chunkA3HH5OULcjs.resolveSessionId.call(void 0, this, spanCtx), spanCtx);
478
434
  };
479
435
  }
480
436
  const wrappedHandler = (req, extra) => _api.context.with(
@@ -503,32 +459,56 @@ function wrapOnRequest(original, tracer) {
503
459
  }
504
460
  };
505
461
  }
462
+ function answerSessionToolCall(protocol, request, tracer, args, original) {
463
+ const handlers = protocol._requestHandlers;
464
+ if (!handlers) {
465
+ return original.apply(protocol, args);
466
+ }
467
+ const { id, result } = _chunkA3HH5OULcjs.sessionToolResult.call(void 0, );
468
+ const started = safeStartServerSpan(tracer, request, protocol, { sessionId: id });
469
+ const handler = () => started ? _api.context.with(started.spanCtx, () => result) : result;
470
+ const hadEntry = handlers.has(METHOD_TOOLS_CALL);
471
+ const prev = handlers.get(METHOD_TOOLS_CALL);
472
+ handlers.set(
473
+ METHOD_TOOLS_CALL,
474
+ (req, extra) => started ? executeHandler(started.span, METHOD_TOOLS_CALL, handler, req, extra) : handler(req, extra)
475
+ );
476
+ try {
477
+ return original.apply(protocol, args);
478
+ } finally {
479
+ if (hadEntry) {
480
+ handlers.set(METHOD_TOOLS_CALL, prev);
481
+ } else {
482
+ handlers.delete(METHOD_TOOLS_CALL);
483
+ }
484
+ }
485
+ }
506
486
  function executeAroundSpan(span, method, run, hooks) {
507
487
  let result;
508
488
  try {
509
489
  result = run();
510
490
  } catch (error) {
511
491
  safeApplyErrorAttributes(span, error);
512
- _optionalChain([hooks, 'optionalAccess', _19 => _19.onError, 'optionalCall', _20 => _20()]);
492
+ _optionalChain([hooks, 'optionalAccess', _16 => _16.onError, 'optionalCall', _17 => _17()]);
513
493
  safeEnd(span);
514
494
  throw error;
515
495
  }
516
496
  if (!isThenable(result)) {
517
497
  safeApplyResultAttributes(span, method, result);
518
- _optionalChain([hooks, 'optionalAccess', _21 => _21.onResult, 'optionalCall', _22 => _22(result)]);
498
+ const replaced = applyResultHook(hooks, result);
519
499
  safeEnd(span);
520
- return result;
500
+ return replaced;
521
501
  }
522
502
  return result.then(
523
503
  (value) => {
524
504
  safeApplyResultAttributes(span, method, value);
525
- _optionalChain([hooks, 'optionalAccess', _23 => _23.onResult, 'optionalCall', _24 => _24(value)]);
505
+ const replaced = applyResultHook(hooks, value);
526
506
  safeEnd(span);
527
- return value;
507
+ return replaced;
528
508
  },
529
509
  (error) => {
530
510
  safeApplyErrorAttributes(span, error);
531
- _optionalChain([hooks, 'optionalAccess', _25 => _25.onError, 'optionalCall', _26 => _26()]);
511
+ _optionalChain([hooks, 'optionalAccess', _18 => _18.onError, 'optionalCall', _19 => _19()]);
532
512
  safeEnd(span);
533
513
  throw error;
534
514
  }
@@ -537,6 +517,18 @@ function executeAroundSpan(span, method, run, hooks) {
537
517
  function executeHandler(span, method, handler, req, extra, hooks) {
538
518
  return executeAroundSpan(span, method, () => handler(req, extra), hooks);
539
519
  }
520
+ function applyResultHook(hooks, value) {
521
+ if (!_optionalChain([hooks, 'optionalAccess', _20 => _20.onResult])) {
522
+ return value;
523
+ }
524
+ try {
525
+ const replaced = hooks.onResult(value);
526
+ return replaced === void 0 ? value : replaced;
527
+ } catch (error) {
528
+ _chunkWC573FCIcjs.logger.debug(`Brizz MCP: result hook failed: ${String(error)}`);
529
+ return value;
530
+ }
531
+ }
540
532
  function safeStartClientSpan(tracer, request, protocol) {
541
533
  try {
542
534
  const spanName = deriveSpanName(request.method, request.params);
@@ -544,7 +536,7 @@ function safeStartClientSpan(tracer, request, protocol) {
544
536
  applyClientRequestAttributes(
545
537
  span,
546
538
  request,
547
- _optionalChain([protocol, 'access', _27 => _27._transport, 'optionalAccess', _28 => _28.constructor, 'optionalAccess', _29 => _29.name])
539
+ _optionalChain([protocol, 'access', _21 => _21._transport, 'optionalAccess', _22 => _22.constructor, 'optionalAccess', _23 => _23.name])
548
540
  );
549
541
  return span;
550
542
  } catch (error) {
@@ -552,7 +544,7 @@ function safeStartClientSpan(tracer, request, protocol) {
552
544
  return null;
553
545
  }
554
546
  }
555
- function safeStartServerSpan(tracer, request, protocol) {
547
+ function safeStartServerSpan(tracer, request, protocol, tracking = {}) {
556
548
  try {
557
549
  const parentCtx = extractParentContext(request);
558
550
  const spanName = deriveSpanName(request.method, request.params);
@@ -562,8 +554,13 @@ function safeStartServerSpan(tracer, request, protocol) {
562
554
  parentCtx
563
555
  );
564
556
  applyServerRequestAttributes(span, request, protocol);
565
- const resolved = request.method === METHOD_TOOLS_CALL ? resolveSessionId(protocol, parentCtx) : void 0;
566
- const { context: sessCtx } = stampAndPropagateSession(span, resolved, parentCtx);
557
+ const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkA3HH5OULcjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
558
+ const { context: sessCtx } = _chunkA3HH5OULcjs.stampAndPropagateSession.call(void 0,
559
+ span,
560
+ resolved,
561
+ parentCtx,
562
+ tracking.intent
563
+ );
567
564
  return { span, spanCtx: _api.trace.setSpan(sessCtx, span) };
568
565
  } catch (error) {
569
566
  _chunkWC573FCIcjs.logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
@@ -572,7 +569,7 @@ function safeStartServerSpan(tracer, request, protocol) {
572
569
  }
573
570
  function extractParentContext(request) {
574
571
  try {
575
- const meta = _optionalChain([request, 'access', _30 => _30.params, 'optionalAccess', _31 => _31._meta]);
572
+ const meta = _optionalChain([request, 'access', _24 => _24.params, 'optionalAccess', _25 => _25._meta]);
576
573
  if (meta && typeof meta === "object") {
577
574
  return _api.propagation.extract(_api.context.active(), meta);
578
575
  }
@@ -614,7 +611,7 @@ function safeEnd(span) {
614
611
 
615
612
  // src/internal/instrumentation/mcp/version.ts
616
613
  var INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
617
- var INSTRUMENTATION_VERSION = _chunkK3NPYISBcjs.getSDKVersion.call(void 0, );
614
+ var INSTRUMENTATION_VERSION = _chunkA3HH5OULcjs.getSDKVersion.call(void 0, );
618
615
 
619
616
  // src/internal/instrumentation/mcp/instrumentation.ts
620
617
  var PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
@@ -632,7 +629,7 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
632
629
  */
633
630
 
634
631
  constructor(_config) {
635
- super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess', _32 => _32.instrumentationConfig]) });
632
+ super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess', _26 => _26.instrumentationConfig]) });
636
633
  this.brizzTracer = _api.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
637
634
  }
638
635
  /**
@@ -642,7 +639,7 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
642
639
  * calls `patchProtocolPrototype`.
643
640
  */
644
641
  patchProtocolModule(module) {
645
- const proto = _optionalChain([module, 'optionalAccess', _33 => _33.Protocol, 'optionalAccess', _34 => _34.prototype]);
642
+ const proto = _optionalChain([module, 'optionalAccess', _27 => _27.Protocol, 'optionalAccess', _28 => _28.prototype]);
646
643
  if (!proto) {
647
644
  _chunkWC573FCIcjs.logger.debug(
648
645
  "Brizz MCP: module does not expose Protocol.prototype \u2014 skipping protocol patches"