@dereekb/firebase-server 13.14.0 → 13.15.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/mcp/index.cjs.js CHANGED
@@ -117,13 +117,13 @@ function _define_property$7(obj, key, value) {
117
117
  * NestJS injection token for the optional {@link McpAuthRoleReader} provider.
118
118
  */ var MCP_AUTH_ROLE_READER = 'MCP_AUTH_ROLE_READER';
119
119
 
120
- function _type_of$2(obj) {
120
+ function _type_of$3(obj) {
121
121
  "@swc/helpers - typeof";
122
122
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
123
123
  }
124
124
  function __decorate(decorators, target, key, desc) {
125
125
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
126
- if ((typeof Reflect === "undefined" ? "undefined" : _type_of$2(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
126
+ if ((typeof Reflect === "undefined" ? "undefined" : _type_of$3(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
127
127
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
128
128
  return c > 3 && r && Object.defineProperty(target, key, r), r;
129
129
  }
@@ -192,7 +192,7 @@ function _class_call_check$4(instance, Constructor) {
192
192
  return isDefault ? "".concat(modelType, ".").concat(call, "._") : "".concat(modelType, ".").concat(call, ".").concat(specifier);
193
193
  }
194
194
 
195
- function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
195
+ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
196
196
  try {
197
197
  var info = gen[key](arg);
198
198
  var value = info.value;
@@ -206,22 +206,22 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
206
206
  Promise.resolve(value).then(_next, _throw);
207
207
  }
208
208
  }
209
- function _async_to_generator$4(fn) {
209
+ function _async_to_generator$5(fn) {
210
210
  return function() {
211
211
  var self = this, args = arguments;
212
212
  return new Promise(function(resolve, reject) {
213
213
  var gen = fn.apply(self, args);
214
214
  function _next(value) {
215
- asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
215
+ asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
216
216
  }
217
217
  function _throw(err) {
218
- asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
218
+ asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
219
219
  }
220
220
  _next(undefined);
221
221
  });
222
222
  };
223
223
  }
224
- function _instanceof(left, right) {
224
+ function _instanceof$1(left, right) {
225
225
  "@swc/helpers - instanceof";
226
226
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
227
227
  return !!right[Symbol.hasInstance](left);
@@ -229,7 +229,7 @@ function _instanceof(left, right) {
229
229
  return left instanceof right;
230
230
  }
231
231
  }
232
- function _ts_generator$4(thisArg, body) {
232
+ function _ts_generator$5(thisArg, body) {
233
233
  var f, y, t, _ = {
234
234
  label: 0,
235
235
  sent: function() {
@@ -357,9 +357,9 @@ function _ts_generator$4(thisArg, body) {
357
357
  * @param details - The handler-level API details (carries the mapper + Tier 2/3 formatters).
358
358
  * @returns The MCP tool response content.
359
359
  */ function formatMcpToolResponse(result, params, details) {
360
- return _async_to_generator$4(function() {
360
+ return _async_to_generator$5(function() {
361
361
  var mcp, value, _tmp, context, response, summary;
362
- return _ts_generator$4(this, function(_state) {
362
+ return _ts_generator$5(this, function(_state) {
363
363
  switch(_state.label){
364
364
  case 0:
365
365
  mcp = details === null || details === void 0 ? void 0 : details.mcp;
@@ -425,7 +425,7 @@ function _ts_generator$4(thisArg, body) {
425
425
  * @param error - The thrown error.
426
426
  * @returns An MCP tool response with `isError: true` and the error message as a text block.
427
427
  */ function formatMcpToolErrorResponse(error) {
428
- var message = _instanceof(error, Error) ? error.message : String(error);
428
+ var message = _instanceof$1(error, Error) ? error.message : String(error);
429
429
  return {
430
430
  isError: true,
431
431
  content: [
@@ -523,15 +523,15 @@ function stringifyResult(result) {
523
523
  return firebase.callModelOidcScopeForCallType(callType);
524
524
  }
525
525
 
526
- function _array_like_to_array$6(arr, len) {
526
+ function _array_like_to_array$7(arr, len) {
527
527
  if (len == null || len > arr.length) len = arr.length;
528
528
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
529
529
  return arr2;
530
530
  }
531
- function _array_with_holes$2(arr) {
531
+ function _array_with_holes$3(arr) {
532
532
  if (Array.isArray(arr)) return arr;
533
533
  }
534
- function _iterable_to_array_limit$2(arr, i) {
534
+ function _iterable_to_array_limit$3(arr, i) {
535
535
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
536
536
  if (_i == null) return;
537
537
  var _arr = [];
@@ -555,23 +555,23 @@ function _iterable_to_array_limit$2(arr, i) {
555
555
  }
556
556
  return _arr;
557
557
  }
558
- function _non_iterable_rest$2() {
558
+ function _non_iterable_rest$3() {
559
559
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
560
560
  }
561
- function _sliced_to_array$2(arr, i) {
562
- return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$6(arr, i) || _non_iterable_rest$2();
561
+ function _sliced_to_array$3(arr, i) {
562
+ return _array_with_holes$3(arr) || _iterable_to_array_limit$3(arr, i) || _unsupported_iterable_to_array$7(arr, i) || _non_iterable_rest$3();
563
563
  }
564
- function _type_of$1(obj) {
564
+ function _type_of$2(obj) {
565
565
  "@swc/helpers - typeof";
566
566
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
567
567
  }
568
- function _unsupported_iterable_to_array$6(o, minLen) {
568
+ function _unsupported_iterable_to_array$7(o, minLen) {
569
569
  if (!o) return;
570
- if (typeof o === "string") return _array_like_to_array$6(o, minLen);
570
+ if (typeof o === "string") return _array_like_to_array$7(o, minLen);
571
571
  var n = Object.prototype.toString.call(o).slice(8, -1);
572
572
  if (n === "Object" && o.constructor) n = o.constructor.name;
573
573
  if (n === "Map" || n === "Set") return Array.from(n);
574
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$6(o, minLen);
574
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$7(o, minLen);
575
575
  }
576
576
  /**
577
577
  * Default `toJsonSchema()` options.
@@ -837,18 +837,18 @@ function _unsupported_iterable_to_array$6(o, minLen) {
837
837
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
838
838
  try {
839
839
  for(var _iterator = Object.entries(apiDetails.models)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
840
- var _step_value = _sliced_to_array$2(_step.value, 2), modelType = _step_value[0], modelEntry = _step_value[1];
840
+ var _step_value = _sliced_to_array$3(_step.value, 2), modelType = _step_value[0], modelEntry = _step_value[1];
841
841
  var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
842
842
  try {
843
843
  for(var _iterator1 = Object.entries(modelEntry.calls)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
844
- var _step_value1 = _sliced_to_array$2(_step1.value, 2), callType = _step_value1[0], callDetails = _step_value1[1];
844
+ var _step_value1 = _sliced_to_array$3(_step1.value, 2), callType = _step_value1[0], callDetails = _step_value1[1];
845
845
  if (callDetails == null) {
846
846
  continue;
847
847
  }
848
848
  var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
849
849
  try {
850
850
  for(var _iterator2 = Object.entries(callDetails.specifiers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
851
- var _step_value2 = _sliced_to_array$2(_step2.value, 2), specifierKey = _step_value2[0], handlerDetails = _step_value2[1];
851
+ var _step_value2 = _sliced_to_array$3(_step2.value, 2), specifierKey = _step_value2[0], handlerDetails = _step_value2[1];
852
852
  var _ref;
853
853
  var _naming_modelSegments, _handlerDetails_mcp, _handlerDetails_mcp1;
854
854
  if (handlerDetails == null) {
@@ -1096,7 +1096,7 @@ function resolveInputSchema(context) {
1096
1096
  var result;
1097
1097
  try {
1098
1098
  var exported = model.arktypeToJsonSchemaForExport(handlerDetails.inputType);
1099
- if (exported && (typeof exported === "undefined" ? "undefined" : _type_of$1(exported)) === 'object') {
1099
+ if (exported && (typeof exported === "undefined" ? "undefined" : _type_of$2(exported)) === 'object') {
1100
1100
  result = exported;
1101
1101
  } else {
1102
1102
  // arktypeToJsonSchemaForExport returned a non-object (shouldn't happen for object schemas).
@@ -1115,15 +1115,15 @@ function resolveInputSchema(context) {
1115
1115
  return result;
1116
1116
  }
1117
1117
 
1118
- function _array_like_to_array$5(arr, len) {
1118
+ function _array_like_to_array$6(arr, len) {
1119
1119
  if (len == null || len > arr.length) len = arr.length;
1120
1120
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1121
1121
  return arr2;
1122
1122
  }
1123
1123
  function _array_without_holes$5(arr) {
1124
- if (Array.isArray(arr)) return _array_like_to_array$5(arr);
1124
+ if (Array.isArray(arr)) return _array_like_to_array$6(arr);
1125
1125
  }
1126
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
1126
+ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
1127
1127
  try {
1128
1128
  var info = gen[key](arg);
1129
1129
  var value = info.value;
@@ -1137,16 +1137,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
1137
1137
  Promise.resolve(value).then(_next, _throw);
1138
1138
  }
1139
1139
  }
1140
- function _async_to_generator$3(fn) {
1140
+ function _async_to_generator$4(fn) {
1141
1141
  return function() {
1142
1142
  var self = this, args = arguments;
1143
1143
  return new Promise(function(resolve, reject) {
1144
1144
  var gen = fn.apply(self, args);
1145
1145
  function _next(value) {
1146
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
1146
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
1147
1147
  }
1148
1148
  function _throw(err) {
1149
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
1149
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
1150
1150
  }
1151
1151
  _next(undefined);
1152
1152
  });
@@ -1159,17 +1159,17 @@ function _non_iterable_spread$5() {
1159
1159
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1160
1160
  }
1161
1161
  function _to_consumable_array$5(arr) {
1162
- return _array_without_holes$5(arr) || _iterable_to_array$5(arr) || _unsupported_iterable_to_array$5(arr) || _non_iterable_spread$5();
1162
+ return _array_without_holes$5(arr) || _iterable_to_array$5(arr) || _unsupported_iterable_to_array$6(arr) || _non_iterable_spread$5();
1163
1163
  }
1164
- function _unsupported_iterable_to_array$5(o, minLen) {
1164
+ function _unsupported_iterable_to_array$6(o, minLen) {
1165
1165
  if (!o) return;
1166
- if (typeof o === "string") return _array_like_to_array$5(o, minLen);
1166
+ if (typeof o === "string") return _array_like_to_array$6(o, minLen);
1167
1167
  var n = Object.prototype.toString.call(o).slice(8, -1);
1168
1168
  if (n === "Object" && o.constructor) n = o.constructor.name;
1169
1169
  if (n === "Map" || n === "Set") return Array.from(n);
1170
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$5(o, minLen);
1170
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$6(o, minLen);
1171
1171
  }
1172
- function _ts_generator$3(thisArg, body) {
1172
+ function _ts_generator$4(thisArg, body) {
1173
1173
  var f, y, t, _ = {
1174
1174
  label: 0,
1175
1175
  sent: function() {
@@ -1339,9 +1339,9 @@ function _ts_generator$3(thisArg, body) {
1339
1339
  }
1340
1340
  // MARK: Handler
1341
1341
  function modelGetToolHandler(args, ctx, deps) {
1342
- return _async_to_generator$3(function() {
1342
+ return _async_to_generator$4(function() {
1343
1343
  var result, input, identity, resolvedKeys, merged, error;
1344
- return _ts_generator$3(this, function(_state) {
1344
+ return _ts_generator$4(this, function(_state) {
1345
1345
  switch(_state.label){
1346
1346
  case 0:
1347
1347
  _state.trys.push([
@@ -1448,9 +1448,9 @@ function resolveKeys(keys, identity) {
1448
1448
  return resolved;
1449
1449
  }
1450
1450
  function readInChunks(input) {
1451
- return _async_to_generator$3(function() {
1451
+ return _async_to_generator$4(function() {
1452
1452
  var modelType, keys, auth, readDocuments, merged, offset, _merged_results, _merged_errors, batch, partial;
1453
- return _ts_generator$3(this, function(_state) {
1453
+ return _ts_generator$4(this, function(_state) {
1454
1454
  switch(_state.label){
1455
1455
  case 0:
1456
1456
  modelType = input.modelType, keys = input.keys, auth = input.auth, readDocuments = input.readDocuments;
@@ -1564,13 +1564,13 @@ var MODEL_GET_OUTPUT_SCHEMA = {
1564
1564
  }
1565
1565
  };
1566
1566
 
1567
- function _array_like_to_array$4(arr, len) {
1567
+ function _array_like_to_array$5(arr, len) {
1568
1568
  if (len == null || len > arr.length) len = arr.length;
1569
1569
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1570
1570
  return arr2;
1571
1571
  }
1572
1572
  function _array_without_holes$4(arr) {
1573
- if (Array.isArray(arr)) return _array_like_to_array$4(arr);
1573
+ if (Array.isArray(arr)) return _array_like_to_array$5(arr);
1574
1574
  }
1575
1575
  function _define_property$6(obj, key, value) {
1576
1576
  if (key in obj) {
@@ -1626,15 +1626,15 @@ function _object_spread_props(target, source) {
1626
1626
  return target;
1627
1627
  }
1628
1628
  function _to_consumable_array$4(arr) {
1629
- return _array_without_holes$4(arr) || _iterable_to_array$4(arr) || _unsupported_iterable_to_array$4(arr) || _non_iterable_spread$4();
1629
+ return _array_without_holes$4(arr) || _iterable_to_array$4(arr) || _unsupported_iterable_to_array$5(arr) || _non_iterable_spread$4();
1630
1630
  }
1631
- function _unsupported_iterable_to_array$4(o, minLen) {
1631
+ function _unsupported_iterable_to_array$5(o, minLen) {
1632
1632
  if (!o) return;
1633
- if (typeof o === "string") return _array_like_to_array$4(o, minLen);
1633
+ if (typeof o === "string") return _array_like_to_array$5(o, minLen);
1634
1634
  var n = Object.prototype.toString.call(o).slice(8, -1);
1635
1635
  if (n === "Object" && o.constructor) n = o.constructor.name;
1636
1636
  if (n === "Map" || n === "Set") return Array.from(n);
1637
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$4(o, minLen);
1637
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$5(o, minLen);
1638
1638
  }
1639
1639
  // MARK: Constants
1640
1640
  /**
@@ -2539,16 +2539,16 @@ var MODEL_DECODE_OUTPUT_SCHEMA = {
2539
2539
  }
2540
2540
  };
2541
2541
 
2542
- function _array_like_to_array$3(arr, len) {
2542
+ function _array_like_to_array$4(arr, len) {
2543
2543
  if (len == null || len > arr.length) len = arr.length;
2544
2544
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
2545
2545
  return arr2;
2546
2546
  }
2547
- function _array_with_holes$1(arr) {
2547
+ function _array_with_holes$2(arr) {
2548
2548
  if (Array.isArray(arr)) return arr;
2549
2549
  }
2550
2550
  function _array_without_holes$3(arr) {
2551
- if (Array.isArray(arr)) return _array_like_to_array$3(arr);
2551
+ if (Array.isArray(arr)) return _array_like_to_array$4(arr);
2552
2552
  }
2553
2553
  function _define_property$4(obj, key, value) {
2554
2554
  if (key in obj) {
@@ -2566,7 +2566,7 @@ function _define_property$4(obj, key, value) {
2566
2566
  function _iterable_to_array$3(iter) {
2567
2567
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
2568
2568
  }
2569
- function _iterable_to_array_limit$1(arr, i) {
2569
+ function _iterable_to_array_limit$2(arr, i) {
2570
2570
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
2571
2571
  if (_i == null) return;
2572
2572
  var _arr = [];
@@ -2590,7 +2590,7 @@ function _iterable_to_array_limit$1(arr, i) {
2590
2590
  }
2591
2591
  return _arr;
2592
2592
  }
2593
- function _non_iterable_rest$1() {
2593
+ function _non_iterable_rest$2() {
2594
2594
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2595
2595
  }
2596
2596
  function _non_iterable_spread$3() {
@@ -2611,19 +2611,19 @@ function _object_spread(target) {
2611
2611
  }
2612
2612
  return target;
2613
2613
  }
2614
- function _sliced_to_array$1(arr, i) {
2615
- return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$3(arr, i) || _non_iterable_rest$1();
2614
+ function _sliced_to_array$2(arr, i) {
2615
+ return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$4(arr, i) || _non_iterable_rest$2();
2616
2616
  }
2617
2617
  function _to_consumable_array$3(arr) {
2618
- return _array_without_holes$3(arr) || _iterable_to_array$3(arr) || _unsupported_iterable_to_array$3(arr) || _non_iterable_spread$3();
2618
+ return _array_without_holes$3(arr) || _iterable_to_array$3(arr) || _unsupported_iterable_to_array$4(arr) || _non_iterable_spread$3();
2619
2619
  }
2620
- function _unsupported_iterable_to_array$3(o, minLen) {
2620
+ function _unsupported_iterable_to_array$4(o, minLen) {
2621
2621
  if (!o) return;
2622
- if (typeof o === "string") return _array_like_to_array$3(o, minLen);
2622
+ if (typeof o === "string") return _array_like_to_array$4(o, minLen);
2623
2623
  var n = Object.prototype.toString.call(o).slice(8, -1);
2624
2624
  if (n === "Object" && o.constructor) n = o.constructor.name;
2625
2625
  if (n === "Map" || n === "Set") return Array.from(n);
2626
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$3(o, minLen);
2626
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$4(o, minLen);
2627
2627
  }
2628
2628
  // MARK: Constants
2629
2629
  /**
@@ -2697,10 +2697,10 @@ function whoamiToolHandler(ctx, deps) {
2697
2697
  }
2698
2698
  var token = (_auth_token = auth.token) !== null && _auth_token !== void 0 ? _auth_token : {};
2699
2699
  var presentKeys = Object.entries(token).filter(function(param) {
2700
- var _param = _sliced_to_array$1(param, 2), value = _param[1];
2700
+ var _param = _sliced_to_array$2(param, 2), value = _param[1];
2701
2701
  return value !== undefined;
2702
2702
  }).map(function(param) {
2703
- var _param = _sliced_to_array$1(param, 1), key = _param[0];
2703
+ var _param = _sliced_to_array$2(param, 1), key = _param[0];
2704
2704
  return key;
2705
2705
  });
2706
2706
  var roleSet = deps.roleReader == null ? new Set() : deps.roleReader(token);
@@ -2973,18 +2973,15 @@ var WHOAMI_OUTPUT_SCHEMA = {
2973
2973
  }
2974
2974
  };
2975
2975
 
2976
- function _array_like_to_array$2(arr, len) {
2976
+ function _array_like_to_array$3(arr, len) {
2977
2977
  if (len == null || len > arr.length) len = arr.length;
2978
2978
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
2979
2979
  return arr2;
2980
2980
  }
2981
- function _array_with_holes(arr) {
2981
+ function _array_with_holes$1(arr) {
2982
2982
  if (Array.isArray(arr)) return arr;
2983
2983
  }
2984
- function _array_without_holes$2(arr) {
2985
- if (Array.isArray(arr)) return _array_like_to_array$2(arr);
2986
- }
2987
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
2984
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
2988
2985
  try {
2989
2986
  var info = gen[key](arg);
2990
2987
  var value = info.value;
@@ -2998,56 +2995,30 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
2998
2995
  Promise.resolve(value).then(_next, _throw);
2999
2996
  }
3000
2997
  }
3001
- function _async_to_generator$2(fn) {
2998
+ function _async_to_generator$3(fn) {
3002
2999
  return function() {
3003
3000
  var self = this, args = arguments;
3004
3001
  return new Promise(function(resolve, reject) {
3005
3002
  var gen = fn.apply(self, args);
3006
3003
  function _next(value) {
3007
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
3004
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
3008
3005
  }
3009
3006
  function _throw(err) {
3010
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
3007
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
3011
3008
  }
3012
3009
  _next(undefined);
3013
3010
  });
3014
3011
  };
3015
3012
  }
3016
- function _class_call_check$3(instance, Constructor) {
3017
- if (!(instance instanceof Constructor)) {
3018
- throw new TypeError("Cannot call a class as a function");
3019
- }
3020
- }
3021
- function _defineProperties$3(target, props) {
3022
- for(var i = 0; i < props.length; i++){
3023
- var descriptor = props[i];
3024
- descriptor.enumerable = descriptor.enumerable || false;
3025
- descriptor.configurable = true;
3026
- if ("value" in descriptor) descriptor.writable = true;
3027
- Object.defineProperty(target, descriptor.key, descriptor);
3028
- }
3029
- }
3030
- function _create_class$3(Constructor, protoProps, staticProps) {
3031
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
3032
- return Constructor;
3033
- }
3034
- function _define_property$3(obj, key, value) {
3035
- if (key in obj) {
3036
- Object.defineProperty(obj, key, {
3037
- value: value,
3038
- enumerable: true,
3039
- configurable: true,
3040
- writable: true
3041
- });
3013
+ function _instanceof(left, right) {
3014
+ "@swc/helpers - instanceof";
3015
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
3016
+ return !!right[Symbol.hasInstance](left);
3042
3017
  } else {
3043
- obj[key] = value;
3018
+ return left instanceof right;
3044
3019
  }
3045
- return obj;
3046
- }
3047
- function _iterable_to_array$2(iter) {
3048
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
3049
3020
  }
3050
- function _iterable_to_array_limit(arr, i) {
3021
+ function _iterable_to_array_limit$1(arr, i) {
3051
3022
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
3052
3023
  if (_i == null) return;
3053
3024
  var _arr = [];
@@ -3071,27 +3042,25 @@ function _iterable_to_array_limit(arr, i) {
3071
3042
  }
3072
3043
  return _arr;
3073
3044
  }
3074
- function _non_iterable_rest() {
3045
+ function _non_iterable_rest$1() {
3075
3046
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3076
3047
  }
3077
- function _non_iterable_spread$2() {
3078
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3079
- }
3080
- function _sliced_to_array(arr, i) {
3081
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest();
3048
+ function _sliced_to_array$1(arr, i) {
3049
+ return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$3(arr, i) || _non_iterable_rest$1();
3082
3050
  }
3083
- function _to_consumable_array$2(arr) {
3084
- return _array_without_holes$2(arr) || _iterable_to_array$2(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread$2();
3051
+ function _type_of$1(obj) {
3052
+ "@swc/helpers - typeof";
3053
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
3085
3054
  }
3086
- function _unsupported_iterable_to_array$2(o, minLen) {
3055
+ function _unsupported_iterable_to_array$3(o, minLen) {
3087
3056
  if (!o) return;
3088
- if (typeof o === "string") return _array_like_to_array$2(o, minLen);
3057
+ if (typeof o === "string") return _array_like_to_array$3(o, minLen);
3089
3058
  var n = Object.prototype.toString.call(o).slice(8, -1);
3090
3059
  if (n === "Object" && o.constructor) n = o.constructor.name;
3091
3060
  if (n === "Map" || n === "Set") return Array.from(n);
3092
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
3061
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$3(o, minLen);
3093
3062
  }
3094
- function _ts_generator$2(thisArg, body) {
3063
+ function _ts_generator$3(thisArg, body) {
3095
3064
  var f, y, t, _ = {
3096
3065
  label: 0,
3097
3066
  sent: function() {
@@ -3190,75 +3159,975 @@ function _ts_generator$2(thisArg, body) {
3190
3159
  };
3191
3160
  }
3192
3161
  }
3193
- var McpServerFactoryService_1;
3162
+ // MARK: Constants
3194
3163
  /**
3195
- * Injectable factory that builds {@link McpServer} instances pre-wired to the
3196
- * call model dispatch chain.
3164
+ * Reserved tool name for the built-in `batch-execute` static tool.
3165
+ */ var BATCH_EXECUTE_TOOL_NAME = 'batch-execute';
3166
+ /**
3167
+ * Synthetic call type used in the tool's dispatch identity (analytics only — the tool re-dispatches
3168
+ * to other callModel tools rather than resolving a `batch` call type of its own).
3169
+ */ var BATCH_EXECUTE_DISPATCH_CALL = 'batch';
3170
+ /**
3171
+ * Synthetic model type used in the tool's dispatch identity. The tool isn't bound to a model type
3172
+ * (each operation carries its own), so we use the literal "batch" as the identity. Apps avoiding
3173
+ * collision should not register a real model literally named "batch".
3174
+ */ var BATCH_EXECUTE_DISPATCH_MODEL_TYPE = 'batch';
3175
+ /**
3176
+ * Default per-operation concurrency when the caller does not specify `maxParallel`.
3177
+ */ var DEFAULT_BATCH_EXECUTE_MAX_PARALLEL = 5;
3178
+ /**
3179
+ * Hard upper bound on operations accepted in a single batch file, guarding against an
3180
+ * accidentally enormous upload exhausting the function's memory/time budget.
3181
+ */ var MAX_BATCH_EXECUTE_OPERATIONS = 1000;
3182
+ /**
3183
+ * Maximum bytes read from the operations file. NDJSON of typical CRUD payloads stays well under
3184
+ * this; an oversized file is rejected rather than streamed.
3185
+ */ var MAX_BATCH_EXECUTE_FILE_BYTES = 5 * 1024 * 1024;
3186
+ // MARK: Coordinate key
3187
+ /**
3188
+ * Builds the lookup key identifying a callModel dispatch coordinate. The factory indexes the
3189
+ * caller's visible callModel tools by this key; the batch handler looks each operation up by the
3190
+ * same key, so authorization reuses the exact tool set advertised on `tools/list`.
3197
3191
  *
3198
- * The factory is invoked per Streamable HTTP request — `@modelcontextprotocol/sdk`
3199
- * recommends a fresh `McpServer` + transport pair per stateless JSON-RPC request,
3200
- * which sidesteps session bookkeeping for the common Claude-connector case.
3201
- */ exports.McpServerFactoryService = McpServerFactoryService_1 = /*#__PURE__*/ function() {
3202
- function McpServerFactoryService(mcpConfig, dispatchService, modelApiGetService, roleReader, analyticsService) {
3203
- _class_call_check$3(this, McpServerFactoryService);
3204
- _define_property$3(this, "mcpConfig", void 0);
3205
- _define_property$3(this, "dispatchService", void 0);
3206
- _define_property$3(this, "modelApiGetService", void 0);
3207
- _define_property$3(this, "roleReader", void 0);
3208
- _define_property$3(this, "_logger", new common.Logger(McpServerFactoryService_1.name));
3209
- _define_property$3(this, "_cachedTools", void 0);
3210
- _define_property$3(this, "_cachedStaticTools", void 0);
3211
- _define_property$3(this, "_cachedManifest", void 0);
3212
- _define_property$3(this, "_cachedManifestModels", void 0);
3213
- _define_property$3(this, "_cachedManifestAuth", void 0);
3214
- _define_property$3(this, "_manifestLoaded", false);
3215
- _define_property$3(this, "_loggedSkips", false);
3216
- _define_property$3(this, "_warnedMissingRoleReader", false);
3217
- _define_property$3(this, "_analyticsService", void 0);
3218
- this.mcpConfig = mcpConfig;
3219
- this.dispatchService = dispatchService;
3220
- this.modelApiGetService = modelApiGetService;
3221
- this.roleReader = roleReader;
3222
- this._analyticsService = analyticsService !== null && analyticsService !== void 0 ? analyticsService : noopMcpAnalyticsService();
3223
- }
3224
- _create_class$3(McpServerFactoryService, [
3225
- {
3226
- /**
3227
- * Builds a configured MCP server with tool listing + dispatch handlers wired up.
3228
- *
3229
- * @param ctx - The per-request context (auth, raw request) used when forwarding tool calls.
3230
- * @returns A configured MCP server ready to be `connect()`-ed to a transport.
3231
- */ key: "createServer",
3232
- value: function createServer(ctx) {
3233
- var _this = this;
3234
- var _this_mcpConfig_serverName, _this_mcpConfig_serverVersion, _this_mcpConfig_serverInstructions;
3235
- var baseServerName = (_this_mcpConfig_serverName = this.mcpConfig.serverName) !== null && _this_mcpConfig_serverName !== void 0 ? _this_mcpConfig_serverName : DEFAULT_MCP_SERVER_NAME;
3236
- var serverName = this.mcpConfig.readOnly === true ? "".concat(baseServerName, " (read-only)") : baseServerName;
3237
- var server = new mcp_js.McpServer({
3238
- name: serverName,
3239
- version: (_this_mcpConfig_serverVersion = this.mcpConfig.serverVersion) !== null && _this_mcpConfig_serverVersion !== void 0 ? _this_mcpConfig_serverVersion : '0.0.0'
3240
- }, {
3241
- instructions: (_this_mcpConfig_serverInstructions = this.mcpConfig.serverInstructions) !== null && _this_mcpConfig_serverInstructions !== void 0 ? _this_mcpConfig_serverInstructions : DEFAULT_MCP_SERVER_INSTRUCTIONS
3242
- });
3243
- server.server.registerCapabilities({
3244
- tools: {}
3245
- });
3246
- var toolGeneration = this._resolveToolDefinitions();
3247
- var staticTools = this._resolveStaticTools();
3248
- var scopes = this._resolveScopes(ctx);
3249
- var authRoles = this._resolveAuthRoles(ctx);
3250
- var combinedTools = _to_consumable_array$2(toolGeneration.tools).concat(_to_consumable_array$2(staticTools));
3251
- var visibleTools = this._filterToolsForRequest(combinedTools, {
3252
- ctx: ctx,
3253
- scopes: scopes,
3254
- authRoles: authRoles
3255
- });
3256
- var definitionsByName = new Map(visibleTools.map(function(tool) {
3192
+ * @param dispatch - The `(call, modelType, specifier?)` coordinate to key.
3193
+ * @returns A stable string key. Uses a NUL separator so segment values can't collide.
3194
+ */ function batchOperationCoordKey(dispatch) {
3195
+ var _dispatch_specifier;
3196
+ return "".concat(dispatch.call, "\0").concat(dispatch.modelType, "\0").concat((_dispatch_specifier = dispatch.specifier) !== null && _dispatch_specifier !== void 0 ? _dispatch_specifier : '');
3197
+ }
3198
+ // MARK: Factory
3199
+ /**
3200
+ * Builds the built-in `batch-execute` MCP tool definition.
3201
+ *
3202
+ * The tool ingests an uploaded JSON / NDJSON file of `(call, modelType, specifier?, data)`
3203
+ * operations and runs them server-side, returning a single success/failure summary. It exists so an
3204
+ * agent can perform a bulk mutation (e.g. "update 200 workers") by *generating* the operations file
3205
+ * with a script and uploading it — rather than emitting each payload as tool-call output and paying
3206
+ * one model turn per record.
3207
+ *
3208
+ * Safety model:
3209
+ * - Every operation is validated and authorized against the caller's visible tool set *before any
3210
+ * dispatch*. A malformed or forbidden operation aborts the whole batch with a pre-flight error and
3211
+ * nothing runs — `dispatch` would otherwise bypass the `tools/list` visibility filter.
3212
+ * - Runtime failures are best-effort by default (collected into the summary); `stopOnError` halts at
3213
+ * the first failure (forcing sequential execution).
3214
+ *
3215
+ * @param deps - Storage reader, dispatch fn, and per-operation authorizer (typically wired in the
3216
+ * server factory to the request's visible tool set).
3217
+ * @returns A statically-registered {@link McpToolDefinition} ready to be appended to the MCP server
3218
+ * factory's tool registry.
3219
+ */ function createBatchExecuteTool(deps) {
3220
+ var handler = function handler(args, ctx) {
3221
+ return batchExecuteToolHandler(args, ctx, deps);
3222
+ };
3223
+ var name = BATCH_EXECUTE_TOOL_NAME;
3224
+ var description = 'Execute a batch of MCP operations server-side from an uploaded JSON/NDJSON file, returning a success/failure summary. Each line/element is an operation `{ call, modelType, specifier?, data }` matching any other write tool you could call individually. Generate the file with a script and upload it instead of invoking a per-record tool many times. Every operation is authorized against your visible tools before any run; a forbidden or malformed operation aborts the whole batch with nothing executed.';
3225
+ return {
3226
+ name: name,
3227
+ description: description,
3228
+ inputSchema: BATCH_EXECUTE_INPUT_SCHEMA,
3229
+ outputSchema: BATCH_EXECUTE_OUTPUT_SCHEMA,
3230
+ dispatch: {
3231
+ call: BATCH_EXECUTE_DISPATCH_CALL,
3232
+ modelType: BATCH_EXECUTE_DISPATCH_MODEL_TYPE
3233
+ },
3234
+ staticHandler: handler,
3235
+ filterMetadata: {
3236
+ visibilityKind: 'declarative',
3237
+ rule: {
3238
+ requireAuthenticated: true
3239
+ },
3240
+ effectiveReadOnly: false
3241
+ },
3242
+ staticWireEntry: buildStaticWireEntry({
3243
+ name: name,
3244
+ description: description,
3245
+ inputSchema: BATCH_EXECUTE_INPUT_SCHEMA,
3246
+ outputSchema: BATCH_EXECUTE_OUTPUT_SCHEMA
3247
+ })
3248
+ };
3249
+ }
3250
+ // MARK: Handler
3251
+ function batchExecuteToolHandler(args, ctx, deps) {
3252
+ return _async_to_generator$3(function() {
3253
+ var result, _deps_maxOperations, input, maxOperations, fileText, operations, preflightErrors, execution, failureCount, successCount, skippedCount, uploadDeleted, summary, error;
3254
+ return _ts_generator$3(this, function(_state) {
3255
+ switch(_state.label){
3256
+ case 0:
3257
+ _state.trys.push([
3258
+ 0,
3259
+ 4,
3260
+ ,
3261
+ 5
3262
+ ]);
3263
+ input = parseBatchExecuteInput(args);
3264
+ maxOperations = (_deps_maxOperations = deps.maxOperations) !== null && _deps_maxOperations !== void 0 ? _deps_maxOperations : MAX_BATCH_EXECUTE_OPERATIONS;
3257
3265
  return [
3258
- tool.name,
3259
- tool
3260
- ];
3266
+ 4,
3267
+ readOperationsFile({
3268
+ storageService: deps.storageService,
3269
+ uploadPath: input.uploadPath,
3270
+ bucketId: input.bucketId
3271
+ })
3272
+ ];
3273
+ case 1:
3274
+ fileText = _state.sent();
3275
+ operations = parseOperations(fileText, input.format, maxOperations);
3276
+ // Pre-flight: validate + authorize every operation before any dispatch. dispatch() bypasses the
3277
+ // tools/list visibility filter, so an unauthorized operation must never reach it.
3278
+ preflightErrors = collectPreflightErrors(operations, deps.authorizeOperation);
3279
+ if (preflightErrors.length > 0) {
3280
+ throw new Error("batch-execute: ".concat(preflightErrors.length, " of ").concat(operations.length, " operation(s) failed pre-flight; nothing was executed. ").concat(describePreflightErrors(preflightErrors)));
3281
+ }
3282
+ return [
3283
+ 4,
3284
+ executeOperations({
3285
+ operations: operations,
3286
+ input: input,
3287
+ ctx: ctx,
3288
+ dispatch: deps.dispatch
3289
+ })
3290
+ ];
3291
+ case 2:
3292
+ execution = _state.sent();
3293
+ failureCount = execution.errors.length;
3294
+ successCount = execution.succeededCount;
3295
+ skippedCount = operations.length - successCount - failureCount;
3296
+ return [
3297
+ 4,
3298
+ maybeDeleteUpload({
3299
+ storageService: deps.storageService,
3300
+ input: input,
3301
+ failureCount: failureCount
3302
+ })
3303
+ ];
3304
+ case 3:
3305
+ uploadDeleted = _state.sent();
3306
+ summary = {
3307
+ total: operations.length,
3308
+ successCount: successCount,
3309
+ failureCount: failureCount,
3310
+ skippedCount: skippedCount,
3311
+ errors: execution.errors,
3312
+ uploadDeleted: uploadDeleted
3313
+ };
3314
+ result = {
3315
+ content: [
3316
+ {
3317
+ type: 'text',
3318
+ text: JSON.stringify(summary)
3319
+ }
3320
+ ],
3321
+ structuredContent: summary
3322
+ };
3323
+ return [
3324
+ 3,
3325
+ 5
3326
+ ];
3327
+ case 4:
3328
+ error = _state.sent();
3329
+ result = formatMcpToolErrorResponse(error);
3330
+ return [
3331
+ 3,
3332
+ 5
3333
+ ];
3334
+ case 5:
3335
+ return [
3336
+ 2,
3337
+ result
3338
+ ];
3339
+ }
3340
+ });
3341
+ })();
3342
+ }
3343
+ // MARK: Input parsing
3344
+ function parseBatchExecuteInput(args) {
3345
+ var _args_format, _args_maxParallel;
3346
+ var uploadPath = args.uploadPath;
3347
+ if (typeof uploadPath !== 'string' || uploadPath.length === 0) {
3348
+ throw new Error('batch-execute: "uploadPath" is required and must be a non-empty string.');
3349
+ }
3350
+ var bucketId = args.bucketId;
3351
+ if (bucketId != null && (typeof bucketId !== 'string' || bucketId.length === 0)) {
3352
+ throw new Error('batch-execute: "bucketId" must be a non-empty string when provided.');
3353
+ }
3354
+ var format = (_args_format = args.format) !== null && _args_format !== void 0 ? _args_format : 'ndjson';
3355
+ if (format !== 'json' && format !== 'ndjson') {
3356
+ throw new Error('batch-execute: "format" must be "json" or "ndjson".');
3357
+ }
3358
+ var maxParallel = (_args_maxParallel = args.maxParallel) !== null && _args_maxParallel !== void 0 ? _args_maxParallel : DEFAULT_BATCH_EXECUTE_MAX_PARALLEL;
3359
+ if (typeof maxParallel !== 'number' || !Number.isInteger(maxParallel) || maxParallel < 1) {
3360
+ throw new Error('batch-execute: "maxParallel" must be a positive integer.');
3361
+ }
3362
+ return {
3363
+ uploadPath: uploadPath,
3364
+ bucketId: bucketId !== null && bucketId !== void 0 ? bucketId : undefined,
3365
+ format: format,
3366
+ maxParallel: maxParallel,
3367
+ stopOnError: args.stopOnError === true,
3368
+ deleteUploadOnSuccess: args.deleteUploadOnSuccess !== false
3369
+ };
3370
+ }
3371
+ function readOperationsFile(input) {
3372
+ return _async_to_generator$3(function() {
3373
+ var file, exists, bytes;
3374
+ return _ts_generator$3(this, function(_state) {
3375
+ switch(_state.label){
3376
+ case 0:
3377
+ file = input.storageService.file(toStoragePathInput(input.uploadPath, input.bucketId));
3378
+ return [
3379
+ 4,
3380
+ file.exists()
3381
+ ];
3382
+ case 1:
3383
+ exists = _state.sent();
3384
+ if (!exists) {
3385
+ throw new Error('batch-execute: operations file not found at "'.concat(input.uploadPath, '".'));
3386
+ }
3387
+ return [
3388
+ 4,
3389
+ file.getBytes(MAX_BATCH_EXECUTE_FILE_BYTES)
3390
+ ];
3391
+ case 2:
3392
+ bytes = _state.sent();
3393
+ return [
3394
+ 2,
3395
+ Buffer.from(bytes).toString('utf8')
3396
+ ];
3397
+ }
3398
+ });
3399
+ })();
3400
+ }
3401
+ // MARK: Operation parsing
3402
+ function parseOperations(fileText, format, maxOperations) {
3403
+ var rawOperations = format === 'ndjson' ? parseNdjsonOperations(fileText) : parseJsonArrayOperations(fileText);
3404
+ if (rawOperations.length === 0) {
3405
+ throw new Error('batch-execute: the operations file contained no operations.');
3406
+ }
3407
+ if (rawOperations.length > maxOperations) {
3408
+ throw new Error("batch-execute: ".concat(rawOperations.length, " operations exceed the limit of ").concat(maxOperations, "."));
3409
+ }
3410
+ return rawOperations.map(function(value, index) {
3411
+ return validateOperation(value, index);
3412
+ });
3413
+ }
3414
+ function parseNdjsonOperations(fileText) {
3415
+ var operations = [];
3416
+ fileText.split('\n').forEach(function(line, lineIndex) {
3417
+ var trimmed = line.trim();
3418
+ if (trimmed.length > 0) {
3419
+ try {
3420
+ operations.push(JSON.parse(trimmed));
3421
+ } catch (error) {
3422
+ throw new Error("batch-execute: invalid JSON on line ".concat(lineIndex + 1, ": ").concat(error.message), {
3423
+ cause: error
3424
+ });
3425
+ }
3426
+ }
3427
+ });
3428
+ return operations;
3429
+ }
3430
+ function parseJsonArrayOperations(fileText) {
3431
+ var parsed;
3432
+ try {
3433
+ parsed = JSON.parse(fileText);
3434
+ } catch (error) {
3435
+ throw new Error("batch-execute: file is not valid JSON: ".concat(error.message), {
3436
+ cause: error
3437
+ });
3438
+ }
3439
+ if (!Array.isArray(parsed)) {
3440
+ throw new Error('batch-execute: with format "json" the file must contain a top-level array of operations.');
3441
+ }
3442
+ return parsed;
3443
+ }
3444
+ function validateOperation(value, index) {
3445
+ if (value == null || (typeof value === "undefined" ? "undefined" : _type_of$1(value)) !== 'object') {
3446
+ throw new Error("batch-execute: operation[".concat(index, "] must be an object."));
3447
+ }
3448
+ var candidate = value;
3449
+ var modelType = candidate.modelType;
3450
+ var call = candidate.call;
3451
+ var specifier = candidate.specifier;
3452
+ if (typeof modelType !== 'string' || modelType.length === 0) {
3453
+ throw new Error("batch-execute: operation[".concat(index, '] is missing a non-empty "modelType".'));
3454
+ }
3455
+ if (typeof call !== 'string' || call.length === 0) {
3456
+ throw new Error("batch-execute: operation[".concat(index, '] is missing a non-empty "call".'));
3457
+ }
3458
+ if (specifier != null && typeof specifier !== 'string') {
3459
+ throw new Error("batch-execute: operation[".concat(index, '] "specifier" must be a string when provided.'));
3460
+ }
3461
+ return {
3462
+ call: call,
3463
+ modelType: modelType,
3464
+ specifier: specifier !== null && specifier !== void 0 ? specifier : undefined,
3465
+ data: candidate.data
3466
+ };
3467
+ }
3468
+ function collectPreflightErrors(operations, authorizeOperation) {
3469
+ var errors = [];
3470
+ operations.forEach(function(operation, index) {
3471
+ var authorization = authorizeOperation(operation);
3472
+ if (!authorization.allowed) {
3473
+ var _operation_call;
3474
+ errors.push({
3475
+ index: index,
3476
+ modelType: operation.modelType,
3477
+ call: (_operation_call = operation.call) !== null && _operation_call !== void 0 ? _operation_call : undefined,
3478
+ specifier: operation.specifier,
3479
+ reason: authorization.reason
3480
+ });
3481
+ }
3482
+ });
3483
+ return errors;
3484
+ }
3485
+ function describePreflightErrors(errors) {
3486
+ var sample = errors.slice(0, 5).map(function(error) {
3487
+ var _error_call;
3488
+ var specifierSuffix = error.specifier ? "/".concat(error.specifier) : '';
3489
+ return "[".concat(error.index, "] ").concat((_error_call = error.call) !== null && _error_call !== void 0 ? _error_call : '?', "/").concat(error.modelType).concat(specifierSuffix, ": ").concat(error.reason);
3490
+ }).join('; ');
3491
+ var suffix = errors.length > 5 ? " (+".concat(errors.length - 5, " more)") : '';
3492
+ return "".concat(sample).concat(suffix);
3493
+ }
3494
+ function executeOperations(input) {
3495
+ return _async_to_generator$3(function() {
3496
+ return _ts_generator$3(this, function(_state) {
3497
+ return [
3498
+ 2,
3499
+ input.input.stopOnError ? executeSequentialStopOnError(input) : executeBestEffort(input)
3500
+ ];
3501
+ });
3502
+ })();
3503
+ }
3504
+ function executeBestEffort(input) {
3505
+ return _async_to_generator$3(function() {
3506
+ var operations, ctx, dispatch, indices, taskResult, errors;
3507
+ return _ts_generator$3(this, function(_state) {
3508
+ switch(_state.label){
3509
+ case 0:
3510
+ operations = input.operations, ctx = input.ctx, dispatch = input.dispatch;
3511
+ indices = operations.map(function(_, index) {
3512
+ return index;
3513
+ });
3514
+ return [
3515
+ 4,
3516
+ util.performAsyncTasks(indices, function(index) {
3517
+ return _async_to_generator$3(function() {
3518
+ var entry, error;
3519
+ return _ts_generator$3(this, function(_state) {
3520
+ switch(_state.label){
3521
+ case 0:
3522
+ _state.trys.push([
3523
+ 0,
3524
+ 2,
3525
+ ,
3526
+ 3
3527
+ ]);
3528
+ return [
3529
+ 4,
3530
+ dispatch(operations[index], ctx.auth, ctx.rawRequest)
3531
+ ];
3532
+ case 1:
3533
+ _state.sent();
3534
+ return [
3535
+ 3,
3536
+ 3
3537
+ ];
3538
+ case 2:
3539
+ error = _state.sent();
3540
+ entry = toErrorEntry(operations[index], index, error);
3541
+ return [
3542
+ 3,
3543
+ 3
3544
+ ];
3545
+ case 3:
3546
+ return [
3547
+ 2,
3548
+ entry
3549
+ ];
3550
+ }
3551
+ });
3552
+ })();
3553
+ }, {
3554
+ throwError: false,
3555
+ maxParallelTasks: input.input.maxParallel
3556
+ })
3557
+ ];
3558
+ case 1:
3559
+ taskResult = _state.sent();
3560
+ errors = taskResult.results.map(function(param) {
3561
+ var _param = _sliced_to_array$1(param, 2), entry = _param[1];
3562
+ return entry;
3563
+ }).filter(function(entry) {
3564
+ return entry != null;
3565
+ }).sort(function(a, b) {
3566
+ return a.index - b.index;
3567
+ });
3568
+ return [
3569
+ 2,
3570
+ {
3571
+ succeededCount: operations.length - errors.length,
3572
+ errors: errors
3573
+ }
3574
+ ];
3575
+ }
3576
+ });
3577
+ })();
3578
+ }
3579
+ function executeSequentialStopOnError(input) {
3580
+ return _async_to_generator$3(function() {
3581
+ var operations, ctx, dispatch, errors, succeededCount, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, index, operation, error, err;
3582
+ return _ts_generator$3(this, function(_state) {
3583
+ switch(_state.label){
3584
+ case 0:
3585
+ operations = input.operations, ctx = input.ctx, dispatch = input.dispatch;
3586
+ errors = [];
3587
+ succeededCount = 0;
3588
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3589
+ _state.label = 1;
3590
+ case 1:
3591
+ _state.trys.push([
3592
+ 1,
3593
+ 8,
3594
+ 9,
3595
+ 10
3596
+ ]);
3597
+ _iterator = operations.entries()[Symbol.iterator]();
3598
+ _state.label = 2;
3599
+ case 2:
3600
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3601
+ 3,
3602
+ 7
3603
+ ];
3604
+ _step_value = _sliced_to_array$1(_step.value, 2), index = _step_value[0], operation = _step_value[1];
3605
+ _state.label = 3;
3606
+ case 3:
3607
+ _state.trys.push([
3608
+ 3,
3609
+ 5,
3610
+ ,
3611
+ 6
3612
+ ]);
3613
+ return [
3614
+ 4,
3615
+ dispatch(operation, ctx.auth, ctx.rawRequest)
3616
+ ];
3617
+ case 4:
3618
+ _state.sent();
3619
+ succeededCount += 1;
3620
+ return [
3621
+ 3,
3622
+ 6
3623
+ ];
3624
+ case 5:
3625
+ error = _state.sent();
3626
+ errors.push(toErrorEntry(operation, index, error));
3627
+ return [
3628
+ 3,
3629
+ 7
3630
+ ];
3631
+ case 6:
3632
+ _iteratorNormalCompletion = true;
3633
+ return [
3634
+ 3,
3635
+ 2
3636
+ ];
3637
+ case 7:
3638
+ return [
3639
+ 3,
3640
+ 10
3641
+ ];
3642
+ case 8:
3643
+ err = _state.sent();
3644
+ _didIteratorError = true;
3645
+ _iteratorError = err;
3646
+ return [
3647
+ 3,
3648
+ 10
3649
+ ];
3650
+ case 9:
3651
+ try {
3652
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3653
+ _iterator.return();
3654
+ }
3655
+ } finally{
3656
+ if (_didIteratorError) {
3657
+ throw _iteratorError;
3658
+ }
3659
+ }
3660
+ return [
3661
+ 7
3662
+ ];
3663
+ case 10:
3664
+ return [
3665
+ 2,
3666
+ {
3667
+ succeededCount: succeededCount,
3668
+ errors: errors
3669
+ }
3670
+ ];
3671
+ }
3672
+ });
3673
+ })();
3674
+ }
3675
+ function toErrorEntry(operation, index, error) {
3676
+ var _operation_call;
3677
+ return {
3678
+ index: index,
3679
+ modelType: operation.modelType,
3680
+ call: (_operation_call = operation.call) !== null && _operation_call !== void 0 ? _operation_call : undefined,
3681
+ specifier: operation.specifier,
3682
+ message: _instanceof(error, Error) ? error.message : String(error)
3683
+ };
3684
+ }
3685
+ function maybeDeleteUpload(input) {
3686
+ return _async_to_generator$3(function() {
3687
+ var deleted, file;
3688
+ return _ts_generator$3(this, function(_state) {
3689
+ switch(_state.label){
3690
+ case 0:
3691
+ deleted = false;
3692
+ if (!(input.input.deleteUploadOnSuccess && input.failureCount === 0)) return [
3693
+ 3,
3694
+ 2
3695
+ ];
3696
+ file = input.storageService.file(toStoragePathInput(input.input.uploadPath, input.input.bucketId));
3697
+ return [
3698
+ 4,
3699
+ file.delete()
3700
+ ];
3701
+ case 1:
3702
+ _state.sent();
3703
+ deleted = true;
3704
+ _state.label = 2;
3705
+ case 2:
3706
+ return [
3707
+ 2,
3708
+ deleted
3709
+ ];
3710
+ }
3711
+ });
3712
+ })();
3713
+ }
3714
+ /**
3715
+ * Builds a {@link StoragePathInput} from a path + optional bucket. Omits `bucketId` entirely when
3716
+ * absent (rather than passing `undefined`) so the accessor falls back to the app default bucket.
3717
+ *
3718
+ * @param pathString - The slash path of the file within the bucket.
3719
+ * @param bucketId - The bucket id, or `undefined` for the default bucket.
3720
+ * @returns The resolved storage path input.
3721
+ */ function toStoragePathInput(pathString, bucketId) {
3722
+ return bucketId != null ? {
3723
+ bucketId: bucketId,
3724
+ pathString: pathString
3725
+ } : {
3726
+ pathString: pathString
3727
+ };
3728
+ }
3729
+ // MARK: Schemas
3730
+ var BATCH_EXECUTE_INPUT_SCHEMA = {
3731
+ type: 'object',
3732
+ required: [
3733
+ 'uploadPath'
3734
+ ],
3735
+ properties: {
3736
+ uploadPath: {
3737
+ type: 'string',
3738
+ minLength: 1,
3739
+ description: 'Storage path of the uploaded operations file (JSON array or NDJSON).'
3740
+ },
3741
+ bucketId: {
3742
+ type: 'string',
3743
+ minLength: 1,
3744
+ description: 'Storage bucket id. Defaults to the app default bucket when omitted.'
3745
+ },
3746
+ format: {
3747
+ type: 'string',
3748
+ enum: [
3749
+ 'json',
3750
+ 'ndjson'
3751
+ ],
3752
+ description: 'File format. "ndjson" (default) = one operation per line; "json" = a top-level array.'
3753
+ },
3754
+ maxParallel: {
3755
+ type: 'integer',
3756
+ minimum: 1,
3757
+ description: "Operations dispatched concurrently. Defaults to ".concat(DEFAULT_BATCH_EXECUTE_MAX_PARALLEL, ". Ignored (forced to sequential) when stopOnError is true.")
3758
+ },
3759
+ stopOnError: {
3760
+ type: 'boolean',
3761
+ description: 'Halt at the first runtime failure (runs sequentially). Defaults to false (best-effort; all operations attempted).'
3762
+ },
3763
+ deleteUploadOnSuccess: {
3764
+ type: 'boolean',
3765
+ description: 'Delete the uploaded file when every operation succeeds. Defaults to true. The file is always kept when any operation fails.'
3766
+ }
3767
+ },
3768
+ additionalProperties: false
3769
+ };
3770
+ var BATCH_EXECUTE_OUTPUT_SCHEMA = {
3771
+ type: 'object',
3772
+ required: [
3773
+ 'total',
3774
+ 'successCount',
3775
+ 'failureCount',
3776
+ 'skippedCount',
3777
+ 'errors',
3778
+ 'uploadDeleted'
3779
+ ],
3780
+ properties: {
3781
+ total: {
3782
+ type: 'integer',
3783
+ description: 'Total operations in the file.'
3784
+ },
3785
+ successCount: {
3786
+ type: 'integer',
3787
+ description: 'Operations that succeeded.'
3788
+ },
3789
+ failureCount: {
3790
+ type: 'integer',
3791
+ description: 'Operations that failed at runtime.'
3792
+ },
3793
+ skippedCount: {
3794
+ type: 'integer',
3795
+ description: 'Operations not attempted (only non-zero when stopOnError halted the run early).'
3796
+ },
3797
+ errors: {
3798
+ type: 'array',
3799
+ description: 'Per-operation runtime failures, keyed by original file index.',
3800
+ items: {
3801
+ type: 'object',
3802
+ required: [
3803
+ 'index',
3804
+ 'modelType',
3805
+ 'message'
3806
+ ],
3807
+ properties: {
3808
+ index: {
3809
+ type: 'integer'
3810
+ },
3811
+ modelType: {
3812
+ type: 'string'
3813
+ },
3814
+ call: {
3815
+ type: 'string'
3816
+ },
3817
+ specifier: {
3818
+ type: 'string'
3819
+ },
3820
+ message: {
3821
+ type: 'string'
3822
+ }
3823
+ }
3824
+ }
3825
+ },
3826
+ uploadDeleted: {
3827
+ type: 'boolean',
3828
+ description: 'Whether the uploaded operations file was deleted after the run.'
3829
+ }
3830
+ }
3831
+ };
3832
+
3833
+ function _array_like_to_array$2(arr, len) {
3834
+ if (len == null || len > arr.length) len = arr.length;
3835
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
3836
+ return arr2;
3837
+ }
3838
+ function _array_with_holes(arr) {
3839
+ if (Array.isArray(arr)) return arr;
3840
+ }
3841
+ function _array_without_holes$2(arr) {
3842
+ if (Array.isArray(arr)) return _array_like_to_array$2(arr);
3843
+ }
3844
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
3845
+ try {
3846
+ var info = gen[key](arg);
3847
+ var value = info.value;
3848
+ } catch (error) {
3849
+ reject(error);
3850
+ return;
3851
+ }
3852
+ if (info.done) {
3853
+ resolve(value);
3854
+ } else {
3855
+ Promise.resolve(value).then(_next, _throw);
3856
+ }
3857
+ }
3858
+ function _async_to_generator$2(fn) {
3859
+ return function() {
3860
+ var self = this, args = arguments;
3861
+ return new Promise(function(resolve, reject) {
3862
+ var gen = fn.apply(self, args);
3863
+ function _next(value) {
3864
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
3865
+ }
3866
+ function _throw(err) {
3867
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
3868
+ }
3869
+ _next(undefined);
3870
+ });
3871
+ };
3872
+ }
3873
+ function _class_call_check$3(instance, Constructor) {
3874
+ if (!(instance instanceof Constructor)) {
3875
+ throw new TypeError("Cannot call a class as a function");
3876
+ }
3877
+ }
3878
+ function _defineProperties$3(target, props) {
3879
+ for(var i = 0; i < props.length; i++){
3880
+ var descriptor = props[i];
3881
+ descriptor.enumerable = descriptor.enumerable || false;
3882
+ descriptor.configurable = true;
3883
+ if ("value" in descriptor) descriptor.writable = true;
3884
+ Object.defineProperty(target, descriptor.key, descriptor);
3885
+ }
3886
+ }
3887
+ function _create_class$3(Constructor, protoProps, staticProps) {
3888
+ if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
3889
+ return Constructor;
3890
+ }
3891
+ function _define_property$3(obj, key, value) {
3892
+ if (key in obj) {
3893
+ Object.defineProperty(obj, key, {
3894
+ value: value,
3895
+ enumerable: true,
3896
+ configurable: true,
3897
+ writable: true
3898
+ });
3899
+ } else {
3900
+ obj[key] = value;
3901
+ }
3902
+ return obj;
3903
+ }
3904
+ function _iterable_to_array$2(iter) {
3905
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
3906
+ }
3907
+ function _iterable_to_array_limit(arr, i) {
3908
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
3909
+ if (_i == null) return;
3910
+ var _arr = [];
3911
+ var _n = true;
3912
+ var _d = false;
3913
+ var _s, _e;
3914
+ try {
3915
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
3916
+ _arr.push(_s.value);
3917
+ if (i && _arr.length === i) break;
3918
+ }
3919
+ } catch (err) {
3920
+ _d = true;
3921
+ _e = err;
3922
+ } finally{
3923
+ try {
3924
+ if (!_n && _i["return"] != null) _i["return"]();
3925
+ } finally{
3926
+ if (_d) throw _e;
3927
+ }
3928
+ }
3929
+ return _arr;
3930
+ }
3931
+ function _non_iterable_rest() {
3932
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3933
+ }
3934
+ function _non_iterable_spread$2() {
3935
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3936
+ }
3937
+ function _sliced_to_array(arr, i) {
3938
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest();
3939
+ }
3940
+ function _to_consumable_array$2(arr) {
3941
+ return _array_without_holes$2(arr) || _iterable_to_array$2(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread$2();
3942
+ }
3943
+ function _unsupported_iterable_to_array$2(o, minLen) {
3944
+ if (!o) return;
3945
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
3946
+ var n = Object.prototype.toString.call(o).slice(8, -1);
3947
+ if (n === "Object" && o.constructor) n = o.constructor.name;
3948
+ if (n === "Map" || n === "Set") return Array.from(n);
3949
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
3950
+ }
3951
+ function _ts_generator$2(thisArg, body) {
3952
+ var f, y, t, _ = {
3953
+ label: 0,
3954
+ sent: function() {
3955
+ if (t[0] & 1) throw t[1];
3956
+ return t[1];
3957
+ },
3958
+ trys: [],
3959
+ ops: []
3960
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
3961
+ return d(g, "next", {
3962
+ value: verb(0)
3963
+ }), d(g, "throw", {
3964
+ value: verb(1)
3965
+ }), d(g, "return", {
3966
+ value: verb(2)
3967
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
3968
+ value: function() {
3969
+ return this;
3970
+ }
3971
+ }), g;
3972
+ function verb(n) {
3973
+ return function(v) {
3974
+ return step([
3975
+ n,
3976
+ v
3977
+ ]);
3978
+ };
3979
+ }
3980
+ function step(op) {
3981
+ if (f) throw new TypeError("Generator is already executing.");
3982
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
3983
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
3984
+ if (y = 0, t) op = [
3985
+ op[0] & 2,
3986
+ t.value
3987
+ ];
3988
+ switch(op[0]){
3989
+ case 0:
3990
+ case 1:
3991
+ t = op;
3992
+ break;
3993
+ case 4:
3994
+ _.label++;
3995
+ return {
3996
+ value: op[1],
3997
+ done: false
3998
+ };
3999
+ case 5:
4000
+ _.label++;
4001
+ y = op[1];
4002
+ op = [
4003
+ 0
4004
+ ];
4005
+ continue;
4006
+ case 7:
4007
+ op = _.ops.pop();
4008
+ _.trys.pop();
4009
+ continue;
4010
+ default:
4011
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
4012
+ _ = 0;
4013
+ continue;
4014
+ }
4015
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
4016
+ _.label = op[1];
4017
+ break;
4018
+ }
4019
+ if (op[0] === 6 && _.label < t[1]) {
4020
+ _.label = t[1];
4021
+ t = op;
4022
+ break;
4023
+ }
4024
+ if (t && _.label < t[2]) {
4025
+ _.label = t[2];
4026
+ _.ops.push(op);
4027
+ break;
4028
+ }
4029
+ if (t[2]) _.ops.pop();
4030
+ _.trys.pop();
4031
+ continue;
4032
+ }
4033
+ op = body.call(thisArg, _);
4034
+ } catch (e) {
4035
+ op = [
4036
+ 6,
4037
+ e
4038
+ ];
4039
+ y = 0;
4040
+ } finally{
4041
+ f = t = 0;
4042
+ }
4043
+ if (op[0] & 5) throw op[1];
4044
+ return {
4045
+ value: op[0] ? op[1] : void 0,
4046
+ done: true
4047
+ };
4048
+ }
4049
+ }
4050
+ var McpServerFactoryService_1;
4051
+ /**
4052
+ * Injectable factory that builds {@link McpServer} instances pre-wired to the
4053
+ * call model dispatch chain.
4054
+ *
4055
+ * The factory is invoked per Streamable HTTP request — `@modelcontextprotocol/sdk`
4056
+ * recommends a fresh `McpServer` + transport pair per stateless JSON-RPC request,
4057
+ * which sidesteps session bookkeeping for the common Claude-connector case.
4058
+ */ exports.McpServerFactoryService = McpServerFactoryService_1 = /*#__PURE__*/ function() {
4059
+ function McpServerFactoryService(mcpConfig, dispatchService, modelApiGetService, roleReader, analyticsService, storageService) {
4060
+ _class_call_check$3(this, McpServerFactoryService);
4061
+ _define_property$3(this, "mcpConfig", void 0);
4062
+ _define_property$3(this, "dispatchService", void 0);
4063
+ _define_property$3(this, "modelApiGetService", void 0);
4064
+ _define_property$3(this, "roleReader", void 0);
4065
+ _define_property$3(this, "storageService", void 0);
4066
+ _define_property$3(this, "_logger", new common.Logger(McpServerFactoryService_1.name));
4067
+ _define_property$3(this, "_cachedTools", void 0);
4068
+ _define_property$3(this, "_cachedStaticTools", void 0);
4069
+ _define_property$3(this, "_cachedManifest", void 0);
4070
+ _define_property$3(this, "_cachedManifestModels", void 0);
4071
+ _define_property$3(this, "_cachedManifestAuth", void 0);
4072
+ _define_property$3(this, "_manifestLoaded", false);
4073
+ _define_property$3(this, "_loggedSkips", false);
4074
+ _define_property$3(this, "_warnedMissingRoleReader", false);
4075
+ _define_property$3(this, "_analyticsService", void 0);
4076
+ this.mcpConfig = mcpConfig;
4077
+ this.dispatchService = dispatchService;
4078
+ this.modelApiGetService = modelApiGetService;
4079
+ this.roleReader = roleReader;
4080
+ this.storageService = storageService;
4081
+ this._analyticsService = analyticsService !== null && analyticsService !== void 0 ? analyticsService : noopMcpAnalyticsService();
4082
+ }
4083
+ _create_class$3(McpServerFactoryService, [
4084
+ {
4085
+ /**
4086
+ * Builds a configured MCP server with tool listing + dispatch handlers wired up.
4087
+ *
4088
+ * @param ctx - The per-request context (auth, raw request) used when forwarding tool calls.
4089
+ * @returns A configured MCP server ready to be `connect()`-ed to a transport.
4090
+ */ key: "createServer",
4091
+ value: function createServer(ctx) {
4092
+ var _this = this;
4093
+ var _this_mcpConfig_serverName, _this_mcpConfig_serverVersion, _this_mcpConfig_serverInstructions;
4094
+ var baseServerName = (_this_mcpConfig_serverName = this.mcpConfig.serverName) !== null && _this_mcpConfig_serverName !== void 0 ? _this_mcpConfig_serverName : DEFAULT_MCP_SERVER_NAME;
4095
+ var serverName = this.mcpConfig.readOnly === true ? "".concat(baseServerName, " (read-only)") : baseServerName;
4096
+ var server = new mcp_js.McpServer({
4097
+ name: serverName,
4098
+ version: (_this_mcpConfig_serverVersion = this.mcpConfig.serverVersion) !== null && _this_mcpConfig_serverVersion !== void 0 ? _this_mcpConfig_serverVersion : '0.0.0'
4099
+ }, {
4100
+ instructions: (_this_mcpConfig_serverInstructions = this.mcpConfig.serverInstructions) !== null && _this_mcpConfig_serverInstructions !== void 0 ? _this_mcpConfig_serverInstructions : DEFAULT_MCP_SERVER_INSTRUCTIONS
4101
+ });
4102
+ server.server.registerCapabilities({
4103
+ tools: {}
4104
+ });
4105
+ var toolGeneration = this._resolveToolDefinitions();
4106
+ var staticTools = this._resolveStaticTools();
4107
+ var scopes = this._resolveScopes(ctx);
4108
+ var authRoles = this._resolveAuthRoles(ctx);
4109
+ var combinedTools = _to_consumable_array$2(toolGeneration.tools).concat(_to_consumable_array$2(staticTools));
4110
+ var visibleTools = this._filterToolsForRequest(combinedTools, {
4111
+ ctx: ctx,
4112
+ scopes: scopes,
4113
+ authRoles: authRoles
4114
+ });
4115
+ var definitionsByName = new Map(visibleTools.map(function(tool) {
4116
+ return [
4117
+ tool.name,
4118
+ tool
4119
+ ];
3261
4120
  }));
4121
+ // The batch tool is request-scoped: it authorizes each batched operation against this caller's
4122
+ // resolved visible tool set, so it can't be cached like the other static tools.
4123
+ var batchTool = this._resolveBatchTool(ctx, definitionsByName);
4124
+ var listedTools = visibleTools;
4125
+ if (batchTool != null) {
4126
+ definitionsByName.set(batchTool.name, batchTool);
4127
+ listedTools = _to_consumable_array$2(visibleTools).concat([
4128
+ batchTool
4129
+ ]);
4130
+ }
3262
4131
  server.server.setRequestHandler(types_js.ListToolsRequestSchema, function() {
3263
4132
  return _async_to_generator$2(function() {
3264
4133
  var _this;
@@ -3267,7 +4136,7 @@ var McpServerFactoryService_1;
3267
4136
  return [
3268
4137
  2,
3269
4138
  {
3270
- tools: visibleTools.map(function(tool) {
4139
+ tools: listedTools.map(function(tool) {
3271
4140
  return _this._buildToolListEntry(tool, ctx, scopes);
3272
4141
  })
3273
4142
  }
@@ -3528,6 +4397,92 @@ var McpServerFactoryService_1;
3528
4397
  },
3529
4398
  {
3530
4399
  /**
4400
+ * Builds the per-request `batch-execute` tool, or `undefined` when it should not be offered.
4401
+ *
4402
+ * Unlike the cached static tools this is rebuilt per request, because it closes over the caller's
4403
+ * resolved visible tool set: each batched operation is authorized against exactly the callModel
4404
+ * tools this caller may invoke directly. Offered only when a storage service is wired (it reads
4405
+ * the uploaded operations file), the caller is authenticated, and the server is not in read-only
4406
+ * mode (the tool performs writes).
4407
+ *
4408
+ * @param ctx - The per-request context (auth, raw request) forwarded to dispatched operations.
4409
+ * @param definitionsByName - The caller's visible tool definitions, keyed by name.
4410
+ * @returns The batch tool definition, or `undefined` when unavailable for this request.
4411
+ */ key: "_resolveBatchTool",
4412
+ value: function _resolveBatchTool(ctx, definitionsByName) {
4413
+ var _this = this;
4414
+ var result;
4415
+ var storageService = this.storageService;
4416
+ if (storageService != null && ctx.auth != null && this.mcpConfig.readOnly !== true) {
4417
+ var authorizedCoords = new Set();
4418
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4419
+ try {
4420
+ for(var _iterator = definitionsByName.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4421
+ var definition = _step.value;
4422
+ // Only callModel tools are re-dispatchable; static tools (model-get, whoami) have synthetic
4423
+ // dispatch identities the callModel chain can't resolve.
4424
+ if (definition.staticHandler == null) {
4425
+ authorizedCoords.add(batchOperationCoordKey(definition.dispatch));
4426
+ }
4427
+ }
4428
+ } catch (err) {
4429
+ _didIteratorError = true;
4430
+ _iteratorError = err;
4431
+ } finally{
4432
+ try {
4433
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
4434
+ _iterator.return();
4435
+ }
4436
+ } finally{
4437
+ if (_didIteratorError) {
4438
+ throw _iteratorError;
4439
+ }
4440
+ }
4441
+ }
4442
+ result = createBatchExecuteTool({
4443
+ storageService: storageService,
4444
+ dispatch: function dispatch(operation, auth, rawRequest) {
4445
+ return _this.dispatchService.dispatch(operation, auth, rawRequest);
4446
+ },
4447
+ authorizeOperation: function authorizeOperation(operation) {
4448
+ return _this._authorizeBatchOperation(operation, authorizedCoords);
4449
+ }
4450
+ });
4451
+ }
4452
+ return result;
4453
+ }
4454
+ },
4455
+ {
4456
+ /**
4457
+ * Authorizes a single batched operation against the caller's visible callModel tool coordinates.
4458
+ *
4459
+ * Re-applies the same gate the `tools/list` filter already enforced: an operation is allowed only
4460
+ * when its `(call, modelType, specifier)` coordinate matches a tool this caller can see. This is
4461
+ * the critical guard — `dispatchService.dispatch` bypasses the MCP visibility filter, so without
4462
+ * this check a batch could reach scope-, role-, or read-only-gated handlers.
4463
+ *
4464
+ * @param operation - The operation to authorize.
4465
+ * @param authorizedCoords - The set of dispatchable coordinate keys visible to this caller.
4466
+ * @returns Whether the operation may be dispatched, with a reason when it may not.
4467
+ */ key: "_authorizeBatchOperation",
4468
+ value: function _authorizeBatchOperation(operation, authorizedCoords) {
4469
+ var _operation_call, _operation_specifier, _operation_call1;
4470
+ var coordKey = batchOperationCoordKey({
4471
+ call: (_operation_call = operation.call) !== null && _operation_call !== void 0 ? _operation_call : '',
4472
+ modelType: operation.modelType,
4473
+ specifier: (_operation_specifier = operation.specifier) !== null && _operation_specifier !== void 0 ? _operation_specifier : undefined
4474
+ });
4475
+ var specifierSuffix = operation.specifier ? ' specifier="'.concat(operation.specifier, '"') : '';
4476
+ return authorizedCoords.has(coordKey) ? {
4477
+ allowed: true
4478
+ } : {
4479
+ allowed: false,
4480
+ reason: 'no visible tool matches call="'.concat((_operation_call1 = operation.call) !== null && _operation_call1 !== void 0 ? _operation_call1 : '', '" modelType="').concat(operation.modelType, '"').concat(specifierSuffix, " (unknown, or hidden by scope/role/read-only).")
4481
+ };
4482
+ }
4483
+ },
4484
+ {
4485
+ /**
3531
4486
  * Reads the pre-rendered MCP manifest JSON once, validates its version, and caches the
3532
4487
  * resulting `key → entry` map plus the optional `models` catalog for the process lifetime.
3533
4488
  *
@@ -4019,7 +4974,9 @@ exports.McpServerFactoryService = McpServerFactoryService_1 = __decorate([
4019
4974
  __param(3, common.Optional()),
4020
4975
  __param(3, common.Inject(MCP_AUTH_ROLE_READER)),
4021
4976
  __param(4, common.Optional()),
4022
- __param(4, common.Inject(MCP_ANALYTICS_SERVICE))
4977
+ __param(4, common.Inject(MCP_ANALYTICS_SERVICE)),
4978
+ __param(5, common.Optional()),
4979
+ __param(5, common.Inject(firebaseServer.FirebaseServerStorageService))
4023
4980
  ], exports.McpServerFactoryService);
4024
4981
 
4025
4982
  function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
@@ -4811,6 +5768,10 @@ function _unsupported_iterable_to_array(o, minLen) {
4811
5768
  };
4812
5769
  }
4813
5770
 
5771
+ exports.BATCH_EXECUTE_DISPATCH_CALL = BATCH_EXECUTE_DISPATCH_CALL;
5772
+ exports.BATCH_EXECUTE_DISPATCH_MODEL_TYPE = BATCH_EXECUTE_DISPATCH_MODEL_TYPE;
5773
+ exports.BATCH_EXECUTE_TOOL_NAME = BATCH_EXECUTE_TOOL_NAME;
5774
+ exports.DEFAULT_BATCH_EXECUTE_MAX_PARALLEL = DEFAULT_BATCH_EXECUTE_MAX_PARALLEL;
4814
5775
  exports.DEFAULT_JSON_SCHEMA_GENERATION_OPTIONS = DEFAULT_JSON_SCHEMA_GENERATION_OPTIONS;
4815
5776
  exports.DEFAULT_MCP_ANALYTICS_EVENT_NAME = DEFAULT_MCP_ANALYTICS_EVENT_NAME;
4816
5777
  exports.DEFAULT_MCP_PATH = DEFAULT_MCP_PATH;
@@ -4820,6 +5781,8 @@ exports.DEFAULT_SPECIFIER_KEY = DEFAULT_SPECIFIER_KEY;
4820
5781
  exports.DEFAULT_VOID_MCP_SUCCESS_VALUE = DEFAULT_VOID_MCP_SUCCESS_VALUE;
4821
5782
  exports.FIREBASE_SERVER_MCP_ANALYTICS_CONFIG = FIREBASE_SERVER_MCP_ANALYTICS_CONFIG;
4822
5783
  exports.FIREBASE_SERVER_MCP_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = FIREBASE_SERVER_MCP_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE;
5784
+ exports.MAX_BATCH_EXECUTE_FILE_BYTES = MAX_BATCH_EXECUTE_FILE_BYTES;
5785
+ exports.MAX_BATCH_EXECUTE_OPERATIONS = MAX_BATCH_EXECUTE_OPERATIONS;
4823
5786
  exports.MCP_ANALYTICS_SERVICE = MCP_ANALYTICS_SERVICE;
4824
5787
  exports.MCP_AUTH_ROLE_READER = MCP_AUTH_ROLE_READER;
4825
5788
  exports.MCP_CALL_TYPE_ABBREVIATIONS = MCP_CALL_TYPE_ABBREVIATIONS;
@@ -4842,11 +5805,13 @@ exports.McpAnalyticsService = McpAnalyticsService;
4842
5805
  exports.McpModuleConfig = McpModuleConfig;
4843
5806
  exports.abbreviateMcpCallType = abbreviateMcpCallType;
4844
5807
  exports.appMcpAnalyticsModuleMetadata = appMcpAnalyticsModuleMetadata;
5808
+ exports.batchOperationCoordKey = batchOperationCoordKey;
4845
5809
  exports.buildDefaultMcpToolDescription = buildDefaultMcpToolDescription;
4846
5810
  exports.buildDisambiguatedMcpToolName = buildDisambiguatedMcpToolName;
4847
5811
  exports.buildMcpToolName = buildMcpToolName;
4848
5812
  exports.buildStaticWireEntry = buildStaticWireEntry;
4849
5813
  exports.classifyVisibility = classifyVisibility;
5814
+ exports.createBatchExecuteTool = createBatchExecuteTool;
4850
5815
  exports.createModelDecodeTool = createModelDecodeTool;
4851
5816
  exports.createModelGetTool = createModelGetTool;
4852
5817
  exports.createModelInfoTool = createModelInfoTool;