Skip to main content
Glama
HasanJahidul

Terminal History MCP

recent_in_dir

Retrieve recent commands executed in a given directory. Helps identify what was done in a specific project folder.

Instructions

List recent commands run in a specific working directory (requires cwd capture, may be empty for legacy entries).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYes
limitNo

Implementation Reference

  • The actual implementation of recentInDir. Queries the 'commands' table filtering by cwd, ordered by timestamp descending.
    export function recentInDir(db: Database.Database, cwd: string, limit = 20): SearchRow[] {
      const stmt = db.prepare(`
        SELECT id, cmd, ts, shell, cwd, exit_code, duration_ms FROM commands
        WHERE cwd = ? ORDER BY ts DESC NULLS LAST LIMIT ?
      `);
      return stmt.all(cwd, limit) as SearchRow[];
    }
  • Schema definition for the 'recent_in_dir' tool, specifying required 'cwd' string and optional 'limit' number.
    {
      name: "recent_in_dir",
      description: "List recent commands run in a specific working directory (requires cwd capture, may be empty for legacy entries).",
      inputSchema: {
        type: "object",
        properties: {
          cwd: { type: "string" },
          limit: { type: "number", default: 20 },
        },
        required: ["cwd"],
      },
    },
  • src/index.ts:110-112 (registration)
    Registration and handler dispatch for 'recent_in_dir' — parses args with Zod and calls recentInDir, formatting the output.
    if (name === "recent_in_dir") {
      const { cwd, limit } = z.object({ cwd: z.string(), limit: z.number().optional() }).parse(args);
      return { content: [{ type: "text", text: fmt(recentInDir(db, cwd, limit ?? 20)) }] };
  • The fmt helper function that formats SearchRow results into human-readable text output.
    function fmt(rows: SearchRow[]): string {
      if (!rows.length) return "(no results)";
      return rows.map((r) => {
        const when = r.ts ? new Date(r.ts).toISOString() : "?";
        const exit = r.exit_code == null ? "" : ` exit=${r.exit_code}`;
        const cwd = r.cwd ? ` cwd=${r.cwd}` : "";
        return `[${r.shell} ${when}${exit}${cwd}] ${r.cmd}`;
      }).join("\n");
    }
Behavior2/5

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

With no annotations, description must fully disclose behavior. It mentions cwd capture and empty results, but does not explain sorting, timeframe for 'recent', or behavior when cwd capture is disabled.

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?

Single sentence, no redundant words, purpose front-loaded. Efficient and clear.

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

Completeness2/5

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

Given 2 parameters and no output schema, description fails to explain what 'recent' means, how results are ordered, or how limit affects output. Inadequate for reliable agent use.

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 coverage is 0%, so description must add meaning. It links cwd to working directory, adding value over schema's plain type, but limit parameter receives no explanation beyond default.

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 verb 'List' and the resource 'recent commands run in a specific working directory', distinguishing it from siblings like command_chains or search_history.

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?

Provides context about requiring cwd capture and potential empty results for legacy entries, but lacks explicit guidance on when to use this tool versus alternatives or when not to use it.

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