git_log
Retrieve commit logs from a specified Git repository to track changes, view history, and monitor activity. Utilize the max_count parameter to limit displayed results for focused insights.
Instructions
Shows the commit logs
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_count | No | ||
| repo_path | Yes |
Input Schema (JSON Schema)
{
"properties": {
"max_count": {
"default": 10,
"title": "Max Count",
"type": "integer"
},
"repo_path": {
"title": "Repo Path",
"type": "string"
}
},
"required": [
"repo_path"
],
"title": "GitLog",
"type": "object"
}
Implementation Reference
- src/mcp_server_git/server.py:101-114 (handler)The git_log handler function that retrieves the most recent commits from the repository, formats them into log entries, and returns them as a list of strings.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 model defining the input schema for the git_log tool, including repository path and optional max_count.class GitLog(BaseModel): repo_path: str max_count: int = 10
- src/mcp_server_git/server.py:206-210 (registration)Registration of the git_log tool in the server's list_tools method, specifying name, description, and input schema.Tool( name=GitTools.LOG, description="Shows the commit logs", inputSchema=GitLog.schema(), ),
- src/mcp_server_git/server.py:71-71 (registration)Enum value defining the tool name 'git_log' within GitTools.LOG = "git_log"
- src/mcp_server_git/server.py:327-332 (helper)Dispatcher in call_tool that invokes the git_log handler and formats the response as TextContent.case GitTools.LOG: log = git_log(repo, arguments.get("max_count", 10)) return [TextContent( type="text", text="Commit history:\n" + "\n".join(log) )]