read_file
Retrieve file contents from your computer's file system. This tool reads text files within permitted directories and handles various encodings while providing clear error feedback.
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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/server.ts:266-272 (handler)Handler for the read_file tool in the main server request handler. Parses args using the schema, calls the readFile helper, and returns the file content.case "read_file": { const parsed = ReadFileArgsSchema.parse(args); const content = await readFile(parsed.path); return { content: [{ type: "text", text: content }], }; }
- src/tools/schemas.ts:32-34 (schema)Zod schema defining the input for read_file tool: requires a 'path' string.export const ReadFileArgsSchema = z.object({ path: z.string(), });
- src/server.ts:126-132 (registration)Registration of the read_file tool in the ListToolsRequestHandler, including name, description, and input schema reference.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), },
- src/tools/filesystem.ts:65-68 (helper)Core implementation of file reading: validates the path for security and reads the file content using fs.readFile.export async function readFile(filePath: string): Promise<string> { const validPath = await validatePath(filePath); return fs.readFile(validPath, "utf-8"); }