From 9cecdc870319f05fe7823329452272d4b72e2184 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Fri, 15 May 2026 23:44:16 +0100 Subject: [PATCH] perf(mcp): emit terse collection summary in serverInstructions Previously buildInstructions emitted one line per collection with name, doc count, and description, which can run to ~1.5 KB for a dozen collections and is injected into every session's system prompt at MCP initialize. Most agents never query qmd in a given session, so the catalogue lines are a recurring token cost for static info that the existing 'status' tool already exposes on demand. Now emit a single comma-joined names line plus a hint that 'status' returns the rest. listContexts() lookup is dropped since the per- collection descriptions are no longer rendered. Refs #647 --- src/mcp/server.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 2f5482f..096fd82 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -106,7 +106,6 @@ function getPackageVersion(): string { */ async function buildInstructions(store: QMDStore): Promise { const status = await store.getStatus(); - const contexts = await store.listContexts(); const globalCtx = await store.getGlobalContext(); const lines: string[] = []; @@ -115,15 +114,13 @@ async function buildInstructions(store: QMDStore): Promise { if (globalCtx) lines.push(`Context: ${globalCtx}`); // --- What's searchable? --- + // Emit names only — the per-collection doc counts and descriptions can run to ~1.5 KB + // across a dozen collections, and the same info is available on demand via the `status` tool. if (status.collections.length > 0) { lines.push(""); - lines.push("Collections (scope with `collection` parameter):"); - for (const col of status.collections) { - // Find root context for this collection - const rootCtx = contexts.find(c => c.collection === col.name && (c.path === "" || c.path === "/")); - const desc = rootCtx ? ` — ${rootCtx.context}` : ""; - lines.push(` - "${col.name}" (${col.documents} docs)${desc}`); - } + const names = status.collections.map(c => c.name).join(", "); + lines.push(`Collections (scope with \`collection\` parameter): ${names}`); + lines.push("Call the `status` tool for collection descriptions, paths, and per-collection doc counts."); } // --- Capability gaps ---