analyze-files
Process and evaluate file content for syntax analysis and dependency mapping, enabling enhanced code understanding and workflow optimization in development projects.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Files to analyze |
Implementation Reference
- The main handler function for the 'analyze-files' tool that processes an array of files, computes metrics for each using the calculateMetrics helper, and returns a JSON-formatted result.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 parameters: an array of objects each with 'path' and 'content' for the files to analyze.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 }> }) => {
- src/features/basic-analysis/ide-analyzer.ts:58-90 (registration)Registration of the 'analyze-files' tool on the McpServer using server.tool(), specifying name, input schema, and handler function.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) }] }; } ); }
- Helper function to calculate basic metrics (lines of code, complexity, maintainability) for a given file content and language, used within the tool handler.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" }; }