@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/app.cjs CHANGED
@@ -3499,6 +3499,147 @@ var ExperimentalServerTasks = class {
3499
3499
  requestStream(request, resultSchema, options) {
3500
3500
  return this._server.requestStream(request, resultSchema, options);
3501
3501
  }
3502
+ /**
3503
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
3504
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
3505
+ *
3506
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
3507
+ * before the final result.
3508
+ *
3509
+ * @example
3510
+ * ```typescript
3511
+ * const stream = server.experimental.tasks.createMessageStream({
3512
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
3513
+ * maxTokens: 100
3514
+ * }, {
3515
+ * onprogress: (progress) => {
3516
+ * // Handle streaming tokens via progress notifications
3517
+ * console.log('Progress:', progress.message);
3518
+ * }
3519
+ * });
3520
+ *
3521
+ * for await (const message of stream) {
3522
+ * switch (message.type) {
3523
+ * case 'taskCreated':
3524
+ * console.log('Task created:', message.task.taskId);
3525
+ * break;
3526
+ * case 'taskStatus':
3527
+ * console.log('Task status:', message.task.status);
3528
+ * break;
3529
+ * case 'result':
3530
+ * console.log('Final result:', message.result);
3531
+ * break;
3532
+ * case 'error':
3533
+ * console.error('Error:', message.error);
3534
+ * break;
3535
+ * }
3536
+ * }
3537
+ * ```
3538
+ *
3539
+ * @param params - The sampling request parameters
3540
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
3541
+ * @returns AsyncGenerator that yields ResponseMessage objects
3542
+ *
3543
+ * @experimental
3544
+ */
3545
+ createMessageStream(params, options) {
3546
+ const clientCapabilities = this._server.getClientCapabilities();
3547
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
3548
+ throw new Error("Client does not support sampling tools capability.");
3549
+ }
3550
+ if (params.messages.length > 0) {
3551
+ const lastMessage = params.messages[params.messages.length - 1];
3552
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
3553
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
3554
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
3555
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
3556
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
3557
+ if (hasToolResults) {
3558
+ if (lastContent.some((c) => c.type !== "tool_result")) {
3559
+ throw new Error("The last message must contain only tool_result content if any is present");
3560
+ }
3561
+ if (!hasPreviousToolUse) {
3562
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
3563
+ }
3564
+ }
3565
+ if (hasPreviousToolUse) {
3566
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
3567
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
3568
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
3569
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
3570
+ }
3571
+ }
3572
+ }
3573
+ return this.requestStream({
3574
+ method: "sampling/createMessage",
3575
+ params
3576
+ }, CreateMessageResultSchema, options);
3577
+ }
3578
+ /**
3579
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
3580
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
3581
+ *
3582
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
3583
+ * and 'taskStatus' messages before the final result.
3584
+ *
3585
+ * @example
3586
+ * ```typescript
3587
+ * const stream = server.experimental.tasks.elicitInputStream({
3588
+ * mode: 'url',
3589
+ * message: 'Please authenticate',
3590
+ * elicitationId: 'auth-123',
3591
+ * url: 'https://example.com/auth'
3592
+ * }, {
3593
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
3594
+ * });
3595
+ *
3596
+ * for await (const message of stream) {
3597
+ * switch (message.type) {
3598
+ * case 'taskCreated':
3599
+ * console.log('Task created:', message.task.taskId);
3600
+ * break;
3601
+ * case 'taskStatus':
3602
+ * console.log('Task status:', message.task.status);
3603
+ * break;
3604
+ * case 'result':
3605
+ * console.log('User action:', message.result.action);
3606
+ * break;
3607
+ * case 'error':
3608
+ * console.error('Error:', message.error);
3609
+ * break;
3610
+ * }
3611
+ * }
3612
+ * ```
3613
+ *
3614
+ * @param params - The elicitation request parameters
3615
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
3616
+ * @returns AsyncGenerator that yields ResponseMessage objects
3617
+ *
3618
+ * @experimental
3619
+ */
3620
+ elicitInputStream(params, options) {
3621
+ const clientCapabilities = this._server.getClientCapabilities();
3622
+ const mode = params.mode ?? "form";
3623
+ switch (mode) {
3624
+ case "url": {
3625
+ if (!clientCapabilities?.elicitation?.url) {
3626
+ throw new Error("Client does not support url elicitation.");
3627
+ }
3628
+ break;
3629
+ }
3630
+ case "form": {
3631
+ if (!clientCapabilities?.elicitation?.form) {
3632
+ throw new Error("Client does not support form elicitation.");
3633
+ }
3634
+ break;
3635
+ }
3636
+ }
3637
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
3638
+ return this.requestStream({
3639
+ method: "elicitation/create",
3640
+ params: normalizedParams
3641
+ }, ElicitResultSchema, options);
3642
+ }
3502
3643
  /**
3503
3644
  * Gets the current status of a task.
3504
3645
  *
@@ -5717,22 +5858,45 @@ async function auth(provider, options) {
5717
5858
  }
5718
5859
  }
5719
5860
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
5861
+ const cachedState = await provider.discoveryState?.();
5720
5862
  let resourceMetadata;
5721
5863
  let authorizationServerUrl;
5722
- try {
5723
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
5724
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
5725
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
5864
+ let metadata;
5865
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
5866
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
5867
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
5868
+ }
5869
+ if (cachedState?.authorizationServerUrl) {
5870
+ authorizationServerUrl = cachedState.authorizationServerUrl;
5871
+ resourceMetadata = cachedState.resourceMetadata;
5872
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
5873
+ if (!resourceMetadata) {
5874
+ try {
5875
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
5876
+ } catch {
5877
+ }
5726
5878
  }
5727
- } catch {
5728
- }
5729
- if (!authorizationServerUrl) {
5730
- authorizationServerUrl = new URL("/", serverUrl);
5879
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
5880
+ await provider.saveDiscoveryState?.({
5881
+ authorizationServerUrl: String(authorizationServerUrl),
5882
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
5883
+ resourceMetadata,
5884
+ authorizationServerMetadata: metadata
5885
+ });
5886
+ }
5887
+ } else {
5888
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
5889
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
5890
+ metadata = serverInfo.authorizationServerMetadata;
5891
+ resourceMetadata = serverInfo.resourceMetadata;
5892
+ await provider.saveDiscoveryState?.({
5893
+ authorizationServerUrl: String(authorizationServerUrl),
5894
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
5895
+ resourceMetadata,
5896
+ authorizationServerMetadata: metadata
5897
+ });
5731
5898
  }
5732
5899
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
5733
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
5734
- fetchFn
5735
- });
5736
5900
  let clientInformation = await Promise.resolve(provider.clientInformation());
5737
5901
  if (!clientInformation) {
5738
5902
  if (authorizationCode !== void 0) {
@@ -5987,6 +6151,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
5987
6151
  }
5988
6152
  return void 0;
5989
6153
  }
6154
+ async function discoverOAuthServerInfo(serverUrl, opts) {
6155
+ let resourceMetadata;
6156
+ let authorizationServerUrl;
6157
+ try {
6158
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
6159
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
6160
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
6161
+ }
6162
+ } catch {
6163
+ }
6164
+ if (!authorizationServerUrl) {
6165
+ authorizationServerUrl = String(new URL("/", serverUrl));
6166
+ }
6167
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
6168
+ return {
6169
+ authorizationServerUrl,
6170
+ authorizationServerMetadata,
6171
+ resourceMetadata
6172
+ };
6173
+ }
5990
6174
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
5991
6175
  let authorizationUrl;
5992
6176
  if (metadata) {
@@ -6851,18 +7035,6 @@ var cleanToolSchema = (schema) => {
6851
7035
  var import_node_process3 = require("node:process");
6852
7036
  var import_node_process4 = __toESM(require("node:process"), 1);
6853
7037
  var import_node_crypto = require("node:crypto");
6854
- var mcpClientPool = /* @__PURE__ */ new Map();
6855
- var mcpClientConnecting = /* @__PURE__ */ new Map();
6856
- var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
6857
- function defSignature(def) {
6858
- const defCopy = {
6859
- ...def
6860
- };
6861
- if (defCopy.transportType === "memory" || defCopy.transport) {
6862
- return `memory:${Date.now()}:${Math.random()}`;
6863
- }
6864
- return JSON.stringify(defCopy);
6865
- }
6866
7038
  function createTransport(def) {
6867
7039
  const defAny = def;
6868
7040
  const explicitType = defAny.transportType || defAny.type;
@@ -6910,90 +7082,43 @@ function createTransport(def) {
6910
7082
  }
6911
7083
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
6912
7084
  }
6913
- async function getOrCreateMcpClient(defKey, def) {
6914
- const pooled = mcpClientPool.get(defKey);
6915
- if (pooled) {
6916
- pooled.refCount += 1;
6917
- return pooled.client;
6918
- }
6919
- const existingConnecting = mcpClientConnecting.get(defKey);
6920
- if (existingConnecting) {
6921
- const client = await existingConnecting;
6922
- const entry = mcpClientPool.get(defKey);
6923
- if (entry) entry.refCount += 1;
6924
- return client;
6925
- }
6926
- const transport = createTransport(def);
6927
- const connecting = (async () => {
6928
- const client = new Client({
6929
- name: `mcp_${shortHash(defSignature(def))}`,
6930
- version: "1.0.0"
6931
- });
6932
- await client.connect(transport, {
6933
- timeout: 6e4 * 10
6934
- });
6935
- return client;
6936
- })();
6937
- mcpClientConnecting.set(defKey, connecting);
6938
- try {
6939
- const client = await connecting;
6940
- mcpClientPool.set(defKey, {
6941
- client,
6942
- refCount: 1
6943
- });
6944
- return client;
6945
- } finally {
6946
- mcpClientConnecting.delete(defKey);
7085
+ function defSignature(def) {
7086
+ const defCopy = {
7087
+ ...def
7088
+ };
7089
+ if (defCopy.transportType === "memory" || defCopy.transport) {
7090
+ return `memory:${Date.now()}:${Math.random()}`;
6947
7091
  }
7092
+ return JSON.stringify(defCopy);
6948
7093
  }
6949
- async function releaseMcpClient(defKey) {
6950
- const entry = mcpClientPool.get(defKey);
6951
- if (!entry) return;
6952
- entry.refCount -= 1;
6953
- if (entry.refCount <= 0) {
6954
- mcpClientPool.delete(defKey);
6955
- try {
6956
- await entry.client.close();
6957
- } catch (err) {
6958
- console.error("Error closing MCP client:", err);
6959
- }
6960
- }
7094
+ var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
7095
+ async function createMcpClient(def) {
7096
+ const transport = createTransport(def);
7097
+ const client = new Client({
7098
+ name: `mcp_${shortHash(defSignature(def))}`,
7099
+ version: "1.0.0"
7100
+ });
7101
+ await client.connect(transport, {
7102
+ timeout: 6e4 * 10
7103
+ });
7104
+ return client;
6961
7105
  }
6962
- var cleanupAllPooledClients = async () => {
6963
- const entries = Array.from(mcpClientPool.entries());
6964
- mcpClientPool.clear();
6965
- await Promise.all(entries.map(async ([, { client }]) => {
6966
- try {
6967
- await client.close();
6968
- } catch (err) {
6969
- console.error("Error closing MCP client:", err);
6970
- }
6971
- }));
6972
- };
6973
- import_node_process4.default.once?.("exit", () => {
6974
- cleanupAllPooledClients();
6975
- });
6976
- import_node_process4.default.once?.("SIGINT", () => {
6977
- cleanupAllPooledClients().finally(() => import_node_process4.default.exit(0));
6978
- });
6979
7106
  async function composeMcpDepTools(mcpConfig, filterIn) {
6980
7107
  const allTools = {};
6981
7108
  const allClients = {};
6982
- const acquiredKeys = [];
7109
+ const clientsToClose = [];
6983
7110
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
6984
7111
  const def = definition;
6985
7112
  if (def.disabled) continue;
6986
- const defKey = shortHash(defSignature(def));
6987
- const serverId = name;
6988
7113
  try {
6989
- const client = await getOrCreateMcpClient(defKey, def);
6990
- acquiredKeys.push(defKey);
6991
- allClients[serverId] = client;
7114
+ const client = await createMcpClient(def);
7115
+ clientsToClose.push(client);
7116
+ allClients[name] = client;
6992
7117
  const { tools } = await client.listTools();
6993
7118
  tools.forEach((tool2) => {
6994
7119
  const toolNameWithScope = `${name}.${tool2.name}`;
6995
7120
  const internalToolName = tool2.name;
6996
- const rawToolId = `${serverId}_${internalToolName}`;
7121
+ const rawToolId = `${name}_${internalToolName}`;
6997
7122
  const toolId = sanitizePropertyKey(rawToolId);
6998
7123
  if (filterIn && !filterIn({
6999
7124
  action: internalToolName,
@@ -7005,7 +7130,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
7005
7130
  })) {
7006
7131
  return;
7007
7132
  }
7008
- const execute = (args) => allClients[serverId].callTool({
7133
+ const execute = (args) => allClients[name].callTool({
7009
7134
  name: internalToolName,
7010
7135
  arguments: args
7011
7136
  }, void 0, {
@@ -7022,10 +7147,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
7022
7147
  }
7023
7148
  }
7024
7149
  const cleanupClients = async () => {
7025
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
7026
- acquiredKeys.length = 0;
7027
- Object.keys(allTools).forEach((key) => delete allTools[key]);
7028
- Object.keys(allClients).forEach((key) => delete allClients[key]);
7150
+ await Promise.all(clientsToClose.map((client) => {
7151
+ try {
7152
+ return client.close();
7153
+ } catch {
7154
+ }
7155
+ }));
7029
7156
  };
7030
7157
  return {
7031
7158
  tools: allTools,
@@ -10782,7 +10909,7 @@ Usage:
10782
10909
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
10783
10910
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
10784
10911
 
10785
- Note: For scripts/ and assets/, use appropriate tools directly.`;
10912
+ Note: For scripts/, use the bash tool with the script path to execute.`;
10786
10913
  }
10787
10914
  function createSkillsPlugin(options) {
10788
10915
  const { paths } = options;
@@ -10890,11 +11017,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
10890
11017
  try {
10891
11018
  const content = await (0, import_promises2.readFile)((0, import_node_path4.join)(meta.basePath, "SKILL.md"), "utf-8");
10892
11019
  const body = extractBody(content);
11020
+ const skillPathInfo = `
11021
+ ---
11022
+ Skill path: ${meta.basePath}
11023
+ `;
10893
11024
  return {
10894
11025
  content: [
10895
11026
  {
10896
11027
  type: "text",
10897
- text: body
11028
+ text: body + skillPathInfo
10898
11029
  }
10899
11030
  ]
10900
11031
  };
@@ -11765,12 +11896,29 @@ function writeFoldedLines(count) {
11765
11896
  if (count > 1) return "\n".repeat(count - 1);
11766
11897
  return "";
11767
11898
  }
11899
+ var Scanner = class {
11900
+ source;
11901
+ #length;
11902
+ position = 0;
11903
+ constructor(source) {
11904
+ source += "\0";
11905
+ this.source = source;
11906
+ this.#length = source.length;
11907
+ }
11908
+ peek(offset = 0) {
11909
+ return this.source.charCodeAt(this.position + offset);
11910
+ }
11911
+ next() {
11912
+ this.position += 1;
11913
+ }
11914
+ eof() {
11915
+ return this.position >= this.#length - 1;
11916
+ }
11917
+ };
11768
11918
  var LoaderState = class {
11769
- input;
11770
- length;
11919
+ #scanner;
11771
11920
  lineIndent = 0;
11772
11921
  lineStart = 0;
11773
- position = 0;
11774
11922
  line = 0;
11775
11923
  onWarning;
11776
11924
  allowDuplicateKeys;
@@ -11780,44 +11928,40 @@ var LoaderState = class {
11780
11928
  tagMap = /* @__PURE__ */ new Map();
11781
11929
  anchorMap = /* @__PURE__ */ new Map();
11782
11930
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
11783
- this.input = input;
11931
+ this.#scanner = new Scanner(input);
11784
11932
  this.onWarning = onWarning;
11785
11933
  this.allowDuplicateKeys = allowDuplicateKeys;
11786
11934
  this.implicitTypes = schema.implicitTypes;
11787
11935
  this.typeMap = schema.typeMap;
11788
- this.length = input.length;
11789
11936
  this.readIndent();
11790
11937
  }
11791
11938
  skipWhitespaces() {
11792
- let ch = this.peek();
11939
+ let ch = this.#scanner.peek();
11793
11940
  while (isWhiteSpace(ch)) {
11794
- ch = this.next();
11941
+ this.#scanner.next();
11942
+ ch = this.#scanner.peek();
11795
11943
  }
11796
11944
  }
11797
11945
  skipComment() {
11798
- let ch = this.peek();
11946
+ let ch = this.#scanner.peek();
11799
11947
  if (ch !== SHARP) return;
11800
- ch = this.next();
11948
+ this.#scanner.next();
11949
+ ch = this.#scanner.peek();
11801
11950
  while (ch !== 0 && !isEOL(ch)) {
11802
- ch = this.next();
11951
+ this.#scanner.next();
11952
+ ch = this.#scanner.peek();
11803
11953
  }
11804
11954
  }
11805
11955
  readIndent() {
11806
- let char = this.peek();
11807
- while (char === SPACE) {
11956
+ let ch = this.#scanner.peek();
11957
+ while (ch === SPACE) {
11808
11958
  this.lineIndent += 1;
11809
- char = this.next();
11959
+ this.#scanner.next();
11960
+ ch = this.#scanner.peek();
11810
11961
  }
11811
11962
  }
11812
- peek(offset = 0) {
11813
- return this.input.charCodeAt(this.position + offset);
11814
- }
11815
- next() {
11816
- this.position += 1;
11817
- return this.peek();
11818
- }
11819
11963
  #createError(message) {
11820
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
11964
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
11821
11965
  return new SyntaxError(`${message} ${mark}`);
11822
11966
  }
11823
11967
  dispatchWarning(message) {
@@ -11862,7 +12006,7 @@ var LoaderState = class {
11862
12006
  }
11863
12007
  captureSegment(start, end, checkJson) {
11864
12008
  if (start < end) {
11865
- const result = this.input.slice(start, end);
12009
+ const result = this.#scanner.source.slice(start, end);
11866
12010
  if (checkJson) {
11867
12011
  for (let position = 0; position < result.length; position++) {
11868
12012
  const character = result.charCodeAt(position);
@@ -11880,21 +12024,21 @@ var LoaderState = class {
11880
12024
  let detected = false;
11881
12025
  const result = [];
11882
12026
  if (anchor !== null) this.anchorMap.set(anchor, result);
11883
- let ch = this.peek();
12027
+ let ch = this.#scanner.peek();
11884
12028
  while (ch !== 0) {
11885
12029
  if (ch !== MINUS) {
11886
12030
  break;
11887
12031
  }
11888
- const following = this.peek(1);
12032
+ const following = this.#scanner.peek(1);
11889
12033
  if (!isWhiteSpaceOrEOL(following)) {
11890
12034
  break;
11891
12035
  }
11892
12036
  detected = true;
11893
- this.position++;
12037
+ this.#scanner.next();
11894
12038
  if (this.skipSeparationSpace(true, -1)) {
11895
12039
  if (this.lineIndent <= nodeIndent) {
11896
12040
  result.push(null);
11897
- ch = this.peek();
12041
+ ch = this.#scanner.peek();
11898
12042
  continue;
11899
12043
  }
11900
12044
  }
@@ -11907,7 +12051,7 @@ var LoaderState = class {
11907
12051
  });
11908
12052
  if (newState) result.push(newState.result);
11909
12053
  this.skipSeparationSpace(true, -1);
11910
- ch = this.peek();
12054
+ ch = this.#scanner.peek();
11911
12055
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
11912
12056
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
11913
12057
  } else if (this.lineIndent < nodeIndent) {
@@ -11963,7 +12107,7 @@ var LoaderState = class {
11963
12107
  } else {
11964
12108
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
11965
12109
  this.line = startLine || this.line;
11966
- this.position = startPos || this.position;
12110
+ this.#scanner.position = startPos || this.#scanner.position;
11967
12111
  throw this.#createError("Cannot store mapping pair: duplicated key");
11968
12112
  }
11969
12113
  Object.defineProperty(result, keyNode, {
@@ -11977,37 +12121,37 @@ var LoaderState = class {
11977
12121
  return result;
11978
12122
  }
11979
12123
  readLineBreak() {
11980
- const ch = this.peek();
12124
+ const ch = this.#scanner.peek();
11981
12125
  if (ch === LINE_FEED) {
11982
- this.position++;
12126
+ this.#scanner.next();
11983
12127
  } else if (ch === CARRIAGE_RETURN) {
11984
- this.position++;
11985
- if (this.peek() === LINE_FEED) {
11986
- this.position++;
12128
+ this.#scanner.next();
12129
+ if (this.#scanner.peek() === LINE_FEED) {
12130
+ this.#scanner.next();
11987
12131
  }
11988
12132
  } else {
11989
12133
  throw this.#createError("Cannot read line: line break not found");
11990
12134
  }
11991
12135
  this.line += 1;
11992
- this.lineStart = this.position;
12136
+ this.lineStart = this.#scanner.position;
11993
12137
  }
11994
12138
  skipSeparationSpace(allowComments, checkIndent) {
11995
12139
  let lineBreaks = 0;
11996
- let ch = this.peek();
12140
+ let ch = this.#scanner.peek();
11997
12141
  while (ch !== 0) {
11998
12142
  this.skipWhitespaces();
11999
- ch = this.peek();
12143
+ ch = this.#scanner.peek();
12000
12144
  if (allowComments) {
12001
12145
  this.skipComment();
12002
- ch = this.peek();
12146
+ ch = this.#scanner.peek();
12003
12147
  }
12004
12148
  if (isEOL(ch)) {
12005
12149
  this.readLineBreak();
12006
- ch = this.peek();
12150
+ ch = this.#scanner.peek();
12007
12151
  lineBreaks++;
12008
12152
  this.lineIndent = 0;
12009
12153
  this.readIndent();
12010
- ch = this.peek();
12154
+ ch = this.#scanner.peek();
12011
12155
  } else {
12012
12156
  break;
12013
12157
  }
@@ -12018,9 +12162,9 @@ var LoaderState = class {
12018
12162
  return lineBreaks;
12019
12163
  }
12020
12164
  testDocumentSeparator() {
12021
- let ch = this.peek();
12022
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
12023
- ch = this.peek(3);
12165
+ let ch = this.#scanner.peek();
12166
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
12167
+ ch = this.#scanner.peek(3);
12024
12168
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
12025
12169
  return true;
12026
12170
  }
@@ -12028,34 +12172,34 @@ var LoaderState = class {
12028
12172
  return false;
12029
12173
  }
12030
12174
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
12031
- let ch = this.peek();
12175
+ let ch = this.#scanner.peek();
12032
12176
  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) {
12033
12177
  return;
12034
12178
  }
12035
12179
  let following;
12036
12180
  if (ch === QUESTION || ch === MINUS) {
12037
- following = this.peek(1);
12181
+ following = this.#scanner.peek(1);
12038
12182
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
12039
12183
  return;
12040
12184
  }
12041
12185
  }
12042
12186
  let result = "";
12043
- let captureEnd = this.position;
12044
- let captureStart = this.position;
12187
+ let captureEnd = this.#scanner.position;
12188
+ let captureStart = this.#scanner.position;
12045
12189
  let hasPendingContent = false;
12046
12190
  let line = 0;
12047
12191
  while (ch !== 0) {
12048
12192
  if (ch === COLON) {
12049
- following = this.peek(1);
12193
+ following = this.#scanner.peek(1);
12050
12194
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
12051
12195
  break;
12052
12196
  }
12053
12197
  } else if (ch === SHARP) {
12054
- const preceding = this.peek(-1);
12198
+ const preceding = this.#scanner.peek(-1);
12055
12199
  if (isWhiteSpaceOrEOL(preceding)) {
12056
12200
  break;
12057
12201
  }
12058
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
12202
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
12059
12203
  break;
12060
12204
  } else if (isEOL(ch)) {
12061
12205
  line = this.line;
@@ -12064,10 +12208,10 @@ var LoaderState = class {
12064
12208
  this.skipSeparationSpace(false, -1);
12065
12209
  if (this.lineIndent >= nodeIndent) {
12066
12210
  hasPendingContent = true;
12067
- ch = this.peek();
12211
+ ch = this.#scanner.peek();
12068
12212
  continue;
12069
12213
  } else {
12070
- this.position = captureEnd;
12214
+ this.#scanner.position = captureEnd;
12071
12215
  this.line = line;
12072
12216
  this.lineStart = lineStart;
12073
12217
  this.lineIndent = lineIndent;
@@ -12078,13 +12222,14 @@ var LoaderState = class {
12078
12222
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
12079
12223
  if (segment2) result += segment2;
12080
12224
  result += writeFoldedLines(this.line - line);
12081
- captureStart = captureEnd = this.position;
12225
+ captureStart = captureEnd = this.#scanner.position;
12082
12226
  hasPendingContent = false;
12083
12227
  }
12084
12228
  if (!isWhiteSpace(ch)) {
12085
- captureEnd = this.position + 1;
12229
+ captureEnd = this.#scanner.position + 1;
12086
12230
  }
12087
- ch = this.next();
12231
+ this.#scanner.next();
12232
+ ch = this.#scanner.peek();
12088
12233
  }
12089
12234
  const segment = this.captureSegment(captureStart, captureEnd, false);
12090
12235
  if (segment) result += segment;
@@ -12097,22 +12242,23 @@ var LoaderState = class {
12097
12242
  };
12098
12243
  }
12099
12244
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
12100
- let ch = this.peek();
12245
+ let ch = this.#scanner.peek();
12101
12246
  if (ch !== SINGLE_QUOTE) return;
12102
12247
  let result = "";
12103
- this.position++;
12104
- let captureStart = this.position;
12105
- let captureEnd = this.position;
12106
- ch = this.peek();
12248
+ this.#scanner.next();
12249
+ let captureStart = this.#scanner.position;
12250
+ let captureEnd = this.#scanner.position;
12251
+ ch = this.#scanner.peek();
12107
12252
  while (ch !== 0) {
12108
12253
  if (ch === SINGLE_QUOTE) {
12109
- const segment = this.captureSegment(captureStart, this.position, true);
12254
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
12110
12255
  if (segment) result += segment;
12111
- ch = this.next();
12256
+ this.#scanner.next();
12257
+ ch = this.#scanner.peek();
12112
12258
  if (ch === SINGLE_QUOTE) {
12113
- captureStart = this.position;
12114
- this.position++;
12115
- captureEnd = this.position;
12259
+ captureStart = this.#scanner.position;
12260
+ this.#scanner.next();
12261
+ captureEnd = this.#scanner.position;
12116
12262
  } else {
12117
12263
  if (anchor !== null) this.anchorMap.set(anchor, result);
12118
12264
  return {
@@ -12126,31 +12272,31 @@ var LoaderState = class {
12126
12272
  const segment = this.captureSegment(captureStart, captureEnd, true);
12127
12273
  if (segment) result += segment;
12128
12274
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
12129
- captureStart = captureEnd = this.position;
12130
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
12275
+ captureStart = captureEnd = this.#scanner.position;
12276
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
12131
12277
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
12132
12278
  } else {
12133
- this.position++;
12134
- captureEnd = this.position;
12279
+ this.#scanner.next();
12280
+ captureEnd = this.#scanner.position;
12135
12281
  }
12136
- ch = this.peek();
12282
+ ch = this.#scanner.peek();
12137
12283
  }
12138
12284
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
12139
12285
  }
12140
12286
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
12141
- let ch = this.peek();
12287
+ let ch = this.#scanner.peek();
12142
12288
  if (ch !== DOUBLE_QUOTE) return;
12143
12289
  let result = "";
12144
- this.position++;
12145
- let captureEnd = this.position;
12146
- let captureStart = this.position;
12290
+ this.#scanner.next();
12291
+ let captureEnd = this.#scanner.position;
12292
+ let captureStart = this.#scanner.position;
12147
12293
  let tmp;
12148
- ch = this.peek();
12294
+ ch = this.#scanner.peek();
12149
12295
  while (ch !== 0) {
12150
12296
  if (ch === DOUBLE_QUOTE) {
12151
- const segment = this.captureSegment(captureStart, this.position, true);
12297
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
12152
12298
  if (segment) result += segment;
12153
- this.position++;
12299
+ this.#scanner.next();
12154
12300
  if (anchor !== null) this.anchorMap.set(anchor, result);
12155
12301
  return {
12156
12302
  tag,
@@ -12160,19 +12306,21 @@ var LoaderState = class {
12160
12306
  };
12161
12307
  }
12162
12308
  if (ch === BACKSLASH) {
12163
- const segment = this.captureSegment(captureStart, this.position, true);
12309
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
12164
12310
  if (segment) result += segment;
12165
- ch = this.next();
12311
+ this.#scanner.next();
12312
+ ch = this.#scanner.peek();
12166
12313
  if (isEOL(ch)) {
12167
12314
  this.skipSeparationSpace(false, nodeIndent);
12168
12315
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
12169
12316
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
12170
- this.position++;
12317
+ this.#scanner.next();
12171
12318
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
12172
12319
  let hexLength = tmp;
12173
12320
  let hexResult = 0;
12174
12321
  for (; hexLength > 0; hexLength--) {
12175
- ch = this.next();
12322
+ this.#scanner.next();
12323
+ ch = this.#scanner.peek();
12176
12324
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
12177
12325
  hexResult = (hexResult << 4) + tmp;
12178
12326
  } else {
@@ -12180,28 +12328,28 @@ var LoaderState = class {
12180
12328
  }
12181
12329
  }
12182
12330
  result += codepointToChar(hexResult);
12183
- this.position++;
12331
+ this.#scanner.next();
12184
12332
  } else {
12185
12333
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
12186
12334
  }
12187
- captureStart = captureEnd = this.position;
12335
+ captureStart = captureEnd = this.#scanner.position;
12188
12336
  } else if (isEOL(ch)) {
12189
12337
  const segment = this.captureSegment(captureStart, captureEnd, true);
12190
12338
  if (segment) result += segment;
12191
12339
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
12192
- captureStart = captureEnd = this.position;
12193
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
12340
+ captureStart = captureEnd = this.#scanner.position;
12341
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
12194
12342
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
12195
12343
  } else {
12196
- this.position++;
12197
- captureEnd = this.position;
12344
+ this.#scanner.next();
12345
+ captureEnd = this.#scanner.position;
12198
12346
  }
12199
- ch = this.peek();
12347
+ ch = this.#scanner.peek();
12200
12348
  }
12201
12349
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
12202
12350
  }
12203
12351
  readFlowCollection(tag, anchor, nodeIndent) {
12204
- let ch = this.peek();
12352
+ let ch = this.#scanner.peek();
12205
12353
  let terminator;
12206
12354
  let isMapping = true;
12207
12355
  let result = {};
@@ -12215,7 +12363,8 @@ var LoaderState = class {
12215
12363
  return;
12216
12364
  }
12217
12365
  if (anchor !== null) this.anchorMap.set(anchor, result);
12218
- ch = this.next();
12366
+ this.#scanner.next();
12367
+ ch = this.#scanner.peek();
12219
12368
  let readNext = true;
12220
12369
  let valueNode = null;
12221
12370
  let keyNode = null;
@@ -12227,9 +12376,9 @@ var LoaderState = class {
12227
12376
  const overridableKeys = /* @__PURE__ */ new Set();
12228
12377
  while (ch !== 0) {
12229
12378
  this.skipSeparationSpace(true, nodeIndent);
12230
- ch = this.peek();
12379
+ ch = this.#scanner.peek();
12231
12380
  if (ch === terminator) {
12232
- this.position++;
12381
+ this.#scanner.next();
12233
12382
  const kind = isMapping ? "mapping" : "sequence";
12234
12383
  return {
12235
12384
  tag,
@@ -12244,10 +12393,10 @@ var LoaderState = class {
12244
12393
  keyTag = keyNode = valueNode = null;
12245
12394
  isPair = isExplicitPair = false;
12246
12395
  if (ch === QUESTION) {
12247
- following = this.peek(1);
12396
+ following = this.#scanner.peek(1);
12248
12397
  if (isWhiteSpaceOrEOL(following)) {
12249
12398
  isPair = isExplicitPair = true;
12250
- this.position++;
12399
+ this.#scanner.next();
12251
12400
  this.skipSeparationSpace(true, nodeIndent);
12252
12401
  }
12253
12402
  }
@@ -12263,10 +12412,11 @@ var LoaderState = class {
12263
12412
  keyNode = newState.result;
12264
12413
  }
12265
12414
  this.skipSeparationSpace(true, nodeIndent);
12266
- ch = this.peek();
12415
+ ch = this.#scanner.peek();
12267
12416
  if ((isExplicitPair || this.line === line) && ch === COLON) {
12268
12417
  isPair = true;
12269
- ch = this.next();
12418
+ this.#scanner.next();
12419
+ ch = this.#scanner.peek();
12270
12420
  this.skipSeparationSpace(true, nodeIndent);
12271
12421
  const newState2 = this.composeNode({
12272
12422
  parentIndent: nodeIndent,
@@ -12284,10 +12434,11 @@ var LoaderState = class {
12284
12434
  result.push(keyNode);
12285
12435
  }
12286
12436
  this.skipSeparationSpace(true, nodeIndent);
12287
- ch = this.peek();
12437
+ ch = this.#scanner.peek();
12288
12438
  if (ch === COMMA) {
12289
12439
  readNext = true;
12290
- ch = this.next();
12440
+ this.#scanner.next();
12441
+ ch = this.#scanner.peek();
12291
12442
  } else {
12292
12443
  readNext = false;
12293
12444
  }
@@ -12303,7 +12454,7 @@ var LoaderState = class {
12303
12454
  let textIndent = nodeIndent;
12304
12455
  let emptyLines = 0;
12305
12456
  let atMoreIndented = false;
12306
- let ch = this.peek();
12457
+ let ch = this.#scanner.peek();
12307
12458
  let folding = false;
12308
12459
  if (ch === VERTICAL_LINE) {
12309
12460
  folding = false;
@@ -12315,7 +12466,8 @@ var LoaderState = class {
12315
12466
  let result = "";
12316
12467
  let tmp = 0;
12317
12468
  while (ch !== 0) {
12318
- ch = this.next();
12469
+ this.#scanner.next();
12470
+ ch = this.#scanner.peek();
12319
12471
  if (ch === PLUS || ch === MINUS) {
12320
12472
  if (CHOMPING_CLIP === chomping) {
12321
12473
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -12338,15 +12490,16 @@ var LoaderState = class {
12338
12490
  if (isWhiteSpace(ch)) {
12339
12491
  this.skipWhitespaces();
12340
12492
  this.skipComment();
12341
- ch = this.peek();
12493
+ ch = this.#scanner.peek();
12342
12494
  }
12343
12495
  while (ch !== 0) {
12344
12496
  this.readLineBreak();
12345
12497
  this.lineIndent = 0;
12346
- ch = this.peek();
12498
+ ch = this.#scanner.peek();
12347
12499
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
12348
12500
  this.lineIndent++;
12349
- ch = this.next();
12501
+ this.#scanner.next();
12502
+ ch = this.#scanner.peek();
12350
12503
  }
12351
12504
  if (!detectedIndent && this.lineIndent > textIndent) {
12352
12505
  textIndent = this.lineIndent;
@@ -12385,11 +12538,12 @@ var LoaderState = class {
12385
12538
  didReadContent = true;
12386
12539
  detectedIndent = true;
12387
12540
  emptyLines = 0;
12388
- const captureStart = this.position;
12541
+ const captureStart = this.#scanner.position;
12389
12542
  while (!isEOL(ch) && ch !== 0) {
12390
- ch = this.next();
12543
+ this.#scanner.next();
12544
+ ch = this.#scanner.peek();
12391
12545
  }
12392
- const segment = this.captureSegment(captureStart, this.position, false);
12546
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
12393
12547
  if (segment) result += segment;
12394
12548
  }
12395
12549
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -12412,11 +12566,11 @@ var LoaderState = class {
12412
12566
  let atExplicitKey = false;
12413
12567
  let detected = false;
12414
12568
  if (anchor !== null) this.anchorMap.set(anchor, result);
12415
- let ch = this.peek();
12569
+ let ch = this.#scanner.peek();
12416
12570
  while (ch !== 0) {
12417
- const following = this.peek(1);
12571
+ const following = this.#scanner.peek(1);
12418
12572
  line = this.line;
12419
- pos = this.position;
12573
+ pos = this.#scanner.position;
12420
12574
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
12421
12575
  if (ch === QUESTION) {
12422
12576
  if (atExplicitKey) {
@@ -12434,7 +12588,7 @@ var LoaderState = class {
12434
12588
  } else {
12435
12589
  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");
12436
12590
  }
12437
- this.position += 1;
12591
+ this.#scanner.next();
12438
12592
  ch = following;
12439
12593
  } else {
12440
12594
  const newState = this.composeNode({
@@ -12445,11 +12599,12 @@ var LoaderState = class {
12445
12599
  });
12446
12600
  if (!newState) break;
12447
12601
  if (this.line === line) {
12448
- ch = this.peek();
12602
+ ch = this.#scanner.peek();
12449
12603
  this.skipWhitespaces();
12450
- ch = this.peek();
12604
+ ch = this.#scanner.peek();
12451
12605
  if (ch === COLON) {
12452
- ch = this.next();
12606
+ this.#scanner.next();
12607
+ ch = this.#scanner.peek();
12453
12608
  if (!isWhiteSpaceOrEOL(ch)) {
12454
12609
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
12455
12610
  }
@@ -12506,7 +12661,7 @@ var LoaderState = class {
12506
12661
  keyTag = keyNode = valueNode = null;
12507
12662
  }
12508
12663
  this.skipSeparationSpace(true, -1);
12509
- ch = this.peek();
12664
+ ch = this.#scanner.peek();
12510
12665
  }
12511
12666
  if (this.lineIndent > nodeIndent && ch !== 0) {
12512
12667
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -12529,30 +12684,35 @@ var LoaderState = class {
12529
12684
  let isNamed = false;
12530
12685
  let tagHandle = "";
12531
12686
  let tagName;
12532
- let ch = this.peek();
12687
+ let ch = this.#scanner.peek();
12533
12688
  if (ch !== EXCLAMATION) return;
12534
12689
  if (tag !== null) {
12535
12690
  throw this.#createError("Cannot read tag property: duplication of a tag property");
12536
12691
  }
12537
- ch = this.next();
12692
+ this.#scanner.next();
12693
+ ch = this.#scanner.peek();
12538
12694
  if (ch === SMALLER_THAN) {
12539
12695
  isVerbatim = true;
12540
- ch = this.next();
12696
+ this.#scanner.next();
12697
+ ch = this.#scanner.peek();
12541
12698
  } else if (ch === EXCLAMATION) {
12542
12699
  isNamed = true;
12543
12700
  tagHandle = "!!";
12544
- ch = this.next();
12701
+ this.#scanner.next();
12702
+ ch = this.#scanner.peek();
12545
12703
  } else {
12546
12704
  tagHandle = "!";
12547
12705
  }
12548
- let position = this.position;
12706
+ let position = this.#scanner.position;
12549
12707
  if (isVerbatim) {
12550
12708
  do {
12551
- ch = this.next();
12709
+ this.#scanner.next();
12710
+ ch = this.#scanner.peek();
12552
12711
  } while (ch !== 0 && ch !== GREATER_THAN);
12553
- if (this.position < this.length) {
12554
- tagName = this.input.slice(position, this.position);
12555
- ch = this.next();
12712
+ if (!this.#scanner.eof()) {
12713
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
12714
+ this.#scanner.next();
12715
+ ch = this.#scanner.peek();
12556
12716
  } else {
12557
12717
  throw this.#createError("Cannot read tag property: unexpected end of stream");
12558
12718
  }
@@ -12560,19 +12720,20 @@ var LoaderState = class {
12560
12720
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
12561
12721
  if (ch === EXCLAMATION) {
12562
12722
  if (!isNamed) {
12563
- tagHandle = this.input.slice(position - 1, this.position + 1);
12723
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
12564
12724
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
12565
12725
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
12566
12726
  }
12567
12727
  isNamed = true;
12568
- position = this.position + 1;
12728
+ position = this.#scanner.position + 1;
12569
12729
  } else {
12570
12730
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
12571
12731
  }
12572
12732
  }
12573
- ch = this.next();
12733
+ this.#scanner.next();
12734
+ ch = this.#scanner.peek();
12574
12735
  }
12575
- tagName = this.input.slice(position, this.position);
12736
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
12576
12737
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
12577
12738
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
12578
12739
  }
@@ -12592,32 +12753,36 @@ var LoaderState = class {
12592
12753
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
12593
12754
  }
12594
12755
  readAnchorProperty(anchor) {
12595
- let ch = this.peek();
12756
+ let ch = this.#scanner.peek();
12596
12757
  if (ch !== AMPERSAND) return;
12597
12758
  if (anchor !== null) {
12598
12759
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
12599
12760
  }
12600
- ch = this.next();
12601
- const position = this.position;
12761
+ this.#scanner.next();
12762
+ ch = this.#scanner.peek();
12763
+ const position = this.#scanner.position;
12602
12764
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
12603
- ch = this.next();
12765
+ this.#scanner.next();
12766
+ ch = this.#scanner.peek();
12604
12767
  }
12605
- if (this.position === position) {
12768
+ if (this.#scanner.position === position) {
12606
12769
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
12607
12770
  }
12608
- return this.input.slice(position, this.position);
12771
+ return this.#scanner.source.slice(position, this.#scanner.position);
12609
12772
  }
12610
12773
  readAlias() {
12611
- if (this.peek() !== ASTERISK) return;
12612
- let ch = this.next();
12613
- const position = this.position;
12774
+ if (this.#scanner.peek() !== ASTERISK) return;
12775
+ this.#scanner.next();
12776
+ let ch = this.#scanner.peek();
12777
+ const position = this.#scanner.position;
12614
12778
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
12615
- ch = this.next();
12779
+ this.#scanner.next();
12780
+ ch = this.#scanner.peek();
12616
12781
  }
12617
- if (this.position === position) {
12782
+ if (this.#scanner.position === position) {
12618
12783
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
12619
12784
  }
12620
- const alias = this.input.slice(position, this.position);
12785
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
12621
12786
  if (!this.anchorMap.has(alias)) {
12622
12787
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
12623
12788
  }
@@ -12700,7 +12865,7 @@ var LoaderState = class {
12700
12865
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
12701
12866
  const flowIndent = cond ? parentIndent : parentIndent + 1;
12702
12867
  if (allowBlockCollections) {
12703
- const blockIndent = this.position - this.lineStart;
12868
+ const blockIndent = this.#scanner.position - this.lineStart;
12704
12869
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
12705
12870
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
12706
12871
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -12734,7 +12899,7 @@ var LoaderState = class {
12734
12899
  return this.resolveTag(plainScalarState);
12735
12900
  }
12736
12901
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
12737
- const blockIndent = this.position - this.lineStart;
12902
+ const blockIndent = this.#scanner.position - this.lineStart;
12738
12903
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
12739
12904
  if (newState2) return this.resolveTag(newState2);
12740
12905
  }
@@ -12749,20 +12914,22 @@ var LoaderState = class {
12749
12914
  readDirectives() {
12750
12915
  let hasDirectives = false;
12751
12916
  let version = null;
12752
- let ch = this.peek();
12917
+ let ch = this.#scanner.peek();
12753
12918
  while (ch !== 0) {
12754
12919
  this.skipSeparationSpace(true, -1);
12755
- ch = this.peek();
12920
+ ch = this.#scanner.peek();
12756
12921
  if (this.lineIndent > 0 || ch !== PERCENT) {
12757
12922
  break;
12758
12923
  }
12759
12924
  hasDirectives = true;
12760
- ch = this.next();
12761
- let position = this.position;
12925
+ this.#scanner.next();
12926
+ ch = this.#scanner.peek();
12927
+ let position = this.#scanner.position;
12762
12928
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
12763
- ch = this.next();
12929
+ this.#scanner.next();
12930
+ ch = this.#scanner.peek();
12764
12931
  }
12765
- const directiveName = this.input.slice(position, this.position);
12932
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
12766
12933
  const directiveArgs = [];
12767
12934
  if (directiveName.length < 1) {
12768
12935
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -12770,13 +12937,14 @@ var LoaderState = class {
12770
12937
  while (ch !== 0) {
12771
12938
  this.skipWhitespaces();
12772
12939
  this.skipComment();
12773
- ch = this.peek();
12940
+ ch = this.#scanner.peek();
12774
12941
  if (isEOL(ch)) break;
12775
- position = this.position;
12942
+ position = this.#scanner.position;
12776
12943
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
12777
- ch = this.next();
12944
+ this.#scanner.next();
12945
+ ch = this.#scanner.peek();
12778
12946
  }
12779
- directiveArgs.push(this.input.slice(position, this.position));
12947
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
12780
12948
  }
12781
12949
  if (ch !== 0) this.readLineBreak();
12782
12950
  switch (directiveName) {
@@ -12793,20 +12961,20 @@ var LoaderState = class {
12793
12961
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
12794
12962
  break;
12795
12963
  }
12796
- ch = this.peek();
12964
+ ch = this.#scanner.peek();
12797
12965
  }
12798
12966
  return hasDirectives;
12799
12967
  }
12800
12968
  readDocument() {
12801
- const documentStart = this.position;
12969
+ const documentStart = this.#scanner.position;
12802
12970
  this.checkLineBreaks = false;
12803
12971
  this.tagMap = /* @__PURE__ */ new Map();
12804
12972
  this.anchorMap = /* @__PURE__ */ new Map();
12805
12973
  const hasDirectives = this.readDirectives();
12806
12974
  this.skipSeparationSpace(true, -1);
12807
12975
  let result = null;
12808
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
12809
- this.position += 3;
12976
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
12977
+ this.#scanner.position += 3;
12810
12978
  this.skipSeparationSpace(true, -1);
12811
12979
  } else if (hasDirectives) {
12812
12980
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -12819,21 +12987,21 @@ var LoaderState = class {
12819
12987
  });
12820
12988
  if (newState) result = newState.result;
12821
12989
  this.skipSeparationSpace(true, -1);
12822
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
12990
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
12823
12991
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
12824
12992
  }
12825
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
12826
- if (this.peek() === DOT) {
12827
- this.position += 3;
12993
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
12994
+ if (this.#scanner.peek() === DOT) {
12995
+ this.#scanner.position += 3;
12828
12996
  this.skipSeparationSpace(true, -1);
12829
12997
  }
12830
- } else if (this.position < this.length - 1) {
12998
+ } else if (!this.#scanner.eof()) {
12831
12999
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
12832
13000
  }
12833
13001
  return result;
12834
13002
  }
12835
13003
  *readDocuments() {
12836
- while (this.position < this.length - 1) {
13004
+ while (!this.#scanner.eof()) {
12837
13005
  yield this.readDocument();
12838
13006
  }
12839
13007
  }
@@ -12846,7 +13014,6 @@ function sanitizeInput(input) {
12846
13014
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
12847
13015
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
12848
13016
  }
12849
- input += "\0";
12850
13017
  return input;
12851
13018
  }
12852
13019
  function parse(content, options = {}) {
@@ -13732,6 +13899,7 @@ data:
13732
13899
  async handleGetRequest(req) {
13733
13900
  const acceptHeader = req.headers.get("accept");
13734
13901
  if (!acceptHeader?.includes("text/event-stream")) {
13902
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
13735
13903
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
13736
13904
  }
13737
13905
  const sessionError = this.validateSession(req);
@@ -13749,6 +13917,7 @@ data:
13749
13917
  }
13750
13918
  }
13751
13919
  if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
13920
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
13752
13921
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
13753
13922
  }
13754
13923
  const encoder2 = new TextEncoder();
@@ -13788,6 +13957,7 @@ data:
13788
13957
  */
13789
13958
  async replayEvents(lastEventId) {
13790
13959
  if (!this._eventStore) {
13960
+ this.onerror?.(new Error("Event store not configured"));
13791
13961
  return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
13792
13962
  }
13793
13963
  try {
@@ -13795,9 +13965,11 @@ data:
13795
13965
  if (this._eventStore.getStreamIdForEventId) {
13796
13966
  streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
13797
13967
  if (!streamId) {
13968
+ this.onerror?.(new Error("Invalid event ID format"));
13798
13969
  return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
13799
13970
  }
13800
13971
  if (this._streamMapping.get(streamId) !== void 0) {
13972
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
13801
13973
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
13802
13974
  }
13803
13975
  }
@@ -13863,7 +14035,8 @@ data:
13863
14035
  `;
13864
14036
  controller.enqueue(encoder2.encode(eventData));
13865
14037
  return true;
13866
- } catch {
14038
+ } catch (error) {
14039
+ this.onerror?.(error);
13867
14040
  return false;
13868
14041
  }
13869
14042
  }
@@ -13871,6 +14044,7 @@ data:
13871
14044
  * Handles unsupported requests (PUT, PATCH, etc.)
13872
14045
  */
13873
14046
  handleUnsupportedRequest() {
14047
+ this.onerror?.(new Error("Method not allowed."));
13874
14048
  return new Response(JSON.stringify({
13875
14049
  jsonrpc: "2.0",
13876
14050
  error: {
@@ -13893,14 +14067,17 @@ data:
13893
14067
  try {
13894
14068
  const acceptHeader = req.headers.get("accept");
13895
14069
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
14070
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
13896
14071
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
13897
14072
  }
13898
14073
  const ct = req.headers.get("content-type");
13899
14074
  if (!ct || !ct.includes("application/json")) {
14075
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
13900
14076
  return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
13901
14077
  }
13902
14078
  const requestInfo = {
13903
- headers: Object.fromEntries(req.headers.entries())
14079
+ headers: Object.fromEntries(req.headers.entries()),
14080
+ url: new URL(req.url)
13904
14081
  };
13905
14082
  let rawMessage;
13906
14083
  if (options?.parsedBody !== void 0) {
@@ -13909,6 +14086,7 @@ data:
13909
14086
  try {
13910
14087
  rawMessage = await req.json();
13911
14088
  } catch {
14089
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
13912
14090
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
13913
14091
  }
13914
14092
  }
@@ -13920,14 +14098,17 @@ data:
13920
14098
  messages = [JSONRPCMessageSchema.parse(rawMessage)];
13921
14099
  }
13922
14100
  } catch {
14101
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
13923
14102
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
13924
14103
  }
13925
14104
  const isInitializationRequest = messages.some(isInitializeRequest);
13926
14105
  if (isInitializationRequest) {
13927
14106
  if (this._initialized && this.sessionId !== void 0) {
14107
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
13928
14108
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
13929
14109
  }
13930
14110
  if (messages.length > 1) {
14111
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
13931
14112
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
13932
14113
  }
13933
14114
  this.sessionId = this.sessionIdGenerator?.();
@@ -14053,13 +14234,16 @@ data:
14053
14234
  return void 0;
14054
14235
  }
14055
14236
  if (!this._initialized) {
14237
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
14056
14238
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
14057
14239
  }
14058
14240
  const sessionId = req.headers.get("mcp-session-id");
14059
14241
  if (!sessionId) {
14242
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
14060
14243
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
14061
14244
  }
14062
14245
  if (sessionId !== this.sessionId) {
14246
+ this.onerror?.(new Error("Session not found"));
14063
14247
  return this.createJsonErrorResponse(404, -32001, "Session not found");
14064
14248
  }
14065
14249
  return void 0;
@@ -14080,6 +14264,7 @@ data:
14080
14264
  validateProtocolVersion(req) {
14081
14265
  const protocolVersion = req.headers.get("mcp-protocol-version");
14082
14266
  if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
14267
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
14083
14268
  return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
14084
14269
  }
14085
14270
  return void 0;
@@ -14286,7 +14471,7 @@ var StreamableHTTPServerTransport = class {
14286
14471
  };
14287
14472
 
14288
14473
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
14289
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
14474
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
14290
14475
  var LETTER_REGEXP = /[A-Za-z]/;
14291
14476
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
14292
14477
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -14297,12 +14482,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
14297
14482
  function isNumber(string3) {
14298
14483
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
14299
14484
  }
14485
+ function isConstructorOrProto(obj, key) {
14486
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
14487
+ }
14300
14488
  function setNested(object5, keys, value, collect = false) {
14301
14489
  keys = [
14302
14490
  ...keys
14303
14491
  ];
14304
14492
  const key = keys.pop();
14305
- keys.forEach((key2) => object5 = object5[key2] ??= {});
14493
+ for (const k of keys) {
14494
+ if (isConstructorOrProto(object5, k)) return;
14495
+ object5 = object5[k] ??= {};
14496
+ }
14497
+ if (isConstructorOrProto(object5, key)) return;
14306
14498
  if (collect) {
14307
14499
  const v = object5[key];
14308
14500
  if (Array.isArray(v)) {
@@ -14433,7 +14625,7 @@ function parseArgs(args, options) {
14433
14625
  let key = groups.key;
14434
14626
  let value = groups.value;
14435
14627
  if (doubleDash2) {
14436
- if (value) {
14628
+ if (value != null) {
14437
14629
  if (booleanSet.has(key)) value = parseBooleanString(value);
14438
14630
  setArgument(key, value, arg, true);
14439
14631
  continue;
@@ -14471,6 +14663,10 @@ function parseArgs(args, options) {
14471
14663
  setArgument(letter, next, arg, true);
14472
14664
  continue;
14473
14665
  }
14666
+ if (next === "=") {
14667
+ setArgument(letter, "", arg, true);
14668
+ continue argsLoop;
14669
+ }
14474
14670
  if (LETTER_REGEXP.test(letter)) {
14475
14671
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
14476
14672
  if (groups2) {
@@ -14548,7 +14744,7 @@ var import_promises4 = require("node:fs/promises");
14548
14744
  var import_node_os3 = require("node:os");
14549
14745
  var import_node_path6 = require("node:path");
14550
14746
  var import_node_process9 = __toESM(require("node:process"), 1);
14551
- var CLI_VERSION = "0.1.44";
14747
+ var CLI_VERSION = "0.1.51";
14552
14748
  function extractServerName(command, commandArgs) {
14553
14749
  for (const arg of commandArgs) {
14554
14750
  if (!arg.startsWith("-")) {