@imenam/mcp-documentor 1.0.24 → 1.0.25

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.
@@ -25,5 +25,6 @@ export declare class StorageEngine {
25
25
  } | null>;
26
26
  deleteDoc(id: string, project?: string): Promise<boolean>;
27
27
  moveDoc(oldId: string, newId: string, project?: string): Promise<boolean>;
28
+ rewriteLinks(oldId: string, newId: string, project?: string): Promise<string[]>;
28
29
  }
29
30
  export {};
@@ -3,6 +3,9 @@ import path from "path";
3
3
  import matter from "gray-matter";
4
4
  import { createLogger } from "@imenam/mcp-gui-interface";
5
5
  const logger = createLogger("StorageEngine");
6
+ function escapeRegex(s) {
7
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8
+ }
6
9
  export class StorageEngine {
7
10
  rootDir;
8
11
  constructor(rootDir) {
@@ -188,4 +191,35 @@ export class StorageEngine {
188
191
  logger.info(`Doc moved: ${oldFilePath} → ${newFilePath}`);
189
192
  return true;
190
193
  }
194
+ async rewriteLinks(oldId, newId, project) {
195
+ const docs = await this.listDocs(project);
196
+ const updated = [];
197
+ for (const summary of docs) {
198
+ if (summary.id === newId)
199
+ continue;
200
+ const doc = await this.getDoc(summary.id, project);
201
+ if (!doc)
202
+ continue;
203
+ let changed = false;
204
+ const newContent = doc.content.replace(new RegExp(`doc://${escapeRegex(oldId)}`, "g"), `doc://${newId}`);
205
+ if (newContent !== doc.content) {
206
+ doc.content = newContent;
207
+ changed = true;
208
+ }
209
+ const newRelated = doc.related_docs.map((ref) => {
210
+ if (ref === oldId) {
211
+ changed = true;
212
+ return newId;
213
+ }
214
+ return ref;
215
+ });
216
+ doc.related_docs = newRelated;
217
+ if (changed) {
218
+ doc.updatedAt = new Date().toISOString();
219
+ await this.saveDoc(doc, project);
220
+ updated.push(summary.id);
221
+ }
222
+ }
223
+ return updated;
224
+ }
191
225
  }
package/dist/src/index.js CHANGED
@@ -404,7 +404,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
404
404
  items: { type: "string" },
405
405
  description: "IDs of related documentation entries",
406
406
  },
407
- project: { type: "string", description: "Project to create the doc in (defaults to current project if omitted)" },
407
+ project: { type: "string", description: "Project to create the doc in (defaults to current project if omitted). If the project name does not exist yet, it will be created automatically." },
408
408
  },
409
409
  required: ["title", "content"],
410
410
  },
@@ -463,7 +463,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
463
463
  },
464
464
  {
465
465
  name: "move_doc",
466
- description: "Move a documentation entry to a new path (changes its folder and/or name). This is the only way to relocate a document — update_doc does not change the location. After moving, use check_links to detect any broken references.",
466
+ description: "Move a documentation entry to a new path (changes its folder and/or name). All existing doc:// links and related_docs references pointing to the old path are automatically rewritten across the project. This is the only way to relocate a document — update_doc does not change the location.",
467
467
  inputSchema: {
468
468
  type: "object",
469
469
  properties: {
@@ -499,11 +499,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
499
499
  },
500
500
  {
501
501
  name: "set_project",
502
- description: "Switch the active project for the GUI display. This does NOT affect MCP tool operations — tools work across all projects automatically. Use only to control what the graphical interface shows.",
502
+ description: "Switch the active project and update it as the default for all subsequent MCP tool operations. If the project name does not exist yet, it is created automatically. Also controls what the GUI displays.",
503
503
  inputSchema: {
504
504
  type: "object",
505
505
  properties: {
506
- project: { type: "string", description: "Project name to switch to" },
506
+ project: { type: "string", description: "Project name to switch to (created if it does not exist)" },
507
507
  },
508
508
  required: ["project"],
509
509
  },
@@ -18,11 +18,15 @@ export async function moveDoc(storageEngine, embeddingEngine, args) {
18
18
  };
19
19
  }
20
20
  await embeddingEngine.moveEmbedding(validated.path, validated.new_path, resolvedProject);
21
+ const rewritten = await storageEngine.rewriteLinks(validated.path, validated.new_path, resolvedProject);
22
+ const rewriteNote = rewritten.length > 0
23
+ ? `\n\nLiens mis à jour automatiquement dans ${rewritten.length} doc(s) :\n${rewritten.map((id) => ` - ${id}`).join("\n")}`
24
+ : "\n\nAucune référence existante à mettre à jour.";
21
25
  return {
22
26
  content: [
23
27
  {
24
28
  type: "text",
25
- text: `Documentation entry moved successfully.\nFrom: "${validated.path}"\nTo: "${validated.new_path}"\n\nNote: if other documents reference "${validated.path}" in their related_docs or via doc:// links, use check_links to detect broken references.`,
29
+ text: `Documentation entry moved successfully.\nFrom: "${validated.path}"\nTo: "${validated.new_path}"${rewriteNote}`,
26
30
  },
27
31
  ],
28
32
  };
@@ -1 +1 @@
1
- export declare const APP_VERSION = "1.0.24";
1
+ export declare const APP_VERSION = "1.0.25";
@@ -1,2 +1,2 @@
1
1
  // Auto-generated version file - do not edit manually
2
- export const APP_VERSION = '1.0.24';
2
+ export const APP_VERSION = '1.0.25';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imenam/mcp-documentor",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "main": "dist/src/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",