fast_list_directory
Retrieve directory listings with automatic chunking and pagination support. Filter files by name, sort by criteria, and manage large directories efficiently.
Instructions
디렉토리 목록을 조회합니다 (자동 청킹 페이징 지원)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| auto_chunk | No | 자동 청킹 활성화 | |
| continuation_token | No | 이전 호출의 연속 토큰 | |
| page | No | 페이지 번호 | |
| page_size | No | 페이지당 항목 수 | |
| path | Yes | 디렉토리 경로 | |
| pattern | No | 파일명 필터 패턴 | |
| reverse | No | 역순 정렬 | |
| show_hidden | No | 숨김 파일 표시 | |
| sort_by | No | 정렬 기준 | name |
Input Schema (JSON Schema)
{
"properties": {
"auto_chunk": {
"default": true,
"description": "자동 청킹 활성화",
"type": "boolean"
},
"continuation_token": {
"description": "이전 호출의 연속 토큰",
"type": "string"
},
"page": {
"default": 1,
"description": "페이지 번호",
"type": "number"
},
"page_size": {
"description": "페이지당 항목 수",
"type": "number"
},
"path": {
"description": "디렉토리 경로",
"type": "string"
},
"pattern": {
"description": "파일명 필터 패턴",
"type": "string"
},
"reverse": {
"default": false,
"description": "역순 정렬",
"type": "boolean"
},
"show_hidden": {
"default": false,
"description": "숨김 파일 표시",
"type": "boolean"
},
"sort_by": {
"default": "name",
"description": "정렬 기준",
"enum": [
"name",
"size",
"modified",
"type"
],
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
}
Implementation Reference
- api/server.ts:522-609 (handler)The primary handler function for the 'fast_list_directory' tool. It validates the directory path, reads directory entries, applies filters (hidden files, exclude patterns, pattern matching), sorts the entries, implements pagination, fetches stats for each item, and returns structured directory listing information.async function handleListDirectory(args: any) { const { path: dirPath, page = 1, page_size, pattern, show_hidden = false, sort_by = 'name', reverse = false } = args; const safePath_resolved = safePath(dirPath); const stats = await fs.stat(safePath_resolved); if (!stats.isDirectory()) { throw new Error('Path is not a directory'); } const pageSize = page_size ? Math.min(page_size, CLAUDE_MAX_DIR_ITEMS) : 50; const entries = await fs.readdir(safePath_resolved, { withFileTypes: true }); let filteredEntries = entries.filter(entry => { if (!show_hidden && entry.name.startsWith('.')) return false; if (shouldExcludePath(path.join(safePath_resolved, entry.name))) return false; if (pattern) { return entry.name.toLowerCase().includes(pattern.toLowerCase()); } return true; }); // 정렬 filteredEntries.sort((a, b) => { let comparison = 0; switch (sort_by) { case 'name': comparison = a.name.localeCompare(b.name); break; case 'type': const aType = a.isDirectory() ? 'directory' : 'file'; const bType = b.isDirectory() ? 'directory' : 'file'; comparison = aType.localeCompare(bType); break; default: comparison = a.name.localeCompare(b.name); } return reverse ? -comparison : comparison; }); const startIdx = (page - 1) * pageSize; const endIdx = startIdx + pageSize; const pageEntries = filteredEntries.slice(startIdx, endIdx); const items = await Promise.all(pageEntries.map(async (entry) => { try { const fullPath = path.join(safePath_resolved, entry.name); const itemStats = await fs.stat(fullPath); return { name: entry.name, type: entry.isDirectory() ? 'directory' : 'file', size: entry.isFile() ? itemStats.size : null, size_readable: entry.isFile() ? formatSize(itemStats.size) : null, modified: itemStats.mtime.toISOString(), created: itemStats.birthtime.toISOString(), permissions: itemStats.mode, path: fullPath }; } catch { return { name: entry.name, type: entry.isDirectory() ? 'directory' : 'file', size: null, size_readable: null, modified: null, created: null, permissions: null, path: path.join(safePath_resolved, entry.name) }; } })); return { path: safePath_resolved, items: items, page: page, page_size: pageSize, total_count: filteredEntries.length, total_pages: Math.ceil(filteredEntries.length / pageSize), has_more: endIdx < filteredEntries.length, sort_by: sort_by, reverse: reverse, timestamp: new Date().toISOString() }; }
- api/server.ts:138-153 (schema)Input schema definition for the 'fast_list_directory' tool, specifying parameters like path, pagination, filtering, sorting options. Part of the MCP_TOOLS registration array.{ name: 'fast_list_directory', description: '디렉토리 목록을 조회합니다 (페이징 지원)', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '디렉토리 경로' }, page: { type: 'number', description: '페이지 번호', default: 1 }, page_size: { type: 'number', description: '페이지당 항목 수' }, pattern: { type: 'string', description: '파일명 필터 패턴' }, show_hidden: { type: 'boolean', description: '숨김 파일 표시', default: false }, sort_by: { type: 'string', description: '정렬 기준', enum: ['name', 'size', 'modified', 'type'], default: 'name' }, reverse: { type: 'boolean', description: '역순 정렬', default: false } }, required: ['path'] }
- api/server.ts:329-330 (registration)Dispatch case in the tools/call handler that routes calls to the fast_list_directory tool to its implementation function.case 'fast_list_directory': result = await handleListDirectory(args);