Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

fix: flag mcp_never_expose entries that are paths or folders instead of ignoring them (#295)

Brenno Ferraridb81b798795c
diff --git a/.claude/scripts/lib/mcp-exposure.ts b/.claude/scripts/lib/mcp-exposure.ts
index 0fda6a0..23fce37 100644
--- a/.claude/scripts/lib/mcp-exposure.ts
+++ b/.claude/scripts/lib/mcp-exposure.ts
@@ -128,6 +128,39 @@ export function isNeverExposed(policy: ExposurePolicy, path: string): boolean {
return false;
}
+/**
+ * `mcp_never_expose` entries that can never withhold anything. The check
+ * compares an entry with a served note's BASENAME, and only `.md` files are
+ * served, so an entry holding a separator (`perf/`, `work/1-1/`,
+ * `brain/North Star.md`) or lacking `.md` (`SOUL`) matches nothing. Such an
+ * entry used to be accepted silently — a privacy control failing open, with
+ * the owner believing those notes were withheld. Withholding a folder is what
+ * `mcp_exposed_roots` does; this list stays filename-only, and `health`
+ * names the entries that cannot work.
+ */
+export function inertNeverExposeEntries(
+ manifest: Record<string, unknown> | null | undefined,
+): { readonly entry: string; readonly fix: string }[] {
+ const list = Array.isArray(manifest?.mcp_never_expose) ? manifest.mcp_never_expose : [];
+ const out: { entry: string; fix: string }[] = [];
+ for (const raw of list) {
+ if (typeof raw !== "string") continue;
+ const entry = raw.trim();
+ if (/[\\/]/.test(entry)) {
+ const name = entry.replace(/[\\/]+$/, "").split(/[\\/]/).pop() ?? "";
+ out.push({
+ entry: raw,
+ fix: name.toLowerCase().endsWith(".md")
+ ? `use the bare filename "${name}"`
+ : "to withhold a folder, leave it out of mcp_exposed_roots",
+ });
+ } else if (entry && !entry.toLowerCase().endsWith(".md")) {
+ out.push({ entry: raw, fix: `only .md notes are served — did you mean "${entry}.md"?` });
+ }
+ }
+ return out;
+}
+
/**
* Memories are never served as ordinary notes, whatever the config says. They
* carry their own declared scope, evaluated per caller; reaching them through
diff --git a/.claude/scripts/lib/memory-discover.ts b/.claude/scripts/lib/memory-discover.ts
index 3cbd625..d5fefad 100644
--- a/.claude/scripts/lib/memory-discover.ts
+++ b/.claude/scripts/lib/memory-discover.ts
@@ -23,6 +23,7 @@
import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
import { normalizePath } from "./mcp-caller.ts";
import { readHead } from "./read-head.ts";
+import { inertNeverExposeEntries } from "./mcp-exposure.ts";
import { MEMORY_SOURCE } from "./memory-write.ts";
import { join, relative, sep } from "node:path";
@@ -425,6 +426,11 @@ export function health(
`Captures are split across ${mem.split.map((s) => `${s.root}/ (${s.memories})`).join(" and ")} — retrieval only sees "${mem.root}/". Move the rest.`,
);
}
+ for (const { entry, fix } of inertNeverExposeEntries(manifest)) {
+ warnings.push(
+ `mcp_never_expose entry "${entry}" withholds nothing: only a note's bare filename is matched. To fix: ${fix}.`,
+ );
+ }
// An undeclared `mcp_exposed_roots` is not a warning: it means the server
// serves the vault's own `user_content_roots`, which is the default and the
// state most vaults should be in. Declaring the key narrows that.
diff --git a/.claude/scripts/tests/memory-discover.test.ts b/.claude/scripts/tests/memory-discover.test.ts
index be2e287..6d15e23 100644
--- a/.claude/scripts/tests/memory-discover.test.ts
+++ b/.claude/scripts/tests/memory-discover.test.ts
@@ -435,6 +435,37 @@ describe("health", () => {
});
});
+ /**
+ * A path or folder in mcp_never_expose used to be accepted silently and
+ * match nothing — the owner believed those notes were withheld.
+ */
+ test("mcp_never_expose entries that can never match are named, with the fix", () => {
+ withVault((dir) => {
+ mkdirSync(join(dir, "brain"), { recursive: true });
+ put(dir, ".claude/scripts/qmd-mcp.mjs", "//");
+ const h = health(dir, {
+ user_content_roots: ["brain/"],
+ mcp_never_expose: ["SOUL.md", "perf/", "brain/North Star.md", "Secrets"],
+ });
+ const w = h.warnings.filter((x) => x.includes("mcp_never_expose"));
+ assert.equal(w.length, 3, w.join("\n"));
+ assert.match(w.join("\n"), /"perf\/".*mcp_exposed_roots/);
+ assert.match(w.join("\n"), /"brain\/North Star\.md".*bare filename "North Star\.md"/);
+ assert.match(w.join("\n"), /"Secrets".*"Secrets\.md"/);
+ assert.ok(!w.some((x) => x.includes('"SOUL.md"')), "a bare filename is valid");
+ assert.equal(h.ok, false);
+ });
+ });
+
+ test("a valid mcp_never_expose list adds no warning", () => {
+ withVault((dir) => {
+ mkdirSync(join(dir, "brain"), { recursive: true });
+ put(dir, ".claude/scripts/qmd-mcp.mjs", "//");
+ const h = health(dir, { user_content_roots: ["brain/"], mcp_never_expose: ["SOUL.md", "north star.MD"] });
+ assert.deepEqual(h.warnings, []);
+ });
+ });
+
test("a missing qmd launcher warns but does not claim the vault is empty", () => {
withVault((dir) => {
mkdirSync(join(dir, "brain"), { recursive: true });