MCPcopy
hub / github.com/modelcontextprotocol/servers / search

Function search

src/filesystem/lib.ts:383–411  ·  view source on GitHub ↗
(currentPath: string)

Source from the content-addressed store, hash-verified

381 const results: string[] = [];
382
383 async function search(currentPath: string) {
384 const entries = await fs.readdir(currentPath, { withFileTypes: true });
385
386 for (const entry of entries) {
387 const fullPath = path.join(currentPath, entry.name);
388
389 try {
390 await validatePath(fullPath);
391
392 const relativePath = path.relative(rootPath, fullPath);
393 const shouldExclude = excludePatterns.some(excludePattern =>
394 minimatch(relativePath, excludePattern, { dot: true })
395 );
396
397 if (shouldExclude) continue;
398
399 // Use glob matching for the search pattern
400 if (minimatch(relativePath, pattern, { dot: true })) {
401 results.push(fullPath);
402 }
403
404 if (entry.isDirectory()) {
405 await search(fullPath);
406 }
407 } catch {
408 continue;
409 }
410 }
411 }
412
413 await search(rootPath);
414 return results;

Callers 1

Calls 1

validatePathFunction · 0.85

Tested by

no test coverage detected