Skip to main content
Glama
mattlemmone

Expo MCP Server

by mattlemmone

tailFile

Retrieve the last N lines of a file to monitor logs or extract recent data efficiently. Specify the file path and number of lines for quick file analysis and debugging.

Instructions

Read the last N lines from a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesThe path to the file to tail
linesYesNumber of lines to read from the end of the file

Implementation Reference

  • The handler function that reads the last N lines from the specified file and returns them as text content.
    export async function tailFile(args: { filePath: string; lines: number }, { log }: LogContext) {
      try {
        log.info(`Tailing file at path: ${args.filePath} (${args.lines} lines)`);
    
        const normalizedPath = path.normalize(args.filePath);
        
        // Read the entire file content
        const fileContent = await fs.promises.readFile(normalizedPath, "utf8");
        
        // Split by newlines and get the last N lines
        const allLines = fileContent.split('\n');
        const lastLines = allLines.slice(-args.lines).join('\n');
    
        log.info(`Successfully tailed ${args.lines} lines from file: ${normalizedPath}`);
    
        return {
          content: [
            {
              type: "text",
              text: lastLines,
            },
          ],
        };
      } catch (error: any) {
        log.error(`Error tailing file: ${error.message}`);
        throw new Error(`Failed to tail file: ${error.message}`);
      }
    }
  • Zod input schema defining filePath (string) and lines (positive integer).
    parameters: z.object({
      filePath: z.string().describe("The path to the file to tail"),
      lines: z.number().int().positive().describe("Number of lines to read from the end of the file"),
    }),
  • src/index.ts:48-56 (registration)
    Registers the tailFile tool with the FastMCP server, specifying name, description, input schema, and handler.
    addTool({
      name: "tailFile",
      description: "Read the last N lines from a file",
      parameters: z.object({
        filePath: z.string().describe("The path to the file to tail"),
        lines: z.number().int().positive().describe("Number of lines to read from the end of the file"),
      }),
      execute: tailFile,
    });
Install Server

Other Tools

Related 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/mattlemmone/expo-mcp'

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