Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

get_git_context

Retrieve Git repository details, including branch info, recent commits, and current working directory changes, to streamline project analysis and version control tasks.

Instructions

Extract Git repository context (branch, recent commits, status)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commit_countNoNumber of recent commits to include
include_diffNoInclude current working directory changes

Implementation Reference

  • server.js:157-175 (registration)
    Tool registration in the list of available tools, including name, description, and input schema.
    { 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)
    Dispatch case in the main tool call handler that routes to the specific handler method.
    case 'get_git_context': return await this.handleGetGitContext(args);
  • Main handler function that processes arguments, calls the git context helper, and formats the 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, }, ], }; }
  • Core helper function that executes Git commands to gather repository context including branch, commits, status, and optional diff.
    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; }
  • Input schema definition for the get_git_context tool parameters.
    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, }, },

Other Tools

Related Tools

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