Skip to main content
Glama
safurrier

MCP Filesystem Server

tail_file

Read the last lines of a text file to monitor logs or check recent content. Specify the number of lines and file path for efficient file viewing.

Instructions

Read the last N lines of a text file.

Args:
    path: Path to the file
    lines: Number of lines to read (default: 10)
    encoding: Text encoding (default: utf-8)
    ctx: MCP context

Returns:
    Last N lines of the file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
linesNo
encodingNoutf-8

Implementation Reference

  • MCP tool handler for 'tail_file'. This is the entrypoint function decorated with @mcp.tool(), defining the input schema via type annotations and docstring, handling errors, and delegating to the operations layer.
    @mcp.tool()
    async def tail_file(
        path: str,
        ctx: Context,
        lines: int = 10,
        encoding: str = "utf-8",
    ) -> str:
        """Read the last N lines of a text file.
    
        Args:
            path: Path to the file
            lines: Number of lines to read (default: 10)
            encoding: Text encoding (default: utf-8)
            ctx: MCP context
    
        Returns:
            Last N lines of the file
        """
        try:
            components = get_components()
            content = await components["operations"].tail_file(path, lines, encoding)
            return content
        except Exception as e:
            return f"Error reading file: {str(e)}"
  • Core implementation of tail_file in the FileOperations class. Performs path validation, reads the entire file content, splits into lines, and returns the last N lines.
    async def tail_file(
        self, path: Union[str, Path], lines: int = 10, encoding: str = "utf-8"
    ) -> str:
        """Read the last N lines of a text file.
    
        Args:
            path: Path to the file
            lines: Number of lines to read (default: 10)
            encoding: Text encoding (default: utf-8)
    
        Returns:
            Last N lines of the file
    
        Raises:
            ValueError: If path is outside allowed directories
            FileNotFoundError: If file does not exist
        """
        abs_path, allowed = await self.validator.validate_path(path)
        if not allowed:
            raise ValueError(f"Path outside allowed directories: {path}")
    
        try:
            # We need to read the whole file to get the last N lines
            # This could be optimized for very large files
            data = await anyio.to_thread.run_sync(abs_path.read_text, encoding)
            file_lines = data.splitlines()
            start = max(0, len(file_lines) - lines)
            return "\n".join(file_lines[start:])
    
        except FileNotFoundError:
            raise FileNotFoundError(f"File not found: {path}")
        except PermissionError:
            raise ValueError(f"Permission denied: {path}")
        except UnicodeDecodeError:
            raise ValueError(f"Cannot decode file as {encoding}: {path}")
  • The @mcp.tool() decorator registers the tail_file function as an MCP tool.
    @mcp.tool()
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the core behavior (reading last lines) and default values, but doesn't mention error conditions (e.g., file not found, insufficient permissions), performance characteristics, or what happens with very large files. It adequately describes the basic operation but lacks richer behavioral context.

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

Conciseness5/5

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

The description is perfectly structured: a clear purpose statement followed by organized sections for Args and Returns. Every sentence earns its place with no wasted words, and the information is front-loaded appropriately.

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 3 parameters, no annotations, and no output schema, the description does well by explaining parameters and return values. However, for a file I/O tool, it could mention error handling or security considerations. It's mostly complete but has minor gaps in behavioral context.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining all 3 parameters: path ('Path to the file'), lines ('Number of lines to read'), and encoding ('Text encoding'), including their default values. This adds significant meaning beyond the bare schema.

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 the last N lines') and resource ('of a text file'), distinguishing it from sibling tools like head_file (which reads first lines) and read_file (which reads entire file). The purpose is unambiguous 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 Guidelines4/5

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

The description implies usage context (reading end of files) but doesn't explicitly state when to use this vs. alternatives like head_file or read_file_lines. However, the function name 'tail_file' and description make the intended use case reasonably clear without explicit exclusions or comparisons.

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/safurrier/mcp-filesystem'

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