analyze-files
Analyze code files to detect syntax issues, visualize dependencies, and support development workflows through comprehensive code analysis.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Files to analyze |
Implementation Reference
- Handler function that processes an array of files, calculates metrics for each using calculateMetrics helper, and returns a JSON-formatted text response with results.async (args: { files: Array<{ path: string; content: string }> }) => { const { files } = args; // Analyze each file const results = await Promise.all( files.map(async (file: { path: string; content: string }) => { const extension = path.extname(file.path).slice(1); const metrics = calculateMetrics(file.content, extension); return { file: path.basename(file.path), metrics }; }) ); return { content: [{ type: "text", text: JSON.stringify({ results }, null, 2) }] }; }
- Zod input schema defining the expected arguments: an array of objects each containing file path and content.{ files: z.array(z.object({ path: z.string().describe("Path to the file"), content: z.string().describe("Content of the file") })).describe("Files to analyze")
- src/features/basic-analysis/ide-analyzer.ts:58-89 (registration)MCP server tool registration for 'analyze-files', specifying input schema and handler function within registerIdeTools.server.tool( "analyze-files", { files: z.array(z.object({ path: z.string().describe("Path to the file"), content: z.string().describe("Content of the file") })).describe("Files to analyze") }, async (args: { files: Array<{ path: string; content: string }> }) => { const { files } = args; // Analyze each file const results = await Promise.all( files.map(async (file: { path: string; content: string }) => { const extension = path.extname(file.path).slice(1); const metrics = calculateMetrics(file.content, extension); return { file: path.basename(file.path), metrics }; }) ); return { content: [{ type: "text", text: JSON.stringify({ results }, null, 2) }] }; } );
- Supporting function called by the analyze-files handler to compute basic metrics (lines of code, complexity score, maintainability rating) for each file.function calculateMetrics( content: string, language: string ): { linesOfCode: number; complexity: number; maintainability: string; } { // This is a placeholder implementation // In a real implementation, you would calculate actual metrics const lines = content.split("\n"); return { linesOfCode: lines.length, complexity: Math.floor(lines.length / 10) + 1, maintainability: "medium" }; }