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

TableJSON Schema
NameRequiredDescriptionDefault
messageYesCommit message
pathNoPath to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)

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';
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Create a commit' implies a write operation but doesn't specify permissions needed, whether it's destructive to existing data, error conditions, or what happens on success. This is a significant gap for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just three words, front-loaded and zero waste. It efficiently states the core action without unnecessary elaboration, though this brevity contributes to gaps in other dimensions.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a commit operation (a mutation with no annotations or output schema), the description is incomplete. It lacks details on behavioral traits, usage context, and expected outcomes, making it inadequate for an AI agent to reliably invoke this tool without additional inference.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('message' and 'path') adequately. The description adds no additional meaning beyond what the schema provides, such as explaining the commit message format or path requirements, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Create a commit' states the action (create) and resource (commit), which is clear but basic. It doesn't differentiate from sibling tools like 'add' or 'push', which could also be involved in commit workflows, making it somewhat vague in isolation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing staged changes), exclusions, or relationships with siblings like 'add' or 'push', leaving usage context implied at best.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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