Skip to main content
Glama
JeremyLakeyJr

Friday MCP Server

read_file

Read a file from the workspace, optionally specifying start and end lines to extract only the needed text without loading the entire document.

Instructions

Read a file from the workspace with optional line slicing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
start_lineNo
end_lineNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'read_file' tool. Reads a file from the workspace with optional line slicing (start_line to end_line). Resolves the path via _resolve_path, validates it's a file, reads the file, slices lines, numbers them, and returns as a string.
    def read_file(path: str, start_line: int = 1, end_line: int = 200) -> str:
        """Read a file from the workspace with optional line slicing."""
        target = _resolve_path(path)
        if not target.is_file():
            raise ValueError(f"'{path}' is not a file.")
        if start_line < 1 or end_line < start_line:
            raise ValueError("Line range is invalid.")
    
        lines = target.read_text(encoding="utf-8", errors="replace").splitlines()
        selected = lines[start_line - 1 : end_line]
        numbered = [
            f"{line_number}. {line}"
            for line_number, line in enumerate(selected, start=start_line)
        ]
        return "\n".join(numbered)
  • Helper function _resolve_path that resolves a given path relative to the workspace root, with security checks to prevent accessing files outside the allowed workspace (unless allow_external_paths is enabled).
    def _resolve_path(path: str) -> Path:
        raw_path = Path(path).expanduser()
        resolved = (
            raw_path.resolve()
            if raw_path.is_absolute()
            else (config.workspace_root / raw_path).resolve()
        )
        if config.allow_external_paths:
            return resolved
        if resolved != config.workspace_root and config.workspace_root not in resolved.parents:
            raise ValueError(
                f"Path '{path}' is outside the workspace root {config.workspace_root}."
            )
        return resolved
  • Registration entry point: register_all_tools calls workspace.register(mcp, config=config) which sets up the @mcp.tool() decorator for read_file.
    def register_all_tools(mcp, *, config, skill_store) -> None:
        system.register(mcp, config=config)
        utils.register(mcp)
        web.register(mcp, config=config)
        workspace.register(mcp, config=config)
        skills.register(mcp, skill_store=skill_store)
  • The register function in workspace.py that takes 'mcp' and 'config' parameters. Inside this function, the @mcp.tool() decorator on line 43 registers read_file as an MCP tool.
    def register(mcp, *, config) -> None:
        def _resolve_path(path: str) -> Path:
            raw_path = Path(path).expanduser()
Behavior2/5

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

No annotations provided, so description must convey behavior. It only states reading with slicing, but omits critical details: error handling for missing files, encoding, file size limits, and whether the file must be in a specific format.

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 a single sentence with no fluff. However, it lacks structure (e.g., bullet points for parameters) that could improve scannability.

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

Completeness2/5

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

Despite having an output schema, the description fails to mention what the tool returns (e.g., file content, status, errors). It also doesn't address path resolution or workspace bounds.

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

Parameters2/5

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

Schema coverage is 0%, meaning the description adds no parameter details beyond what the schema provides. 'Line slicing' is mentioned but doesn't clarify start_line/end_line semantics (e.g., inclusive/exclusive, 1-indexed).

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

Purpose4/5

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

The description clearly states the action (read) and resource (file from workspace), and mentions optional line slicing. It distinguishes from sibling tools like write_file and run_bash.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives (e.g., write_file, fetch_url). No mention of prerequisites or contexts where line slicing is appropriate.

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/JeremyLakeyJr/mcp-server'

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