Skip to main content
Glama
A-Niranjan

MCP Filesystem Server

by A-Niranjan

read_multiple_files

Read contents from multiple files simultaneously for efficient analysis or comparison. Returns each file's content with its path, continues operation even if individual reads fail, and works within allowed directories.

Instructions

Read the contents of multiple files simultaneously. This is more efficient than reading files one by one when you need to analyze or compare multiple files. Each file's content is returned with its path as a reference. Failed reads for individual files won't stop the entire operation. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathsYesList of file paths to read
encodingNoFile encodingutf-8

Implementation Reference

  • Core handler function that implements the read_multiple_files tool logic: reads multiple files concurrently with path validation, size checks, and per-file error handling.
    export async function readMultipleFiles( args: z.infer<typeof ReadMultipleFilesArgsSchema>, config: Config ): Promise<Record<string, string | Error>> { const endMetric = metrics.startOperation('read_multiple_files') const results: Record<string, string | Error> = {} await Promise.all( args.paths.map(async (filePath: string) => { try { const validPath = await validatePath(filePath, config) // Validate file size if (config.security.maxFileSize > 0) { await validateFileSize(validPath, config.security.maxFileSize) } const content = await fs.readFile(validPath, args.encoding) results[filePath] = content } catch (error) { if (error instanceof Error) { results[filePath] = error } else { results[filePath] = new Error(String(error)) } } }) ) endMetric() return results }
  • Zod schema for validating input arguments to the read_multiple_files tool: requires an array of file paths and optional encoding.
    export const ReadMultipleFilesArgsSchema = z.object({ paths: z.array(z.string()).describe('List of file paths to read'), encoding: z .enum(['utf-8', 'utf8', 'base64']) .optional() .default('utf-8') .describe('File encoding'), })
  • src/index.ts:244-253 (registration)
    Registration of the read_multiple_files tool in the ListTools response, including name, description, and derived JSON schema.
    { name: 'read_multiple_files', description: 'Read the contents of multiple files simultaneously. This is more ' + 'efficient than reading files one by one when you need to analyze ' + "or compare multiple files. Each file's content is returned with its " + "path as a reference. Failed reads for individual files won't stop " + 'the entire operation. Only works within allowed directories.', inputSchema: zodToJsonSchema(ReadMultipleFilesArgsSchema) as ToolInput, },
  • MCP server dispatcher case for read_multiple_files: parses arguments, calls the core handler, formats results with error handling, and returns MCP content response.
    case 'read_multiple_files': { const parsed = ReadMultipleFilesArgsSchema.safeParse(a) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } const results = await readMultipleFiles(parsed.data, config) const formattedResults = Object.entries(results) .map(([filePath, content]) => { if (content instanceof Error) { return `${filePath}: Error - ${content.message}` } return `${filePath}:\n${content}\n` }) .join('\n---\n') endMetric() return { content: [{ type: 'text', text: formattedResults }], } }

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/A-Niranjan/mcp-filesystem'

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