git_log
View git commit history to track changes and understand project evolution. Specify repository path and optional limit to display recent commits.
Instructions
Shows git commit history
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | ||
| max_count | No |
Implementation Reference
- Core implementation of git_log tool: fetches recent commits using gitpython Repo.iter_commits and formats commit details (hash, author, date, message).async def log(self, repo_path: str, max_count: int = 10) -> str: """Show git commit history.""" repo = git.Repo(repo_path) commits = list(repo.iter_commits(max_count=max_count)) log = [] for commit in commits: log.append(f"Commit: {commit.hexsha}\nAuthor: {commit.author}\nDate: {commit.authored_datetime}\nMessage: {commit.message}\n") return "\n".join(log)
- Pydantic model defining input schema for git_log tool: repo_path (required) and optional max_count (default 10).class GitLog(BaseModel): repo_path: str max_count: int = 10
- src/mcp_server_code_assist/server.py:131-135 (registration)Registers the git_log tool in the MCP server.list_tools() with name, description, and input schema.Tool( name=CodeAssistTools.GIT_LOG, description="Shows git commit history", inputSchema=GitLog.model_json_schema(), ),
- Handler dispatch in server.call_tool(): parses arguments into GitLog model and delegates to git_tools.log.case CodeAssistTools.GIT_LOG: model = GitLog(repo_path=arguments["repo_path"], max_count=arguments.get("max_count", 10)) result = await git_tools.log(model.repo_path, model.max_count) return [TextContent(type="text", text=result)]
- Factory function to get singleton GitTools instance, used by server to invoke git_log.def get_git_tools(allowed_paths: list[str]) -> GitTools: """Get or create GitTools instance with given allowed paths. Args: allowed_paths: List of paths that tools can operate on Returns: GitTools instance with updated paths """ global _git_tools if not _git_tools or not all(path in _git_tools.allowed_paths for path in allowed_paths): _git_tools = GitTools(allowed_paths=allowed_paths) return _git_tools