Skip to main content
Glama

read_context

Extract code segments from files by specifying a line number and surrounding context to analyze specific sections without reviewing entire files.

Instructions

Read code around a specific line with context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
contextNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The implementation of the read_context tool, which reads code surrounding a target line within a file.
    @mcp.tool()
    async def read_context(
        file_path: str,
        line: int,
        context: int = 10
    ) -> str:
        """Read code around a specific line with context."""
        path = Path(file_path).resolve()
        if not path.exists():
            return _error(f"File not found: {file_path}")
    
        try:
            content = path.read_text(encoding="utf-8")
            lines = content.splitlines()
            total_lines = len(lines)
    
            if line < 1 or line > total_lines:
                return _error(f"Line {line} out of range (1-{total_lines})")
    
            start = max(0, line - 1 - context)
            end = min(total_lines, line + context)
    
            selected = {i + 1: lines[i] for i in range(start, end)}
    
            return _ok({
                "file": path.name,
                "path": str(path),
                "target_line": line,
                "range": {"start": start + 1, "end": end},
                "total_lines": total_lines,
                "lines": selected
            })
    
        except UnicodeDecodeError:
            return _error(f"Cannot read file (not UTF-8): {file_path}")
        except Exception as e:
            return _error(str(e))
Behavior2/5

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

No annotations are provided, so the description carries full disclosure burden. While it mentions 'context', it fails to explain that this refers to line count, doesn't describe return format despite output schema existing, and omits error handling (e.g., invalid line numbers).

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

Conciseness2/5

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

Single 9-word sentence is excessively terse given the lack of schema descriptions and annotations. Under-specification masquerading as conciseness; fails to front-load critical distinctions from siblings.

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?

Inadequate for a 3-parameter tool with 0% schema coverage and no annotations. Missing sibling differentiation, parameter details, and behavioral expectations despite having an output schema that could have been referenced.

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%, requiring the description to compensate. It mentions 'context' conceptually but does not explain that the `context` parameter specifies the number of surrounding lines, or that it defaults to 10. `file_path` and `line` are implied but not clarified.

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

Purpose3/5

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

States the core action (read code) and scope (around a specific line), but fails to differentiate from sibling tool `read_code`, leaving ambiguity about when to use this versus the general file reader.

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?

Provides no guidance on when to use this tool versus alternatives like `read_code` or `get_definition`, and mentions no prerequisites or error conditions.

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/qinsehm1128/mcp-ty'

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