Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/mcp/src/tools/frontmatterValidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ export function registerFrontmatterValidateTool(server: McpServer, deps: McpTool
});
}

const typedLinkMode = args.typed_link_constraint_mode;

let targetLookupNotes: TargetLookupNote[] = scannedNotes.map((note) => ({
path: note.path,
parsed_frontmatter: note.parsed_frontmatter,
Expand All @@ -413,7 +415,8 @@ export function registerFrontmatterValidateTool(server: McpServer, deps: McpTool
// Prefix scan policy
// - source-note set is limited by path_prefix/max_files
// - target resolution uses vault-wide metadata for better relation validation accuracy
if (prefix) {
// - when typed-link constraints are disabled, skip vault-wide lookup expansion
if (prefix && typedLinkMode !== "off") {
const scannedPathSet = new Set(scannedNotes.map((note) => note.path));
const additionalLookupNotes: TargetLookupNote[] = [];

Expand All @@ -439,13 +442,9 @@ export function registerFrontmatterValidateTool(server: McpServer, deps: McpTool
}

const typedLinkDiagnostics =
args.typed_link_constraint_mode === "off"
typedLinkMode === "off"
? []
: collectTypedLinkDiagnostics(
scannedNotes,
targetLookupNotes,
args.typed_link_constraint_mode,
);
: collectTypedLinkDiagnostics(scannedNotes, targetLookupNotes, typedLinkMode);

const diagnosticsByPath = new Map<string, TypedLinkDiagnostic[]>();
for (const diag of typedLinkDiagnostics) {
Expand Down
34 changes: 33 additions & 1 deletion packages/mcp/test/httpTools.frontmatterValidateEdge.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

import { promises as fs } from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -407,4 +407,36 @@ describe("MCP HTTP server (frontmatter_validate edge cases)", () => {
});
});
});

it("skips vault-wide target lookup when typed_link_constraint_mode is off", async () => {
await withTempDir("ailss-mcp-http-", async (vaultPath) => {
await fs.mkdir(path.join(vaultPath, "Folder"), { recursive: true });
await fs.writeFile(path.join(vaultPath, "Folder", "Only.md"), OK_FRONTMATTER + "x\n", "utf8");
await fs.writeFile(path.join(vaultPath, "Root.md"), OK_FRONTMATTER + "y\n", "utf8");

const readSpy = vi.spyOn(fs, "readFile");
try {
await withMcpHttpServer({ vaultPath, enableWriteTools: false }, async ({ url, token }) => {
const sessionId = await mcpInitialize(url, token, "client-a");
readSpy.mockClear();

const res = await mcpToolsCall(url, token, sessionId, "frontmatter_validate", {
path_prefix: "Folder/",
typed_link_constraint_mode: "off",
});

const structured = getStructuredContent(res);
expect(structured["files_scanned"]).toBe(1);
expect(structured["typed_link_constraint_mode"]).toBe("off");
expect(structured["typed_link_diagnostic_count"]).toBe(0);

const readPaths = readSpy.mock.calls.map((call) => String(call[0] ?? ""));
expect(readPaths).toContain(path.join(vaultPath, "Folder", "Only.md"));
expect(readPaths).not.toContain(path.join(vaultPath, "Root.md"));
});
} finally {
readSpy.mockRestore();
}
});
});
});