@modelcontextprotocol/server-customer-segmentation 1.3.1 → 1.4.0

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/index.js CHANGED
@@ -20839,7 +20839,7 @@ var require_utils2 = __commonJS((exports, module) => {
20839
20839
  var hexTable = function() {
20840
20840
  var array2 = [];
20841
20841
  for (var i = 0;i < 256; ++i) {
20842
- array2.push("%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase());
20842
+ array2[array2.length] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase();
20843
20843
  }
20844
20844
  return array2;
20845
20845
  }();
@@ -20851,7 +20851,7 @@ var require_utils2 = __commonJS((exports, module) => {
20851
20851
  var compacted = [];
20852
20852
  for (var j = 0;j < obj.length; ++j) {
20853
20853
  if (typeof obj[j] !== "undefined") {
20854
- compacted.push(obj[j]);
20854
+ compacted[compacted.length] = obj[j];
20855
20855
  }
20856
20856
  }
20857
20857
  item.obj[item.prop] = compacted;
@@ -20873,12 +20873,18 @@ var require_utils2 = __commonJS((exports, module) => {
20873
20873
  }
20874
20874
  if (typeof source !== "object" && typeof source !== "function") {
20875
20875
  if (isArray(target)) {
20876
- target.push(source);
20876
+ var nextIndex = target.length;
20877
+ if (options && typeof options.arrayLimit === "number" && nextIndex > options.arrayLimit) {
20878
+ return markOverflow(arrayToObject(target.concat(source), options), nextIndex);
20879
+ }
20880
+ target[nextIndex] = source;
20877
20881
  } else if (target && typeof target === "object") {
20878
20882
  if (isOverflow(target)) {
20879
20883
  var newIndex = getMaxIndex(target) + 1;
20880
20884
  target[newIndex] = source;
20881
20885
  setMaxIndex(target, newIndex);
20886
+ } else if (options && options.strictMerge) {
20887
+ return [target, source];
20882
20888
  } else if (options && (options.plainObjects || options.allowPrototypes) || !has.call(Object.prototype, source)) {
20883
20889
  target[source] = true;
20884
20890
  }
@@ -20897,7 +20903,11 @@ var require_utils2 = __commonJS((exports, module) => {
20897
20903
  }
20898
20904
  return markOverflow(result, getMaxIndex(source) + 1);
20899
20905
  }
20900
- return [target].concat(source);
20906
+ var combined = [target].concat(source);
20907
+ if (options && typeof options.arrayLimit === "number" && combined.length > options.arrayLimit) {
20908
+ return markOverflow(arrayToObject(combined, options), combined.length - 1);
20909
+ }
20910
+ return combined;
20901
20911
  }
20902
20912
  var mergeTarget = target;
20903
20913
  if (isArray(target) && !isArray(source)) {
@@ -20910,7 +20920,7 @@ var require_utils2 = __commonJS((exports, module) => {
20910
20920
  if (targetItem && typeof targetItem === "object" && item && typeof item === "object") {
20911
20921
  target[i] = merge3(targetItem, item, options);
20912
20922
  } else {
20913
- target.push(item);
20923
+ target[target.length] = item;
20914
20924
  }
20915
20925
  } else {
20916
20926
  target[i] = item;
@@ -20925,6 +20935,15 @@ var require_utils2 = __commonJS((exports, module) => {
20925
20935
  } else {
20926
20936
  acc[key] = value;
20927
20937
  }
20938
+ if (isOverflow(source) && !isOverflow(acc)) {
20939
+ markOverflow(acc, getMaxIndex(source));
20940
+ }
20941
+ if (isOverflow(acc)) {
20942
+ var keyNum = parseInt(key, 10);
20943
+ if (String(keyNum) === key && keyNum >= 0 && keyNum > getMaxIndex(acc)) {
20944
+ setMaxIndex(acc, keyNum);
20945
+ }
20946
+ }
20928
20947
  return acc;
20929
20948
  }, mergeTarget);
20930
20949
  };
@@ -21002,8 +21021,8 @@ var require_utils2 = __commonJS((exports, module) => {
21002
21021
  var key = keys[j];
21003
21022
  var val = obj[key];
21004
21023
  if (typeof val === "object" && val !== null && refs.indexOf(val) === -1) {
21005
- queue.push({ obj, prop: key });
21006
- refs.push(val);
21024
+ queue[queue.length] = { obj, prop: key };
21025
+ refs[refs.length] = val;
21007
21026
  }
21008
21027
  }
21009
21028
  }
@@ -21036,7 +21055,7 @@ var require_utils2 = __commonJS((exports, module) => {
21036
21055
  if (isArray(val)) {
21037
21056
  var mapped = [];
21038
21057
  for (var i = 0;i < val.length; i += 1) {
21039
- mapped.push(fn(val[i]));
21058
+ mapped[mapped.length] = fn(val[i]);
21040
21059
  }
21041
21060
  return mapped;
21042
21061
  }
@@ -21052,6 +21071,7 @@ var require_utils2 = __commonJS((exports, module) => {
21052
21071
  isBuffer,
21053
21072
  isOverflow,
21054
21073
  isRegExp,
21074
+ markOverflow,
21055
21075
  maybeMap,
21056
21076
  merge: merge2
21057
21077
  };
@@ -21323,6 +21343,7 @@ var require_parse = __commonJS((exports, module) => {
21323
21343
  parseArrays: true,
21324
21344
  plainObjects: false,
21325
21345
  strictDepth: false,
21346
+ strictMerge: true,
21326
21347
  strictNullHandling: false,
21327
21348
  throwOnLimitExceeded: false
21328
21349
  };
@@ -21393,9 +21414,15 @@ var require_parse = __commonJS((exports, module) => {
21393
21414
  if (part.indexOf("[]=") > -1) {
21394
21415
  val = isArray(val) ? [val] : val;
21395
21416
  }
21417
+ if (options.comma && isArray(val) && val.length > options.arrayLimit) {
21418
+ if (options.throwOnLimitExceeded) {
21419
+ throw new RangeError("Array limit exceeded. Only " + options.arrayLimit + " element" + (options.arrayLimit === 1 ? "" : "s") + " allowed in an array.");
21420
+ }
21421
+ val = utils.combine([], val, options.arrayLimit, options.plainObjects);
21422
+ }
21396
21423
  if (key !== null) {
21397
21424
  var existing = has.call(obj, key);
21398
- if (existing && options.duplicates === "combine") {
21425
+ if (existing && (options.duplicates === "combine" || part.indexOf("[]=") > -1)) {
21399
21426
  obj[key] = utils.combine(obj[key], val, options.arrayLimit, options.plainObjects);
21400
21427
  } else if (!existing || options.duplicates === "last") {
21401
21428
  obj[key] = val;
@@ -21425,11 +21452,17 @@ var require_parse = __commonJS((exports, module) => {
21425
21452
  var cleanRoot = root.charAt(0) === "[" && root.charAt(root.length - 1) === "]" ? root.slice(1, -1) : root;
21426
21453
  var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/g, ".") : cleanRoot;
21427
21454
  var index = parseInt(decodedRoot, 10);
21455
+ var isValidArrayIndex = !isNaN(index) && root !== decodedRoot && String(index) === decodedRoot && index >= 0 && options.parseArrays;
21428
21456
  if (!options.parseArrays && decodedRoot === "") {
21429
21457
  obj = { 0: leaf };
21430
- } else if (!isNaN(index) && root !== decodedRoot && String(index) === decodedRoot && index >= 0 && (options.parseArrays && index <= options.arrayLimit)) {
21458
+ } else if (isValidArrayIndex && index < options.arrayLimit) {
21431
21459
  obj = [];
21432
21460
  obj[index] = leaf;
21461
+ } else if (isValidArrayIndex && options.throwOnLimitExceeded) {
21462
+ throw new RangeError("Array limit exceeded. Only " + options.arrayLimit + " element" + (options.arrayLimit === 1 ? "" : "s") + " allowed in an array.");
21463
+ } else if (isValidArrayIndex) {
21464
+ obj[index] = leaf;
21465
+ utils.markOverflow(obj, index);
21433
21466
  } else if (decodedRoot !== "__proto__") {
21434
21467
  obj[decodedRoot] = leaf;
21435
21468
  }
@@ -21459,7 +21492,7 @@ var require_parse = __commonJS((exports, module) => {
21459
21492
  return;
21460
21493
  }
21461
21494
  }
21462
- keys.push(parent);
21495
+ keys[keys.length] = parent;
21463
21496
  }
21464
21497
  var i = 0;
21465
21498
  while ((segment = child.exec(key)) !== null && i < options.depth) {
@@ -21470,13 +21503,13 @@ var require_parse = __commonJS((exports, module) => {
21470
21503
  return;
21471
21504
  }
21472
21505
  }
21473
- keys.push(segment[1]);
21506
+ keys[keys.length] = segment[1];
21474
21507
  }
21475
21508
  if (segment) {
21476
21509
  if (options.strictDepth === true) {
21477
21510
  throw new RangeError("Input depth exceeded depth option of " + options.depth + " and strictDepth is true");
21478
21511
  }
21479
- keys.push("[" + key.slice(segment.index) + "]");
21512
+ keys[keys.length] = "[" + key.slice(segment.index) + "]";
21480
21513
  }
21481
21514
  return keys;
21482
21515
  };
@@ -21535,6 +21568,7 @@ var require_parse = __commonJS((exports, module) => {
21535
21568
  parseArrays: opts.parseArrays !== false,
21536
21569
  plainObjects: typeof opts.plainObjects === "boolean" ? opts.plainObjects : defaults.plainObjects,
21537
21570
  strictDepth: typeof opts.strictDepth === "boolean" ? !!opts.strictDepth : defaults.strictDepth,
21571
+ strictMerge: typeof opts.strictMerge === "boolean" ? !!opts.strictMerge : defaults.strictMerge,
21538
21572
  strictNullHandling: typeof opts.strictNullHandling === "boolean" ? opts.strictNullHandling : defaults.strictNullHandling,
21539
21573
  throwOnLimitExceeded: typeof opts.throwOnLimitExceeded === "boolean" ? opts.throwOnLimitExceeded : false
21540
21574
  };
@@ -23205,17 +23239,8 @@ var require_dist = __commonJS((exports) => {
23205
23239
  var NOOP_VALUE = (value) => value;
23206
23240
  var ID_START = /^[$_\p{ID_Start}]$/u;
23207
23241
  var ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u;
23208
- var SIMPLE_TOKENS = {
23209
- "{": "{",
23210
- "}": "}",
23211
- "(": "(",
23212
- ")": ")",
23213
- "[": "[",
23214
- "]": "]",
23215
- "+": "+",
23216
- "?": "?",
23217
- "!": "!"
23218
- };
23242
+ var ID = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
23243
+ var SIMPLE_TOKENS = "{}()[]+?!";
23219
23244
  function escapeText(str) {
23220
23245
  return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
23221
23246
  }
@@ -23256,8 +23281,8 @@ var require_dist = __commonJS((exports) => {
23256
23281
  } while (ID_CONTINUE.test(chars[index]));
23257
23282
  } else if (chars[index] === '"') {
23258
23283
  let quoteStart = index;
23259
- while (index++ < chars.length) {
23260
- if (chars[index] === '"') {
23284
+ while (index < chars.length) {
23285
+ if (chars[++index] === '"') {
23261
23286
  index++;
23262
23287
  quoteStart = 0;
23263
23288
  break;
@@ -23276,18 +23301,17 @@ var require_dist = __commonJS((exports) => {
23276
23301
  return value;
23277
23302
  }
23278
23303
  while (index < chars.length) {
23279
- const value = chars[index];
23280
- const type = SIMPLE_TOKENS[value];
23281
- if (type) {
23282
- tokens.push({ type, index: index++, value });
23304
+ const value = chars[index++];
23305
+ if (SIMPLE_TOKENS.includes(value)) {
23306
+ tokens.push({ type: value, index, value });
23283
23307
  } else if (value === "\\") {
23284
- tokens.push({ type: "escape", index: index++, value: chars[index++] });
23308
+ tokens.push({ type: "escape", index, value: chars[index++] });
23285
23309
  } else if (value === ":") {
23286
- tokens.push({ type: "param", index: index++, value: name() });
23310
+ tokens.push({ type: "param", index, value: name() });
23287
23311
  } else if (value === "*") {
23288
- tokens.push({ type: "wildcard", index: index++, value: name() });
23312
+ tokens.push({ type: "wildcard", index, value: name() });
23289
23313
  } else {
23290
- tokens.push({ type: "char", index: index++, value });
23314
+ tokens.push({ type: "char", index, value });
23291
23315
  }
23292
23316
  }
23293
23317
  tokens.push({ type: "end", index, value: "" });
@@ -23424,106 +23448,129 @@ var require_dist = __commonJS((exports) => {
23424
23448
  function pathToRegexp(path, options = {}) {
23425
23449
  const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true } = options;
23426
23450
  const keys = [];
23427
- const flags = sensitive ? "" : "i";
23428
23451
  const sources = [];
23429
- for (const input of pathsToArray(path, [])) {
23430
- const data = typeof input === "object" ? input : parse5(input, options);
23431
- for (const tokens of flatten(data.tokens, 0, [])) {
23432
- sources.push(toRegExpSource(tokens, delimiter, keys, data.originalPath));
23452
+ const paths = [path];
23453
+ let combinations = 0;
23454
+ while (paths.length) {
23455
+ const path2 = paths.shift();
23456
+ if (Array.isArray(path2)) {
23457
+ paths.push(...path2);
23458
+ continue;
23433
23459
  }
23460
+ const data = typeof path2 === "object" ? path2 : parse5(path2, options);
23461
+ flatten(data.tokens, 0, [], (tokens) => {
23462
+ if (combinations++ >= 256) {
23463
+ throw new PathError("Too many path combinations", data.originalPath);
23464
+ }
23465
+ sources.push(toRegExpSource(tokens, delimiter, keys, data.originalPath));
23466
+ });
23434
23467
  }
23435
23468
  let pattern = `^(?:${sources.join("|")})`;
23436
23469
  if (trailing)
23437
- pattern += `(?:${escape2(delimiter)}$)?`;
23438
- pattern += end ? "$" : `(?=${escape2(delimiter)}|$)`;
23439
- const regexp = new RegExp(pattern, flags);
23440
- return { regexp, keys };
23441
- }
23442
- function pathsToArray(paths, init) {
23443
- if (Array.isArray(paths)) {
23444
- for (const p of paths)
23445
- pathsToArray(p, init);
23446
- } else {
23447
- init.push(paths);
23448
- }
23449
- return init;
23470
+ pattern += "(?:" + escape2(delimiter) + "$)?";
23471
+ pattern += end ? "$" : "(?=" + escape2(delimiter) + "|$)";
23472
+ return { regexp: new RegExp(pattern, sensitive ? "" : "i"), keys };
23450
23473
  }
23451
- function* flatten(tokens, index, init) {
23452
- if (index === tokens.length) {
23453
- return yield init;
23454
- }
23455
- const token = tokens[index];
23456
- if (token.type === "group") {
23457
- for (const seq of flatten(token.tokens, 0, init.slice())) {
23458
- yield* flatten(tokens, index + 1, seq);
23474
+ function flatten(tokens, index, result, callback) {
23475
+ while (index < tokens.length) {
23476
+ const token = tokens[index++];
23477
+ if (token.type === "group") {
23478
+ flatten(token.tokens, 0, result.slice(), (seq) => flatten(tokens, index, seq, callback));
23479
+ continue;
23459
23480
  }
23460
- } else {
23461
- init.push(token);
23481
+ result.push(token);
23462
23482
  }
23463
- yield* flatten(tokens, index + 1, init);
23483
+ callback(result);
23464
23484
  }
23465
23485
  function toRegExpSource(tokens, delimiter, keys, originalPath) {
23466
23486
  let result = "";
23467
23487
  let backtrack = "";
23468
- let isSafeSegmentParam = true;
23469
- for (const token of tokens) {
23488
+ let wildcardBacktrack = "";
23489
+ let prevCaptureType = 0;
23490
+ let hasSegmentCapture = 0;
23491
+ let index = 0;
23492
+ function hasInSegment(index2, type) {
23493
+ while (index2 < tokens.length) {
23494
+ const token = tokens[index2++];
23495
+ if (token.type === type)
23496
+ return true;
23497
+ if (token.type === "text") {
23498
+ if (token.value.includes(delimiter))
23499
+ break;
23500
+ }
23501
+ }
23502
+ return false;
23503
+ }
23504
+ function peekText(index2) {
23505
+ let result2 = "";
23506
+ while (index2 < tokens.length) {
23507
+ const token = tokens[index2++];
23508
+ if (token.type !== "text")
23509
+ break;
23510
+ result2 += token.value;
23511
+ }
23512
+ return result2;
23513
+ }
23514
+ while (index < tokens.length) {
23515
+ const token = tokens[index++];
23470
23516
  if (token.type === "text") {
23471
23517
  result += escape2(token.value);
23472
23518
  backtrack += token.value;
23473
- isSafeSegmentParam || (isSafeSegmentParam = token.value.includes(delimiter));
23519
+ if (prevCaptureType === 2)
23520
+ wildcardBacktrack += token.value;
23521
+ if (token.value.includes(delimiter))
23522
+ hasSegmentCapture = 0;
23474
23523
  continue;
23475
23524
  }
23476
23525
  if (token.type === "param" || token.type === "wildcard") {
23477
- if (!isSafeSegmentParam && !backtrack) {
23526
+ if (prevCaptureType && !backtrack) {
23478
23527
  throw new PathError(`Missing text before "${token.name}" ${token.type}`, originalPath);
23479
23528
  }
23480
23529
  if (token.type === "param") {
23481
- result += `(${negate(delimiter, isSafeSegmentParam ? "" : backtrack)}+)`;
23530
+ result += hasSegmentCapture & 2 ? `(${negate(delimiter, backtrack)}+)` : hasInSegment(index, "wildcard") ? `(${negate(delimiter, peekText(index))}+)` : hasSegmentCapture & 1 ? `(${negate(delimiter, backtrack)}+|${escape2(backtrack)})` : `(${negate(delimiter, "")}+)`;
23531
+ hasSegmentCapture |= prevCaptureType = 1;
23482
23532
  } else {
23483
- result += `([\\s\\S]+)`;
23533
+ result += hasSegmentCapture & 2 ? `(${negate(backtrack, "")}+)` : wildcardBacktrack ? `(${negate(wildcardBacktrack, "")}+|${negate(delimiter, "")}+)` : `([^]+)`;
23534
+ wildcardBacktrack = "";
23535
+ hasSegmentCapture |= prevCaptureType = 2;
23484
23536
  }
23485
23537
  keys.push(token);
23486
23538
  backtrack = "";
23487
- isSafeSegmentParam = false;
23488
23539
  continue;
23489
23540
  }
23541
+ throw new TypeError(`Unknown token type: ${token.type}`);
23490
23542
  }
23491
23543
  return result;
23492
23544
  }
23493
- function negate(delimiter, backtrack) {
23494
- if (backtrack.length < 2) {
23495
- if (delimiter.length < 2)
23496
- return `[^${escape2(delimiter + backtrack)}]`;
23497
- return `(?:(?!${escape2(delimiter)})[^${escape2(backtrack)}])`;
23498
- }
23499
- if (delimiter.length < 2) {
23500
- return `(?:(?!${escape2(backtrack)})[^${escape2(delimiter)}])`;
23501
- }
23502
- return `(?:(?!${escape2(backtrack)}|${escape2(delimiter)})[\\s\\S])`;
23503
- }
23504
- function stringifyTokens(tokens) {
23545
+ function negate(a, b) {
23546
+ if (b.length > a.length)
23547
+ return negate(b, a);
23548
+ if (a === b)
23549
+ b = "";
23550
+ if (b.length > 1)
23551
+ return `(?:(?!${escape2(a)}|${escape2(b)})[^])`;
23552
+ if (a.length > 1)
23553
+ return `(?:(?!${escape2(a)})[^${escape2(b)}])`;
23554
+ return `[^${escape2(a + b)}]`;
23555
+ }
23556
+ function stringifyTokens(tokens, index) {
23505
23557
  let value = "";
23506
- let i = 0;
23507
- function name(value2) {
23508
- const isSafe = isNameSafe(value2) && isNextNameSafe(tokens[i]);
23509
- return isSafe ? value2 : JSON.stringify(value2);
23510
- }
23511
- while (i < tokens.length) {
23512
- const token = tokens[i++];
23558
+ while (index < tokens.length) {
23559
+ const token = tokens[index++];
23513
23560
  if (token.type === "text") {
23514
23561
  value += escapeText(token.value);
23515
23562
  continue;
23516
23563
  }
23517
23564
  if (token.type === "group") {
23518
- value += `{${stringifyTokens(token.tokens)}}`;
23565
+ value += "{" + stringifyTokens(token.tokens, 0) + "}";
23519
23566
  continue;
23520
23567
  }
23521
23568
  if (token.type === "param") {
23522
- value += `:${name(token.name)}`;
23569
+ value += ":" + stringifyName(token.name, tokens[index]);
23523
23570
  continue;
23524
23571
  }
23525
23572
  if (token.type === "wildcard") {
23526
- value += `*${name(token.name)}`;
23573
+ value += "*" + stringifyName(token.name, tokens[index]);
23527
23574
  continue;
23528
23575
  }
23529
23576
  throw new TypeError(`Unknown token type: ${token.type}`);
@@ -23531,16 +23578,15 @@ var require_dist = __commonJS((exports) => {
23531
23578
  return value;
23532
23579
  }
23533
23580
  function stringify(data) {
23534
- return stringifyTokens(data.tokens);
23535
- }
23536
- function isNameSafe(name) {
23537
- const [first, ...rest] = name;
23538
- return ID_START.test(first) && rest.every((char) => ID_CONTINUE.test(char));
23581
+ return stringifyTokens(data.tokens, 0);
23539
23582
  }
23540
- function isNextNameSafe(token) {
23541
- if (token && token.type === "text")
23542
- return !ID_CONTINUE.test(token.value[0]);
23543
- return true;
23583
+ function stringifyName(name, next) {
23584
+ if (!ID.test(name))
23585
+ return JSON.stringify(name);
23586
+ if ((next === null || next === undefined ? undefined : next.type) === "text" && ID_CONTINUE.test(next.value[0])) {
23587
+ return JSON.stringify(name);
23588
+ }
23589
+ return name;
23544
23590
  }
23545
23591
  });
23546
23592
 
@@ -32072,7 +32118,7 @@ var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || t
32072
32118
  var ProgressTokenSchema = union([string2(), number2().int()]);
32073
32119
  var CursorSchema = string2();
32074
32120
  var TaskCreationParamsSchema = looseObject({
32075
- ttl: union([number2(), _null3()]).optional(),
32121
+ ttl: number2().optional(),
32076
32122
  pollInterval: number2().optional()
32077
32123
  });
32078
32124
  var TaskMetadataSchema = object({
@@ -32224,7 +32270,8 @@ var ClientCapabilitiesSchema = object({
32224
32270
  roots: object({
32225
32271
  listChanged: boolean2().optional()
32226
32272
  }).optional(),
32227
- tasks: ClientTasksCapabilitySchema.optional()
32273
+ tasks: ClientTasksCapabilitySchema.optional(),
32274
+ extensions: record(string2(), AssertObjectSchema).optional()
32228
32275
  });
32229
32276
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
32230
32277
  protocolVersion: string2(),
@@ -32250,7 +32297,8 @@ var ServerCapabilitiesSchema = object({
32250
32297
  tools: object({
32251
32298
  listChanged: boolean2().optional()
32252
32299
  }).optional(),
32253
- tasks: ServerTasksCapabilitySchema.optional()
32300
+ tasks: ServerTasksCapabilitySchema.optional(),
32301
+ extensions: record(string2(), AssertObjectSchema).optional()
32254
32302
  });
32255
32303
  var InitializeResultSchema = ResultSchema.extend({
32256
32304
  protocolVersion: string2(),
@@ -32365,6 +32413,7 @@ var ResourceSchema = object({
32365
32413
  uri: string2(),
32366
32414
  description: optional(string2()),
32367
32415
  mimeType: optional(string2()),
32416
+ size: optional(number2()),
32368
32417
  annotations: AnnotationsSchema.optional(),
32369
32418
  _meta: optional(looseObject({}))
32370
32419
  });
@@ -33555,6 +33604,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
33555
33604
  class WebStandardStreamableHTTPServerTransport {
33556
33605
  constructor(options = {}) {
33557
33606
  this._started = false;
33607
+ this._hasHandledRequest = false;
33558
33608
  this._streamMapping = new Map;
33559
33609
  this._requestToStreamMapping = new Map;
33560
33610
  this._requestResponseMap = new Map;
@@ -33617,6 +33667,10 @@ class WebStandardStreamableHTTPServerTransport {
33617
33667
  return;
33618
33668
  }
33619
33669
  async handleRequest(req, options) {
33670
+ if (!this.sessionIdGenerator && this._hasHandledRequest) {
33671
+ throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
33672
+ }
33673
+ this._hasHandledRequest = true;
33620
33674
  const validationError = this.validateRequestHeaders(req);
33621
33675
  if (validationError) {
33622
33676
  return validationError;
@@ -33656,6 +33710,7 @@ data:
33656
33710
  async handleGetRequest(req) {
33657
33711
  const acceptHeader = req.headers.get("accept");
33658
33712
  if (!acceptHeader?.includes("text/event-stream")) {
33713
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
33659
33714
  return this.createJsonErrorResponse(406, -32000, "Not Acceptable: Client must accept text/event-stream");
33660
33715
  }
33661
33716
  const sessionError = this.validateSession(req);
@@ -33673,6 +33728,7 @@ data:
33673
33728
  }
33674
33729
  }
33675
33730
  if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) {
33731
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
33676
33732
  return this.createJsonErrorResponse(409, -32000, "Conflict: Only one SSE stream is allowed per session");
33677
33733
  }
33678
33734
  const encoder = new TextEncoder;
@@ -33707,6 +33763,7 @@ data:
33707
33763
  }
33708
33764
  async replayEvents(lastEventId) {
33709
33765
  if (!this._eventStore) {
33766
+ this.onerror?.(new Error("Event store not configured"));
33710
33767
  return this.createJsonErrorResponse(400, -32000, "Event store not configured");
33711
33768
  }
33712
33769
  try {
@@ -33714,9 +33771,11 @@ data:
33714
33771
  if (this._eventStore.getStreamIdForEventId) {
33715
33772
  streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
33716
33773
  if (!streamId) {
33774
+ this.onerror?.(new Error("Invalid event ID format"));
33717
33775
  return this.createJsonErrorResponse(400, -32000, "Invalid event ID format");
33718
33776
  }
33719
33777
  if (this._streamMapping.get(streamId) !== undefined) {
33778
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
33720
33779
  return this.createJsonErrorResponse(409, -32000, "Conflict: Stream already has an active connection");
33721
33780
  }
33722
33781
  }
@@ -33776,11 +33835,13 @@ data:
33776
33835
  `;
33777
33836
  controller.enqueue(encoder.encode(eventData));
33778
33837
  return true;
33779
- } catch {
33838
+ } catch (error2) {
33839
+ this.onerror?.(error2);
33780
33840
  return false;
33781
33841
  }
33782
33842
  }
33783
33843
  handleUnsupportedRequest() {
33844
+ this.onerror?.(new Error("Method not allowed."));
33784
33845
  return new Response(JSON.stringify({
33785
33846
  jsonrpc: "2.0",
33786
33847
  error: {
@@ -33800,14 +33861,17 @@ data:
33800
33861
  try {
33801
33862
  const acceptHeader = req.headers.get("accept");
33802
33863
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
33864
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
33803
33865
  return this.createJsonErrorResponse(406, -32000, "Not Acceptable: Client must accept both application/json and text/event-stream");
33804
33866
  }
33805
33867
  const ct = req.headers.get("content-type");
33806
33868
  if (!ct || !ct.includes("application/json")) {
33869
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
33807
33870
  return this.createJsonErrorResponse(415, -32000, "Unsupported Media Type: Content-Type must be application/json");
33808
33871
  }
33809
33872
  const requestInfo = {
33810
- headers: Object.fromEntries(req.headers.entries())
33873
+ headers: Object.fromEntries(req.headers.entries()),
33874
+ url: new URL(req.url)
33811
33875
  };
33812
33876
  let rawMessage;
33813
33877
  if (options?.parsedBody !== undefined) {
@@ -33816,6 +33880,7 @@ data:
33816
33880
  try {
33817
33881
  rawMessage = await req.json();
33818
33882
  } catch {
33883
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
33819
33884
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
33820
33885
  }
33821
33886
  }
@@ -33827,14 +33892,17 @@ data:
33827
33892
  messages = [JSONRPCMessageSchema.parse(rawMessage)];
33828
33893
  }
33829
33894
  } catch {
33895
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
33830
33896
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
33831
33897
  }
33832
33898
  const isInitializationRequest = messages.some(isInitializeRequest);
33833
33899
  if (isInitializationRequest) {
33834
33900
  if (this._initialized && this.sessionId !== undefined) {
33901
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
33835
33902
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
33836
33903
  }
33837
33904
  if (messages.length > 1) {
33905
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
33838
33906
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
33839
33907
  }
33840
33908
  this.sessionId = this.sessionIdGenerator?.();
@@ -33952,13 +34020,16 @@ data:
33952
34020
  return;
33953
34021
  }
33954
34022
  if (!this._initialized) {
34023
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
33955
34024
  return this.createJsonErrorResponse(400, -32000, "Bad Request: Server not initialized");
33956
34025
  }
33957
34026
  const sessionId = req.headers.get("mcp-session-id");
33958
34027
  if (!sessionId) {
34028
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
33959
34029
  return this.createJsonErrorResponse(400, -32000, "Bad Request: Mcp-Session-Id header is required");
33960
34030
  }
33961
34031
  if (sessionId !== this.sessionId) {
34032
+ this.onerror?.(new Error("Session not found"));
33962
34033
  return this.createJsonErrorResponse(404, -32001, "Session not found");
33963
34034
  }
33964
34035
  return;
@@ -33966,6 +34037,7 @@ data:
33966
34037
  validateProtocolVersion(req) {
33967
34038
  const protocolVersion = req.headers.get("mcp-protocol-version");
33968
34039
  if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
34040
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion}` + ` (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
33969
34041
  return this.createJsonErrorResponse(400, -32000, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
33970
34042
  }
33971
34043
  return;
@@ -34071,7 +34143,7 @@ class StreamableHTTPServerTransport {
34071
34143
  authInfo: context?.authInfo,
34072
34144
  parsedBody: context?.parsedBody
34073
34145
  });
34074
- });
34146
+ }, { overrideGlobalObjects: false });
34075
34147
  }
34076
34148
  get sessionId() {
34077
34149
  return this._webStandardTransport.sessionId;
@@ -34110,7 +34182,7 @@ class StreamableHTTPServerTransport {
34110
34182
  authInfo,
34111
34183
  parsedBody
34112
34184
  });
34113
- });
34185
+ }, { overrideGlobalObjects: false });
34114
34186
  await handler(req, res);
34115
34187
  }
34116
34188
  closeSSEStream(requestId) {