Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathsYesArray of file paths
encodingNoFile encoding
fail_on_errorNoFail if any file errors

Implementation Reference

  • 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),
          },
        ],
      };
    }
  • 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);
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-tool-shop-org/mcp-file-forge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server