analyze_repo
Analyze a code repository's structure by flattening it into a textual representation. Gain a high-level overview of code organization, directory structure, and file contents to understand the codebase before a detailed review or when a full review is unnecessary.
Instructions
Use this tool when you need to analyze a code repository structure without performing a detailed review. This tool flattens the repository into a textual representation and is ideal for getting a high-level overview of code organization, directory structure, and file contents. Use it before code_review when you need to understand the codebase structure first, or when a full code review is not needed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileTypes | No | File types to include in the analysis | |
| repoPath | Yes | Path to the repository to analyze | |
| specificFiles | No | Specific files to analyze |
Implementation Reference
- src/index.ts:45-53 (handler)Inline asynchronous handler function for the 'analyze_repo' MCP tool. Parses input parameters into RepomixOptions and invokes executeRepomix to perform repository structure analysis, returning the result as MCP content.async (params) => { const options: RepomixOptions = { includePaths: params.specificFiles, fileTypes: params.fileTypes, outputFormat: 'plain' }; const result = await executeRepomix(options); return { content: [{ type: 'text', text: `Analyzing repository: ${result}` }] };
- src/index.ts:34-38 (schema)Zod schema definition for 'analyze_repo' tool input parameters, including repoPath, optional specificFiles, and fileTypes.const analyzeRepoParams = { repoPath: z.string().describe('Path to the repository to analyze'), specificFiles: z.array(z.string()).optional().describe('Specific files to analyze'), fileTypes: z.array(z.string()).optional().describe('File types to include in the analysis') };
- src/index.ts:41-55 (registration)Registration of the 'analyze_repo' tool on the McpServer instance, specifying name, detailed description, input schema, and handler function.server.tool( 'analyze_repo', 'Use this tool when you need to analyze a code repository structure without performing a detailed review. This tool flattens the repository into a textual representation and is ideal for getting a high-level overview of code organization, directory structure, and file contents. Use it before code_review when you need to understand the codebase structure first, or when a full code review is not needed.', analyzeRepoParams, async (params) => { const options: RepomixOptions = { includePaths: params.specificFiles, fileTypes: params.fileTypes, outputFormat: 'plain' }; const result = await executeRepomix(options); return { content: [{ type: 'text', text: `Analyzing repository: ${result}` }] }; } );
- src/repomix.ts:58-105 (helper)Core helper function executeRepomix that runs the Repomix CLI tool with configurable options to flatten/analyze repository structure into text output. Called by the analyze_repo handler.export async function executeRepomix(options: RepomixOptions = {}): Promise<string> { console.log('Analyzing repository at', options, 'with Repomix...'); // In test environment or Bun test, return mock result if (process.env.NODE_ENV === 'test' || process.env.BUN_ENV === 'test') { console.log('Running in test mode, returning mock result'); return 'Repomix analysis completed'; } // The real implementation would call the Repomix CLI try { const execPromise = util.promisify(exec); const outputPath = path.join(process.cwd(), 'repomix-output.txt'); let command = 'repomix'; // Add style flag command += ' --style plain'; // Add include paths if (options.includePaths && options.includePaths.length > 0) { const paths = options.includePaths.join(' '); command += ` ${paths}`; } else { command += ' .'; } // Add output redirection command += ` && cat repomix-output.txt`; // Mock return in case running tests if (process.argv.includes('test')) { return 'Repomix analysis completed'; } const { stdout } = await execPromise(command); return stdout || outputPath; } catch (error) { console.error('Error executing Repomix:', error); // Mock return in case of error during tests if (process.argv.includes('test')) { return 'Repomix analysis completed'; } throw new Error(`Failed to execute Repomix: ${error}`); } }
- build/src/repomix.js:132-138 (handler)analyzeRepo function implementing full repo analysis: runs Repomix then sends output to LLM for code review. Dispatched to by 'analyze_repo' tool handler in build/src/index.js.export async function analyzeRepo(repoPath, options = {}, systemPrompt, userPrompt) { // Execute Repomix to get the flattened codebase const repomixOutputPath = await executeRepomix(options); // Send the flattened codebase to an LLM for analysis const result = await sendToLLM(repomixOutputPath, systemPrompt || DEFAULT_SYSTEM_PROMPT, userPrompt || DEFAULT_USER_PROMPT); return result; }