Skip to main content
Glama

read

Extract specific lines from a text file by defining start and end positions to prepare content for editing operations.

Instructions

Read lines from the current file from start line to end line, returning them in a dictionary like {"lines":[[1,"text on first line"],[2,"text on second line"]]}. This makes it easier to find the precise lines to select for editing.

Args: start (int, optional): Start line number end (int, optional): End line number

Returns: dict: lines, start_line, end_line

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startYes
endYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Implementation of the 'read' tool handler. Reads a range of lines (start to end) from the currently set file, validates the range, formats lines with numbers, and returns them in a structured dictionary. Handles errors like no file set or invalid ranges.
    async def read(start: int, end: int) -> Dict[str, Any]:
        """
        Read lines from the current file from start line to end line, returning them in a dictionary
        like {"lines":[[1,"text on first line"],[2,"text on second line"]]}. This makes it easier to find the precise lines to select for editing.
    
        Args:
            start (int, optional): Start line number
            end (int, optional): End line number
    
        Returns:
            dict: lines, start_line, end_line
        """
        result = {}
    
        if self.current_file_path is None:
            return {"error": "No file path is set. Use set_file first."}
    
        try:
            with open(self.current_file_path, "r", encoding="utf-8") as file:
                lines = file.readlines()
    
            if start < 1:
                return {"error": "start must be at least 1"}
            if end > len(lines):
                end = len(lines)
            if start > end:
                return {
                    "error": f"{start=} cannot be greater than {end=}. {len(lines)=}"
                }
    
            selected_lines = lines[start - 1 : end]
    
            formatted_lines = []
            for i, line in enumerate(selected_lines, start):
                formatted_lines.append((i, line.rstrip()))
    
            result["lines"] = formatted_lines
            result["start_line"] = start
            result["end_line"] = end
    
            return result
    
        except Exception as e:
            return {"error": f"Error reading file: {str(e)}"}
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool reads lines and returns them in a specific dictionary format, which is useful. However, it lacks details on error handling, file state changes, or permissions needed, leaving behavioral gaps for a read operation.

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 and front-loaded with the core functionality in the first sentence. The Args and Returns sections are structured but slightly verbose; every sentence adds value, though it could be more streamlined.

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 low complexity, no annotations, and an output schema present, the description is fairly complete. It explains the purpose, parameters, and return format adequately. However, it could improve by addressing error cases or interaction with sibling tools for better context.

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

Parameters4/5

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

The schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that 'start' and 'end' are line numbers and are optional in the Args section, clarifying their role in selecting lines. However, it doesn't detail default behaviors or constraints beyond basic types.

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 specific action ('Read lines from the current file') and resource ('current file'), distinguishing it from siblings like 'skim' or 'select'. It precisely defines what the tool does without being vague or tautological.

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

Usage Guidelines3/5

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

The description implies usage for editing by mentioning 'easier to find the precise lines to select for editing', but does not explicitly state when to use this tool versus alternatives like 'skim' or 'find_line'. No exclusions or clear alternatives are provided, leaving usage context somewhat implied.

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/danielpodrazka/editor-mcp'

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