@mcpc-tech/cli 0.1.50 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (11) hide show
  1. package/app.cjs +463 -267
  2. package/app.mjs +463 -267
  3. package/bin/mcpc.cjs +443 -265
  4. package/bin/mcpc.mjs +443 -265
  5. package/bin.cjs +443 -265
  6. package/bin.mjs +443 -265
  7. package/index.cjs +463 -267
  8. package/index.mjs +463 -267
  9. package/package.json +1 -1
  10. package/server.cjs +463 -267
  11. package/server.mjs +463 -267
package/bin/mcpc.cjs CHANGED
@@ -2378,7 +2378,7 @@ if (typeof global.crypto === "undefined") {
2378
2378
  var outgoingEnded = Symbol("outgoingEnded");
2379
2379
 
2380
2380
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
2381
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
2381
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
2382
2382
  var LETTER_REGEXP = /[A-Za-z]/;
2383
2383
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
2384
2384
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -2389,12 +2389,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
2389
2389
  function isNumber(string3) {
2390
2390
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
2391
2391
  }
2392
+ function isConstructorOrProto(obj, key) {
2393
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
2394
+ }
2392
2395
  function setNested(object5, keys, value, collect = false) {
2393
2396
  keys = [
2394
2397
  ...keys
2395
2398
  ];
2396
2399
  const key = keys.pop();
2397
- keys.forEach((key2) => object5 = object5[key2] ??= {});
2400
+ for (const k of keys) {
2401
+ if (isConstructorOrProto(object5, k)) return;
2402
+ object5 = object5[k] ??= {};
2403
+ }
2404
+ if (isConstructorOrProto(object5, key)) return;
2398
2405
  if (collect) {
2399
2406
  const v = object5[key];
2400
2407
  if (Array.isArray(v)) {
@@ -2525,7 +2532,7 @@ function parseArgs(args, options) {
2525
2532
  let key = groups.key;
2526
2533
  let value = groups.value;
2527
2534
  if (doubleDash2) {
2528
- if (value) {
2535
+ if (value != null) {
2529
2536
  if (booleanSet.has(key)) value = parseBooleanString(value);
2530
2537
  setArgument(key, value, arg, true);
2531
2538
  continue;
@@ -2563,6 +2570,10 @@ function parseArgs(args, options) {
2563
2570
  setArgument(letter, next, arg, true);
2564
2571
  continue;
2565
2572
  }
2573
+ if (next === "=") {
2574
+ setArgument(letter, "", arg, true);
2575
+ continue argsLoop;
2576
+ }
2566
2577
  if (LETTER_REGEXP.test(letter)) {
2567
2578
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
2568
2579
  if (groups2) {
@@ -3057,7 +3068,7 @@ Usage:
3057
3068
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
3058
3069
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
3059
3070
 
3060
- Note: For scripts/ and assets/, use appropriate tools directly.`;
3071
+ Note: For scripts/, use the bash tool with the script path to execute.`;
3061
3072
  }
3062
3073
  function createSkillsPlugin(options) {
3063
3074
  const { paths } = options;
@@ -3165,11 +3176,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
3165
3176
  try {
3166
3177
  const content = await (0, import_promises2.readFile)((0, import_node_path4.join)(meta.basePath, "SKILL.md"), "utf-8");
3167
3178
  const body = extractBody(content);
3179
+ const skillPathInfo = `
3180
+ ---
3181
+ Skill path: ${meta.basePath}
3182
+ `;
3168
3183
  return {
3169
3184
  content: [
3170
3185
  {
3171
3186
  type: "text",
3172
- text: body
3187
+ text: body + skillPathInfo
3173
3188
  }
3174
3189
  ]
3175
3190
  };
@@ -4040,12 +4055,29 @@ function writeFoldedLines(count) {
4040
4055
  if (count > 1) return "\n".repeat(count - 1);
4041
4056
  return "";
4042
4057
  }
4058
+ var Scanner = class {
4059
+ source;
4060
+ #length;
4061
+ position = 0;
4062
+ constructor(source) {
4063
+ source += "\0";
4064
+ this.source = source;
4065
+ this.#length = source.length;
4066
+ }
4067
+ peek(offset = 0) {
4068
+ return this.source.charCodeAt(this.position + offset);
4069
+ }
4070
+ next() {
4071
+ this.position += 1;
4072
+ }
4073
+ eof() {
4074
+ return this.position >= this.#length - 1;
4075
+ }
4076
+ };
4043
4077
  var LoaderState = class {
4044
- input;
4045
- length;
4078
+ #scanner;
4046
4079
  lineIndent = 0;
4047
4080
  lineStart = 0;
4048
- position = 0;
4049
4081
  line = 0;
4050
4082
  onWarning;
4051
4083
  allowDuplicateKeys;
@@ -4055,44 +4087,40 @@ var LoaderState = class {
4055
4087
  tagMap = /* @__PURE__ */ new Map();
4056
4088
  anchorMap = /* @__PURE__ */ new Map();
4057
4089
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
4058
- this.input = input;
4090
+ this.#scanner = new Scanner(input);
4059
4091
  this.onWarning = onWarning;
4060
4092
  this.allowDuplicateKeys = allowDuplicateKeys;
4061
4093
  this.implicitTypes = schema.implicitTypes;
4062
4094
  this.typeMap = schema.typeMap;
4063
- this.length = input.length;
4064
4095
  this.readIndent();
4065
4096
  }
4066
4097
  skipWhitespaces() {
4067
- let ch = this.peek();
4098
+ let ch = this.#scanner.peek();
4068
4099
  while (isWhiteSpace(ch)) {
4069
- ch = this.next();
4100
+ this.#scanner.next();
4101
+ ch = this.#scanner.peek();
4070
4102
  }
4071
4103
  }
4072
4104
  skipComment() {
4073
- let ch = this.peek();
4105
+ let ch = this.#scanner.peek();
4074
4106
  if (ch !== SHARP) return;
4075
- ch = this.next();
4107
+ this.#scanner.next();
4108
+ ch = this.#scanner.peek();
4076
4109
  while (ch !== 0 && !isEOL(ch)) {
4077
- ch = this.next();
4110
+ this.#scanner.next();
4111
+ ch = this.#scanner.peek();
4078
4112
  }
4079
4113
  }
4080
4114
  readIndent() {
4081
- let char = this.peek();
4082
- while (char === SPACE) {
4115
+ let ch = this.#scanner.peek();
4116
+ while (ch === SPACE) {
4083
4117
  this.lineIndent += 1;
4084
- char = this.next();
4118
+ this.#scanner.next();
4119
+ ch = this.#scanner.peek();
4085
4120
  }
4086
4121
  }
4087
- peek(offset = 0) {
4088
- return this.input.charCodeAt(this.position + offset);
4089
- }
4090
- next() {
4091
- this.position += 1;
4092
- return this.peek();
4093
- }
4094
4122
  #createError(message) {
4095
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
4123
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
4096
4124
  return new SyntaxError(`${message} ${mark}`);
4097
4125
  }
4098
4126
  dispatchWarning(message) {
@@ -4137,7 +4165,7 @@ var LoaderState = class {
4137
4165
  }
4138
4166
  captureSegment(start, end, checkJson) {
4139
4167
  if (start < end) {
4140
- const result = this.input.slice(start, end);
4168
+ const result = this.#scanner.source.slice(start, end);
4141
4169
  if (checkJson) {
4142
4170
  for (let position = 0; position < result.length; position++) {
4143
4171
  const character = result.charCodeAt(position);
@@ -4155,21 +4183,21 @@ var LoaderState = class {
4155
4183
  let detected = false;
4156
4184
  const result = [];
4157
4185
  if (anchor !== null) this.anchorMap.set(anchor, result);
4158
- let ch = this.peek();
4186
+ let ch = this.#scanner.peek();
4159
4187
  while (ch !== 0) {
4160
4188
  if (ch !== MINUS) {
4161
4189
  break;
4162
4190
  }
4163
- const following = this.peek(1);
4191
+ const following = this.#scanner.peek(1);
4164
4192
  if (!isWhiteSpaceOrEOL(following)) {
4165
4193
  break;
4166
4194
  }
4167
4195
  detected = true;
4168
- this.position++;
4196
+ this.#scanner.next();
4169
4197
  if (this.skipSeparationSpace(true, -1)) {
4170
4198
  if (this.lineIndent <= nodeIndent) {
4171
4199
  result.push(null);
4172
- ch = this.peek();
4200
+ ch = this.#scanner.peek();
4173
4201
  continue;
4174
4202
  }
4175
4203
  }
@@ -4182,7 +4210,7 @@ var LoaderState = class {
4182
4210
  });
4183
4211
  if (newState) result.push(newState.result);
4184
4212
  this.skipSeparationSpace(true, -1);
4185
- ch = this.peek();
4213
+ ch = this.#scanner.peek();
4186
4214
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
4187
4215
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
4188
4216
  } else if (this.lineIndent < nodeIndent) {
@@ -4238,7 +4266,7 @@ var LoaderState = class {
4238
4266
  } else {
4239
4267
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
4240
4268
  this.line = startLine || this.line;
4241
- this.position = startPos || this.position;
4269
+ this.#scanner.position = startPos || this.#scanner.position;
4242
4270
  throw this.#createError("Cannot store mapping pair: duplicated key");
4243
4271
  }
4244
4272
  Object.defineProperty(result, keyNode, {
@@ -4252,37 +4280,37 @@ var LoaderState = class {
4252
4280
  return result;
4253
4281
  }
4254
4282
  readLineBreak() {
4255
- const ch = this.peek();
4283
+ const ch = this.#scanner.peek();
4256
4284
  if (ch === LINE_FEED) {
4257
- this.position++;
4285
+ this.#scanner.next();
4258
4286
  } else if (ch === CARRIAGE_RETURN) {
4259
- this.position++;
4260
- if (this.peek() === LINE_FEED) {
4261
- this.position++;
4287
+ this.#scanner.next();
4288
+ if (this.#scanner.peek() === LINE_FEED) {
4289
+ this.#scanner.next();
4262
4290
  }
4263
4291
  } else {
4264
4292
  throw this.#createError("Cannot read line: line break not found");
4265
4293
  }
4266
4294
  this.line += 1;
4267
- this.lineStart = this.position;
4295
+ this.lineStart = this.#scanner.position;
4268
4296
  }
4269
4297
  skipSeparationSpace(allowComments, checkIndent) {
4270
4298
  let lineBreaks = 0;
4271
- let ch = this.peek();
4299
+ let ch = this.#scanner.peek();
4272
4300
  while (ch !== 0) {
4273
4301
  this.skipWhitespaces();
4274
- ch = this.peek();
4302
+ ch = this.#scanner.peek();
4275
4303
  if (allowComments) {
4276
4304
  this.skipComment();
4277
- ch = this.peek();
4305
+ ch = this.#scanner.peek();
4278
4306
  }
4279
4307
  if (isEOL(ch)) {
4280
4308
  this.readLineBreak();
4281
- ch = this.peek();
4309
+ ch = this.#scanner.peek();
4282
4310
  lineBreaks++;
4283
4311
  this.lineIndent = 0;
4284
4312
  this.readIndent();
4285
- ch = this.peek();
4313
+ ch = this.#scanner.peek();
4286
4314
  } else {
4287
4315
  break;
4288
4316
  }
@@ -4293,9 +4321,9 @@ var LoaderState = class {
4293
4321
  return lineBreaks;
4294
4322
  }
4295
4323
  testDocumentSeparator() {
4296
- let ch = this.peek();
4297
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
4298
- ch = this.peek(3);
4324
+ let ch = this.#scanner.peek();
4325
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
4326
+ ch = this.#scanner.peek(3);
4299
4327
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
4300
4328
  return true;
4301
4329
  }
@@ -4303,34 +4331,34 @@ var LoaderState = class {
4303
4331
  return false;
4304
4332
  }
4305
4333
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
4306
- let ch = this.peek();
4334
+ let ch = this.#scanner.peek();
4307
4335
  if (isWhiteSpaceOrEOL(ch) || isFlowIndicator(ch) || ch === SHARP || ch === AMPERSAND || ch === ASTERISK || ch === EXCLAMATION || ch === VERTICAL_LINE || ch === GREATER_THAN || ch === SINGLE_QUOTE || ch === DOUBLE_QUOTE || ch === PERCENT || ch === COMMERCIAL_AT || ch === GRAVE_ACCENT) {
4308
4336
  return;
4309
4337
  }
4310
4338
  let following;
4311
4339
  if (ch === QUESTION || ch === MINUS) {
4312
- following = this.peek(1);
4340
+ following = this.#scanner.peek(1);
4313
4341
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
4314
4342
  return;
4315
4343
  }
4316
4344
  }
4317
4345
  let result = "";
4318
- let captureEnd = this.position;
4319
- let captureStart = this.position;
4346
+ let captureEnd = this.#scanner.position;
4347
+ let captureStart = this.#scanner.position;
4320
4348
  let hasPendingContent = false;
4321
4349
  let line = 0;
4322
4350
  while (ch !== 0) {
4323
4351
  if (ch === COLON) {
4324
- following = this.peek(1);
4352
+ following = this.#scanner.peek(1);
4325
4353
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
4326
4354
  break;
4327
4355
  }
4328
4356
  } else if (ch === SHARP) {
4329
- const preceding = this.peek(-1);
4357
+ const preceding = this.#scanner.peek(-1);
4330
4358
  if (isWhiteSpaceOrEOL(preceding)) {
4331
4359
  break;
4332
4360
  }
4333
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
4361
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
4334
4362
  break;
4335
4363
  } else if (isEOL(ch)) {
4336
4364
  line = this.line;
@@ -4339,10 +4367,10 @@ var LoaderState = class {
4339
4367
  this.skipSeparationSpace(false, -1);
4340
4368
  if (this.lineIndent >= nodeIndent) {
4341
4369
  hasPendingContent = true;
4342
- ch = this.peek();
4370
+ ch = this.#scanner.peek();
4343
4371
  continue;
4344
4372
  } else {
4345
- this.position = captureEnd;
4373
+ this.#scanner.position = captureEnd;
4346
4374
  this.line = line;
4347
4375
  this.lineStart = lineStart;
4348
4376
  this.lineIndent = lineIndent;
@@ -4353,13 +4381,14 @@ var LoaderState = class {
4353
4381
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
4354
4382
  if (segment2) result += segment2;
4355
4383
  result += writeFoldedLines(this.line - line);
4356
- captureStart = captureEnd = this.position;
4384
+ captureStart = captureEnd = this.#scanner.position;
4357
4385
  hasPendingContent = false;
4358
4386
  }
4359
4387
  if (!isWhiteSpace(ch)) {
4360
- captureEnd = this.position + 1;
4388
+ captureEnd = this.#scanner.position + 1;
4361
4389
  }
4362
- ch = this.next();
4390
+ this.#scanner.next();
4391
+ ch = this.#scanner.peek();
4363
4392
  }
4364
4393
  const segment = this.captureSegment(captureStart, captureEnd, false);
4365
4394
  if (segment) result += segment;
@@ -4372,22 +4401,23 @@ var LoaderState = class {
4372
4401
  };
4373
4402
  }
4374
4403
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
4375
- let ch = this.peek();
4404
+ let ch = this.#scanner.peek();
4376
4405
  if (ch !== SINGLE_QUOTE) return;
4377
4406
  let result = "";
4378
- this.position++;
4379
- let captureStart = this.position;
4380
- let captureEnd = this.position;
4381
- ch = this.peek();
4407
+ this.#scanner.next();
4408
+ let captureStart = this.#scanner.position;
4409
+ let captureEnd = this.#scanner.position;
4410
+ ch = this.#scanner.peek();
4382
4411
  while (ch !== 0) {
4383
4412
  if (ch === SINGLE_QUOTE) {
4384
- const segment = this.captureSegment(captureStart, this.position, true);
4413
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4385
4414
  if (segment) result += segment;
4386
- ch = this.next();
4415
+ this.#scanner.next();
4416
+ ch = this.#scanner.peek();
4387
4417
  if (ch === SINGLE_QUOTE) {
4388
- captureStart = this.position;
4389
- this.position++;
4390
- captureEnd = this.position;
4418
+ captureStart = this.#scanner.position;
4419
+ this.#scanner.next();
4420
+ captureEnd = this.#scanner.position;
4391
4421
  } else {
4392
4422
  if (anchor !== null) this.anchorMap.set(anchor, result);
4393
4423
  return {
@@ -4401,31 +4431,31 @@ var LoaderState = class {
4401
4431
  const segment = this.captureSegment(captureStart, captureEnd, true);
4402
4432
  if (segment) result += segment;
4403
4433
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
4404
- captureStart = captureEnd = this.position;
4405
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
4434
+ captureStart = captureEnd = this.#scanner.position;
4435
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
4406
4436
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
4407
4437
  } else {
4408
- this.position++;
4409
- captureEnd = this.position;
4438
+ this.#scanner.next();
4439
+ captureEnd = this.#scanner.position;
4410
4440
  }
4411
- ch = this.peek();
4441
+ ch = this.#scanner.peek();
4412
4442
  }
4413
4443
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
4414
4444
  }
4415
4445
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
4416
- let ch = this.peek();
4446
+ let ch = this.#scanner.peek();
4417
4447
  if (ch !== DOUBLE_QUOTE) return;
4418
4448
  let result = "";
4419
- this.position++;
4420
- let captureEnd = this.position;
4421
- let captureStart = this.position;
4449
+ this.#scanner.next();
4450
+ let captureEnd = this.#scanner.position;
4451
+ let captureStart = this.#scanner.position;
4422
4452
  let tmp;
4423
- ch = this.peek();
4453
+ ch = this.#scanner.peek();
4424
4454
  while (ch !== 0) {
4425
4455
  if (ch === DOUBLE_QUOTE) {
4426
- const segment = this.captureSegment(captureStart, this.position, true);
4456
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4427
4457
  if (segment) result += segment;
4428
- this.position++;
4458
+ this.#scanner.next();
4429
4459
  if (anchor !== null) this.anchorMap.set(anchor, result);
4430
4460
  return {
4431
4461
  tag,
@@ -4435,19 +4465,21 @@ var LoaderState = class {
4435
4465
  };
4436
4466
  }
4437
4467
  if (ch === BACKSLASH) {
4438
- const segment = this.captureSegment(captureStart, this.position, true);
4468
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4439
4469
  if (segment) result += segment;
4440
- ch = this.next();
4470
+ this.#scanner.next();
4471
+ ch = this.#scanner.peek();
4441
4472
  if (isEOL(ch)) {
4442
4473
  this.skipSeparationSpace(false, nodeIndent);
4443
4474
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
4444
4475
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
4445
- this.position++;
4476
+ this.#scanner.next();
4446
4477
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
4447
4478
  let hexLength = tmp;
4448
4479
  let hexResult = 0;
4449
4480
  for (; hexLength > 0; hexLength--) {
4450
- ch = this.next();
4481
+ this.#scanner.next();
4482
+ ch = this.#scanner.peek();
4451
4483
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
4452
4484
  hexResult = (hexResult << 4) + tmp;
4453
4485
  } else {
@@ -4455,28 +4487,28 @@ var LoaderState = class {
4455
4487
  }
4456
4488
  }
4457
4489
  result += codepointToChar(hexResult);
4458
- this.position++;
4490
+ this.#scanner.next();
4459
4491
  } else {
4460
4492
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
4461
4493
  }
4462
- captureStart = captureEnd = this.position;
4494
+ captureStart = captureEnd = this.#scanner.position;
4463
4495
  } else if (isEOL(ch)) {
4464
4496
  const segment = this.captureSegment(captureStart, captureEnd, true);
4465
4497
  if (segment) result += segment;
4466
4498
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
4467
- captureStart = captureEnd = this.position;
4468
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
4499
+ captureStart = captureEnd = this.#scanner.position;
4500
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
4469
4501
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
4470
4502
  } else {
4471
- this.position++;
4472
- captureEnd = this.position;
4503
+ this.#scanner.next();
4504
+ captureEnd = this.#scanner.position;
4473
4505
  }
4474
- ch = this.peek();
4506
+ ch = this.#scanner.peek();
4475
4507
  }
4476
4508
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
4477
4509
  }
4478
4510
  readFlowCollection(tag, anchor, nodeIndent) {
4479
- let ch = this.peek();
4511
+ let ch = this.#scanner.peek();
4480
4512
  let terminator;
4481
4513
  let isMapping = true;
4482
4514
  let result = {};
@@ -4490,7 +4522,8 @@ var LoaderState = class {
4490
4522
  return;
4491
4523
  }
4492
4524
  if (anchor !== null) this.anchorMap.set(anchor, result);
4493
- ch = this.next();
4525
+ this.#scanner.next();
4526
+ ch = this.#scanner.peek();
4494
4527
  let readNext = true;
4495
4528
  let valueNode = null;
4496
4529
  let keyNode = null;
@@ -4502,9 +4535,9 @@ var LoaderState = class {
4502
4535
  const overridableKeys = /* @__PURE__ */ new Set();
4503
4536
  while (ch !== 0) {
4504
4537
  this.skipSeparationSpace(true, nodeIndent);
4505
- ch = this.peek();
4538
+ ch = this.#scanner.peek();
4506
4539
  if (ch === terminator) {
4507
- this.position++;
4540
+ this.#scanner.next();
4508
4541
  const kind = isMapping ? "mapping" : "sequence";
4509
4542
  return {
4510
4543
  tag,
@@ -4519,10 +4552,10 @@ var LoaderState = class {
4519
4552
  keyTag = keyNode = valueNode = null;
4520
4553
  isPair = isExplicitPair = false;
4521
4554
  if (ch === QUESTION) {
4522
- following = this.peek(1);
4555
+ following = this.#scanner.peek(1);
4523
4556
  if (isWhiteSpaceOrEOL(following)) {
4524
4557
  isPair = isExplicitPair = true;
4525
- this.position++;
4558
+ this.#scanner.next();
4526
4559
  this.skipSeparationSpace(true, nodeIndent);
4527
4560
  }
4528
4561
  }
@@ -4538,10 +4571,11 @@ var LoaderState = class {
4538
4571
  keyNode = newState.result;
4539
4572
  }
4540
4573
  this.skipSeparationSpace(true, nodeIndent);
4541
- ch = this.peek();
4574
+ ch = this.#scanner.peek();
4542
4575
  if ((isExplicitPair || this.line === line) && ch === COLON) {
4543
4576
  isPair = true;
4544
- ch = this.next();
4577
+ this.#scanner.next();
4578
+ ch = this.#scanner.peek();
4545
4579
  this.skipSeparationSpace(true, nodeIndent);
4546
4580
  const newState2 = this.composeNode({
4547
4581
  parentIndent: nodeIndent,
@@ -4559,10 +4593,11 @@ var LoaderState = class {
4559
4593
  result.push(keyNode);
4560
4594
  }
4561
4595
  this.skipSeparationSpace(true, nodeIndent);
4562
- ch = this.peek();
4596
+ ch = this.#scanner.peek();
4563
4597
  if (ch === COMMA) {
4564
4598
  readNext = true;
4565
- ch = this.next();
4599
+ this.#scanner.next();
4600
+ ch = this.#scanner.peek();
4566
4601
  } else {
4567
4602
  readNext = false;
4568
4603
  }
@@ -4578,7 +4613,7 @@ var LoaderState = class {
4578
4613
  let textIndent = nodeIndent;
4579
4614
  let emptyLines = 0;
4580
4615
  let atMoreIndented = false;
4581
- let ch = this.peek();
4616
+ let ch = this.#scanner.peek();
4582
4617
  let folding = false;
4583
4618
  if (ch === VERTICAL_LINE) {
4584
4619
  folding = false;
@@ -4590,7 +4625,8 @@ var LoaderState = class {
4590
4625
  let result = "";
4591
4626
  let tmp = 0;
4592
4627
  while (ch !== 0) {
4593
- ch = this.next();
4628
+ this.#scanner.next();
4629
+ ch = this.#scanner.peek();
4594
4630
  if (ch === PLUS || ch === MINUS) {
4595
4631
  if (CHOMPING_CLIP === chomping) {
4596
4632
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -4613,15 +4649,16 @@ var LoaderState = class {
4613
4649
  if (isWhiteSpace(ch)) {
4614
4650
  this.skipWhitespaces();
4615
4651
  this.skipComment();
4616
- ch = this.peek();
4652
+ ch = this.#scanner.peek();
4617
4653
  }
4618
4654
  while (ch !== 0) {
4619
4655
  this.readLineBreak();
4620
4656
  this.lineIndent = 0;
4621
- ch = this.peek();
4657
+ ch = this.#scanner.peek();
4622
4658
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
4623
4659
  this.lineIndent++;
4624
- ch = this.next();
4660
+ this.#scanner.next();
4661
+ ch = this.#scanner.peek();
4625
4662
  }
4626
4663
  if (!detectedIndent && this.lineIndent > textIndent) {
4627
4664
  textIndent = this.lineIndent;
@@ -4660,11 +4697,12 @@ var LoaderState = class {
4660
4697
  didReadContent = true;
4661
4698
  detectedIndent = true;
4662
4699
  emptyLines = 0;
4663
- const captureStart = this.position;
4700
+ const captureStart = this.#scanner.position;
4664
4701
  while (!isEOL(ch) && ch !== 0) {
4665
- ch = this.next();
4702
+ this.#scanner.next();
4703
+ ch = this.#scanner.peek();
4666
4704
  }
4667
- const segment = this.captureSegment(captureStart, this.position, false);
4705
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
4668
4706
  if (segment) result += segment;
4669
4707
  }
4670
4708
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -4687,11 +4725,11 @@ var LoaderState = class {
4687
4725
  let atExplicitKey = false;
4688
4726
  let detected = false;
4689
4727
  if (anchor !== null) this.anchorMap.set(anchor, result);
4690
- let ch = this.peek();
4728
+ let ch = this.#scanner.peek();
4691
4729
  while (ch !== 0) {
4692
- const following = this.peek(1);
4730
+ const following = this.#scanner.peek(1);
4693
4731
  line = this.line;
4694
- pos = this.position;
4732
+ pos = this.#scanner.position;
4695
4733
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
4696
4734
  if (ch === QUESTION) {
4697
4735
  if (atExplicitKey) {
@@ -4709,7 +4747,7 @@ var LoaderState = class {
4709
4747
  } else {
4710
4748
  throw this.#createError("Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line");
4711
4749
  }
4712
- this.position += 1;
4750
+ this.#scanner.next();
4713
4751
  ch = following;
4714
4752
  } else {
4715
4753
  const newState = this.composeNode({
@@ -4720,11 +4758,12 @@ var LoaderState = class {
4720
4758
  });
4721
4759
  if (!newState) break;
4722
4760
  if (this.line === line) {
4723
- ch = this.peek();
4761
+ ch = this.#scanner.peek();
4724
4762
  this.skipWhitespaces();
4725
- ch = this.peek();
4763
+ ch = this.#scanner.peek();
4726
4764
  if (ch === COLON) {
4727
- ch = this.next();
4765
+ this.#scanner.next();
4766
+ ch = this.#scanner.peek();
4728
4767
  if (!isWhiteSpaceOrEOL(ch)) {
4729
4768
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
4730
4769
  }
@@ -4781,7 +4820,7 @@ var LoaderState = class {
4781
4820
  keyTag = keyNode = valueNode = null;
4782
4821
  }
4783
4822
  this.skipSeparationSpace(true, -1);
4784
- ch = this.peek();
4823
+ ch = this.#scanner.peek();
4785
4824
  }
4786
4825
  if (this.lineIndent > nodeIndent && ch !== 0) {
4787
4826
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -4804,30 +4843,35 @@ var LoaderState = class {
4804
4843
  let isNamed = false;
4805
4844
  let tagHandle = "";
4806
4845
  let tagName;
4807
- let ch = this.peek();
4846
+ let ch = this.#scanner.peek();
4808
4847
  if (ch !== EXCLAMATION) return;
4809
4848
  if (tag !== null) {
4810
4849
  throw this.#createError("Cannot read tag property: duplication of a tag property");
4811
4850
  }
4812
- ch = this.next();
4851
+ this.#scanner.next();
4852
+ ch = this.#scanner.peek();
4813
4853
  if (ch === SMALLER_THAN) {
4814
4854
  isVerbatim = true;
4815
- ch = this.next();
4855
+ this.#scanner.next();
4856
+ ch = this.#scanner.peek();
4816
4857
  } else if (ch === EXCLAMATION) {
4817
4858
  isNamed = true;
4818
4859
  tagHandle = "!!";
4819
- ch = this.next();
4860
+ this.#scanner.next();
4861
+ ch = this.#scanner.peek();
4820
4862
  } else {
4821
4863
  tagHandle = "!";
4822
4864
  }
4823
- let position = this.position;
4865
+ let position = this.#scanner.position;
4824
4866
  if (isVerbatim) {
4825
4867
  do {
4826
- ch = this.next();
4868
+ this.#scanner.next();
4869
+ ch = this.#scanner.peek();
4827
4870
  } while (ch !== 0 && ch !== GREATER_THAN);
4828
- if (this.position < this.length) {
4829
- tagName = this.input.slice(position, this.position);
4830
- ch = this.next();
4871
+ if (!this.#scanner.eof()) {
4872
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
4873
+ this.#scanner.next();
4874
+ ch = this.#scanner.peek();
4831
4875
  } else {
4832
4876
  throw this.#createError("Cannot read tag property: unexpected end of stream");
4833
4877
  }
@@ -4835,19 +4879,20 @@ var LoaderState = class {
4835
4879
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
4836
4880
  if (ch === EXCLAMATION) {
4837
4881
  if (!isNamed) {
4838
- tagHandle = this.input.slice(position - 1, this.position + 1);
4882
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
4839
4883
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
4840
4884
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
4841
4885
  }
4842
4886
  isNamed = true;
4843
- position = this.position + 1;
4887
+ position = this.#scanner.position + 1;
4844
4888
  } else {
4845
4889
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
4846
4890
  }
4847
4891
  }
4848
- ch = this.next();
4892
+ this.#scanner.next();
4893
+ ch = this.#scanner.peek();
4849
4894
  }
4850
- tagName = this.input.slice(position, this.position);
4895
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
4851
4896
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
4852
4897
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
4853
4898
  }
@@ -4867,32 +4912,36 @@ var LoaderState = class {
4867
4912
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
4868
4913
  }
4869
4914
  readAnchorProperty(anchor) {
4870
- let ch = this.peek();
4915
+ let ch = this.#scanner.peek();
4871
4916
  if (ch !== AMPERSAND) return;
4872
4917
  if (anchor !== null) {
4873
4918
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
4874
4919
  }
4875
- ch = this.next();
4876
- const position = this.position;
4920
+ this.#scanner.next();
4921
+ ch = this.#scanner.peek();
4922
+ const position = this.#scanner.position;
4877
4923
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
4878
- ch = this.next();
4924
+ this.#scanner.next();
4925
+ ch = this.#scanner.peek();
4879
4926
  }
4880
- if (this.position === position) {
4927
+ if (this.#scanner.position === position) {
4881
4928
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
4882
4929
  }
4883
- return this.input.slice(position, this.position);
4930
+ return this.#scanner.source.slice(position, this.#scanner.position);
4884
4931
  }
4885
4932
  readAlias() {
4886
- if (this.peek() !== ASTERISK) return;
4887
- let ch = this.next();
4888
- const position = this.position;
4933
+ if (this.#scanner.peek() !== ASTERISK) return;
4934
+ this.#scanner.next();
4935
+ let ch = this.#scanner.peek();
4936
+ const position = this.#scanner.position;
4889
4937
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
4890
- ch = this.next();
4938
+ this.#scanner.next();
4939
+ ch = this.#scanner.peek();
4891
4940
  }
4892
- if (this.position === position) {
4941
+ if (this.#scanner.position === position) {
4893
4942
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
4894
4943
  }
4895
- const alias = this.input.slice(position, this.position);
4944
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
4896
4945
  if (!this.anchorMap.has(alias)) {
4897
4946
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
4898
4947
  }
@@ -4975,7 +5024,7 @@ var LoaderState = class {
4975
5024
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
4976
5025
  const flowIndent = cond ? parentIndent : parentIndent + 1;
4977
5026
  if (allowBlockCollections) {
4978
- const blockIndent = this.position - this.lineStart;
5027
+ const blockIndent = this.#scanner.position - this.lineStart;
4979
5028
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
4980
5029
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
4981
5030
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -5009,7 +5058,7 @@ var LoaderState = class {
5009
5058
  return this.resolveTag(plainScalarState);
5010
5059
  }
5011
5060
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
5012
- const blockIndent = this.position - this.lineStart;
5061
+ const blockIndent = this.#scanner.position - this.lineStart;
5013
5062
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
5014
5063
  if (newState2) return this.resolveTag(newState2);
5015
5064
  }
@@ -5024,20 +5073,22 @@ var LoaderState = class {
5024
5073
  readDirectives() {
5025
5074
  let hasDirectives = false;
5026
5075
  let version = null;
5027
- let ch = this.peek();
5076
+ let ch = this.#scanner.peek();
5028
5077
  while (ch !== 0) {
5029
5078
  this.skipSeparationSpace(true, -1);
5030
- ch = this.peek();
5079
+ ch = this.#scanner.peek();
5031
5080
  if (this.lineIndent > 0 || ch !== PERCENT) {
5032
5081
  break;
5033
5082
  }
5034
5083
  hasDirectives = true;
5035
- ch = this.next();
5036
- let position = this.position;
5084
+ this.#scanner.next();
5085
+ ch = this.#scanner.peek();
5086
+ let position = this.#scanner.position;
5037
5087
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
5038
- ch = this.next();
5088
+ this.#scanner.next();
5089
+ ch = this.#scanner.peek();
5039
5090
  }
5040
- const directiveName = this.input.slice(position, this.position);
5091
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
5041
5092
  const directiveArgs = [];
5042
5093
  if (directiveName.length < 1) {
5043
5094
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -5045,13 +5096,14 @@ var LoaderState = class {
5045
5096
  while (ch !== 0) {
5046
5097
  this.skipWhitespaces();
5047
5098
  this.skipComment();
5048
- ch = this.peek();
5099
+ ch = this.#scanner.peek();
5049
5100
  if (isEOL(ch)) break;
5050
- position = this.position;
5101
+ position = this.#scanner.position;
5051
5102
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
5052
- ch = this.next();
5103
+ this.#scanner.next();
5104
+ ch = this.#scanner.peek();
5053
5105
  }
5054
- directiveArgs.push(this.input.slice(position, this.position));
5106
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
5055
5107
  }
5056
5108
  if (ch !== 0) this.readLineBreak();
5057
5109
  switch (directiveName) {
@@ -5068,20 +5120,20 @@ var LoaderState = class {
5068
5120
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
5069
5121
  break;
5070
5122
  }
5071
- ch = this.peek();
5123
+ ch = this.#scanner.peek();
5072
5124
  }
5073
5125
  return hasDirectives;
5074
5126
  }
5075
5127
  readDocument() {
5076
- const documentStart = this.position;
5128
+ const documentStart = this.#scanner.position;
5077
5129
  this.checkLineBreaks = false;
5078
5130
  this.tagMap = /* @__PURE__ */ new Map();
5079
5131
  this.anchorMap = /* @__PURE__ */ new Map();
5080
5132
  const hasDirectives = this.readDirectives();
5081
5133
  this.skipSeparationSpace(true, -1);
5082
5134
  let result = null;
5083
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
5084
- this.position += 3;
5135
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
5136
+ this.#scanner.position += 3;
5085
5137
  this.skipSeparationSpace(true, -1);
5086
5138
  } else if (hasDirectives) {
5087
5139
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -5094,21 +5146,21 @@ var LoaderState = class {
5094
5146
  });
5095
5147
  if (newState) result = newState.result;
5096
5148
  this.skipSeparationSpace(true, -1);
5097
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
5149
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
5098
5150
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
5099
5151
  }
5100
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
5101
- if (this.peek() === DOT) {
5102
- this.position += 3;
5152
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5153
+ if (this.#scanner.peek() === DOT) {
5154
+ this.#scanner.position += 3;
5103
5155
  this.skipSeparationSpace(true, -1);
5104
5156
  }
5105
- } else if (this.position < this.length - 1) {
5157
+ } else if (!this.#scanner.eof()) {
5106
5158
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
5107
5159
  }
5108
5160
  return result;
5109
5161
  }
5110
5162
  *readDocuments() {
5111
- while (this.position < this.length - 1) {
5163
+ while (!this.#scanner.eof()) {
5112
5164
  yield this.readDocument();
5113
5165
  }
5114
5166
  }
@@ -5121,7 +5173,6 @@ function sanitizeInput(input) {
5121
5173
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
5122
5174
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
5123
5175
  }
5124
- input += "\0";
5125
5176
  return input;
5126
5177
  }
5127
5178
  function parse(content, options = {}) {
@@ -5281,7 +5332,7 @@ function getDefaultAgents() {
5281
5332
  }
5282
5333
 
5283
5334
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
5284
- var CLI_VERSION = "0.1.44";
5335
+ var CLI_VERSION = "0.1.51";
5285
5336
  function extractServerName(command, commandArgs) {
5286
5337
  for (const arg of commandArgs) {
5287
5338
  if (!arg.startsWith("-")) {
@@ -6890,6 +6941,147 @@ var ExperimentalServerTasks = class {
6890
6941
  requestStream(request, resultSchema, options) {
6891
6942
  return this._server.requestStream(request, resultSchema, options);
6892
6943
  }
6944
+ /**
6945
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
6946
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
6947
+ *
6948
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
6949
+ * before the final result.
6950
+ *
6951
+ * @example
6952
+ * ```typescript
6953
+ * const stream = server.experimental.tasks.createMessageStream({
6954
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
6955
+ * maxTokens: 100
6956
+ * }, {
6957
+ * onprogress: (progress) => {
6958
+ * // Handle streaming tokens via progress notifications
6959
+ * console.log('Progress:', progress.message);
6960
+ * }
6961
+ * });
6962
+ *
6963
+ * for await (const message of stream) {
6964
+ * switch (message.type) {
6965
+ * case 'taskCreated':
6966
+ * console.log('Task created:', message.task.taskId);
6967
+ * break;
6968
+ * case 'taskStatus':
6969
+ * console.log('Task status:', message.task.status);
6970
+ * break;
6971
+ * case 'result':
6972
+ * console.log('Final result:', message.result);
6973
+ * break;
6974
+ * case 'error':
6975
+ * console.error('Error:', message.error);
6976
+ * break;
6977
+ * }
6978
+ * }
6979
+ * ```
6980
+ *
6981
+ * @param params - The sampling request parameters
6982
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
6983
+ * @returns AsyncGenerator that yields ResponseMessage objects
6984
+ *
6985
+ * @experimental
6986
+ */
6987
+ createMessageStream(params, options) {
6988
+ const clientCapabilities = this._server.getClientCapabilities();
6989
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
6990
+ throw new Error("Client does not support sampling tools capability.");
6991
+ }
6992
+ if (params.messages.length > 0) {
6993
+ const lastMessage = params.messages[params.messages.length - 1];
6994
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
6995
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
6996
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
6997
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
6998
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
6999
+ if (hasToolResults) {
7000
+ if (lastContent.some((c) => c.type !== "tool_result")) {
7001
+ throw new Error("The last message must contain only tool_result content if any is present");
7002
+ }
7003
+ if (!hasPreviousToolUse) {
7004
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
7005
+ }
7006
+ }
7007
+ if (hasPreviousToolUse) {
7008
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
7009
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
7010
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
7011
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
7012
+ }
7013
+ }
7014
+ }
7015
+ return this.requestStream({
7016
+ method: "sampling/createMessage",
7017
+ params
7018
+ }, CreateMessageResultSchema, options);
7019
+ }
7020
+ /**
7021
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
7022
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
7023
+ *
7024
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
7025
+ * and 'taskStatus' messages before the final result.
7026
+ *
7027
+ * @example
7028
+ * ```typescript
7029
+ * const stream = server.experimental.tasks.elicitInputStream({
7030
+ * mode: 'url',
7031
+ * message: 'Please authenticate',
7032
+ * elicitationId: 'auth-123',
7033
+ * url: 'https://example.com/auth'
7034
+ * }, {
7035
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
7036
+ * });
7037
+ *
7038
+ * for await (const message of stream) {
7039
+ * switch (message.type) {
7040
+ * case 'taskCreated':
7041
+ * console.log('Task created:', message.task.taskId);
7042
+ * break;
7043
+ * case 'taskStatus':
7044
+ * console.log('Task status:', message.task.status);
7045
+ * break;
7046
+ * case 'result':
7047
+ * console.log('User action:', message.result.action);
7048
+ * break;
7049
+ * case 'error':
7050
+ * console.error('Error:', message.error);
7051
+ * break;
7052
+ * }
7053
+ * }
7054
+ * ```
7055
+ *
7056
+ * @param params - The elicitation request parameters
7057
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
7058
+ * @returns AsyncGenerator that yields ResponseMessage objects
7059
+ *
7060
+ * @experimental
7061
+ */
7062
+ elicitInputStream(params, options) {
7063
+ const clientCapabilities = this._server.getClientCapabilities();
7064
+ const mode = params.mode ?? "form";
7065
+ switch (mode) {
7066
+ case "url": {
7067
+ if (!clientCapabilities?.elicitation?.url) {
7068
+ throw new Error("Client does not support url elicitation.");
7069
+ }
7070
+ break;
7071
+ }
7072
+ case "form": {
7073
+ if (!clientCapabilities?.elicitation?.form) {
7074
+ throw new Error("Client does not support form elicitation.");
7075
+ }
7076
+ break;
7077
+ }
7078
+ }
7079
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
7080
+ return this.requestStream({
7081
+ method: "elicitation/create",
7082
+ params: normalizedParams
7083
+ }, ElicitResultSchema, options);
7084
+ }
6893
7085
  /**
6894
7086
  * Gets the current status of a task.
6895
7087
  *
@@ -9078,22 +9270,45 @@ async function auth(provider, options) {
9078
9270
  }
9079
9271
  }
9080
9272
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
9273
+ const cachedState = await provider.discoveryState?.();
9081
9274
  let resourceMetadata;
9082
9275
  let authorizationServerUrl;
9083
- try {
9084
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
9085
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
9086
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
9276
+ let metadata;
9277
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
9278
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
9279
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
9280
+ }
9281
+ if (cachedState?.authorizationServerUrl) {
9282
+ authorizationServerUrl = cachedState.authorizationServerUrl;
9283
+ resourceMetadata = cachedState.resourceMetadata;
9284
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
9285
+ if (!resourceMetadata) {
9286
+ try {
9287
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
9288
+ } catch {
9289
+ }
9087
9290
  }
9088
- } catch {
9089
- }
9090
- if (!authorizationServerUrl) {
9091
- authorizationServerUrl = new URL("/", serverUrl);
9291
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
9292
+ await provider.saveDiscoveryState?.({
9293
+ authorizationServerUrl: String(authorizationServerUrl),
9294
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
9295
+ resourceMetadata,
9296
+ authorizationServerMetadata: metadata
9297
+ });
9298
+ }
9299
+ } else {
9300
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
9301
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
9302
+ metadata = serverInfo.authorizationServerMetadata;
9303
+ resourceMetadata = serverInfo.resourceMetadata;
9304
+ await provider.saveDiscoveryState?.({
9305
+ authorizationServerUrl: String(authorizationServerUrl),
9306
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
9307
+ resourceMetadata,
9308
+ authorizationServerMetadata: metadata
9309
+ });
9092
9310
  }
9093
9311
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
9094
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
9095
- fetchFn
9096
- });
9097
9312
  let clientInformation = await Promise.resolve(provider.clientInformation());
9098
9313
  if (!clientInformation) {
9099
9314
  if (authorizationCode !== void 0) {
@@ -9348,6 +9563,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
9348
9563
  }
9349
9564
  return void 0;
9350
9565
  }
9566
+ async function discoverOAuthServerInfo(serverUrl, opts) {
9567
+ let resourceMetadata;
9568
+ let authorizationServerUrl;
9569
+ try {
9570
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
9571
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
9572
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
9573
+ }
9574
+ } catch {
9575
+ }
9576
+ if (!authorizationServerUrl) {
9577
+ authorizationServerUrl = String(new URL("/", serverUrl));
9578
+ }
9579
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
9580
+ return {
9581
+ authorizationServerUrl,
9582
+ authorizationServerMetadata,
9583
+ resourceMetadata
9584
+ };
9585
+ }
9351
9586
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
9352
9587
  let authorizationUrl;
9353
9588
  if (metadata) {
@@ -10212,18 +10447,6 @@ var cleanToolSchema = (schema) => {
10212
10447
  var import_node_process7 = require("node:process");
10213
10448
  var import_node_process8 = __toESM(require("node:process"), 1);
10214
10449
  var import_node_crypto = require("node:crypto");
10215
- var mcpClientPool = /* @__PURE__ */ new Map();
10216
- var mcpClientConnecting = /* @__PURE__ */ new Map();
10217
- var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
10218
- function defSignature(def) {
10219
- const defCopy = {
10220
- ...def
10221
- };
10222
- if (defCopy.transportType === "memory" || defCopy.transport) {
10223
- return `memory:${Date.now()}:${Math.random()}`;
10224
- }
10225
- return JSON.stringify(defCopy);
10226
- }
10227
10450
  function createTransport(def) {
10228
10451
  const defAny = def;
10229
10452
  const explicitType = defAny.transportType || defAny.type;
@@ -10271,90 +10494,43 @@ function createTransport(def) {
10271
10494
  }
10272
10495
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
10273
10496
  }
10274
- async function getOrCreateMcpClient(defKey, def) {
10275
- const pooled = mcpClientPool.get(defKey);
10276
- if (pooled) {
10277
- pooled.refCount += 1;
10278
- return pooled.client;
10279
- }
10280
- const existingConnecting = mcpClientConnecting.get(defKey);
10281
- if (existingConnecting) {
10282
- const client = await existingConnecting;
10283
- const entry = mcpClientPool.get(defKey);
10284
- if (entry) entry.refCount += 1;
10285
- return client;
10286
- }
10287
- const transport = createTransport(def);
10288
- const connecting = (async () => {
10289
- const client = new Client({
10290
- name: `mcp_${shortHash(defSignature(def))}`,
10291
- version: "1.0.0"
10292
- });
10293
- await client.connect(transport, {
10294
- timeout: 6e4 * 10
10295
- });
10296
- return client;
10297
- })();
10298
- mcpClientConnecting.set(defKey, connecting);
10299
- try {
10300
- const client = await connecting;
10301
- mcpClientPool.set(defKey, {
10302
- client,
10303
- refCount: 1
10304
- });
10305
- return client;
10306
- } finally {
10307
- mcpClientConnecting.delete(defKey);
10497
+ function defSignature(def) {
10498
+ const defCopy = {
10499
+ ...def
10500
+ };
10501
+ if (defCopy.transportType === "memory" || defCopy.transport) {
10502
+ return `memory:${Date.now()}:${Math.random()}`;
10308
10503
  }
10504
+ return JSON.stringify(defCopy);
10309
10505
  }
10310
- async function releaseMcpClient(defKey) {
10311
- const entry = mcpClientPool.get(defKey);
10312
- if (!entry) return;
10313
- entry.refCount -= 1;
10314
- if (entry.refCount <= 0) {
10315
- mcpClientPool.delete(defKey);
10316
- try {
10317
- await entry.client.close();
10318
- } catch (err) {
10319
- console.error("Error closing MCP client:", err);
10320
- }
10321
- }
10506
+ var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
10507
+ async function createMcpClient(def) {
10508
+ const transport = createTransport(def);
10509
+ const client = new Client({
10510
+ name: `mcp_${shortHash(defSignature(def))}`,
10511
+ version: "1.0.0"
10512
+ });
10513
+ await client.connect(transport, {
10514
+ timeout: 6e4 * 10
10515
+ });
10516
+ return client;
10322
10517
  }
10323
- var cleanupAllPooledClients = async () => {
10324
- const entries = Array.from(mcpClientPool.entries());
10325
- mcpClientPool.clear();
10326
- await Promise.all(entries.map(async ([, { client }]) => {
10327
- try {
10328
- await client.close();
10329
- } catch (err) {
10330
- console.error("Error closing MCP client:", err);
10331
- }
10332
- }));
10333
- };
10334
- import_node_process8.default.once?.("exit", () => {
10335
- cleanupAllPooledClients();
10336
- });
10337
- import_node_process8.default.once?.("SIGINT", () => {
10338
- cleanupAllPooledClients().finally(() => import_node_process8.default.exit(0));
10339
- });
10340
10518
  async function composeMcpDepTools(mcpConfig, filterIn) {
10341
10519
  const allTools = {};
10342
10520
  const allClients = {};
10343
- const acquiredKeys = [];
10521
+ const clientsToClose = [];
10344
10522
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
10345
10523
  const def = definition;
10346
10524
  if (def.disabled) continue;
10347
- const defKey = shortHash(defSignature(def));
10348
- const serverId = name;
10349
10525
  try {
10350
- const client = await getOrCreateMcpClient(defKey, def);
10351
- acquiredKeys.push(defKey);
10352
- allClients[serverId] = client;
10526
+ const client = await createMcpClient(def);
10527
+ clientsToClose.push(client);
10528
+ allClients[name] = client;
10353
10529
  const { tools } = await client.listTools();
10354
10530
  tools.forEach((tool2) => {
10355
10531
  const toolNameWithScope = `${name}.${tool2.name}`;
10356
10532
  const internalToolName = tool2.name;
10357
- const rawToolId = `${serverId}_${internalToolName}`;
10533
+ const rawToolId = `${name}_${internalToolName}`;
10358
10534
  const toolId = sanitizePropertyKey(rawToolId);
10359
10535
  if (filterIn && !filterIn({
10360
10536
  action: internalToolName,
@@ -10366,7 +10542,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
10366
10542
  })) {
10367
10543
  return;
10368
10544
  }
10369
- const execute = (args) => allClients[serverId].callTool({
10545
+ const execute = (args) => allClients[name].callTool({
10370
10546
  name: internalToolName,
10371
10547
  arguments: args
10372
10548
  }, void 0, {
@@ -10383,10 +10559,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
10383
10559
  }
10384
10560
  }
10385
10561
  const cleanupClients = async () => {
10386
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
10387
- acquiredKeys.length = 0;
10388
- Object.keys(allTools).forEach((key) => delete allTools[key]);
10389
- Object.keys(allClients).forEach((key) => delete allClients[key]);
10562
+ await Promise.all(clientsToClose.map((client) => {
10563
+ try {
10564
+ return client.close();
10565
+ } catch {
10566
+ }
10567
+ }));
10390
10568
  };
10391
10569
  return {
10392
10570
  tools: allTools,