Skip to main content
Glama
modelcontextprotocol

git MCP server

Official

git_log

Read-onlyIdempotent

Retrieve commit logs from a Git repository. Filter by maximum number of commits or time range using start and end timestamps.

Instructions

Shows the commit logs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes
max_countNo
start_timestampNoStart timestamp for filtering commits. Accepts: ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')
end_timestampNoEnd timestamp for filtering commits. Accepts: ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')

Implementation Reference

  • The git_log function that executes the tool logic. It accepts a repo, max_count (default 10), optional start_timestamp and end_timestamp for filtering commits by date. Without timestamps, it uses repo.iter_commits; with timestamps, it uses git log with --since/--until flags. Returns a list of formatted commit strings.
    def git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str] = None, end_timestamp: Optional[str] = None) -> list[str]:
        if start_timestamp or end_timestamp:
            # Defense in depth: reject timestamps starting with '-' to prevent flag injection
            if start_timestamp and start_timestamp.startswith("-"):
                raise ValueError(f"Invalid start_timestamp: '{start_timestamp}' - cannot start with '-'")
            if end_timestamp and end_timestamp.startswith("-"):
                raise ValueError(f"Invalid end_timestamp: '{end_timestamp}' - cannot start with '-'")
            # Use git log command with date filtering
            args = []
            if start_timestamp:
                args.extend(['--since', start_timestamp])
            if end_timestamp:
                args.extend(['--until', end_timestamp])
            args.extend(['--format=%H%n%an%n%ad%n%s%n'])
    
            log_output = repo.git.log(*args).split('\n')
    
            log = []
            # Process commits in groups of 4 (hash, author, date, message)
            for i in range(0, len(log_output), 4):
                if i + 3 < len(log_output) and len(log) < max_count:
                    log.append(
                        f"Commit: {log_output[i]}\n"
                        f"Author: {log_output[i+1]}\n"
                        f"Date: {log_output[i+2]}\n"
                        f"Message: {log_output[i+3]}\n"
                    )
            return log
        else:
            # Use existing logic for simple log without date filtering
            commits = list(repo.iter_commits(max_count=max_count))
            log = []
            for commit in commits:
                log.append(
                    f"Commit: {commit.hexsha!r}\n"
                    f"Author: {commit.author!r}\n"
                    f"Date: {commit.authored_datetime}\n"
                    f"Message: {commit.message!r}\n"
                )
            return log
  • GitLog Pydantic model defining the input schema for the git_log tool. Fields: repo_path (str), max_count (int, default 10), start_timestamp (Optional[str] with ISO 8601/relative date description), end_timestamp (Optional[str] with same description).
    class GitLog(BaseModel):
        repo_path: str
        max_count: int = 10
        start_timestamp: Optional[str] = Field(
            None,
            description="Start timestamp for filtering commits. Accepts: ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')"
        )
        end_timestamp: Optional[str] = Field(
            None,
            description="End timestamp for filtering commits. Accepts: ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')"
        )
  • Registration of the git_log tool in the list_tools handler via GitTools.LOG enum value 'git_log', with description 'Shows the commit logs' and inputSchema from GitLog.model_json_schema().
    Tool(
        name=GitTools.LOG,
        description="Shows the commit logs",
        inputSchema=GitLog.model_json_schema(),
        annotations=ToolAnnotations(
            readOnlyHint=True,
            destructiveHint=False,
            idempotentHint=True,
            openWorldHint=False,
        ),
    ),
  • GitTools enum defining LOG = 'git_log' as the tool name identifier used in both registration and call routing.
    class GitTools(str, Enum):
        STATUS = "git_status"
        DIFF_UNSTAGED = "git_diff_unstaged"
        DIFF_STAGED = "git_diff_staged"
        DIFF = "git_diff"
        COMMIT = "git_commit"
        ADD = "git_add"
        RESET = "git_reset"
        LOG = "git_log"
        CREATE_BRANCH = "git_create_branch"
        CHECKOUT = "git_checkout"
        SHOW = "git_show"
  • The call_tool handler that dispatches GitTools.LOG to the git_log function, extracting arguments for max_count, start_timestamp, and end_timestamp from the request.
    # Update the LOG case:
    case GitTools.LOG:
        log = git_log(
            repo,
            arguments.get("max_count", 10),
            arguments.get("start_timestamp"),
            arguments.get("end_timestamp")
        )
        return [TextContent(
            type="text",
            text="Commit history:\n" + "\n".join(log)
        )]
Behavior2/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true. The description adds no behavioral information beyond the tool's basic purpose, such as whether it returns a list or respects truncation.

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

Conciseness3/5

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

The description is a single short sentence, which is concise but omits necessary details. It is not verbose, but could be more informative without losing conciseness.

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?

For a log tool with four parameters and no output schema, the description should explain return values (e.g., list of commits with hash, message). It does not mention output format or the effect of timestamp filters, making it incomplete.

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 description coverage is 50% (two of four parameters have descriptions). The tool description does not add meaning to the parameters, e.g., that repo_path is required or that max_count limits output. It relies solely on the schema for parameter details.

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 'Shows the commit logs' clearly states the verb and resource, and it distinguishes from siblings like git_diff or git_show by focusing on the log. However, it is very brief and does not mention filtering or scope.

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 vs alternatives such as git_show for individual commits or git_diff for changes. The description lacks context for appropriate usage.

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/modelcontextprotocol/git'

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