Skip to main content
Glama

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

NameRequiredDescriptionDefault
messageYesCommit message
pathNoPath 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

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

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/Sheshiyer/git-mcp-v2'

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