Skip to content

Commit f938b92

Browse files
committed
Improve search_files tool
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent a5a545d commit f938b92

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

pkg/tools/builtin/filesystem.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (t *FilesystemTool) Tools(context.Context) ([]tools.Tool, error) {
178178
{
179179
Function: &tools.FunctionDefinition{
180180
Name: "list_allowed_directories",
181-
Description: "Returns a list of directories that the server has permission to access.",
181+
Description: "Returns a list of directories that the server has permission to access. Don't call if you access only the current working directory. It's always allowed.",
182182
Annotations: tools.ToolAnnotation{
183183
ReadOnlyHint: &[]bool{true}[0],
184184
Title: "List Allowed Directories",
@@ -332,7 +332,7 @@ func (t *FilesystemTool) Tools(context.Context) ([]tools.Tool, error) {
332332
{
333333
Function: &tools.FunctionDefinition{
334334
Name: "search_files",
335-
Description: "Recursively search for files and directories matching a pattern.",
335+
Description: "Recursively search for files and directories matching a pattern. Prints the full paths of matching files and the total number of files found.",
336336
Annotations: tools.ToolAnnotation{
337337
ReadOnlyHint: &[]bool{true}[0],
338338
Title: "Search Files",
@@ -346,14 +346,14 @@ func (t *FilesystemTool) Tools(context.Context) ([]tools.Tool, error) {
346346
},
347347
"pattern": map[string]any{
348348
"type": "string",
349-
"description": "The search pattern (case-insensitive)",
349+
"description": "The search pattern",
350350
},
351351
"excludePatterns": map[string]any{
352-
"type": "array",
352+
"type": "array",
353+
"description": "Patterns to exclude from search",
353354
"items": map[string]any{
354355
"type": "string",
355356
},
356-
"description": "Patterns to exclude from search",
357357
},
358358
},
359359
Required: []string{"path", "pattern"},
@@ -912,7 +912,9 @@ func (t *FilesystemTool) handleSearchFiles(_ context.Context, toolCall tools.Too
912912
return &tools.ToolCallResult{Output: "No files found"}, nil
913913
}
914914

915-
return &tools.ToolCallResult{Output: strings.Join(matches, "\n")}, nil
915+
return &tools.ToolCallResult{
916+
Output: fmt.Sprintf("%d files found:\n%s", len(matches), strings.Join(matches, "\n")),
917+
}, nil
916918
}
917919

918920
func (t *FilesystemTool) handleSearchFilesContent(_ context.Context, toolCall tools.ToolCall) (*tools.ToolCallResult, error) {

pkg/tools/builtin/filesystem_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ func TestFilesystemTool_SearchFiles(t *testing.T) {
484484
result = callHandler(t, handler, args)
485485

486486
lines = strings.Split(strings.TrimSpace(result.Output), "\n")
487-
assert.Len(t, lines, 3) // Should find test.txt, test.log, and test_sub.txt
487+
assert.Contains(t, result.Output, "3 files found:\n")
488+
assert.Len(t, lines, 3+1) // Should find test.txt, test.log, and test_sub.txt
488489

489490
// Test search with exclude patterns
490491
args = map[string]any{
@@ -573,7 +574,8 @@ func TestFilesystemTool_SearchFiles_RecursivePattern(t *testing.T) {
573574
result := callHandler(t, handler, args)
574575

575576
lines := strings.Split(strings.TrimSpace(result.Output), "\n")
576-
assert.Len(t, lines, 3) // Should find first.txt, second.txt, and third.txt
577+
assert.Contains(t, result.Output, "3 files found:\n")
578+
assert.Len(t, lines, 3+1) // Should find first.txt, second.txt, and third.txt
577579
}
578580

579581
func TestFilesystemTool_ListAllowedDirectories(t *testing.T) {

0 commit comments

Comments
 (0)