You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tools/multi-file.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,33 +4,35 @@ This document provides details on the `read_many_files` tool.
4
4
5
5
## `read_many_files`
6
6
7
-
-**Purpose:** Reads content from multiple text files specified by paths or glob patterns and concatenates them into a single string. This is useful for getting an overview of a codebase, finding where specific functionality is implemented, reviewing documentation, or gathering context from multiple configuration files.
7
+
-**Purpose:** Reads content from multiple files specified by paths or glob patterns. For text files, it concatenates their content into a single string. For image (e.g., PNG, JPEG) and PDF files, it reads and returns them as base64 encoded data, provided they are explicitly requested by name or extension. This is useful for getting an overview of a codebase, finding where specific functionality is implemented, reviewing documentation, or gathering context from multiple configuration files.
8
8
-**Arguments:**
9
-
-`paths` (list[string], required): An array of glob patterns or paths relative to the tool's target directory (e.g., `["src/**/*.ts"]`, `["README.md", "docs/"]`).
9
+
-`paths` (list[string], required): An array of glob patterns or paths relative to the tool's target directory (e.g., `["src/**/*.ts"]`, `["README.md", "docs/", "assets/logo.png"]`).
10
10
-`exclude` (list[string], optional): Glob patterns for files/directories to exclude (e.g., `["**/*.log", "temp/"]`). These are added to default excludes if `useDefaultExcludes` is true.
11
-
-`include` (list[string], optional): Additional glob patterns to include. These are merged with `paths` (e.g., `["*.test.ts"]` to specifically add test files if they were broadly excluded).
11
+
-`include` (list[string], optional): Additional glob patterns to include. These are merged with `paths` (e.g., `["*.test.ts"]` to specifically add test files if they were broadly excluded, or `["images/*.jpg"]` to include specific image types).
12
12
-`recursive` (boolean, optional): Whether to search recursively. This is primarily controlled by `**` in glob patterns. Defaults to `true`.
13
-
-`useDefaultExcludes` (boolean, optional): Whether to apply a list of default exclusion patterns (e.g., `node_modules`, `.git`, binary files). Defaults to `true`.
13
+
-`useDefaultExcludes` (boolean, optional): Whether to apply a list of default exclusion patterns (e.g., `node_modules`, `.git`, non image/pdf binary files). Defaults to `true`.
14
14
-**Behavior:**
15
15
- The tool searches for files matching the provided `paths` and `include` patterns, while respecting `exclude` patterns and default excludes (if enabled).
16
-
-It reads the content of each matched text file (attempting to skip binary files).
17
-
-The content of all successfully read files is concatenated into a single string, with a separator `--- {filePath} ---` between the content of each file.
18
-
-Uses UTF-8 encoding by default.
16
+
-For text files: it reads the content of each matched file (attempting to skip binary files not explicitly requested as image/PDF) and concatenates it into a single string, with a separator `--- {filePath} ---` between the content of each file. Uses UTF-8 encoding by default.
17
+
-For image and PDF files: if explicitly requested by name or extension (e.g., `paths: ["logo.png"]` or `include: ["*.pdf"]`), the tool reads the file and returns its content as a base64 encoded string.
18
+
-The tool attempts to detect and skip other binary files (those not matching common image/PDF types or not explicitly requested) by checking for null bytes in their initial content.
19
19
-**Examples:**
20
20
- Reading all TypeScript files in the `src` directory:
21
21
```
22
22
read_many_files(paths=["src/**/*.ts"])
23
23
```
24
-
- Reading the main README and all Markdown files in the `docs` directory, excluding a specific file:
24
+
- Reading the main README, all Markdown files in the `docs` directory, and a specific logo image, excluding a specific file:
- **Binary Files:** This tool is designed for text files and attempts to skip binary files. Its behavior with binary content is not guaranteed.
33
+
- **Binary File Handling:**
34
+
- **Image/PDF Files:** The tool can read common image types (PNG, JPEG, etc.) and PDF files, returning them as base64 encoded data. These files _must_ be explicitly targeted by the `paths` or `include` patterns (e.g., by specifying the exact filename like `image.png` or a pattern like `*.jpeg`).
35
+
- **Other Binary Files:** The tool attempts to detect and skip other types of binary files by examining their initial content for null bytes. Its behavior with such files is to exclude them from the output.
34
36
- **Performance:** Reading a very large number of files or very large individual files can be resource-intensive.
35
-
- **Path Specificity:** Ensure paths and glob patterns are correctly specified relative to the tool's target directory.
37
+
- **Path Specificity:** Ensure paths and glob patterns are correctly specified relative to the tool's target directory. For image/PDF files, ensure the patterns are specific enough to include them.
36
38
- **Default Excludes:** Be aware of the default exclusion patterns (like `node_modules`, `.git`) and use `useDefaultExcludes=False` if you need to override them, but do so cautiously.
Copy file name to clipboardExpand all lines: packages/server/src/tools/read-many-files.ts
+16-6Lines changed: 16 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -161,20 +161,30 @@ export class ReadManyFilesTool extends BaseTool<
161
161
super(
162
162
ReadManyFilesTool.Name,
163
163
'ReadManyFiles',
164
-
`Reads content from multiple text files specified by paths or glob patterns within a configured target directory and concatenates them into a single string.
164
+
`Reads content from multiple files specified by paths or glob patterns
165
+
within a configured target directory. For text files, it concatenates their content
166
+
into a single string. It is primarily designed for text-based files. However, it can
167
+
also process image (e.g., .png, .jpg) and PDF (.pdf) files if their file names or
168
+
extensions are explicitly included in the 'paths' argument. For these explicitly
169
+
requested non-text files, their data is read and included in a format suitable for
170
+
model consumption (e.g., base64 encoded).
171
+
165
172
This tool is useful when you need to understand or analyze a collection of files, such as:
166
173
- Getting an overview of a codebase or parts of it (e.g., all TypeScript files in the 'src' directory).
167
174
- Finding where specific functionality is implemented if the user asks broad questions about code.
168
175
- Reviewing documentation files (e.g., all Markdown files in the 'docs' directory).
169
176
- Gathering context from multiple configuration files.
170
177
- When the user asks to "read all files in X directory" or "show me the content of all Y files".
171
178
172
-
Use this tool when the user's query implies needing the content of several files simultaneously for context, analysis, or summarization.
173
-
It uses default UTF-8 encoding and a '--- {filePath} ---' separator between file contents.
179
+
Use this tool when the user's query implies needing the content of several files
180
+
simultaneously for context, analysis, or summarization.
181
+
For text files, it uses default UTF-8 encoding and a '--- {filePath} ---' separator between file contents.
174
182
Ensure paths are relative to the target directory. Glob patterns like 'src/**/*.js' are supported.
175
-
Avoid using for single files if a more specific single-file reading tool is available, unless the user specifically requests to process a list containing just one file via this tool.
176
-
This tool should NOT be used for binary files; it attempts to skip them.
177
-
Default excludes apply to common non-text files and large dependency directories unless 'useDefaultExcludes' is false.`,
183
+
Avoid using for single files if a more specific single-file reading tool is available,
184
+
unless the user specifically requests to process a list containing just one file via this tool.
185
+
Other binary files (not explicitly requested as image/PDF) are generally skipped.
186
+
Default excludes apply to common non-text files (except for explicitly requested images/PDFs)
187
+
and large dependency directories unless 'useDefaultExcludes' is false.`,
0 commit comments