knowledge-mcp-server 1.0.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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +205 -0
- package/dist/analytics.d.ts +24 -0
- package/dist/analytics.js +102 -0
- package/dist/analytics.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +98 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +39 -0
- package/dist/config.js +80 -0
- package/dist/config.js.map +1 -0
- package/dist/embeddings.d.ts +26 -0
- package/dist/embeddings.js +534 -0
- package/dist/embeddings.js.map +1 -0
- package/dist/formatter.d.ts +51 -0
- package/dist/formatter.js +273 -0
- package/dist/formatter.js.map +1 -0
- package/dist/generate-embeddings.d.ts +8 -0
- package/dist/generate-embeddings.js +146 -0
- package/dist/generate-embeddings.js.map +1 -0
- package/dist/graph.d.ts +20 -0
- package/dist/graph.js +133 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +481 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +65 -0
- package/dist/init.js.map +1 -0
- package/dist/loader.d.ts +26 -0
- package/dist/loader.js +151 -0
- package/dist/loader.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.js +15 -0
- package/dist/logger.js.map +1 -0
- package/dist/query-classifier.d.ts +23 -0
- package/dist/query-classifier.js +111 -0
- package/dist/query-classifier.js.map +1 -0
- package/dist/reranker.d.ts +7 -0
- package/dist/reranker.js +38 -0
- package/dist/reranker.js.map +1 -0
- package/dist/search.d.ts +17 -0
- package/dist/search.js +299 -0
- package/dist/search.js.map +1 -0
- package/dist/validator.d.ts +23 -0
- package/dist/validator.js +97 -0
- package/dist/validator.js.map +1 -0
- package/dist/writer.d.ts +36 -0
- package/dist/writer.js +360 -0
- package/dist/writer.js.map +1 -0
- package/package.json +58 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { buildGraph, getAncestors, getRelated } from "./graph.js";
|
|
4
|
+
import { knowledgeSearch } from "./search.js";
|
|
5
|
+
import { buildTfIdfIndex } from "./embeddings.js";
|
|
6
|
+
import { formatLookupResult, formatGraphResult, formatWriteResult, formatDeleteResult, formatListResult, } from "./formatter.js";
|
|
7
|
+
import { writeDocument, deleteDocument } from "./writer.js";
|
|
8
|
+
import { validateGraph, formatValidationReport } from "./validator.js";
|
|
9
|
+
import { computeStats, formatStats } from "./analytics.js";
|
|
10
|
+
import { log } from "./logger.js";
|
|
11
|
+
import { loadConfig, getEffectiveDomains, getEffectivePhaseIds } from "./config.js";
|
|
12
|
+
import { buildClassifierConfig } from "./query-classifier.js";
|
|
13
|
+
// --- Fuzzy ID matching for knowledge_lookup ---
|
|
14
|
+
function fuzzyMatchId(g, query) {
|
|
15
|
+
const lower = query.toLowerCase();
|
|
16
|
+
const queryTokens = lower.split(/[\s\-/]+/).filter(Boolean);
|
|
17
|
+
const candidates = [];
|
|
18
|
+
for (const doc of g.documents.values()) {
|
|
19
|
+
let score = 0;
|
|
20
|
+
const idLower = doc.id.toLowerCase();
|
|
21
|
+
const titleLower = doc.title.toLowerCase();
|
|
22
|
+
// Substring match on ID
|
|
23
|
+
if (idLower.includes(lower))
|
|
24
|
+
score += 3;
|
|
25
|
+
else if (lower.includes(idLower))
|
|
26
|
+
score += 2;
|
|
27
|
+
// Substring match on title
|
|
28
|
+
if (titleLower.includes(lower))
|
|
29
|
+
score += 2;
|
|
30
|
+
// Token overlap
|
|
31
|
+
const idTokens = idLower.split(/[-/]+/);
|
|
32
|
+
const titleTokens = titleLower.split(/\s+/);
|
|
33
|
+
for (const qt of queryTokens) {
|
|
34
|
+
if (idTokens.some((t) => t.includes(qt) || qt.includes(t)))
|
|
35
|
+
score += 1;
|
|
36
|
+
if (titleTokens.some((t) => t.includes(qt) || qt.includes(t)))
|
|
37
|
+
score += 1;
|
|
38
|
+
}
|
|
39
|
+
if (score > 0)
|
|
40
|
+
candidates.push({ id: doc.id, title: doc.title, score });
|
|
41
|
+
}
|
|
42
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
43
|
+
return candidates.slice(0, 5);
|
|
44
|
+
}
|
|
45
|
+
export function createKnowledgeServer(knowledgeDir) {
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
const config = loadConfig(knowledgeDir);
|
|
48
|
+
const validDomains = getEffectiveDomains(config, knowledgeDir);
|
|
49
|
+
const validPhaseIds = getEffectivePhaseIds(config);
|
|
50
|
+
const graph = buildGraph(knowledgeDir, validDomains);
|
|
51
|
+
let tfidfIndex = buildTfIdfIndex(graph.documents);
|
|
52
|
+
const classifierConfig = buildClassifierConfig(config);
|
|
53
|
+
const elapsed = Date.now() - start;
|
|
54
|
+
log.info("startup", {
|
|
55
|
+
docs: graph.documents.size,
|
|
56
|
+
embeddings: graph.embeddings.vectors.size,
|
|
57
|
+
embeddingsAvailable: graph.embeddings.available,
|
|
58
|
+
ms: elapsed,
|
|
59
|
+
});
|
|
60
|
+
// --- Write serialization queue (prevents concurrent index corruption) ---
|
|
61
|
+
let writeQueue = Promise.resolve();
|
|
62
|
+
function enqueueWrite(fn) {
|
|
63
|
+
const result = writeQueue.then(fn);
|
|
64
|
+
writeQueue = result.catch(() => { });
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
const server = new McpServer({
|
|
68
|
+
name: "knowledge",
|
|
69
|
+
version: "1.0.0",
|
|
70
|
+
});
|
|
71
|
+
// Tool 1: knowledge_search
|
|
72
|
+
server.tool("knowledge_search", `Semantic search over the ${config?.name || "project"} knowledge graph. Returns relevant documents with ancestor context and cross-references, formatted as XML.`, {
|
|
73
|
+
query: z.string().describe("Natural language query"),
|
|
74
|
+
domains: z
|
|
75
|
+
.array(z.string())
|
|
76
|
+
.optional()
|
|
77
|
+
.describe(validDomains
|
|
78
|
+
? `Pre-filter to specific domains: ${validDomains.join(", ")}`
|
|
79
|
+
: "Pre-filter to specific domains (auto-discovered from directory structure)"),
|
|
80
|
+
phases: z
|
|
81
|
+
.array(z.number())
|
|
82
|
+
.optional()
|
|
83
|
+
.describe(validPhaseIds
|
|
84
|
+
? `Pre-filter to specific phases: ${validPhaseIds.join(", ")}`
|
|
85
|
+
: "Pre-filter to specific phases (positive integers)"),
|
|
86
|
+
tags: z.array(z.string()).optional().describe("Require specific tags"),
|
|
87
|
+
type: z
|
|
88
|
+
.enum(["summary", "detail", "decision", "reference"])
|
|
89
|
+
.optional()
|
|
90
|
+
.describe("Filter by document type"),
|
|
91
|
+
max_results: z
|
|
92
|
+
.number()
|
|
93
|
+
.optional()
|
|
94
|
+
.default(10)
|
|
95
|
+
.describe("Maximum number of documents to return (default 10)"),
|
|
96
|
+
detail_level: z
|
|
97
|
+
.enum(["summary", "normal", "full"])
|
|
98
|
+
.optional()
|
|
99
|
+
.default("normal")
|
|
100
|
+
.describe('Content detail level: "summary" (~40-500 words per doc), "normal" (~80-1500 words, default), "full" (no truncation)'),
|
|
101
|
+
include_drafts: z
|
|
102
|
+
.boolean()
|
|
103
|
+
.optional()
|
|
104
|
+
.default(false)
|
|
105
|
+
.describe("Include draft documents in results (default false)"),
|
|
106
|
+
}, async ({ query, domains, phases, tags, type, max_results, detail_level, include_drafts }) => {
|
|
107
|
+
const result = await knowledgeSearch(graph, tfidfIndex, {
|
|
108
|
+
query,
|
|
109
|
+
domains,
|
|
110
|
+
phases,
|
|
111
|
+
tags,
|
|
112
|
+
type,
|
|
113
|
+
maxResults: max_results,
|
|
114
|
+
detailLevel: detail_level,
|
|
115
|
+
includeDrafts: include_drafts,
|
|
116
|
+
}, classifierConfig);
|
|
117
|
+
return { content: [{ type: "text", text: result }] };
|
|
118
|
+
});
|
|
119
|
+
// Tool 2: knowledge_lookup
|
|
120
|
+
server.tool("knowledge_lookup", "Retrieve one or more documents by ID. Accepts a single `id` string or an `ids` array (max 10). Returns documents with optional ancestor summaries and related documents.", {
|
|
121
|
+
id: z
|
|
122
|
+
.string()
|
|
123
|
+
.optional()
|
|
124
|
+
.describe('Single document ID, e.g., "business/pricing-tiers" or "technology/audio-detection/pitch-detection"'),
|
|
125
|
+
ids: z
|
|
126
|
+
.array(z.string())
|
|
127
|
+
.optional()
|
|
128
|
+
.describe("Array of document IDs for batch retrieval (max 10)"),
|
|
129
|
+
include_ancestors: z
|
|
130
|
+
.boolean()
|
|
131
|
+
.optional()
|
|
132
|
+
.default(true)
|
|
133
|
+
.describe("Include parent summary documents (default true)"),
|
|
134
|
+
include_related: z
|
|
135
|
+
.boolean()
|
|
136
|
+
.optional()
|
|
137
|
+
.default(false)
|
|
138
|
+
.describe("Include related documents (default false)"),
|
|
139
|
+
content: z
|
|
140
|
+
.enum(["full", "summary"])
|
|
141
|
+
.optional()
|
|
142
|
+
.default("full")
|
|
143
|
+
.describe('Content level: "full" (complete content, default) or "summary" (truncated)'),
|
|
144
|
+
}, async ({ id, ids, include_ancestors, include_related, content }) => {
|
|
145
|
+
// Resolve list of IDs (single or batch)
|
|
146
|
+
const lookupIds = ids ? ids.slice(0, 10) : id ? [id] : [];
|
|
147
|
+
if (lookupIds.length === 0) {
|
|
148
|
+
return {
|
|
149
|
+
content: [
|
|
150
|
+
{ type: "text", text: "Error: provide either `id` or `ids` parameter." },
|
|
151
|
+
],
|
|
152
|
+
isError: true,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// Single document lookup (original behavior with fuzzy matching)
|
|
156
|
+
if (lookupIds.length === 1) {
|
|
157
|
+
const docId = lookupIds[0];
|
|
158
|
+
const doc = graph.documents.get(docId);
|
|
159
|
+
if (!doc) {
|
|
160
|
+
const suggestions = fuzzyMatchId(graph, docId);
|
|
161
|
+
const hint = suggestions.length > 0
|
|
162
|
+
? `\n\nDid you mean:\n${suggestions.map((s) => ` - ${s.id} ("${s.title}")`).join("\n")}`
|
|
163
|
+
: "\n\nUse knowledge_graph to browse available documents.";
|
|
164
|
+
return {
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
type: "text",
|
|
168
|
+
text: `Document not found: "${docId}".${hint}`,
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const ancestors = include_ancestors ? getAncestors(graph, docId) : [];
|
|
174
|
+
const related = include_related ? getRelated(graph, docId) : [];
|
|
175
|
+
const result = formatLookupResult(doc, ancestors, related, content);
|
|
176
|
+
return { content: [{ type: "text", text: result }] };
|
|
177
|
+
}
|
|
178
|
+
// Batch lookup: collect all docs, deduplicate ancestors/related
|
|
179
|
+
const seen = new Set();
|
|
180
|
+
const allAncestors = [];
|
|
181
|
+
const allPrimary = [];
|
|
182
|
+
const allRelated = [];
|
|
183
|
+
const notFound = [];
|
|
184
|
+
for (const docId of lookupIds) {
|
|
185
|
+
const doc = graph.documents.get(docId);
|
|
186
|
+
if (!doc) {
|
|
187
|
+
notFound.push(docId);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!seen.has(doc.id)) {
|
|
191
|
+
seen.add(doc.id);
|
|
192
|
+
allPrimary.push(doc);
|
|
193
|
+
}
|
|
194
|
+
if (include_ancestors) {
|
|
195
|
+
for (const a of getAncestors(graph, docId)) {
|
|
196
|
+
if (!seen.has(a.id)) {
|
|
197
|
+
seen.add(a.id);
|
|
198
|
+
allAncestors.push(a);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (include_related) {
|
|
203
|
+
for (const r of getRelated(graph, docId)) {
|
|
204
|
+
if (!seen.has(r.id)) {
|
|
205
|
+
seen.add(r.id);
|
|
206
|
+
allRelated.push(r);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Format as combined lookup (first primary doc is the "main", rest are related-style)
|
|
212
|
+
const parts = [];
|
|
213
|
+
if (notFound.length > 0) {
|
|
214
|
+
parts.push(`Documents not found: ${notFound.join(", ")}`);
|
|
215
|
+
}
|
|
216
|
+
// Use first primary as the main doc, rest as additional
|
|
217
|
+
if (allPrimary.length > 0) {
|
|
218
|
+
const result = formatLookupResult(allPrimary[0], allAncestors, [...allPrimary.slice(1), ...allRelated], content);
|
|
219
|
+
parts.push(result);
|
|
220
|
+
}
|
|
221
|
+
return { content: [{ type: "text", text: parts.join("\n\n") }] };
|
|
222
|
+
});
|
|
223
|
+
// Tool 3: knowledge_graph
|
|
224
|
+
server.tool("knowledge_graph", "Returns the graph structure for a subtree. Useful for understanding document relationships and navigating the knowledge base.", {
|
|
225
|
+
root_id: z.string().optional().default("root").describe('Starting node ID (default "root")'),
|
|
226
|
+
depth: z
|
|
227
|
+
.number()
|
|
228
|
+
.optional()
|
|
229
|
+
.default(2)
|
|
230
|
+
.describe("Levels deep to traverse (default 2, max 4)"),
|
|
231
|
+
include_related: z
|
|
232
|
+
.boolean()
|
|
233
|
+
.optional()
|
|
234
|
+
.default(false)
|
|
235
|
+
.describe("Include related edges (default false)"),
|
|
236
|
+
max_nodes: z
|
|
237
|
+
.number()
|
|
238
|
+
.optional()
|
|
239
|
+
.default(50)
|
|
240
|
+
.describe("Maximum number of nodes to return (default 50)"),
|
|
241
|
+
}, async ({ root_id, depth, include_related, max_nodes }) => {
|
|
242
|
+
const rootDoc = graph.documents.get(root_id);
|
|
243
|
+
if (!rootDoc) {
|
|
244
|
+
return {
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: "text",
|
|
248
|
+
text: `Document not found: "${root_id}". Available root domains: ${[...graph.domainIndex.keys()].join(", ")}`,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
// Cap depth at 4
|
|
254
|
+
const effectiveDepth = Math.min(depth, 4);
|
|
255
|
+
const nodes = [];
|
|
256
|
+
const edges = [];
|
|
257
|
+
const visited = new Set();
|
|
258
|
+
function walk(id, currentDepth) {
|
|
259
|
+
if (visited.has(id) || currentDepth > effectiveDepth || nodes.length >= max_nodes)
|
|
260
|
+
return;
|
|
261
|
+
visited.add(id);
|
|
262
|
+
const doc = graph.documents.get(id);
|
|
263
|
+
if (!doc)
|
|
264
|
+
return;
|
|
265
|
+
nodes.push({
|
|
266
|
+
id: doc.id,
|
|
267
|
+
title: doc.title,
|
|
268
|
+
type: doc.type,
|
|
269
|
+
domain: doc.domain,
|
|
270
|
+
wordCount: doc.wordCount,
|
|
271
|
+
childrenCount: doc.childrenIds.length,
|
|
272
|
+
});
|
|
273
|
+
// Child edges
|
|
274
|
+
for (const childId of doc.childrenIds) {
|
|
275
|
+
if (nodes.length >= max_nodes)
|
|
276
|
+
break;
|
|
277
|
+
edges.push({ source: id, target: childId, type: "child" });
|
|
278
|
+
walk(childId, currentDepth + 1);
|
|
279
|
+
}
|
|
280
|
+
// Related edges (non-recursive)
|
|
281
|
+
if (include_related) {
|
|
282
|
+
for (const relatedId of doc.related) {
|
|
283
|
+
if (graph.documents.has(relatedId)) {
|
|
284
|
+
edges.push({
|
|
285
|
+
source: id,
|
|
286
|
+
target: relatedId,
|
|
287
|
+
type: "related",
|
|
288
|
+
});
|
|
289
|
+
// Add related node if not visited (but don't recurse into it)
|
|
290
|
+
if (!visited.has(relatedId) && nodes.length < max_nodes) {
|
|
291
|
+
const relDoc = graph.documents.get(relatedId);
|
|
292
|
+
nodes.push({
|
|
293
|
+
id: relDoc.id,
|
|
294
|
+
title: relDoc.title,
|
|
295
|
+
type: relDoc.type,
|
|
296
|
+
domain: relDoc.domain,
|
|
297
|
+
wordCount: relDoc.wordCount,
|
|
298
|
+
childrenCount: relDoc.childrenIds.length,
|
|
299
|
+
});
|
|
300
|
+
visited.add(relatedId);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
walk(root_id, 0);
|
|
307
|
+
const result = formatGraphResult(nodes, edges, graph.documents.size, root_id);
|
|
308
|
+
return { content: [{ type: "text", text: result }] };
|
|
309
|
+
});
|
|
310
|
+
// Tool 4: knowledge_list
|
|
311
|
+
server.tool("knowledge_list", "List documents in the knowledge graph with metadata only (no content). Supports filtering by domain, type, phase, tags, and title search.", {
|
|
312
|
+
domain: z.string().optional().describe("Filter by domain"),
|
|
313
|
+
type: z
|
|
314
|
+
.enum(["summary", "detail", "decision", "reference"])
|
|
315
|
+
.optional()
|
|
316
|
+
.describe("Filter by document type"),
|
|
317
|
+
phase: z.number().optional().describe("Filter by phase (1, 2, or 3)"),
|
|
318
|
+
tags: z.array(z.string()).optional().describe("Require specific tags"),
|
|
319
|
+
title_search: z.string().optional().describe("Substring search on document titles"),
|
|
320
|
+
include_drafts: z
|
|
321
|
+
.boolean()
|
|
322
|
+
.optional()
|
|
323
|
+
.default(false)
|
|
324
|
+
.describe("Include draft documents (default false)"),
|
|
325
|
+
}, async ({ domain, type, phase, tags, title_search, include_drafts }) => {
|
|
326
|
+
const results = [];
|
|
327
|
+
for (const doc of graph.documents.values()) {
|
|
328
|
+
// Apply filters
|
|
329
|
+
if (!include_drafts && doc.status === "draft")
|
|
330
|
+
continue;
|
|
331
|
+
if (domain && doc.domain.toLowerCase() !== domain.toLowerCase())
|
|
332
|
+
continue;
|
|
333
|
+
if (type && doc.type !== type)
|
|
334
|
+
continue;
|
|
335
|
+
if (phase && !doc.phase.includes(phase))
|
|
336
|
+
continue;
|
|
337
|
+
if (tags && tags.length > 0) {
|
|
338
|
+
const docTagsLower = new Set(doc.tags.map((t) => t.toLowerCase()));
|
|
339
|
+
if (!tags.every((t) => docTagsLower.has(t.toLowerCase())))
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (title_search && !doc.title.toLowerCase().includes(title_search.toLowerCase()))
|
|
343
|
+
continue;
|
|
344
|
+
results.push({
|
|
345
|
+
id: doc.id,
|
|
346
|
+
title: doc.title,
|
|
347
|
+
type: doc.type,
|
|
348
|
+
domain: doc.domain,
|
|
349
|
+
tags: doc.tags,
|
|
350
|
+
wordCount: doc.wordCount,
|
|
351
|
+
status: doc.status,
|
|
352
|
+
lastUpdated: doc.lastUpdated,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
// Sort by domain, then ID
|
|
356
|
+
results.sort((a, b) => a.domain.localeCompare(b.domain) || a.id.localeCompare(b.id));
|
|
357
|
+
const result = formatListResult(results, graph.documents.size);
|
|
358
|
+
return { content: [{ type: "text", text: result }] };
|
|
359
|
+
});
|
|
360
|
+
// Tool 5: knowledge_write
|
|
361
|
+
server.tool("knowledge_write", "Create or update a document in the knowledge graph. Validates inputs, writes to disk, and updates in-memory indices so the document is immediately searchable.", {
|
|
362
|
+
id: z
|
|
363
|
+
.string()
|
|
364
|
+
.describe('Document ID, e.g., "technology/audio-detection/pitch-detection". Lowercase, hyphens, slashes only.'),
|
|
365
|
+
title: z.string().describe("Human-readable document title"),
|
|
366
|
+
type: z
|
|
367
|
+
.enum(["summary", "detail", "decision", "reference"])
|
|
368
|
+
.describe("Document type: summary (domain/subdomain overview), detail (deep analysis), decision (choice with alternatives), reference (external tools/datasets)"),
|
|
369
|
+
domain: z
|
|
370
|
+
.string()
|
|
371
|
+
.describe(validDomains
|
|
372
|
+
? `Top-level domain: ${validDomains.join(", ")}`
|
|
373
|
+
: "Top-level domain (any valid domain directory)"),
|
|
374
|
+
subdomain: z.string().optional().describe("Optional subdomain within the domain"),
|
|
375
|
+
tags: z.array(z.string()).describe("Searchable tags"),
|
|
376
|
+
phase: z
|
|
377
|
+
.array(z.number())
|
|
378
|
+
.describe(validPhaseIds
|
|
379
|
+
? `Applicable phases: ${validPhaseIds.join(", ")}`
|
|
380
|
+
: "Applicable phases (positive integers)"),
|
|
381
|
+
related: z
|
|
382
|
+
.array(z.string())
|
|
383
|
+
.optional()
|
|
384
|
+
.describe("IDs of related documents for cross-referencing"),
|
|
385
|
+
children: z
|
|
386
|
+
.array(z.string())
|
|
387
|
+
.optional()
|
|
388
|
+
.describe("Child document IDs (only for summary type)"),
|
|
389
|
+
content: z.string().describe("Markdown body content (no frontmatter)"),
|
|
390
|
+
status: z
|
|
391
|
+
.enum(["active", "draft", "deprecated"])
|
|
392
|
+
.optional()
|
|
393
|
+
.describe('Document status: "active" (default), "draft" (excluded from search), "deprecated" (ranked lower)'),
|
|
394
|
+
superseded_by: z
|
|
395
|
+
.string()
|
|
396
|
+
.optional()
|
|
397
|
+
.describe("ID of document that supersedes this one (for deprecated docs)"),
|
|
398
|
+
decision_status: z
|
|
399
|
+
.enum(["proposed", "accepted", "deprecated", "superseded", "finalized"])
|
|
400
|
+
.optional()
|
|
401
|
+
.describe("Decision status (only for decision type)"),
|
|
402
|
+
alternatives_considered: z
|
|
403
|
+
.array(z.string())
|
|
404
|
+
.optional()
|
|
405
|
+
.describe("List of alternatives that were considered (only for decision type)"),
|
|
406
|
+
decision_date: z
|
|
407
|
+
.string()
|
|
408
|
+
.optional()
|
|
409
|
+
.describe("Date when decision was made, ISO format (only for decision type)"),
|
|
410
|
+
}, async ({ id, title, type, domain, subdomain, tags, phase, related, children, content, status, superseded_by, decision_status, alternatives_considered, decision_date, }) => enqueueWrite(async () => {
|
|
411
|
+
try {
|
|
412
|
+
const result = writeDocument(graph, tfidfIndex, knowledgeDir, {
|
|
413
|
+
id,
|
|
414
|
+
title,
|
|
415
|
+
type,
|
|
416
|
+
domain,
|
|
417
|
+
subdomain,
|
|
418
|
+
tags,
|
|
419
|
+
phase,
|
|
420
|
+
related,
|
|
421
|
+
children,
|
|
422
|
+
content,
|
|
423
|
+
status,
|
|
424
|
+
superseded_by,
|
|
425
|
+
decision_status,
|
|
426
|
+
alternatives_considered,
|
|
427
|
+
decision_date,
|
|
428
|
+
}, validDomains, validPhaseIds);
|
|
429
|
+
tfidfIndex = result.tfidfIndex;
|
|
430
|
+
log.info("write", { id, status: result.status });
|
|
431
|
+
return {
|
|
432
|
+
content: [{ type: "text", text: formatWriteResult(result) }],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
437
|
+
log.error("write_error", { id, error: message });
|
|
438
|
+
return {
|
|
439
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
440
|
+
isError: true,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}));
|
|
444
|
+
// Tool 6: knowledge_delete
|
|
445
|
+
server.tool("knowledge_delete", "Delete a document from the knowledge graph. Removes from disk and all in-memory indices. Warns about orphaned children and broken cross-references.", {
|
|
446
|
+
id: z.string().describe("Document ID to delete"),
|
|
447
|
+
}, async ({ id }) => enqueueWrite(async () => {
|
|
448
|
+
try {
|
|
449
|
+
const result = deleteDocument(graph, tfidfIndex, knowledgeDir, id);
|
|
450
|
+
tfidfIndex = result.tfidfIndex;
|
|
451
|
+
log.info("delete", { id });
|
|
452
|
+
return {
|
|
453
|
+
content: [{ type: "text", text: formatDeleteResult(result) }],
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
catch (err) {
|
|
457
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
458
|
+
log.error("delete_error", { id, error: message });
|
|
459
|
+
return {
|
|
460
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
461
|
+
isError: true,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
}));
|
|
465
|
+
// Tool 7: knowledge_validate
|
|
466
|
+
server.tool("knowledge_validate", "Run graph integrity checks. Reports orphaned documents, broken references, circular parents, missing tags, empty summaries, stale documents, and embedding coverage.", {}, async () => {
|
|
467
|
+
const report = validateGraph(graph);
|
|
468
|
+
return {
|
|
469
|
+
content: [{ type: "text", text: formatValidationReport(report) }],
|
|
470
|
+
};
|
|
471
|
+
});
|
|
472
|
+
// Tool 8: knowledge_stats
|
|
473
|
+
server.tool("knowledge_stats", "Returns read-only metrics about the knowledge graph: document counts by type/domain/phase, tag distribution, cross-link density, most-connected documents, and embedding coverage.", {}, async () => {
|
|
474
|
+
const stats = computeStats(graph);
|
|
475
|
+
return {
|
|
476
|
+
content: [{ type: "text", text: formatStats(stats) }],
|
|
477
|
+
};
|
|
478
|
+
});
|
|
479
|
+
return { server, graph, tfidfIndex, config };
|
|
480
|
+
}
|
|
481
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG3D,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,oBAAoB,EAAwB,MAAM,aAAa,CAAC;AAC1G,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,iDAAiD;AACjD,SAAS,YAAY,CACnB,CAAiB,EACjB,KAAa;IAEb,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAClC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5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;AAC/C,CAAC"}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initKnowledgeDir(knowledgeDir: string): void;
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const CONFIG_TEMPLATE = `# Knowledge graph configuration
|
|
4
|
+
# See: https://github.com/rossng/knowledge-mcp-server#configuration
|
|
5
|
+
|
|
6
|
+
# name: "my-project"
|
|
7
|
+
|
|
8
|
+
# Uncomment and customize domains to enforce strict validation:
|
|
9
|
+
# domains:
|
|
10
|
+
# - technology
|
|
11
|
+
# - architecture
|
|
12
|
+
# - business
|
|
13
|
+
|
|
14
|
+
# Uncomment to define project phases:
|
|
15
|
+
# phases:
|
|
16
|
+
# - id: 1
|
|
17
|
+
# name: "Phase 1"
|
|
18
|
+
# - id: 2
|
|
19
|
+
# name: "Phase 2"
|
|
20
|
+
|
|
21
|
+
# Uncomment to add query hints for domain classification:
|
|
22
|
+
# query_hints:
|
|
23
|
+
# technology: ["api", "database", "framework"]
|
|
24
|
+
|
|
25
|
+
# Uncomment to define synonym expansion:
|
|
26
|
+
# synonyms:
|
|
27
|
+
# ml: ["machine learning"]
|
|
28
|
+
# ai: ["artificial intelligence"]
|
|
29
|
+
|
|
30
|
+
# Embedding configuration (optional, enables semantic search):
|
|
31
|
+
# embeddings:
|
|
32
|
+
# provider: "voyage"
|
|
33
|
+
# model: "voyage-3-lite"
|
|
34
|
+
# api_key_env: "VOYAGE_API_KEY"
|
|
35
|
+
`;
|
|
36
|
+
const ROOT_SUMMARY_TEMPLATE = `---
|
|
37
|
+
id: root
|
|
38
|
+
title: Knowledge Root
|
|
39
|
+
type: summary
|
|
40
|
+
domain: root
|
|
41
|
+
tags: []
|
|
42
|
+
phase: []
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
Root node of the knowledge graph. Add domain directories and documents below this.
|
|
46
|
+
`;
|
|
47
|
+
export function initKnowledgeDir(knowledgeDir) {
|
|
48
|
+
const configPath = join(knowledgeDir, "knowledge.config.yaml");
|
|
49
|
+
if (existsSync(configPath)) {
|
|
50
|
+
console.log(`Already initialized: ${configPath} exists.`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
mkdirSync(knowledgeDir, { recursive: true });
|
|
54
|
+
writeFileSync(configPath, CONFIG_TEMPLATE);
|
|
55
|
+
writeFileSync(join(knowledgeDir, "_summary.md"), ROOT_SUMMARY_TEMPLATE);
|
|
56
|
+
console.log(`Initialized knowledge directory at ${knowledgeDir}`);
|
|
57
|
+
console.log(" Created: knowledge.config.yaml");
|
|
58
|
+
console.log(" Created: _summary.md (root node)");
|
|
59
|
+
console.log("");
|
|
60
|
+
console.log("Next steps:");
|
|
61
|
+
console.log(" 1. Edit knowledge.config.yaml to configure domains and phases");
|
|
62
|
+
console.log(" 2. Create domain directories (e.g., mkdir knowledge/technology)");
|
|
63
|
+
console.log(" 3. Add documents with YAML frontmatter (see README for format)");
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCvB,CAAC;AAEF,MAAM,qBAAqB,GAAG;;;;;;;;;;CAU7B,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,YAAoB;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAAC;IAE/D,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,wBAAwB,UAAU,UAAU,CAAC,CAAC;QAC1D,OAAO;IACT,CAAC;IAED,SAAS,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,aAAa,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IAC3C,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAExE,OAAO,CAAC,GAAG,CAAC,sCAAsC,YAAY,EAAE,CAAC,CAAC;IAClE,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,kEAAkE,CAAC,CAAC;AAClF,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type DocumentStatus = "active" | "draft" | "deprecated";
|
|
2
|
+
export interface KnowledgeDocument {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
type: "summary" | "detail" | "decision" | "reference";
|
|
6
|
+
domain: string;
|
|
7
|
+
subdomain?: string;
|
|
8
|
+
tags: string[];
|
|
9
|
+
phase: number[];
|
|
10
|
+
related: string[];
|
|
11
|
+
parentId: string | null;
|
|
12
|
+
childrenIds: string[];
|
|
13
|
+
contentBody: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
wordCount: number;
|
|
16
|
+
status: DocumentStatus;
|
|
17
|
+
supersededBy?: string;
|
|
18
|
+
lastUpdated?: string;
|
|
19
|
+
decisionStatus?: "proposed" | "accepted" | "deprecated" | "superseded" | "finalized";
|
|
20
|
+
alternativesConsidered?: string[];
|
|
21
|
+
decisionDate?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const VALID_TYPES: readonly ["summary", "detail", "decision", "reference"];
|
|
24
|
+
export declare function deriveParentId(id: string): string | null;
|
|
25
|
+
export declare function collectMarkdownFiles(dir: string): string[];
|
|
26
|
+
export declare function loadDocuments(knowledgeDir: string, validDomains?: string[] | null): Map<string, KnowledgeDocument>;
|