Skip to main content
Glama

git_commit_guided

Guide developers through creating structured Git commits with proper formatting and conventions for clear version history.

Instructions

Guide through creating a proper commit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The async handler function for the git_commit_guided tool. It validates the commit message length, optionally stages all changes with 'git add -A', checks if there are staged files using 'git diff --cached', performs the commit, and returns success message with next steps.
    async ({ message, stage_all }) => {
      // Validate commit message
      if (!message || message.length < 10) {
        return { content: [{ type: "text", text: "Commit message should be at least 10 characters.\n\nGood commit message format:\n- feat: add user login feature\n- fix: resolve null pointer in checkout\n- docs: update README setup instructions\n- refactor: simplify payment processing" }] };
      }
    
      let output = "";
    
      if (stage_all) {
        const stageResult = await runCommand("git add -A");
        if (!stageResult.success) {
          return { content: [{ type: "text", text: `Failed to stage: ${stageResult.error}` }] };
        }
        output += "Staged all changes.\n";
      }
    
      // Check if there's anything to commit
      const statusResult = await runCommand("git diff --cached --name-only");
      if (!statusResult.stdout) {
        return { content: [{ type: "text", text: "Nothing staged to commit.\n\nFirst stage your changes:\n  git add <file>     - stage specific file\n  git add -A         - stage all changes" }] };
      }
    
      output += `Files to be committed:\n${statusResult.stdout}\n\n`;
    
      const commitResult = await runCommand(`git commit -m "${message.replace(/"/g, '\\"')}"`);
      if (!commitResult.success) {
        return { content: [{ type: "text", text: `Commit failed: ${commitResult.error}\n${commitResult.stderr}` }] };
      }
    
      output += `Committed successfully!\n\n`;
      output += `Next steps:\n`;
      output += `1. Push to remote: git push origin <branch-name>\n`;
      output += `2. Create a PR: gh pr create\n`;
    
      return { content: [{ type: "text", text: output }] };
    }
  • The input schema (parameters) for the git_commit_guided tool, defining 'message' as required string and 'stage_all' as optional boolean.
    {
      message: { type: "string", description: "Commit message" },
      stage_all: { type: "boolean", description: "Stage all changes first", default: false }
    },
  • src/index.js:105-148 (registration)
    The MCP server.tool registration call for 'git_commit_guided', providing name, description, input schema, and inline handler function.
    server.tool(
      "git_commit_guided",
      "Guide through creating a proper commit",
      {
        message: { type: "string", description: "Commit message" },
        stage_all: { type: "boolean", description: "Stage all changes first", default: false }
      },
      async ({ message, stage_all }) => {
        // Validate commit message
        if (!message || message.length < 10) {
          return { content: [{ type: "text", text: "Commit message should be at least 10 characters.\n\nGood commit message format:\n- feat: add user login feature\n- fix: resolve null pointer in checkout\n- docs: update README setup instructions\n- refactor: simplify payment processing" }] };
        }
    
        let output = "";
    
        if (stage_all) {
          const stageResult = await runCommand("git add -A");
          if (!stageResult.success) {
            return { content: [{ type: "text", text: `Failed to stage: ${stageResult.error}` }] };
          }
          output += "Staged all changes.\n";
        }
    
        // Check if there's anything to commit
        const statusResult = await runCommand("git diff --cached --name-only");
        if (!statusResult.stdout) {
          return { content: [{ type: "text", text: "Nothing staged to commit.\n\nFirst stage your changes:\n  git add <file>     - stage specific file\n  git add -A         - stage all changes" }] };
        }
    
        output += `Files to be committed:\n${statusResult.stdout}\n\n`;
    
        const commitResult = await runCommand(`git commit -m "${message.replace(/"/g, '\\"')}"`);
        if (!commitResult.success) {
          return { content: [{ type: "text", text: `Commit failed: ${commitResult.error}\n${commitResult.stderr}` }] };
        }
    
        output += `Committed successfully!\n\n`;
        output += `Next steps:\n`;
        output += `1. Push to remote: git push origin <branch-name>\n`;
        output += `2. Create a PR: gh pr create\n`;
    
        return { content: [{ type: "text", text: output }] };
      }
    );

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/rideRTD/RTD-DevOps'

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