Skip to main content
Glama
HasanJahidul

Terminal History MCP

search_history

Search indexed shell history by keyword to retrieve matching commands with their timestamp, working directory, and exit code.

Instructions

Full-text search across indexed shell history. Returns matching commands with timestamp/cwd/exit code.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesKeywords to search. Supports prefix match.
limitNo

Implementation Reference

  • Core handler function that executes the search_history tool logic. It builds an FTS (full-text search) query from the user input using escapeFts(), then queries the commands_fts table joined with commands, ordered by rank.
    export function searchHistory(db: Database.Database, query: string, limit = 20): SearchRow[] {
      const fts = escapeFts(query);
      if (!fts) return [];
      const stmt = db.prepare(`
        SELECT c.id, c.cmd, c.ts, c.shell, c.cwd, c.exit_code, c.duration_ms, commands_fts.rank AS rank
        FROM commands_fts
        JOIN commands c ON c.id = commands_fts.rowid
        WHERE commands_fts MATCH ?
        ORDER BY rank LIMIT ?
      `);
      return stmt.all(fts, limit) as SearchRow[];
    }
  • Tool registration with inputSchema definition for search_history. Defines the 'query' (required string) and 'limit' (optional number, default 20) parameters.
    {
      name: "search_history",
      description: "Full-text search across indexed shell history. Returns matching commands with timestamp/cwd/exit code.",
      inputSchema: {
        type: "object",
        properties: {
          query: { type: "string", description: "Keywords to search. Supports prefix match." },
          limit: { type: "number", default: 20 },
        },
        required: ["query"],
      },
  • src/index.ts:106-108 (registration)
    Handler dispatch in the CallToolRequestSchema callback that routes 'search_history' tool calls to the searchHistory function with Zod-parsed arguments.
    if (name === "search_history") {
      const { query, limit } = z.object({ query: z.string(), limit: z.number().optional() }).parse(args);
      return { content: [{ type: "text", text: fmt(searchHistory(db, query, limit ?? 20)) }] };
  • src/index.ts:12-14 (registration)
    Import of the searchHistory function from the search module.
    import {
      searchHistory,
      recentInDir,
  • Helper function that escapes user query tokens for SQLite FTS syntax (prefix matching with asterisk, quoted phrases).
    function escapeFts(q: string): string {
      const tokens = q.split(/\s+/).filter(Boolean).map((t) => {
        const cleaned = t.replace(/["']/g, "");
        if (!cleaned) return "";
        if (/^[A-Za-z0-9_-]+$/.test(cleaned)) return cleaned + "*";
        return `"${cleaned}"`;
      }).filter(Boolean);
      return tokens.join(" OR ");
    }
Behavior3/5

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

With no annotations, the description carries full burden. It discloses the tool is a search (read-only) and the return fields (timestamp, cwd, exit code). However, it does not mention any side effects, authentication needs, rate limits, or other behavioral traits beyond the basic operation.

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

Conciseness4/5

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

The description is a single, concise sentence that front-loads the core purpose. No unnecessary words, but could include more details without being verbose.

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 simplicity (2 params, no output schema), the description provides a minimally adequate overview. However, it lacks context about ordering, pagination, or integration with sibling tools, leaving some gaps for an agent.

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 50% (only 'query' has a description). The description does not add any information about the 'limit' parameter, nor does it elaborate on 'query' beyond what is already in the schema. It offers marginal added value.

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 tool performs full-text search across shell history, specifying the resource (indexed shell history) and the action (search). It also mentions the return format, which distinguishes it from siblings like 'reindex' or 'failed_commands'.

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?

No guidance is provided on when to use this tool versus alternatives like 'command_chains' or 'recent_in_dir'. The description only states what the tool does without any usage context, exclusions, 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/HasanJahidul/terminal-history-mcp'

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