analyze_dependencies
Analyze package.json files to identify and report project dependencies, including development dependencies when specified.
Instructions
프로젝트의 package.json을 분석하여 의존성 정보를 제공합니다.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | 분석할 프로젝트 경로 (package.json이 있는 디렉토리) | |
| includeDevDeps | No | 개발 의존성 포함 여부. 기본값: true |
Implementation Reference
- src/project-analyzer.ts:209-270 (handler)Core handler function that parses package.json to extract project name, version, description, production dependencies, optional devDependencies, and scripts.export function analyzeDependencies( targetPath: string, options: DependencyOptions = {} ): DependencyResult { const { includeDevDeps = true } = options; try { const packagePath = path.join(targetPath, "package.json"); if (!fs.existsSync(packagePath)) { return { success: false, error: `package.json을 찾을 수 없습니다: ${packagePath}`, }; } const content = fs.readFileSync(packagePath, "utf-8"); const pkg = JSON.parse(content); const result: DependencyResult = { success: true, name: pkg.name, version: pkg.version, description: pkg.description, }; // 프로덕션 의존성 if (pkg.dependencies) { result.dependencies = Object.entries(pkg.dependencies).map( ([name, version]) => ({ name, version: version as string, }) ); } // 개발 의존성 if (includeDevDeps && pkg.devDependencies) { result.devDependencies = Object.entries(pkg.devDependencies).map( ([name, version]) => ({ name, version: version as string, }) ); } // 스크립트 if (pkg.scripts) { result.scripts = Object.entries(pkg.scripts).map(([name, command]) => ({ name, command: command as string, })); } return result; } catch (err) { return { success: false, error: err instanceof Error ? err.message : String(err), }; } }
- src/index.ts:466-516 (registration)Registers the analyze_dependencies tool with the MCP server, including description, Zod input schema, and wrapper handler that formats the output.server.tool( "analyze_dependencies", "프로젝트의 package.json을 분석하여 의존성 정보를 제공합니다.", { path: z.string().describe("분석할 프로젝트 경로 (package.json이 있는 디렉토리)"), includeDevDeps: z .boolean() .optional() .describe("개발 의존성 포함 여부. 기본값: true"), }, async ({ path: targetPath, includeDevDeps }) => { const result = analyzeDependencies(targetPath, { includeDevDeps }); if (!result.success) { return { content: [{ type: "text", text: `오류: ${result.error}` }], isError: true, }; } let text = `📦 ${result.name} v${result.version}\n`; if (result.description) { text += `📝 ${result.description}\n`; } if (result.dependencies && result.dependencies.length > 0) { text += `\n🔗 프로덕션 의존성 (${result.dependencies.length}개):\n`; result.dependencies.forEach(dep => { text += ` - ${dep.name}: ${dep.version}\n`; }); } if (result.devDependencies && result.devDependencies.length > 0) { text += `\n🛠️ 개발 의존성 (${result.devDependencies.length}개):\n`; result.devDependencies.forEach(dep => { text += ` - ${dep.name}: ${dep.version}\n`; }); } if (result.scripts && result.scripts.length > 0) { text += `\n📜 스크립트 (${result.scripts.length}개):\n`; result.scripts.forEach(script => { text += ` - ${script.name}: ${script.command}\n`; }); } return { content: [{ type: "text", text }], }; } );
- src/index.ts:469-475 (schema)Zod input schema for the tool parameters: project path and optional includeDevDeps flag.{ path: z.string().describe("분석할 프로젝트 경로 (package.json이 있는 디렉토리)"), includeDevDeps: z .boolean() .optional() .describe("개발 의존성 포함 여부. 기본값: true"), },
- src/project-analyzer.ts:43-75 (schema)TypeScript interfaces defining input options, output result structure, and supporting types for dependencies and scripts.export interface DependencyInfo { name: string; version: string; } /** * 스크립트 정보 */ export interface ScriptInfo { name: string; command: string; } /** * 의존성 분석 옵션 */ export interface DependencyOptions { includeDevDeps?: boolean; } /** * 의존성 분석 결과 */ export interface DependencyResult { success: boolean; name?: string; version?: string; description?: string; dependencies?: DependencyInfo[]; devDependencies?: DependencyInfo[]; scripts?: ScriptInfo[]; error?: string; }