@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.mjs CHANGED
@@ -2385,7 +2385,7 @@ if (typeof global.crypto === "undefined") {
2385
2385
  var outgoingEnded = Symbol("outgoingEnded");
2386
2386
 
2387
2387
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
2388
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
2388
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
2389
2389
  var LETTER_REGEXP = /[A-Za-z]/;
2390
2390
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
2391
2391
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -2396,12 +2396,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
2396
2396
  function isNumber(string3) {
2397
2397
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
2398
2398
  }
2399
+ function isConstructorOrProto(obj, key) {
2400
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
2401
+ }
2399
2402
  function setNested(object5, keys, value, collect = false) {
2400
2403
  keys = [
2401
2404
  ...keys
2402
2405
  ];
2403
2406
  const key = keys.pop();
2404
- keys.forEach((key2) => object5 = object5[key2] ??= {});
2407
+ for (const k of keys) {
2408
+ if (isConstructorOrProto(object5, k)) return;
2409
+ object5 = object5[k] ??= {};
2410
+ }
2411
+ if (isConstructorOrProto(object5, key)) return;
2405
2412
  if (collect) {
2406
2413
  const v = object5[key];
2407
2414
  if (Array.isArray(v)) {
@@ -2532,7 +2539,7 @@ function parseArgs(args, options) {
2532
2539
  let key = groups.key;
2533
2540
  let value = groups.value;
2534
2541
  if (doubleDash2) {
2535
- if (value) {
2542
+ if (value != null) {
2536
2543
  if (booleanSet.has(key)) value = parseBooleanString(value);
2537
2544
  setArgument(key, value, arg, true);
2538
2545
  continue;
@@ -2570,6 +2577,10 @@ function parseArgs(args, options) {
2570
2577
  setArgument(letter, next, arg, true);
2571
2578
  continue;
2572
2579
  }
2580
+ if (next === "=") {
2581
+ setArgument(letter, "", arg, true);
2582
+ continue argsLoop;
2583
+ }
2573
2584
  if (LETTER_REGEXP.test(letter)) {
2574
2585
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
2575
2586
  if (groups2) {
@@ -3064,7 +3075,7 @@ Usage:
3064
3075
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
3065
3076
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
3066
3077
 
3067
- Note: For scripts/ and assets/, use appropriate tools directly.`;
3078
+ Note: For scripts/, use the bash tool with the script path to execute.`;
3068
3079
  }
3069
3080
  function createSkillsPlugin(options) {
3070
3081
  const { paths } = options;
@@ -3172,11 +3183,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
3172
3183
  try {
3173
3184
  const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
3174
3185
  const body = extractBody(content);
3186
+ const skillPathInfo = `
3187
+ ---
3188
+ Skill path: ${meta.basePath}
3189
+ `;
3175
3190
  return {
3176
3191
  content: [
3177
3192
  {
3178
3193
  type: "text",
3179
- text: body
3194
+ text: body + skillPathInfo
3180
3195
  }
3181
3196
  ]
3182
3197
  };
@@ -4047,12 +4062,29 @@ function writeFoldedLines(count) {
4047
4062
  if (count > 1) return "\n".repeat(count - 1);
4048
4063
  return "";
4049
4064
  }
4065
+ var Scanner = class {
4066
+ source;
4067
+ #length;
4068
+ position = 0;
4069
+ constructor(source) {
4070
+ source += "\0";
4071
+ this.source = source;
4072
+ this.#length = source.length;
4073
+ }
4074
+ peek(offset = 0) {
4075
+ return this.source.charCodeAt(this.position + offset);
4076
+ }
4077
+ next() {
4078
+ this.position += 1;
4079
+ }
4080
+ eof() {
4081
+ return this.position >= this.#length - 1;
4082
+ }
4083
+ };
4050
4084
  var LoaderState = class {
4051
- input;
4052
- length;
4085
+ #scanner;
4053
4086
  lineIndent = 0;
4054
4087
  lineStart = 0;
4055
- position = 0;
4056
4088
  line = 0;
4057
4089
  onWarning;
4058
4090
  allowDuplicateKeys;
@@ -4062,44 +4094,40 @@ var LoaderState = class {
4062
4094
  tagMap = /* @__PURE__ */ new Map();
4063
4095
  anchorMap = /* @__PURE__ */ new Map();
4064
4096
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
4065
- this.input = input;
4097
+ this.#scanner = new Scanner(input);
4066
4098
  this.onWarning = onWarning;
4067
4099
  this.allowDuplicateKeys = allowDuplicateKeys;
4068
4100
  this.implicitTypes = schema.implicitTypes;
4069
4101
  this.typeMap = schema.typeMap;
4070
- this.length = input.length;
4071
4102
  this.readIndent();
4072
4103
  }
4073
4104
  skipWhitespaces() {
4074
- let ch = this.peek();
4105
+ let ch = this.#scanner.peek();
4075
4106
  while (isWhiteSpace(ch)) {
4076
- ch = this.next();
4107
+ this.#scanner.next();
4108
+ ch = this.#scanner.peek();
4077
4109
  }
4078
4110
  }
4079
4111
  skipComment() {
4080
- let ch = this.peek();
4112
+ let ch = this.#scanner.peek();
4081
4113
  if (ch !== SHARP) return;
4082
- ch = this.next();
4114
+ this.#scanner.next();
4115
+ ch = this.#scanner.peek();
4083
4116
  while (ch !== 0 && !isEOL(ch)) {
4084
- ch = this.next();
4117
+ this.#scanner.next();
4118
+ ch = this.#scanner.peek();
4085
4119
  }
4086
4120
  }
4087
4121
  readIndent() {
4088
- let char = this.peek();
4089
- while (char === SPACE) {
4122
+ let ch = this.#scanner.peek();
4123
+ while (ch === SPACE) {
4090
4124
  this.lineIndent += 1;
4091
- char = this.next();
4125
+ this.#scanner.next();
4126
+ ch = this.#scanner.peek();
4092
4127
  }
4093
4128
  }
4094
- peek(offset = 0) {
4095
- return this.input.charCodeAt(this.position + offset);
4096
- }
4097
- next() {
4098
- this.position += 1;
4099
- return this.peek();
4100
- }
4101
4129
  #createError(message) {
4102
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
4130
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
4103
4131
  return new SyntaxError(`${message} ${mark}`);
4104
4132
  }
4105
4133
  dispatchWarning(message) {
@@ -4144,7 +4172,7 @@ var LoaderState = class {
4144
4172
  }
4145
4173
  captureSegment(start, end, checkJson) {
4146
4174
  if (start < end) {
4147
- const result = this.input.slice(start, end);
4175
+ const result = this.#scanner.source.slice(start, end);
4148
4176
  if (checkJson) {
4149
4177
  for (let position = 0; position < result.length; position++) {
4150
4178
  const character = result.charCodeAt(position);
@@ -4162,21 +4190,21 @@ var LoaderState = class {
4162
4190
  let detected = false;
4163
4191
  const result = [];
4164
4192
  if (anchor !== null) this.anchorMap.set(anchor, result);
4165
- let ch = this.peek();
4193
+ let ch = this.#scanner.peek();
4166
4194
  while (ch !== 0) {
4167
4195
  if (ch !== MINUS) {
4168
4196
  break;
4169
4197
  }
4170
- const following = this.peek(1);
4198
+ const following = this.#scanner.peek(1);
4171
4199
  if (!isWhiteSpaceOrEOL(following)) {
4172
4200
  break;
4173
4201
  }
4174
4202
  detected = true;
4175
- this.position++;
4203
+ this.#scanner.next();
4176
4204
  if (this.skipSeparationSpace(true, -1)) {
4177
4205
  if (this.lineIndent <= nodeIndent) {
4178
4206
  result.push(null);
4179
- ch = this.peek();
4207
+ ch = this.#scanner.peek();
4180
4208
  continue;
4181
4209
  }
4182
4210
  }
@@ -4189,7 +4217,7 @@ var LoaderState = class {
4189
4217
  });
4190
4218
  if (newState) result.push(newState.result);
4191
4219
  this.skipSeparationSpace(true, -1);
4192
- ch = this.peek();
4220
+ ch = this.#scanner.peek();
4193
4221
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
4194
4222
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
4195
4223
  } else if (this.lineIndent < nodeIndent) {
@@ -4245,7 +4273,7 @@ var LoaderState = class {
4245
4273
  } else {
4246
4274
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
4247
4275
  this.line = startLine || this.line;
4248
- this.position = startPos || this.position;
4276
+ this.#scanner.position = startPos || this.#scanner.position;
4249
4277
  throw this.#createError("Cannot store mapping pair: duplicated key");
4250
4278
  }
4251
4279
  Object.defineProperty(result, keyNode, {
@@ -4259,37 +4287,37 @@ var LoaderState = class {
4259
4287
  return result;
4260
4288
  }
4261
4289
  readLineBreak() {
4262
- const ch = this.peek();
4290
+ const ch = this.#scanner.peek();
4263
4291
  if (ch === LINE_FEED) {
4264
- this.position++;
4292
+ this.#scanner.next();
4265
4293
  } else if (ch === CARRIAGE_RETURN) {
4266
- this.position++;
4267
- if (this.peek() === LINE_FEED) {
4268
- this.position++;
4294
+ this.#scanner.next();
4295
+ if (this.#scanner.peek() === LINE_FEED) {
4296
+ this.#scanner.next();
4269
4297
  }
4270
4298
  } else {
4271
4299
  throw this.#createError("Cannot read line: line break not found");
4272
4300
  }
4273
4301
  this.line += 1;
4274
- this.lineStart = this.position;
4302
+ this.lineStart = this.#scanner.position;
4275
4303
  }
4276
4304
  skipSeparationSpace(allowComments, checkIndent) {
4277
4305
  let lineBreaks = 0;
4278
- let ch = this.peek();
4306
+ let ch = this.#scanner.peek();
4279
4307
  while (ch !== 0) {
4280
4308
  this.skipWhitespaces();
4281
- ch = this.peek();
4309
+ ch = this.#scanner.peek();
4282
4310
  if (allowComments) {
4283
4311
  this.skipComment();
4284
- ch = this.peek();
4312
+ ch = this.#scanner.peek();
4285
4313
  }
4286
4314
  if (isEOL(ch)) {
4287
4315
  this.readLineBreak();
4288
- ch = this.peek();
4316
+ ch = this.#scanner.peek();
4289
4317
  lineBreaks++;
4290
4318
  this.lineIndent = 0;
4291
4319
  this.readIndent();
4292
- ch = this.peek();
4320
+ ch = this.#scanner.peek();
4293
4321
  } else {
4294
4322
  break;
4295
4323
  }
@@ -4300,9 +4328,9 @@ var LoaderState = class {
4300
4328
  return lineBreaks;
4301
4329
  }
4302
4330
  testDocumentSeparator() {
4303
- let ch = this.peek();
4304
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
4305
- ch = this.peek(3);
4331
+ let ch = this.#scanner.peek();
4332
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
4333
+ ch = this.#scanner.peek(3);
4306
4334
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
4307
4335
  return true;
4308
4336
  }
@@ -4310,34 +4338,34 @@ var LoaderState = class {
4310
4338
  return false;
4311
4339
  }
4312
4340
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
4313
- let ch = this.peek();
4341
+ let ch = this.#scanner.peek();
4314
4342
  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) {
4315
4343
  return;
4316
4344
  }
4317
4345
  let following;
4318
4346
  if (ch === QUESTION || ch === MINUS) {
4319
- following = this.peek(1);
4347
+ following = this.#scanner.peek(1);
4320
4348
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
4321
4349
  return;
4322
4350
  }
4323
4351
  }
4324
4352
  let result = "";
4325
- let captureEnd = this.position;
4326
- let captureStart = this.position;
4353
+ let captureEnd = this.#scanner.position;
4354
+ let captureStart = this.#scanner.position;
4327
4355
  let hasPendingContent = false;
4328
4356
  let line = 0;
4329
4357
  while (ch !== 0) {
4330
4358
  if (ch === COLON) {
4331
- following = this.peek(1);
4359
+ following = this.#scanner.peek(1);
4332
4360
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
4333
4361
  break;
4334
4362
  }
4335
4363
  } else if (ch === SHARP) {
4336
- const preceding = this.peek(-1);
4364
+ const preceding = this.#scanner.peek(-1);
4337
4365
  if (isWhiteSpaceOrEOL(preceding)) {
4338
4366
  break;
4339
4367
  }
4340
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
4368
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
4341
4369
  break;
4342
4370
  } else if (isEOL(ch)) {
4343
4371
  line = this.line;
@@ -4346,10 +4374,10 @@ var LoaderState = class {
4346
4374
  this.skipSeparationSpace(false, -1);
4347
4375
  if (this.lineIndent >= nodeIndent) {
4348
4376
  hasPendingContent = true;
4349
- ch = this.peek();
4377
+ ch = this.#scanner.peek();
4350
4378
  continue;
4351
4379
  } else {
4352
- this.position = captureEnd;
4380
+ this.#scanner.position = captureEnd;
4353
4381
  this.line = line;
4354
4382
  this.lineStart = lineStart;
4355
4383
  this.lineIndent = lineIndent;
@@ -4360,13 +4388,14 @@ var LoaderState = class {
4360
4388
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
4361
4389
  if (segment2) result += segment2;
4362
4390
  result += writeFoldedLines(this.line - line);
4363
- captureStart = captureEnd = this.position;
4391
+ captureStart = captureEnd = this.#scanner.position;
4364
4392
  hasPendingContent = false;
4365
4393
  }
4366
4394
  if (!isWhiteSpace(ch)) {
4367
- captureEnd = this.position + 1;
4395
+ captureEnd = this.#scanner.position + 1;
4368
4396
  }
4369
- ch = this.next();
4397
+ this.#scanner.next();
4398
+ ch = this.#scanner.peek();
4370
4399
  }
4371
4400
  const segment = this.captureSegment(captureStart, captureEnd, false);
4372
4401
  if (segment) result += segment;
@@ -4379,22 +4408,23 @@ var LoaderState = class {
4379
4408
  };
4380
4409
  }
4381
4410
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
4382
- let ch = this.peek();
4411
+ let ch = this.#scanner.peek();
4383
4412
  if (ch !== SINGLE_QUOTE) return;
4384
4413
  let result = "";
4385
- this.position++;
4386
- let captureStart = this.position;
4387
- let captureEnd = this.position;
4388
- ch = this.peek();
4414
+ this.#scanner.next();
4415
+ let captureStart = this.#scanner.position;
4416
+ let captureEnd = this.#scanner.position;
4417
+ ch = this.#scanner.peek();
4389
4418
  while (ch !== 0) {
4390
4419
  if (ch === SINGLE_QUOTE) {
4391
- const segment = this.captureSegment(captureStart, this.position, true);
4420
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4392
4421
  if (segment) result += segment;
4393
- ch = this.next();
4422
+ this.#scanner.next();
4423
+ ch = this.#scanner.peek();
4394
4424
  if (ch === SINGLE_QUOTE) {
4395
- captureStart = this.position;
4396
- this.position++;
4397
- captureEnd = this.position;
4425
+ captureStart = this.#scanner.position;
4426
+ this.#scanner.next();
4427
+ captureEnd = this.#scanner.position;
4398
4428
  } else {
4399
4429
  if (anchor !== null) this.anchorMap.set(anchor, result);
4400
4430
  return {
@@ -4408,31 +4438,31 @@ var LoaderState = class {
4408
4438
  const segment = this.captureSegment(captureStart, captureEnd, true);
4409
4439
  if (segment) result += segment;
4410
4440
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
4411
- captureStart = captureEnd = this.position;
4412
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
4441
+ captureStart = captureEnd = this.#scanner.position;
4442
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
4413
4443
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
4414
4444
  } else {
4415
- this.position++;
4416
- captureEnd = this.position;
4445
+ this.#scanner.next();
4446
+ captureEnd = this.#scanner.position;
4417
4447
  }
4418
- ch = this.peek();
4448
+ ch = this.#scanner.peek();
4419
4449
  }
4420
4450
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
4421
4451
  }
4422
4452
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
4423
- let ch = this.peek();
4453
+ let ch = this.#scanner.peek();
4424
4454
  if (ch !== DOUBLE_QUOTE) return;
4425
4455
  let result = "";
4426
- this.position++;
4427
- let captureEnd = this.position;
4428
- let captureStart = this.position;
4456
+ this.#scanner.next();
4457
+ let captureEnd = this.#scanner.position;
4458
+ let captureStart = this.#scanner.position;
4429
4459
  let tmp;
4430
- ch = this.peek();
4460
+ ch = this.#scanner.peek();
4431
4461
  while (ch !== 0) {
4432
4462
  if (ch === DOUBLE_QUOTE) {
4433
- const segment = this.captureSegment(captureStart, this.position, true);
4463
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4434
4464
  if (segment) result += segment;
4435
- this.position++;
4465
+ this.#scanner.next();
4436
4466
  if (anchor !== null) this.anchorMap.set(anchor, result);
4437
4467
  return {
4438
4468
  tag,
@@ -4442,19 +4472,21 @@ var LoaderState = class {
4442
4472
  };
4443
4473
  }
4444
4474
  if (ch === BACKSLASH) {
4445
- const segment = this.captureSegment(captureStart, this.position, true);
4475
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4446
4476
  if (segment) result += segment;
4447
- ch = this.next();
4477
+ this.#scanner.next();
4478
+ ch = this.#scanner.peek();
4448
4479
  if (isEOL(ch)) {
4449
4480
  this.skipSeparationSpace(false, nodeIndent);
4450
4481
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
4451
4482
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
4452
- this.position++;
4483
+ this.#scanner.next();
4453
4484
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
4454
4485
  let hexLength = tmp;
4455
4486
  let hexResult = 0;
4456
4487
  for (; hexLength > 0; hexLength--) {
4457
- ch = this.next();
4488
+ this.#scanner.next();
4489
+ ch = this.#scanner.peek();
4458
4490
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
4459
4491
  hexResult = (hexResult << 4) + tmp;
4460
4492
  } else {
@@ -4462,28 +4494,28 @@ var LoaderState = class {
4462
4494
  }
4463
4495
  }
4464
4496
  result += codepointToChar(hexResult);
4465
- this.position++;
4497
+ this.#scanner.next();
4466
4498
  } else {
4467
4499
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
4468
4500
  }
4469
- captureStart = captureEnd = this.position;
4501
+ captureStart = captureEnd = this.#scanner.position;
4470
4502
  } else if (isEOL(ch)) {
4471
4503
  const segment = this.captureSegment(captureStart, captureEnd, true);
4472
4504
  if (segment) result += segment;
4473
4505
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
4474
- captureStart = captureEnd = this.position;
4475
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
4506
+ captureStart = captureEnd = this.#scanner.position;
4507
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
4476
4508
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
4477
4509
  } else {
4478
- this.position++;
4479
- captureEnd = this.position;
4510
+ this.#scanner.next();
4511
+ captureEnd = this.#scanner.position;
4480
4512
  }
4481
- ch = this.peek();
4513
+ ch = this.#scanner.peek();
4482
4514
  }
4483
4515
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
4484
4516
  }
4485
4517
  readFlowCollection(tag, anchor, nodeIndent) {
4486
- let ch = this.peek();
4518
+ let ch = this.#scanner.peek();
4487
4519
  let terminator;
4488
4520
  let isMapping = true;
4489
4521
  let result = {};
@@ -4497,7 +4529,8 @@ var LoaderState = class {
4497
4529
  return;
4498
4530
  }
4499
4531
  if (anchor !== null) this.anchorMap.set(anchor, result);
4500
- ch = this.next();
4532
+ this.#scanner.next();
4533
+ ch = this.#scanner.peek();
4501
4534
  let readNext = true;
4502
4535
  let valueNode = null;
4503
4536
  let keyNode = null;
@@ -4509,9 +4542,9 @@ var LoaderState = class {
4509
4542
  const overridableKeys = /* @__PURE__ */ new Set();
4510
4543
  while (ch !== 0) {
4511
4544
  this.skipSeparationSpace(true, nodeIndent);
4512
- ch = this.peek();
4545
+ ch = this.#scanner.peek();
4513
4546
  if (ch === terminator) {
4514
- this.position++;
4547
+ this.#scanner.next();
4515
4548
  const kind = isMapping ? "mapping" : "sequence";
4516
4549
  return {
4517
4550
  tag,
@@ -4526,10 +4559,10 @@ var LoaderState = class {
4526
4559
  keyTag = keyNode = valueNode = null;
4527
4560
  isPair = isExplicitPair = false;
4528
4561
  if (ch === QUESTION) {
4529
- following = this.peek(1);
4562
+ following = this.#scanner.peek(1);
4530
4563
  if (isWhiteSpaceOrEOL(following)) {
4531
4564
  isPair = isExplicitPair = true;
4532
- this.position++;
4565
+ this.#scanner.next();
4533
4566
  this.skipSeparationSpace(true, nodeIndent);
4534
4567
  }
4535
4568
  }
@@ -4545,10 +4578,11 @@ var LoaderState = class {
4545
4578
  keyNode = newState.result;
4546
4579
  }
4547
4580
  this.skipSeparationSpace(true, nodeIndent);
4548
- ch = this.peek();
4581
+ ch = this.#scanner.peek();
4549
4582
  if ((isExplicitPair || this.line === line) && ch === COLON) {
4550
4583
  isPair = true;
4551
- ch = this.next();
4584
+ this.#scanner.next();
4585
+ ch = this.#scanner.peek();
4552
4586
  this.skipSeparationSpace(true, nodeIndent);
4553
4587
  const newState2 = this.composeNode({
4554
4588
  parentIndent: nodeIndent,
@@ -4566,10 +4600,11 @@ var LoaderState = class {
4566
4600
  result.push(keyNode);
4567
4601
  }
4568
4602
  this.skipSeparationSpace(true, nodeIndent);
4569
- ch = this.peek();
4603
+ ch = this.#scanner.peek();
4570
4604
  if (ch === COMMA) {
4571
4605
  readNext = true;
4572
- ch = this.next();
4606
+ this.#scanner.next();
4607
+ ch = this.#scanner.peek();
4573
4608
  } else {
4574
4609
  readNext = false;
4575
4610
  }
@@ -4585,7 +4620,7 @@ var LoaderState = class {
4585
4620
  let textIndent = nodeIndent;
4586
4621
  let emptyLines = 0;
4587
4622
  let atMoreIndented = false;
4588
- let ch = this.peek();
4623
+ let ch = this.#scanner.peek();
4589
4624
  let folding = false;
4590
4625
  if (ch === VERTICAL_LINE) {
4591
4626
  folding = false;
@@ -4597,7 +4632,8 @@ var LoaderState = class {
4597
4632
  let result = "";
4598
4633
  let tmp = 0;
4599
4634
  while (ch !== 0) {
4600
- ch = this.next();
4635
+ this.#scanner.next();
4636
+ ch = this.#scanner.peek();
4601
4637
  if (ch === PLUS || ch === MINUS) {
4602
4638
  if (CHOMPING_CLIP === chomping) {
4603
4639
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -4620,15 +4656,16 @@ var LoaderState = class {
4620
4656
  if (isWhiteSpace(ch)) {
4621
4657
  this.skipWhitespaces();
4622
4658
  this.skipComment();
4623
- ch = this.peek();
4659
+ ch = this.#scanner.peek();
4624
4660
  }
4625
4661
  while (ch !== 0) {
4626
4662
  this.readLineBreak();
4627
4663
  this.lineIndent = 0;
4628
- ch = this.peek();
4664
+ ch = this.#scanner.peek();
4629
4665
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
4630
4666
  this.lineIndent++;
4631
- ch = this.next();
4667
+ this.#scanner.next();
4668
+ ch = this.#scanner.peek();
4632
4669
  }
4633
4670
  if (!detectedIndent && this.lineIndent > textIndent) {
4634
4671
  textIndent = this.lineIndent;
@@ -4667,11 +4704,12 @@ var LoaderState = class {
4667
4704
  didReadContent = true;
4668
4705
  detectedIndent = true;
4669
4706
  emptyLines = 0;
4670
- const captureStart = this.position;
4707
+ const captureStart = this.#scanner.position;
4671
4708
  while (!isEOL(ch) && ch !== 0) {
4672
- ch = this.next();
4709
+ this.#scanner.next();
4710
+ ch = this.#scanner.peek();
4673
4711
  }
4674
- const segment = this.captureSegment(captureStart, this.position, false);
4712
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
4675
4713
  if (segment) result += segment;
4676
4714
  }
4677
4715
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -4694,11 +4732,11 @@ var LoaderState = class {
4694
4732
  let atExplicitKey = false;
4695
4733
  let detected = false;
4696
4734
  if (anchor !== null) this.anchorMap.set(anchor, result);
4697
- let ch = this.peek();
4735
+ let ch = this.#scanner.peek();
4698
4736
  while (ch !== 0) {
4699
- const following = this.peek(1);
4737
+ const following = this.#scanner.peek(1);
4700
4738
  line = this.line;
4701
- pos = this.position;
4739
+ pos = this.#scanner.position;
4702
4740
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
4703
4741
  if (ch === QUESTION) {
4704
4742
  if (atExplicitKey) {
@@ -4716,7 +4754,7 @@ var LoaderState = class {
4716
4754
  } else {
4717
4755
  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");
4718
4756
  }
4719
- this.position += 1;
4757
+ this.#scanner.next();
4720
4758
  ch = following;
4721
4759
  } else {
4722
4760
  const newState = this.composeNode({
@@ -4727,11 +4765,12 @@ var LoaderState = class {
4727
4765
  });
4728
4766
  if (!newState) break;
4729
4767
  if (this.line === line) {
4730
- ch = this.peek();
4768
+ ch = this.#scanner.peek();
4731
4769
  this.skipWhitespaces();
4732
- ch = this.peek();
4770
+ ch = this.#scanner.peek();
4733
4771
  if (ch === COLON) {
4734
- ch = this.next();
4772
+ this.#scanner.next();
4773
+ ch = this.#scanner.peek();
4735
4774
  if (!isWhiteSpaceOrEOL(ch)) {
4736
4775
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
4737
4776
  }
@@ -4788,7 +4827,7 @@ var LoaderState = class {
4788
4827
  keyTag = keyNode = valueNode = null;
4789
4828
  }
4790
4829
  this.skipSeparationSpace(true, -1);
4791
- ch = this.peek();
4830
+ ch = this.#scanner.peek();
4792
4831
  }
4793
4832
  if (this.lineIndent > nodeIndent && ch !== 0) {
4794
4833
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -4811,30 +4850,35 @@ var LoaderState = class {
4811
4850
  let isNamed = false;
4812
4851
  let tagHandle = "";
4813
4852
  let tagName;
4814
- let ch = this.peek();
4853
+ let ch = this.#scanner.peek();
4815
4854
  if (ch !== EXCLAMATION) return;
4816
4855
  if (tag !== null) {
4817
4856
  throw this.#createError("Cannot read tag property: duplication of a tag property");
4818
4857
  }
4819
- ch = this.next();
4858
+ this.#scanner.next();
4859
+ ch = this.#scanner.peek();
4820
4860
  if (ch === SMALLER_THAN) {
4821
4861
  isVerbatim = true;
4822
- ch = this.next();
4862
+ this.#scanner.next();
4863
+ ch = this.#scanner.peek();
4823
4864
  } else if (ch === EXCLAMATION) {
4824
4865
  isNamed = true;
4825
4866
  tagHandle = "!!";
4826
- ch = this.next();
4867
+ this.#scanner.next();
4868
+ ch = this.#scanner.peek();
4827
4869
  } else {
4828
4870
  tagHandle = "!";
4829
4871
  }
4830
- let position = this.position;
4872
+ let position = this.#scanner.position;
4831
4873
  if (isVerbatim) {
4832
4874
  do {
4833
- ch = this.next();
4875
+ this.#scanner.next();
4876
+ ch = this.#scanner.peek();
4834
4877
  } while (ch !== 0 && ch !== GREATER_THAN);
4835
- if (this.position < this.length) {
4836
- tagName = this.input.slice(position, this.position);
4837
- ch = this.next();
4878
+ if (!this.#scanner.eof()) {
4879
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
4880
+ this.#scanner.next();
4881
+ ch = this.#scanner.peek();
4838
4882
  } else {
4839
4883
  throw this.#createError("Cannot read tag property: unexpected end of stream");
4840
4884
  }
@@ -4842,19 +4886,20 @@ var LoaderState = class {
4842
4886
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
4843
4887
  if (ch === EXCLAMATION) {
4844
4888
  if (!isNamed) {
4845
- tagHandle = this.input.slice(position - 1, this.position + 1);
4889
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
4846
4890
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
4847
4891
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
4848
4892
  }
4849
4893
  isNamed = true;
4850
- position = this.position + 1;
4894
+ position = this.#scanner.position + 1;
4851
4895
  } else {
4852
4896
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
4853
4897
  }
4854
4898
  }
4855
- ch = this.next();
4899
+ this.#scanner.next();
4900
+ ch = this.#scanner.peek();
4856
4901
  }
4857
- tagName = this.input.slice(position, this.position);
4902
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
4858
4903
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
4859
4904
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
4860
4905
  }
@@ -4874,32 +4919,36 @@ var LoaderState = class {
4874
4919
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
4875
4920
  }
4876
4921
  readAnchorProperty(anchor) {
4877
- let ch = this.peek();
4922
+ let ch = this.#scanner.peek();
4878
4923
  if (ch !== AMPERSAND) return;
4879
4924
  if (anchor !== null) {
4880
4925
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
4881
4926
  }
4882
- ch = this.next();
4883
- const position = this.position;
4927
+ this.#scanner.next();
4928
+ ch = this.#scanner.peek();
4929
+ const position = this.#scanner.position;
4884
4930
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
4885
- ch = this.next();
4931
+ this.#scanner.next();
4932
+ ch = this.#scanner.peek();
4886
4933
  }
4887
- if (this.position === position) {
4934
+ if (this.#scanner.position === position) {
4888
4935
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
4889
4936
  }
4890
- return this.input.slice(position, this.position);
4937
+ return this.#scanner.source.slice(position, this.#scanner.position);
4891
4938
  }
4892
4939
  readAlias() {
4893
- if (this.peek() !== ASTERISK) return;
4894
- let ch = this.next();
4895
- const position = this.position;
4940
+ if (this.#scanner.peek() !== ASTERISK) return;
4941
+ this.#scanner.next();
4942
+ let ch = this.#scanner.peek();
4943
+ const position = this.#scanner.position;
4896
4944
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
4897
- ch = this.next();
4945
+ this.#scanner.next();
4946
+ ch = this.#scanner.peek();
4898
4947
  }
4899
- if (this.position === position) {
4948
+ if (this.#scanner.position === position) {
4900
4949
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
4901
4950
  }
4902
- const alias = this.input.slice(position, this.position);
4951
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
4903
4952
  if (!this.anchorMap.has(alias)) {
4904
4953
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
4905
4954
  }
@@ -4982,7 +5031,7 @@ var LoaderState = class {
4982
5031
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
4983
5032
  const flowIndent = cond ? parentIndent : parentIndent + 1;
4984
5033
  if (allowBlockCollections) {
4985
- const blockIndent = this.position - this.lineStart;
5034
+ const blockIndent = this.#scanner.position - this.lineStart;
4986
5035
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
4987
5036
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
4988
5037
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -5016,7 +5065,7 @@ var LoaderState = class {
5016
5065
  return this.resolveTag(plainScalarState);
5017
5066
  }
5018
5067
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
5019
- const blockIndent = this.position - this.lineStart;
5068
+ const blockIndent = this.#scanner.position - this.lineStart;
5020
5069
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
5021
5070
  if (newState2) return this.resolveTag(newState2);
5022
5071
  }
@@ -5031,20 +5080,22 @@ var LoaderState = class {
5031
5080
  readDirectives() {
5032
5081
  let hasDirectives = false;
5033
5082
  let version = null;
5034
- let ch = this.peek();
5083
+ let ch = this.#scanner.peek();
5035
5084
  while (ch !== 0) {
5036
5085
  this.skipSeparationSpace(true, -1);
5037
- ch = this.peek();
5086
+ ch = this.#scanner.peek();
5038
5087
  if (this.lineIndent > 0 || ch !== PERCENT) {
5039
5088
  break;
5040
5089
  }
5041
5090
  hasDirectives = true;
5042
- ch = this.next();
5043
- let position = this.position;
5091
+ this.#scanner.next();
5092
+ ch = this.#scanner.peek();
5093
+ let position = this.#scanner.position;
5044
5094
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
5045
- ch = this.next();
5095
+ this.#scanner.next();
5096
+ ch = this.#scanner.peek();
5046
5097
  }
5047
- const directiveName = this.input.slice(position, this.position);
5098
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
5048
5099
  const directiveArgs = [];
5049
5100
  if (directiveName.length < 1) {
5050
5101
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -5052,13 +5103,14 @@ var LoaderState = class {
5052
5103
  while (ch !== 0) {
5053
5104
  this.skipWhitespaces();
5054
5105
  this.skipComment();
5055
- ch = this.peek();
5106
+ ch = this.#scanner.peek();
5056
5107
  if (isEOL(ch)) break;
5057
- position = this.position;
5108
+ position = this.#scanner.position;
5058
5109
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
5059
- ch = this.next();
5110
+ this.#scanner.next();
5111
+ ch = this.#scanner.peek();
5060
5112
  }
5061
- directiveArgs.push(this.input.slice(position, this.position));
5113
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
5062
5114
  }
5063
5115
  if (ch !== 0) this.readLineBreak();
5064
5116
  switch (directiveName) {
@@ -5075,20 +5127,20 @@ var LoaderState = class {
5075
5127
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
5076
5128
  break;
5077
5129
  }
5078
- ch = this.peek();
5130
+ ch = this.#scanner.peek();
5079
5131
  }
5080
5132
  return hasDirectives;
5081
5133
  }
5082
5134
  readDocument() {
5083
- const documentStart = this.position;
5135
+ const documentStart = this.#scanner.position;
5084
5136
  this.checkLineBreaks = false;
5085
5137
  this.tagMap = /* @__PURE__ */ new Map();
5086
5138
  this.anchorMap = /* @__PURE__ */ new Map();
5087
5139
  const hasDirectives = this.readDirectives();
5088
5140
  this.skipSeparationSpace(true, -1);
5089
5141
  let result = null;
5090
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
5091
- this.position += 3;
5142
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
5143
+ this.#scanner.position += 3;
5092
5144
  this.skipSeparationSpace(true, -1);
5093
5145
  } else if (hasDirectives) {
5094
5146
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -5101,21 +5153,21 @@ var LoaderState = class {
5101
5153
  });
5102
5154
  if (newState) result = newState.result;
5103
5155
  this.skipSeparationSpace(true, -1);
5104
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
5156
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
5105
5157
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
5106
5158
  }
5107
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
5108
- if (this.peek() === DOT) {
5109
- this.position += 3;
5159
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5160
+ if (this.#scanner.peek() === DOT) {
5161
+ this.#scanner.position += 3;
5110
5162
  this.skipSeparationSpace(true, -1);
5111
5163
  }
5112
- } else if (this.position < this.length - 1) {
5164
+ } else if (!this.#scanner.eof()) {
5113
5165
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
5114
5166
  }
5115
5167
  return result;
5116
5168
  }
5117
5169
  *readDocuments() {
5118
- while (this.position < this.length - 1) {
5170
+ while (!this.#scanner.eof()) {
5119
5171
  yield this.readDocument();
5120
5172
  }
5121
5173
  }
@@ -5128,7 +5180,6 @@ function sanitizeInput(input) {
5128
5180
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
5129
5181
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
5130
5182
  }
5131
- input += "\0";
5132
5183
  return input;
5133
5184
  }
5134
5185
  function parse(content, options = {}) {
@@ -5288,7 +5339,7 @@ function getDefaultAgents() {
5288
5339
  }
5289
5340
 
5290
5341
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
5291
- var CLI_VERSION = "0.1.44";
5342
+ var CLI_VERSION = "0.1.51";
5292
5343
  function extractServerName(command, commandArgs) {
5293
5344
  for (const arg of commandArgs) {
5294
5345
  if (!arg.startsWith("-")) {
@@ -6897,6 +6948,147 @@ var ExperimentalServerTasks = class {
6897
6948
  requestStream(request, resultSchema, options) {
6898
6949
  return this._server.requestStream(request, resultSchema, options);
6899
6950
  }
6951
+ /**
6952
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
6953
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
6954
+ *
6955
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
6956
+ * before the final result.
6957
+ *
6958
+ * @example
6959
+ * ```typescript
6960
+ * const stream = server.experimental.tasks.createMessageStream({
6961
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
6962
+ * maxTokens: 100
6963
+ * }, {
6964
+ * onprogress: (progress) => {
6965
+ * // Handle streaming tokens via progress notifications
6966
+ * console.log('Progress:', progress.message);
6967
+ * }
6968
+ * });
6969
+ *
6970
+ * for await (const message of stream) {
6971
+ * switch (message.type) {
6972
+ * case 'taskCreated':
6973
+ * console.log('Task created:', message.task.taskId);
6974
+ * break;
6975
+ * case 'taskStatus':
6976
+ * console.log('Task status:', message.task.status);
6977
+ * break;
6978
+ * case 'result':
6979
+ * console.log('Final result:', message.result);
6980
+ * break;
6981
+ * case 'error':
6982
+ * console.error('Error:', message.error);
6983
+ * break;
6984
+ * }
6985
+ * }
6986
+ * ```
6987
+ *
6988
+ * @param params - The sampling request parameters
6989
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
6990
+ * @returns AsyncGenerator that yields ResponseMessage objects
6991
+ *
6992
+ * @experimental
6993
+ */
6994
+ createMessageStream(params, options) {
6995
+ const clientCapabilities = this._server.getClientCapabilities();
6996
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
6997
+ throw new Error("Client does not support sampling tools capability.");
6998
+ }
6999
+ if (params.messages.length > 0) {
7000
+ const lastMessage = params.messages[params.messages.length - 1];
7001
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
7002
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
7003
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
7004
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
7005
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
7006
+ if (hasToolResults) {
7007
+ if (lastContent.some((c) => c.type !== "tool_result")) {
7008
+ throw new Error("The last message must contain only tool_result content if any is present");
7009
+ }
7010
+ if (!hasPreviousToolUse) {
7011
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
7012
+ }
7013
+ }
7014
+ if (hasPreviousToolUse) {
7015
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
7016
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
7017
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
7018
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
7019
+ }
7020
+ }
7021
+ }
7022
+ return this.requestStream({
7023
+ method: "sampling/createMessage",
7024
+ params
7025
+ }, CreateMessageResultSchema, options);
7026
+ }
7027
+ /**
7028
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
7029
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
7030
+ *
7031
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
7032
+ * and 'taskStatus' messages before the final result.
7033
+ *
7034
+ * @example
7035
+ * ```typescript
7036
+ * const stream = server.experimental.tasks.elicitInputStream({
7037
+ * mode: 'url',
7038
+ * message: 'Please authenticate',
7039
+ * elicitationId: 'auth-123',
7040
+ * url: 'https://example.com/auth'
7041
+ * }, {
7042
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
7043
+ * });
7044
+ *
7045
+ * for await (const message of stream) {
7046
+ * switch (message.type) {
7047
+ * case 'taskCreated':
7048
+ * console.log('Task created:', message.task.taskId);
7049
+ * break;
7050
+ * case 'taskStatus':
7051
+ * console.log('Task status:', message.task.status);
7052
+ * break;
7053
+ * case 'result':
7054
+ * console.log('User action:', message.result.action);
7055
+ * break;
7056
+ * case 'error':
7057
+ * console.error('Error:', message.error);
7058
+ * break;
7059
+ * }
7060
+ * }
7061
+ * ```
7062
+ *
7063
+ * @param params - The elicitation request parameters
7064
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
7065
+ * @returns AsyncGenerator that yields ResponseMessage objects
7066
+ *
7067
+ * @experimental
7068
+ */
7069
+ elicitInputStream(params, options) {
7070
+ const clientCapabilities = this._server.getClientCapabilities();
7071
+ const mode = params.mode ?? "form";
7072
+ switch (mode) {
7073
+ case "url": {
7074
+ if (!clientCapabilities?.elicitation?.url) {
7075
+ throw new Error("Client does not support url elicitation.");
7076
+ }
7077
+ break;
7078
+ }
7079
+ case "form": {
7080
+ if (!clientCapabilities?.elicitation?.form) {
7081
+ throw new Error("Client does not support form elicitation.");
7082
+ }
7083
+ break;
7084
+ }
7085
+ }
7086
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
7087
+ return this.requestStream({
7088
+ method: "elicitation/create",
7089
+ params: normalizedParams
7090
+ }, ElicitResultSchema, options);
7091
+ }
6900
7092
  /**
6901
7093
  * Gets the current status of a task.
6902
7094
  *
@@ -9085,22 +9277,45 @@ async function auth(provider, options) {
9085
9277
  }
9086
9278
  }
9087
9279
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
9280
+ const cachedState = await provider.discoveryState?.();
9088
9281
  let resourceMetadata;
9089
9282
  let authorizationServerUrl;
9090
- try {
9091
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
9092
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
9093
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
9283
+ let metadata;
9284
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
9285
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
9286
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
9287
+ }
9288
+ if (cachedState?.authorizationServerUrl) {
9289
+ authorizationServerUrl = cachedState.authorizationServerUrl;
9290
+ resourceMetadata = cachedState.resourceMetadata;
9291
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
9292
+ if (!resourceMetadata) {
9293
+ try {
9294
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
9295
+ } catch {
9296
+ }
9094
9297
  }
9095
- } catch {
9096
- }
9097
- if (!authorizationServerUrl) {
9098
- authorizationServerUrl = new URL("/", serverUrl);
9298
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
9299
+ await provider.saveDiscoveryState?.({
9300
+ authorizationServerUrl: String(authorizationServerUrl),
9301
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
9302
+ resourceMetadata,
9303
+ authorizationServerMetadata: metadata
9304
+ });
9305
+ }
9306
+ } else {
9307
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
9308
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
9309
+ metadata = serverInfo.authorizationServerMetadata;
9310
+ resourceMetadata = serverInfo.resourceMetadata;
9311
+ await provider.saveDiscoveryState?.({
9312
+ authorizationServerUrl: String(authorizationServerUrl),
9313
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
9314
+ resourceMetadata,
9315
+ authorizationServerMetadata: metadata
9316
+ });
9099
9317
  }
9100
9318
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
9101
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
9102
- fetchFn
9103
- });
9104
9319
  let clientInformation = await Promise.resolve(provider.clientInformation());
9105
9320
  if (!clientInformation) {
9106
9321
  if (authorizationCode !== void 0) {
@@ -9355,6 +9570,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
9355
9570
  }
9356
9571
  return void 0;
9357
9572
  }
9573
+ async function discoverOAuthServerInfo(serverUrl, opts) {
9574
+ let resourceMetadata;
9575
+ let authorizationServerUrl;
9576
+ try {
9577
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
9578
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
9579
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
9580
+ }
9581
+ } catch {
9582
+ }
9583
+ if (!authorizationServerUrl) {
9584
+ authorizationServerUrl = String(new URL("/", serverUrl));
9585
+ }
9586
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
9587
+ return {
9588
+ authorizationServerUrl,
9589
+ authorizationServerMetadata,
9590
+ resourceMetadata
9591
+ };
9592
+ }
9358
9593
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
9359
9594
  let authorizationUrl;
9360
9595
  if (metadata) {
@@ -10219,18 +10454,6 @@ var cleanToolSchema = (schema) => {
10219
10454
  import { cwd } from "node:process";
10220
10455
  import process8 from "node:process";
10221
10456
  import { createHash } from "node:crypto";
10222
- var mcpClientPool = /* @__PURE__ */ new Map();
10223
- var mcpClientConnecting = /* @__PURE__ */ new Map();
10224
- var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
10225
- function defSignature(def) {
10226
- const defCopy = {
10227
- ...def
10228
- };
10229
- if (defCopy.transportType === "memory" || defCopy.transport) {
10230
- return `memory:${Date.now()}:${Math.random()}`;
10231
- }
10232
- return JSON.stringify(defCopy);
10233
- }
10234
10457
  function createTransport(def) {
10235
10458
  const defAny = def;
10236
10459
  const explicitType = defAny.transportType || defAny.type;
@@ -10278,90 +10501,43 @@ function createTransport(def) {
10278
10501
  }
10279
10502
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
10280
10503
  }
10281
- async function getOrCreateMcpClient(defKey, def) {
10282
- const pooled = mcpClientPool.get(defKey);
10283
- if (pooled) {
10284
- pooled.refCount += 1;
10285
- return pooled.client;
10286
- }
10287
- const existingConnecting = mcpClientConnecting.get(defKey);
10288
- if (existingConnecting) {
10289
- const client = await existingConnecting;
10290
- const entry = mcpClientPool.get(defKey);
10291
- if (entry) entry.refCount += 1;
10292
- return client;
10293
- }
10294
- const transport = createTransport(def);
10295
- const connecting = (async () => {
10296
- const client = new Client({
10297
- name: `mcp_${shortHash(defSignature(def))}`,
10298
- version: "1.0.0"
10299
- });
10300
- await client.connect(transport, {
10301
- timeout: 6e4 * 10
10302
- });
10303
- return client;
10304
- })();
10305
- mcpClientConnecting.set(defKey, connecting);
10306
- try {
10307
- const client = await connecting;
10308
- mcpClientPool.set(defKey, {
10309
- client,
10310
- refCount: 1
10311
- });
10312
- return client;
10313
- } finally {
10314
- mcpClientConnecting.delete(defKey);
10504
+ function defSignature(def) {
10505
+ const defCopy = {
10506
+ ...def
10507
+ };
10508
+ if (defCopy.transportType === "memory" || defCopy.transport) {
10509
+ return `memory:${Date.now()}:${Math.random()}`;
10315
10510
  }
10511
+ return JSON.stringify(defCopy);
10316
10512
  }
10317
- async function releaseMcpClient(defKey) {
10318
- const entry = mcpClientPool.get(defKey);
10319
- if (!entry) return;
10320
- entry.refCount -= 1;
10321
- if (entry.refCount <= 0) {
10322
- mcpClientPool.delete(defKey);
10323
- try {
10324
- await entry.client.close();
10325
- } catch (err) {
10326
- console.error("Error closing MCP client:", err);
10327
- }
10328
- }
10513
+ var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
10514
+ async function createMcpClient(def) {
10515
+ const transport = createTransport(def);
10516
+ const client = new Client({
10517
+ name: `mcp_${shortHash(defSignature(def))}`,
10518
+ version: "1.0.0"
10519
+ });
10520
+ await client.connect(transport, {
10521
+ timeout: 6e4 * 10
10522
+ });
10523
+ return client;
10329
10524
  }
10330
- var cleanupAllPooledClients = async () => {
10331
- const entries = Array.from(mcpClientPool.entries());
10332
- mcpClientPool.clear();
10333
- await Promise.all(entries.map(async ([, { client }]) => {
10334
- try {
10335
- await client.close();
10336
- } catch (err) {
10337
- console.error("Error closing MCP client:", err);
10338
- }
10339
- }));
10340
- };
10341
- process8.once?.("exit", () => {
10342
- cleanupAllPooledClients();
10343
- });
10344
- process8.once?.("SIGINT", () => {
10345
- cleanupAllPooledClients().finally(() => process8.exit(0));
10346
- });
10347
10525
  async function composeMcpDepTools(mcpConfig, filterIn) {
10348
10526
  const allTools = {};
10349
10527
  const allClients = {};
10350
- const acquiredKeys = [];
10528
+ const clientsToClose = [];
10351
10529
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
10352
10530
  const def = definition;
10353
10531
  if (def.disabled) continue;
10354
- const defKey = shortHash(defSignature(def));
10355
- const serverId = name;
10356
10532
  try {
10357
- const client = await getOrCreateMcpClient(defKey, def);
10358
- acquiredKeys.push(defKey);
10359
- allClients[serverId] = client;
10533
+ const client = await createMcpClient(def);
10534
+ clientsToClose.push(client);
10535
+ allClients[name] = client;
10360
10536
  const { tools } = await client.listTools();
10361
10537
  tools.forEach((tool2) => {
10362
10538
  const toolNameWithScope = `${name}.${tool2.name}`;
10363
10539
  const internalToolName = tool2.name;
10364
- const rawToolId = `${serverId}_${internalToolName}`;
10540
+ const rawToolId = `${name}_${internalToolName}`;
10365
10541
  const toolId = sanitizePropertyKey(rawToolId);
10366
10542
  if (filterIn && !filterIn({
10367
10543
  action: internalToolName,
@@ -10373,7 +10549,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
10373
10549
  })) {
10374
10550
  return;
10375
10551
  }
10376
- const execute = (args) => allClients[serverId].callTool({
10552
+ const execute = (args) => allClients[name].callTool({
10377
10553
  name: internalToolName,
10378
10554
  arguments: args
10379
10555
  }, void 0, {
@@ -10390,10 +10566,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
10390
10566
  }
10391
10567
  }
10392
10568
  const cleanupClients = async () => {
10393
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
10394
- acquiredKeys.length = 0;
10395
- Object.keys(allTools).forEach((key) => delete allTools[key]);
10396
- Object.keys(allClients).forEach((key) => delete allClients[key]);
10569
+ await Promise.all(clientsToClose.map((client) => {
10570
+ try {
10571
+ return client.close();
10572
+ } catch {
10573
+ }
10574
+ }));
10397
10575
  };
10398
10576
  return {
10399
10577
  tools: allTools,