@mhalder/qdrant-mcp-server 1.4.0 → 1.5.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.
Files changed (82) hide show
  1. package/.codecov.yml +16 -0
  2. package/CHANGELOG.md +18 -0
  3. package/README.md +236 -9
  4. package/build/code/chunker/base.d.ts +19 -0
  5. package/build/code/chunker/base.d.ts.map +1 -0
  6. package/build/code/chunker/base.js +5 -0
  7. package/build/code/chunker/base.js.map +1 -0
  8. package/build/code/chunker/character-chunker.d.ts +22 -0
  9. package/build/code/chunker/character-chunker.d.ts.map +1 -0
  10. package/build/code/chunker/character-chunker.js +111 -0
  11. package/build/code/chunker/character-chunker.js.map +1 -0
  12. package/build/code/chunker/tree-sitter-chunker.d.ts +29 -0
  13. package/build/code/chunker/tree-sitter-chunker.d.ts.map +1 -0
  14. package/build/code/chunker/tree-sitter-chunker.js +213 -0
  15. package/build/code/chunker/tree-sitter-chunker.js.map +1 -0
  16. package/build/code/config.d.ts +11 -0
  17. package/build/code/config.d.ts.map +1 -0
  18. package/build/code/config.js +145 -0
  19. package/build/code/config.js.map +1 -0
  20. package/build/code/indexer.d.ts +42 -0
  21. package/build/code/indexer.d.ts.map +1 -0
  22. package/build/code/indexer.js +508 -0
  23. package/build/code/indexer.js.map +1 -0
  24. package/build/code/metadata.d.ts +32 -0
  25. package/build/code/metadata.d.ts.map +1 -0
  26. package/build/code/metadata.js +128 -0
  27. package/build/code/metadata.js.map +1 -0
  28. package/build/code/scanner.d.ts +35 -0
  29. package/build/code/scanner.d.ts.map +1 -0
  30. package/build/code/scanner.js +108 -0
  31. package/build/code/scanner.js.map +1 -0
  32. package/build/code/sync/merkle.d.ts +45 -0
  33. package/build/code/sync/merkle.d.ts.map +1 -0
  34. package/build/code/sync/merkle.js +116 -0
  35. package/build/code/sync/merkle.js.map +1 -0
  36. package/build/code/sync/snapshot.d.ts +41 -0
  37. package/build/code/sync/snapshot.d.ts.map +1 -0
  38. package/build/code/sync/snapshot.js +91 -0
  39. package/build/code/sync/snapshot.js.map +1 -0
  40. package/build/code/sync/synchronizer.d.ts +53 -0
  41. package/build/code/sync/synchronizer.d.ts.map +1 -0
  42. package/build/code/sync/synchronizer.js +132 -0
  43. package/build/code/sync/synchronizer.js.map +1 -0
  44. package/build/code/types.d.ts +98 -0
  45. package/build/code/types.d.ts.map +1 -0
  46. package/build/code/types.js +5 -0
  47. package/build/code/types.js.map +1 -0
  48. package/build/index.js +250 -0
  49. package/build/index.js.map +1 -1
  50. package/examples/code-search/README.md +271 -0
  51. package/package.json +13 -1
  52. package/src/code/chunker/base.ts +22 -0
  53. package/src/code/chunker/character-chunker.ts +131 -0
  54. package/src/code/chunker/tree-sitter-chunker.ts +250 -0
  55. package/src/code/config.ts +156 -0
  56. package/src/code/indexer.ts +613 -0
  57. package/src/code/metadata.ts +153 -0
  58. package/src/code/scanner.ts +124 -0
  59. package/src/code/sync/merkle.ts +136 -0
  60. package/src/code/sync/snapshot.ts +110 -0
  61. package/src/code/sync/synchronizer.ts +154 -0
  62. package/src/code/types.ts +117 -0
  63. package/src/index.ts +296 -0
  64. package/tests/code/chunker/character-chunker.test.ts +141 -0
  65. package/tests/code/chunker/tree-sitter-chunker.test.ts +275 -0
  66. package/tests/code/fixtures/sample-py/calculator.py +32 -0
  67. package/tests/code/fixtures/sample-ts/async-operations.ts +120 -0
  68. package/tests/code/fixtures/sample-ts/auth.ts +31 -0
  69. package/tests/code/fixtures/sample-ts/config.ts +52 -0
  70. package/tests/code/fixtures/sample-ts/database.ts +50 -0
  71. package/tests/code/fixtures/sample-ts/index.ts +39 -0
  72. package/tests/code/fixtures/sample-ts/types-advanced.ts +132 -0
  73. package/tests/code/fixtures/sample-ts/utils.ts +105 -0
  74. package/tests/code/fixtures/sample-ts/validator.ts +169 -0
  75. package/tests/code/indexer.test.ts +828 -0
  76. package/tests/code/integration.test.ts +708 -0
  77. package/tests/code/metadata.test.ts +457 -0
  78. package/tests/code/scanner.test.ts +131 -0
  79. package/tests/code/sync/merkle.test.ts +406 -0
  80. package/tests/code/sync/snapshot.test.ts +360 -0
  81. package/tests/code/sync/synchronizer.test.ts +501 -0
  82. package/vitest.config.ts +1 -0
@@ -0,0 +1,132 @@
1
+ /**
2
+ * FileSynchronizer - Manages incremental updates using Merkle trees
3
+ * Detects file changes and updates snapshots
4
+ */
5
+ import { createHash } from "node:crypto";
6
+ import { promises as fs } from "node:fs";
7
+ import { homedir } from "node:os";
8
+ import { join, relative } from "node:path";
9
+ import { MerkleTree } from "./merkle.js";
10
+ import { SnapshotManager } from "./snapshot.js";
11
+ export class FileSynchronizer {
12
+ codebasePath;
13
+ snapshotManager;
14
+ previousHashes = new Map();
15
+ previousTree = null;
16
+ constructor(codebasePath, collectionName) {
17
+ this.codebasePath = codebasePath;
18
+ // Store snapshots in ~/.qdrant-mcp/snapshots/
19
+ const snapshotDir = join(homedir(), ".qdrant-mcp", "snapshots");
20
+ const snapshotPath = join(snapshotDir, `${collectionName}.json`);
21
+ this.snapshotManager = new SnapshotManager(snapshotPath);
22
+ }
23
+ /**
24
+ * Initialize synchronizer by loading previous snapshot
25
+ */
26
+ async initialize() {
27
+ const snapshot = await this.snapshotManager.load();
28
+ if (snapshot) {
29
+ this.previousHashes = snapshot.fileHashes;
30
+ this.previousTree = snapshot.merkleTree;
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+ /**
36
+ * Compute hash for a file's content
37
+ */
38
+ async hashFile(filePath) {
39
+ try {
40
+ // Resolve path relative to codebase if not absolute
41
+ const absolutePath = filePath.startsWith(this.codebasePath)
42
+ ? filePath
43
+ : join(this.codebasePath, filePath);
44
+ const content = await fs.readFile(absolutePath, "utf-8");
45
+ return createHash("sha256").update(content).digest("hex");
46
+ }
47
+ catch (_error) {
48
+ // If file can't be read, return empty hash
49
+ return "";
50
+ }
51
+ }
52
+ /**
53
+ * Compute hashes for all files
54
+ */
55
+ async computeFileHashes(filePaths) {
56
+ const fileHashes = new Map();
57
+ for (const filePath of filePaths) {
58
+ const hash = await this.hashFile(filePath);
59
+ if (hash) {
60
+ // Normalize to relative path
61
+ const relativePath = filePath.startsWith(this.codebasePath)
62
+ ? relative(this.codebasePath, filePath)
63
+ : filePath;
64
+ fileHashes.set(relativePath, hash);
65
+ }
66
+ }
67
+ return fileHashes;
68
+ }
69
+ /**
70
+ * Detect changes since last snapshot
71
+ */
72
+ async detectChanges(currentFiles) {
73
+ // Compute current hashes
74
+ const currentHashes = await this.computeFileHashes(currentFiles);
75
+ // Compare with previous snapshot
76
+ const changes = MerkleTree.compare(this.previousHashes, currentHashes);
77
+ return changes;
78
+ }
79
+ /**
80
+ * Update snapshot with current state
81
+ */
82
+ async updateSnapshot(files) {
83
+ const fileHashes = await this.computeFileHashes(files);
84
+ const tree = new MerkleTree();
85
+ tree.build(fileHashes);
86
+ await this.snapshotManager.save(this.codebasePath, fileHashes, tree);
87
+ // Update internal state
88
+ this.previousHashes = fileHashes;
89
+ this.previousTree = tree;
90
+ }
91
+ /**
92
+ * Delete snapshot
93
+ */
94
+ async deleteSnapshot() {
95
+ await this.snapshotManager.delete();
96
+ this.previousHashes.clear();
97
+ this.previousTree = null;
98
+ }
99
+ /**
100
+ * Check if snapshot exists
101
+ */
102
+ async hasSnapshot() {
103
+ return this.snapshotManager.exists();
104
+ }
105
+ /**
106
+ * Validate snapshot integrity
107
+ */
108
+ async validateSnapshot() {
109
+ return this.snapshotManager.validate();
110
+ }
111
+ /**
112
+ * Get snapshot age in milliseconds
113
+ */
114
+ async getSnapshotAge() {
115
+ const snapshot = await this.snapshotManager.load();
116
+ if (!snapshot)
117
+ return null;
118
+ return Date.now() - snapshot.timestamp;
119
+ }
120
+ /**
121
+ * Quick check if re-indexing is needed (compare root hashes)
122
+ */
123
+ async needsReindex(currentFiles) {
124
+ if (!this.previousTree)
125
+ return true;
126
+ const currentHashes = await this.computeFileHashes(currentFiles);
127
+ const currentTree = new MerkleTree();
128
+ currentTree.build(currentHashes);
129
+ return this.previousTree.getRootHash() !== currentTree.getRootHash();
130
+ }
131
+ }
132
+ //# sourceMappingURL=synchronizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synchronizer.js","sourceRoot":"","sources":["../../../src/code/sync/synchronizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,OAAO,gBAAgB;IAMjB;IALF,eAAe,CAAkB;IACjC,cAAc,GAAwB,IAAI,GAAG,EAAE,CAAC;IAChD,YAAY,GAAsB,IAAI,CAAC;IAE/C,YACU,YAAoB,EAC5B,cAAsB;QADd,iBAAY,GAAZ,YAAY,CAAQ;QAG5B,8CAA8C;QAC9C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;QAChE,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,cAAc,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QAEnD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,UAAU,CAAC;YAC1C,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,UAAU,CAAC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC;QA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Q,CAAC,SAAS,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,YAAsB;QACvC,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;QAEpC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QACjE,MAAM,WAAW,GAAG,IAAI,UAAU,EAAE,CAAC;QACrC,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAEjC,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Type definitions for code vectorization module
3
+ */
4
+ export interface CodeConfig {
5
+ chunkSize: number;
6
+ chunkOverlap: number;
7
+ enableASTChunking: boolean;
8
+ supportedExtensions: string[];
9
+ ignorePatterns: string[];
10
+ customExtensions?: string[];
11
+ customIgnorePatterns?: string[];
12
+ batchSize: number;
13
+ maxChunksPerFile?: number;
14
+ maxTotalChunks?: number;
15
+ defaultSearchLimit: number;
16
+ enableHybridSearch: boolean;
17
+ }
18
+ export interface ScannerConfig {
19
+ supportedExtensions: string[];
20
+ ignorePatterns: string[];
21
+ customIgnorePatterns?: string[];
22
+ }
23
+ export interface ChunkerConfig {
24
+ chunkSize: number;
25
+ chunkOverlap: number;
26
+ maxChunkSize: number;
27
+ }
28
+ export interface IndexOptions {
29
+ forceReindex?: boolean;
30
+ extensions?: string[];
31
+ ignorePatterns?: string[];
32
+ }
33
+ export interface IndexStats {
34
+ filesScanned: number;
35
+ filesIndexed: number;
36
+ chunksCreated: number;
37
+ durationMs: number;
38
+ status: "completed" | "partial" | "failed";
39
+ errors?: string[];
40
+ }
41
+ export interface ChangeStats {
42
+ filesAdded: number;
43
+ filesModified: number;
44
+ filesDeleted: number;
45
+ chunksAdded: number;
46
+ chunksDeleted: number;
47
+ durationMs: number;
48
+ }
49
+ export interface CodeSearchResult {
50
+ content: string;
51
+ filePath: string;
52
+ startLine: number;
53
+ endLine: number;
54
+ language: string;
55
+ score: number;
56
+ fileExtension: string;
57
+ }
58
+ export interface SearchOptions {
59
+ limit?: number;
60
+ useHybrid?: boolean;
61
+ fileTypes?: string[];
62
+ pathPattern?: string;
63
+ scoreThreshold?: number;
64
+ }
65
+ export interface IndexStatus {
66
+ isIndexed: boolean;
67
+ collectionName?: string;
68
+ filesCount?: number;
69
+ chunksCount?: number;
70
+ lastUpdated?: Date;
71
+ languages?: string[];
72
+ }
73
+ export type ProgressCallback = (progress: ProgressUpdate) => void;
74
+ export interface ProgressUpdate {
75
+ phase: "scanning" | "chunking" | "embedding" | "storing";
76
+ current: number;
77
+ total: number;
78
+ percentage: number;
79
+ message: string;
80
+ }
81
+ export interface CodeChunk {
82
+ content: string;
83
+ startLine: number;
84
+ endLine: number;
85
+ metadata: {
86
+ filePath: string;
87
+ language: string;
88
+ chunkIndex: number;
89
+ chunkType?: "function" | "class" | "interface" | "block";
90
+ name?: string;
91
+ };
92
+ }
93
+ export interface FileChanges {
94
+ added: string[];
95
+ modified: string[];
96
+ deleted: string[];
97
+ }
98
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/code/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IAEzB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;IAG3B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EA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,0 +1,5 @@
1
+ /**
2
+ * Type definitions for code vectorization module
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/code/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/build/index.js CHANGED
@@ -9,6 +9,8 @@ import { CallToolRequestSchema, GetPromptRequestSchema, ListPromptsRequestSchema
9
9
  import Bottleneck from "bottleneck";
10
10
  import express from "express";
11
11
  import { z } from "zod";
12
+ import { DEFAULT_BATCH_SIZE, DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE, DEFAULT_CODE_EXTENSIONS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SEARCH_LIMIT, } from "./code/config.js";
13
+ import { CodeIndexer } from "./code/indexer.js";
12
14
  import { EmbeddingProviderFactory } from "./embeddings/factory.js";
13
15
  import { BM25SparseVectorGenerator } from "./embeddings/sparse.js";
14
16
  import { getPrompt, listPrompts, loadPromptsConfig } from "./prompts/index.js";
@@ -116,6 +118,18 @@ async function checkOllamaAvailability() {
116
118
  // Initialize clients
117
119
  const qdrant = new QdrantManager(QDRANT_URL);
118
120
  const embeddings = EmbeddingProviderFactory.createFromEnv();
121
+ // Initialize code indexer
122
+ const codeConfig = {
123
+ chunkSize: parseInt(process.env.CODE_CHUNK_SIZE || String(DEFAULT_CHUNK_SIZE), 10),
124
+ chunkOverlap: parseInt(process.env.CODE_CHUNK_OVERLAP || String(DEFAULT_CHUNK_OVERLAP), 10),
125
+ enableASTChunking: process.env.CODE_ENABLE_AST !== "false",
126
+ supportedExtensions: DEFAULT_CODE_EXTENSIONS,
127
+ ignorePatterns: DEFAULT_IGNORE_PATTERNS,
128
+ batchSize: parseInt(process.env.CODE_BATCH_SIZE || String(DEFAULT_BATCH_SIZE), 10),
129
+ defaultSearchLimit: parseInt(process.env.CODE_SEARCH_LIMIT || String(DEFAULT_SEARCH_LIMIT), 10),
130
+ enableHybridSearch: process.env.CODE_ENABLE_HYBRID === "true",
131
+ };
132
+ const codeIndexer = new CodeIndexer(qdrant, embeddings, codeConfig);
119
133
  // Load prompts configuration if file exists
120
134
  let promptsConfig = null;
121
135
  if (existsSync(PROMPTS_CONFIG_FILE)) {
@@ -322,6 +336,107 @@ function registerHandlers(server) {
322
336
  required: ["collection", "query"],
323
337
  },
324
338
  },
339
+ {
340
+ name: "index_codebase",
341
+ description: "Index a codebase for semantic code search. Automatically discovers files, chunks code intelligently using AST-aware parsing, and stores in vector database. Respects .gitignore and other ignore files.",
342
+ inputSchema: {
343
+ type: "object",
344
+ properties: {
345
+ path: {
346
+ type: "string",
347
+ description: "Absolute or relative path to codebase root directory",
348
+ },
349
+ forceReindex: {
350
+ type: "boolean",
351
+ description: "Force full re-index even if already indexed (default: false)",
352
+ },
353
+ extensions: {
354
+ type: "array",
355
+ items: { type: "string" },
356
+ description: "Custom file extensions to index (e.g., ['.proto', '.graphql'])",
357
+ },
358
+ ignorePatterns: {
359
+ type: "array",
360
+ items: { type: "string" },
361
+ description: "Additional patterns to ignore (e.g., ['**/test/**', '**/*.test.ts'])",
362
+ },
363
+ },
364
+ required: ["path"],
365
+ },
366
+ },
367
+ {
368
+ name: "search_code",
369
+ description: "Search indexed codebase using natural language queries. Returns semantically relevant code chunks with file paths and line numbers.",
370
+ inputSchema: {
371
+ type: "object",
372
+ properties: {
373
+ path: {
374
+ type: "string",
375
+ description: "Path to codebase (must be indexed first)",
376
+ },
377
+ query: {
378
+ type: "string",
379
+ description: "Natural language search query (e.g., 'authentication logic')",
380
+ },
381
+ limit: {
382
+ type: "number",
383
+ description: "Maximum number of results (default: 5, max: 100)",
384
+ },
385
+ fileTypes: {
386
+ type: "array",
387
+ items: { type: "string" },
388
+ description: "Filter by file extensions (e.g., ['.ts', '.py'])",
389
+ },
390
+ pathPattern: {
391
+ type: "string",
392
+ description: "Filter by path glob pattern (e.g., 'src/services/**')",
393
+ },
394
+ },
395
+ required: ["path", "query"],
396
+ },
397
+ },
398
+ {
399
+ name: "reindex_changes",
400
+ description: "Incrementally re-index only changed files. Detects added, modified, and deleted files since last index. Requires previous indexing with index_codebase.",
401
+ inputSchema: {
402
+ type: "object",
403
+ properties: {
404
+ path: {
405
+ type: "string",
406
+ description: "Path to codebase",
407
+ },
408
+ },
409
+ required: ["path"],
410
+ },
411
+ },
412
+ {
413
+ name: "get_index_status",
414
+ description: "Get indexing status and statistics for a codebase.",
415
+ inputSchema: {
416
+ type: "object",
417
+ properties: {
418
+ path: {
419
+ type: "string",
420
+ description: "Path to codebase",
421
+ },
422
+ },
423
+ required: ["path"],
424
+ },
425
+ },
426
+ {
427
+ name: "clear_index",
428
+ description: "Delete all indexed data for a codebase. This is irreversible and will remove the entire collection.",
429
+ inputSchema: {
430
+ type: "object",
431
+ properties: {
432
+ path: {
433
+ type: "string",
434
+ description: "Path to codebase",
435
+ },
436
+ },
437
+ required: ["path"],
438
+ },
439
+ },
325
440
  ],
326
441
  };
327
442
  });
@@ -521,6 +636,141 @@ function registerHandlers(server) {
521
636
  ],
522
637
  };
523
638
  }
639
+ case "index_codebase": {
640
+ const IndexCodebaseSchema = z.object({
641
+ path: z.string(),
642
+ forceReindex: z.boolean().optional(),
643
+ extensions: z.array(z.string()).optional(),
644
+ ignorePatterns: z.array(z.string()).optional(),
645
+ });
646
+ const { path, forceReindex, extensions, ignorePatterns } = IndexCodebaseSchema.parse(args);
647
+ const stats = await codeIndexer.indexCodebase(path, { forceReindex, extensions, ignorePatterns }, (progress) => {
648
+ // Progress callback - could send progress updates via SSE in future
649
+ console.error(`[${progress.phase}] ${progress.percentage}% - ${progress.message}`);
650
+ });
651
+ let statusMessage = `Indexed ${stats.filesIndexed}/${stats.filesScanned} files (${stats.chunksCreated} chunks) in ${(stats.durationMs / 1000).toFixed(1)}s`;
652
+ if (stats.status === "partial") {
653
+ statusMessage += `\n\nWarnings:\n${stats.errors?.join("\n")}`;
654
+ }
655
+ else if (stats.status === "failed") {
656
+ statusMessage = `Indexing failed:\n${stats.errors?.join("\n")}`;
657
+ }
658
+ return {
659
+ content: [
660
+ {
661
+ type: "text",
662
+ text: statusMessage,
663
+ },
664
+ ],
665
+ isError: stats.status === "failed",
666
+ };
667
+ }
668
+ case "search_code": {
669
+ const SearchCodeSchema = z.object({
670
+ path: z.string(),
671
+ query: z.string(),
672
+ limit: z.number().optional(),
673
+ fileTypes: z.array(z.string()).optional(),
674
+ pathPattern: z.string().optional(),
675
+ });
676
+ const { path, query, limit, fileTypes, pathPattern } = SearchCodeSchema.parse(args);
677
+ const results = await codeIndexer.searchCode(path, query, {
678
+ limit,
679
+ fileTypes,
680
+ pathPattern,
681
+ });
682
+ if (results.length === 0) {
683
+ return {
684
+ content: [
685
+ {
686
+ type: "text",
687
+ text: `No results found for query: "${query}"`,
688
+ },
689
+ ],
690
+ };
691
+ }
692
+ // Format results with file references
693
+ const formattedResults = results
694
+ .map((r, idx) => `\n--- Result ${idx + 1} (score: ${r.score.toFixed(3)}) ---\n` +
695
+ `File: ${r.filePath}:${r.startLine}-${r.endLine}\n` +
696
+ `Language: ${r.language}\n\n` +
697
+ `${r.content}\n`)
698
+ .join("\n");
699
+ return {
700
+ content: [
701
+ {
702
+ type: "text",
703
+ text: `Found ${results.length} result(s):\n${formattedResults}`,
704
+ },
705
+ ],
706
+ };
707
+ }
708
+ case "get_index_status": {
709
+ const GetIndexStatusSchema = z.object({
710
+ path: z.string(),
711
+ });
712
+ const { path } = GetIndexStatusSchema.parse(args);
713
+ const status = await codeIndexer.getIndexStatus(path);
714
+ if (!status.isIndexed) {
715
+ return {
716
+ content: [
717
+ {
718
+ type: "text",
719
+ text: `Codebase at "${path}" is not indexed. Use index_codebase to index it first.`,
720
+ },
721
+ ],
722
+ };
723
+ }
724
+ return {
725
+ content: [
726
+ {
727
+ type: "text",
728
+ text: JSON.stringify(status, null, 2),
729
+ },
730
+ ],
731
+ };
732
+ }
733
+ case "reindex_changes": {
734
+ const ReindexChangesSchema = z.object({
735
+ path: z.string(),
736
+ });
737
+ const { path } = ReindexChangesSchema.parse(args);
738
+ const stats = await codeIndexer.reindexChanges(path, (progress) => {
739
+ console.error(`[${progress.phase}] ${progress.percentage}% - ${progress.message}`);
740
+ });
741
+ let message = `Incremental re-index complete:\n`;
742
+ message += `- Files added: ${stats.filesAdded}\n`;
743
+ message += `- Files modified: ${stats.filesModified}\n`;
744
+ message += `- Files deleted: ${stats.filesDeleted}\n`;
745
+ message += `- Chunks added: ${stats.chunksAdded}\n`;
746
+ message += `- Duration: ${(stats.durationMs / 1000).toFixed(1)}s`;
747
+ if (stats.filesAdded === 0 && stats.filesModified === 0 && stats.filesDeleted === 0) {
748
+ message = `No changes detected. Codebase is up to date.`;
749
+ }
750
+ return {
751
+ content: [
752
+ {
753
+ type: "text",
754
+ text: message,
755
+ },
756
+ ],
757
+ };
758
+ }
759
+ case "clear_index": {
760
+ const ClearIndexSchema = z.object({
761
+ path: z.string(),
762
+ });
763
+ const { path } = ClearIndexSchema.parse(args);
764
+ await codeIndexer.clearIndex(path);
765
+ return {
766
+ content: [
767
+ {
768
+ type: "text",
769
+ text: `Index cleared for codebase at "${path}".`,
770
+ },
771
+ ],
772
+ };
773
+ }
524
774
  default:
525
775
  return {
526
776
  content: [