Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

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
NameRequiredDescriptionDefault
include_diffNoInclude current working directory changes
commit_countNoNumber of recent commits to include

Implementation Reference

  • 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; }
  • 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, }, ], }; }
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PWalaGov/File-Control-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server