index_local_project
Index a local project directory into a vector database to enable semantic code search and analysis across your codebase.
Instructions
Index a local project directory into the vector database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exclude_patterns | No | File patterns to exclude (optional) | |
| include_patterns | No | File patterns to include (optional) | |
| project_name | Yes | Name for the project (used as identifier) | |
| project_path | Yes | Absolute path to the local project directory |
Implementation Reference
- src/shared/CodeSearchEngine.ts:178-259 (handler)Core handler function for the 'index_local_project' tool. Validates input, traverses directory, processes files into chunks, generates embeddings, and stores them in ChromaDB.async indexLocalProject(args: { project_path: string; project_name: string; include_patterns?: string[]; exclude_patterns?: string[]; }) { const { project_path, project_name, include_patterns = this.getDefaultIncludePatterns(), exclude_patterns = this.getDefaultExcludePatterns() } = args; try { const stats = await fs.stat(project_path); if (!stats.isDirectory()) { throw new Error(`Path is not a directory: ${project_path}`); } } catch (error) { throw new Error(`Cannot access project path: ${project_path}`); } const projectId = this.sanitizeProjectId(project_name); try { const collection = await this.getOrCreateCollection(); const files = await this.getFilesToIndex(project_path, include_patterns, exclude_patterns); const chunks = []; let processedFiles = 0; for (const filePath of files) { try { const relativePath = path.relative(project_path, filePath); const fileExtension = path.extname(filePath).slice(1) || 'txt'; const fileStats = await fs.stat(filePath); const fileSizeMB = fileStats.size / (1024 * 1024); console.error(`Processing file: ${relativePath} (${fileSizeMB.toFixed(2)} MB)`); const fileChunks = await this.processFileWithStreaming(filePath, relativePath, fileExtension); if (fileChunks.length > 0) { chunks.push(...fileChunks.map(chunk => ({ ...chunk, project_id: projectId, project_name, project_path, source_type: 'local', indexed_at: new Date().toISOString() }))); } processedFiles++; } catch (error) { console.error(`Error processing file ${filePath}:`, error); } } if (chunks.length > 0) { await this.storeChunksInBatches(collection, chunks, projectId); } return { content: [ { type: "text", text: `Successfully indexed local project: ${project_name}\n` + `Project ID: ${projectId}\n` + `Project Path: ${project_path}\n` + `Files processed: ${processedFiles}\n` + `Chunks created: ${chunks.length}\n` + `Embedding provider: ${this.config.embedding_provider}` } ] }; } catch (error) { throw error; } }
- src/http-server.ts:207-232 (schema)Input schema definition for the index_local_project tool, used in tool listing for HTTP server.name: "index_local_project", description: "Index a local project directory into the vector database", inputSchema: { type: "object", properties: { project_path: { type: "string", description: "Absolute path to the local project directory" }, project_name: { type: "string", description: "Name for the project (used as identifier)" }, include_patterns: { type: "array", items: { type: "string" }, description: "File patterns to include (optional)" }, exclude_patterns: { type: "array", items: { type: "string" }, description: "File patterns to exclude (optional)" } }, required: ["project_path", "project_name"] }
- src/http-server.ts:256-257 (registration)Tool registration/dispatch in HTTP server's callTool switch statement.case "index_local_project": return await this.indexLocalProject(args);
- src/index.ts:112-113 (registration)Tool registration/dispatch in stdio server's CallToolRequestSchema handler.case "index_local_project": return await this.indexLocalProject(args as any);
- src/index.ts:37-62 (schema)Input schema definition for the index_local_project tool, used in tool listing for stdio server.name: "index_local_project", description: "Index a local project directory into the vector database", inputSchema: { type: "object", properties: { project_path: { type: "string", description: "Absolute path to the local project directory" }, project_name: { type: "string", description: "Name for the project (used as identifier)" }, include_patterns: { type: "array", items: { type: "string" }, description: "File patterns to include (optional)" }, exclude_patterns: { type: "array", items: { type: "string" }, description: "File patterns to exclude (optional)" } }, required: ["project_path", "project_name"] }