Skip to main content
Glama

analyze_project

Analyze project structure, code quality, and architecture to help AI understand existing projects by examining directories, files, and content.

Instructions

【项目分析】深度分析项目结构、代码质量和架构,帮助AI快速理解老项目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathNo项目路径(默认当前目录)
max_depthNo目录树最大深度(默认 5)
include_contentNo是否包含文件内容(默认 true)

Implementation Reference

  • The core handler function for the 'analyze_project' tool. It takes arguments like project_path, max_depth, and include_content, performs analysis, and returns a structured Markdown report with project structure, directory tree, key files, dependencies, code metrics, architecture, and summary.
    export async function analyzeProject(args: any): Promise<any> {
      const projectPath = args.project_path || process.cwd();
      const maxDepth = args.max_depth || 5;
      const includeContent = args.include_content !== false;
    
      try {
        console.error(`开始分析项目: ${projectPath}`);
        const analysis = await performProjectAnalysis(projectPath, maxDepth, includeContent);
        
        return {
          content: [
            {
              type: "text",
              text: `# 📊 项目分析报告
    
    ## 🏗️ 项目概览
    - **项目名称**: ${analysis.projectStructure.name}
    - **项目类型**: ${analysis.projectStructure.type}
    - **技术栈**: ${analysis.projectStructure.framework}
    - **主要语言**: ${analysis.projectStructure.language}
    - **包管理器**: ${analysis.projectStructure.packageManager}
    
    ## 📁 目录结构
    \`\`\`
    ${analysis.directoryTree}
    \`\`\`
    
    ## 🔑 关键文件
    ${analysis.keyFiles.map(file => 
      `### ${file.path}
    **用途**: ${file.purpose}
    ${includeContent ? `\`\`\`${getFileExtension(file.path)}
    ${file.content.substring(0, 500)}${file.content.length > 500 ? '\n...' : ''}
    \`\`\`` : ''}`).join('\n\n')}
    
    ## 📦 依赖分析
    - **生产依赖**: ${analysis.dependencies.production.length} 个
    - **开发依赖**: ${analysis.dependencies.development.length} 个
    - **总依赖数**: ${analysis.dependencies.total} 个
    
    ### 主要依赖
    ${analysis.dependencies.production.slice(0, 10).map(dep => `- ${dep}`).join('\n')}
    
    ## 📈 代码指标
    - **总文件数**: ${analysis.codeMetrics.totalFiles}
    - **总行数**: ${analysis.codeMetrics.totalLines}
    ${analysis.codeMetrics.skippedFiles > 0 ? `- **跳过文件**: ${analysis.codeMetrics.skippedFiles} 个(过大或无法读取)` : ''}
    - **文件类型分布**:
    ${Object.entries(analysis.codeMetrics.fileTypes)
      .sort(([, a], [, b]) => (b as number) - (a as number))
      .slice(0, 10)
      .map(([type, count]) => `  - ${type}: ${count} 个文件`)
      .join('\n')}
    ${Object.keys(analysis.codeMetrics.fileTypes).length > 10 ? '  - ... (更多类型已省略)' : ''}
    
    ### 最大文件
    ${analysis.codeMetrics.largestFiles.slice(0, 5).map(file => 
      `- ${file.path} (${file.lines} 行)`
    ).join('\n')}
    
    ## 🏛️ 架构分析
    - **设计模式**: ${analysis.architecture.patterns.join(', ')}
    - **入口文件**: ${analysis.architecture.entryPoints.join(', ')}
    - **核心模块**: ${analysis.architecture.mainModules.join(', ')}
    
    ## 📋 项目总结
    **项目目的**: ${analysis.summary.purpose}
    **复杂度**: ${analysis.summary.complexity}
    **建议**: 
    ${analysis.summary.recommendations.map(rec => `- ${rec}`).join('\n')}
    
    ---
    *分析完成时间: ${new Date().toLocaleString('zh-CN')}*
    *分析工具: MCP Probe Kit v${VERSION}*
    
    **分析说明**:
    - 大型项目会自动采样分析,限制最多扫描 5000 个文件
    - 已自动忽略以下目录: \`node_modules\`, \`dist\`, \`build\`, \`.git\`, \`coverage\`, \`.next\`, \`.nuxt\`, \`vendor\` 等
    - 单个文件大小限制: 1MB,超过则跳过`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `❌ 项目分析失败: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Tool registration in ListToolsRequestSchema handler, including the input schema defining parameters for project_path, max_depth, and include_content.
    {
      name: "analyze_project",
      description: "【项目分析】深度分析项目结构、代码质量和架构,帮助AI快速理解老项目",
      inputSchema: {
        type: "object",
        properties: {
          project_path: {
            type: "string",
            description: "项目路径(默认当前目录)",
          },
          max_depth: {
            type: "number",
            description: "目录树最大深度(默认 5)",
          },
          include_content: {
            type: "boolean",
            description: "是否包含文件内容(默认 true)",
          },
        },
        required: [],
      },
    },
  • src/index.ts:525-527 (registration)
    Registration and dispatch logic in the CallToolRequestSchema switch statement, invoking the analyzeProject handler.
    case "analyze_project":
      return await analyzeProject(args);
  • Re-export of the analyzeProject function from its implementation module, making it available for import in src/index.ts.
    export { analyzeProject } from "./analyze_project.js";
  • TypeScript interface defining the internal structure of the project analysis result, used for output validation and typing.
    interface ProjectAnalysis {
      projectStructure: {
        name: string;
        type: string;
        framework: string;
        language: string;
        packageManager: string;
      };
      directoryTree: string;
      keyFiles: Array<{
        path: string;
        purpose: string;
        content: string;
      }>;
      dependencies: {
        production: string[];
        development: string[];
        total: number;
      };
      codeMetrics: {
        totalFiles: number;
        totalLines: number;
        fileTypes: Record<string, number>;
        largestFiles: Array<{
          path: string;
          lines: number;
        }>;
        skippedFiles: number;
      };
      architecture: {
        patterns: string[];
        entryPoints: string[];
        mainModules: string[];
      };
      summary: {
        purpose: string;
        complexity: 'low' | 'medium' | 'high';
        recommendations: string[];
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions '深度分析' (deep analysis) and '快速理解' (quick understanding), but lacks details on behavioral traits such as performance characteristics, output format, error handling, or any side effects. This is inadequate for a tool with no annotation coverage.

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 concise and front-loaded with the core purpose in a single sentence. It uses efficient language without unnecessary words, though the inclusion of '帮助AI快速理解老项目' (help AI quickly understand old projects) adds some context but could be integrated more tightly.

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 complexity of analyzing project structure and code quality, with no annotations and no output schema, the description is incomplete. It fails to explain what the analysis outputs (e.g., reports, metrics, summaries) or any prerequisites, making it insufficient for effective tool selection and invocation.

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?

The schema description coverage is 100%, so the schema already documents all three parameters with their types and default values. The description adds no additional meaning beyond what the schema provides, such as explaining how 'max_depth' affects analysis or what 'include_content' entails. Baseline 3 is appropriate as the schema does the heavy lifting.

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: '深度分析项目结构、代码质量和架构' (deeply analyze project structure, code quality, and architecture). It specifies the verb 'analyze' and resource 'project', though it doesn't explicitly differentiate from siblings like 'code_review' or 'refactor' which might have overlapping scopes.

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. It mentions '帮助AI快速理解老项目' (help AI quickly understand old projects), which implies a context for legacy projects, but doesn't specify exclusions or compare with siblings like 'explain' or 'check_deps' for similar analysis tasks.

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/mybolide/mcp-probe-kit'

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