read_multiple
Read multiple files simultaneously to retrieve content from specified paths with configurable encoding and error handling options.
Instructions
Read multiple files at once
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes | Array of file paths | |
| encoding | No | File encoding | |
| fail_on_error | No | Fail if any file errors |
Implementation Reference
- src/tools/read.ts:294-339 (handler)The implementation of the read_multiple tool handler.
async function readMultipleImpl(input: { paths: string[]; encoding?: string; fail_on_error?: boolean; }): Promise<ToolResult> { const results: Array<{ path: string; success: boolean; content?: string; error?: string; }> = []; for (const filePath of input.paths) { const result = await readFileImpl({ path: filePath, encoding: input.encoding ?? 'utf-8', max_size_kb: 10240, }); if ('isError' in result && result.isError) { if (input.fail_on_error) { return result; } results.push({ path: filePath, success: false, error: result.content[0].text, }); } else { results.push({ path: filePath, success: true, content: result.content[0].text, }); } } return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } - src/tools/read.ts:390-402 (registration)Registration of the read_multiple tool.
// read_multiple tool server.tool( 'read_multiple', 'Read multiple files at once', { paths: z.array(z.string()).describe('Array of file paths'), encoding: z.string().optional().describe('File encoding'), fail_on_error: z.boolean().optional().describe('Fail if any file errors'), }, async (args) => { return await readMultipleImpl(args); } );