git_log
View commit history in Git repositories to track changes and review project evolution. Specify repository path and optional limit for log entries.
Instructions
Shows the commit logs
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | ||
| max_count | No |
Implementation Reference
- src/mcp_server_git/server.py:101-114 (handler)The handler function that retrieves the git commit history using gitpython, formats log entries with commit hash, author, date, and message, or returns an error message.
def git_log(repo: git.Repo, max_count: int = 10) -> list[str]: try: commits = list(repo.iter_commits('HEAD', max_count=max_count)) log_entries = [] for commit in commits: log_entries.append( f"commit {commit.hexsha}\n" f"Author: {commit.author.name} <{commit.author.email}>\n" f"Date: {commit.committed_datetime}\n\n" f" {commit.message.strip()}\n" ) return log_entries except Exception as e: return [f"Error running git log: {str(e)}"] - src/mcp_server_git/server.py:43-45 (schema)Pydantic BaseModel defining the input parameters for the git_log tool: repo_path (required string) and max_count (optional int default 10).
class GitLog(BaseModel): repo_path: str max_count: int = 10 - src/mcp_server_git/server.py:206-210 (registration)Registers the git_log tool in the MCP server with name from GitTools.LOG ("git_log"), description, and input schema from GitLog model.
Tool( name=GitTools.LOG, description="Shows the commit logs", inputSchema=GitLog.schema(), ), - src/mcp_server_git/server.py:71-71 (helper)Enum value in GitTools defining the tool name "git_log".
LOG = "git_log" - src/mcp_server_git/server.py:327-332 (handler)Tool dispatcher in call_tool() that invokes the git_log handler and formats the response as TextContent for MCP protocol.
case GitTools.LOG: log = git_log(repo, arguments.get("max_count", 10)) return [TextContent( type="text", text="Commit history:\n" + "\n".join(log) )]