git_commit
Create Git commits with staged changes using custom messages, amend previous commits, and optionally skip pre-commit hooks for version control management.
Instructions
Create a commit with staged changes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Commit message | |
| cwd | No | Repository directory | |
| amend | No | Amend previous commit | |
| noVerify | No | Skip pre-commit hooks |
Implementation Reference
- src/tools/git.ts:222-228 (handler)The main handler function for the git_commit tool. It constructs and executes the git commit command with options for amending and skipping hooks, using the shared executeGitCommand helper.export async function gitCommit(args: z.infer<typeof gitCommitSchema>): Promise<ToolResponse> { const amendFlag = args.amend ? '--amend' : ''; const noVerifyFlag = args.noVerify ? '--no-verify' : ''; // Escape message for shell const escapedMessage = args.message.replace(/'/g, "'\\''"); return executeGitCommand(`git commit ${amendFlag} ${noVerifyFlag} -m '${escapedMessage}'`, args.cwd); }
- src/tools/git.ts:75-80 (schema)Zod schema used for input validation of the git_commit tool parameters.export const gitCommitSchema = z.object({ message: z.string().describe('Commit message'), cwd: z.string().optional().describe('Repository directory'), amend: z.boolean().optional().default(false).describe('Amend previous commit'), noVerify: z.boolean().optional().default(false).describe('Skip pre-commit hooks') });
- src/index.ts:365-368 (registration)MCP server dispatch logic that handles calls to 'git_commit' by validating inputs with gitCommitSchema and invoking the gitCommit handler.if (name === 'git_commit') { const validated = gitCommitSchema.parse(args); return await gitCommit(validated); }
- src/tools/git.ts:520-533 (registration)Tool metadata registration in the gitTools array, used by MCP server for listing available tools including name, description, and JSON schema.{ name: 'git_commit', description: 'Create a commit with staged changes', inputSchema: { type: 'object', properties: { message: { type: 'string', description: 'Commit message' }, cwd: { type: 'string', description: 'Repository directory' }, amend: { type: 'boolean', default: false, description: 'Amend previous commit' }, noVerify: { type: 'boolean', default: false, description: 'Skip pre-commit hooks' } }, required: ['message'] } },
- src/tools/git.ts:21-61 (helper)Shared utility function used by all git tools, including gitCommit, to execute git commands asynchronously with proper error handling and JSON-formatted 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 }; } }