@imenam/mcp-documentor 1.0.33 → 1.0.34
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/dist/src/index.js
CHANGED
|
@@ -33,6 +33,7 @@ import { HistoryStore } from "./core/history-store.js";
|
|
|
33
33
|
import { listDocVersions } from "./tools/list-doc-versions.js";
|
|
34
34
|
import { getDocVersion } from "./tools/get-doc-version.js";
|
|
35
35
|
import { restoreDocVersion } from "./tools/restore-doc-version.js";
|
|
36
|
+
import { reindexEmbeddings } from "./tools/reindex-embeddings.js";
|
|
36
37
|
const __filename = fileURLToPath(import.meta.url);
|
|
37
38
|
const __dirname = path.dirname(__filename);
|
|
38
39
|
function findProjectRoot(startDir) {
|
|
@@ -709,6 +710,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
709
710
|
required: ["path", "version"],
|
|
710
711
|
},
|
|
711
712
|
},
|
|
713
|
+
{
|
|
714
|
+
name: "reindex_embeddings",
|
|
715
|
+
description: "Generate missing embeddings for all documentation entries in a project (or all projects). Useful when importing existing documentation that was created outside the MCP. Use force: true to regenerate embeddings for all docs, including those already indexed.",
|
|
716
|
+
inputSchema: {
|
|
717
|
+
type: "object",
|
|
718
|
+
properties: {
|
|
719
|
+
project: { type: "string", description: "Project to reindex (processes all projects if omitted)" },
|
|
720
|
+
force: { type: "boolean", description: "If true, regenerates embeddings for all docs even if they are already indexed (default: false)" },
|
|
721
|
+
},
|
|
722
|
+
required: [],
|
|
723
|
+
},
|
|
724
|
+
},
|
|
712
725
|
],
|
|
713
726
|
};
|
|
714
727
|
});
|
|
@@ -754,6 +767,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
754
767
|
return await getDocVersion(historyStore, storageEngine, args);
|
|
755
768
|
case "restore_doc_version":
|
|
756
769
|
return await restoreDocVersion(historyStore, storageEngine, embeddingEngine, args);
|
|
770
|
+
case "reindex_embeddings":
|
|
771
|
+
return await reindexEmbeddings(storageEngine, embeddingEngine, embeddingStore, args);
|
|
757
772
|
default:
|
|
758
773
|
throw new Error(`Tool not found: ${name}`);
|
|
759
774
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StorageEngine } from "../core/storage-engine.js";
|
|
2
|
+
import type { EmbeddingEngine } from "../core/embedding-engine.js";
|
|
3
|
+
import type { EmbeddingStore } from "../core/embedding-store.js";
|
|
4
|
+
export declare function reindexEmbeddings(storageEngine: StorageEngine, embeddingEngine: EmbeddingEngine, embeddingStore: EmbeddingStore, args: unknown): Promise<{
|
|
5
|
+
isError: boolean;
|
|
6
|
+
content: {
|
|
7
|
+
type: string;
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
|
+
} | {
|
|
11
|
+
content: {
|
|
12
|
+
type: string;
|
|
13
|
+
text: string;
|
|
14
|
+
}[];
|
|
15
|
+
isError?: undefined;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ReindexEmbeddingsArgsSchema = z.object({
|
|
3
|
+
project: z.string().optional(),
|
|
4
|
+
force: z.boolean().optional().default(false),
|
|
5
|
+
});
|
|
6
|
+
export async function reindexEmbeddings(storageEngine, embeddingEngine, embeddingStore, args) {
|
|
7
|
+
try {
|
|
8
|
+
if (!embeddingEngine.isConfigured()) {
|
|
9
|
+
return {
|
|
10
|
+
isError: true,
|
|
11
|
+
content: [
|
|
12
|
+
{
|
|
13
|
+
type: "text",
|
|
14
|
+
text: "OpenAI API key is not configured. Set MCP_DOCUMENTOR_OPENAI_API_KEY in your .env file to enable embedding generation.",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const validated = ReindexEmbeddingsArgsSchema.parse(args);
|
|
20
|
+
const config = storageEngine.getConfig();
|
|
21
|
+
const projectsToProcess = validated.project
|
|
22
|
+
? [validated.project]
|
|
23
|
+
: config.projects;
|
|
24
|
+
const summary = [];
|
|
25
|
+
for (const project of projectsToProcess) {
|
|
26
|
+
const docs = await storageEngine.listDocs(project);
|
|
27
|
+
if (docs.length === 0) {
|
|
28
|
+
summary.push({ project, indexed: 0, skipped: 0, failed: 0 });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const existingEmbeddings = embeddingStore.loadAll(project);
|
|
32
|
+
let indexed = 0;
|
|
33
|
+
let skipped = 0;
|
|
34
|
+
let failed = 0;
|
|
35
|
+
for (const docSummary of docs) {
|
|
36
|
+
const alreadyIndexed = existingEmbeddings.has(docSummary.id);
|
|
37
|
+
if (alreadyIndexed && !validated.force) {
|
|
38
|
+
skipped++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const doc = await storageEngine.getDoc(docSummary.id, project);
|
|
42
|
+
if (!doc) {
|
|
43
|
+
failed++;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const embedding = await embeddingEngine.generateEmbedding(doc.content);
|
|
47
|
+
if (embedding) {
|
|
48
|
+
await embeddingEngine.saveEmbedding(doc.id, embedding, project);
|
|
49
|
+
indexed++;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
failed++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
summary.push({ project, indexed, skipped, failed });
|
|
56
|
+
}
|
|
57
|
+
const lines = summary.map((s) => `• [${s.project}] ${s.indexed} indexed, ${s.skipped} skipped (already indexed), ${s.failed} failed`);
|
|
58
|
+
const totalIndexed = summary.reduce((acc, s) => acc + s.indexed, 0);
|
|
59
|
+
const totalSkipped = summary.reduce((acc, s) => acc + s.skipped, 0);
|
|
60
|
+
const totalFailed = summary.reduce((acc, s) => acc + s.failed, 0);
|
|
61
|
+
const resultText = [
|
|
62
|
+
`Reindex complete across ${summary.length} project(s):`,
|
|
63
|
+
...lines,
|
|
64
|
+
"",
|
|
65
|
+
`Total: ${totalIndexed} indexed, ${totalSkipped} skipped, ${totalFailed} failed.`,
|
|
66
|
+
totalSkipped > 0 && !validated.force
|
|
67
|
+
? "Tip: use force: true to regenerate all embeddings including existing ones."
|
|
68
|
+
: "",
|
|
69
|
+
]
|
|
70
|
+
.filter((l) => l !== "")
|
|
71
|
+
.join("\n");
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: "text", text: resultText }],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
78
|
+
return {
|
|
79
|
+
isError: true,
|
|
80
|
+
content: [{ type: "text", text: `Error during reindex: ${message}` }],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const APP_VERSION = "1.0.
|
|
1
|
+
export declare const APP_VERSION = "1.0.34";
|
package/dist/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated version file - do not edit manually
|
|
2
|
-
export const APP_VERSION = '1.0.
|
|
2
|
+
export const APP_VERSION = '1.0.34';
|