fast_find_large_files
Identify large files in directories by specifying minimum size thresholds to manage disk space and organize storage efficiently.
Instructions
Finds large files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Directory to search in | |
| min_size | No | Minimum size (e.g., 100MB, 1GB) | 100MB |
| max_results | No | Maximum number of results |
Implementation Reference
- api/server.ts:861-941 (handler)Implements the core logic for finding large files recursively in the specified directory, filtering by minimum size, excluding certain paths, sorting by size descending, and limiting results.
async function handleFindLargeFiles(args: any) { const { path: searchPath, min_size = '100MB', max_results = 50 } = args; const safePath_resolved = safePath(searchPath); const maxResults = Math.min(max_results, 100); // 크기 파싱 (예: 100MB -> bytes) const parseSize = (sizeStr: string): number => { const match = sizeStr.match(/^(\d+(\.\d+)?)\s*(B|KB|MB|GB|TB)?$/i); if (!match) return 100 * 1024 * 1024; // 기본값 100MB const value = parseFloat(match[1]); const unit = (match[3] || 'B').toUpperCase(); const units: {[key: string]: number} = { 'B': 1, 'KB': 1024, 'MB': 1024 * 1024, 'GB': 1024 * 1024 * 1024, 'TB': 1024 * 1024 * 1024 * 1024 }; return value * (units[unit] || 1); }; const minSizeBytes = parseSize(min_size); const results: any[] = []; async function findLargeFilesRecursive(dirPath: string) { if (results.length >= maxResults) return; try { const entries = await fs.readdir(dirPath, { withFileTypes: true }); for (const entry of entries) { if (results.length >= maxResults) break; const fullPath = path.join(dirPath, entry.name); if (shouldExcludePath(fullPath)) continue; if (entry.isFile()) { try { const stats = await fs.stat(fullPath); if (stats.size >= minSizeBytes) { results.push({ path: fullPath, name: entry.name, size: stats.size, size_readable: formatSize(stats.size), modified: stats.mtime.toISOString(), extension: path.extname(fullPath) }); } } catch { // 파일 접근 실패 무시 } } else if (entry.isDirectory()) { await findLargeFilesRecursive(fullPath); } } } catch { // 권한 없는 디렉토리 무시 } } await findLargeFilesRecursive(safePath_resolved); // 크기별로 정렬 (큰 것부터) results.sort((a, b) => b.size - a.size); return { results: results, total_found: results.length, search_path: safePath_resolved, min_size: min_size, min_size_bytes: minSizeBytes, max_results_reached: results.length >= maxResults, timestamp: new Date().toISOString() }; } - api/server.ts:347-349 (registration)Dispatches tool calls to the handleFindLargeFiles handler in the main switch statement.
case 'fast_find_large_files': result = await handleFindLargeFiles(args); break; - api/server.ts:217-229 (registration)Registers the tool in the MCP_TOOLS array with name, description, and input schema.
{ name: 'fast_find_large_files', description: '큰 파일들을 찾습니다', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '검색할 디렉토리' }, min_size: { type: 'string', description: '최소 크기 (예: 100MB, 1GB)', default: '100MB' }, max_results: { type: 'number', description: '최대 결과 수', default: 50 } }, required: ['path'] } } - api/server.ts:220-227 (schema)Defines the input schema for the fast_find_large_files tool, specifying parameters like path, min_size, and max_results.
inputSchema: { type: 'object', properties: { path: { type: 'string', description: '검색할 디렉토리' }, min_size: { type: 'string', description: '최소 크기 (예: 100MB, 1GB)', default: '100MB' }, max_results: { type: 'number', description: '최대 결과 수', default: 50 } }, required: ['path'] - api/server.ts:45-56 (helper)Utility function to format file sizes in human-readable format, used in the handler output.
function formatSize(bytes: number): string { const units = ['B', 'KB', 'MB', 'GB', 'TB']; let size = bytes; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } return `${size.toFixed(2)} ${units[unitIndex]}`; }