Skip to main content
Glama
modelcontextprotocol

git MCP server

Official

git_log

View commit history in Git repositories with timestamp filtering to track changes and review project evolution.

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 main handler function implementing the git_log tool logic, which retrieves commit logs with optional date filtering and formatting.
    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:
            # 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
  • Pydantic BaseModel defining the input schema for the git_log tool.
    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 MCP server's list_tools method.
    Tool(
        name=GitTools.LOG,
        description="Shows the commit logs",
        inputSchema=GitLog.model_json_schema(),
    ),
  • MCP call_tool dispatcher case that invokes the git_log handler and formats the response.
    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)
        )]

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