Skip to main content
Glama

analyze_readme

Analyzes README files to assess length, evaluate structure, and identify optimization opportunities for improved documentation quality.

Instructions

Comprehensive README analysis with length assessment, structure evaluation, and optimization opportunities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the project directory containing README
target_audienceNoTarget audience for analysiscommunity_contributors
optimization_levelNoLevel of optimization suggestionsmoderate
max_length_targetNoTarget maximum length in lines

Implementation Reference

  • The primary handler function `analyzeReadme` that implements the core logic for README analysis. It validates input, locates and reads the README, performs multi-dimensional analysis (length, structure, content, community readiness), computes scores, generates recommendations, and returns structured MCPToolResponse.
    export async function analyzeReadme(
      input: Partial<AnalyzeReadmeInput>,
    ): Promise<MCPToolResponse<{ analysis: ReadmeAnalysis; nextSteps: string[] }>> {
      const startTime = Date.now();
    
      try {
        // Validate input
        const validatedInput = AnalyzeReadmeInputSchema.parse(input);
        const {
          project_path,
          target_audience,
          optimization_level,
          max_length_target,
        } = validatedInput;
    
        // Find README file
        const readmePath = await findReadmeFile(project_path);
        if (!readmePath) {
          return {
            success: false,
            error: {
              code: "README_NOT_FOUND",
              message: "No README file found in the project directory",
              details:
                "Looked for README.md, README.txt, readme.md in project root",
              resolution: "Create a README.md file in the project root directory",
            },
            metadata: {
              toolVersion: "1.0.0",
              executionTime: Date.now() - startTime,
              timestamp: new Date().toISOString(),
            },
          };
        }
    
        // Read README content
        const readmeContent = await fs.readFile(readmePath, "utf-8");
    
        // Get project context
        const projectContext = await analyzeProjectContext(project_path);
    
        // Perform comprehensive analysis
        const lengthAnalysis = analyzeLengthMetrics(
          readmeContent,
          max_length_target,
        );
        const structureAnalysis = analyzeStructure(readmeContent);
        const contentAnalysis = analyzeContent(readmeContent);
        const communityReadiness = analyzeCommunityReadiness(
          readmeContent,
          projectContext,
        );
    
        // Generate optimization opportunities
        const optimizationOpportunities = generateOptimizationOpportunities(
          lengthAnalysis,
          structureAnalysis,
          contentAnalysis,
          communityReadiness,
          optimization_level,
          target_audience,
        );
    
        // Calculate overall score
        const overallScore = calculateOverallScore(
          lengthAnalysis,
          structureAnalysis,
          contentAnalysis,
          communityReadiness,
        );
    
        // Generate recommendations
        const recommendations = generateRecommendations(
          optimizationOpportunities,
          target_audience,
          optimization_level,
        );
    
        const analysis: ReadmeAnalysis = {
          lengthAnalysis,
          structureAnalysis,
          contentAnalysis,
          communityReadiness,
          optimizationOpportunities,
          overallScore,
          recommendations,
        };
    
        const nextSteps = generateNextSteps(analysis, optimization_level);
    
        return {
          success: true,
          data: {
            analysis,
            nextSteps,
          },
          metadata: {
            toolVersion: "1.0.0",
            executionTime: Date.now() - startTime,
            timestamp: new Date().toISOString(),
            analysisId: `readme-analysis-${Date.now()}`,
          },
        };
      } catch (error) {
        return {
          success: false,
          error: {
            code: "ANALYSIS_FAILED",
            message: "Failed to analyze README",
            details: error instanceof Error ? error.message : "Unknown error",
            resolution: "Check project path and README file accessibility",
          },
          metadata: {
            toolVersion: "1.0.0",
            executionTime: Date.now() - startTime,
            timestamp: new Date().toISOString(),
          },
        };
      }
    }
  • Zod input schema defining parameters for the analyze_readme tool: project_path (required), target_audience, optimization_level, and max_length_target.
    const AnalyzeReadmeInputSchema = z.object({
      project_path: z.string().min(1, "Project path is required"),
      target_audience: z
        .enum([
          "community_contributors",
          "enterprise_users",
          "developers",
          "general",
        ])
        .optional()
        .default("community_contributors"),
      optimization_level: z
        .enum(["light", "moderate", "aggressive"])
        .optional()
        .default("moderate"),
      max_length_target: z.number().min(50).max(1000).optional().default(300),
    });
  • Helper function to locate the README file by trying common naming conventions in the project root.
    async function findReadmeFile(projectPath: string): Promise<string | null> {
      const possibleNames = [
        "README.md",
        "README.txt",
        "readme.md",
        "Readme.md",
        "README",
      ];
    
      for (const name of possibleNames) {
        const filePath = path.join(projectPath, name);
        try {
          await fs.access(filePath);
          return filePath;
        } catch {
          continue;
        }
      }
    
      return null;
    }
  • Helper function that computes length metrics for the README content against target length.
    function analyzeLengthMetrics(content: string, targetLines: number) {
      const lines = content.split("\n");
      const words = content.split(/\s+/).length;
      const currentLines = lines.length;
    
      return {
        currentLines,
        currentWords: words,
        targetLines,
        exceedsTarget: currentLines > targetLines,
        reductionNeeded: Math.max(0, currentLines - targetLines),
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'analysis' and 'optimization opportunities' but does not specify whether this is a read-only operation, what permissions are needed, how results are returned, or any rate limits. This leaves significant gaps in understanding the tool's behavior and safety profile.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Comprehensive README analysis') and lists key components. It avoids redundancy and waste, though it could be slightly more structured by separating components with clearer formatting.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (analysis with multiple parameters) and lack of annotations and output schema, the description is insufficient. It does not explain what the analysis returns, how results are formatted, or any behavioral traits, making it incomplete for effective agent use without additional context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional meaning beyond the schema, such as explaining how parameters interact or affect analysis. This meets the baseline of 3, as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Comprehensive README analysis' with specific components: length assessment, structure evaluation, and optimization opportunities. It uses a specific verb ('analyze') and resource ('README'), but does not explicitly differentiate from sibling tools like 'evaluate_readme_health' or 'optimize_readme', which limits it to a 4 instead of a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'evaluate_readme_health' or 'optimize_readme' among the many sibling tools. It lacks context about prerequisites, scenarios, or exclusions, offering only a basic functional statement without usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/tosin2013/documcp'

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