@mcpc-tech/cli 0.1.50 → 0.1.52

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 +632 -289
  2. package/app.mjs +632 -289
  3. package/bin/mcpc.cjs +630 -305
  4. package/bin/mcpc.mjs +628 -303
  5. package/bin.cjs +630 -305
  6. package/bin.mjs +628 -303
  7. package/index.cjs +652 -309
  8. package/index.mjs +650 -307
  9. package/package.json +1 -1
  10. package/server.cjs +652 -309
  11. package/server.mjs +650 -307
package/index.mjs CHANGED
@@ -509,7 +509,7 @@ var require_cross_spawn = __commonJS({
509
509
  var cp = __require("child_process");
510
510
  var parse2 = require_parse();
511
511
  var enoent = require_enoent();
512
- function spawn2(command, args, options) {
512
+ function spawn3(command, args, options) {
513
513
  const parsed = parse2(command, args, options);
514
514
  const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
515
515
  enoent.hookChildProcess(spawned, parsed);
@@ -521,8 +521,8 @@ var require_cross_spawn = __commonJS({
521
521
  result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
522
522
  return result;
523
523
  }
524
- module.exports = spawn2;
525
- module.exports.spawn = spawn2;
524
+ module.exports = spawn3;
525
+ module.exports.spawn = spawn3;
526
526
  module.exports.sync = spawnSync;
527
527
  module.exports._parse = parse2;
528
528
  module.exports._enoent = enoent;
@@ -3030,6 +3030,7 @@ data:
3030
3030
  async handleGetRequest(req) {
3031
3031
  const acceptHeader = req.headers.get("accept");
3032
3032
  if (!acceptHeader?.includes("text/event-stream")) {
3033
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
3033
3034
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
3034
3035
  }
3035
3036
  const sessionError = this.validateSession(req);
@@ -3047,6 +3048,7 @@ data:
3047
3048
  }
3048
3049
  }
3049
3050
  if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
3051
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
3050
3052
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
3051
3053
  }
3052
3054
  const encoder2 = new TextEncoder();
@@ -3086,6 +3088,7 @@ data:
3086
3088
  */
3087
3089
  async replayEvents(lastEventId) {
3088
3090
  if (!this._eventStore) {
3091
+ this.onerror?.(new Error("Event store not configured"));
3089
3092
  return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
3090
3093
  }
3091
3094
  try {
@@ -3093,9 +3096,11 @@ data:
3093
3096
  if (this._eventStore.getStreamIdForEventId) {
3094
3097
  streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
3095
3098
  if (!streamId) {
3099
+ this.onerror?.(new Error("Invalid event ID format"));
3096
3100
  return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
3097
3101
  }
3098
3102
  if (this._streamMapping.get(streamId) !== void 0) {
3103
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
3099
3104
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
3100
3105
  }
3101
3106
  }
@@ -3161,7 +3166,8 @@ data:
3161
3166
  `;
3162
3167
  controller.enqueue(encoder2.encode(eventData));
3163
3168
  return true;
3164
- } catch {
3169
+ } catch (error) {
3170
+ this.onerror?.(error);
3165
3171
  return false;
3166
3172
  }
3167
3173
  }
@@ -3169,6 +3175,7 @@ data:
3169
3175
  * Handles unsupported requests (PUT, PATCH, etc.)
3170
3176
  */
3171
3177
  handleUnsupportedRequest() {
3178
+ this.onerror?.(new Error("Method not allowed."));
3172
3179
  return new Response(JSON.stringify({
3173
3180
  jsonrpc: "2.0",
3174
3181
  error: {
@@ -3191,14 +3198,17 @@ data:
3191
3198
  try {
3192
3199
  const acceptHeader = req.headers.get("accept");
3193
3200
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
3201
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
3194
3202
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
3195
3203
  }
3196
3204
  const ct = req.headers.get("content-type");
3197
3205
  if (!ct || !ct.includes("application/json")) {
3206
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
3198
3207
  return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
3199
3208
  }
3200
3209
  const requestInfo = {
3201
- headers: Object.fromEntries(req.headers.entries())
3210
+ headers: Object.fromEntries(req.headers.entries()),
3211
+ url: new URL(req.url)
3202
3212
  };
3203
3213
  let rawMessage;
3204
3214
  if (options?.parsedBody !== void 0) {
@@ -3207,6 +3217,7 @@ data:
3207
3217
  try {
3208
3218
  rawMessage = await req.json();
3209
3219
  } catch {
3220
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
3210
3221
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
3211
3222
  }
3212
3223
  }
@@ -3218,14 +3229,17 @@ data:
3218
3229
  messages = [JSONRPCMessageSchema.parse(rawMessage)];
3219
3230
  }
3220
3231
  } catch {
3232
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
3221
3233
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
3222
3234
  }
3223
3235
  const isInitializationRequest = messages.some(isInitializeRequest);
3224
3236
  if (isInitializationRequest) {
3225
3237
  if (this._initialized && this.sessionId !== void 0) {
3238
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
3226
3239
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
3227
3240
  }
3228
3241
  if (messages.length > 1) {
3242
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
3229
3243
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
3230
3244
  }
3231
3245
  this.sessionId = this.sessionIdGenerator?.();
@@ -3351,13 +3365,16 @@ data:
3351
3365
  return void 0;
3352
3366
  }
3353
3367
  if (!this._initialized) {
3368
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
3354
3369
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
3355
3370
  }
3356
3371
  const sessionId = req.headers.get("mcp-session-id");
3357
3372
  if (!sessionId) {
3373
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
3358
3374
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
3359
3375
  }
3360
3376
  if (sessionId !== this.sessionId) {
3377
+ this.onerror?.(new Error("Session not found"));
3361
3378
  return this.createJsonErrorResponse(404, -32001, "Session not found");
3362
3379
  }
3363
3380
  return void 0;
@@ -3378,6 +3395,7 @@ data:
3378
3395
  validateProtocolVersion(req) {
3379
3396
  const protocolVersion = req.headers.get("mcp-protocol-version");
3380
3397
  if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
3398
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
3381
3399
  return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
3382
3400
  }
3383
3401
  return void 0;
@@ -3584,7 +3602,7 @@ var StreamableHTTPServerTransport = class {
3584
3602
  };
3585
3603
 
3586
3604
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
3587
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
3605
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
3588
3606
  var LETTER_REGEXP = /[A-Za-z]/;
3589
3607
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
3590
3608
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -3595,12 +3613,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
3595
3613
  function isNumber(string3) {
3596
3614
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
3597
3615
  }
3616
+ function isConstructorOrProto(obj, key) {
3617
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
3618
+ }
3598
3619
  function setNested(object5, keys, value, collect = false) {
3599
3620
  keys = [
3600
3621
  ...keys
3601
3622
  ];
3602
3623
  const key = keys.pop();
3603
- keys.forEach((key2) => object5 = object5[key2] ??= {});
3624
+ for (const k of keys) {
3625
+ if (isConstructorOrProto(object5, k)) return;
3626
+ object5 = object5[k] ??= {};
3627
+ }
3628
+ if (isConstructorOrProto(object5, key)) return;
3604
3629
  if (collect) {
3605
3630
  const v = object5[key];
3606
3631
  if (Array.isArray(v)) {
@@ -3731,7 +3756,7 @@ function parseArgs(args, options) {
3731
3756
  let key = groups.key;
3732
3757
  let value = groups.value;
3733
3758
  if (doubleDash2) {
3734
- if (value) {
3759
+ if (value != null) {
3735
3760
  if (booleanSet.has(key)) value = parseBooleanString(value);
3736
3761
  setArgument(key, value, arg, true);
3737
3762
  continue;
@@ -3769,6 +3794,10 @@ function parseArgs(args, options) {
3769
3794
  setArgument(letter, next, arg, true);
3770
3795
  continue;
3771
3796
  }
3797
+ if (next === "=") {
3798
+ setArgument(letter, "", arg, true);
3799
+ continue argsLoop;
3800
+ }
3772
3801
  if (LETTER_REGEXP.test(letter)) {
3773
3802
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
3774
3803
  if (groups2) {
@@ -3845,7 +3874,7 @@ function parseArgs(args, options) {
3845
3874
  import { mkdir, readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
3846
3875
  import { homedir } from "node:os";
3847
3876
  import { dirname, join as join3, resolve as resolve4 } from "node:path";
3848
- import process4 from "node:process";
3877
+ import process5 from "node:process";
3849
3878
 
3850
3879
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/large-result.js
3851
3880
  import { mkdtemp, writeFile } from "node:fs/promises";
@@ -4263,7 +4292,7 @@ Usage:
4263
4292
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
4264
4293
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
4265
4294
 
4266
- Note: For scripts/ and assets/, use appropriate tools directly.`;
4295
+ Note: For scripts/, use the bash tool with the script path to execute.`;
4267
4296
  }
4268
4297
  function createSkillsPlugin(options) {
4269
4298
  const { paths } = options;
@@ -4371,11 +4400,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
4371
4400
  try {
4372
4401
  const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
4373
4402
  const body = extractBody(content);
4403
+ const skillPathInfo = `
4404
+ ---
4405
+ Skill path: ${meta.basePath}
4406
+ `;
4374
4407
  return {
4375
4408
  content: [
4376
4409
  {
4377
4410
  type: "text",
4378
- text: body
4411
+ text: body + skillPathInfo
4379
4412
  }
4380
4413
  ]
4381
4414
  };
@@ -4402,6 +4435,152 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
4402
4435
  };
4403
4436
  }
4404
4437
 
4438
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/bash.js
4439
+ import { spawn } from "node:child_process";
4440
+ import process2 from "node:process";
4441
+ var DEFAULT_MAX_BYTES = 1e5;
4442
+ var DEFAULT_MAX_LINES = 2e3;
4443
+ var DEFAULT_TIMEOUT_MS = 6e4;
4444
+ function truncateOutput(stdout, stderr, maxBytes = DEFAULT_MAX_BYTES, maxLines = DEFAULT_MAX_LINES) {
4445
+ const fullOutput = (stderr ? `STDERR:
4446
+ ${stderr}
4447
+
4448
+ STDOUT:
4449
+ ` : "") + stdout;
4450
+ const lines = fullOutput.split("\n");
4451
+ if (lines.length > maxLines) {
4452
+ const truncatedLines = lines.slice(-maxLines);
4453
+ return {
4454
+ output: `[OUTPUT TRUNCATED] Showing last ${maxLines} lines of ${lines.length} total
4455
+
4456
+ ` + truncatedLines.join("\n"),
4457
+ truncated: true
4458
+ };
4459
+ }
4460
+ if (fullOutput.length > maxBytes) {
4461
+ const truncatedBytes = fullOutput.slice(-maxBytes);
4462
+ return {
4463
+ output: `[OUTPUT TRUNCATED] Showing last ${maxBytes} bytes of ${fullOutput.length} total
4464
+
4465
+ ` + truncatedBytes,
4466
+ truncated: true
4467
+ };
4468
+ }
4469
+ return {
4470
+ output: fullOutput,
4471
+ truncated: false
4472
+ };
4473
+ }
4474
+ function executeBash(command, cwd2, timeoutMs) {
4475
+ return new Promise((resolve5) => {
4476
+ const stdout = [];
4477
+ const stderr = [];
4478
+ const proc = spawn("bash", [
4479
+ "-c",
4480
+ command
4481
+ ], {
4482
+ cwd: cwd2,
4483
+ stdio: [
4484
+ "ignore",
4485
+ "pipe",
4486
+ "pipe"
4487
+ ]
4488
+ });
4489
+ proc.stdout?.on("data", (data) => {
4490
+ stdout.push(data.toString());
4491
+ });
4492
+ proc.stderr?.on("data", (data) => {
4493
+ stderr.push(data.toString());
4494
+ });
4495
+ proc.on("close", (code) => {
4496
+ resolve5({
4497
+ stdout: stdout.join(""),
4498
+ stderr: stderr.join(""),
4499
+ exitCode: code
4500
+ });
4501
+ });
4502
+ proc.on("error", (err) => {
4503
+ resolve5({
4504
+ stdout: "",
4505
+ stderr: err.message,
4506
+ exitCode: null
4507
+ });
4508
+ });
4509
+ setTimeout(() => {
4510
+ proc.kill("SIGTERM");
4511
+ resolve5({
4512
+ stdout: stdout.join(""),
4513
+ stderr: stderr.join("") + "\n\n[TIMEOUT] Command execution timed out",
4514
+ exitCode: null
4515
+ });
4516
+ }, timeoutMs);
4517
+ });
4518
+ }
4519
+ function createBashPlugin(options = {}) {
4520
+ const { maxBytes, maxLines, timeoutMs } = {
4521
+ maxBytes: DEFAULT_MAX_BYTES,
4522
+ maxLines: DEFAULT_MAX_LINES,
4523
+ timeoutMs: DEFAULT_TIMEOUT_MS,
4524
+ ...options
4525
+ };
4526
+ let serverRef = null;
4527
+ return {
4528
+ name: "plugin-bash",
4529
+ version: "1.0.0",
4530
+ // Store server reference for tool registration
4531
+ configureServer: (server) => {
4532
+ serverRef = server;
4533
+ },
4534
+ // Register bash tool with agent name prefix
4535
+ composeStart: (context2) => {
4536
+ if (!serverRef) return;
4537
+ const agentName = context2.serverName;
4538
+ const toolName = `${agentName}__bash`;
4539
+ serverRef.tool(toolName, "Execute a bash command and return its output.\n\nUse this for:\n- Running shell commands\n- Executing scripts\n- System operations\n\nNote: Output is truncated if too large.", {
4540
+ type: "object",
4541
+ properties: {
4542
+ command: {
4543
+ type: "string",
4544
+ description: "The bash command to execute"
4545
+ },
4546
+ cwd: {
4547
+ type: "string",
4548
+ description: "Optional: Working directory for the command (defaults to current directory)"
4549
+ }
4550
+ },
4551
+ required: [
4552
+ "command"
4553
+ ]
4554
+ }, async (args) => {
4555
+ const cwd2 = args.cwd || process2.cwd();
4556
+ const result = await executeBash(args.command, cwd2, timeoutMs);
4557
+ const { output, truncated } = truncateOutput(result.stdout, result.stderr, maxBytes, maxLines);
4558
+ let finalOutput = output;
4559
+ if (result.exitCode !== null && result.exitCode !== 0) {
4560
+ finalOutput = `[EXIT CODE: ${result.exitCode}]
4561
+ ` + finalOutput;
4562
+ }
4563
+ if (truncated) {
4564
+ finalOutput += `
4565
+
4566
+ [Note: Output was truncated]`;
4567
+ }
4568
+ return {
4569
+ content: [
4570
+ {
4571
+ type: "text",
4572
+ text: finalOutput
4573
+ }
4574
+ ],
4575
+ isError: result.exitCode !== null && result.exitCode !== 0
4576
+ };
4577
+ }, {
4578
+ internal: true
4579
+ });
4580
+ }
4581
+ };
4582
+ }
4583
+
4405
4584
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
4406
4585
  import { createCodeExecutionPlugin } from "@mcpc-tech/plugin-code-execution";
4407
4586
 
@@ -5246,12 +5425,29 @@ function writeFoldedLines(count) {
5246
5425
  if (count > 1) return "\n".repeat(count - 1);
5247
5426
  return "";
5248
5427
  }
5428
+ var Scanner = class {
5429
+ source;
5430
+ #length;
5431
+ position = 0;
5432
+ constructor(source) {
5433
+ source += "\0";
5434
+ this.source = source;
5435
+ this.#length = source.length;
5436
+ }
5437
+ peek(offset = 0) {
5438
+ return this.source.charCodeAt(this.position + offset);
5439
+ }
5440
+ next() {
5441
+ this.position += 1;
5442
+ }
5443
+ eof() {
5444
+ return this.position >= this.#length - 1;
5445
+ }
5446
+ };
5249
5447
  var LoaderState = class {
5250
- input;
5251
- length;
5448
+ #scanner;
5252
5449
  lineIndent = 0;
5253
5450
  lineStart = 0;
5254
- position = 0;
5255
5451
  line = 0;
5256
5452
  onWarning;
5257
5453
  allowDuplicateKeys;
@@ -5261,44 +5457,40 @@ var LoaderState = class {
5261
5457
  tagMap = /* @__PURE__ */ new Map();
5262
5458
  anchorMap = /* @__PURE__ */ new Map();
5263
5459
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
5264
- this.input = input;
5460
+ this.#scanner = new Scanner(input);
5265
5461
  this.onWarning = onWarning;
5266
5462
  this.allowDuplicateKeys = allowDuplicateKeys;
5267
5463
  this.implicitTypes = schema.implicitTypes;
5268
5464
  this.typeMap = schema.typeMap;
5269
- this.length = input.length;
5270
5465
  this.readIndent();
5271
5466
  }
5272
5467
  skipWhitespaces() {
5273
- let ch = this.peek();
5468
+ let ch = this.#scanner.peek();
5274
5469
  while (isWhiteSpace(ch)) {
5275
- ch = this.next();
5470
+ this.#scanner.next();
5471
+ ch = this.#scanner.peek();
5276
5472
  }
5277
5473
  }
5278
5474
  skipComment() {
5279
- let ch = this.peek();
5475
+ let ch = this.#scanner.peek();
5280
5476
  if (ch !== SHARP) return;
5281
- ch = this.next();
5477
+ this.#scanner.next();
5478
+ ch = this.#scanner.peek();
5282
5479
  while (ch !== 0 && !isEOL(ch)) {
5283
- ch = this.next();
5480
+ this.#scanner.next();
5481
+ ch = this.#scanner.peek();
5284
5482
  }
5285
5483
  }
5286
5484
  readIndent() {
5287
- let char = this.peek();
5288
- while (char === SPACE) {
5485
+ let ch = this.#scanner.peek();
5486
+ while (ch === SPACE) {
5289
5487
  this.lineIndent += 1;
5290
- char = this.next();
5488
+ this.#scanner.next();
5489
+ ch = this.#scanner.peek();
5291
5490
  }
5292
5491
  }
5293
- peek(offset = 0) {
5294
- return this.input.charCodeAt(this.position + offset);
5295
- }
5296
- next() {
5297
- this.position += 1;
5298
- return this.peek();
5299
- }
5300
5492
  #createError(message) {
5301
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
5493
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
5302
5494
  return new SyntaxError(`${message} ${mark}`);
5303
5495
  }
5304
5496
  dispatchWarning(message) {
@@ -5343,7 +5535,7 @@ var LoaderState = class {
5343
5535
  }
5344
5536
  captureSegment(start, end, checkJson) {
5345
5537
  if (start < end) {
5346
- const result = this.input.slice(start, end);
5538
+ const result = this.#scanner.source.slice(start, end);
5347
5539
  if (checkJson) {
5348
5540
  for (let position = 0; position < result.length; position++) {
5349
5541
  const character = result.charCodeAt(position);
@@ -5361,21 +5553,21 @@ var LoaderState = class {
5361
5553
  let detected = false;
5362
5554
  const result = [];
5363
5555
  if (anchor !== null) this.anchorMap.set(anchor, result);
5364
- let ch = this.peek();
5556
+ let ch = this.#scanner.peek();
5365
5557
  while (ch !== 0) {
5366
5558
  if (ch !== MINUS) {
5367
5559
  break;
5368
5560
  }
5369
- const following = this.peek(1);
5561
+ const following = this.#scanner.peek(1);
5370
5562
  if (!isWhiteSpaceOrEOL(following)) {
5371
5563
  break;
5372
5564
  }
5373
5565
  detected = true;
5374
- this.position++;
5566
+ this.#scanner.next();
5375
5567
  if (this.skipSeparationSpace(true, -1)) {
5376
5568
  if (this.lineIndent <= nodeIndent) {
5377
5569
  result.push(null);
5378
- ch = this.peek();
5570
+ ch = this.#scanner.peek();
5379
5571
  continue;
5380
5572
  }
5381
5573
  }
@@ -5388,7 +5580,7 @@ var LoaderState = class {
5388
5580
  });
5389
5581
  if (newState) result.push(newState.result);
5390
5582
  this.skipSeparationSpace(true, -1);
5391
- ch = this.peek();
5583
+ ch = this.#scanner.peek();
5392
5584
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
5393
5585
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
5394
5586
  } else if (this.lineIndent < nodeIndent) {
@@ -5444,7 +5636,7 @@ var LoaderState = class {
5444
5636
  } else {
5445
5637
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
5446
5638
  this.line = startLine || this.line;
5447
- this.position = startPos || this.position;
5639
+ this.#scanner.position = startPos || this.#scanner.position;
5448
5640
  throw this.#createError("Cannot store mapping pair: duplicated key");
5449
5641
  }
5450
5642
  Object.defineProperty(result, keyNode, {
@@ -5458,37 +5650,37 @@ var LoaderState = class {
5458
5650
  return result;
5459
5651
  }
5460
5652
  readLineBreak() {
5461
- const ch = this.peek();
5653
+ const ch = this.#scanner.peek();
5462
5654
  if (ch === LINE_FEED) {
5463
- this.position++;
5655
+ this.#scanner.next();
5464
5656
  } else if (ch === CARRIAGE_RETURN) {
5465
- this.position++;
5466
- if (this.peek() === LINE_FEED) {
5467
- this.position++;
5657
+ this.#scanner.next();
5658
+ if (this.#scanner.peek() === LINE_FEED) {
5659
+ this.#scanner.next();
5468
5660
  }
5469
5661
  } else {
5470
5662
  throw this.#createError("Cannot read line: line break not found");
5471
5663
  }
5472
5664
  this.line += 1;
5473
- this.lineStart = this.position;
5665
+ this.lineStart = this.#scanner.position;
5474
5666
  }
5475
5667
  skipSeparationSpace(allowComments, checkIndent) {
5476
5668
  let lineBreaks = 0;
5477
- let ch = this.peek();
5669
+ let ch = this.#scanner.peek();
5478
5670
  while (ch !== 0) {
5479
5671
  this.skipWhitespaces();
5480
- ch = this.peek();
5672
+ ch = this.#scanner.peek();
5481
5673
  if (allowComments) {
5482
5674
  this.skipComment();
5483
- ch = this.peek();
5675
+ ch = this.#scanner.peek();
5484
5676
  }
5485
5677
  if (isEOL(ch)) {
5486
5678
  this.readLineBreak();
5487
- ch = this.peek();
5679
+ ch = this.#scanner.peek();
5488
5680
  lineBreaks++;
5489
5681
  this.lineIndent = 0;
5490
5682
  this.readIndent();
5491
- ch = this.peek();
5683
+ ch = this.#scanner.peek();
5492
5684
  } else {
5493
5685
  break;
5494
5686
  }
@@ -5499,9 +5691,9 @@ var LoaderState = class {
5499
5691
  return lineBreaks;
5500
5692
  }
5501
5693
  testDocumentSeparator() {
5502
- let ch = this.peek();
5503
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
5504
- ch = this.peek(3);
5694
+ let ch = this.#scanner.peek();
5695
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
5696
+ ch = this.#scanner.peek(3);
5505
5697
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
5506
5698
  return true;
5507
5699
  }
@@ -5509,34 +5701,34 @@ var LoaderState = class {
5509
5701
  return false;
5510
5702
  }
5511
5703
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
5512
- let ch = this.peek();
5704
+ let ch = this.#scanner.peek();
5513
5705
  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) {
5514
5706
  return;
5515
5707
  }
5516
5708
  let following;
5517
5709
  if (ch === QUESTION || ch === MINUS) {
5518
- following = this.peek(1);
5710
+ following = this.#scanner.peek(1);
5519
5711
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
5520
5712
  return;
5521
5713
  }
5522
5714
  }
5523
5715
  let result = "";
5524
- let captureEnd = this.position;
5525
- let captureStart = this.position;
5716
+ let captureEnd = this.#scanner.position;
5717
+ let captureStart = this.#scanner.position;
5526
5718
  let hasPendingContent = false;
5527
5719
  let line = 0;
5528
5720
  while (ch !== 0) {
5529
5721
  if (ch === COLON) {
5530
- following = this.peek(1);
5722
+ following = this.#scanner.peek(1);
5531
5723
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
5532
5724
  break;
5533
5725
  }
5534
5726
  } else if (ch === SHARP) {
5535
- const preceding = this.peek(-1);
5727
+ const preceding = this.#scanner.peek(-1);
5536
5728
  if (isWhiteSpaceOrEOL(preceding)) {
5537
5729
  break;
5538
5730
  }
5539
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
5731
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
5540
5732
  break;
5541
5733
  } else if (isEOL(ch)) {
5542
5734
  line = this.line;
@@ -5545,10 +5737,10 @@ var LoaderState = class {
5545
5737
  this.skipSeparationSpace(false, -1);
5546
5738
  if (this.lineIndent >= nodeIndent) {
5547
5739
  hasPendingContent = true;
5548
- ch = this.peek();
5740
+ ch = this.#scanner.peek();
5549
5741
  continue;
5550
5742
  } else {
5551
- this.position = captureEnd;
5743
+ this.#scanner.position = captureEnd;
5552
5744
  this.line = line;
5553
5745
  this.lineStart = lineStart;
5554
5746
  this.lineIndent = lineIndent;
@@ -5559,13 +5751,14 @@ var LoaderState = class {
5559
5751
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
5560
5752
  if (segment2) result += segment2;
5561
5753
  result += writeFoldedLines(this.line - line);
5562
- captureStart = captureEnd = this.position;
5754
+ captureStart = captureEnd = this.#scanner.position;
5563
5755
  hasPendingContent = false;
5564
5756
  }
5565
5757
  if (!isWhiteSpace(ch)) {
5566
- captureEnd = this.position + 1;
5758
+ captureEnd = this.#scanner.position + 1;
5567
5759
  }
5568
- ch = this.next();
5760
+ this.#scanner.next();
5761
+ ch = this.#scanner.peek();
5569
5762
  }
5570
5763
  const segment = this.captureSegment(captureStart, captureEnd, false);
5571
5764
  if (segment) result += segment;
@@ -5578,22 +5771,23 @@ var LoaderState = class {
5578
5771
  };
5579
5772
  }
5580
5773
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
5581
- let ch = this.peek();
5774
+ let ch = this.#scanner.peek();
5582
5775
  if (ch !== SINGLE_QUOTE) return;
5583
5776
  let result = "";
5584
- this.position++;
5585
- let captureStart = this.position;
5586
- let captureEnd = this.position;
5587
- ch = this.peek();
5777
+ this.#scanner.next();
5778
+ let captureStart = this.#scanner.position;
5779
+ let captureEnd = this.#scanner.position;
5780
+ ch = this.#scanner.peek();
5588
5781
  while (ch !== 0) {
5589
5782
  if (ch === SINGLE_QUOTE) {
5590
- const segment = this.captureSegment(captureStart, this.position, true);
5783
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5591
5784
  if (segment) result += segment;
5592
- ch = this.next();
5785
+ this.#scanner.next();
5786
+ ch = this.#scanner.peek();
5593
5787
  if (ch === SINGLE_QUOTE) {
5594
- captureStart = this.position;
5595
- this.position++;
5596
- captureEnd = this.position;
5788
+ captureStart = this.#scanner.position;
5789
+ this.#scanner.next();
5790
+ captureEnd = this.#scanner.position;
5597
5791
  } else {
5598
5792
  if (anchor !== null) this.anchorMap.set(anchor, result);
5599
5793
  return {
@@ -5607,31 +5801,31 @@ var LoaderState = class {
5607
5801
  const segment = this.captureSegment(captureStart, captureEnd, true);
5608
5802
  if (segment) result += segment;
5609
5803
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
5610
- captureStart = captureEnd = this.position;
5611
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
5804
+ captureStart = captureEnd = this.#scanner.position;
5805
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5612
5806
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
5613
5807
  } else {
5614
- this.position++;
5615
- captureEnd = this.position;
5808
+ this.#scanner.next();
5809
+ captureEnd = this.#scanner.position;
5616
5810
  }
5617
- ch = this.peek();
5811
+ ch = this.#scanner.peek();
5618
5812
  }
5619
5813
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
5620
5814
  }
5621
5815
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
5622
- let ch = this.peek();
5816
+ let ch = this.#scanner.peek();
5623
5817
  if (ch !== DOUBLE_QUOTE) return;
5624
5818
  let result = "";
5625
- this.position++;
5626
- let captureEnd = this.position;
5627
- let captureStart = this.position;
5819
+ this.#scanner.next();
5820
+ let captureEnd = this.#scanner.position;
5821
+ let captureStart = this.#scanner.position;
5628
5822
  let tmp;
5629
- ch = this.peek();
5823
+ ch = this.#scanner.peek();
5630
5824
  while (ch !== 0) {
5631
5825
  if (ch === DOUBLE_QUOTE) {
5632
- const segment = this.captureSegment(captureStart, this.position, true);
5826
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5633
5827
  if (segment) result += segment;
5634
- this.position++;
5828
+ this.#scanner.next();
5635
5829
  if (anchor !== null) this.anchorMap.set(anchor, result);
5636
5830
  return {
5637
5831
  tag,
@@ -5641,19 +5835,21 @@ var LoaderState = class {
5641
5835
  };
5642
5836
  }
5643
5837
  if (ch === BACKSLASH) {
5644
- const segment = this.captureSegment(captureStart, this.position, true);
5838
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5645
5839
  if (segment) result += segment;
5646
- ch = this.next();
5840
+ this.#scanner.next();
5841
+ ch = this.#scanner.peek();
5647
5842
  if (isEOL(ch)) {
5648
5843
  this.skipSeparationSpace(false, nodeIndent);
5649
5844
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
5650
5845
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
5651
- this.position++;
5846
+ this.#scanner.next();
5652
5847
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
5653
5848
  let hexLength = tmp;
5654
5849
  let hexResult = 0;
5655
5850
  for (; hexLength > 0; hexLength--) {
5656
- ch = this.next();
5851
+ this.#scanner.next();
5852
+ ch = this.#scanner.peek();
5657
5853
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
5658
5854
  hexResult = (hexResult << 4) + tmp;
5659
5855
  } else {
@@ -5661,28 +5857,28 @@ var LoaderState = class {
5661
5857
  }
5662
5858
  }
5663
5859
  result += codepointToChar(hexResult);
5664
- this.position++;
5860
+ this.#scanner.next();
5665
5861
  } else {
5666
5862
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
5667
5863
  }
5668
- captureStart = captureEnd = this.position;
5864
+ captureStart = captureEnd = this.#scanner.position;
5669
5865
  } else if (isEOL(ch)) {
5670
5866
  const segment = this.captureSegment(captureStart, captureEnd, true);
5671
5867
  if (segment) result += segment;
5672
5868
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
5673
- captureStart = captureEnd = this.position;
5674
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
5869
+ captureStart = captureEnd = this.#scanner.position;
5870
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5675
5871
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
5676
5872
  } else {
5677
- this.position++;
5678
- captureEnd = this.position;
5873
+ this.#scanner.next();
5874
+ captureEnd = this.#scanner.position;
5679
5875
  }
5680
- ch = this.peek();
5876
+ ch = this.#scanner.peek();
5681
5877
  }
5682
5878
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
5683
5879
  }
5684
5880
  readFlowCollection(tag, anchor, nodeIndent) {
5685
- let ch = this.peek();
5881
+ let ch = this.#scanner.peek();
5686
5882
  let terminator;
5687
5883
  let isMapping = true;
5688
5884
  let result = {};
@@ -5696,7 +5892,8 @@ var LoaderState = class {
5696
5892
  return;
5697
5893
  }
5698
5894
  if (anchor !== null) this.anchorMap.set(anchor, result);
5699
- ch = this.next();
5895
+ this.#scanner.next();
5896
+ ch = this.#scanner.peek();
5700
5897
  let readNext = true;
5701
5898
  let valueNode = null;
5702
5899
  let keyNode = null;
@@ -5708,9 +5905,9 @@ var LoaderState = class {
5708
5905
  const overridableKeys = /* @__PURE__ */ new Set();
5709
5906
  while (ch !== 0) {
5710
5907
  this.skipSeparationSpace(true, nodeIndent);
5711
- ch = this.peek();
5908
+ ch = this.#scanner.peek();
5712
5909
  if (ch === terminator) {
5713
- this.position++;
5910
+ this.#scanner.next();
5714
5911
  const kind = isMapping ? "mapping" : "sequence";
5715
5912
  return {
5716
5913
  tag,
@@ -5725,10 +5922,10 @@ var LoaderState = class {
5725
5922
  keyTag = keyNode = valueNode = null;
5726
5923
  isPair = isExplicitPair = false;
5727
5924
  if (ch === QUESTION) {
5728
- following = this.peek(1);
5925
+ following = this.#scanner.peek(1);
5729
5926
  if (isWhiteSpaceOrEOL(following)) {
5730
5927
  isPair = isExplicitPair = true;
5731
- this.position++;
5928
+ this.#scanner.next();
5732
5929
  this.skipSeparationSpace(true, nodeIndent);
5733
5930
  }
5734
5931
  }
@@ -5744,10 +5941,11 @@ var LoaderState = class {
5744
5941
  keyNode = newState.result;
5745
5942
  }
5746
5943
  this.skipSeparationSpace(true, nodeIndent);
5747
- ch = this.peek();
5944
+ ch = this.#scanner.peek();
5748
5945
  if ((isExplicitPair || this.line === line) && ch === COLON) {
5749
5946
  isPair = true;
5750
- ch = this.next();
5947
+ this.#scanner.next();
5948
+ ch = this.#scanner.peek();
5751
5949
  this.skipSeparationSpace(true, nodeIndent);
5752
5950
  const newState2 = this.composeNode({
5753
5951
  parentIndent: nodeIndent,
@@ -5765,10 +5963,11 @@ var LoaderState = class {
5765
5963
  result.push(keyNode);
5766
5964
  }
5767
5965
  this.skipSeparationSpace(true, nodeIndent);
5768
- ch = this.peek();
5966
+ ch = this.#scanner.peek();
5769
5967
  if (ch === COMMA) {
5770
5968
  readNext = true;
5771
- ch = this.next();
5969
+ this.#scanner.next();
5970
+ ch = this.#scanner.peek();
5772
5971
  } else {
5773
5972
  readNext = false;
5774
5973
  }
@@ -5784,7 +5983,7 @@ var LoaderState = class {
5784
5983
  let textIndent = nodeIndent;
5785
5984
  let emptyLines = 0;
5786
5985
  let atMoreIndented = false;
5787
- let ch = this.peek();
5986
+ let ch = this.#scanner.peek();
5788
5987
  let folding = false;
5789
5988
  if (ch === VERTICAL_LINE) {
5790
5989
  folding = false;
@@ -5796,7 +5995,8 @@ var LoaderState = class {
5796
5995
  let result = "";
5797
5996
  let tmp = 0;
5798
5997
  while (ch !== 0) {
5799
- ch = this.next();
5998
+ this.#scanner.next();
5999
+ ch = this.#scanner.peek();
5800
6000
  if (ch === PLUS || ch === MINUS) {
5801
6001
  if (CHOMPING_CLIP === chomping) {
5802
6002
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -5819,15 +6019,16 @@ var LoaderState = class {
5819
6019
  if (isWhiteSpace(ch)) {
5820
6020
  this.skipWhitespaces();
5821
6021
  this.skipComment();
5822
- ch = this.peek();
6022
+ ch = this.#scanner.peek();
5823
6023
  }
5824
6024
  while (ch !== 0) {
5825
6025
  this.readLineBreak();
5826
6026
  this.lineIndent = 0;
5827
- ch = this.peek();
6027
+ ch = this.#scanner.peek();
5828
6028
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
5829
6029
  this.lineIndent++;
5830
- ch = this.next();
6030
+ this.#scanner.next();
6031
+ ch = this.#scanner.peek();
5831
6032
  }
5832
6033
  if (!detectedIndent && this.lineIndent > textIndent) {
5833
6034
  textIndent = this.lineIndent;
@@ -5866,11 +6067,12 @@ var LoaderState = class {
5866
6067
  didReadContent = true;
5867
6068
  detectedIndent = true;
5868
6069
  emptyLines = 0;
5869
- const captureStart = this.position;
6070
+ const captureStart = this.#scanner.position;
5870
6071
  while (!isEOL(ch) && ch !== 0) {
5871
- ch = this.next();
6072
+ this.#scanner.next();
6073
+ ch = this.#scanner.peek();
5872
6074
  }
5873
- const segment = this.captureSegment(captureStart, this.position, false);
6075
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
5874
6076
  if (segment) result += segment;
5875
6077
  }
5876
6078
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -5893,11 +6095,11 @@ var LoaderState = class {
5893
6095
  let atExplicitKey = false;
5894
6096
  let detected = false;
5895
6097
  if (anchor !== null) this.anchorMap.set(anchor, result);
5896
- let ch = this.peek();
6098
+ let ch = this.#scanner.peek();
5897
6099
  while (ch !== 0) {
5898
- const following = this.peek(1);
6100
+ const following = this.#scanner.peek(1);
5899
6101
  line = this.line;
5900
- pos = this.position;
6102
+ pos = this.#scanner.position;
5901
6103
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
5902
6104
  if (ch === QUESTION) {
5903
6105
  if (atExplicitKey) {
@@ -5915,7 +6117,7 @@ var LoaderState = class {
5915
6117
  } else {
5916
6118
  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");
5917
6119
  }
5918
- this.position += 1;
6120
+ this.#scanner.next();
5919
6121
  ch = following;
5920
6122
  } else {
5921
6123
  const newState = this.composeNode({
@@ -5926,11 +6128,12 @@ var LoaderState = class {
5926
6128
  });
5927
6129
  if (!newState) break;
5928
6130
  if (this.line === line) {
5929
- ch = this.peek();
6131
+ ch = this.#scanner.peek();
5930
6132
  this.skipWhitespaces();
5931
- ch = this.peek();
6133
+ ch = this.#scanner.peek();
5932
6134
  if (ch === COLON) {
5933
- ch = this.next();
6135
+ this.#scanner.next();
6136
+ ch = this.#scanner.peek();
5934
6137
  if (!isWhiteSpaceOrEOL(ch)) {
5935
6138
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
5936
6139
  }
@@ -5987,7 +6190,7 @@ var LoaderState = class {
5987
6190
  keyTag = keyNode = valueNode = null;
5988
6191
  }
5989
6192
  this.skipSeparationSpace(true, -1);
5990
- ch = this.peek();
6193
+ ch = this.#scanner.peek();
5991
6194
  }
5992
6195
  if (this.lineIndent > nodeIndent && ch !== 0) {
5993
6196
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -6010,30 +6213,35 @@ var LoaderState = class {
6010
6213
  let isNamed = false;
6011
6214
  let tagHandle = "";
6012
6215
  let tagName;
6013
- let ch = this.peek();
6216
+ let ch = this.#scanner.peek();
6014
6217
  if (ch !== EXCLAMATION) return;
6015
6218
  if (tag !== null) {
6016
6219
  throw this.#createError("Cannot read tag property: duplication of a tag property");
6017
6220
  }
6018
- ch = this.next();
6221
+ this.#scanner.next();
6222
+ ch = this.#scanner.peek();
6019
6223
  if (ch === SMALLER_THAN) {
6020
6224
  isVerbatim = true;
6021
- ch = this.next();
6225
+ this.#scanner.next();
6226
+ ch = this.#scanner.peek();
6022
6227
  } else if (ch === EXCLAMATION) {
6023
6228
  isNamed = true;
6024
6229
  tagHandle = "!!";
6025
- ch = this.next();
6230
+ this.#scanner.next();
6231
+ ch = this.#scanner.peek();
6026
6232
  } else {
6027
6233
  tagHandle = "!";
6028
6234
  }
6029
- let position = this.position;
6235
+ let position = this.#scanner.position;
6030
6236
  if (isVerbatim) {
6031
6237
  do {
6032
- ch = this.next();
6238
+ this.#scanner.next();
6239
+ ch = this.#scanner.peek();
6033
6240
  } while (ch !== 0 && ch !== GREATER_THAN);
6034
- if (this.position < this.length) {
6035
- tagName = this.input.slice(position, this.position);
6036
- ch = this.next();
6241
+ if (!this.#scanner.eof()) {
6242
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
6243
+ this.#scanner.next();
6244
+ ch = this.#scanner.peek();
6037
6245
  } else {
6038
6246
  throw this.#createError("Cannot read tag property: unexpected end of stream");
6039
6247
  }
@@ -6041,19 +6249,20 @@ var LoaderState = class {
6041
6249
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6042
6250
  if (ch === EXCLAMATION) {
6043
6251
  if (!isNamed) {
6044
- tagHandle = this.input.slice(position - 1, this.position + 1);
6252
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
6045
6253
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
6046
6254
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
6047
6255
  }
6048
6256
  isNamed = true;
6049
- position = this.position + 1;
6257
+ position = this.#scanner.position + 1;
6050
6258
  } else {
6051
6259
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
6052
6260
  }
6053
6261
  }
6054
- ch = this.next();
6262
+ this.#scanner.next();
6263
+ ch = this.#scanner.peek();
6055
6264
  }
6056
- tagName = this.input.slice(position, this.position);
6265
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
6057
6266
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
6058
6267
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
6059
6268
  }
@@ -6073,32 +6282,36 @@ var LoaderState = class {
6073
6282
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
6074
6283
  }
6075
6284
  readAnchorProperty(anchor) {
6076
- let ch = this.peek();
6285
+ let ch = this.#scanner.peek();
6077
6286
  if (ch !== AMPERSAND) return;
6078
6287
  if (anchor !== null) {
6079
6288
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
6080
6289
  }
6081
- ch = this.next();
6082
- const position = this.position;
6290
+ this.#scanner.next();
6291
+ ch = this.#scanner.peek();
6292
+ const position = this.#scanner.position;
6083
6293
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
6084
- ch = this.next();
6294
+ this.#scanner.next();
6295
+ ch = this.#scanner.peek();
6085
6296
  }
6086
- if (this.position === position) {
6297
+ if (this.#scanner.position === position) {
6087
6298
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
6088
6299
  }
6089
- return this.input.slice(position, this.position);
6300
+ return this.#scanner.source.slice(position, this.#scanner.position);
6090
6301
  }
6091
6302
  readAlias() {
6092
- if (this.peek() !== ASTERISK) return;
6093
- let ch = this.next();
6094
- const position = this.position;
6303
+ if (this.#scanner.peek() !== ASTERISK) return;
6304
+ this.#scanner.next();
6305
+ let ch = this.#scanner.peek();
6306
+ const position = this.#scanner.position;
6095
6307
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
6096
- ch = this.next();
6308
+ this.#scanner.next();
6309
+ ch = this.#scanner.peek();
6097
6310
  }
6098
- if (this.position === position) {
6311
+ if (this.#scanner.position === position) {
6099
6312
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
6100
6313
  }
6101
- const alias = this.input.slice(position, this.position);
6314
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
6102
6315
  if (!this.anchorMap.has(alias)) {
6103
6316
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
6104
6317
  }
@@ -6181,7 +6394,7 @@ var LoaderState = class {
6181
6394
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
6182
6395
  const flowIndent = cond ? parentIndent : parentIndent + 1;
6183
6396
  if (allowBlockCollections) {
6184
- const blockIndent = this.position - this.lineStart;
6397
+ const blockIndent = this.#scanner.position - this.lineStart;
6185
6398
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
6186
6399
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
6187
6400
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -6215,7 +6428,7 @@ var LoaderState = class {
6215
6428
  return this.resolveTag(plainScalarState);
6216
6429
  }
6217
6430
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
6218
- const blockIndent = this.position - this.lineStart;
6431
+ const blockIndent = this.#scanner.position - this.lineStart;
6219
6432
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
6220
6433
  if (newState2) return this.resolveTag(newState2);
6221
6434
  }
@@ -6230,20 +6443,22 @@ var LoaderState = class {
6230
6443
  readDirectives() {
6231
6444
  let hasDirectives = false;
6232
6445
  let version = null;
6233
- let ch = this.peek();
6446
+ let ch = this.#scanner.peek();
6234
6447
  while (ch !== 0) {
6235
6448
  this.skipSeparationSpace(true, -1);
6236
- ch = this.peek();
6449
+ ch = this.#scanner.peek();
6237
6450
  if (this.lineIndent > 0 || ch !== PERCENT) {
6238
6451
  break;
6239
6452
  }
6240
6453
  hasDirectives = true;
6241
- ch = this.next();
6242
- let position = this.position;
6454
+ this.#scanner.next();
6455
+ ch = this.#scanner.peek();
6456
+ let position = this.#scanner.position;
6243
6457
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6244
- ch = this.next();
6458
+ this.#scanner.next();
6459
+ ch = this.#scanner.peek();
6245
6460
  }
6246
- const directiveName = this.input.slice(position, this.position);
6461
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
6247
6462
  const directiveArgs = [];
6248
6463
  if (directiveName.length < 1) {
6249
6464
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -6251,13 +6466,14 @@ var LoaderState = class {
6251
6466
  while (ch !== 0) {
6252
6467
  this.skipWhitespaces();
6253
6468
  this.skipComment();
6254
- ch = this.peek();
6469
+ ch = this.#scanner.peek();
6255
6470
  if (isEOL(ch)) break;
6256
- position = this.position;
6471
+ position = this.#scanner.position;
6257
6472
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6258
- ch = this.next();
6473
+ this.#scanner.next();
6474
+ ch = this.#scanner.peek();
6259
6475
  }
6260
- directiveArgs.push(this.input.slice(position, this.position));
6476
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
6261
6477
  }
6262
6478
  if (ch !== 0) this.readLineBreak();
6263
6479
  switch (directiveName) {
@@ -6274,20 +6490,20 @@ var LoaderState = class {
6274
6490
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
6275
6491
  break;
6276
6492
  }
6277
- ch = this.peek();
6493
+ ch = this.#scanner.peek();
6278
6494
  }
6279
6495
  return hasDirectives;
6280
6496
  }
6281
6497
  readDocument() {
6282
- const documentStart = this.position;
6498
+ const documentStart = this.#scanner.position;
6283
6499
  this.checkLineBreaks = false;
6284
6500
  this.tagMap = /* @__PURE__ */ new Map();
6285
6501
  this.anchorMap = /* @__PURE__ */ new Map();
6286
6502
  const hasDirectives = this.readDirectives();
6287
6503
  this.skipSeparationSpace(true, -1);
6288
6504
  let result = null;
6289
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
6290
- this.position += 3;
6505
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
6506
+ this.#scanner.position += 3;
6291
6507
  this.skipSeparationSpace(true, -1);
6292
6508
  } else if (hasDirectives) {
6293
6509
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -6300,21 +6516,21 @@ var LoaderState = class {
6300
6516
  });
6301
6517
  if (newState) result = newState.result;
6302
6518
  this.skipSeparationSpace(true, -1);
6303
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
6519
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
6304
6520
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
6305
6521
  }
6306
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
6307
- if (this.peek() === DOT) {
6308
- this.position += 3;
6522
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
6523
+ if (this.#scanner.peek() === DOT) {
6524
+ this.#scanner.position += 3;
6309
6525
  this.skipSeparationSpace(true, -1);
6310
6526
  }
6311
- } else if (this.position < this.length - 1) {
6527
+ } else if (!this.#scanner.eof()) {
6312
6528
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
6313
6529
  }
6314
6530
  return result;
6315
6531
  }
6316
6532
  *readDocuments() {
6317
- while (this.position < this.length - 1) {
6533
+ while (!this.#scanner.eof()) {
6318
6534
  yield this.readDocument();
6319
6535
  }
6320
6536
  }
@@ -6327,7 +6543,6 @@ function sanitizeInput(input) {
6327
6543
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
6328
6544
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
6329
6545
  }
6330
- input += "\0";
6331
6546
  return input;
6332
6547
  }
6333
6548
  function parse(content, options = {}) {
@@ -6345,10 +6560,10 @@ function parse(content, options = {}) {
6345
6560
  }
6346
6561
 
6347
6562
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__plugin-markdown-loader/src/markdown-loader.js
6348
- import process2 from "node:process";
6563
+ import process3 from "node:process";
6349
6564
  function replaceEnvVars(str2) {
6350
6565
  return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\s*\()/g, (match, varName) => {
6351
- const value = process2.env[varName];
6566
+ const value = process3.env[varName];
6352
6567
  if (value !== void 0) {
6353
6568
  return value;
6354
6569
  }
@@ -6447,18 +6662,19 @@ var defaultPlugin = markdownLoaderPlugin();
6447
6662
 
6448
6663
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
6449
6664
  import { resolve as resolve3 } from "node:path";
6450
- import process3 from "node:process";
6665
+ import process4 from "node:process";
6451
6666
  var DEFAULT_SKILLS_PATHS = [
6452
6667
  ".agent/skills"
6453
6668
  ];
6454
6669
  var DEFAULT_CODE_EXECUTION_TIMEOUT = 3e5;
6455
6670
  function getGlobalPlugins(skillsPaths) {
6456
- const resolvedPaths = skillsPaths.map((p2) => resolve3(process3.cwd(), p2));
6671
+ const resolvedPaths = skillsPaths.map((p2) => resolve3(process4.cwd(), p2));
6457
6672
  return [
6458
6673
  markdownLoaderPlugin(),
6459
6674
  createSkillsPlugin({
6460
6675
  paths: resolvedPaths
6461
- })
6676
+ }),
6677
+ createBashPlugin()
6462
6678
  ];
6463
6679
  }
6464
6680
  function getAgentPlugins() {
@@ -6487,7 +6703,7 @@ function getDefaultAgents() {
6487
6703
  }
6488
6704
 
6489
6705
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
6490
- var CLI_VERSION = "0.1.44";
6706
+ var CLI_VERSION = "0.1.52";
6491
6707
  function extractServerName(command, commandArgs) {
6492
6708
  for (const arg of commandArgs) {
6493
6709
  if (!arg.startsWith("-")) {
@@ -6547,7 +6763,7 @@ async function saveUserConfig(config, newAgentName) {
6547
6763
  async function createWrapConfig(args) {
6548
6764
  if (!args.mcpServers || args.mcpServers.length === 0) {
6549
6765
  console.error("Error: --wrap/--add requires at least one MCP server\nExample: mcpc --wrap --mcp-stdio 'npx -y @wonderwhy-er/desktop-commander'\nMultiple: mcpc --add --mcp-stdio 'npx -y server1' --mcp-http 'https://api.example.com'");
6550
- process4.exit(1);
6766
+ process5.exit(1);
6551
6767
  }
6552
6768
  const mcpServers = {};
6553
6769
  const serverNames = [];
@@ -6670,7 +6886,7 @@ function parseMcpServer(cmdString, transportType) {
6670
6886
  };
6671
6887
  }
6672
6888
  function parseCLIArgs() {
6673
- const args = parseArgs(process4.argv.slice(2), {
6889
+ const args = parseArgs(process5.argv.slice(2), {
6674
6890
  boolean: [
6675
6891
  "help",
6676
6892
  "version",
@@ -6759,15 +6975,15 @@ async function loadConfig() {
6759
6975
  const args = parseCLIArgs();
6760
6976
  if (args.version) {
6761
6977
  printVersion();
6762
- process4.exit(0);
6978
+ process5.exit(0);
6763
6979
  }
6764
6980
  if (args.help) {
6765
6981
  printHelp();
6766
- process4.exit(0);
6982
+ process5.exit(0);
6767
6983
  }
6768
6984
  if (args.cwd) {
6769
- const targetCwd = resolve4(process4.cwd(), args.cwd);
6770
- process4.chdir(targetCwd);
6985
+ const targetCwd = resolve4(process5.cwd(), args.cwd);
6986
+ process5.chdir(targetCwd);
6771
6987
  console.error(`Changed working directory to: ${targetCwd}`);
6772
6988
  }
6773
6989
  const mergeSkills = (config) => {
@@ -6779,7 +6995,7 @@ async function loadConfig() {
6779
6995
  ...args,
6780
6996
  saveConfig: true
6781
6997
  });
6782
- process4.exit(0);
6998
+ process5.exit(0);
6783
6999
  }
6784
7000
  if (args.wrap) {
6785
7001
  return mergeSkills(await createWrapConfig({
@@ -6796,16 +7012,16 @@ async function loadConfig() {
6796
7012
  throw error;
6797
7013
  }
6798
7014
  }
6799
- if (process4.env.MCPC_CONFIG) {
7015
+ if (process5.env.MCPC_CONFIG) {
6800
7016
  try {
6801
- const parsed = JSON.parse(process4.env.MCPC_CONFIG);
7017
+ const parsed = JSON.parse(process5.env.MCPC_CONFIG);
6802
7018
  return mergeSkills(applyModeOverride(normalizeConfig(parsed), args.mode));
6803
7019
  } catch (error) {
6804
7020
  console.error("Failed to parse MCPC_CONFIG environment variable:", error);
6805
7021
  throw error;
6806
7022
  }
6807
7023
  }
6808
- const configUrl = args.configUrl || process4.env.MCPC_CONFIG_URL;
7024
+ const configUrl = args.configUrl || process5.env.MCPC_CONFIG_URL;
6809
7025
  if (configUrl) {
6810
7026
  try {
6811
7027
  const headers = {
@@ -6826,7 +7042,7 @@ async function loadConfig() {
6826
7042
  throw error;
6827
7043
  }
6828
7044
  }
6829
- const configFile = args.configFile || process4.env.MCPC_CONFIG_FILE;
7045
+ const configFile = args.configFile || process5.env.MCPC_CONFIG_FILE;
6830
7046
  if (configFile) {
6831
7047
  try {
6832
7048
  const config = await loadConfigFromFile(configFile);
@@ -6851,7 +7067,7 @@ async function loadConfig() {
6851
7067
  throw error;
6852
7068
  }
6853
7069
  }
6854
- const defaultJsonConfigPath = resolve4(process4.cwd(), "mcpc.config.json");
7070
+ const defaultJsonConfigPath = resolve4(process5.cwd(), "mcpc.config.json");
6855
7071
  try {
6856
7072
  const config = await loadConfigFromFile(defaultJsonConfigPath);
6857
7073
  return mergeSkills(applyModeOverride(config, args.mode));
@@ -6866,7 +7082,7 @@ async function loadConfig() {
6866
7082
  }
6867
7083
  function replaceEnvVars2(str2) {
6868
7084
  return str2.replace(/\$([A-Z_][A-Z0-9_]*)/g, (_match, varName) => {
6869
- return process4.env[varName] || "";
7085
+ return process5.env[varName] || "";
6870
7086
  });
6871
7087
  }
6872
7088
  function isMarkdownFile2(path) {
@@ -8168,6 +8384,147 @@ var ExperimentalServerTasks = class {
8168
8384
  requestStream(request, resultSchema, options) {
8169
8385
  return this._server.requestStream(request, resultSchema, options);
8170
8386
  }
8387
+ /**
8388
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
8389
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
8390
+ *
8391
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
8392
+ * before the final result.
8393
+ *
8394
+ * @example
8395
+ * ```typescript
8396
+ * const stream = server.experimental.tasks.createMessageStream({
8397
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
8398
+ * maxTokens: 100
8399
+ * }, {
8400
+ * onprogress: (progress) => {
8401
+ * // Handle streaming tokens via progress notifications
8402
+ * console.log('Progress:', progress.message);
8403
+ * }
8404
+ * });
8405
+ *
8406
+ * for await (const message of stream) {
8407
+ * switch (message.type) {
8408
+ * case 'taskCreated':
8409
+ * console.log('Task created:', message.task.taskId);
8410
+ * break;
8411
+ * case 'taskStatus':
8412
+ * console.log('Task status:', message.task.status);
8413
+ * break;
8414
+ * case 'result':
8415
+ * console.log('Final result:', message.result);
8416
+ * break;
8417
+ * case 'error':
8418
+ * console.error('Error:', message.error);
8419
+ * break;
8420
+ * }
8421
+ * }
8422
+ * ```
8423
+ *
8424
+ * @param params - The sampling request parameters
8425
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
8426
+ * @returns AsyncGenerator that yields ResponseMessage objects
8427
+ *
8428
+ * @experimental
8429
+ */
8430
+ createMessageStream(params, options) {
8431
+ const clientCapabilities = this._server.getClientCapabilities();
8432
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
8433
+ throw new Error("Client does not support sampling tools capability.");
8434
+ }
8435
+ if (params.messages.length > 0) {
8436
+ const lastMessage = params.messages[params.messages.length - 1];
8437
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
8438
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
8439
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
8440
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
8441
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
8442
+ if (hasToolResults) {
8443
+ if (lastContent.some((c) => c.type !== "tool_result")) {
8444
+ throw new Error("The last message must contain only tool_result content if any is present");
8445
+ }
8446
+ if (!hasPreviousToolUse) {
8447
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
8448
+ }
8449
+ }
8450
+ if (hasPreviousToolUse) {
8451
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
8452
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
8453
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
8454
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
8455
+ }
8456
+ }
8457
+ }
8458
+ return this.requestStream({
8459
+ method: "sampling/createMessage",
8460
+ params
8461
+ }, CreateMessageResultSchema, options);
8462
+ }
8463
+ /**
8464
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
8465
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
8466
+ *
8467
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
8468
+ * and 'taskStatus' messages before the final result.
8469
+ *
8470
+ * @example
8471
+ * ```typescript
8472
+ * const stream = server.experimental.tasks.elicitInputStream({
8473
+ * mode: 'url',
8474
+ * message: 'Please authenticate',
8475
+ * elicitationId: 'auth-123',
8476
+ * url: 'https://example.com/auth'
8477
+ * }, {
8478
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
8479
+ * });
8480
+ *
8481
+ * for await (const message of stream) {
8482
+ * switch (message.type) {
8483
+ * case 'taskCreated':
8484
+ * console.log('Task created:', message.task.taskId);
8485
+ * break;
8486
+ * case 'taskStatus':
8487
+ * console.log('Task status:', message.task.status);
8488
+ * break;
8489
+ * case 'result':
8490
+ * console.log('User action:', message.result.action);
8491
+ * break;
8492
+ * case 'error':
8493
+ * console.error('Error:', message.error);
8494
+ * break;
8495
+ * }
8496
+ * }
8497
+ * ```
8498
+ *
8499
+ * @param params - The elicitation request parameters
8500
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
8501
+ * @returns AsyncGenerator that yields ResponseMessage objects
8502
+ *
8503
+ * @experimental
8504
+ */
8505
+ elicitInputStream(params, options) {
8506
+ const clientCapabilities = this._server.getClientCapabilities();
8507
+ const mode = params.mode ?? "form";
8508
+ switch (mode) {
8509
+ case "url": {
8510
+ if (!clientCapabilities?.elicitation?.url) {
8511
+ throw new Error("Client does not support url elicitation.");
8512
+ }
8513
+ break;
8514
+ }
8515
+ case "form": {
8516
+ if (!clientCapabilities?.elicitation?.form) {
8517
+ throw new Error("Client does not support form elicitation.");
8518
+ }
8519
+ break;
8520
+ }
8521
+ }
8522
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
8523
+ return this.requestStream({
8524
+ method: "elicitation/create",
8525
+ params: normalizedParams
8526
+ }, ElicitResultSchema, options);
8527
+ }
8171
8528
  /**
8172
8529
  * Gets the current status of a task.
8173
8530
  *
@@ -9367,7 +9724,7 @@ var Client = class extends Protocol {
9367
9724
 
9368
9725
  // __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
9369
9726
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
9370
- import process5 from "node:process";
9727
+ import process6 from "node:process";
9371
9728
  import { PassThrough } from "node:stream";
9372
9729
 
9373
9730
  // __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
@@ -9399,7 +9756,7 @@ function serializeMessage(message) {
9399
9756
  }
9400
9757
 
9401
9758
  // __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
9402
- var DEFAULT_INHERITED_ENV_VARS = process5.platform === "win32" ? [
9759
+ var DEFAULT_INHERITED_ENV_VARS = process6.platform === "win32" ? [
9403
9760
  "APPDATA",
9404
9761
  "HOMEDRIVE",
9405
9762
  "HOMEPATH",
@@ -9419,7 +9776,7 @@ var DEFAULT_INHERITED_ENV_VARS = process5.platform === "win32" ? [
9419
9776
  function getDefaultEnvironment() {
9420
9777
  const env = {};
9421
9778
  for (const key of DEFAULT_INHERITED_ENV_VARS) {
9422
- const value = process5.env[key];
9779
+ const value = process6.env[key];
9423
9780
  if (value === void 0) {
9424
9781
  continue;
9425
9782
  }
@@ -9455,7 +9812,7 @@ var StdioClientTransport = class {
9455
9812
  },
9456
9813
  stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
9457
9814
  shell: false,
9458
- windowsHide: process5.platform === "win32" && isElectron(),
9815
+ windowsHide: process6.platform === "win32" && isElectron(),
9459
9816
  cwd: this._serverParams.cwd
9460
9817
  });
9461
9818
  this._process.on("error", (error) => {
@@ -9563,7 +9920,7 @@ var StdioClientTransport = class {
9563
9920
  }
9564
9921
  };
9565
9922
  function isElectron() {
9566
- return "type" in process5;
9923
+ return "type" in process6;
9567
9924
  }
9568
9925
 
9569
9926
  // __mcpc__cli_latest/node_modules/eventsource-parser/dist/index.js
@@ -10386,22 +10743,45 @@ async function auth(provider, options) {
10386
10743
  }
10387
10744
  }
10388
10745
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
10746
+ const cachedState = await provider.discoveryState?.();
10389
10747
  let resourceMetadata;
10390
10748
  let authorizationServerUrl;
10391
- try {
10392
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
10393
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
10394
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
10749
+ let metadata;
10750
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
10751
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
10752
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
10753
+ }
10754
+ if (cachedState?.authorizationServerUrl) {
10755
+ authorizationServerUrl = cachedState.authorizationServerUrl;
10756
+ resourceMetadata = cachedState.resourceMetadata;
10757
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
10758
+ if (!resourceMetadata) {
10759
+ try {
10760
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
10761
+ } catch {
10762
+ }
10395
10763
  }
10396
- } catch {
10397
- }
10398
- if (!authorizationServerUrl) {
10399
- authorizationServerUrl = new URL("/", serverUrl);
10764
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
10765
+ await provider.saveDiscoveryState?.({
10766
+ authorizationServerUrl: String(authorizationServerUrl),
10767
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
10768
+ resourceMetadata,
10769
+ authorizationServerMetadata: metadata
10770
+ });
10771
+ }
10772
+ } else {
10773
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
10774
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
10775
+ metadata = serverInfo.authorizationServerMetadata;
10776
+ resourceMetadata = serverInfo.resourceMetadata;
10777
+ await provider.saveDiscoveryState?.({
10778
+ authorizationServerUrl: String(authorizationServerUrl),
10779
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
10780
+ resourceMetadata,
10781
+ authorizationServerMetadata: metadata
10782
+ });
10400
10783
  }
10401
10784
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
10402
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
10403
- fetchFn
10404
- });
10405
10785
  let clientInformation = await Promise.resolve(provider.clientInformation());
10406
10786
  if (!clientInformation) {
10407
10787
  if (authorizationCode !== void 0) {
@@ -10656,6 +11036,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
10656
11036
  }
10657
11037
  return void 0;
10658
11038
  }
11039
+ async function discoverOAuthServerInfo(serverUrl, opts) {
11040
+ let resourceMetadata;
11041
+ let authorizationServerUrl;
11042
+ try {
11043
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
11044
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
11045
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
11046
+ }
11047
+ } catch {
11048
+ }
11049
+ if (!authorizationServerUrl) {
11050
+ authorizationServerUrl = String(new URL("/", serverUrl));
11051
+ }
11052
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
11053
+ return {
11054
+ authorizationServerUrl,
11055
+ authorizationServerMetadata,
11056
+ resourceMetadata
11057
+ };
11058
+ }
10659
11059
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
10660
11060
  let authorizationUrl;
10661
11061
  if (metadata) {
@@ -11444,8 +11844,8 @@ var InMemoryTransport = class _InMemoryTransport {
11444
11844
  };
11445
11845
 
11446
11846
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/config.js
11447
- import process6 from "node:process";
11448
- var GEMINI_PREFERRED_FORMAT = process6.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
11847
+ import process7 from "node:process";
11848
+ var GEMINI_PREFERRED_FORMAT = process7.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
11449
11849
 
11450
11850
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/json.js
11451
11851
  import { jsonrepair as jsonrepair2 } from "jsonrepair";
@@ -11518,20 +11918,8 @@ var cleanToolSchema = (schema) => {
11518
11918
 
11519
11919
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/mcp.js
11520
11920
  import { cwd } from "node:process";
11521
- import process7 from "node:process";
11921
+ import process8 from "node:process";
11522
11922
  import { createHash } from "node:crypto";
11523
- var mcpClientPool = /* @__PURE__ */ new Map();
11524
- var mcpClientConnecting = /* @__PURE__ */ new Map();
11525
- var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
11526
- function defSignature(def) {
11527
- const defCopy = {
11528
- ...def
11529
- };
11530
- if (defCopy.transportType === "memory" || defCopy.transport) {
11531
- return `memory:${Date.now()}:${Math.random()}`;
11532
- }
11533
- return JSON.stringify(defCopy);
11534
- }
11535
11923
  function createTransport(def) {
11536
11924
  const defAny = def;
11537
11925
  const explicitType = defAny.transportType || defAny.type;
@@ -11571,7 +11959,7 @@ function createTransport(def) {
11571
11959
  command: defAny.command,
11572
11960
  args: defAny.args,
11573
11961
  env: {
11574
- ...process7.env,
11962
+ ...process8.env,
11575
11963
  ...defAny.env ?? {}
11576
11964
  },
11577
11965
  cwd: cwd()
@@ -11579,90 +11967,43 @@ function createTransport(def) {
11579
11967
  }
11580
11968
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
11581
11969
  }
11582
- async function getOrCreateMcpClient(defKey, def) {
11583
- const pooled = mcpClientPool.get(defKey);
11584
- if (pooled) {
11585
- pooled.refCount += 1;
11586
- return pooled.client;
11587
- }
11588
- const existingConnecting = mcpClientConnecting.get(defKey);
11589
- if (existingConnecting) {
11590
- const client = await existingConnecting;
11591
- const entry = mcpClientPool.get(defKey);
11592
- if (entry) entry.refCount += 1;
11593
- return client;
11594
- }
11595
- const transport = createTransport(def);
11596
- const connecting = (async () => {
11597
- const client = new Client({
11598
- name: `mcp_${shortHash(defSignature(def))}`,
11599
- version: "1.0.0"
11600
- });
11601
- await client.connect(transport, {
11602
- timeout: 6e4 * 10
11603
- });
11604
- return client;
11605
- })();
11606
- mcpClientConnecting.set(defKey, connecting);
11607
- try {
11608
- const client = await connecting;
11609
- mcpClientPool.set(defKey, {
11610
- client,
11611
- refCount: 1
11612
- });
11613
- return client;
11614
- } finally {
11615
- mcpClientConnecting.delete(defKey);
11970
+ function defSignature(def) {
11971
+ const defCopy = {
11972
+ ...def
11973
+ };
11974
+ if (defCopy.transportType === "memory" || defCopy.transport) {
11975
+ return `memory:${Date.now()}:${Math.random()}`;
11616
11976
  }
11977
+ return JSON.stringify(defCopy);
11617
11978
  }
11618
- async function releaseMcpClient(defKey) {
11619
- const entry = mcpClientPool.get(defKey);
11620
- if (!entry) return;
11621
- entry.refCount -= 1;
11622
- if (entry.refCount <= 0) {
11623
- mcpClientPool.delete(defKey);
11624
- try {
11625
- await entry.client.close();
11626
- } catch (err) {
11627
- console.error("Error closing MCP client:", err);
11628
- }
11629
- }
11979
+ var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
11980
+ async function createMcpClient(def) {
11981
+ const transport = createTransport(def);
11982
+ const client = new Client({
11983
+ name: `mcp_${shortHash(defSignature(def))}`,
11984
+ version: "1.0.0"
11985
+ });
11986
+ await client.connect(transport, {
11987
+ timeout: 6e4 * 10
11988
+ });
11989
+ return client;
11630
11990
  }
11631
- var cleanupAllPooledClients = async () => {
11632
- const entries = Array.from(mcpClientPool.entries());
11633
- mcpClientPool.clear();
11634
- await Promise.all(entries.map(async ([, { client }]) => {
11635
- try {
11636
- await client.close();
11637
- } catch (err) {
11638
- console.error("Error closing MCP client:", err);
11639
- }
11640
- }));
11641
- };
11642
- process7.once?.("exit", () => {
11643
- cleanupAllPooledClients();
11644
- });
11645
- process7.once?.("SIGINT", () => {
11646
- cleanupAllPooledClients().finally(() => process7.exit(0));
11647
- });
11648
11991
  async function composeMcpDepTools(mcpConfig, filterIn) {
11649
11992
  const allTools = {};
11650
11993
  const allClients = {};
11651
- const acquiredKeys = [];
11994
+ const clientsToClose = [];
11652
11995
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
11653
11996
  const def = definition;
11654
11997
  if (def.disabled) continue;
11655
- const defKey = shortHash(defSignature(def));
11656
- const serverId = name;
11657
11998
  try {
11658
- const client = await getOrCreateMcpClient(defKey, def);
11659
- acquiredKeys.push(defKey);
11660
- allClients[serverId] = client;
11999
+ const client = await createMcpClient(def);
12000
+ clientsToClose.push(client);
12001
+ allClients[name] = client;
11661
12002
  const { tools } = await client.listTools();
11662
12003
  tools.forEach((tool2) => {
11663
12004
  const toolNameWithScope = `${name}.${tool2.name}`;
11664
12005
  const internalToolName = tool2.name;
11665
- const rawToolId = `${serverId}_${internalToolName}`;
12006
+ const rawToolId = `${name}_${internalToolName}`;
11666
12007
  const toolId = sanitizePropertyKey(rawToolId);
11667
12008
  if (filterIn && !filterIn({
11668
12009
  action: internalToolName,
@@ -11674,7 +12015,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
11674
12015
  })) {
11675
12016
  return;
11676
12017
  }
11677
- const execute = (args) => allClients[serverId].callTool({
12018
+ const execute = (args) => allClients[name].callTool({
11678
12019
  name: internalToolName,
11679
12020
  arguments: args
11680
12021
  }, void 0, {
@@ -11691,10 +12032,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
11691
12032
  }
11692
12033
  }
11693
12034
  const cleanupClients = async () => {
11694
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
11695
- acquiredKeys.length = 0;
11696
- Object.keys(allTools).forEach((key) => delete allTools[key]);
11697
- Object.keys(allClients).forEach((key) => delete allClients[key]);
12035
+ await Promise.all(clientsToClose.map((client) => {
12036
+ try {
12037
+ return client.close();
12038
+ } catch {
12039
+ }
12040
+ }));
11698
12041
  };
11699
12042
  return {
11700
12043
  tools: allTools,
@@ -12266,7 +12609,7 @@ function endSpan(span, error) {
12266
12609
  }
12267
12610
 
12268
12611
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-executor.js
12269
- import process8 from "node:process";
12612
+ import process9 from "node:process";
12270
12613
  var AgenticExecutor = class {
12271
12614
  name;
12272
12615
  allToolNames;
@@ -12286,13 +12629,13 @@ var AgenticExecutor = class {
12286
12629
  this.logger = createLogger(`mcpc.agentic.${name}`, server);
12287
12630
  this.toolSchemaMap = new Map(toolNameToDetailList);
12288
12631
  try {
12289
- this.tracingEnabled = process8.env.MCPC_TRACING_ENABLED === "true";
12632
+ this.tracingEnabled = process9.env.MCPC_TRACING_ENABLED === "true";
12290
12633
  if (this.tracingEnabled) {
12291
12634
  initializeTracing({
12292
12635
  enabled: true,
12293
12636
  serviceName: `mcpc-agentic-${name}`,
12294
- exportTo: process8.env.MCPC_TRACING_EXPORT ?? "otlp",
12295
- otlpEndpoint: process8.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
12637
+ exportTo: process9.env.MCPC_TRACING_EXPORT ?? "otlp",
12638
+ otlpEndpoint: process9.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
12296
12639
  });
12297
12640
  }
12298
12641
  } catch {
@@ -15006,12 +15349,12 @@ var ComposableMCPServer = class extends Server {
15006
15349
  };
15007
15350
 
15008
15351
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
15009
- import process9 from "node:process";
15010
- var isSCF = () => Boolean(process9.env.SCF_RUNTIME || process9.env.PROD_SCF);
15352
+ import process10 from "node:process";
15353
+ var isSCF = () => Boolean(process10.env.SCF_RUNTIME || process10.env.PROD_SCF);
15011
15354
  if (isSCF()) {
15012
15355
  console.log({
15013
15356
  isSCF: isSCF(),
15014
- SCF_RUNTIME: process9.env.SCF_RUNTIME
15357
+ SCF_RUNTIME: process10.env.SCF_RUNTIME
15015
15358
  });
15016
15359
  }
15017
15360
 
@@ -15094,8 +15437,8 @@ var createApp = (config) => {
15094
15437
 
15095
15438
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/server.js
15096
15439
  import { OpenAPIHono as OpenAPIHono2 } from "@hono/zod-openapi";
15097
- import process10 from "node:process";
15098
- var port = Number(process10.env.PORT || "3002");
15440
+ import process11 from "node:process";
15441
+ var port = Number(process11.env.PORT || "3002");
15099
15442
  var hostname = "0.0.0.0";
15100
15443
  async function main() {
15101
15444
  const config = await loadConfig();