Skip to main content
Glama

Search Terminal Output

search_output

Search recent terminal output for specific patterns or error messages to quickly identify issues without manual scanning.

Instructions

Search through recent terminal output for a specific pattern or error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesText pattern to search for (case-insensitive)
countNoNumber of recent commands to search through

Implementation Reference

  • Handler function that implements the search_output tool: parses recent terminal history, searches for the given pattern in commands and outputs, and returns matching entries with highlighted lines.
    async ({ pattern, count = 10 }) => {
      const entries = parseLogFile();
      
      if (entries.length === 0) {
        return {
          content: [{
            type: 'text',
            text: 'No terminal history found.',
          }],
        };
      }
    
      const recent = entries.slice(-count);
      const regex = new RegExp(pattern, 'gi');
      const matches = [];
    
      for (const entry of recent) {
        const fullText = `${entry.command}\n${entry.output}`;
        if (regex.test(fullText)) {
          // Find matching lines
          const lines = fullText.split('\n');
          const matchingLines = lines.filter(line => new RegExp(pattern, 'i').test(line));
          
          matches.push({
            command: entry.command,
            exitCode: entry.exitCode,
            matchingLines,
          });
        }
      }
    
      if (matches.length === 0) {
        return {
          content: [{
            type: 'text',
            text: `No matches found for "${pattern}" in the last ${count} commands.`,
          }],
        };
      }
    
      const formatted = matches.map(m => {
        const status = m.exitCode === 0 ? '✓' : `✗ (${m.exitCode})`;
        return `${status} $ ${m.command}\nMatching lines:\n${m.matchingLines.map(l => `  > ${l}`).join('\n')}`;
      }).join('\n\n');
      
      return {
        content: [{
          type: 'text',
          text: `Found ${matches.length} command(s) matching "${pattern}":\n\n${formatted}`,
        }],
      };
    }
  • Input schema definition for the search_output tool using Zod for validation: requires a pattern string and optional count of recent commands.
    {
      title: 'Search Terminal Output',
      description: 'Search through recent terminal output for a specific pattern or error message.',
      inputSchema: {
        pattern: z.string().describe('Text pattern to search for (case-insensitive)'),
        count: z.number().min(1).max(50).default(10).describe('Number of recent commands to search through'),
      },
  • index.js:188-250 (registration)
    Registers the search_output tool with the MCP server, including name, schema, and handler reference.
    server.registerTool(
      'search_output',
      {
        title: 'Search Terminal Output',
        description: 'Search through recent terminal output for a specific pattern or error message.',
        inputSchema: {
          pattern: z.string().describe('Text pattern to search for (case-insensitive)'),
          count: z.number().min(1).max(50).default(10).describe('Number of recent commands to search through'),
        },
      },
      async ({ pattern, count = 10 }) => {
        const entries = parseLogFile();
        
        if (entries.length === 0) {
          return {
            content: [{
              type: 'text',
              text: 'No terminal history found.',
            }],
          };
        }
    
        const recent = entries.slice(-count);
        const regex = new RegExp(pattern, 'gi');
        const matches = [];
    
        for (const entry of recent) {
          const fullText = `${entry.command}\n${entry.output}`;
          if (regex.test(fullText)) {
            // Find matching lines
            const lines = fullText.split('\n');
            const matchingLines = lines.filter(line => new RegExp(pattern, 'i').test(line));
            
            matches.push({
              command: entry.command,
              exitCode: entry.exitCode,
              matchingLines,
            });
          }
        }
    
        if (matches.length === 0) {
          return {
            content: [{
              type: 'text',
              text: `No matches found for "${pattern}" in the last ${count} commands.`,
            }],
          };
        }
    
        const formatted = matches.map(m => {
          const status = m.exitCode === 0 ? '✓' : `✗ (${m.exitCode})`;
          return `${status} $ ${m.command}\nMatching lines:\n${m.matchingLines.map(l => `  > ${l}`).join('\n')}`;
        }).join('\n\n');
        
        return {
          content: [{
            type: 'text',
            text: `Found ${matches.length} command(s) matching "${pattern}":\n\n${formatted}`,
          }],
        };
      }
    );
  • Helper function to parse the terminal log file into structured command entries, used by search_output to access history.
    function parseLogFile() {
      if (!existsSync(LOG_FILE)) {
        return [];
      }
    
      const content = readFileSync(LOG_FILE, 'utf8');
      const entries = [];
      const blocks = content.split('---CMD---').filter(block => block.trim());
    
      for (const block of blocks) {
        const entry = {
          command: '',
          output: '',
          exitCode: null,
          timestamp: null,
        };
    
        // Extract command (line starting with $)
        const cmdMatch = block.match(/^\s*\$\s*(.+?)(?:\n|---)/m);
        if (cmdMatch) {
          entry.command = cmdMatch[1].trim();
        }
    
        // Extract output
        const outputMatch = block.match(/---OUTPUT---\n([\s\S]*?)(?:---EXIT|---END|$)/);
        if (outputMatch) {
          entry.output = outputMatch[1].trim();
        }
    
        // Extract exit code
        const exitMatch = block.match(/---EXIT:(\d+)---/);
        if (exitMatch) {
          entry.exitCode = parseInt(exitMatch[1], 10);
        }
    
        // Extract timestamp if present
        const timestampMatch = block.match(/---TIMESTAMP:(.+?)---/);
        if (timestampMatch) {
          entry.timestamp = timestampMatch[1];
        }
    
        if (entry.command) {
          entries.push(entry);
        }
      }
    
      return entries;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions searching 'recent terminal output' but doesn't specify what 'recent' means, whether results are paginated, if there are rate limits, or how errors are handled. This leaves significant gaps in understanding the tool's behavior beyond basic functionality.

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, well-structured sentence that efficiently conveys the core functionality without unnecessary words. It's appropriately sized and front-loaded with the main purpose, making it easy for an agent to parse quickly.

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?

Given the tool's moderate complexity (search functionality with 2 parameters), no annotations, and no output schema, the description is minimally complete. It covers the basic purpose but lacks details on behavioral traits, output format, and differentiation from siblings, leaving room for improvement in guiding the agent effectively.

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 (pattern and count). The description adds no additional parameter semantics beyond what's in the schema, such as search algorithm details or pattern matching behavior. The baseline score of 3 reflects adequate but minimal value added.

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 tool's purpose as searching through recent terminal output for patterns or error messages, using specific verbs ('search through') and resources ('terminal output'). However, it doesn't explicitly differentiate from sibling tools like get_last_error or get_recent_commands, which might have overlapping functionality.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like get_last_error (for specific errors) or get_recent_commands (for command history), leaving the agent to infer usage context without explicit direction.

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/chrisvin-jabamani/terminal-reader-mcp'

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