git_config
Manage Git configuration settings by getting, setting, or listing values for repository or global scope to customize your development workflow.
Instructions
Get or set git configuration
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| action | No | Config action | list |
| key | No | Config key (required for get/set) | |
| value | No | Config value (required for set) | |
| global | No | Use global config instead of repository config |
Implementation Reference
- src/tools/git.ts:458-486 (handler)Main handler function that executes git config commands based on action (list/get/set) using the shared executeGitCommand helper.
export async function gitConfig(args: z.infer<typeof gitConfigSchema>): Promise<ToolResponse> { const globalFlag = args.global ? '--global' : ''; switch (args.action) { case 'list': return executeGitCommand(`git config ${globalFlag} --list`.trim(), args.cwd); case 'get': if (!args.key) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Key required for get action' }, null, 2) }], isError: true }; } return executeGitCommand(`git config ${globalFlag} ${args.key}`.trim(), args.cwd); case 'set': if (!args.key || !args.value) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Key and value required for set action' }, null, 2) }], isError: true }; } return executeGitCommand(`git config ${globalFlag} ${args.key} "${args.value}"`.trim(), args.cwd); default: return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Invalid config action' }, null, 2) }], isError: true }; } } - src/tools/git.ts:202-208 (schema)Zod schema used for input validation in the gitConfig handler.
export const gitConfigSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), action: z.enum(['get', 'set', 'list']).optional().default('list').describe('Config action'), key: z.string().optional().describe('Config key (required for get/set)'), value: z.string().optional().describe('Config value (required for set)'), global: z.boolean().optional().default(false).describe('Use global config instead of repository config') }); - src/tools/git.ts:760-773 (registration)MCP tool registration/definition in the gitTools array, including name, description, and JSON inputSchema.
{ name: 'git_config', description: 'Get or set git configuration', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, action: { type: 'string', enum: ['get', 'set', 'list'], default: 'list', description: 'Config action' }, key: { type: 'string', description: 'Config key (required for get/set)' }, value: { type: 'string', description: 'Config value (required for set)' }, global: { type: 'boolean', default: false, description: 'Use global config instead of repository config' } } } } - src/index.ts:437-440 (registration)Dispatcher/registration in main index.ts handler that routes 'git_config' calls to the gitConfig function after schema validation.
if (name === 'git_config') { const validated = gitConfigSchema.parse(args); return await gitConfig(validated); } - src/tools/git.ts:21-61 (helper)Shared helper function used by all git tools (including git_config) to execute git commands and format responses.
async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }