Skip to main content
Glama
mariosss

Local Logs MCP Server

by mariosss

tail_log

Retrieve the last lines from a log file to monitor recent activity and debug applications by viewing recent log entries.

Instructions

Get the last N lines from a log file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameNoName of the log file (default: combined.log)combined.log
linesNoNumber of lines to return (default: 50)

Implementation Reference

  • The tailLog method that executes the core logic of the 'tail_log' MCP tool. It reads the last N lines from the specified log file, preferring the 'tail' command on Unix-like systems and falling back to reading the entire file on Windows or if the command fails.
    tailLog(filename = 'combined.log', lines = 50) {
      try {
        const filePath = path.join(this.logsDir, filename);
        
        if (!fs.existsSync(filePath)) {
          return { 
            content: '', 
            message: `Log file ${filename} not found. Available files: ${this.getLogFiles().files.map(f => f.name).join(', ')}`,
            filename,
            lines: 0
          };
        }
    
        let content;
        try {
          if (process.platform === 'win32') {
            const fullContent = fs.readFileSync(filePath, 'utf8');
            const allLines = fullContent.split('\n');
            content = allLines.slice(-lines).join('\n');
          } else {
            content = execSync(`tail -n ${lines} "${filePath}"`, { encoding: 'utf8' });
          }
        } catch (cmdError) {
          const fullContent = fs.readFileSync(filePath, 'utf8');
          const allLines = fullContent.split('\n');
          content = allLines.slice(-lines).join('\n');
        }
    
        const actualLines = content.split('\n').filter(line => line.trim()).length;
    
        return { 
          content, 
          message: `Last ${actualLines} lines from ${filename}`,
          filename,
          lines: actualLines,
          fileSize: fs.statSync(filePath).size,
          fileSizeHuman: this.formatBytes(fs.statSync(filePath).size)
        };
      } catch (error) {
        return { content: '', error: error.message, filename };
      }
    }
  • The registration of the 'tail_log' tool in the 'tools/list' RPC method response, including its name, description, and input schema.
      name: 'tail_log',
      description: 'Get the last N lines from a log file',
      inputSchema: {
        type: 'object',
        properties: {
          filename: {
            type: 'string',
            description: 'Name of the log file (default: combined.log)',
            default: 'combined.log'
          },
          lines: {
            type: 'number',
            description: 'Number of lines to return (default: 50)',
            default: 50
          }
        },
        required: []
      }
    },
  • The dispatch case in the 'tools/call' handler that routes 'tail_log' calls to the tailLog implementation method.
    case 'tail_log':
      result = this.tailLog(args?.filename, args?.lines);
      break;
  • The JSON schema defining the input parameters for the 'tail_log' tool: optional filename (string) and lines (number).
    inputSchema: {
      type: 'object',
      properties: {
        filename: {
          type: 'string',
          description: 'Name of the log file (default: combined.log)',
          default: 'combined.log'
        },
        lines: {
          type: 'number',
          description: 'Number of lines to return (default: 50)',
          default: 50
        }
      },
      required: []
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic function. It doesn't disclose behavioral traits such as whether this requires file read permissions, if it handles large files efficiently, potential rate limits, or error behavior for missing files. The description is minimal and lacks operational 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 a single, efficient sentence that directly states the tool's purpose with zero wasted words. It's appropriately sized for a simple tool and front-loaded with essential information.

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

Completeness3/5

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

For a simple read operation with no annotations and no output schema, the description is minimally adequate but incomplete. It doesn't explain what the output looks like (e.g., raw text, structured data), error conditions, or performance characteristics, leaving gaps in operational understanding.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents both parameters (filename and lines) with descriptions and defaults. The description adds no additional parameter semantics beyond what the schema provides, meeting the baseline for high schema coverage.

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 ('Get the last N lines') and resource ('from a log file'), distinguishing it from siblings like get_log_files (list files), search_logs (search content), and watch_log (continuous monitoring). It precisely defines the tool's function without ambiguity.

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 retrieving recent log entries, but provides no explicit guidance on when to use this tool versus alternatives like search_logs (for specific patterns) or get_errors (for error-focused retrieval). It lacks clear when-not-to-use statements or prerequisites.

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/mariosss/local-logs-mcp-server'

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