Skip to main content
Glama
lin2000wl

Serena MCP Server

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
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses some behavioral traits: it can read chunks of files (via start_line/end_line), has a character limit (max_answer_chars), and returns full text. However, it doesn't cover important aspects like error handling (e.g., what happens if file doesn't exist), performance implications, or whether this is a read-only operation (though implied by 'Reads'). The description adds value but lacks comprehensive behavioral context for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with three sentences that each serve a distinct purpose: stating the core function, providing usage guidelines, and specifying the return value. It's front-loaded with the main action. While efficient, the third sentence could be slightly more concise by integrating the return information earlier.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (file reading with chunking and limits), no annotations, and no output schema, the description does reasonably well. It covers the core purpose, usage guidelines, and return value. However, it lacks details about error conditions, performance characteristics, or what exactly 'Returns the full text' means in practice (e.g., formatting, encoding). For a tool with no annotations or output schema, it's mostly complete but has some gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description adds minimal parameter semantics beyond the schema: it mentions reading 'a chunk of it' (hinting at start_line/end_line) and the character limit warning. However, it doesn't provide additional syntax, format, or usage details that aren't already in the schema descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('Reads', 'Returns') and resource ('the given file or a chunk of it'). It distinguishes from sibling tools by explicitly mentioning alternatives like 'find_symbol' or 'find_referencing_symbols' should be preferred when possible, making the purpose specific and differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool vs alternatives: '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.' This clearly defines when to use and when not to use this tool, naming specific alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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