Skip to main content
Glama

get_history

Retrieve git commit history for a file to understand its evolution before editing or restoring. Returns newest-first entries with hash, message, date, and author.

Instructions

Return the git commit history for one file (newest first), each entry with hash, message, date, and author. Reads the file's owning repo: the project's git repo for project files, the KB backup repo for KB files. Read-only; no side effects, auth, or rate limits. Returns {file_id, path, history}; an empty array means the file has not been committed yet. Use to understand a file's evolution before editing or restoring. Pair with get_diff to see exact line changes; use restore_file to roll back.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_idYesID of the file

Implementation Reference

  • The core implementation of getHistory. Uses simple-git to get the git log for a file and returns an array of {hash, message, date, author} objects.
    export async function getHistory(
      repoDir: string,
      filePath: string
    ): Promise<Array<{ hash: string; message: string; date: string; author: string }>> {
      const git: SimpleGit = gitFor(repoDir);
      const relativePath = relative(repoDir, filePath);
    
      const log: LogResult = await git.log({ file: relativePath });
    
      return log.all.map((commit) => ({
        hash: commit.hash,
        message: commit.message,
        date: commit.date,
        author: commit.author_name,
      }));
    }
  • The MCP tool registration for get_history. Defines the Zod schema (file_id: number), handler logic calling readFile + getHistory, and the description string.
    server.tool(
      "get_history",
      "Return the git commit history for one file (newest first), each entry with hash, message, date, and author. Reads the file's owning repo: the project's git repo for project files, the KB backup repo for KB files. Read-only; no side effects, auth, or rate limits. Returns `{file_id, path, history}`; an empty array means the file has not been committed yet. Use to understand a file's evolution before editing or restoring. Pair with `get_diff` to see exact line changes; use `restore_file` to roll back.",
      {
        file_id: z.number().describe("ID of the file"),
      },
      async ({ file_id }) => {
        const file = readFile(file_id);
        const history = await getHistory(repoDirForFile(file), file.path);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ file_id, path: file.path, history }, null, 2),
            },
          ],
        };
      }
    );
  • Re-exports getHistory from the git module in the core package's public API.
    export { commitFile, getHistory, getDiff, restoreVersion, syncBackup, syncGlobalVault, getGlobalRemote, setGlobalRemote, isValidGitRemoteUrl, type SyncStage } from "./git/index.js";
  • Helper function repoDirForFile used by the get_history handler to determine the correct git repository directory based on file storage type.
    function repoDirForFile(file: { storage_type: string; project_id: number | null }): string {
      if (file.storage_type === "reference" && file.project_id) {
        const project = getDatabase()
          .prepare("SELECT path FROM projects WHERE id = ?")
          .get(file.project_id) as { path: string | null } | undefined;
        if (project?.path) return project.path;
      }
      return dataDir;
    }
  • Categorizes get_history under 'Versioning' in the web UI tool category map.
    get_history: "Versioning",
    get_diff: "Versioning",
    restore_file: "Versioning",
    commit_backup: "Versioning",
    // Discovery
    stats: "Discovery",
    whats_new: "Discovery",
    project_map: "Discovery",
    diff_against_disk: "Discovery",
    refresh_index: "Discovery",
Behavior5/5

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

Describes read-only nature, no side effects, auth, or rate limits. Also explains repo source for project vs KB files. No annotations provided, so description fully covers behavior.

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?

Three sentences are concise, front-loaded with main purpose, no unnecessary words.

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

Completeness5/5

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

Covers return format, output structure, use cases, and behavioral aspects. Complete for a simple history tool.

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 has 100% coverage and description does not add substantial meaning beyond file_id. Baseline 3 is appropriate.

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?

Clearly states 'Return the git commit history for one file (newest first)' with specifics on output content. Distinguishes from siblings like get_diff and restore_file.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly says 'Use to understand a file's evolution before editing or restoring' and suggests pair with get_diff or use restore_file for rollback, providing clear context.

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/safiyu/ctxnest'

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