get_git_context
Extract Git repository context including branch information, recent commits, and working directory status to provide comprehensive project state awareness.
Instructions
Extract Git repository context (branch, recent commits, status)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| include_diff | No | Include current working directory changes | |
| commit_count | No | Number of recent commits to include |
Implementation Reference
- server.js:1135-1180 (handler)Core handler function that executes Git commands to retrieve repository context: branch, recent commits, status, and optional diff using child_process.async getGitContext(includeDiff, commitCount) { const { exec } = await import('child_process'); const { promisify } = await import('util'); const execAsync = promisify(exec); let gitContext = '# Git Context\n\n'; try { // Check if it's a git repository await execAsync('git rev-parse --git-dir', { cwd: this.workingDirectory }); // Get current branch const { stdout: branch } = await execAsync('git branch --show-current', { cwd: this.workingDirectory }); gitContext += `**Current Branch:** ${branch.trim()}\n\n`; // Get recent commits const { stdout: commits } = await execAsync( `git log --oneline -${commitCount}`, { cwd: this.workingDirectory } ); gitContext += `**Recent Commits:**\n\`\`\`\n${commits}\`\`\`\n\n`; // Get status const { stdout: status } = await execAsync('git status --porcelain', { cwd: this.workingDirectory }); if (status.trim()) { gitContext += `**Working Directory Status:**\n\`\`\`\n${status}\`\`\`\n\n`; } // Get diff if requested if (includeDiff) { try { const { stdout: diff } = await execAsync('git diff HEAD', { cwd: this.workingDirectory }); if (diff.trim()) { gitContext += `**Current Changes:**\n\`\`\`diff\n${diff.slice(0, 2000)}${diff.length > 2000 ? '\n... (truncated)' : ''}\n\`\`\`\n\n`; } } catch (error) { // No diff available } } } catch (error) { gitContext += 'Not a Git repository or Git not available.\n'; } return gitContext; }
- server.js:935-947 (handler)Tool handler wrapper that parses arguments and delegates to getGitContext method, returning formatted response.async handleGetGitContext(args) { const { include_diff = true, commit_count = 10 } = args; const gitContext = await this.getGitContext(include_diff, commit_count); return { content: [ { type: 'text', text: gitContext, }, ], }; }
- server.js:157-175 (schema)Input schema definition and tool registration in the list of available tools.{ name: 'get_git_context', description: 'Extract Git repository context (branch, recent commits, status)', inputSchema: { type: 'object', properties: { include_diff: { type: 'boolean', description: 'Include current working directory changes', default: true, }, commit_count: { type: 'number', description: 'Number of recent commits to include', default: 10, }, }, }, },
- server.js:469-470 (registration)Switch case registration that routes get_git_context tool calls to the handler method.case 'get_git_context': return await this.handleGetGitContext(args);