@abraca/mcp 2.38.0 → 2.39.0

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.
@@ -10,7 +10,7 @@ import * as os from "node:os";
10
10
  import * as path from "node:path";
11
11
  import { AbracadabraClient, AbracadabraProvider, PAGE_TYPES, SERVER_ROOT_ID, TYPE_ALIASES, WebSocketStatus, awarenessStatesToArray, foldRecords, isEncryptedContent, loadOrCreateKeyFile, loginOrRegisterWithKey, makeChallengeSigner, makeEntryMap, normalizeRootId, openSyncedProvider, patchEntry, pickEntrySpace, readEntries, readEntries as readEntries$1, reconcileDocCover, recordFromYAny, resolvePageType, toPlain, waitForSync } from "@abraca/dabra";
12
12
  import * as Y from "yjs";
13
- import { parseFrontmatter, populateYDocFromMarkdown, yjsToMarkdown } from "@abraca/convert";
13
+ import { appendJsonNodes, markdownToFragmentNodes, parseFrontmatter, populateYDocFromMarkdown, yjsToMarkdown } from "@abraca/convert";
14
14
 
15
15
  //#region \0rolldown/runtime.js
16
16
  var __create = Object.create;
@@ -21394,6 +21394,79 @@ function registerChannelTools(mcp, server) {
21394
21394
 
21395
21395
  //#endregion
21396
21396
  //#region packages/mcp/src/tools/content.ts
21397
+ /**
21398
+ * Content tools — read/write document content via markdown ↔ Y.js conversion.
21399
+ */
21400
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21401
+ /** Clamp per-block streaming delay to a sane window. */
21402
+ const STREAM_MS_DEFAULT = 90;
21403
+ const STREAM_MS_MAX = 2e3;
21404
+ /**
21405
+ * Collect every body Y.XmlText in a fragment, skipping the `documentHeader`
21406
+ * and `documentMeta` elements — the title/meta are synced to the tree entry
21407
+ * elsewhere, so a surgical body edit must never touch them (it would desync
21408
+ * the header from the tree `label`).
21409
+ */
21410
+ function collectBodyXmlText(frag, out) {
21411
+ for (const child of frag.toArray()) if (child instanceof Y.XmlText) out.push(child);
21412
+ else if (child instanceof Y.XmlElement) {
21413
+ const tag = child.nodeName;
21414
+ if (tag === "documentHeader" || tag === "documentMeta") continue;
21415
+ collectXmlTextDeep(child, out);
21416
+ }
21417
+ }
21418
+ function collectXmlTextDeep(node, out) {
21419
+ for (const child of node.toArray()) if (child instanceof Y.XmlText) out.push(child);
21420
+ else if (child instanceof Y.XmlElement) collectXmlTextDeep(child, out);
21421
+ }
21422
+ /**
21423
+ * Plain text of a Y.XmlText aligned with its Y character indices. Critically
21424
+ * NOT `text.toString()` — that serialises marks as XML tags
21425
+ * (`hello <bold>WORLD</bold>`), which throws off `indexOf` offsets. Each
21426
+ * non-string embed (inline atom) counts as one character, matching how Yjs
21427
+ * indexes them, so `delete`/`insert` offsets stay correct.
21428
+ */
21429
+ function plainTextForIndex(text) {
21430
+ const delta = text.toDelta();
21431
+ let s = "";
21432
+ for (const op of delta) s += typeof op.insert === "string" ? op.insert : "";
21433
+ return s;
21434
+ }
21435
+ /** Marks/attributes active at a character offset inside a Y.XmlText, so a
21436
+ * replacement can re-use the surrounding formatting (bold, link, etc.). */
21437
+ function attrsAtOffset(text, offset) {
21438
+ const delta = text.toDelta();
21439
+ let pos = 0;
21440
+ for (const op of delta) {
21441
+ const len = typeof op.insert === "string" ? op.insert.length : 1;
21442
+ if (offset < pos + len) return op.attributes;
21443
+ pos += len;
21444
+ }
21445
+ }
21446
+ /**
21447
+ * Replace `find` with `replace` inside a single Y.XmlText, preserving the
21448
+ * formatting at each match's start. Splices right-to-left so earlier offsets
21449
+ * stay valid. Returns the number of replacements made. Caller wraps the whole
21450
+ * pass in one transaction.
21451
+ */
21452
+ function surgicalReplaceInText(text, find, replace, all) {
21453
+ const s = plainTextForIndex(text);
21454
+ const offsets = [];
21455
+ let idx = s.indexOf(find);
21456
+ while (idx !== -1) {
21457
+ offsets.push(idx);
21458
+ if (!all) break;
21459
+ idx = s.indexOf(find, idx + find.length);
21460
+ }
21461
+ for (let i = offsets.length - 1; i >= 0; i--) {
21462
+ const at = offsets[i];
21463
+ const attrs = attrsAtOffset(text, at);
21464
+ text.delete(at, find.length);
21465
+ if (replace.length > 0) if (attrs && Object.keys(attrs).length > 0) text.insert(at, replace, attrs);
21466
+ else text.insert(at, replace);
21467
+ }
21468
+ return offsets.length;
21469
+ }
21397
21470
  function registerContentTools(mcp, server) {
21398
21471
  mcp.tool("read_document", "Read a document's content as markdown, along with its immediate children. IMPORTANT: A document's full content is its body text PLUS all its children. An empty body does not mean empty content — the children ARE the content (sub-docs, kanban columns, table columns, calendar events, etc.). Always check the returned \"children\" array and read child documents too.", { docId: z.string().describe("Document ID to read.") }, async ({ docId }) => {
21399
21472
  try {
@@ -21458,8 +21531,10 @@ function registerContentTools(mcp, server) {
21458
21531
  mcp.tool("write_document", "Write markdown content to a document. Parses the markdown and writes it to the Y.js CRDT document, which syncs in real-time to all connected clients. Supports optional YAML frontmatter for title and metadata. Use ![[docId]] to embed another document as a block, or [[docId|label]] for inline doc links.", {
21459
21532
  docId: z.string().describe("Document ID to write to."),
21460
21533
  markdown: z.string().describe("Markdown content to write. Can include YAML frontmatter with title and metadata fields."),
21461
- mode: z.enum(["replace", "append"]).optional().describe("Write mode. \"replace\" clears existing content first (default). \"append\" adds to the end.")
21462
- }, async ({ docId, markdown, mode }) => {
21534
+ mode: z.enum(["replace", "append"]).optional().describe("Write mode. \"replace\" clears existing content first (default). \"append\" adds to the end."),
21535
+ stream: z.boolean().optional().describe("When true, insert the content block-by-block (typewriter effect) so collaborators watching the document see it appear progressively, with the agent cursor advancing. The final document is identical to a non-streamed write. Default false."),
21536
+ streamMs: z.number().optional().describe("Delay in milliseconds between streamed blocks (only used when stream=true). Default 90, clamped to [0, 2000].")
21537
+ }, async ({ docId, markdown, mode, stream, streamMs }) => {
21463
21538
  try {
21464
21539
  server.setAutoStatus("writing", docId);
21465
21540
  server.setActiveToolCall({
@@ -21495,14 +21570,28 @@ function registerContentTools(mcp, server) {
21495
21570
  });
21496
21571
  const contentToWrite = body || markdown;
21497
21572
  const existingLabel = server.getDocSummary(docId)?.label;
21498
- populateYDocFromMarkdown(fragment, contentToWrite, title || existingLabel || "Untitled");
21573
+ const fallbackTitle = title || existingLabel || "Untitled";
21574
+ if (stream) {
21575
+ const { header, meta: metaNode, body: bodyNodes } = markdownToFragmentNodes(contentToWrite, fallbackTitle);
21576
+ if (writeMode !== "append") {
21577
+ const lead = [header, metaNode].filter((n) => !!n);
21578
+ if (lead.length) appendJsonNodes(fragment, lead);
21579
+ }
21580
+ const delay = Math.max(0, Math.min(streamMs ?? STREAM_MS_DEFAULT, STREAM_MS_MAX));
21581
+ for (const node of bodyNodes) {
21582
+ appendJsonNodes(fragment, [node]);
21583
+ server.setFocusedDoc(docId);
21584
+ server.setDocCursor(docId, fragment.length);
21585
+ if (delay > 0) await sleep(delay);
21586
+ }
21587
+ } else populateYDocFromMarkdown(fragment, contentToWrite, fallbackTitle);
21499
21588
  const coverTree = server.getTreeMap();
21500
21589
  if (coverTree) reconcileDocCover(coverTree, docId, fragment);
21501
21590
  server.setFocusedDoc(docId);
21502
21591
  server.setDocCursor(docId, fragment.length);
21503
21592
  return { content: [{
21504
21593
  type: "text",
21505
- text: `Document ${docId} updated (${writeMode} mode)`
21594
+ text: `Document ${docId} updated (${writeMode} mode${stream ? ", streamed" : ""})`
21506
21595
  }] };
21507
21596
  } catch (error) {
21508
21597
  return {
@@ -21514,6 +21603,204 @@ function registerContentTools(mcp, server) {
21514
21603
  };
21515
21604
  }
21516
21605
  });
21606
+ mcp.tool("patch_document", "Make a targeted edit to a document by find-and-replace on its markdown, WITHOUT resending the whole document. Reads the current content as markdown, replaces an exact substring, and writes it back. Use this for small/surgical edits (fix a typo, update one line, insert a paragraph next to an anchor) instead of read_document + write_document. The `find` string must match the current markdown exactly (whitespace included); the tool errors if it is not found so you never silently no-op.", {
21607
+ docId: z.string().describe("Document ID to patch."),
21608
+ find: z.string().describe("Exact substring of the current markdown to replace. Must be present verbatim. Returns an error listing nothing-matched if not found."),
21609
+ replace: z.string().describe("Replacement text. Use an empty string to delete the matched text."),
21610
+ all: z.boolean().optional().describe("Replace every occurrence (true) or only the first (false, default).")
21611
+ }, async ({ docId, find, replace, all }) => {
21612
+ try {
21613
+ server.setAutoStatus("writing", docId);
21614
+ server.setActiveToolCall({
21615
+ name: "patch_document",
21616
+ target: docId
21617
+ });
21618
+ if (find.length === 0) return {
21619
+ content: [{
21620
+ type: "text",
21621
+ text: "Error patching document: `find` must be a non-empty string."
21622
+ }],
21623
+ isError: true
21624
+ };
21625
+ await server.ensureSpaceActive(docId);
21626
+ const doc = (await server.getChildProvider(docId)).document;
21627
+ const fragment = doc.getXmlFragment("default");
21628
+ const textNodes = [];
21629
+ collectBodyXmlText(fragment, textNodes);
21630
+ let surgicalCount = 0;
21631
+ doc.transact(() => {
21632
+ for (const tn of textNodes) {
21633
+ surgicalCount += surgicalReplaceInText(tn, find, replace, !!all);
21634
+ if (!all && surgicalCount > 0) break;
21635
+ }
21636
+ });
21637
+ if (surgicalCount > 0) {
21638
+ server.setFocusedDoc(docId);
21639
+ return { content: [{
21640
+ type: "text",
21641
+ text: `Patched ${docId}: ${surgicalCount} replacement${surgicalCount === 1 ? "" : "s"} (surgical).`
21642
+ }] };
21643
+ }
21644
+ const treeMap = server.getTreeMap();
21645
+ let label = "Untitled";
21646
+ let type;
21647
+ let meta;
21648
+ if (treeMap) {
21649
+ const entry = toPlain(treeMap.get(docId));
21650
+ if (entry && typeof entry === "object") {
21651
+ label = entry.label || label;
21652
+ type = entry.type;
21653
+ meta = entry.meta;
21654
+ }
21655
+ }
21656
+ const current = yjsToMarkdown(fragment, label, meta, type);
21657
+ if (!current.includes(find)) return {
21658
+ content: [{
21659
+ type: "text",
21660
+ text: `Error patching document: \`find\` text not present in ${docId}. Read the document first to see its exact current markdown.`
21661
+ }],
21662
+ isError: true
21663
+ };
21664
+ let count = 0;
21665
+ let next;
21666
+ if (all) {
21667
+ next = current.split(find).join(replace);
21668
+ count = current.split(find).length - 1;
21669
+ } else {
21670
+ next = current.replace(find, replace);
21671
+ count = 1;
21672
+ }
21673
+ const { title, meta: fmMeta, body } = parseFrontmatter(next);
21674
+ if (title || Object.keys(fmMeta).length > 0) {
21675
+ const rootDoc = server.rootDocument;
21676
+ if (treeMap && rootDoc) {
21677
+ const rawEntry = treeMap.get(docId);
21678
+ if (rawEntry) {
21679
+ const cur = toPlain(rawEntry);
21680
+ rootDoc.transact(() => {
21681
+ const patch = { updatedAt: Date.now() };
21682
+ if (title) patch.label = title;
21683
+ if (Object.keys(fmMeta).length > 0) patch.meta = {
21684
+ ...cur.meta ?? {},
21685
+ ...fmMeta
21686
+ };
21687
+ patchEntry(treeMap, docId, patch);
21688
+ });
21689
+ }
21690
+ }
21691
+ }
21692
+ doc.transact(() => {
21693
+ while (fragment.length > 0) fragment.delete(0);
21694
+ });
21695
+ populateYDocFromMarkdown(fragment, body || next, title || label || "Untitled");
21696
+ const coverTree = server.getTreeMap();
21697
+ if (coverTree) reconcileDocCover(coverTree, docId, fragment);
21698
+ server.setFocusedDoc(docId);
21699
+ server.setDocCursor(docId, fragment.length);
21700
+ return { content: [{
21701
+ type: "text",
21702
+ text: `Patched ${docId}: ${count} replacement${count === 1 ? "" : "s"} (re-rendered).`
21703
+ }] };
21704
+ } catch (error) {
21705
+ return {
21706
+ content: [{
21707
+ type: "text",
21708
+ text: `Error patching document: ${error.message}`
21709
+ }],
21710
+ isError: true
21711
+ };
21712
+ }
21713
+ });
21714
+ mcp.tool("read_subtree", "Read a document AND its descendants' markdown in ONE call, as a nested tree. Use this instead of repeated read_document + get_document_tree walks when you need the actual content of a board/outline/checklist and its children (e.g. \"summarize this kanban\"). Each node carries {id,label,type,meta,markdown,children[]}. Bounded by `depth` and `maxNodes` so it can't run away on huge trees — nodes past the cap are listed with their label/type but `markdown:null` and `truncated:true`.", {
21715
+ rootId: z.string().describe("Document ID to read from (its own content is included as the tree root)."),
21716
+ depth: z.number().optional().describe("How many levels of descendants to include. Default 2. Use 0 for just the root doc, -1 for unlimited (still capped by maxNodes)."),
21717
+ maxNodes: z.number().optional().describe("Maximum number of documents whose content is loaded. Default 40, hard cap 200. Protects against loading hundreds of child providers.")
21718
+ }, async ({ rootId, depth, maxNodes }) => {
21719
+ try {
21720
+ server.setAutoStatus("reading", rootId);
21721
+ server.setActiveToolCall({
21722
+ name: "read_subtree",
21723
+ target: rootId
21724
+ });
21725
+ await server.ensureSpaceActive(rootId);
21726
+ const treeMap = server.getTreeMap();
21727
+ if (!treeMap) return {
21728
+ content: [{
21729
+ type: "text",
21730
+ text: "Not connected"
21731
+ }],
21732
+ isError: true
21733
+ };
21734
+ const targetId = normalizeRootId(rootId, server.rootDocId);
21735
+ const maxDepth = depth ?? 2;
21736
+ const cap = Math.max(1, Math.min(maxNodes ?? 40, 200));
21737
+ const entries = readEntries(treeMap, server.rootDocId);
21738
+ const byParent = /* @__PURE__ */ new Map();
21739
+ for (const e of entries) {
21740
+ const list = byParent.get(e.parentId) ?? [];
21741
+ list.push(e);
21742
+ byParent.set(e.parentId, list);
21743
+ }
21744
+ const childrenOf = (id) => (byParent.get(id) ?? []).slice().sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
21745
+ let loaded = 0;
21746
+ const visited = /* @__PURE__ */ new Set();
21747
+ const readMarkdown = async (id, label, meta, type) => {
21748
+ if (loaded >= cap) return {
21749
+ markdown: null,
21750
+ truncated: true
21751
+ };
21752
+ loaded++;
21753
+ return { markdown: yjsToMarkdown((await server.getChildProvider(id)).document.getXmlFragment("default"), label, meta, type) };
21754
+ };
21755
+ const build = async (id, curDepth) => {
21756
+ if (maxDepth >= 0 && curDepth > maxDepth) return [];
21757
+ const out = [];
21758
+ for (const child of childrenOf(id)) {
21759
+ if (visited.has(child.id)) continue;
21760
+ visited.add(child.id);
21761
+ const { markdown, truncated } = await readMarkdown(child.id, child.label, child.meta, child.type);
21762
+ out.push({
21763
+ id: child.id,
21764
+ label: child.label,
21765
+ type: child.type,
21766
+ meta: child.meta,
21767
+ markdown,
21768
+ ...truncated ? { truncated: true } : {},
21769
+ children: await build(child.id, curDepth + 1)
21770
+ });
21771
+ }
21772
+ return out;
21773
+ };
21774
+ const rootEntry = toPlain(treeMap.get(targetId ?? ""));
21775
+ const rootLabel = rootEntry && rootEntry.label || "Untitled";
21776
+ const rootType = rootEntry?.type;
21777
+ const rootMeta = rootEntry?.meta;
21778
+ visited.add(targetId ?? rootId);
21779
+ const rootContent = targetId === null ? { markdown: null } : await readMarkdown(targetId, rootLabel, rootMeta, rootType);
21780
+ const result = {
21781
+ id: targetId ?? rootId,
21782
+ label: rootLabel,
21783
+ type: rootType,
21784
+ meta: rootMeta,
21785
+ markdown: rootContent.markdown,
21786
+ ...rootContent.truncated ? { truncated: true } : {},
21787
+ children: await build(targetId, 1),
21788
+ ...loaded >= cap ? { note: `Stopped loading content after ${cap} nodes (maxNodes). Increase maxNodes or narrow rootId to see more.` } : {}
21789
+ };
21790
+ return { content: [{
21791
+ type: "text",
21792
+ text: JSON.stringify(result, null, 2)
21793
+ }] };
21794
+ } catch (error) {
21795
+ return {
21796
+ content: [{
21797
+ type: "text",
21798
+ text: `Error reading subtree: ${error.message}`
21799
+ }],
21800
+ isError: true
21801
+ };
21802
+ }
21803
+ });
21517
21804
  }
21518
21805
 
21519
21806
  //#endregion
@@ -21947,6 +22234,46 @@ function descendantsOf(entries, id) {
21947
22234
  collect(id);
21948
22235
  return result;
21949
22236
  }
22237
+ /**
22238
+ * Evaluate one `where` predicate value against a doc's actual value. The
22239
+ * predicate is a small string DSL so agents can filter on meta without a
22240
+ * structured query language:
22241
+ * - `>=N` `<=N` `>N` `<N` → numeric comparison (value coerced to number)
22242
+ * - `contains:X` → array membership OR string substring
22243
+ * - `exists` / `!exists` → presence / absence (null counts as absent)
22244
+ * - `=X` or bare `X` → loose equality (string-coerced)
22245
+ */
22246
+ function matchPredicate(actual, pred) {
22247
+ const p = pred.trim();
22248
+ if (p === "exists") return actual !== void 0 && actual !== null;
22249
+ if (p === "!exists") return actual === void 0 || actual === null;
22250
+ const cmp = p.match(/^(>=|<=|>|<)\s*(-?\d+(?:\.\d+)?)$/);
22251
+ if (cmp) {
22252
+ const n = Number(actual);
22253
+ if (Number.isNaN(n)) return false;
22254
+ const rhs = Number(cmp[2]);
22255
+ switch (cmp[1]) {
22256
+ case ">=": return n >= rhs;
22257
+ case "<=": return n <= rhs;
22258
+ case ">": return n > rhs;
22259
+ case "<": return n < rhs;
22260
+ }
22261
+ }
22262
+ if (p.startsWith("contains:")) {
22263
+ const needle = p.slice(9);
22264
+ if (Array.isArray(actual)) return actual.map(String).includes(needle);
22265
+ if (typeof actual === "string") return actual.toLowerCase().includes(needle.toLowerCase());
22266
+ return false;
22267
+ }
22268
+ const want = p.startsWith("=") ? p.slice(1) : p;
22269
+ return String(actual) === want;
22270
+ }
22271
+ /** True when an entry satisfies EVERY predicate in `where`. The special key
22272
+ * `type` matches the entry's page type; every other key matches `entry.meta[key]`. */
22273
+ function matchesWhere(entry, where) {
22274
+ for (const [key, pred] of Object.entries(where)) if (!matchPredicate(key === "type" ? entry.type : entry.meta?.[key], pred)) return false;
22275
+ return true;
22276
+ }
21950
22277
  function buildTree(entries, rootId, maxDepth, currentDepth = 0, visited = /* @__PURE__ */ new Set()) {
21951
22278
  if (maxDepth >= 0 && currentDepth >= maxDepth) return [];
21952
22279
  return childrenOf(entries, rootId).filter((e) => !visited.has(e.id)).map((entry) => {
@@ -21999,15 +22326,24 @@ function registerTreeTools(mcp, server, validator = null) {
21999
22326
  text: JSON.stringify(tree, null, 2)
22000
22327
  }] };
22001
22328
  });
22002
- mcp.tool("find_document", "Search for documents by name across the entire tree. Returns matching documents with their full ancestor path. Use this when you're looking for a specific document and don't know where it is in the hierarchy.", {
22003
- query: z.string().describe("Search query — matched case-insensitively against document labels (substring match)."),
22329
+ mcp.tool("find_document", "Search for documents across the tree by name and/or metadata. Returns matching documents with their full ancestor path. Use this when looking for a document and you don't know where it is. At least one of `query` or `where` is required. `where` filters on metadata — e.g. find every high-priority card or every doc tagged \"bug\" without knowing labels.", {
22330
+ query: z.string().optional().describe("Case-insensitive substring match against document labels. Optional when `where` is given."),
22331
+ where: z.record(z.string(), z.string()).optional().describe("Metadata predicates, ALL of which must match. Key is a meta field (or the special key \"type\" for page type); value is a tiny predicate: \">=3\" / \"<=1\" (numeric, e.g. priority), \"contains:bug\" (array membership or string substring, e.g. tags), \"exists\" / \"!exists\", or a bare/\"=value\" for equality. Example: {\"priority\":\">=3\",\"type\":\"kanban\"}."),
22004
22332
  rootId: z.string().optional().describe("Restrict search to descendants of this document. Omit to search the entire tree.")
22005
- }, async ({ query, rootId }) => {
22333
+ }, async ({ query, where, rootId }) => {
22334
+ const label = query ?? (where ? Object.keys(where).join(",") : "find");
22006
22335
  server.setAutoStatus("searching");
22007
22336
  server.setActiveToolCall({
22008
22337
  name: "find_document",
22009
- target: query
22338
+ target: label
22010
22339
  });
22340
+ if (!query && (!where || Object.keys(where).length === 0)) return {
22341
+ content: [{
22342
+ type: "text",
22343
+ text: "find_document needs at least one of `query` (label substring) or `where` (metadata predicates)."
22344
+ }],
22345
+ isError: true
22346
+ };
22011
22347
  await server.ensureSpaceActive(rootId);
22012
22348
  const treeMap = server.getTreeMap();
22013
22349
  if (!treeMap) return { content: [{
@@ -22015,9 +22351,13 @@ function registerTreeTools(mcp, server, validator = null) {
22015
22351
  text: "Not connected"
22016
22352
  }] };
22017
22353
  const entries = readEntries$1(treeMap, server.rootDocId);
22018
- const lowerQuery = query.toLowerCase();
22354
+ const lowerQuery = query?.toLowerCase();
22019
22355
  const normalizedRoot = normalizeRootId$1(rootId, server);
22020
- const matches = (normalizedRoot ? descendantsOf(entries, normalizedRoot) : entries).filter((e) => e.label.toLowerCase().includes(lowerQuery));
22356
+ const matches = (normalizedRoot ? descendantsOf(entries, normalizedRoot) : entries).filter((e) => {
22357
+ if (lowerQuery !== void 0 && !e.label.toLowerCase().includes(lowerQuery)) return false;
22358
+ if (where && !matchesWhere(e, where)) return false;
22359
+ return true;
22360
+ });
22021
22361
  const byId = new Map(entries.map((e) => [e.id, e]));
22022
22362
  const results = matches.map((entry) => {
22023
22363
  const path = [];
@@ -22040,7 +22380,7 @@ function registerTreeTools(mcp, server, validator = null) {
22040
22380
  });
22041
22381
  if (results.length === 0) return { content: [{
22042
22382
  type: "text",
22043
- text: `No documents found matching "${query}". Try get_document_tree to see the full hierarchy.`
22383
+ text: `No documents found matching ${[query ? `label~"${query}"` : null, where ? `where=${JSON.stringify(where)}` : null].filter(Boolean).join(" AND ")}. Try get_document_tree to see the full hierarchy.`
22044
22384
  }] };
22045
22385
  return { content: [{
22046
22386
  type: "text",