Skip to content

read_file - Read File

Overview

The read_file tool reads the content of a specified file from the local filesystem. It handles text files, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files. For text files, it can read specific line ranges.

Tool Name

  • Internal Name: read_file
  • Display Name: ReadFile
  • Icon: FileSearch

Parameters

Required Parameters

ParameterTypeDescription
absolute_pathstringThe absolute path to the file to read (e.g., /home/user/project/file.txt). Relative paths are not supported. You must provide an absolute path.

Optional Parameters

ParameterTypeDescription
offsetnumberFor text files, the 0-based line number to start reading from. Requires limit to be set. Use for paginating through large files.
limitnumberFor text files, maximum number of lines to read. Use with offset to paginate through large files. If omitted, reads the entire file (if feasible, up to a default limit).
prefer_full_readbooleanSet to true to bypass large-file preview guards. Only use if you are confident the file is small enough to read fully.

Features

  1. File Type Support:

    • Text files: Supports various text encodings
    • Image files: PNG, JPG, GIF, WEBP, SVG, BMP
    • PDF files: Can extract PDF content
  2. Pagination:

    • Use offset and limit parameters to paginate through large text files
    • Suitable for handling very large files without loading everything at once
  3. Security Restrictions:

    • File path must be absolute
    • File must be within the project root directory
    • Respects .siiignore file patterns
  4. Large File Protection:

    • Default preview limits for large files
    • Can bypass limits with prefer_full_read parameter

Usage Examples

Read Entire File

json
{
  "absolute_path": "/home/user/project/src/main.ts"
}

Paginated Read (lines 10-20)

json
{
  "absolute_path": "/home/user/project/logs/app.log",
  "offset": 10,
  "limit": 10
}

Force Full Read

json
{
  "absolute_path": "/home/user/project/config.json",
  "prefer_full_read": true
}

Return Value

The tool returns an object containing:

  • llmContent: The actual file content (text or other format)
  • returnDisplay: User-friendly display information
  • summary: Operation summary (optional)

Error Handling

Possible error scenarios:

  1. Path Errors:

    • Path is not absolute
    • Path is outside project root directory
    • File is ignored by .siiignore
  2. File Access Errors:

    • File does not exist
    • No read permission
    • Path is a directory, not a file
  3. Parameter Errors:

    • offset is negative
    • limit is less than or equal to 0
    • Incorrect parameter types

Notes

  1. Path Requirement: Must use absolute paths, relative paths are not supported
  2. Performance: For large files, use pagination
  3. Security: Tool checks if file is within allowed directory scope
  4. Encoding: Text files default to UTF-8 encoding
  • write_file: Write to file
  • replace: Replace text in file
  • read_many_files: Read multiple files in batch
  • list_directory: List directory contents

Released under the MIT License.