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[]; }; }

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