MCPcopy Index your code
hub / github.com/modelcontextprotocol/servers / searchFilesWithValidation

Function searchFilesWithValidation

src/filesystem/lib.ts:374–415  ·  view source on GitHub ↗
(
  rootPath: string,
  pattern: string,
  allowedDirectories: string[],
  options: SearchOptions = {}
)

Source from the content-addressed store, hash-verified

372}
373
374export async function searchFilesWithValidation(
375 rootPath: string,
376 pattern: string,
377 allowedDirectories: string[],
378 options: SearchOptions = {}
379): Promise<string[]> {
380 const { excludePatterns = [] } = options;
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;
415}

Callers 2

index.tsFile · 0.85
lib.test.tsFile · 0.85

Calls 1

searchFunction · 0.85

Tested by

no test coverage detected