Skip to main content
Glama

read_file

Extract and read the full contents of a file from your file system, handling multiple text encodings and providing clear error messages. Works within specified allowed directories for secure access.

Instructions

Read the complete contents of a file from the file system. Handles various text encodings and provides detailed error messages if the file cannot be read. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Handler for the 'read_file' tool that parses the input arguments using ReadFileArgsSchema, calls the readFile helper function, and returns the file content wrapped in the expected response format.
    case "read_file": { const parsed = ReadFileArgsSchema.parse(args); const content = await readFile(parsed.path); return { content: [{ type: "text", text: content }], }; }
  • Zod schema defining the input for the read_file tool: an object with a required 'path' string parameter.
    export const ReadFileArgsSchema = z.object({ path: z.string(), });
  • src/server.ts:126-132 (registration)
    Registration of the 'read_file' tool in the ListToolsRequest handler, specifying name, description, and input schema.
    name: "read_file", description: "Read the complete contents of a file from the file system. " + "Handles various text encodings and provides detailed error messages " + "if the file cannot be read. Only works within allowed directories.", inputSchema: zodToJsonSchema(ReadFileArgsSchema), },
  • Helper function that validates the file path using validatePath and reads the file contents using Node.js fs.readFile.
    export async function readFile(filePath: string): Promise<string> { const validPath = await validatePath(filePath); return fs.readFile(validPath, "utf-8"); }

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/MrGNSS/ClaudeDesktopCommander'

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