analyze_dependencies
Analyze project dependencies to identify unused packages, outdated versions, and security vulnerabilities for improved code quality and maintenance.
Instructions
Analyze project dependencies including unused, outdated, and vulnerable packages
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | No | Path to project root (defaults to current directory) | |
| checkUnused | No | Check for unused dependencies | |
| checkOutdated | No | Check for outdated packages | |
| checkVulnerabilities | No | Check for security vulnerabilities | |
| checkBundleSize | No | Check bundle size |
Implementation Reference
- Core handler function implementing the logic to analyze project dependencies by parsing package.json and performing optional checks for unused deps, outdated packages, and vulnerabilities.async analyzeDependencies( projectPath: string = process.cwd(), options?: DependencyAnalysisOptions ): Promise<DependencyReport> { const packageJsonPath = join(projectPath, 'package.json'); if (!existsSync(packageJsonPath)) { throw new Error('package.json not found'); } const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); const dependencies = this.extractDependencies(packageJson); const report: DependencyReport = { dependencies, unused: options?.checkUnused !== false ? await this.findUnusedDependencies(projectPath) : [], outdated: options?.checkOutdated !== false ? await this.findOutdatedPackages(packageJson) : [], vulnerabilities: options?.checkVulnerabilities !== false ? await this.findVulnerabilities(projectPath) : [], totalDependencies: dependencies.length, }; return report; }
- src/tools/dependency-analysis.ts:113-122 (handler)Tool-specific handler case within handleDependencyAnalysisTool that parses input arguments and invokes the core analyzer.case 'analyze_dependencies': { const options: DependencyAnalysisOptions = { checkUnused: params.checkUnused as boolean, checkOutdated: params.checkOutdated as boolean, checkVulnerabilities: params.checkVulnerabilities as boolean, checkBundleSize: params.checkBundleSize as boolean, }; const report = await analyzer.analyzeDependencies(projectPath, options); return Formatters.formatDependencyReport(report); }
- JSON Schema defining the input parameters for the analyze_dependencies tool.inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Path to project root (defaults to current directory)', }, checkUnused: { type: 'boolean', description: 'Check for unused dependencies', default: true, }, checkOutdated: { type: 'boolean', description: 'Check for outdated packages', default: true, }, checkVulnerabilities: { type: 'boolean', description: 'Check for security vulnerabilities', default: true, }, checkBundleSize: { type: 'boolean', description: 'Check bundle size', default: false, }, }, },
- src/tools/dependency-analysis.ts:7-39 (registration)Tool registration object defining name, description, and schema, exported as part of dependencyAnalysisTools array.{ name: 'analyze_dependencies', description: 'Analyze project dependencies including unused, outdated, and vulnerable packages', inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Path to project root (defaults to current directory)', }, checkUnused: { type: 'boolean', description: 'Check for unused dependencies', default: true, }, checkOutdated: { type: 'boolean', description: 'Check for outdated packages', default: true, }, checkVulnerabilities: { type: 'boolean', description: 'Check for security vulnerabilities', default: true, }, checkBundleSize: { type: 'boolean', description: 'Check bundle size', default: false, }, }, }, },
- src/server.ts:66-67 (registration)Main server dispatch registration routing calls to analyze_dependencies to the appropriate handler.} else if (dependencyAnalysisTools.some((t) => t.name === name)) { result = await handleDependencyAnalysisTool(name, args || {});