fast_search_files
Search files by name or content with support for regex, context lines, and line numbering. Filters by file pattern, handles large files with auto-chunking, and includes binary files if specified.
Instructions
파일을 검색합니다 (이름/내용) - 자동 청킹, 정규표현식, 컨텍스트, 라인번호 지원
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| auto_chunk | No | 자동 청킹 활성화 | |
| case_sensitive | No | 대소문자 구분 | |
| content_search | No | 파일 내용 검색 | |
| context_lines | No | 매치된 라인 주변 컨텍스트 라인 수 | |
| continuation_token | No | 이전 호출의 연속 토큰 | |
| file_pattern | No | 파일명 필터 패턴 (*.js, *.txt 등) | |
| include_binary | No | 바이너리 파일 포함 여부 | |
| max_results | No | 최대 결과 수 | |
| path | Yes | 검색할 디렉토리 | |
| pattern | Yes | 검색 패턴 (정규표현식 지원) |
Input Schema (JSON Schema)
{
"properties": {
"auto_chunk": {
"default": true,
"description": "자동 청킹 활성화",
"type": "boolean"
},
"case_sensitive": {
"default": false,
"description": "대소문자 구분",
"type": "boolean"
},
"content_search": {
"default": false,
"description": "파일 내용 검색",
"type": "boolean"
},
"context_lines": {
"default": 0,
"description": "매치된 라인 주변 컨텍스트 라인 수",
"type": "number"
},
"continuation_token": {
"description": "이전 호출의 연속 토큰",
"type": "string"
},
"file_pattern": {
"default": "",
"description": "파일명 필터 패턴 (*.js, *.txt 등)",
"type": "string"
},
"include_binary": {
"default": false,
"description": "바이너리 파일 포함 여부",
"type": "boolean"
},
"max_results": {
"default": 100,
"description": "최대 결과 수",
"type": "number"
},
"path": {
"description": "검색할 디렉토리",
"type": "string"
},
"pattern": {
"description": "검색 패턴 (정규표현식 지원)",
"type": "string"
}
},
"required": [
"path",
"pattern"
],
"type": "object"
}
Implementation Reference
- api/server.ts:676-763 (handler)The main handler function that implements the logic for the fast_search_files tool, including recursive directory search for file names and optional content matching.async function handleSearchFiles(args: any) { const { path: searchPath, pattern, content_search = false, case_sensitive = false, max_results = 100 } = args; const safePath_resolved = safePath(searchPath); const maxResults = Math.min(max_results, 200); const results: any[] = []; const searchPattern = case_sensitive ? pattern : pattern.toLowerCase(); async function searchDirectory(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()) { const searchName = case_sensitive ? entry.name : entry.name.toLowerCase(); let matched = false; let matchType = ''; if (searchName.includes(searchPattern)) { matched = true; matchType = 'filename'; } if (!matched && content_search) { try { const stats = await fs.stat(fullPath); if (stats.size < 10 * 1024 * 1024) { // 10MB 제한 const content = await fs.readFile(fullPath, 'utf-8'); const searchContent = case_sensitive ? content : content.toLowerCase(); if (searchContent.includes(searchPattern)) { matched = true; matchType = 'content'; } } } catch { // 바이너리 파일 등 읽기 실패 무시 } } if (matched) { const stats = await fs.stat(fullPath); results.push({ path: fullPath, name: entry.name, match_type: matchType, size: stats.size, size_readable: formatSize(stats.size), modified: stats.mtime.toISOString(), extension: path.extname(fullPath) }); } } else if (entry.isDirectory()) { await searchDirectory(fullPath); } } } catch { // 권한 없는 디렉토리 등 무시 } } await searchDirectory(safePath_resolved); return { results: results, total_found: results.length, search_pattern: pattern, search_path: safePath_resolved, content_search: content_search, case_sensitive: case_sensitive, max_results_reached: results.length >= maxResults, timestamp: new Date().toISOString() }; }
- api/server.ts:178-192 (schema)Input schema definition for the fast_search_files tool, specifying parameters like path, pattern, content_search, etc.{ name: 'fast_search_files', description: '파일을 검색합니다 (이름/내용)', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '검색할 디렉토리' }, pattern: { type: 'string', description: '검색 패턴' }, content_search: { type: 'boolean', description: '파일 내용 검색', default: false }, case_sensitive: { type: 'boolean', description: '대소문자 구분', default: false }, max_results: { type: 'number', description: '최대 결과 수', default: 100 } }, required: ['path', 'pattern'] } },
- api/server.ts:338-340 (registration)Registration of the fast_search_files tool handler in the main switch statement that dispatches tool calls.case 'fast_search_files': result = await handleSearchFiles(args); break;