commit
Create a Git commit with a specified message and repository path using the Git MCP Server, enabling AI-assisted version control and repository management.
Instructions
Create a commit
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Commit message | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) |
Input Schema (JSON Schema)
{
"properties": {
"message": {
"description": "Commit message",
"type": "string"
},
"path": {
"description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
"type": "string"
}
},
"required": [
"message"
],
"type": "object"
}
Implementation Reference
- src/git-operations.ts:211-255 (handler)The core handler function for the 'commit' tool. Validates the repository, checks for staged changes, executes 'git commit -m "message"', handles caching and errors, and returns the result in MCP format.static async commit({ path, message }: CommitOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); // Verify there are staged changes const statusResult = await CommandExecutor.executeGitCommand( 'status --porcelain', context.operation, repoPath ); if (!statusResult.stdout.trim()) { return { content: [{ type: 'text', text: 'No changes to commit' }], isError: true }; } const result = await CommandExecutor.executeGitCommand( `commit -m "${message}"`, context.operation, repoPath ); return { content: [{ type: 'text', text: `Changes committed successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'commit', invalidateCache: true, // Invalidate status and branch caches stateType: RepoStateType.STATUS } ); }
- src/tool-handler.ts:139-155 (schema)JSON schema definition for the 'commit' tool input, including path (optional) and required message, provided to MCP clients via ListTools.name: 'commit', description: 'Create a commit', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, message: { type: 'string', description: 'Commit message', }, }, required: ['message'], }, },
- src/tool-handler.ts:588-591 (registration)Tool dispatch registration in the CallToolRequest handler switch statement, which validates arguments using isCommitOptions and invokes the GitOperations.commit handler.case 'commit': { const validArgs = this.validateArguments(operation, args, isCommitOptions); return await GitOperations.commit(validArgs, context); }
- src/types.ts:62-162 (schema)TypeScript interface CommitOptions defining the input shape (path and message) and type guard isCommitOptions used for runtime validation.export interface CommitOptions extends GitOptions, BasePathOptions { message: string; } export interface PushPullOptions extends GitOptions, BasePathOptions { remote?: string; branch: string; force?: boolean; // Allow force push/pull noVerify?: boolean; // Skip pre-push/pre-pull hooks tags?: boolean; // Include tags } export interface BranchOptions extends GitOptions, BasePathOptions { name: string; force?: boolean; // Allow force operations track?: boolean; // Set up tracking mode setUpstream?: boolean; // Set upstream for push/pull } export interface CheckoutOptions extends GitOptions, BasePathOptions { target: string; } export interface TagOptions extends GitOptions, BasePathOptions { name: string; message?: string; force?: boolean; // Allow force operations annotated?: boolean; // Create an annotated tag sign?: boolean; // Create a signed tag } export interface RemoteOptions extends GitOptions, BasePathOptions { name: string; url?: string; force?: boolean; // Allow force operations mirror?: boolean; // Mirror all refs tags?: boolean; // Include tags } export interface StashOptions extends GitOptions, BasePathOptions { message?: string; index?: number; includeUntracked?: boolean; // Include untracked files keepIndex?: boolean; // Keep staged changes all?: boolean; // Include ignored files } // New bulk action interfaces export interface BulkActionStage { type: 'stage'; files?: string[]; // If not provided, stages all files } export interface BulkActionCommit { type: 'commit'; message: string; } export interface BulkActionPush { type: 'push'; remote?: string; branch: string; } export type BulkAction = BulkActionStage | BulkActionCommit | BulkActionPush; export interface BulkActionOptions extends GitOptions, BasePathOptions { actions: BulkAction[]; } // Type guard functions export function isAbsolutePath(path: string): boolean { return path.startsWith('/'); } export function validatePath(path?: string): boolean { return !path || isAbsolutePath(path); } export function isInitOptions(obj: any): obj is InitOptions { return obj && validatePath(obj.path); } export function isCloneOptions(obj: any): obj is CloneOptions { return obj && typeof obj.url === 'string' && validatePath(obj.path); } export function isAddOptions(obj: any): obj is AddOptions { return obj && validatePath(obj.path) && Array.isArray(obj.files) && obj.files.every((f: any) => typeof f === 'string' && isAbsolutePath(f)); } export function isCommitOptions(obj: any): obj is CommitOptions { return obj && validatePath(obj.path) && typeof obj.message === 'string'; }