search_codebase
Search enterprise codebases using semantic AI to find relevant code snippets across local projects and Git repositories based on natural language queries.
Instructions
Search the indexed codebase using semantic search
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results | |
| project_filter | No | Filter by specific project name | |
| query | Yes | Search query |
Implementation Reference
- src/shared/CodeSearchEngine.ts:261-313 (handler)The core handler function that executes the 'search_codebase' tool. Performs semantic search query on ChromaDB vector store, handles project filtering, formats results with similarity scores, file metadata, and code snippets in Markdown.async searchCodebase(args: { query: string; limit?: number; project_filter?: string; }) { const { query, limit = 10, project_filter } = args; const collection = await this.getOrCreateCollection(); let whereClause: any = {}; if (project_filter) { whereClause.project_id = { "$eq": project_filter }; } const results = await collection.query({ queryTexts: [query], nResults: limit, where: Object.keys(whereClause).length > 0 ? whereClause : undefined }); if (!results.documents[0] || results.documents[0].length === 0) { return { content: [ { type: "text", text: "No results found for your query." } ] }; } const formattedResults = results.documents[0] .map((doc, i) => { const metadata = results.metadatas?.[0]?.[i] as any; const distance = results.distances?.[0]?.[i] || 0; const similarity = (1 - distance).toFixed(3); return `## Result ${i + 1} (Similarity: ${similarity})\n` + `**File:** ${metadata?.file_path}\n` + `**Project:** ${metadata?.project_name}\n\n` + `\`\`\`${metadata?.file_type}\n${doc}\n\`\`\`\n`; }) .join('\n---\n\n'); return { content: [ { type: "text", text: `Found ${results.documents[0].length} results for: "${query}"\n\n${formattedResults}` } ] }; }
- src/index.ts:67-85 (schema)Input schema definition for the 'search_codebase' tool, specifying parameters: query (required string), limit (optional number, default 10), project_filter (optional string).inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query" }, limit: { type: "number", description: "Maximum number of results", default: 10 }, project_filter: { type: "string", description: "Filter by specific project name" } }, required: ["query"] }
- src/index.ts:64-86 (registration)Registration of the 'search_codebase' tool in the ListTools response, including name, description, and input schema.{ name: "search_codebase", description: "Search the indexed codebase using semantic search", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query" }, limit: { type: "number", description: "Maximum number of results", default: 10 }, project_filter: { type: "string", description: "Filter by specific project name" } }, required: ["query"] } },
- src/index.ts:114-115 (registration)Dispatch/registration in the CallToolRequestSchema handler switch statement, routing tool calls to the searchCodebase method.case "search_codebase": return await this.searchCodebase(args as any);