@mcpc-tech/cli 0.1.49 → 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 +465 -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 +445 -265
  7. package/index.cjs +463 -267
  8. package/index.mjs +465 -267
  9. package/package.json +1 -1
  10. package/server.cjs +463 -267
  11. package/server.mjs +465 -267
package/bin.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
1
3
  var __create = Object.create;
2
4
  var __defProp = Object.defineProperty;
3
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -2383,7 +2385,7 @@ if (typeof global.crypto === "undefined") {
2383
2385
  var outgoingEnded = Symbol("outgoingEnded");
2384
2386
 
2385
2387
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
2386
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
2388
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
2387
2389
  var LETTER_REGEXP = /[A-Za-z]/;
2388
2390
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
2389
2391
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -2394,12 +2396,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
2394
2396
  function isNumber(string3) {
2395
2397
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
2396
2398
  }
2399
+ function isConstructorOrProto(obj, key) {
2400
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
2401
+ }
2397
2402
  function setNested(object5, keys, value, collect = false) {
2398
2403
  keys = [
2399
2404
  ...keys
2400
2405
  ];
2401
2406
  const key = keys.pop();
2402
- 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;
2403
2412
  if (collect) {
2404
2413
  const v = object5[key];
2405
2414
  if (Array.isArray(v)) {
@@ -2530,7 +2539,7 @@ function parseArgs(args, options) {
2530
2539
  let key = groups.key;
2531
2540
  let value = groups.value;
2532
2541
  if (doubleDash2) {
2533
- if (value) {
2542
+ if (value != null) {
2534
2543
  if (booleanSet.has(key)) value = parseBooleanString(value);
2535
2544
  setArgument(key, value, arg, true);
2536
2545
  continue;
@@ -2568,6 +2577,10 @@ function parseArgs(args, options) {
2568
2577
  setArgument(letter, next, arg, true);
2569
2578
  continue;
2570
2579
  }
2580
+ if (next === "=") {
2581
+ setArgument(letter, "", arg, true);
2582
+ continue argsLoop;
2583
+ }
2571
2584
  if (LETTER_REGEXP.test(letter)) {
2572
2585
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
2573
2586
  if (groups2) {
@@ -3062,7 +3075,7 @@ Usage:
3062
3075
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
3063
3076
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
3064
3077
 
3065
- Note: For scripts/ and assets/, use appropriate tools directly.`;
3078
+ Note: For scripts/, use the bash tool with the script path to execute.`;
3066
3079
  }
3067
3080
  function createSkillsPlugin(options) {
3068
3081
  const { paths } = options;
@@ -3170,11 +3183,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
3170
3183
  try {
3171
3184
  const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
3172
3185
  const body = extractBody(content);
3186
+ const skillPathInfo = `
3187
+ ---
3188
+ Skill path: ${meta.basePath}
3189
+ `;
3173
3190
  return {
3174
3191
  content: [
3175
3192
  {
3176
3193
  type: "text",
3177
- text: body
3194
+ text: body + skillPathInfo
3178
3195
  }
3179
3196
  ]
3180
3197
  };
@@ -4045,12 +4062,29 @@ function writeFoldedLines(count) {
4045
4062
  if (count > 1) return "\n".repeat(count - 1);
4046
4063
  return "";
4047
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
+ };
4048
4084
  var LoaderState = class {
4049
- input;
4050
- length;
4085
+ #scanner;
4051
4086
  lineIndent = 0;
4052
4087
  lineStart = 0;
4053
- position = 0;
4054
4088
  line = 0;
4055
4089
  onWarning;
4056
4090
  allowDuplicateKeys;
@@ -4060,44 +4094,40 @@ var LoaderState = class {
4060
4094
  tagMap = /* @__PURE__ */ new Map();
4061
4095
  anchorMap = /* @__PURE__ */ new Map();
4062
4096
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
4063
- this.input = input;
4097
+ this.#scanner = new Scanner(input);
4064
4098
  this.onWarning = onWarning;
4065
4099
  this.allowDuplicateKeys = allowDuplicateKeys;
4066
4100
  this.implicitTypes = schema.implicitTypes;
4067
4101
  this.typeMap = schema.typeMap;
4068
- this.length = input.length;
4069
4102
  this.readIndent();
4070
4103
  }
4071
4104
  skipWhitespaces() {
4072
- let ch = this.peek();
4105
+ let ch = this.#scanner.peek();
4073
4106
  while (isWhiteSpace(ch)) {
4074
- ch = this.next();
4107
+ this.#scanner.next();
4108
+ ch = this.#scanner.peek();
4075
4109
  }
4076
4110
  }
4077
4111
  skipComment() {
4078
- let ch = this.peek();
4112
+ let ch = this.#scanner.peek();
4079
4113
  if (ch !== SHARP) return;
4080
- ch = this.next();
4114
+ this.#scanner.next();
4115
+ ch = this.#scanner.peek();
4081
4116
  while (ch !== 0 && !isEOL(ch)) {
4082
- ch = this.next();
4117
+ this.#scanner.next();
4118
+ ch = this.#scanner.peek();
4083
4119
  }
4084
4120
  }
4085
4121
  readIndent() {
4086
- let char = this.peek();
4087
- while (char === SPACE) {
4122
+ let ch = this.#scanner.peek();
4123
+ while (ch === SPACE) {
4088
4124
  this.lineIndent += 1;
4089
- char = this.next();
4125
+ this.#scanner.next();
4126
+ ch = this.#scanner.peek();
4090
4127
  }
4091
4128
  }
4092
- peek(offset = 0) {
4093
- return this.input.charCodeAt(this.position + offset);
4094
- }
4095
- next() {
4096
- this.position += 1;
4097
- return this.peek();
4098
- }
4099
4129
  #createError(message) {
4100
- 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);
4101
4131
  return new SyntaxError(`${message} ${mark}`);
4102
4132
  }
4103
4133
  dispatchWarning(message) {
@@ -4142,7 +4172,7 @@ var LoaderState = class {
4142
4172
  }
4143
4173
  captureSegment(start, end, checkJson) {
4144
4174
  if (start < end) {
4145
- const result = this.input.slice(start, end);
4175
+ const result = this.#scanner.source.slice(start, end);
4146
4176
  if (checkJson) {
4147
4177
  for (let position = 0; position < result.length; position++) {
4148
4178
  const character = result.charCodeAt(position);
@@ -4160,21 +4190,21 @@ var LoaderState = class {
4160
4190
  let detected = false;
4161
4191
  const result = [];
4162
4192
  if (anchor !== null) this.anchorMap.set(anchor, result);
4163
- let ch = this.peek();
4193
+ let ch = this.#scanner.peek();
4164
4194
  while (ch !== 0) {
4165
4195
  if (ch !== MINUS) {
4166
4196
  break;
4167
4197
  }
4168
- const following = this.peek(1);
4198
+ const following = this.#scanner.peek(1);
4169
4199
  if (!isWhiteSpaceOrEOL(following)) {
4170
4200
  break;
4171
4201
  }
4172
4202
  detected = true;
4173
- this.position++;
4203
+ this.#scanner.next();
4174
4204
  if (this.skipSeparationSpace(true, -1)) {
4175
4205
  if (this.lineIndent <= nodeIndent) {
4176
4206
  result.push(null);
4177
- ch = this.peek();
4207
+ ch = this.#scanner.peek();
4178
4208
  continue;
4179
4209
  }
4180
4210
  }
@@ -4187,7 +4217,7 @@ var LoaderState = class {
4187
4217
  });
4188
4218
  if (newState) result.push(newState.result);
4189
4219
  this.skipSeparationSpace(true, -1);
4190
- ch = this.peek();
4220
+ ch = this.#scanner.peek();
4191
4221
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
4192
4222
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
4193
4223
  } else if (this.lineIndent < nodeIndent) {
@@ -4243,7 +4273,7 @@ var LoaderState = class {
4243
4273
  } else {
4244
4274
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
4245
4275
  this.line = startLine || this.line;
4246
- this.position = startPos || this.position;
4276
+ this.#scanner.position = startPos || this.#scanner.position;
4247
4277
  throw this.#createError("Cannot store mapping pair: duplicated key");
4248
4278
  }
4249
4279
  Object.defineProperty(result, keyNode, {
@@ -4257,37 +4287,37 @@ var LoaderState = class {
4257
4287
  return result;
4258
4288
  }
4259
4289
  readLineBreak() {
4260
- const ch = this.peek();
4290
+ const ch = this.#scanner.peek();
4261
4291
  if (ch === LINE_FEED) {
4262
- this.position++;
4292
+ this.#scanner.next();
4263
4293
  } else if (ch === CARRIAGE_RETURN) {
4264
- this.position++;
4265
- if (this.peek() === LINE_FEED) {
4266
- this.position++;
4294
+ this.#scanner.next();
4295
+ if (this.#scanner.peek() === LINE_FEED) {
4296
+ this.#scanner.next();
4267
4297
  }
4268
4298
  } else {
4269
4299
  throw this.#createError("Cannot read line: line break not found");
4270
4300
  }
4271
4301
  this.line += 1;
4272
- this.lineStart = this.position;
4302
+ this.lineStart = this.#scanner.position;
4273
4303
  }
4274
4304
  skipSeparationSpace(allowComments, checkIndent) {
4275
4305
  let lineBreaks = 0;
4276
- let ch = this.peek();
4306
+ let ch = this.#scanner.peek();
4277
4307
  while (ch !== 0) {
4278
4308
  this.skipWhitespaces();
4279
- ch = this.peek();
4309
+ ch = this.#scanner.peek();
4280
4310
  if (allowComments) {
4281
4311
  this.skipComment();
4282
- ch = this.peek();
4312
+ ch = this.#scanner.peek();
4283
4313
  }
4284
4314
  if (isEOL(ch)) {
4285
4315
  this.readLineBreak();
4286
- ch = this.peek();
4316
+ ch = this.#scanner.peek();
4287
4317
  lineBreaks++;
4288
4318
  this.lineIndent = 0;
4289
4319
  this.readIndent();
4290
- ch = this.peek();
4320
+ ch = this.#scanner.peek();
4291
4321
  } else {
4292
4322
  break;
4293
4323
  }
@@ -4298,9 +4328,9 @@ var LoaderState = class {
4298
4328
  return lineBreaks;
4299
4329
  }
4300
4330
  testDocumentSeparator() {
4301
- let ch = this.peek();
4302
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
4303
- 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);
4304
4334
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
4305
4335
  return true;
4306
4336
  }
@@ -4308,34 +4338,34 @@ var LoaderState = class {
4308
4338
  return false;
4309
4339
  }
4310
4340
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
4311
- let ch = this.peek();
4341
+ let ch = this.#scanner.peek();
4312
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) {
4313
4343
  return;
4314
4344
  }
4315
4345
  let following;
4316
4346
  if (ch === QUESTION || ch === MINUS) {
4317
- following = this.peek(1);
4347
+ following = this.#scanner.peek(1);
4318
4348
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
4319
4349
  return;
4320
4350
  }
4321
4351
  }
4322
4352
  let result = "";
4323
- let captureEnd = this.position;
4324
- let captureStart = this.position;
4353
+ let captureEnd = this.#scanner.position;
4354
+ let captureStart = this.#scanner.position;
4325
4355
  let hasPendingContent = false;
4326
4356
  let line = 0;
4327
4357
  while (ch !== 0) {
4328
4358
  if (ch === COLON) {
4329
- following = this.peek(1);
4359
+ following = this.#scanner.peek(1);
4330
4360
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
4331
4361
  break;
4332
4362
  }
4333
4363
  } else if (ch === SHARP) {
4334
- const preceding = this.peek(-1);
4364
+ const preceding = this.#scanner.peek(-1);
4335
4365
  if (isWhiteSpaceOrEOL(preceding)) {
4336
4366
  break;
4337
4367
  }
4338
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
4368
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
4339
4369
  break;
4340
4370
  } else if (isEOL(ch)) {
4341
4371
  line = this.line;
@@ -4344,10 +4374,10 @@ var LoaderState = class {
4344
4374
  this.skipSeparationSpace(false, -1);
4345
4375
  if (this.lineIndent >= nodeIndent) {
4346
4376
  hasPendingContent = true;
4347
- ch = this.peek();
4377
+ ch = this.#scanner.peek();
4348
4378
  continue;
4349
4379
  } else {
4350
- this.position = captureEnd;
4380
+ this.#scanner.position = captureEnd;
4351
4381
  this.line = line;
4352
4382
  this.lineStart = lineStart;
4353
4383
  this.lineIndent = lineIndent;
@@ -4358,13 +4388,14 @@ var LoaderState = class {
4358
4388
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
4359
4389
  if (segment2) result += segment2;
4360
4390
  result += writeFoldedLines(this.line - line);
4361
- captureStart = captureEnd = this.position;
4391
+ captureStart = captureEnd = this.#scanner.position;
4362
4392
  hasPendingContent = false;
4363
4393
  }
4364
4394
  if (!isWhiteSpace(ch)) {
4365
- captureEnd = this.position + 1;
4395
+ captureEnd = this.#scanner.position + 1;
4366
4396
  }
4367
- ch = this.next();
4397
+ this.#scanner.next();
4398
+ ch = this.#scanner.peek();
4368
4399
  }
4369
4400
  const segment = this.captureSegment(captureStart, captureEnd, false);
4370
4401
  if (segment) result += segment;
@@ -4377,22 +4408,23 @@ var LoaderState = class {
4377
4408
  };
4378
4409
  }
4379
4410
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
4380
- let ch = this.peek();
4411
+ let ch = this.#scanner.peek();
4381
4412
  if (ch !== SINGLE_QUOTE) return;
4382
4413
  let result = "";
4383
- this.position++;
4384
- let captureStart = this.position;
4385
- let captureEnd = this.position;
4386
- ch = this.peek();
4414
+ this.#scanner.next();
4415
+ let captureStart = this.#scanner.position;
4416
+ let captureEnd = this.#scanner.position;
4417
+ ch = this.#scanner.peek();
4387
4418
  while (ch !== 0) {
4388
4419
  if (ch === SINGLE_QUOTE) {
4389
- const segment = this.captureSegment(captureStart, this.position, true);
4420
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4390
4421
  if (segment) result += segment;
4391
- ch = this.next();
4422
+ this.#scanner.next();
4423
+ ch = this.#scanner.peek();
4392
4424
  if (ch === SINGLE_QUOTE) {
4393
- captureStart = this.position;
4394
- this.position++;
4395
- captureEnd = this.position;
4425
+ captureStart = this.#scanner.position;
4426
+ this.#scanner.next();
4427
+ captureEnd = this.#scanner.position;
4396
4428
  } else {
4397
4429
  if (anchor !== null) this.anchorMap.set(anchor, result);
4398
4430
  return {
@@ -4406,31 +4438,31 @@ var LoaderState = class {
4406
4438
  const segment = this.captureSegment(captureStart, captureEnd, true);
4407
4439
  if (segment) result += segment;
4408
4440
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
4409
- captureStart = captureEnd = this.position;
4410
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
4441
+ captureStart = captureEnd = this.#scanner.position;
4442
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
4411
4443
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
4412
4444
  } else {
4413
- this.position++;
4414
- captureEnd = this.position;
4445
+ this.#scanner.next();
4446
+ captureEnd = this.#scanner.position;
4415
4447
  }
4416
- ch = this.peek();
4448
+ ch = this.#scanner.peek();
4417
4449
  }
4418
4450
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
4419
4451
  }
4420
4452
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
4421
- let ch = this.peek();
4453
+ let ch = this.#scanner.peek();
4422
4454
  if (ch !== DOUBLE_QUOTE) return;
4423
4455
  let result = "";
4424
- this.position++;
4425
- let captureEnd = this.position;
4426
- let captureStart = this.position;
4456
+ this.#scanner.next();
4457
+ let captureEnd = this.#scanner.position;
4458
+ let captureStart = this.#scanner.position;
4427
4459
  let tmp;
4428
- ch = this.peek();
4460
+ ch = this.#scanner.peek();
4429
4461
  while (ch !== 0) {
4430
4462
  if (ch === DOUBLE_QUOTE) {
4431
- const segment = this.captureSegment(captureStart, this.position, true);
4463
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4432
4464
  if (segment) result += segment;
4433
- this.position++;
4465
+ this.#scanner.next();
4434
4466
  if (anchor !== null) this.anchorMap.set(anchor, result);
4435
4467
  return {
4436
4468
  tag,
@@ -4440,19 +4472,21 @@ var LoaderState = class {
4440
4472
  };
4441
4473
  }
4442
4474
  if (ch === BACKSLASH) {
4443
- const segment = this.captureSegment(captureStart, this.position, true);
4475
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
4444
4476
  if (segment) result += segment;
4445
- ch = this.next();
4477
+ this.#scanner.next();
4478
+ ch = this.#scanner.peek();
4446
4479
  if (isEOL(ch)) {
4447
4480
  this.skipSeparationSpace(false, nodeIndent);
4448
4481
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
4449
4482
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
4450
- this.position++;
4483
+ this.#scanner.next();
4451
4484
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
4452
4485
  let hexLength = tmp;
4453
4486
  let hexResult = 0;
4454
4487
  for (; hexLength > 0; hexLength--) {
4455
- ch = this.next();
4488
+ this.#scanner.next();
4489
+ ch = this.#scanner.peek();
4456
4490
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
4457
4491
  hexResult = (hexResult << 4) + tmp;
4458
4492
  } else {
@@ -4460,28 +4494,28 @@ var LoaderState = class {
4460
4494
  }
4461
4495
  }
4462
4496
  result += codepointToChar(hexResult);
4463
- this.position++;
4497
+ this.#scanner.next();
4464
4498
  } else {
4465
4499
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
4466
4500
  }
4467
- captureStart = captureEnd = this.position;
4501
+ captureStart = captureEnd = this.#scanner.position;
4468
4502
  } else if (isEOL(ch)) {
4469
4503
  const segment = this.captureSegment(captureStart, captureEnd, true);
4470
4504
  if (segment) result += segment;
4471
4505
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
4472
- captureStart = captureEnd = this.position;
4473
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
4506
+ captureStart = captureEnd = this.#scanner.position;
4507
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
4474
4508
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
4475
4509
  } else {
4476
- this.position++;
4477
- captureEnd = this.position;
4510
+ this.#scanner.next();
4511
+ captureEnd = this.#scanner.position;
4478
4512
  }
4479
- ch = this.peek();
4513
+ ch = this.#scanner.peek();
4480
4514
  }
4481
4515
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
4482
4516
  }
4483
4517
  readFlowCollection(tag, anchor, nodeIndent) {
4484
- let ch = this.peek();
4518
+ let ch = this.#scanner.peek();
4485
4519
  let terminator;
4486
4520
  let isMapping = true;
4487
4521
  let result = {};
@@ -4495,7 +4529,8 @@ var LoaderState = class {
4495
4529
  return;
4496
4530
  }
4497
4531
  if (anchor !== null) this.anchorMap.set(anchor, result);
4498
- ch = this.next();
4532
+ this.#scanner.next();
4533
+ ch = this.#scanner.peek();
4499
4534
  let readNext = true;
4500
4535
  let valueNode = null;
4501
4536
  let keyNode = null;
@@ -4507,9 +4542,9 @@ var LoaderState = class {
4507
4542
  const overridableKeys = /* @__PURE__ */ new Set();
4508
4543
  while (ch !== 0) {
4509
4544
  this.skipSeparationSpace(true, nodeIndent);
4510
- ch = this.peek();
4545
+ ch = this.#scanner.peek();
4511
4546
  if (ch === terminator) {
4512
- this.position++;
4547
+ this.#scanner.next();
4513
4548
  const kind = isMapping ? "mapping" : "sequence";
4514
4549
  return {
4515
4550
  tag,
@@ -4524,10 +4559,10 @@ var LoaderState = class {
4524
4559
  keyTag = keyNode = valueNode = null;
4525
4560
  isPair = isExplicitPair = false;
4526
4561
  if (ch === QUESTION) {
4527
- following = this.peek(1);
4562
+ following = this.#scanner.peek(1);
4528
4563
  if (isWhiteSpaceOrEOL(following)) {
4529
4564
  isPair = isExplicitPair = true;
4530
- this.position++;
4565
+ this.#scanner.next();
4531
4566
  this.skipSeparationSpace(true, nodeIndent);
4532
4567
  }
4533
4568
  }
@@ -4543,10 +4578,11 @@ var LoaderState = class {
4543
4578
  keyNode = newState.result;
4544
4579
  }
4545
4580
  this.skipSeparationSpace(true, nodeIndent);
4546
- ch = this.peek();
4581
+ ch = this.#scanner.peek();
4547
4582
  if ((isExplicitPair || this.line === line) && ch === COLON) {
4548
4583
  isPair = true;
4549
- ch = this.next();
4584
+ this.#scanner.next();
4585
+ ch = this.#scanner.peek();
4550
4586
  this.skipSeparationSpace(true, nodeIndent);
4551
4587
  const newState2 = this.composeNode({
4552
4588
  parentIndent: nodeIndent,
@@ -4564,10 +4600,11 @@ var LoaderState = class {
4564
4600
  result.push(keyNode);
4565
4601
  }
4566
4602
  this.skipSeparationSpace(true, nodeIndent);
4567
- ch = this.peek();
4603
+ ch = this.#scanner.peek();
4568
4604
  if (ch === COMMA) {
4569
4605
  readNext = true;
4570
- ch = this.next();
4606
+ this.#scanner.next();
4607
+ ch = this.#scanner.peek();
4571
4608
  } else {
4572
4609
  readNext = false;
4573
4610
  }
@@ -4583,7 +4620,7 @@ var LoaderState = class {
4583
4620
  let textIndent = nodeIndent;
4584
4621
  let emptyLines = 0;
4585
4622
  let atMoreIndented = false;
4586
- let ch = this.peek();
4623
+ let ch = this.#scanner.peek();
4587
4624
  let folding = false;
4588
4625
  if (ch === VERTICAL_LINE) {
4589
4626
  folding = false;
@@ -4595,7 +4632,8 @@ var LoaderState = class {
4595
4632
  let result = "";
4596
4633
  let tmp = 0;
4597
4634
  while (ch !== 0) {
4598
- ch = this.next();
4635
+ this.#scanner.next();
4636
+ ch = this.#scanner.peek();
4599
4637
  if (ch === PLUS || ch === MINUS) {
4600
4638
  if (CHOMPING_CLIP === chomping) {
4601
4639
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -4618,15 +4656,16 @@ var LoaderState = class {
4618
4656
  if (isWhiteSpace(ch)) {
4619
4657
  this.skipWhitespaces();
4620
4658
  this.skipComment();
4621
- ch = this.peek();
4659
+ ch = this.#scanner.peek();
4622
4660
  }
4623
4661
  while (ch !== 0) {
4624
4662
  this.readLineBreak();
4625
4663
  this.lineIndent = 0;
4626
- ch = this.peek();
4664
+ ch = this.#scanner.peek();
4627
4665
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
4628
4666
  this.lineIndent++;
4629
- ch = this.next();
4667
+ this.#scanner.next();
4668
+ ch = this.#scanner.peek();
4630
4669
  }
4631
4670
  if (!detectedIndent && this.lineIndent > textIndent) {
4632
4671
  textIndent = this.lineIndent;
@@ -4665,11 +4704,12 @@ var LoaderState = class {
4665
4704
  didReadContent = true;
4666
4705
  detectedIndent = true;
4667
4706
  emptyLines = 0;
4668
- const captureStart = this.position;
4707
+ const captureStart = this.#scanner.position;
4669
4708
  while (!isEOL(ch) && ch !== 0) {
4670
- ch = this.next();
4709
+ this.#scanner.next();
4710
+ ch = this.#scanner.peek();
4671
4711
  }
4672
- const segment = this.captureSegment(captureStart, this.position, false);
4712
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
4673
4713
  if (segment) result += segment;
4674
4714
  }
4675
4715
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -4692,11 +4732,11 @@ var LoaderState = class {
4692
4732
  let atExplicitKey = false;
4693
4733
  let detected = false;
4694
4734
  if (anchor !== null) this.anchorMap.set(anchor, result);
4695
- let ch = this.peek();
4735
+ let ch = this.#scanner.peek();
4696
4736
  while (ch !== 0) {
4697
- const following = this.peek(1);
4737
+ const following = this.#scanner.peek(1);
4698
4738
  line = this.line;
4699
- pos = this.position;
4739
+ pos = this.#scanner.position;
4700
4740
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
4701
4741
  if (ch === QUESTION) {
4702
4742
  if (atExplicitKey) {
@@ -4714,7 +4754,7 @@ var LoaderState = class {
4714
4754
  } else {
4715
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");
4716
4756
  }
4717
- this.position += 1;
4757
+ this.#scanner.next();
4718
4758
  ch = following;
4719
4759
  } else {
4720
4760
  const newState = this.composeNode({
@@ -4725,11 +4765,12 @@ var LoaderState = class {
4725
4765
  });
4726
4766
  if (!newState) break;
4727
4767
  if (this.line === line) {
4728
- ch = this.peek();
4768
+ ch = this.#scanner.peek();
4729
4769
  this.skipWhitespaces();
4730
- ch = this.peek();
4770
+ ch = this.#scanner.peek();
4731
4771
  if (ch === COLON) {
4732
- ch = this.next();
4772
+ this.#scanner.next();
4773
+ ch = this.#scanner.peek();
4733
4774
  if (!isWhiteSpaceOrEOL(ch)) {
4734
4775
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
4735
4776
  }
@@ -4786,7 +4827,7 @@ var LoaderState = class {
4786
4827
  keyTag = keyNode = valueNode = null;
4787
4828
  }
4788
4829
  this.skipSeparationSpace(true, -1);
4789
- ch = this.peek();
4830
+ ch = this.#scanner.peek();
4790
4831
  }
4791
4832
  if (this.lineIndent > nodeIndent && ch !== 0) {
4792
4833
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -4809,30 +4850,35 @@ var LoaderState = class {
4809
4850
  let isNamed = false;
4810
4851
  let tagHandle = "";
4811
4852
  let tagName;
4812
- let ch = this.peek();
4853
+ let ch = this.#scanner.peek();
4813
4854
  if (ch !== EXCLAMATION) return;
4814
4855
  if (tag !== null) {
4815
4856
  throw this.#createError("Cannot read tag property: duplication of a tag property");
4816
4857
  }
4817
- ch = this.next();
4858
+ this.#scanner.next();
4859
+ ch = this.#scanner.peek();
4818
4860
  if (ch === SMALLER_THAN) {
4819
4861
  isVerbatim = true;
4820
- ch = this.next();
4862
+ this.#scanner.next();
4863
+ ch = this.#scanner.peek();
4821
4864
  } else if (ch === EXCLAMATION) {
4822
4865
  isNamed = true;
4823
4866
  tagHandle = "!!";
4824
- ch = this.next();
4867
+ this.#scanner.next();
4868
+ ch = this.#scanner.peek();
4825
4869
  } else {
4826
4870
  tagHandle = "!";
4827
4871
  }
4828
- let position = this.position;
4872
+ let position = this.#scanner.position;
4829
4873
  if (isVerbatim) {
4830
4874
  do {
4831
- ch = this.next();
4875
+ this.#scanner.next();
4876
+ ch = this.#scanner.peek();
4832
4877
  } while (ch !== 0 && ch !== GREATER_THAN);
4833
- if (this.position < this.length) {
4834
- tagName = this.input.slice(position, this.position);
4835
- 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();
4836
4882
  } else {
4837
4883
  throw this.#createError("Cannot read tag property: unexpected end of stream");
4838
4884
  }
@@ -4840,19 +4886,20 @@ var LoaderState = class {
4840
4886
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
4841
4887
  if (ch === EXCLAMATION) {
4842
4888
  if (!isNamed) {
4843
- tagHandle = this.input.slice(position - 1, this.position + 1);
4889
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
4844
4890
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
4845
4891
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
4846
4892
  }
4847
4893
  isNamed = true;
4848
- position = this.position + 1;
4894
+ position = this.#scanner.position + 1;
4849
4895
  } else {
4850
4896
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
4851
4897
  }
4852
4898
  }
4853
- ch = this.next();
4899
+ this.#scanner.next();
4900
+ ch = this.#scanner.peek();
4854
4901
  }
4855
- tagName = this.input.slice(position, this.position);
4902
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
4856
4903
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
4857
4904
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
4858
4905
  }
@@ -4872,32 +4919,36 @@ var LoaderState = class {
4872
4919
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
4873
4920
  }
4874
4921
  readAnchorProperty(anchor) {
4875
- let ch = this.peek();
4922
+ let ch = this.#scanner.peek();
4876
4923
  if (ch !== AMPERSAND) return;
4877
4924
  if (anchor !== null) {
4878
4925
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
4879
4926
  }
4880
- ch = this.next();
4881
- const position = this.position;
4927
+ this.#scanner.next();
4928
+ ch = this.#scanner.peek();
4929
+ const position = this.#scanner.position;
4882
4930
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
4883
- ch = this.next();
4931
+ this.#scanner.next();
4932
+ ch = this.#scanner.peek();
4884
4933
  }
4885
- if (this.position === position) {
4934
+ if (this.#scanner.position === position) {
4886
4935
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
4887
4936
  }
4888
- return this.input.slice(position, this.position);
4937
+ return this.#scanner.source.slice(position, this.#scanner.position);
4889
4938
  }
4890
4939
  readAlias() {
4891
- if (this.peek() !== ASTERISK) return;
4892
- let ch = this.next();
4893
- 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;
4894
4944
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
4895
- ch = this.next();
4945
+ this.#scanner.next();
4946
+ ch = this.#scanner.peek();
4896
4947
  }
4897
- if (this.position === position) {
4948
+ if (this.#scanner.position === position) {
4898
4949
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
4899
4950
  }
4900
- const alias = this.input.slice(position, this.position);
4951
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
4901
4952
  if (!this.anchorMap.has(alias)) {
4902
4953
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
4903
4954
  }
@@ -4980,7 +5031,7 @@ var LoaderState = class {
4980
5031
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
4981
5032
  const flowIndent = cond ? parentIndent : parentIndent + 1;
4982
5033
  if (allowBlockCollections) {
4983
- const blockIndent = this.position - this.lineStart;
5034
+ const blockIndent = this.#scanner.position - this.lineStart;
4984
5035
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
4985
5036
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
4986
5037
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -5014,7 +5065,7 @@ var LoaderState = class {
5014
5065
  return this.resolveTag(plainScalarState);
5015
5066
  }
5016
5067
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
5017
- const blockIndent = this.position - this.lineStart;
5068
+ const blockIndent = this.#scanner.position - this.lineStart;
5018
5069
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
5019
5070
  if (newState2) return this.resolveTag(newState2);
5020
5071
  }
@@ -5029,20 +5080,22 @@ var LoaderState = class {
5029
5080
  readDirectives() {
5030
5081
  let hasDirectives = false;
5031
5082
  let version = null;
5032
- let ch = this.peek();
5083
+ let ch = this.#scanner.peek();
5033
5084
  while (ch !== 0) {
5034
5085
  this.skipSeparationSpace(true, -1);
5035
- ch = this.peek();
5086
+ ch = this.#scanner.peek();
5036
5087
  if (this.lineIndent > 0 || ch !== PERCENT) {
5037
5088
  break;
5038
5089
  }
5039
5090
  hasDirectives = true;
5040
- ch = this.next();
5041
- let position = this.position;
5091
+ this.#scanner.next();
5092
+ ch = this.#scanner.peek();
5093
+ let position = this.#scanner.position;
5042
5094
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
5043
- ch = this.next();
5095
+ this.#scanner.next();
5096
+ ch = this.#scanner.peek();
5044
5097
  }
5045
- const directiveName = this.input.slice(position, this.position);
5098
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
5046
5099
  const directiveArgs = [];
5047
5100
  if (directiveName.length < 1) {
5048
5101
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -5050,13 +5103,14 @@ var LoaderState = class {
5050
5103
  while (ch !== 0) {
5051
5104
  this.skipWhitespaces();
5052
5105
  this.skipComment();
5053
- ch = this.peek();
5106
+ ch = this.#scanner.peek();
5054
5107
  if (isEOL(ch)) break;
5055
- position = this.position;
5108
+ position = this.#scanner.position;
5056
5109
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
5057
- ch = this.next();
5110
+ this.#scanner.next();
5111
+ ch = this.#scanner.peek();
5058
5112
  }
5059
- directiveArgs.push(this.input.slice(position, this.position));
5113
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
5060
5114
  }
5061
5115
  if (ch !== 0) this.readLineBreak();
5062
5116
  switch (directiveName) {
@@ -5073,20 +5127,20 @@ var LoaderState = class {
5073
5127
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
5074
5128
  break;
5075
5129
  }
5076
- ch = this.peek();
5130
+ ch = this.#scanner.peek();
5077
5131
  }
5078
5132
  return hasDirectives;
5079
5133
  }
5080
5134
  readDocument() {
5081
- const documentStart = this.position;
5135
+ const documentStart = this.#scanner.position;
5082
5136
  this.checkLineBreaks = false;
5083
5137
  this.tagMap = /* @__PURE__ */ new Map();
5084
5138
  this.anchorMap = /* @__PURE__ */ new Map();
5085
5139
  const hasDirectives = this.readDirectives();
5086
5140
  this.skipSeparationSpace(true, -1);
5087
5141
  let result = null;
5088
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
5089
- 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;
5090
5144
  this.skipSeparationSpace(true, -1);
5091
5145
  } else if (hasDirectives) {
5092
5146
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -5099,21 +5153,21 @@ var LoaderState = class {
5099
5153
  });
5100
5154
  if (newState) result = newState.result;
5101
5155
  this.skipSeparationSpace(true, -1);
5102
- 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))) {
5103
5157
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
5104
5158
  }
5105
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
5106
- if (this.peek() === DOT) {
5107
- this.position += 3;
5159
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5160
+ if (this.#scanner.peek() === DOT) {
5161
+ this.#scanner.position += 3;
5108
5162
  this.skipSeparationSpace(true, -1);
5109
5163
  }
5110
- } else if (this.position < this.length - 1) {
5164
+ } else if (!this.#scanner.eof()) {
5111
5165
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
5112
5166
  }
5113
5167
  return result;
5114
5168
  }
5115
5169
  *readDocuments() {
5116
- while (this.position < this.length - 1) {
5170
+ while (!this.#scanner.eof()) {
5117
5171
  yield this.readDocument();
5118
5172
  }
5119
5173
  }
@@ -5126,7 +5180,6 @@ function sanitizeInput(input) {
5126
5180
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
5127
5181
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
5128
5182
  }
5129
- input += "\0";
5130
5183
  return input;
5131
5184
  }
5132
5185
  function parse(content, options = {}) {
@@ -5286,7 +5339,7 @@ function getDefaultAgents() {
5286
5339
  }
5287
5340
 
5288
5341
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
5289
- var CLI_VERSION = "0.1.44";
5342
+ var CLI_VERSION = "0.1.51";
5290
5343
  function extractServerName(command, commandArgs) {
5291
5344
  for (const arg of commandArgs) {
5292
5345
  if (!arg.startsWith("-")) {
@@ -6895,6 +6948,147 @@ var ExperimentalServerTasks = class {
6895
6948
  requestStream(request, resultSchema, options) {
6896
6949
  return this._server.requestStream(request, resultSchema, options);
6897
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
+ }
6898
7092
  /**
6899
7093
  * Gets the current status of a task.
6900
7094
  *
@@ -9083,22 +9277,45 @@ async function auth(provider, options) {
9083
9277
  }
9084
9278
  }
9085
9279
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
9280
+ const cachedState = await provider.discoveryState?.();
9086
9281
  let resourceMetadata;
9087
9282
  let authorizationServerUrl;
9088
- try {
9089
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
9090
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
9091
- 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
+ }
9092
9297
  }
9093
- } catch {
9094
- }
9095
- if (!authorizationServerUrl) {
9096
- 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
+ });
9097
9317
  }
9098
9318
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
9099
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
9100
- fetchFn
9101
- });
9102
9319
  let clientInformation = await Promise.resolve(provider.clientInformation());
9103
9320
  if (!clientInformation) {
9104
9321
  if (authorizationCode !== void 0) {
@@ -9353,6 +9570,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
9353
9570
  }
9354
9571
  return void 0;
9355
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
+ }
9356
9593
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
9357
9594
  let authorizationUrl;
9358
9595
  if (metadata) {
@@ -10217,18 +10454,6 @@ var cleanToolSchema = (schema) => {
10217
10454
  import { cwd } from "node:process";
10218
10455
  import process8 from "node:process";
10219
10456
  import { createHash } from "node:crypto";
10220
- var mcpClientPool = /* @__PURE__ */ new Map();
10221
- var mcpClientConnecting = /* @__PURE__ */ new Map();
10222
- var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
10223
- function defSignature(def) {
10224
- const defCopy = {
10225
- ...def
10226
- };
10227
- if (defCopy.transportType === "memory" || defCopy.transport) {
10228
- return `memory:${Date.now()}:${Math.random()}`;
10229
- }
10230
- return JSON.stringify(defCopy);
10231
- }
10232
10457
  function createTransport(def) {
10233
10458
  const defAny = def;
10234
10459
  const explicitType = defAny.transportType || defAny.type;
@@ -10276,90 +10501,43 @@ function createTransport(def) {
10276
10501
  }
10277
10502
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
10278
10503
  }
10279
- async function getOrCreateMcpClient(defKey, def) {
10280
- const pooled = mcpClientPool.get(defKey);
10281
- if (pooled) {
10282
- pooled.refCount += 1;
10283
- return pooled.client;
10284
- }
10285
- const existingConnecting = mcpClientConnecting.get(defKey);
10286
- if (existingConnecting) {
10287
- const client = await existingConnecting;
10288
- const entry = mcpClientPool.get(defKey);
10289
- if (entry) entry.refCount += 1;
10290
- return client;
10291
- }
10292
- const transport = createTransport(def);
10293
- const connecting = (async () => {
10294
- const client = new Client({
10295
- name: `mcp_${shortHash(defSignature(def))}`,
10296
- version: "1.0.0"
10297
- });
10298
- await client.connect(transport, {
10299
- timeout: 6e4 * 10
10300
- });
10301
- return client;
10302
- })();
10303
- mcpClientConnecting.set(defKey, connecting);
10304
- try {
10305
- const client = await connecting;
10306
- mcpClientPool.set(defKey, {
10307
- client,
10308
- refCount: 1
10309
- });
10310
- return client;
10311
- } finally {
10312
- 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()}`;
10313
10510
  }
10511
+ return JSON.stringify(defCopy);
10314
10512
  }
10315
- async function releaseMcpClient(defKey) {
10316
- const entry = mcpClientPool.get(defKey);
10317
- if (!entry) return;
10318
- entry.refCount -= 1;
10319
- if (entry.refCount <= 0) {
10320
- mcpClientPool.delete(defKey);
10321
- try {
10322
- await entry.client.close();
10323
- } catch (err) {
10324
- console.error("Error closing MCP client:", err);
10325
- }
10326
- }
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;
10327
10524
  }
10328
- var cleanupAllPooledClients = async () => {
10329
- const entries = Array.from(mcpClientPool.entries());
10330
- mcpClientPool.clear();
10331
- await Promise.all(entries.map(async ([, { client }]) => {
10332
- try {
10333
- await client.close();
10334
- } catch (err) {
10335
- console.error("Error closing MCP client:", err);
10336
- }
10337
- }));
10338
- };
10339
- process8.once?.("exit", () => {
10340
- cleanupAllPooledClients();
10341
- });
10342
- process8.once?.("SIGINT", () => {
10343
- cleanupAllPooledClients().finally(() => process8.exit(0));
10344
- });
10345
10525
  async function composeMcpDepTools(mcpConfig, filterIn) {
10346
10526
  const allTools = {};
10347
10527
  const allClients = {};
10348
- const acquiredKeys = [];
10528
+ const clientsToClose = [];
10349
10529
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
10350
10530
  const def = definition;
10351
10531
  if (def.disabled) continue;
10352
- const defKey = shortHash(defSignature(def));
10353
- const serverId = name;
10354
10532
  try {
10355
- const client = await getOrCreateMcpClient(defKey, def);
10356
- acquiredKeys.push(defKey);
10357
- allClients[serverId] = client;
10533
+ const client = await createMcpClient(def);
10534
+ clientsToClose.push(client);
10535
+ allClients[name] = client;
10358
10536
  const { tools } = await client.listTools();
10359
10537
  tools.forEach((tool2) => {
10360
10538
  const toolNameWithScope = `${name}.${tool2.name}`;
10361
10539
  const internalToolName = tool2.name;
10362
- const rawToolId = `${serverId}_${internalToolName}`;
10540
+ const rawToolId = `${name}_${internalToolName}`;
10363
10541
  const toolId = sanitizePropertyKey(rawToolId);
10364
10542
  if (filterIn && !filterIn({
10365
10543
  action: internalToolName,
@@ -10371,7 +10549,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
10371
10549
  })) {
10372
10550
  return;
10373
10551
  }
10374
- const execute = (args) => allClients[serverId].callTool({
10552
+ const execute = (args) => allClients[name].callTool({
10375
10553
  name: internalToolName,
10376
10554
  arguments: args
10377
10555
  }, void 0, {
@@ -10388,10 +10566,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
10388
10566
  }
10389
10567
  }
10390
10568
  const cleanupClients = async () => {
10391
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
10392
- acquiredKeys.length = 0;
10393
- Object.keys(allTools).forEach((key) => delete allTools[key]);
10394
- 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
+ }));
10395
10575
  };
10396
10576
  return {
10397
10577
  tools: allTools,