git-log
Retrieve recent git commit history for a specified directory, allowing users to define the number of commits to display. Supports error handling for non-git directories and provides a default limit of 10 commits.
Instructions
Get recent git commit history
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of recent commits to show (default: 10) | |
| directory | No | Directory path to check git log (defaults to current directory) |
Input Schema (JSON Schema)
{
"properties": {
"count": {
"default": 10,
"description": "Number of recent commits to show (default: 10)",
"type": "number"
},
"directory": {
"description": "Directory path to check git log (defaults to current directory)",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/index.ts:131-161 (handler)Handler for the git-log tool within the CallToolRequestSchema handler. Destructures input arguments, executes the git log command using execSync, formats the response, and handles errors.if (name === "git-log") { const { directory, count = 10 }: { directory?: string; count?: number } = args || {}; try { const cwd = directory || process.cwd(); const gitLog = execSync(`git log --oneline -n ${count}`, { cwd: cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }); return { content: [{ type: "text", text: `Recent Git Commits (${count} most recent):\n\n${gitLog}` }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error running git log: ${errorMessage}` }], isError: true }; } }
- src/index.ts:43-60 (registration)Tool registration for git-log in the ListToolsRequestSchema handler, defining name, description, and input schema.{ name: "git-log", description: "Get recent git commit history", inputSchema: { type: "object", properties: { directory: { type: "string", description: "Directory path to check git log (defaults to current directory)" }, count: { type: "number", description: "Number of recent commits to show (default: 10)", default: 10 } } } }
- src/index.ts:46-59 (schema)Input schema definition for the git-log tool, specifying directory and count parameters.inputSchema: { type: "object", properties: { directory: { type: "string", description: "Directory path to check git log (defaults to current directory)" }, count: { type: "number", description: "Number of recent commits to show (default: 10)", default: 10 } } }