Skip to content

Commit fd886fa

Browse files
Finndersendomdomeggclaude
authored
Support glob pattern in search_files tool (#745)
Co-authored-by: Adam Jones <adamj+git@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Adam Jones <adamj@anthropic.com>
1 parent d381cf1 commit fd886fa

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/filesystem/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ The server's directory access control follows this flow:
145145
- Fails if destination exists
146146

147147
- **search_files**
148-
- Recursively search for files/directories
148+
- Recursively search for files/directories that match or do not match patterns
149149
- Inputs:
150150
- `path` (string): Starting directory
151151
- `pattern` (string): Search pattern
152-
- `excludePatterns` (string[]): Exclude any patterns. Glob formats are supported.
153-
- Case-insensitive matching
152+
- `excludePatterns` (string[]): Exclude any patterns.
153+
- Glob-style pattern matching
154154
- Returns full paths to matches
155155

156156
- **directory_tree**

src/filesystem/__tests__/lib.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ describe('Lib Functions', () => {
316316

317317
const result = await searchFilesWithValidation(
318318
testDir,
319-
'test',
319+
'*test*',
320320
allowedDirs,
321321
{ excludePatterns: ['*.log', 'node_modules'] }
322322
);
@@ -346,7 +346,7 @@ describe('Lib Functions', () => {
346346

347347
const result = await searchFilesWithValidation(
348348
testDir,
349-
'test',
349+
'*test*',
350350
allowedDirs,
351351
{}
352352
);
@@ -370,7 +370,7 @@ describe('Lib Functions', () => {
370370

371371
const result = await searchFilesWithValidation(
372372
testDir,
373-
'test',
373+
'*test*',
374374
allowedDirs,
375375
{ excludePatterns: ['*.backup'] }
376376
);

src/filesystem/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
277277
name: "search_files",
278278
description:
279279
"Recursively search for files and directories matching a pattern. " +
280-
"Searches through all subdirectories from the starting path. The search " +
281-
"is case-insensitive and matches partial names. Returns full paths to all " +
282-
"matching items. Great for finding files when you don't know their exact location. " +
280+
"The patterns should be glob-style patterns that match paths relative to the working directory. " +
281+
"Use pattern like '*.ext' to match files in current directory, and '**/*.ext' to match files in all subdirectories. " +
282+
"Returns full paths to all matching items. Great for finding files when you don't know their exact location. " +
283283
"Only searches within allowed directories.",
284284
inputSchema: zodToJsonSchema(SearchFilesArgsSchema) as ToolInput,
285285
},

src/filesystem/lib.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ export async function searchFilesWithValidation(
367367
await validatePath(fullPath);
368368

369369
const relativePath = path.relative(rootPath, fullPath);
370-
const shouldExclude = excludePatterns.some(excludePattern => {
371-
const globPattern = excludePattern.includes('*') ? excludePattern : `**/${excludePattern}/**`;
372-
return minimatch(relativePath, globPattern, { dot: true });
373-
});
370+
const shouldExclude = excludePatterns.some(excludePattern =>
371+
minimatch(relativePath, excludePattern, { dot: true })
372+
);
374373

375374
if (shouldExclude) continue;
376375

377-
if (entry.name.toLowerCase().includes(pattern.toLowerCase())) {
376+
// Use glob matching for the search pattern
377+
if (minimatch(relativePath, pattern, { dot: true })) {
378378
results.push(fullPath);
379379
}
380380

0 commit comments

Comments
 (0)