Skip to main content
Glama

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
NameRequiredDescriptionDefault
filesYesFiles 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 }> }) => {
  • 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" }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xjcf/MCP_CodeAnalysis'

If you have feedback or need assistance with the MCP directory API, please join our Discord server