@brizz/sdk 0.1.42 → 0.1.43
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/chunk-5SWAZUC5.js +240 -0
- package/dist/chunk-WTQTF57J.cjs +240 -0
- package/dist/index.cjs +16 -6
- package/dist/index.js +13 -3
- package/dist/{mcp-5BFXKN63.js → mcp-6R6KZ5U3.js} +83 -86
- package/dist/{mcp-GVGTOWHP.cjs → mcp-UJD6KF7G.cjs} +97 -100
- package/dist/types/cjs/internal/instrumentation/mcp/client-session.d.ts +24 -0
- package/dist/types/cjs/internal/instrumentation/mcp/session.d.ts +3 -1
- package/dist/types/cjs/internal/sdk.d.ts +2 -0
- package/dist/types/esm/internal/instrumentation/mcp/client-session.d.ts +24 -0
- package/dist/types/esm/internal/instrumentation/mcp/session.d.ts +3 -1
- package/dist/types/esm/internal/sdk.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunk-K3NPYISB.cjs +0 -8
- package/dist/chunk-KVOGOKOB.js +0 -8
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getSDKVersion
|
|
3
|
-
|
|
2
|
+
getSDKVersion,
|
|
3
|
+
isEnabled,
|
|
4
|
+
isSessionToolCall,
|
|
5
|
+
patchListToolsResult,
|
|
6
|
+
popTrackingArguments,
|
|
7
|
+
resolveSessionId,
|
|
8
|
+
resolveTransportSessionId,
|
|
9
|
+
sessionToolResult,
|
|
10
|
+
stampAndPropagateSession
|
|
11
|
+
} from "./chunk-5SWAZUC5.js";
|
|
4
12
|
import {
|
|
5
13
|
logger
|
|
6
14
|
} from "./chunk-Y4HNUX3Q.js";
|
|
7
|
-
import
|
|
8
|
-
BRIZZ,
|
|
9
|
-
PROPERTIES_CONTEXT_KEY,
|
|
10
|
-
SESSION_ID
|
|
11
|
-
} from "./chunk-Y7NMZAQT.js";
|
|
15
|
+
import "./chunk-Y7NMZAQT.js";
|
|
12
16
|
import "./chunk-3RG5ZIWI.js";
|
|
13
17
|
|
|
14
18
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
@@ -17,7 +21,7 @@ import { trace as trace2 } from "@opentelemetry/api";
|
|
|
17
21
|
import { InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
|
|
18
22
|
|
|
19
23
|
// src/internal/instrumentation/mcp/patches/protocol.ts
|
|
20
|
-
import { context
|
|
24
|
+
import { context, propagation, SpanKind as SpanKind2, trace } from "@opentelemetry/api";
|
|
21
25
|
|
|
22
26
|
// src/internal/instrumentation/mcp/schemas.ts
|
|
23
27
|
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
@@ -130,70 +134,6 @@ function extractTools(result) {
|
|
|
130
134
|
);
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
// src/internal/instrumentation/mcp/session.ts
|
|
134
|
-
import { context } from "@opentelemetry/api";
|
|
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 protocol.sessionId ?? protocol._transport?.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(PROPERTIES_CONTEXT_KEY);
|
|
163
|
-
if (bound?.[SESSION_ID]) {
|
|
164
|
-
return void 0;
|
|
165
|
-
}
|
|
166
|
-
} catch {
|
|
167
|
-
}
|
|
168
|
-
protocol[FALLBACK_SESSION_ID] ??= generateSessionId();
|
|
169
|
-
return protocol[FALLBACK_SESSION_ID];
|
|
170
|
-
}
|
|
171
|
-
function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
|
|
172
|
-
if (!sessionId) {
|
|
173
|
-
return { context: baseContext, sessionId: null };
|
|
174
|
-
}
|
|
175
|
-
if (span.isRecording()) {
|
|
176
|
-
try {
|
|
177
|
-
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
logger.warn(
|
|
180
|
-
`Brizz MCP: failed to stamp session id on span: ${String(error)}`
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const prev = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
|
|
186
|
-
const merged = prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId };
|
|
187
|
-
return {
|
|
188
|
-
context: baseContext.setValue(PROPERTIES_CONTEXT_KEY, merged),
|
|
189
|
-
sessionId
|
|
190
|
-
};
|
|
191
|
-
} catch (error) {
|
|
192
|
-
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
|
import { SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
199
139
|
function deriveSpanName(method, params) {
|
|
@@ -431,8 +371,8 @@ function wrapRequest(original, tracer) {
|
|
|
431
371
|
return original.apply(this, args);
|
|
432
372
|
}
|
|
433
373
|
return executeAroundSpan(span, request.method, () => {
|
|
434
|
-
const ctx = trace.setSpan(
|
|
435
|
-
return
|
|
374
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
375
|
+
return context.with(ctx, () => original.apply(this, args));
|
|
436
376
|
});
|
|
437
377
|
};
|
|
438
378
|
}
|
|
@@ -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 && isSessionToolCall(request)) {
|
|
391
|
+
return answerSessionToolCall(this, request, tracer, args, original);
|
|
392
|
+
}
|
|
450
393
|
const handler = handlers.get(method) ?? this.fallbackRequestHandler;
|
|
451
394
|
if (!handler) {
|
|
452
395
|
return original.apply(this, args);
|
|
453
396
|
}
|
|
454
|
-
const
|
|
397
|
+
const tracking = isEnabled() && method === METHOD_TOOLS_CALL ? popTrackingArguments(request) : {};
|
|
398
|
+
const started = safeStartServerSpan(tracer, request, this, tracking);
|
|
455
399
|
if (!started) {
|
|
456
400
|
return original.apply(this, args);
|
|
457
401
|
}
|
|
@@ -459,9 +403,20 @@ 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 (isEnabled()) {
|
|
408
|
+
try {
|
|
409
|
+
advertised = patchListToolsResult(result);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
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
|
-
|
|
419
|
+
advertised,
|
|
465
420
|
resolveTransportSessionId(this),
|
|
466
421
|
tracer
|
|
467
422
|
);
|
|
@@ -470,6 +425,7 @@ 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) {
|
|
@@ -477,7 +433,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
477
433
|
stampAndPropagateSession(span, resolveSessionId(this, spanCtx), spanCtx);
|
|
478
434
|
};
|
|
479
435
|
}
|
|
480
|
-
const wrappedHandler = (req, extra) =>
|
|
436
|
+
const wrappedHandler = (req, extra) => context.with(
|
|
481
437
|
spanCtx,
|
|
482
438
|
() => executeHandler(span, method, handler, req, extra, hooks)
|
|
483
439
|
);
|
|
@@ -503,6 +459,30 @@ 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 } = sessionToolResult();
|
|
468
|
+
const started = safeStartServerSpan(tracer, request, protocol, { sessionId: id });
|
|
469
|
+
const handler = () => started ? 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 {
|
|
@@ -515,16 +495,16 @@ function executeAroundSpan(span, method, run, hooks) {
|
|
|
515
495
|
}
|
|
516
496
|
if (!isThenable(result)) {
|
|
517
497
|
safeApplyResultAttributes(span, method, result);
|
|
518
|
-
hooks
|
|
498
|
+
const replaced = applyResultHook(hooks, result);
|
|
519
499
|
safeEnd(span);
|
|
520
|
-
return
|
|
500
|
+
return replaced;
|
|
521
501
|
}
|
|
522
502
|
return result.then(
|
|
523
503
|
(value) => {
|
|
524
504
|
safeApplyResultAttributes(span, method, value);
|
|
525
|
-
hooks
|
|
505
|
+
const replaced = applyResultHook(hooks, value);
|
|
526
506
|
safeEnd(span);
|
|
527
|
-
return
|
|
507
|
+
return replaced;
|
|
528
508
|
},
|
|
529
509
|
(error) => {
|
|
530
510
|
safeApplyErrorAttributes(span, error);
|
|
@@ -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 (!hooks?.onResult) {
|
|
522
|
+
return value;
|
|
523
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
const replaced = hooks.onResult(value);
|
|
526
|
+
return replaced === void 0 ? value : replaced;
|
|
527
|
+
} catch (error) {
|
|
528
|
+
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);
|
|
@@ -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(
|
|
557
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? tracking.sessionId ?? resolveSessionId(protocol, parentCtx) : void 0;
|
|
558
|
+
const { context: sessCtx } = stampAndPropagateSession(
|
|
559
|
+
span,
|
|
560
|
+
resolved,
|
|
561
|
+
parentCtx,
|
|
562
|
+
tracking.intent
|
|
563
|
+
);
|
|
567
564
|
return { span, spanCtx: trace.setSpan(sessCtx, span) };
|
|
568
565
|
} catch (error) {
|
|
569
566
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
@@ -574,14 +571,14 @@ function extractParentContext(request) {
|
|
|
574
571
|
try {
|
|
575
572
|
const meta = request.params?._meta;
|
|
576
573
|
if (meta && typeof meta === "object") {
|
|
577
|
-
return propagation.extract(
|
|
574
|
+
return propagation.extract(context.active(), meta);
|
|
578
575
|
}
|
|
579
576
|
} catch (error) {
|
|
580
577
|
logger.debug(
|
|
581
578
|
`Brizz MCP: failed to extract parent context from _meta: ${String(error)}`
|
|
582
579
|
);
|
|
583
580
|
}
|
|
584
|
-
return
|
|
581
|
+
return context.active();
|
|
585
582
|
}
|
|
586
583
|
function isThenable(value) {
|
|
587
584
|
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
@@ -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
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkWTQTF57Jcjs = require('./chunk-WTQTF57J.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
|
|
15
|
+
require('./chunk-FORVS4QW.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',
|
|
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',
|
|
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',
|
|
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 (
|
|
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',
|
|
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',
|
|
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',
|
|
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',
|
|
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',
|
|
250
|
+
} else if (_optionalChain([error, 'optionalAccess', _10 => _10.name]) === "AbortError") {
|
|
311
251
|
span.setAttribute(ERROR_TYPE, "cancelled");
|
|
312
|
-
} else if (_optionalChain([error, 'optionalAccess',
|
|
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',
|
|
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 (
|
|
259
|
+
} catch (e3) {
|
|
320
260
|
}
|
|
321
261
|
span.setStatus({
|
|
322
262
|
code: _api.SpanStatusCode.ERROR,
|
|
323
|
-
message: typeof _optionalChain([error, 'optionalAccess',
|
|
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 (
|
|
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 (
|
|
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 && _chunkWTQTF57Jcjs.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
|
|
397
|
+
const tracking = _chunkWTQTF57Jcjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkWTQTF57Jcjs.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 (_chunkWTQTF57Jcjs.isEnabled.call(void 0, )) {
|
|
408
|
+
try {
|
|
409
|
+
advertised = _chunkWTQTF57Jcjs.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
|
-
|
|
465
|
-
resolveTransportSessionId(this),
|
|
419
|
+
advertised,
|
|
420
|
+
_chunkWTQTF57Jcjs.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
|
+
_chunkWTQTF57Jcjs.stampAndPropagateSession.call(void 0, span, _chunkWTQTF57Jcjs.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 } = _chunkWTQTF57Jcjs.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',
|
|
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
|
-
|
|
498
|
+
const replaced = applyResultHook(hooks, result);
|
|
519
499
|
safeEnd(span);
|
|
520
|
-
return
|
|
500
|
+
return replaced;
|
|
521
501
|
}
|
|
522
502
|
return result.then(
|
|
523
503
|
(value) => {
|
|
524
504
|
safeApplyResultAttributes(span, method, value);
|
|
525
|
-
|
|
505
|
+
const replaced = applyResultHook(hooks, value);
|
|
526
506
|
safeEnd(span);
|
|
527
|
-
return
|
|
507
|
+
return replaced;
|
|
528
508
|
},
|
|
529
509
|
(error) => {
|
|
530
510
|
safeApplyErrorAttributes(span, error);
|
|
531
|
-
_optionalChain([hooks, 'optionalAccess',
|
|
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',
|
|
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(
|
|
557
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkWTQTF57Jcjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
|
|
558
|
+
const { context: sessCtx } = _chunkWTQTF57Jcjs.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',
|
|
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 =
|
|
614
|
+
var INSTRUMENTATION_VERSION = _chunkWTQTF57Jcjs.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',
|
|
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',
|
|
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"
|