@dudko.dev/agent-web 0.0.41 → 0.0.43

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.
package/dist/mcp.cjs CHANGED
@@ -1231,7 +1231,7 @@ var mcpSkillFilePath = (skillUri, fileUri) => {
1231
1231
  }
1232
1232
  return path;
1233
1233
  };
1234
- var mcpSkillEntryRefusal = (entry) => {
1234
+ var mcpSkillEntryRefusal = (entry, options = {}) => {
1235
1235
  if (!isRecord(entry) || typeof entry.uri !== "string") return "not a skill entry (no uri)";
1236
1236
  const path = mcpSkillPath(entry.uri);
1237
1237
  if (!path) return `${entry.uri} is not the SKILL.md of a named skill directory`;
@@ -1248,6 +1248,7 @@ var mcpSkillEntryRefusal = (entry) => {
1248
1248
  if (!oneLine(frontmatter.description)) return "the frontmatter has no description";
1249
1249
  const resources = entry.resources;
1250
1250
  if (resources === "dynamic") {
1251
+ if (options.dynamic === true) return void 0;
1251
1252
  return 'its content is generated ("resources": "dynamic"): there are no digests to verify it against';
1252
1253
  }
1253
1254
  if (!Array.isArray(resources)) return 'the entry does not list its files ("resources")';
@@ -1293,7 +1294,8 @@ var mcpSkillRecordOf = (entry) => {
1293
1294
  name: entry.frontmatter.name,
1294
1295
  description: oneLine(entry.frontmatter.description),
1295
1296
  path: mcpSkillPath(entry.uri) ?? [entry.frontmatter.name],
1296
- files
1297
+ files,
1298
+ ...entry.resources === "dynamic" ? { dynamic: true } : {}
1297
1299
  };
1298
1300
  };
1299
1301
  var shownUri = (uri) => oneLine(uri).replace(/[[\]]/g, "").slice(0, 200);
@@ -1312,6 +1314,90 @@ var resolveMcpSkillFile = (files, requested) => {
1312
1314
  }
1313
1315
  return { path };
1314
1316
  };
1317
+ var MCP_SKILL_DIRECTORY_ENTRIES_MAX = MCP_SKILL_MAX_RESOURCES + 128;
1318
+ var MCP_SKILL_DIRECTORY_MIME_TYPE = "inode/directory";
1319
+ var skillDirectoryRef = (requested) => {
1320
+ if (typeof requested !== "string") return { refused: "no directory path given" };
1321
+ const raw = requested.trim();
1322
+ if (raw === "" || raw === "." || raw === "./" || raw === "/") return { dir: "" };
1323
+ const refused = { refused: `"${oneLine(requested)}" is not a directory inside the skill` };
1324
+ if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("/") || /[?#\\]/.test(raw)) {
1325
+ return refused;
1326
+ }
1327
+ const dir = raw.replace(/^\.\/+/, "").replace(/\/+$/, "");
1328
+ if (!dir) return { dir: "" };
1329
+ if (dir.split("/").some((s) => !s || s === "." || s === "..")) return refused;
1330
+ return { dir };
1331
+ };
1332
+ var isPlainPath = (path) => path.split("/").every((s) => s !== "" && s !== "." && s !== "..");
1333
+ var skillDirectoryChildren = (paths, dir) => {
1334
+ const prefix = dir ? `${dir}/` : "";
1335
+ const files = /* @__PURE__ */ new Set();
1336
+ const directories = /* @__PURE__ */ new Set();
1337
+ for (const path of paths) {
1338
+ if (typeof path !== "string" || !isPlainPath(path) || !path.startsWith(prefix)) continue;
1339
+ const rest = path.slice(prefix.length);
1340
+ const cut = rest.indexOf("/");
1341
+ if (cut < 0) files.add(path);
1342
+ else directories.add(`${prefix}${rest.slice(0, cut)}`);
1343
+ }
1344
+ if (dir && !files.size && !directories.size) return void 0;
1345
+ return { files: [...files].sort(), directories: [...directories].sort() };
1346
+ };
1347
+ var canonicalUriOf = (uri) => {
1348
+ try {
1349
+ const url = new URL(uri);
1350
+ url.hash = "";
1351
+ return url.href;
1352
+ } catch {
1353
+ return void 0;
1354
+ }
1355
+ };
1356
+ var decodedSegment = (segment) => segment.replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
1357
+ let out = "";
1358
+ for (let at = 0; at < run.length; ) {
1359
+ const lead = Number.parseInt(run.slice(at + 1, at + 3), 16);
1360
+ const width = 3 * (lead >= 240 ? 4 : lead >= 224 ? 3 : lead >= 192 ? 2 : 1);
1361
+ try {
1362
+ out += decodeURIComponent(run.slice(at, at + width));
1363
+ at += width;
1364
+ } catch {
1365
+ out += run.slice(at, at + 3);
1366
+ at += 3;
1367
+ }
1368
+ }
1369
+ return out;
1370
+ });
1371
+ var isPlainName = (name) => name !== "" && name !== "." && name !== ".." && !name.includes("/") && !name.includes("\0");
1372
+ var compareMcpSkillDirectory = (o) => {
1373
+ const own = skillDirectoryChildren(o.manifest, o.dir) ?? { files: [], directories: [] };
1374
+ const root = canonicalUriOf(o.root);
1375
+ if (!root) return { extra: 0, notServed: [], truncated: false };
1376
+ const at = o.dir ? o.dir.split("/").map(decodedSegment) : [];
1377
+ const nameOf = (path) => decodedSegment(path.slice(path.lastIndexOf("/") + 1));
1378
+ const ownFiles = new Map(own.files.map((p) => [nameOf(p), p]));
1379
+ const ownDirectories = new Map(own.directories.map((p) => [nameOf(p), p]));
1380
+ const truncated = o.live.length > MCP_SKILL_DIRECTORY_ENTRIES_MAX;
1381
+ const seen = /* @__PURE__ */ new Set();
1382
+ const extra = /* @__PURE__ */ new Set();
1383
+ for (const item of o.live.slice(0, MCP_SKILL_DIRECTORY_ENTRIES_MAX)) {
1384
+ if (!isRecord(item) || typeof item.uri !== "string") continue;
1385
+ const uri = canonicalUriOf(item.uri);
1386
+ if (!uri || uri.includes("?") || !uri.startsWith(`${root}/`)) continue;
1387
+ const segments = uri.slice(root.length + 1).split("/").map(decodedSegment);
1388
+ if (segments.length !== at.length + 1 || !segments.every(isPlainName)) continue;
1389
+ if (at.some((s, i) => segments[i] !== s)) continue;
1390
+ const name = segments[segments.length - 1];
1391
+ const kind = typeof item.mimeType !== "string" ? "any" : item.mimeType === MCP_SKILL_DIRECTORY_MIME_TYPE ? "directory" : "file";
1392
+ const file = kind !== "directory" ? ownFiles.get(name) : void 0;
1393
+ const directory = kind !== "file" ? ownDirectories.get(name) : void 0;
1394
+ if (file !== void 0) seen.add(file);
1395
+ if (directory !== void 0) seen.add(directory);
1396
+ if (file === void 0 && directory === void 0) extra.add(`${kind} ${name}`);
1397
+ }
1398
+ const notServed = truncated ? [] : [...own.directories, ...own.files].filter((p) => !seen.has(p)).sort();
1399
+ return { extra: extra.size, notServed, truncated };
1400
+ };
1315
1401
  var MCP_SKILL_URI_MAX_CHARS = 512;
1316
1402
  var mcpSkillUriRefusal = (uri) => {
1317
1403
  if (typeof uri !== "string" || !uri) return "no skill URI given";
@@ -1346,12 +1432,94 @@ var mcpSkillsSettingOf = (setting, server) => {
1346
1432
  if (setting === true) return { on: true };
1347
1433
  if (isRecord(setting)) {
1348
1434
  const consent = mcpSkillConsentOf(setting.consent, `${server}: skills.consent`);
1349
- return consent ? { on: true, consent } : { on: true };
1435
+ const dynamic = setting.dynamic;
1436
+ if (dynamic !== void 0 && typeof dynamic !== "boolean") {
1437
+ throw new Error(
1438
+ `${server}: skills.dynamic must be true or false, got ${JSON.stringify(dynamic)}`
1439
+ );
1440
+ }
1441
+ return {
1442
+ on: true,
1443
+ ...consent ? { consent } : {},
1444
+ ...dynamic === true ? { dynamic: true } : {}
1445
+ };
1350
1446
  }
1351
1447
  throw new Error(
1352
- `${server}: skills must be true, false or { consent?: ${consentList} }, got ${JSON.stringify(setting)}`
1448
+ `${server}: skills must be true, false or { consent?: ${consentList}, dynamic?: boolean }, got ${JSON.stringify(setting)}`
1353
1449
  );
1354
1450
  };
1451
+ var MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES = 64;
1452
+ var MCP_SKILL_SNAPSHOT_MAX_DEPTH = 8;
1453
+ var MCP_SKILL_SNAPSHOTS_MAX_BYTES = 64 * 1024 * 1024;
1454
+ var createMcpSkillSnapshotMemory = () => ({ used: 0 });
1455
+ var mcpSkillSnapshotBytesRefusal = (bytes, held = 0) => {
1456
+ if (bytes > MCP_SKILL_MAX_TOTAL_BYTES) {
1457
+ return `its files take more than ${MCP_SKILL_MAX_TOTAL_BYTES} bytes (the limit for one skill)`;
1458
+ }
1459
+ if (held + bytes > MCP_SKILL_SNAPSHOTS_MAX_BYTES) {
1460
+ return `the copies of generated skills this agent holds would pass ${MCP_SKILL_SNAPSHOTS_MAX_BYTES} bytes (${held} held, ${bytes} read of this one)`;
1461
+ }
1462
+ return void 0;
1463
+ };
1464
+ var startMcpSkillWalk = (skillUri) => {
1465
+ const root = canonicalUriOf(skillUri.slice(0, -"/SKILL.md".length));
1466
+ if (!root || root.includes("?")) return void 0;
1467
+ return {
1468
+ root,
1469
+ pending: [{ path: "", depth: 0 }],
1470
+ directories: /* @__PURE__ */ new Set([""]),
1471
+ files: [],
1472
+ seen: /* @__PURE__ */ new Set(["SKILL.md"])
1473
+ };
1474
+ };
1475
+ var nextMcpSkillWalkDirectory = (walk) => {
1476
+ const next = walk.pending.shift();
1477
+ if (!next) return void 0;
1478
+ return { ...next, uri: next.path ? `${walk.root}/${next.path}` : walk.root };
1479
+ };
1480
+ var takeMcpSkillWalkListing = (walk, at, live) => {
1481
+ const parent = at.path ? at.path.split("/").map(decodedSegment) : [];
1482
+ for (const item of live) {
1483
+ if (!isRecord(item) || typeof item.uri !== "string") continue;
1484
+ const uri = canonicalUriOf(item.uri);
1485
+ if (!uri || uri.includes("?") || !uri.startsWith(`${walk.root}/`)) continue;
1486
+ const path = uri.slice(walk.root.length + 1);
1487
+ if (path.includes("\\")) continue;
1488
+ const segments = path.split("/").map(decodedSegment);
1489
+ if (segments.length !== parent.length + 1 || !segments.every(isPlainName)) continue;
1490
+ if (parent.some((s, i) => segments[i] !== s)) continue;
1491
+ const key = segments.join("/");
1492
+ if (walk.directories.has(key) || walk.seen.has(key)) continue;
1493
+ if (item.mimeType === MCP_SKILL_DIRECTORY_MIME_TYPE) {
1494
+ if (at.depth + 1 > MCP_SKILL_SNAPSHOT_MAX_DEPTH) {
1495
+ return `its directories go deeper than ${MCP_SKILL_SNAPSHOT_MAX_DEPTH} levels (${shownUri(uri)})`;
1496
+ }
1497
+ if (walk.directories.size + 1 > MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES) {
1498
+ return `it has more than ${MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES} directories to read`;
1499
+ }
1500
+ walk.directories.add(key);
1501
+ walk.pending.push({ path, depth: at.depth + 1 });
1502
+ continue;
1503
+ }
1504
+ if (walk.files.length + 2 > MCP_SKILL_MAX_RESOURCES) {
1505
+ return `it holds more than ${MCP_SKILL_MAX_RESOURCES} files (SKILL.md included; the limit)`;
1506
+ }
1507
+ walk.seen.add(key);
1508
+ walk.files.push(path);
1509
+ }
1510
+ return void 0;
1511
+ };
1512
+ var mcpSkillSnapshotEntry = (entry, files) => ({
1513
+ uri: entry.uri,
1514
+ frontmatter: entry.frontmatter,
1515
+ resources: files.map(({ uri, size, digest }) => ({ uri, size, digest }))
1516
+ });
1517
+ var mcpSkillSha256 = async (bytes) => {
1518
+ const subtle = globalThis.crypto?.subtle;
1519
+ if (!subtle) throw new Error("no WebCrypto (globalThis.crypto.subtle) to compute a digest with");
1520
+ const hash = new Uint8Array(await subtle.digest("SHA-256", bytes));
1521
+ return `sha256:${Array.from(hash, (b) => b.toString(16).padStart(2, "0")).join("")}`;
1522
+ };
1355
1523
  var MCP_SKILLS_MARK = /* @__PURE__ */ Symbol.for("@dudko.dev/agent:mcp-skills");
1356
1524
  var markMcpSkills = (tool, source) => {
1357
1525
  Object.defineProperty(tool, MCP_SKILLS_MARK, {
@@ -1380,12 +1548,164 @@ var mcpSkillGetFailure = (err) => {
1380
1548
  return typeof code === "number" ? `${messageOf2(err)} (${code})` : messageOf2(err);
1381
1549
  };
1382
1550
  var createMcpSkillCatalog = (server, client, log, options = {}) => {
1551
+ const admission = { dynamic: options.dynamic === true };
1552
+ const digest = options.digest ?? mcpSkillSha256;
1383
1553
  let records = [];
1384
1554
  let entries = /* @__PURE__ */ new Map();
1385
1555
  const added = /* @__PURE__ */ new Map();
1386
1556
  const entryOf = (uri) => entries.get(uri) ?? added.get(uri)?.entry;
1387
1557
  const held = /* @__PURE__ */ new WeakMap();
1388
1558
  const files = /* @__PURE__ */ new WeakMap();
1559
+ const changed = /* @__PURE__ */ new WeakSet();
1560
+ const copies = /* @__PURE__ */ new WeakMap();
1561
+ const snapshotOf = async (entry, opts = {}) => {
1562
+ const memory = opts.memory ?? createMcpSkillSnapshotMemory();
1563
+ const signal = opts.signal;
1564
+ const readOpts = signal ? { signal } : void 0;
1565
+ const declined = (why) => {
1566
+ log(
1567
+ "warn",
1568
+ `[mcp] ${server}: the generated skill ${shownUri(entry.uri)} is declined - ${why}; no one is asked, nothing of it is used`
1569
+ );
1570
+ return new Error(
1571
+ `the skill ${shownUri(entry.uri)} of the MCP server "${server}" was not loaded: ${why}`
1572
+ );
1573
+ };
1574
+ const bytesOf = (file) => file.bytes instanceof Uint8Array ? file.bytes : new TextEncoder().encode(typeof file.text === "string" ? file.text : "");
1575
+ let main;
1576
+ try {
1577
+ main = await client.read(entry, void 0, readOpts);
1578
+ } catch (err) {
1579
+ throw new Error(
1580
+ `the skill ${shownUri(entry.uri)} of the MCP server "${server}" was not loaded: ${mcpSkillReadFailure(err)}`
1581
+ );
1582
+ }
1583
+ const parts = [
1584
+ { uri: entry.uri, path: "SKILL.md", bytes: bytesOf(main) }
1585
+ ];
1586
+ let total = parts[0].bytes.byteLength;
1587
+ let refused = mcpSkillSnapshotBytesRefusal(total, memory.used);
1588
+ if (refused) throw declined(refused);
1589
+ const listed = client.directoryRead === true && typeof client.readDirectory === "function";
1590
+ if (listed) {
1591
+ const walk = startMcpSkillWalk(entry.uri);
1592
+ if (!walk) throw declined("its URI names no directory to read");
1593
+ for (let at = nextMcpSkillWalkDirectory(walk); at; at = nextMcpSkillWalkDirectory(walk)) {
1594
+ let live;
1595
+ try {
1596
+ live = (await client.readDirectory(
1597
+ at.uri,
1598
+ readOpts
1599
+ ))?.resources;
1600
+ } catch (err) {
1601
+ if (signal?.aborted) throw err;
1602
+ const code = err?.code;
1603
+ throw declined(
1604
+ `resources/directory/read of ${shownUri(at.uri)} failed - ${messageOf2(err)}${typeof code === "number" ? ` (${code})` : ""}`
1605
+ );
1606
+ }
1607
+ if (!Array.isArray(live)) {
1608
+ throw declined(
1609
+ `resources/directory/read of ${shownUri(at.uri)} gave no list of resources`
1610
+ );
1611
+ }
1612
+ refused = takeMcpSkillWalkListing(walk, at, live);
1613
+ if (refused) throw declined(refused);
1614
+ }
1615
+ const root = entry.uri.slice(0, -"SKILL.md".length);
1616
+ for (const path of walk.files) {
1617
+ const uri = `${root}${path}`;
1618
+ let file;
1619
+ try {
1620
+ file = await client.read(entry, uri, readOpts);
1621
+ } catch (err) {
1622
+ if (signal?.aborted) throw err;
1623
+ throw declined(`its file "${oneLine(path)}" was not read: ${mcpSkillReadFailure(err)}`);
1624
+ }
1625
+ const bytes = bytesOf(file);
1626
+ total += bytes.byteLength;
1627
+ refused = mcpSkillSnapshotBytesRefusal(total, memory.used);
1628
+ if (refused) throw declined(refused);
1629
+ parts.push({
1630
+ uri,
1631
+ path,
1632
+ bytes,
1633
+ ...typeof file.text === "string" ? { text: file.text } : {}
1634
+ });
1635
+ }
1636
+ }
1637
+ const resources = [];
1638
+ for (const part of parts) {
1639
+ resources.push({
1640
+ uri: part.uri,
1641
+ size: part.bytes.byteLength,
1642
+ digest: await digest(part.bytes)
1643
+ });
1644
+ }
1645
+ const manifest = mcpSkillSnapshotEntry(entry, resources);
1646
+ refused = mcpSkillSnapshotBytesRefusal(total, memory.used);
1647
+ if (refused) throw declined(refused);
1648
+ memory.used += total;
1649
+ copies.set(manifest, new Map(parts.slice(1).map((p) => [p.path, p.text])));
1650
+ const loaded = {
1651
+ uri: entry.uri,
1652
+ body: typeof main.body === "string" ? main.body : "",
1653
+ files: mcpSkillRecordOf(manifest).files,
1654
+ entry: manifest,
1655
+ snapshot: { bytes: total, listed }
1656
+ };
1657
+ held.set(loaded, manifest);
1658
+ log(
1659
+ "info",
1660
+ `[mcp] ${server}: the generated skill ${shownUri(entry.uri)} read into a snapshot - ${parts.length} file(s), ${total} bytes${listed ? "" : " (the server cannot list its files: SKILL.md alone)"}; the agent's copies of generated skills now hold ${memory.used} bytes`
1661
+ );
1662
+ return loaded;
1663
+ };
1664
+ const readDirectory = async (loaded, dir, opts) => {
1665
+ const entry = held.get(loaded);
1666
+ if (!entry) {
1667
+ throw new Error(`the skill ${loaded.uri} was not loaded from the MCP server "${server}"`);
1668
+ }
1669
+ const ownFiles = mcpSkillRecordOf(entry).files;
1670
+ const ref = skillDirectoryRef(dir);
1671
+ if ("refused" in ref || ref.dir !== dir || !skillDirectoryChildren(ownFiles, dir)) {
1672
+ throw new Error(`the skill ${shownUri(entry.uri)} has no directory "${oneLine(dir)}"`);
1673
+ }
1674
+ const root = entry.uri.slice(0, -"/SKILL.md".length);
1675
+ const uri = dir ? `${root}/${dir}` : root;
1676
+ let live;
1677
+ try {
1678
+ live = (await client.readDirectory(uri, opts))?.resources;
1679
+ } catch (err) {
1680
+ if (opts?.signal?.aborted) throw err;
1681
+ const code = err?.code;
1682
+ log(
1683
+ "warn",
1684
+ `[mcp] ${server}: resources/directory/read of ${shownUri(uri)} failed - ${messageOf2(err)}${typeof code === "number" ? ` (${code})` : ""}; the directory is listed from the skill's entry alone`
1685
+ );
1686
+ return void 0;
1687
+ }
1688
+ if (!Array.isArray(live)) {
1689
+ log(
1690
+ "warn",
1691
+ `[mcp] ${server}: resources/directory/read of ${shownUri(uri)} gave no list of resources; the directory is listed from the skill's entry alone`
1692
+ );
1693
+ return void 0;
1694
+ }
1695
+ const manifest = ["SKILL.md", ...ownFiles];
1696
+ const drift = compareMcpSkillDirectory({ manifest, dir, root, live });
1697
+ if (drift.extra > 0 || drift.notServed.length > 0) {
1698
+ log(
1699
+ "warn",
1700
+ `[mcp] ${server}: the skill "${oneLine(entry.frontmatter.name)}" (${shownUri(entry.uri)}) changed on the server - its directory "${oneLine(dir) || "."}" lists ${drift.truncated ? "at least " : ""}${drift.extra} item(s) its entry does not and not ${drift.notServed.length} it does; only the files of the entry it was loaded with are read until the server's skills are listed again`
1701
+ );
1702
+ if (!changed.has(entry)) {
1703
+ changed.add(entry);
1704
+ options.onChanged?.();
1705
+ }
1706
+ }
1707
+ return drift;
1708
+ };
1389
1709
  const refresh = async () => {
1390
1710
  let listing;
1391
1711
  try {
@@ -1408,7 +1728,7 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
1408
1728
  const nextEntries = /* @__PURE__ */ new Map();
1409
1729
  const nextRecords = [];
1410
1730
  for (const entry of listing.skills) {
1411
- const refused = mcpSkillEntryRefusal(entry);
1731
+ const refused = mcpSkillEntryRefusal(entry, admission);
1412
1732
  const uri = isRecord(entry) && typeof entry.uri === "string" ? entry.uri : "(no uri)";
1413
1733
  if (refused) {
1414
1734
  log("warn", `[mcp] ${server}: skill ${oneLine(uri).slice(0, 200)} refused - ${refused}`);
@@ -1452,7 +1772,7 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
1452
1772
  );
1453
1773
  }
1454
1774
  const entry = answer?.skill;
1455
- const why = mcpSkillEntryRefusal(entry);
1775
+ const why = mcpSkillEntryRefusal(entry, admission);
1456
1776
  if (why) {
1457
1777
  log("warn", `[mcp] ${server}: skill ${shownUri(uri)} (by URI) refused - ${why}`);
1458
1778
  throw new Error(
@@ -1473,9 +1793,14 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
1473
1793
  if (!entry) {
1474
1794
  throw new Error(`the MCP server "${server}" no longer lists the skill ${uri}`);
1475
1795
  }
1796
+ if (entry.resources === "dynamic") return snapshotOf(entry, options2);
1476
1797
  let file;
1477
1798
  try {
1478
- file = await client.read(entry, void 0, options2);
1799
+ file = await client.read(
1800
+ entry,
1801
+ void 0,
1802
+ options2?.signal ? { signal: options2.signal } : void 0
1803
+ );
1479
1804
  } catch (err) {
1480
1805
  throw new Error(
1481
1806
  `the skill ${uri} of the MCP server "${server}" was not loaded: ${mcpSkillReadFailure(err)}`
@@ -1496,6 +1821,16 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
1496
1821
  throw new Error(`the skill ${loaded.uri} was not loaded from the MCP server "${server}"`);
1497
1822
  const target = resolveMcpSkillFile(loaded.files, path);
1498
1823
  if ("refused" in target) throw new Error(target.refused);
1824
+ const copy = copies.get(entry);
1825
+ if (copy) {
1826
+ const text = copy.get(target.path);
1827
+ if (typeof text !== "string") {
1828
+ throw new Error(
1829
+ `the file "${target.path}" of the skill ${loaded.uri} is not text; it is not shown`
1830
+ );
1831
+ }
1832
+ return text;
1833
+ }
1499
1834
  let read = files.get(entry);
1500
1835
  const kept = read?.get(target.path);
1501
1836
  if (kept !== void 0) return kept;
@@ -1518,7 +1853,10 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
1518
1853
  }
1519
1854
  read.set(target.path, file.text);
1520
1855
  return file.text;
1521
- }
1856
+ },
1857
+ // Never called on a server that did not declare it (Capability Negotiation: a client "MUST
1858
+ // NOT call resources/directory/read" there).
1859
+ ...client.directoryRead === true && typeof client.readDirectory === "function" ? { readDirectory } : {}
1522
1860
  };
1523
1861
  return { source, refresh };
1524
1862
  };
@@ -2599,11 +2937,16 @@ var connectAndList = async (name, cfg, opts, log, probe, onClient, onListener, e
2599
2937
  log("info", `[mcp] ${name}: the server does not offer skills (${MCP_SKILLS_EXTENSION})`);
2600
2938
  } else {
2601
2939
  const { SkillsClient } = await import("@modelcontextprotocol/client/ext/skills");
2940
+ const notify = opts.onToolsChanged;
2602
2941
  skills = createMcpSkillCatalog(
2603
2942
  name,
2604
2943
  new SkillsClient(client, { skipInvalid: true }),
2605
2944
  (level, message) => log(level, message),
2606
- skillsSetting.consent ? { consent: skillsSetting.consent } : {}
2945
+ {
2946
+ ...skillsSetting.consent ? { consent: skillsSetting.consent } : {},
2947
+ ...skillsSetting.dynamic ? { dynamic: true } : {},
2948
+ ...notify ? { onChanged: () => notify(name) } : {}
2949
+ }
2607
2950
  );
2608
2951
  await skills.refresh();
2609
2952
  }