@yawlabs/mcp 1.1.1 → 1.1.2

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.
@@ -161,8 +161,13 @@ function stripInternalSecretsFromEnv(env) {
161
161
 
162
162
  // src/logger.ts
163
163
  var LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
164
+ function resolveLogLevel() {
165
+ const raw = process.env.LOG_LEVEL?.trim().toLowerCase();
166
+ return raw !== void 0 && Object.hasOwn(LOG_LEVELS, raw) ? raw : null;
167
+ }
164
168
  function minLevel() {
165
- return LOG_LEVELS[process.env.LOG_LEVEL?.toLowerCase()] ?? LOG_LEVELS.info;
169
+ const level = resolveLogLevel();
170
+ return level === null ? LOG_LEVELS.info : LOG_LEVELS[level];
166
171
  }
167
172
  function guardStderrErrors() {
168
173
  try {
@@ -178,8 +183,7 @@ function setLogSurface(next) {
178
183
  surface = next;
179
184
  }
180
185
  function logLevelRequested() {
181
- const raw = process.env.LOG_LEVEL?.trim().toLowerCase();
182
- return raw !== void 0 && raw in LOG_LEVELS;
186
+ return resolveLogLevel() !== null;
183
187
  }
184
188
  function renderData(data) {
185
189
  if (data === void 0) return "";
@@ -245,6 +249,21 @@ function isFeatureDisabled(name, env = process.env) {
245
249
  if (trimmed === "") return false;
246
250
  return trimmed === "0" || trimmed.toLowerCase() === "false";
247
251
  }
252
+ function isFeatureEnabled(name, env = process.env) {
253
+ const raw = env[name];
254
+ if (raw === void 0) return false;
255
+ const trimmed = raw.trim();
256
+ return trimmed === "1" || trimmed.toLowerCase() === "true";
257
+ }
258
+ function resolveNonNegativeIntEnv(name, defaultValue, env = process.env, min = 0) {
259
+ const raw = env[name];
260
+ if (raw === void 0) return defaultValue;
261
+ const trimmed = raw.trim();
262
+ if (!/^\d+$/.test(trimmed)) return defaultValue;
263
+ const n = Number.parseInt(trimmed, 10);
264
+ if (!Number.isFinite(n) || n < min) return defaultValue;
265
+ return n;
266
+ }
248
267
  function isTestSandbox(env = process.env) {
249
268
  const raw = env.VITEST;
250
269
  return raw !== void 0 && raw !== "";
@@ -701,6 +720,12 @@ function addJsoncArrayElement(src, path5, value) {
701
720
  const errors = [];
702
721
  const root = parseTree(debommed, errors, { allowTrailingComma: true });
703
722
  const existing = root === void 0 ? void 0 : findNodeAtLocation(root, path5);
723
+ if (existing?.type === "array") {
724
+ const wanted2 = JSON.stringify(value);
725
+ const elements = (existing.children ?? []).map(elementValue);
726
+ if (elements.some((e) => JSON.stringify(e) === wanted2)) return src;
727
+ return editJsoncPath(debommed, path5, [...elements, value]);
728
+ }
704
729
  if (existing !== void 0) {
705
730
  throw new Error(`addJsoncArrayElement: ${path5.join(".")} is a ${existing.type}, not an array`);
706
731
  }
@@ -721,7 +746,16 @@ function removeJsoncArrayElements(src, path5, matches) {
721
746
  if (path5.length === 0) throw new Error("removeJsoncArrayElements: path must not be empty");
722
747
  const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
723
748
  const array = arrayNodeAt(debommed, path5);
724
- if (array === null) return src;
749
+ if (array === null) {
750
+ const errors = [];
751
+ const root = parseTree(debommed, errors, { allowTrailingComma: true });
752
+ const existing = root === void 0 ? void 0 : findNodeAtLocation(root, path5);
753
+ if (existing?.type !== "array") return src;
754
+ const elements = (existing.children ?? []).map(elementValue);
755
+ const kept = elements.filter((e) => !matches(e));
756
+ if (kept.length === elements.length) return src;
757
+ return editJsoncPath(debommed, path5, kept);
758
+ }
725
759
  const doomed = (array.children ?? []).filter((child) => matches(elementValue(child)));
726
760
  if (doomed.length === 0) return src;
727
761
  let text = debommed;
@@ -1134,7 +1168,7 @@ function makeView(read, raw, address, addressIndex, adapter, opts) {
1134
1168
  legacyKey: () => findLegacyKey(entries.map((e) => e.key)),
1135
1169
  otherServerKeys: () => {
1136
1170
  const skip = /* @__PURE__ */ new Set([ENTRY_NAME, ...LEGACY_ENTRY_NAMES]);
1137
- return entries.filter((e) => !skip.has(e.key) && typeof e.value === "object" && e.value !== null && !Array.isArray(e.value)).map((e) => e.key);
1171
+ return entries.filter((e) => !skip.has(e.key) && isRecord(e.value)).map((e) => e.key);
1138
1172
  },
1139
1173
  count: () => entries.length,
1140
1174
  carryableEnv: (key) => carryableEnvOf(at(key)?.value),
@@ -2121,7 +2155,7 @@ function tomlNumber(value, key) {
2121
2155
  if (!Number.isFinite(value)) {
2122
2156
  throw new TomlRenderError(`cannot write ${String(value)} as the "${key}" value: it is not a finite number`);
2123
2157
  }
2124
- if (FLOAT_FIELDS.has(key) && Number.isInteger(value)) return `${value}.0`;
2158
+ if (FLOAT_FIELDS.has(key) && Number.isInteger(value) && Math.abs(value) < 1e21) return `${value}.0`;
2125
2159
  return String(value);
2126
2160
  }
2127
2161
  function tomlValue(value, key) {
@@ -3084,7 +3118,7 @@ var ZED_TARGET = defineTarget({
3084
3118
  entry: {
3085
3119
  carry: carryZedFields
3086
3120
  },
3087
- notes: "Zed reads context_servers from settings.json, which allows // comments and trailing commas, and starts, restarts or stops servers when the file is saved -- no restart needed. On Linux the path follows $XDG_CONFIG_HOME when it is set; the Flatpak build reads $FLATPAK_XDG_CONFIG_HOME/zed/settings.json instead, which install does not follow. Zed ignores a project's .zed/settings.json until you trust the project. Needs Zed v0.214.5 (2025-11-26) or newer: earlier versions reject this entry shape.",
3121
+ notes: "Zed reads context_servers from settings.json, which allows // comments and trailing commas, and starts, restarts or stops servers when the file is saved -- no restart needed. On Linux the path follows an absolute $XDG_CONFIG_HOME (Zed ignores a relative one, and so does install); the Flatpak build reads $FLATPAK_XDG_CONFIG_HOME/zed/settings.json instead, which install does not follow. Zed ignores a project's .zed/settings.json until you trust the project. Needs Zed v0.214.5 (2025-11-26) or newer: earlier versions reject this entry shape.",
3088
3122
  resolvePath: resolveZedPath,
3089
3123
  scopes: [
3090
3124
  // User FIRST, like every other multi-scope row: the probe walks this array
@@ -3156,8 +3190,9 @@ async function settingsFingerprint(path5) {
3156
3190
  try {
3157
3191
  const st = await stat2(path5);
3158
3192
  return { mtimeMs: st.mtimeMs, size: st.size };
3159
- } catch {
3160
- return null;
3193
+ } catch (err) {
3194
+ if (err?.code === "ENOENT") return null;
3195
+ throw err;
3161
3196
  }
3162
3197
  }
3163
3198
  async function prepareClaudeCodeSettingsPatch(opts) {
@@ -3169,7 +3204,21 @@ async function prepareClaudeCodeSettingsPatch(opts) {
3169
3204
  if (!path5) return null;
3170
3205
  let existing = {};
3171
3206
  let rawSettings = null;
3172
- const fingerprint = await settingsFingerprint(path5);
3207
+ let fingerprint;
3208
+ try {
3209
+ fingerprint = await settingsFingerprint(path5);
3210
+ } catch (e) {
3211
+ return {
3212
+ path: path5,
3213
+ nextJson: "",
3214
+ changed: false,
3215
+ added: [],
3216
+ removed: [],
3217
+ malformed: true,
3218
+ malformedReason: `could not stat it (${e.message})`,
3219
+ fingerprint: null
3220
+ };
3221
+ }
3173
3222
  if (fingerprint !== null) {
3174
3223
  try {
3175
3224
  const raw = await readFile2(path5, "utf8");
@@ -3229,6 +3278,20 @@ async function prepareClaudeCodeSettingsPatch(opts) {
3229
3278
  }
3230
3279
  try {
3231
3280
  const next = patchPermissionsAllowText(rawSettings, [CLAUDE_CODE_ALLOW_PATTERN], op);
3281
+ const nextAllow = parseJsonc(next)?.permissions?.allow;
3282
+ const hasPattern = Array.isArray(nextAllow) && nextAllow.includes(CLAUDE_CODE_ALLOW_PATTERN);
3283
+ if (next === rawSettings || hasPattern !== (op === "add")) {
3284
+ return {
3285
+ path: path5,
3286
+ nextJson: "",
3287
+ changed: false,
3288
+ added: [],
3289
+ removed: [],
3290
+ malformed: true,
3291
+ malformedReason: `could not splice permissions.allow (the edit left the pattern ${op === "add" ? "absent" : "present"})`,
3292
+ fingerprint
3293
+ };
3294
+ }
3232
3295
  return { path: path5, nextJson: terminateWithNewline(next), changed: true, added, removed, fingerprint };
3233
3296
  } catch (e) {
3234
3297
  return {
@@ -3837,7 +3900,7 @@ function rememberWarnedUntrustedDir(candidate) {
3837
3900
  }
3838
3901
  function ownedByCurrentUser(st, env) {
3839
3902
  const geteuid = process.geteuid;
3840
- if (typeof geteuid !== "function") return env[ALLOW_UNOWNED_ENV] === "1";
3903
+ if (typeof geteuid !== "function") return isFeatureEnabled(ALLOW_UNOWNED_ENV, env);
3841
3904
  return typeof st.uid === "number" && st.uid === geteuid.call(process);
3842
3905
  }
3843
3906
  async function findProjectConfigDir(start, home = homedir3(), env = process.env) {
@@ -4030,9 +4093,7 @@ var STATE_SCHEMA_VERSION = 2;
4030
4093
  var STATE_FILENAME = "state.json";
4031
4094
  var DISABLE_PERSISTENCE_ENV = "YAW_MCP_DISABLE_PERSISTENCE";
4032
4095
  function isPersistenceDisabled(env = process.env) {
4033
- const raw = env[DISABLE_PERSISTENCE_ENV]?.trim();
4034
- if (raw === void 0 || raw === "") return false;
4035
- return raw === "1" || raw.toLowerCase() === "true";
4096
+ return isFeatureEnabled(DISABLE_PERSISTENCE_ENV, env);
4036
4097
  }
4037
4098
  var READABLE_STATE_VERSIONS = /* @__PURE__ */ new Set([1, STATE_SCHEMA_VERSION]);
4038
4099
  function isReadableStateVersion(version) {
@@ -4904,13 +4965,15 @@ async function probeOamUncached(run, generation) {
4904
4965
  // on), so below-min always means out of date, and oam updates itself
4905
4966
  // in place.
4906
4967
  updateWith: "oam self-update",
4907
- // ...but updating alone changes nothing here. oamProbeCache is written
4908
- // once per process and only ever cleared by a test hook, so every
4909
- // opted-in server keeps landing on node until the broker restarts --
4910
- // and an MCP broker under a desktop client lives for days. Without this
4911
- // the user runs the update, sees no further log line, and reads a
4912
- // working fix as a fix that did not work. The timeout and generic
4913
- // failure warns say "for this process" for the same reason.
4968
+ // ...but updating alone changes nothing here. A non-timeout verdict
4969
+ // like this one is cached for the process lifetime and only cleared by
4970
+ // a test hook (only a timeout verdict lapses, after
4971
+ // OAM_PROBE_TIMEOUT_RECHECK_MS), so every opted-in server keeps landing
4972
+ // on node until the broker restarts -- and an MCP broker under a
4973
+ // desktop client lives for days. Without this the user runs the update,
4974
+ // sees no further log line, and reads a working fix as a fix that did
4975
+ // not work. The generic failure warns say "for this process" for the
4976
+ // same reason; the timeout warn says it is probed again instead.
4914
4977
  thenRestart: "restart yaw-mcp; this probe is cached for the process lifetime"
4915
4978
  });
4916
4979
  return publish({ bin: null, binPath: null, version, belowMin: true, failure: null, failureDetail: null });
@@ -5047,11 +5110,11 @@ function managedNodeBin(env = process.env, platform = process.platform, execPath
5047
5110
  return resolveBinAbsolute("node", env, platform);
5048
5111
  }
5049
5112
  function rewriteNpmToManagedNode(command, args, deps) {
5113
+ if (nodeLaunchKind(command) !== "npx") return { command, args };
5050
5114
  if (!deps.nodeBin) {
5051
5115
  log("debug", "no node binary located for the managed sidecar spawn; staying on npx", { command });
5052
5116
  return { command, args };
5053
5117
  }
5054
- if (nodeLaunchKind(command) !== "npx") return { command, args };
5055
5118
  const specIdx = npxSpecIndex(args);
5056
5119
  const spec = specIdx === -1 ? void 0 : args[specIdx];
5057
5120
  if (!spec) return { command, args };
@@ -5319,7 +5382,7 @@ function notePinnedSidecar(pkg, version, source, from) {
5319
5382
  pinnedReported.add(pkg);
5320
5383
  log(
5321
5384
  source === "managed" ? "debug" : "info",
5322
- "hosting sidecar on oam from an on-disk copy; it will not self-update the way npx does",
5385
+ "running sidecar from an on-disk copy instead of npx; it will not self-update the way npx does",
5323
5386
  {
5324
5387
  package: pkg,
5325
5388
  version: version ?? "unknown",
@@ -5383,9 +5446,10 @@ async function resolveOamSpawn(command, args, optedIn = true) {
5383
5446
  });
5384
5447
  }
5385
5448
  var managedEntryMemo = /* @__PURE__ */ new Map();
5386
- function resolveManagedSpawn(command, args, fromUrl = import.meta.url, npmCache = npmCacheDir(fromUrl), managedRoot = sidecarsNodeModules(), nodeBin = managedNodeBin()) {
5449
+ function resolveManagedSpawn(command, args, fromUrl = import.meta.url, npmCache = npmCacheDir(fromUrl), managedRoot = sidecarsNodeModules(), nodeBin) {
5450
+ if (nodeLaunchKind(command) !== "npx") return { command, args };
5387
5451
  return rewriteNpmToManagedNode(command, args, {
5388
- nodeBin,
5452
+ nodeBin: nodeBin === void 0 ? managedNodeBin() : nodeBin,
5389
5453
  resolveEntry: (pkg, wantVersion) => {
5390
5454
  if (wantVersion !== null) return resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, wantVersion);
5391
5455
  const memoed = managedEntryMemo.get(pkg);
@@ -5482,7 +5546,6 @@ function classifyEntrypoint(argvPath) {
5482
5546
  if (/\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5483
5547
  if (POSIX_GLOBAL_LIB_PREFIX.test(normalized)) return "global-npm";
5484
5548
  if (MANAGED_NODE_LIB_PREFIX.test(normalized)) return "global-npm";
5485
- if (/\/AppData\/Roaming\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5486
5549
  if (/\/\.npm-global\/(?:lib\/)?node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5487
5550
  if (/\/bin\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5488
5551
  if (/\/pnpm\/global\/\d+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "pnpm-global";
@@ -5491,10 +5554,19 @@ function classifyEntrypoint(argvPath) {
5491
5554
  if (/\/(yaw-mcp|mcph|mcp)\/(dist|src)\//.test(normalized)) return "dev-checkout";
5492
5555
  return "unknown";
5493
5556
  }
5494
- function localInstallRoot(argvPath) {
5557
+ function localInstallRoot(argvPath, realpath3 = realpathSync2) {
5495
5558
  if (!argvPath) return null;
5496
- const idx = argvPath.replace(/\\/g, "/").indexOf("/node_modules/");
5497
- return idx > 0 ? argvPath.slice(0, idx) : null;
5559
+ const literal = treeRootOf(argvPath);
5560
+ if (literal !== null) return literal;
5561
+ try {
5562
+ return treeRootOf(realpath3(argvPath));
5563
+ } catch {
5564
+ return null;
5565
+ }
5566
+ }
5567
+ function treeRootOf(p) {
5568
+ const idx = p.replace(/\\/g, "/").indexOf("/node_modules/");
5569
+ return idx > 0 ? p.slice(0, idx) : null;
5498
5570
  }
5499
5571
  function runningPackageDir(argvPath, realpath3 = realpathSync2) {
5500
5572
  if (!argvPath) return null;
@@ -5698,17 +5770,17 @@ async function oamFloorLines(probe) {
5698
5770
  }
5699
5771
  async function defaultRunningPrefix(argvPath) {
5700
5772
  if (isTestSandbox()) return null;
5701
- const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-EXON4SEO.js");
5773
+ const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-XHSUUYUG.js");
5702
5774
  return detectRunningInstallPrefix2(argvPath);
5703
5775
  }
5704
5776
  async function defaultAcquireLock(prefixDir) {
5705
5777
  if (isTestSandbox()) return () => {
5706
5778
  };
5707
- const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-EXON4SEO.js");
5779
+ const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-XHSUUYUG.js");
5708
5780
  return acquireUpgradeLock2(prefixDir);
5709
5781
  }
5710
5782
  async function upgradeLockPath(prefixDir) {
5711
- const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-EXON4SEO.js");
5783
+ const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-XHSUUYUG.js");
5712
5784
  return join11(prefixDir, UPGRADE_LOCK_NAME2);
5713
5785
  }
5714
5786
  async function defaultSpawn(cmd, args, cwd) {
@@ -5756,7 +5828,8 @@ async function runUpgrade(opts = {}) {
5756
5828
  const current = opts.currentVersion ?? readCurrentVersion();
5757
5829
  const argvPath = opts.argvPath ?? process.argv[1];
5758
5830
  const sea = opts.isSea ? opts.isSea() : await detectSea();
5759
- const method = sea ? "binary" : await refineInstallMethod(detectInstallMethod(argvPath), argvPath, opts.npmPrefix);
5831
+ const realpath3 = opts.realpath ?? realpathSync2;
5832
+ const method = sea ? "binary" : await refineInstallMethod(detectInstallMethod(argvPath, realpath3), argvPath, opts.npmPrefix);
5760
5833
  let latest;
5761
5834
  try {
5762
5835
  latest = await fetcher();
@@ -5770,7 +5843,7 @@ async function runUpgrade(opts = {}) {
5770
5843
  if (method === "global-npm") {
5771
5844
  rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
5772
5845
  if (rawPrefix !== null) {
5773
- const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-EXON4SEO.js");
5846
+ const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-XHSUUYUG.js");
5774
5847
  const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
5775
5848
  const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
5776
5849
  if (spawnForm !== null && displayForm !== null) {
@@ -5780,7 +5853,7 @@ async function runUpgrade(opts = {}) {
5780
5853
  }
5781
5854
  }
5782
5855
  }
5783
- const installRoot = method === "local-node-modules" ? localInstallRoot(argvPath) : null;
5856
+ const installRoot = method === "local-node-modules" ? localInstallRoot(argvPath, realpath3) : null;
5784
5857
  if (opts.json) {
5785
5858
  print(JSON.stringify({ ...plan, command: suggestedCommand, cwd: installRoot }, null, 2));
5786
5859
  return { exitCode: plan.stale ? 1 : 0, lines };
@@ -5880,7 +5953,7 @@ async function runUpgrade(opts = {}) {
5880
5953
  if (code === 0) {
5881
5954
  print("");
5882
5955
  print(`OK: Upgraded @yawlabs/mcp to ${latest}`);
5883
- const pkgDir = runningPackageDir(argvPath);
5956
+ const pkgDir = runningPackageDir(argvPath, realpath3);
5884
5957
  const running = pkgDir === null ? null : await (opts.installedVersion ?? defaultInstalledVersion)(pkgDir);
5885
5958
  const bare = (s) => s.startsWith("v") ? s.slice(1) : s;
5886
5959
  if (running !== null && compareVersions(bare(running), bare(latest)) < 0) {
@@ -5902,7 +5975,7 @@ async function runUpgrade(opts = {}) {
5902
5975
  return { exitCode: 3, lines };
5903
5976
  }
5904
5977
  function readCurrentVersion() {
5905
- return true ? "1.1.1" : "dev";
5978
+ return true ? "1.1.2" : "dev";
5906
5979
  }
5907
5980
 
5908
5981
  // src/auto-upgrade.ts
@@ -6194,7 +6267,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
6194
6267
  }
6195
6268
  async function maybeAutoUpgrade(deps = {}) {
6196
6269
  if (isFeatureDisabled("YAW_MCP_AUTO_UPGRADE")) return;
6197
- const current = deps.currentVersion ?? (true ? "1.1.1" : "dev");
6270
+ const current = deps.currentVersion ?? (true ? "1.1.2" : "dev");
6198
6271
  if (current === "dev") return;
6199
6272
  const argvPath = deps.argvPath ?? process.argv[1];
6200
6273
  let method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync3, ["unknown", "local-node-modules"]);
@@ -6311,6 +6384,10 @@ export {
6311
6384
  stripTrailingCommas,
6312
6385
  parseJsonc,
6313
6386
  editJsoncPath,
6387
+ isFeatureDisabled,
6388
+ isFeatureEnabled,
6389
+ resolveNonNegativeIntEnv,
6390
+ isTestSandbox,
6314
6391
  cacheDir,
6315
6392
  CONFIG_DIRNAME,
6316
6393
  sidecarsRoot,
@@ -6323,8 +6400,6 @@ export {
6323
6400
  ALLOW_UNOWNED_ENV,
6324
6401
  findProjectConfigDir,
6325
6402
  guidePath,
6326
- isFeatureDisabled,
6327
- isTestSandbox,
6328
6403
  launchOf,
6329
6404
  canonicalJson,
6330
6405
  describeValueShape,