Skip to main content
Glama
lin2000wl
by lin2000wl

read_file

Retrieve file content or specific sections from codebases to analyze, reference, or process data when symbolic operations are insufficient.

Instructions

Reads the given file or a chunk of it. Generally, symbolic operations like find_symbol or find_referencing_symbols should be preferred if you know which symbols you are looking for. Reading the entire file is only recommended if there is no other way to get the content required for the task. Returns the full text of the file at the given relative path.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
relative_pathYesThe relative path to the file to read.
start_lineNoThe 0-based index of the first line to be retrieved.
end_lineNoThe 0-based index of the last line to be retrieved (inclusive). If None, read until the end of the file.
max_answer_charsNoIf the file (chunk) is longer than this number of characters, no content will be returned. Don't adjust unless there is really no other way to get the content required for the task.

Implementation Reference

  • The implementation of reading a file's contents, used as the core logic for file reading tools.
    def read_file(logger: LanguageServerLogger, file_path: str) -> str: """ Reads the file at the given path and returns the contents as a string. """ if not os.path.exists(file_path): logger.log(f"File read '{file_path}' failed: File does not exist.", logging.ERROR) raise LanguageServerException(f"File read '{file_path}' failed: File does not exist.") try: with open(file_path, encoding="utf-8") as inp_file: return inp_file.read() except Exception as exc: logger.log(f"File read '{file_path}' failed to read with encoding 'utf-8': {exc}", logging.ERROR) raise LanguageServerException("File read failed.") from None

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/lin2000wl/Serena-cursor-mcp'

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